From 82c890db235fc434b1d226f2f0b73a6d45c0a3e0 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 22 Jun 2016 05:57:59 -0600 Subject: [PATCH] syslog_dev_flush() needs to check if the inode is a mountpoint before calling the flush() method. Noted by David Sidrane. --- drivers/syslog/syslog_device.c | 4 +- fs/inode/inode.h | 72 +++++++--------------------------- include/nuttx/fs/fs.h | 46 ++++++++++++++++++++++ 3 files changed, 64 insertions(+), 58 deletions(-) diff --git a/drivers/syslog/syslog_device.c b/drivers/syslog/syslog_device.c index 25639e4b50..0364c603a2 100644 --- a/drivers/syslog/syslog_device.c +++ b/drivers/syslog/syslog_device.c @@ -583,7 +583,9 @@ int syslog_dev_flush(void) /* Is this a mountpoint? Does it support the sync method? */ - if (inode && inode->u.i_mops->sync) + if (inode != NULL && /* File opened (i.e., has inode)? */ + INODE_IS_MOUNTPT(inode) && /* Inode is a mountpoint? */ + inode->u.i_mops->sync != NULL) /* And supports synce method? */ { /* Yes... synchronize to the stream */ diff --git a/fs/inode/inode.h b/fs/inode/inode.h index 089bf67234..f909d74ef1 100644 --- a/fs/inode/inode.h +++ b/fs/inode/inode.h @@ -49,55 +49,6 @@ #include #include -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ -/* Inode i_flag values */ - -#define FSNODEFLAG_TYPE_MASK 0x00000007 /* Isolates type field */ -#define FSNODEFLAG_TYPE_DRIVER 0x00000000 /* Character driver */ -#define FSNODEFLAG_TYPE_BLOCK 0x00000001 /* Block driver */ -#define FSNODEFLAG_TYPE_MOUNTPT 0x00000002 /* Mount point */ -#define FSNODEFLAG_TYPE_SPECIAL 0x00000004 /* Special OS type */ -#define FSNODEFLAG_TYPE_NAMEDSEM 0x00000004 /* Named semaphore */ -#define FSNODEFLAG_TYPE_MQUEUE 0x00000005 /* Message Queue */ -#define FSNODEFLAG_TYPE_SHM 0x00000006 /* Shared memory region */ -#define FSNODEFLAG_DELETED 0x00000008 /* Unlinked */ - -#define INODE_IS_TYPE(i,t) \ - (((i)->i_flags & FSNODEFLAG_TYPE_MASK) == (t)) -#define INODE_IS_SPECIAL(i) \ - (((i)->i_flags & FSNODEFLAG_TYPE_SPECIAL) != 0) - -#define INODE_IS_DRIVER(i) INODE_IS_TYPE(i,FSNODEFLAG_TYPE_DRIVER) -#define INODE_IS_BLOCK(i) INODE_IS_TYPE(i,FSNODEFLAG_TYPE_BLOCK) -#define INODE_IS_MOUNTPT(i) INODE_IS_TYPE(i,FSNODEFLAG_TYPE_MOUNTPT) -#define INODE_IS_NAMEDSEM(i) INODE_IS_TYPE(i,FSNODEFLAG_TYPE_NAMEDSEM) -#define INODE_IS_MQUEUE(i) INODE_IS_TYPE(i,FSNODEFLAG_TYPE_MQUEUE) -#define INODE_IS_SHM(i) INODE_IS_TYPE(i,FSNODEFLAG_TYPE_SHM) - -#define INODE_GET_TYPE(i) ((i)->i_flags & FSNODEFLAG_TYPE_MASK) -#define INODE_SET_TYPE(i,t) \ - do \ - { \ - (i)->i_flags = ((i)->i_flags & ~FSNODEFLAG_TYPE_MASK) | (t); \ - } \ - while (0) - -#define INODE_SET_DRIVER(i) INODE_SET_TYPE(i,FSNODEFLAG_TYPE_DRIVER) -#define INODE_SET_BLOCK(i) INODE_SET_TYPE(i,FSNODEFLAG_TYPE_BLOCK) -#define INODE_SET_MOUNTPT(i) INODE_SET_TYPE(i,FSNODEFLAG_TYPE_MOUNTPT) -#define INODE_SET_NAMEDSEM(i) INODE_SET_TYPE(i,FSNODEFLAG_TYPE_NAMEDSEM) -#define INODE_SET_MQUEUE(i) INODE_SET_TYPE(i,FSNODEFLAG_TYPE_MQUEUE) -#define INODE_SET_SHM(i) INODE_SET_TYPE(i,FSNODEFLAG_TYPE_SHM) - -/* Mountpoint fd_flags values */ - -#define DIRENTFLAGS_PSEUDONODE 1 - -#define DIRENT_SETPSEUDONODE(f) do (f) |= DIRENTFLAGS_PSEUDONODE; while (0) -#define DIRENT_ISPSEUDONODE(f) (((f) & DIRENTFLAGS_PSEUDONODE) != 0) - /**************************************************************************** * Public Types ****************************************************************************/ @@ -129,7 +80,6 @@ EXTERN FAR struct inode *g_root_inode; * Public Function Prototypes ****************************************************************************/ -/* fs_inode.c ***************************************************************/ /**************************************************************************** * Name: inode_initialize * @@ -199,7 +149,6 @@ void inode_free(FAR struct inode *node); const char *inode_nextname(FAR const char *name); -/* fs_inodereserver.c *******************************************************/ /**************************************************************************** * Name: inode_reserve * @@ -224,7 +173,6 @@ const char *inode_nextname(FAR const char *name); int inode_reserve(FAR const char *path, FAR struct inode **inode); -/* fs_inoderemove.c *********************************************************/ /**************************************************************************** * Name: inode_unlink * @@ -256,7 +204,6 @@ FAR struct inode *inode_unlink(FAR const char *path); int inode_remove(FAR const char *path); -/* fs_inodefind.c ***********************************************************/ /**************************************************************************** * Name: inode_find * @@ -268,15 +215,27 @@ int inode_remove(FAR const char *path); FAR struct inode *inode_find(FAR const char *path, const char **relpath); -/* fs_inodeaddref.c *********************************************************/ +/**************************************************************************** + * Name: inode_addref + * + * Description: + * Increment the reference count on an inode (as when a file descriptor + * is dup'ed). + * + ****************************************************************************/ void inode_addref(FAR struct inode *inode); -/* fs_inoderelease.c ********************************************************/ +/**************************************************************************** + * Name: inode_release + * + * Description: + * This is called from close() logic when it no longer refers to the inode. + * + ****************************************************************************/ void inode_release(FAR struct inode *inode); -/* fs_foreachinode.c ********************************************************/ /**************************************************************************** * Name: foreach_inode * @@ -295,7 +254,6 @@ void inode_release(FAR struct inode *inode); int foreach_inode(foreach_inode_t handler, FAR void *arg); -/* fs_files.c ***************************************************************/ /**************************************************************************** * Name: files_initialize * diff --git a/include/nuttx/fs/fs.h b/include/nuttx/fs/fs.h index b415725ee8..f1bc737ffe 100644 --- a/include/nuttx/fs/fs.h +++ b/include/nuttx/fs/fs.h @@ -65,6 +65,52 @@ #define __FS_FLAG_EOF (1 << 0) /* EOF detected by a read operation */ #define __FS_FLAG_ERROR (1 << 1) /* Error detected by any operation */ +/* Inode i_flag values */ + +#define FSNODEFLAG_TYPE_MASK 0x00000007 /* Isolates type field */ +#define FSNODEFLAG_TYPE_DRIVER 0x00000000 /* Character driver */ +#define FSNODEFLAG_TYPE_BLOCK 0x00000001 /* Block driver */ +#define FSNODEFLAG_TYPE_MOUNTPT 0x00000002 /* Mount point */ +#define FSNODEFLAG_TYPE_SPECIAL 0x00000004 /* Special OS type */ +#define FSNODEFLAG_TYPE_NAMEDSEM 0x00000004 /* Named semaphore */ +#define FSNODEFLAG_TYPE_MQUEUE 0x00000005 /* Message Queue */ +#define FSNODEFLAG_TYPE_SHM 0x00000006 /* Shared memory region */ +#define FSNODEFLAG_DELETED 0x00000008 /* Unlinked */ + +#define INODE_IS_TYPE(i,t) \ + (((i)->i_flags & FSNODEFLAG_TYPE_MASK) == (t)) +#define INODE_IS_SPECIAL(i) \ + (((i)->i_flags & FSNODEFLAG_TYPE_SPECIAL) != 0) + +#define INODE_IS_DRIVER(i) INODE_IS_TYPE(i,FSNODEFLAG_TYPE_DRIVER) +#define INODE_IS_BLOCK(i) INODE_IS_TYPE(i,FSNODEFLAG_TYPE_BLOCK) +#define INODE_IS_MOUNTPT(i) INODE_IS_TYPE(i,FSNODEFLAG_TYPE_MOUNTPT) +#define INODE_IS_NAMEDSEM(i) INODE_IS_TYPE(i,FSNODEFLAG_TYPE_NAMEDSEM) +#define INODE_IS_MQUEUE(i) INODE_IS_TYPE(i,FSNODEFLAG_TYPE_MQUEUE) +#define INODE_IS_SHM(i) INODE_IS_TYPE(i,FSNODEFLAG_TYPE_SHM) + +#define INODE_GET_TYPE(i) ((i)->i_flags & FSNODEFLAG_TYPE_MASK) +#define INODE_SET_TYPE(i,t) \ + do \ + { \ + (i)->i_flags = ((i)->i_flags & ~FSNODEFLAG_TYPE_MASK) | (t); \ + } \ + while (0) + +#define INODE_SET_DRIVER(i) INODE_SET_TYPE(i,FSNODEFLAG_TYPE_DRIVER) +#define INODE_SET_BLOCK(i) INODE_SET_TYPE(i,FSNODEFLAG_TYPE_BLOCK) +#define INODE_SET_MOUNTPT(i) INODE_SET_TYPE(i,FSNODEFLAG_TYPE_MOUNTPT) +#define INODE_SET_NAMEDSEM(i) INODE_SET_TYPE(i,FSNODEFLAG_TYPE_NAMEDSEM) +#define INODE_SET_MQUEUE(i) INODE_SET_TYPE(i,FSNODEFLAG_TYPE_MQUEUE) +#define INODE_SET_SHM(i) INODE_SET_TYPE(i,FSNODEFLAG_TYPE_SHM) + +/* Mountpoint fd_flags values */ + +#define DIRENTFLAGS_PSEUDONODE 1 + +#define DIRENT_SETPSEUDONODE(f) do (f) |= DIRENTFLAGS_PSEUDONODE; while (0) +#define DIRENT_ISPSEUDONODE(f) (((f) & DIRENTFLAGS_PSEUDONODE) != 0) + /**************************************************************************** * Public Type Definitions ****************************************************************************/