diff options
Diffstat (limited to 'nuttx/fs')
-rw-r--r-- | nuttx/fs/Kconfig | 42 | ||||
-rw-r--r-- | nuttx/fs/fat/fs_configfat.c | 14 | ||||
-rw-r--r-- | nuttx/fs/fat/fs_fat32.c | 3 | ||||
-rw-r--r-- | nuttx/fs/fat/fs_fat32util.c | 4 | ||||
-rw-r--r-- | nuttx/fs/fs_fdopen.c | 13 | ||||
-rw-r--r-- | nuttx/fs/fs_files.c | 101 | ||||
-rw-r--r-- | nuttx/fs/fs_syslog.c | 59 | ||||
-rw-r--r-- | nuttx/fs/nxffs/nxffs_dump.c | 2 |
8 files changed, 110 insertions, 128 deletions
diff --git a/nuttx/fs/Kconfig b/nuttx/fs/Kconfig index dfbfda3fa..6aac7a3f7 100644 --- a/nuttx/fs/Kconfig +++ b/nuttx/fs/Kconfig @@ -5,6 +5,10 @@ comment "File system configuration" +config DISABLE_MOUNTPOINT + bool "Disable support for mount points" + default n + source fs/mmap/Kconfig source fs/fat/Kconfig source fs/nfs/Kconfig @@ -14,29 +18,43 @@ source fs/binfs/Kconfig comment "System Logging" -config SYSLOG - bool "System logging" +config SYSLOG_ENABLE + bool "Enable SYSLOG Controls" default n ---help--- - Enables generic system logging features. + Support an interface called syslog_enable to dynamically enable or + disable SYSLOG output. Default: SYSLOG output is always enabled. -config SYSLOG_DEVPATH - string "System log device" - default "/dev/syslog" - depends on SYSLOG +config SYSLOG + bool "Advanced SYSLOG features" + default n ---help--- - The full path to the system logging device. For the RAMLOG SYSLOG device, - this is normally "/dev/ramlog". For character SYSLOG devices, it should be - some other existing character device (or file) supported by the configuration - (such as "/dev/ttyS1")/ + Enables generic system logging features. NOTE: This setting is not + required to enable system logging. If this feature is not enable + system logging will still be available and will log to the system + console (like printf()). This setting is required to enable + customization of the basic system loggin capability. + +if SYSLOG config SYSLOG_CHAR bool "System log character device support" default y - depends on SYSLOG ---help--- Enable the generic character device for the SYSLOG. The full path to the SYSLOG device is provided by SYSLOG_DEVPATH. A valid character device (or file) must exist at this path. It will by opened by syslog_initialize. Do not enable more than one SYSLOG device. + +config SYSLOG_DEVPATH + string "System log device" + default "/dev/syslog" + depends on SYSLOG_CHAR + ---help--- + The full path to the system logging device. For the RAMLOG SYSLOG device, + this is normally "/dev/ramlog". For character SYSLOG devices, it should be + some other existing character device (or file) supported by the configuration + (such as "/dev/ttyS1")/ + +endif diff --git a/nuttx/fs/fat/fs_configfat.c b/nuttx/fs/fat/fs_configfat.c index 2075caa9f..04141ee2b 100644 --- a/nuttx/fs/fat/fs_configfat.c +++ b/nuttx/fs/fat/fs_configfat.c @@ -406,7 +406,7 @@ mkfatfs_clustersearchlimits(FAR struct fat_format_s *fmt, FAR struct fat_var_s * } /**************************************************************************** - * Name: mkfatfs_try12 + * Name: mkfatfs_tryfat12 * * Description: * Try to define a FAT12 filesystem on the device using the candidate @@ -462,7 +462,7 @@ mkfatfs_tryfat12(FAR struct fat_format_s *fmt, FAR struct fat_var_s *var, * FAT12 (remembering that two FAT cluster slots are reserved). */ - if (config->fc_nclusters > maxnclusters - 2) + if (config->fc_nclusters + 2 > maxnclusters) { fvdbg("Too many clusters for FAT12\n"); return -ENFILE; @@ -472,7 +472,7 @@ mkfatfs_tryfat12(FAR struct fat_format_s *fmt, FAR struct fat_var_s *var, } /**************************************************************************** - * Name: mkfatfs_try16 + * Name: mkfatfs_tryfat16 * * Description: * Try to define a FAT16 filesystem on the device using the candidate @@ -532,7 +532,7 @@ mkfatfs_tryfat16(FAR struct fat_format_s *fmt, FAR struct fat_var_s *var, * be confused as a FAT12 at mount time. */ - if ((config->fc_nclusters > maxnclusters - 2) || + if ((config->fc_nclusters + 2 > maxnclusters) || (config->fc_nclusters < FAT_MINCLUST16)) { fvdbg("Too few or too many clusters for FAT16\n"); @@ -543,7 +543,7 @@ mkfatfs_tryfat16(FAR struct fat_format_s *fmt, FAR struct fat_var_s *var, } /**************************************************************************** - * Name: mkfatfs_try32 + * Name: mkfatfs_tryfat32 * * Description: * Try to define a FAT32 filesystem on the device using the candidate @@ -587,7 +587,7 @@ mkfatfs_tryfat32(FAR struct fat_format_s *fmt, FAR struct fat_var_s *var, * maxnclusters = nfatsects * sectorsize / 4 - 2 */ - maxnclusters = (config->fc_nfatsects >> (var->fv_sectshift - 2)); + maxnclusters = (config->fc_nfatsects << (var->fv_sectshift - 2)); if (maxnclusters > FAT_MAXCLUST32) { maxnclusters = FAT_MAXCLUST32; @@ -599,7 +599,7 @@ mkfatfs_tryfat32(FAR struct fat_format_s *fmt, FAR struct fat_var_s *var, * FAT32 (remembering that two FAT cluster slots are reserved). */ - if ((config->fc_nclusters > maxnclusters - 3) || + if ((config->fc_nclusters + 3 > maxnclusters) || (config->fc_nclusters < FAT_MINCLUST32 && fmt->ff_fattype != 32)) { fvdbg("Too few or too many clusters for FAT32\n"); diff --git a/nuttx/fs/fat/fs_fat32.c b/nuttx/fs/fat/fs_fat32.c index c10c28a5c..df8962b51 100644 --- a/nuttx/fs/fat/fs_fat32.c +++ b/nuttx/fs/fat/fs_fat32.c @@ -381,6 +381,7 @@ static int fat_close(FAR struct file *filep) { struct inode *inode; struct fat_file_s *ff; + struct fat_mountpt_s *fs; int ret = OK; /* Sanity checks */ @@ -391,6 +392,7 @@ static int fat_close(FAR struct file *filep) ff = filep->f_priv; inode = filep->f_inode; + fs = inode->i_private; /* Do not check if the mount is healthy. We must support closing of * the file even when there is healthy mount. @@ -408,6 +410,7 @@ static int fat_close(FAR struct file *filep) if (ff->ff_buffer) { + (void)fs; /* Unused if fat_io_free == free(). */ fat_io_free(ff->ff_buffer, fs->fs_hwsectorsize); } diff --git a/nuttx/fs/fat/fs_fat32util.c b/nuttx/fs/fat/fs_fat32util.c index 9aa1d3992..8edef7735 100644 --- a/nuttx/fs/fat/fs_fat32util.c +++ b/nuttx/fs/fat/fs_fat32util.c @@ -106,8 +106,8 @@ static int fat_checkfsinfo(struct fat_mountpt_s *fs) FSI_GETSTRUCTSIG(fs->fs_buffer) == 0x61417272 && FSI_GETTRAILSIG(fs->fs_buffer) == BOOT_SIGNATURE32) { - fs->fs_fsinextfree = FSI_GETFREECOUNT(fs->fs_buffer); - fs->fs_fsifreecount = FSI_GETNXTFREE(fs->fs_buffer); + fs->fs_fsifreecount = FSI_GETFREECOUNT(fs->fs_buffer); + fs->fs_fsinextfree = FSI_GETNXTFREE(fs->fs_buffer); return OK; } } diff --git a/nuttx/fs/fs_fdopen.c b/nuttx/fs/fs_fdopen.c index fd6aa88a8..d8a370482 100644 --- a/nuttx/fs/fs_fdopen.c +++ b/nuttx/fs/fs_fdopen.c @@ -1,7 +1,7 @@ /**************************************************************************** * fs/fs_fdopen.c * - * Copyright (C) 2007-2012 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2013 Gregory Nutt. All rights reserved. * Author: Gregory Nutt <gnutt@nuttx.org> * * Redistribution and use in source and binary forms, with or without @@ -68,9 +68,11 @@ static inline int fs_checkfd(FAR _TCB *tcb, int fd, int oflags) FAR struct filelist *flist; FAR struct inode *inode; - /* Get the file list from the TCB */ + DEBUGASSERT(tcb && tcb->group); - flist = tcb->filelist; + /* Get the file list from the task group */ + + flist = &tcb->group->tg_filelist; /* Get the inode associated with the file descriptor. This should * normally be the case if fd >= 0. But not in the case where the @@ -142,6 +144,7 @@ FAR struct file_struct *fs_fdopen(int fd, int oflags, FAR _TCB *tcb) { tcb = sched_self(); } + DEBUGASSERT(tcb && tcb->group); /* Verify that this is a valid file/socket descriptor and that the * requested access can be support. @@ -189,9 +192,9 @@ FAR struct file_struct *fs_fdopen(int fd, int oflags, FAR _TCB *tcb) /* Get the stream list from the TCB */ - slist = tcb->streams; + slist = &tcb->group->tg_streamlist; - /* Find an unallocated FILE structure in the stream list */ + /* Find an unallocated FILE structure in the stream list */ ret = sem_wait(&slist->sl_sem); if (ret != OK) diff --git a/nuttx/fs/fs_files.c b/nuttx/fs/fs_files.c index 06addb1ef..c68ec7e73 100644 --- a/nuttx/fs/fs_files.c +++ b/nuttx/fs/fs_files.c @@ -155,56 +155,19 @@ void files_initialize(void) } /**************************************************************************** - * Name: files_alloclist + * Name: files_initlist * - * Description: Allocate a list of files for a new task + * Description: Initializes the list of files for a new task * ****************************************************************************/ -FAR struct filelist *files_alloclist(void) +void files_initlist(FAR struct filelist *list) { - FAR struct filelist *list; - list = (FAR struct filelist*)kzalloc(sizeof(struct filelist)); - if (list) - { - /* Start with a reference count of one */ - - list->fl_crefs = 1; - - /* Initialize the list access mutex */ + DEBUGASSERT(list); - (void)sem_init(&list->fl_sem, 0, 1); - } + /* Initialize the list access mutex */ - return list; -} - -/**************************************************************************** - * Name: files_addreflist - * - * Description: - * Increase the reference count on a file list - * - ****************************************************************************/ - -int files_addreflist(FAR struct filelist *list) -{ - if (list) - { - /* Increment the reference count on the list. - * NOTE: that we disable interrupts to do this - * (vs. taking the list semaphore). We do this - * because file cleanup operations often must be - * done from the IDLE task which cannot wait - * on semaphores. - */ - - register irqstate_t flags = irqsave(); - list->fl_crefs++; - irqrestore(flags); - } - - return OK; + (void)sem_init(&list->fl_sem, 0, 1); } /**************************************************************************** @@ -215,51 +178,25 @@ int files_addreflist(FAR struct filelist *list) * ****************************************************************************/ -int files_releaselist(FAR struct filelist *list) +void files_releaselist(FAR struct filelist *list) { - int crefs; - if (list) - { - /* Decrement the reference count on the list. - * NOTE: that we disable interrupts to do this - * (vs. taking the list semaphore). We do this - * because file cleanup operations often must be - * done from the IDLE task which cannot wait - * on semaphores. - */ - - register irqstate_t flags = irqsave(); - crefs = --(list->fl_crefs); - irqrestore(flags); - - /* If the count decrements to zero, then there is no reference - * to the structure and it should be deallocated. Since there - * are references, it would be an error if any task still held - * a reference to the list's semaphore. - */ - - if (crefs <= 0) - { - int i; + int i; - /* Close each file descriptor .. Normally, you would need - * take the list semaphore, but it is safe to ignore the - * semaphore in this context because there are no references - */ + DEBUGASSERT(list); - for (i = 0; i < CONFIG_NFILE_DESCRIPTORS; i++) - { - (void)_files_close(&list->fl_files[i]); - } - - /* Destroy the semaphore and release the filelist */ + /* Close each file descriptor .. Normally, you would need take the list + * semaphore, but it is safe to ignore the semaphore in this context because + * there should not be any references in this context. + */ - (void)sem_destroy(&list->fl_sem); - sched_free(list); - } + for (i = 0; i < CONFIG_NFILE_DESCRIPTORS; i++) + { + (void)_files_close(&list->fl_files[i]); } - return OK; + /* Destroy the semaphore */ + + (void)sem_destroy(&list->fl_sem); } /**************************************************************************** diff --git a/nuttx/fs/fs_syslog.c b/nuttx/fs/fs_syslog.c index 1d569082a..d9ad29e0f 100644 --- a/nuttx/fs/fs_syslog.c +++ b/nuttx/fs/fs_syslog.c @@ -42,6 +42,7 @@ #include <sys/types.h> #include <stdint.h> +#include <stdio.h> #include <unistd.h> #include <fcntl.h> #include <semaphore.h> @@ -167,8 +168,10 @@ static inline int syslog_takesem(void) static inline void syslog_givesem(void) { +#ifdef CONFIG_DEBUG pid_t me = getpid(); DEBUGASSERT(g_sysdev.sl_holder == me); +#endif /* Relinquish the semaphore */ @@ -265,7 +268,7 @@ int syslog_initialize(void) { /* The inode was not found. In this case, we will attempt to re-open * the device repeatedly. The assumption is that the device path is - * value but that the driver has not yet been registered. + * valid but that the driver has not yet been registered. */ g_sysdev.sl_state = SYSLOG_REOPEN; @@ -282,7 +285,7 @@ int syslog_initialize(void) if (!INODE_IS_DRIVER(inode)) #endif { - ret = ENXIO; + ret = -ENXIO; goto errout_with_inode; } @@ -290,7 +293,7 @@ int syslog_initialize(void) if (!inode->u.i_ops || !inode->u.i_ops->write) { - return -EACCES; + ret = -EACCES; goto errout_with_inode; } @@ -346,8 +349,8 @@ int syslog_initialize(void) return OK; errout_with_inode: - g_sysdev.sl_state = SYSLOG_FAILURE; inode_release(inode); + g_sysdev.sl_state = SYSLOG_FAILURE; return ret; } @@ -356,16 +359,18 @@ int syslog_initialize(void) * * Description: * This is the low-level system logging interface. The debugging/syslogging - * interfaces are lib_rawprintf() and lib_lowprinf(). The difference is - * the lib_rawprintf() writes to fd=1 (stdout) and lib_lowprintf() uses + * interfaces are syslog() and lowsyslog(). The difference is is that + * the syslog() function writes to fd=1 (stdout) whereas lowsyslog() uses * a lower level interface that works from interrupt handlers. This - * function is a a low-level interface used to implement lib_lowprintf(). + * function is a a low-level interface used to implement lowsyslog(). * ****************************************************************************/ int syslog_putc(int ch) { ssize_t nbytes; + uint8_t uch; + int errcode; int ret; /* Ignore any output: @@ -382,7 +387,10 @@ int syslog_putc(int ch) * (4) Any debug output generated from interrupt handlers. A disadvantage * of using the generic character device for the SYSLOG is that it * cannot handle debug output generated from interrupt level handlers. - * (5) If an irrecoverable failure occurred during initialization. In + * (5) Any debug output generated from the IDLE loop. The character + * driver interface is blocking and the IDLE thread is not permitted + * to block. + * (6) If an irrecoverable failure occurred during initialization. In * this case, we won't ever bother to try again (ever). * * NOTE: That the third case is different. It applies only to the thread @@ -390,11 +398,12 @@ int syslog_putc(int ch) * that is why that case is handled in syslog_semtake(). */ - /* Case (4) */ + /* Cases (4) and (5) */ - if (up_interrupt_context()) + if (up_interrupt_context() || getpid() == 0) { - return -ENOSYS; /* Not supported */ + errcode = ENOSYS; + goto errout_with_errcode; } /* We can save checks in the usual case: That after the SYSLOG device @@ -408,14 +417,16 @@ int syslog_putc(int ch) if (g_sysdev.sl_state == SYSLOG_UNINITIALIZED || g_sysdev.sl_state == SYSLOG_INITIALIZING) { - return -EAGAIN; /* Can't access the SYSLOG now... maybe next time? */ + errcode = EAGAIN; /* Can't access the SYSLOG now... maybe next time? */ + goto errout_with_errcode; } - /* Case (5) */ + /* Case (6) */ if (g_sysdev.sl_state == SYSLOG_FAILURE) { - return -ENXIO; /* There is no SYSLOG device */ + errcode = ENXIO; /* There is no SYSLOG device */ + goto errout_with_errcode; } /* syslog_initialize() is called as soon as enough of the operating @@ -443,7 +454,8 @@ int syslog_putc(int ch) if (ret < 0) { sched_unlock(); - return ret; + errcode = -ret; + goto errout_with_errcode; } } @@ -471,7 +483,8 @@ int syslog_putc(int ch) * way, we are outta here. */ - return ret; + errcode = -ret; + goto errout_with_errcode; } /* Pre-pend a newline with a carriage return. */ @@ -497,19 +510,27 @@ int syslog_putc(int ch) { /* Write the non-newline character (and don't flush) */ - nbytes = syslog_write(&ch, 1); + uch = (uint8_t)ch; + nbytes = syslog_write(&uch, 1); } syslog_givesem(); - /* Check if the write was successful */ + /* Check if the write was successful. If not, nbytes will be + * a negated errno value. + */ if (nbytes < 0) { - return nbytes; + errcode = -ret; + goto errout_with_errcode; } return ch; + +errout_with_errcode: + set_errno(errcode); + return EOF; } #endif /* CONFIG_SYSLOG && CONFIG_SYSLOG_CHAR */ diff --git a/nuttx/fs/nxffs/nxffs_dump.c b/nuttx/fs/nxffs/nxffs_dump.c index 6a89aaf1d..9caac4c4b 100644 --- a/nuttx/fs/nxffs/nxffs_dump.c +++ b/nuttx/fs/nxffs/nxffs_dump.c @@ -60,7 +60,7 @@ */ #undef fdbg -#define fdbg lib_rawprintf +#define fdbg syslog /**************************************************************************** * Private Types |