You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2020/12/30 18:21:15 UTC

[incubator-nuttx] branch master updated (81224cc -> 3386941)

This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git.


    from 81224cc  arch/stm32: Fix nxstyle errors
     new f5b59e2  fs/vfs: add nx_unlink support
     new 3386941  fs: remove INODE_IS_SPECIAL() use others instead

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 fs/mount/fs_mount.c   |   2 +-
 fs/vfs/fs_stat.c      | 145 +++++++++++++++++++++-----------------------
 fs/vfs/fs_unlink.c    | 165 +++++++++++++++++++++++++-------------------------
 include/nuttx/fs/fs.h |  42 +++++++++----
 4 files changed, 184 insertions(+), 170 deletions(-)


[incubator-nuttx] 02/02: fs: remove INODE_IS_SPECIAL() use others instead

Posted by xi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git

commit 3386941a109f9e786428311d58a4ee687ab3b1bd
Author: ligd <li...@xiaomi.com>
AuthorDate: Thu Dec 24 22:53:32 2020 +0800

    fs: remove INODE_IS_SPECIAL() use others instead
    
    Change-Id: I949f1ad012836e6cb233d5362fe2542732b5ecf4
    Signed-off-by: ligd <li...@xiaomi.com>
---
 fs/mount/fs_mount.c   |   2 +-
 fs/vfs/fs_stat.c      | 145 ++++++++++++++++++++++++--------------------------
 fs/vfs/fs_unlink.c    | 128 ++++++++++++++++++++------------------------
 include/nuttx/fs/fs.h |  25 +++++----
 4 files changed, 142 insertions(+), 158 deletions(-)

diff --git a/fs/mount/fs_mount.c b/fs/mount/fs_mount.c
index e032530..1057d71 100644
--- a/fs/mount/fs_mount.c
+++ b/fs/mount/fs_mount.c
@@ -356,7 +356,7 @@ int nx_mount(FAR const char *source, FAR const char *target,
        * node)?
        */
 
-      if (INODE_IS_SPECIAL(mountpt_inode))
+      if (!INODE_IS_PSEUDODIR(mountpt_inode))
         {
           ferr("ERROR: target %s exists and is a special node\n", target);
           ret = -ENOTDIR;
diff --git a/fs/vfs/fs_stat.c b/fs/vfs/fs_stat.c
index c1a6b54..ad31c58 100644
--- a/fs/vfs/fs_stat.c
+++ b/fs/vfs/fs_stat.c
@@ -259,115 +259,110 @@ int inode_stat(FAR struct inode *inode, FAR struct stat *buf, int resolve)
 
   /* Handle "special" nodes */
 
-  if (INODE_IS_SPECIAL(inode))
-    {
 #if defined(CONFIG_FS_NAMED_SEMAPHORES)
-      /* Check for a named semaphore */
+  /* Check for a named semaphore */
 
-      if (INODE_IS_NAMEDSEM(inode))
-        {
-          buf->st_mode = S_IFSEM;
-        }
-      else
+  if (INODE_IS_NAMEDSEM(inode))
+    {
+      buf->st_mode = S_IFSEM;
+    }
+  else
 #endif
 #if !defined(CONFIG_DISABLE_MQUEUE)
-      /* Check for a message queue */
+  /* Check for a message queue */
 
-      if (INODE_IS_MQUEUE(inode))
-        {
-          buf->st_mode = S_IFMQ;
-        }
-      else
+  if (INODE_IS_MQUEUE(inode))
+    {
+      buf->st_mode = S_IFMQ;
+    }
+  else
 #endif
 #if defined(CONFIG_FS_SHM)
-      /* Check for shared memory */
+  /* Check for shared memory */
 
-      if (INODE_IS_SHM(inode))
-        {
-          buf->st_mode = S_IFSHM;
-        }
-      else
+  if (INODE_IS_SHM(inode))
+    {
+      buf->st_mode = S_IFSHM;
+    }
+  else
 #endif
 #if defined(CONFIG_MTD)
-      /* Check for an MTD driver */
+  /* Check for an MTD driver */
 
-      if (INODE_IS_MTD(inode))
-        {
-          struct mtd_geometry_s mtdgeo;
+  if (INODE_IS_MTD(inode))
+    {
+      struct mtd_geometry_s mtdgeo;
 
-          buf->st_mode  = S_IFMTD;
-          buf->st_mode |= S_IROTH | S_IRGRP | S_IRUSR;
-          buf->st_mode |= S_IWOTH | S_IWGRP | S_IWUSR;
+      buf->st_mode  = S_IFMTD;
+      buf->st_mode |= S_IROTH | S_IRGRP | S_IRUSR;
+      buf->st_mode |= S_IWOTH | S_IWGRP | S_IWUSR;
 
-          if (inode->u.i_mtd != NULL &&
-              MTD_IOCTL(inode->u.i_mtd, MTDIOC_GEOMETRY,
-                        (unsigned long)((uintptr_t)&mtdgeo)) >= 0)
-            {
-              buf->st_size = mtdgeo.neraseblocks * mtdgeo.erasesize;
-            }
+      if (inode->u.i_mtd != NULL &&
+          MTD_IOCTL(inode->u.i_mtd, MTDIOC_GEOMETRY,
+                    (unsigned long)((uintptr_t)&mtdgeo)) >= 0)
+        {
+          buf->st_size = mtdgeo.neraseblocks * mtdgeo.erasesize;
         }
-      else
+    }
+  else
 #endif
 #ifdef CONFIG_PSEUDOFS_SOFTLINKS
-      /* Handle softlinks differently.  Just call stat() recursively on the
-       * target of the softlink.
-       *
-       * REVISIT: This has the possibility of an infinite loop!
-       */
+  /* Handle softlinks differently.  Just call stat() recursively on the
+   * target of the softlink.
+   *
+   * REVISIT: This has the possibility of an infinite loop!
+   */
 
-      if (INODE_IS_SOFTLINK(inode))
+  if (INODE_IS_SOFTLINK(inode))
+    {
+      if (resolve)
         {
-          if (resolve)
+          int ret;
+
+          /* Increment the link counter.  This is necessary to avoid
+           * infinite recursion if loops are encountered in the
+           * traversal. If we encounter more SYMLOOP_MAX symbolic links
+           * at any time during the traversal, error out.
+           *
+           * NOTE: That inode_search() will automatically skip over
+           * consecutive, intermediate symbolic links.  Those numbers
+           * will not be included in the total.
+           */
+
+          if (++buf->st_count > SYMLOOP_MAX)
             {
-              int ret;
-
-              /* Increment the link counter.  This is necessary to avoid
-               * infinite recursion if loops are encountered in the
-               * traversal. If we encounter more SYMLOOP_MAX symbolic links
-               * at any time during the traversal, error out.
-               *
-               * NOTE: That inode_search() will automatically skip over
-               * consecutive, intermediate symbolic links.  Those numbers
-               * will not be included in the total.
-               */
-
-              if (++buf->st_count > SYMLOOP_MAX)
-                {
-                  return -ELOOP;
-                }
+              return -ELOOP;
+            }
 
-              DEBUGASSERT(buf->st_count > 0);  /* Check for unsigned integer overflow */
+          DEBUGASSERT(buf->st_count > 0);  /* Check for unsigned integer overflow */
 
-              /* stat() the target of the soft link. */
+          /* stat() the target of the soft link. */
 
-              ret = stat_recursive(inode->u.i_link, buf, 1);
+          ret = stat_recursive(inode->u.i_link, buf, 1);
 
-              /* If stat() fails, then there is a problem with the target of
-               * the symbolic link, but not with the symbolic link itself.
-               * We should still report success, just with less information.
-               */
+          /* If stat() fails, then there is a problem with the target of
+           * the symbolic link, but not with the symbolic link itself.
+           * We should still report success, just with less information.
+           */
 
-              if (ret < 0)
-                {
-                  RESET_BUF(buf);
-                }
-            }
-          else
+          if (ret < 0)
             {
-              /* Make sure the caller knows that this is a symbolic link. */
-
-              buf->st_mode = S_IRWXO | S_IRWXG | S_IRWXU | S_IFLNK;
+              RESET_BUF(buf);
             }
         }
       else
-#endif
         {
+          /* Make sure the caller knows that this is a symbolic link. */
+
+          buf->st_mode = S_IRWXO | S_IRWXG | S_IRWXU | S_IFLNK;
         }
     }
+  else
+#endif
 
   /* Handle "normal inodes */
 
-  else if (inode->u.i_ops != NULL)
+  if (inode->u.i_ops != NULL)
     {
       /* Determine read/write privileges based on the existence of read
        * and write methods.
diff --git a/fs/vfs/fs_unlink.c b/fs/vfs/fs_unlink.c
index dde986b..5b0b605 100644
--- a/fs/vfs/fs_unlink.c
+++ b/fs/vfs/fs_unlink.c
@@ -106,96 +106,83 @@ int nx_unlink(FAR const char *pathname)
   else
 #endif
 
+    {
 #ifndef CONFIG_DISABLE_PSEUDOFS_OPERATIONS
-  /* If this is a "dangling" pseudo-file node (i.e., it has no operations)
-   * or a soft link, then rm should remove the node.
-   */
-
-#ifdef CONFIG_PSEUDOFS_SOFTLINKS
-  /* A soft link is the only "specal" file that we can remove via unlink(). */
+      ret = inode_semtake();
+      if (ret < 0)
+        {
+          goto errout_with_inode;
+        }
 
-  if (!INODE_IS_SPECIAL(inode) || INODE_IS_SOFTLINK(inode))
-#else
-  if (!INODE_IS_SPECIAL(inode))
-#endif
-    {
-      /* If this is a pseudo-file node (i.e., it has no operations)
-       * then unlink should remove the node.
+      /* Refuse to unlink the inode if it has children.  I.e., if it is
+       * functioning as a directory and the directory is not empty.
        */
 
-      if (inode->u.i_ops != NULL)
+      if (inode->i_child != NULL)
         {
-          ret = inode_semtake();
-          if (ret < 0)
-            {
-              goto errout_with_inode;
-            }
-
-          /* Refuse to unlink the inode if it has children.  I.e., if it is
-           * functioning as a directory and the directory is not empty.
-           */
+          ret = -ENOTEMPTY;
+          goto errout_with_sem;
+        }
 
-          if (inode->i_child != NULL)
-            {
-              ret = -ENOTEMPTY;
-              inode_semgive();
-              goto errout_with_inode;
-            }
+      /* Notify the driver that it has been unlinked.  If there are no
+       * open references to the driver instance, then the driver should
+       * release all resources because it is no longer accessible.
+       */
 
-          /* Notify the driver that it has been unlinked.  If there are no
-           * open references to the driver instance, then the driver should
-           * release all resources because it is no longer accessible.
-           */
+      if (INODE_IS_DRIVER(inode) && inode->u.i_ops->unlink)
+        {
+          /* Notify the character driver that it has been unlinked */
 
-          if (INODE_IS_DRIVER(inode) && inode->u.i_ops->unlink)
+          ret = inode->u.i_ops->unlink(inode);
+          if (ret < 0)
             {
-              /* Notify the character driver that it has been unlinked */
-
-              ret = inode->u.i_ops->unlink(inode);
-              if (ret < 0)
-                {
-                  goto errout_with_inode;
-                }
+              goto errout_with_sem;
             }
+        }
 #ifndef CONFIG_DISABLE_MOUNTPOINT
-          else if (INODE_IS_BLOCK(inode) && inode->u.i_bops->unlink)
-            {
-              /* Notify the block driver that it has been unlinked */
+      else if (INODE_IS_BLOCK(inode) && inode->u.i_bops->unlink)
+        {
+          /* Notify the block driver that it has been unlinked */
 
-              ret = inode->u.i_bops->unlink(inode);
-              if (ret < 0)
-                {
-                  goto errout_with_inode;
-                }
+          ret = inode->u.i_bops->unlink(inode);
+          if (ret < 0)
+            {
+              goto errout_with_sem;
             }
+        }
 #endif
-
-          /* Remove the old inode.  Because we hold a reference count on the
-           * inode, it will not be deleted now.  It will be deleted when all
-           * of the references to the inode have been released (perhaps
-           * when inode_release() is called below).  inode_remove() will
-           * return -EBUSY to indicate that the inode was not deleted now.
+#ifdef CONFIG_PSEUDOFS_SOFTLINKS
+      else if (INODE_IS_PSEUDODIR(inode) || INODE_IS_SOFTLINK(inode))
+#else
+      else if (INODE_IS_PSEUDODIR(inode))
+#endif
+        {
+          /* If this is a "dangling" pseudo-file node
+           * (i.e., it has no operations) or a soft link,
+           * then rm should remove the node.
            */
-
-          ret = inode_remove(pathname);
-          inode_semgive();
-
-          if (ret < 0 && ret != -EBUSY)
-            {
-              goto errout_with_inode;
-            }
         }
       else
         {
-          ret = -EISDIR;
+          ret = -ENXIO;
+          goto errout_with_sem;
+        }
+
+      /* Remove the old inode.  Because we hold a reference count on the
+       * inode, it will not be deleted now.  It will be deleted when all
+       * of the references to the inode have been released (perhaps
+       * when inode_release() is called below).  inode_remove() will
+       * return -EBUSY to indicate that the inode was not deleted now.
+       */
+
+      ret = inode_remove(pathname);
+      inode_semgive();
+
+      if (ret < 0 && ret != -EBUSY)
+        {
           goto errout_with_inode;
         }
-    }
-  else
 #endif
-    {
-      ret = -ENXIO;
-      goto errout_with_inode;
     }
 
   /* Successfully unlinked */
@@ -204,6 +191,9 @@ int nx_unlink(FAR const char *pathname)
   RELEASE_SEARCH(&desc);
   return OK;
 
+errout_with_sem:
+  inode_semgive();
+
 errout_with_inode:
   inode_release(inode);
 
diff --git a/include/nuttx/fs/fs.h b/include/nuttx/fs/fs.h
index bb9ad8f..70e6f9e 100644
--- a/include/nuttx/fs/fs.h
+++ b/include/nuttx/fs/fs.h
@@ -108,23 +108,22 @@
  *   Bit 4:   Set if inode has been unlinked and is pending removal.
  */
 
-#define FSNODEFLAG_TYPE_MASK       0x0000000f /* 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    0x00000008 /* Special OS type          */
-#define   FSNODEFLAG_TYPE_NAMEDSEM 0x00000008 /*   Named semaphore        */
-#define   FSNODEFLAG_TYPE_MQUEUE   0x00000009 /*   Message Queue          */
-#define   FSNODEFLAG_TYPE_SHM      0x0000000a /*   Shared memory region   */
-#define   FSNODEFLAG_TYPE_MTD      0x0000000b /*   Named MTD driver       */
-#define   FSNODEFLAG_TYPE_SOFTLINK 0x0000000c /*   Soft link              */
-#define FSNODEFLAG_DELETED         0x00000010 /* Unlinked                 */
+#define FSNODEFLAG_TYPE_MASK        0x0000000f /* Isolates type field      */
+#define   FSNODEFLAG_TYPE_PSEUDODIR 0x00000000 /*   Pseudo dir (default)   */
+#define   FSNODEFLAG_TYPE_DRIVER    0x00000001 /*   Character driver       */
+#define   FSNODEFLAG_TYPE_BLOCK     0x00000002 /*   Block driver           */
+#define   FSNODEFLAG_TYPE_MOUNTPT   0x00000003 /*   Mount point            */
+#define   FSNODEFLAG_TYPE_NAMEDSEM  0x00000004 /*   Named semaphore        */
+#define   FSNODEFLAG_TYPE_MQUEUE    0x00000005 /*   Message Queue          */
+#define   FSNODEFLAG_TYPE_SHM       0x00000006 /*   Shared memory region   */
+#define   FSNODEFLAG_TYPE_MTD       0x00000007 /*   Named MTD driver       */
+#define   FSNODEFLAG_TYPE_SOFTLINK  0x00000008 /*   Soft link              */
+#define FSNODEFLAG_DELETED          0x00000010 /* 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_PSEUDODIR(i) INODE_IS_TYPE(i,FSNODEFLAG_TYPE_PSEUDODIR)
 #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)


[incubator-nuttx] 01/02: fs/vfs: add nx_unlink support

Posted by xi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git

commit f5b59e287a9f78a53811b0c80fb52c8bb424814a
Author: ligd <li...@xiaomi.com>
AuthorDate: Thu Dec 24 18:22:51 2020 +0800

    fs/vfs: add nx_unlink support
    
    Change-Id: If9009cb7301bb4e49bdce3aea2d56c243256f5a2
    Signed-off-by: ligd <li...@xiaomi.com>
---
 fs/vfs/fs_unlink.c    | 43 ++++++++++++++++++++++++++++---------------
 include/nuttx/fs/fs.h | 17 +++++++++++++++++
 2 files changed, 45 insertions(+), 15 deletions(-)

diff --git a/fs/vfs/fs_unlink.c b/fs/vfs/fs_unlink.c
index 91c12ff..dde986b 100644
--- a/fs/vfs/fs_unlink.c
+++ b/fs/vfs/fs_unlink.c
@@ -49,17 +49,16 @@
  ****************************************************************************/
 
 /****************************************************************************
- * Name: unlink
+ * Name: nx_unlink
  *
  * Description:  Remove a file managed a mountpoint
  *
  ****************************************************************************/
 
-int unlink(FAR const char *pathname)
+int nx_unlink(FAR const char *pathname)
 {
   struct inode_search_s desc;
   FAR struct inode *inode;
-  int errcode;
   int ret;
 
   /* Get an inode for this file (without deference the final node in the path
@@ -73,7 +72,6 @@ int unlink(FAR const char *pathname)
     {
       /* There is no inode that includes in this path */
 
-      errcode = -ret;
       goto errout_with_search;
     }
 
@@ -96,13 +94,12 @@ int unlink(FAR const char *pathname)
           ret = inode->u.i_mops->unlink(inode, desc.relpath);
           if (ret < 0)
             {
-              errcode = -ret;
               goto errout_with_inode;
             }
         }
       else
         {
-          errcode = ENOSYS;
+          ret = -ENOSYS;
           goto errout_with_inode;
         }
     }
@@ -131,7 +128,6 @@ int unlink(FAR const char *pathname)
           ret = inode_semtake();
           if (ret < 0)
             {
-              errcode = -ret;
               goto errout_with_inode;
             }
 
@@ -141,7 +137,7 @@ int unlink(FAR const char *pathname)
 
           if (inode->i_child != NULL)
             {
-              errcode = ENOTEMPTY;
+              ret = -ENOTEMPTY;
               inode_semgive();
               goto errout_with_inode;
             }
@@ -158,7 +154,6 @@ int unlink(FAR const char *pathname)
               ret = inode->u.i_ops->unlink(inode);
               if (ret < 0)
                 {
-                  errcode = -ret;
                   goto errout_with_inode;
                 }
             }
@@ -170,7 +165,6 @@ int unlink(FAR const char *pathname)
               ret = inode->u.i_bops->unlink(inode);
               if (ret < 0)
                 {
-                  errcode = -ret;
                   goto errout_with_inode;
                 }
             }
@@ -188,20 +182,19 @@ int unlink(FAR const char *pathname)
 
           if (ret < 0 && ret != -EBUSY)
             {
-              errcode = -ret;
               goto errout_with_inode;
             }
         }
       else
         {
-          errcode = EISDIR;
+          ret = -EISDIR;
           goto errout_with_inode;
         }
     }
   else
 #endif
     {
-      errcode = ENXIO;
+      ret = -ENXIO;
       goto errout_with_inode;
     }
 
@@ -216,8 +209,28 @@ errout_with_inode:
 
 errout_with_search:
   RELEASE_SEARCH(&desc);
-  set_errno(errcode);
-  return ERROR;
+  return ret;
+}
+
+/****************************************************************************
+ * Name: unlink
+ *
+ * Description:  Remove a file managed a mountpoint
+ *
+ ****************************************************************************/
+
+int unlink(FAR const char *pathname)
+{
+  int ret;
+
+  ret = nx_unlink(pathname);
+  if (ret < 0)
+    {
+      set_errno(-ret);
+      return ERROR;
+    }
+
+  return OK;
 }
 
 #endif /* FS_HAVE_UNLINK */
diff --git a/include/nuttx/fs/fs.h b/include/nuttx/fs/fs.h
index e8ad6c4..bb9ad8f 100644
--- a/include/nuttx/fs/fs.h
+++ b/include/nuttx/fs/fs.h
@@ -1458,6 +1458,23 @@ int file_fstat(FAR struct file *filep, FAR struct stat *buf);
 
 int nx_stat(FAR const char *path, FAR struct stat *buf, int resolve);
 
+/****************************************************************************
+ * Name: nx_unlink
+ *
+ * Description:
+ *   nx_unlink() is similar to the standard 'unlink' interface except that
+ *   is not a cancellation point and it does not modify the errno variable.
+ *
+ *   nx_unlink() is an internal NuttX interface and should not be called
+ *   from applications.
+ *
+ * Returned Value:
+ *   Zero is returned on success; a negated value is returned on any failure.
+ *
+ ****************************************************************************/
+
+int nx_unlink(FAR const char *pathname);
+
 #undef EXTERN
 #if defined(__cplusplus)
 }