You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by da...@apache.org on 2020/09/16 18:47:53 UTC
[incubator-nuttx] branch master updated: vfs: Create a node as the
root of pseudo file system
This is an automated email from the ASF dual-hosted git repository.
davids5 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git
The following commit(s) were added to refs/heads/master by this push:
new b76c467 vfs: Create a node as the root of pseudo file system
b76c467 is described below
commit b76c4672d64d226e6ea5c44fa7d3b95e2df8482c
Author: Xiang Xiao <xi...@xiaomi.com>
AuthorDate: Tue Sep 15 17:42:42 2020 +0800
vfs: Create a node as the root of pseudo file system
to remove the special process for root
Signed-off-by: Xiang Xiao <xi...@xiaomi.com>
---
fs/dirent/fs_opendir.c | 54 +++++++++++++---------------------------------
fs/inode/fs_inode.c | 4 ++++
fs/inode/fs_inoderemove.c | 17 +++++----------
fs/inode/fs_inodereserve.c | 30 +++++++++++++++-----------
fs/inode/fs_inodesearch.c | 24 ++++-----------------
fs/inode/inode.h | 10 +++++++++
fs/vfs/fs_rename.c | 32 ---------------------------
fs/vfs/fs_stat.c | 21 ------------------
fs/vfs/fs_statfs.c | 7 ------
9 files changed, 55 insertions(+), 144 deletions(-)
diff --git a/fs/dirent/fs_opendir.c b/fs/dirent/fs_opendir.c
index a8af368..9082aa4 100644
--- a/fs/dirent/fs_opendir.c
+++ b/fs/dirent/fs_opendir.c
@@ -218,7 +218,6 @@ FAR DIR *opendir(FAR const char *path)
FAR const char *relpath = NULL;
#endif
FAR char *alloc = NULL;
- bool isroot = false;
int len;
int ret;
@@ -277,32 +276,24 @@ FAR DIR *opendir(FAR const char *path)
goto errout_with_alloc;
}
- if (path == NULL || *path == '\0' || strcmp(path, "/") == 0)
+ /* We don't know what to do with relative paths */
+
+ if (*path != '/')
{
- inode = g_root_inode;
- isroot = true;
+ ret = ENOTDIR;
+ goto errout_with_semaphore;
}
- else
- {
- /* We don't know what to do with relative paths */
- if (*path != '/')
- {
- ret = ENOTDIR;
- goto errout_with_semaphore;
- }
-
- /* Find the node matching the path. */
+ /* Find the node matching the path. */
- ret = inode_search(&desc);
- if (ret >= 0)
- {
- inode = desc.node;
- DEBUGASSERT(inode != NULL);
+ ret = inode_search(&desc);
+ if (ret >= 0)
+ {
+ inode = desc.node;
+ DEBUGASSERT(inode != NULL);
#ifndef CONFIG_DISABLE_MOUNTPOINT
- relpath = desc.relpath;
+ relpath = desc.relpath;
#endif
- }
}
/* Did we get an inode? */
@@ -335,25 +326,10 @@ FAR DIR *opendir(FAR const char *path)
dir->fd_position = 0; /* This is the position in the read stream */
- /* First, handle the special case of the root inode. This must be
- * special-cased here because the root inode might ALSO be a mountpoint.
- */
-
- if (isroot)
- {
- /* Whatever payload the root inode carries, the root inode is always
- * a directory inode in the pseudo-file system
- */
-
- open_pseudodir(inode, dir);
- }
-
- /* Is this a node in the pseudo filesystem? Or a mountpoint? If the node
- * is the root (isroot == TRUE), then this is a special case.
- */
+ /* Is this a node in the pseudo filesystem? Or a mountpoint? */
#ifndef CONFIG_DISABLE_MOUNTPOINT
- else if (INODE_IS_MOUNTPT(inode))
+ if (INODE_IS_MOUNTPT(inode))
{
/* Yes, the node is a file system mountpoint */
@@ -367,8 +343,8 @@ FAR DIR *opendir(FAR const char *path)
goto errout_with_direntry;
}
}
-#endif
else
+#endif
{
/* The node is part of the root pseudo file system. Does the inode
* have a child? If so that the child would be the 'root' of a list
diff --git a/fs/inode/fs_inode.c b/fs/inode/fs_inode.c
index e048004..1e8793f 100644
--- a/fs/inode/fs_inode.c
+++ b/fs/inode/fs_inode.c
@@ -87,6 +87,10 @@ void inode_initialize(void)
g_inode_sem.holder = NO_HOLDER;
g_inode_sem.count = 0;
+ /* Reserve the root node */
+
+ inode_root_reserve();
+
/* Initialize files array (if it is used) */
#ifdef CONFIG_HAVE_WEAKFUNCTIONS
diff --git a/fs/inode/fs_inoderemove.c b/fs/inode/fs_inoderemove.c
index 8effd4c..e11f7f8 100644
--- a/fs/inode/fs_inoderemove.c
+++ b/fs/inode/fs_inoderemove.c
@@ -100,20 +100,12 @@ FAR struct inode *inode_unlink(FAR const char *path)
desc.peer->i_peer = node->i_peer;
}
- /* If parent is non-null, then remove the node from head of
- * of the list of children.
- */
-
- else if (desc.parent)
- {
- desc.parent->i_child = node->i_peer;
- }
-
- /* Otherwise, we must be removing the root inode. */
+ /* Then remove the node from head of the list of children. */
else
{
- g_root_inode = node->i_peer;
+ DEBUGASSERT(desc.parent != NULL);
+ desc.parent->i_child = node->i_peer;
}
node->i_peer = NULL;
@@ -162,7 +154,8 @@ int inode_remove(FAR const char *path)
else
{
/* And delete it now -- recursively to delete all of its children.
- * Since it has been unlinked, then the peer pointer should be NULL.
+ * Since it has been unlinked, then the peer pointer should be
+ * NULL.
*/
DEBUGASSERT(node->i_peer == NULL);
diff --git a/fs/inode/fs_inodereserve.c b/fs/inode/fs_inodereserve.c
index ef8c17e..3f2c789 100644
--- a/fs/inode/fs_inodereserve.c
+++ b/fs/inode/fs_inodereserve.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * fs/inode/fs_registerreserve.c
+ * fs/inode/fs_inodereserve.c
*
* Copyright (C) 2007-2009, 2011-2012, 2015, 2017 Gregory Nutt. All
* rights reserved.
@@ -118,23 +118,14 @@ static void inode_insert(FAR struct inode *node,
peer->i_peer = node;
}
- /* If parent is non-null, then it must go at the head of its
- * list of children.
- */
+ /* Then it must go at the head of parent's list of children. */
- else if (parent)
+ else
{
+ DEBUGASSERT(parent != NULL);
node->i_peer = parent->i_child;
parent->i_child = node;
}
-
- /* Otherwise, this must be the new root_inode */
-
- else
- {
- node->i_peer = g_root_inode;
- g_root_inode = node;
- }
}
/****************************************************************************
@@ -142,6 +133,19 @@ static void inode_insert(FAR struct inode *node,
****************************************************************************/
/****************************************************************************
+ * Name: inode_root_reserve
+ *
+ * Description:
+ * Reserve the root inode for the pseudo file system.
+ *
+ ****************************************************************************/
+
+void inode_root_reserve(void)
+{
+ g_root_inode = inode_alloc("");
+}
+
+/****************************************************************************
* Name: inode_reserve
*
* Description:
diff --git a/fs/inode/fs_inodesearch.c b/fs/inode/fs_inodesearch.c
index c525478..68810c6 100644
--- a/fs/inode/fs_inodesearch.c
+++ b/fs/inode/fs_inodesearch.c
@@ -1,7 +1,8 @@
/****************************************************************************
* fs/inode/fs_inodesearch.c
*
- * Copyright (C) 2007-2009, 2011-2012, 2016-2017 Gregory Nutt. All rights reserved.
+ * Copyright (C) 2007-2009, 2011-2012, 2016-2017 Gregory Nutt.
+ * All rights reserved.
* Author: Gregory Nutt <gn...@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@@ -255,24 +256,6 @@ static int _inode_search(FAR struct inode_search_s *desc)
return -EINVAL;
}
- /* Skip over the leading '/' */
-
- while (*name == '/')
- {
- name++;
- }
-
- /* Special case the root directory. There is no root inode and there is
- * no name for the root.
- */
-
- if (*name == '\0')
- {
- /* This is a bug. I don't know how to handle this case yet. */
-
- return -ENOSYS;
- }
-
/* Traverse the pseudo file system node tree until either (1) all nodes
* have been examined without finding the matching node, or (2) the
* matching node is found.
@@ -347,7 +330,8 @@ static int _inode_search(FAR struct inode_search_s *desc)
/* If this intermediate inode in the is a soft link, then
* (1) get the name of the full path of the soft link, (2)
* recursively look-up the inode referenced by the soft
- * link, and (3) continue searching with that inode instead.
+ * link, and (3) continue searching with that inode
+ * instead.
*/
status = _inode_linktarget(node, desc);
diff --git a/fs/inode/inode.h b/fs/inode/inode.h
index eb9ef58..6275c4e 100644
--- a/fs/inode/inode.h
+++ b/fs/inode/inode.h
@@ -284,6 +284,16 @@ void inode_free(FAR struct inode *node);
const char *inode_nextname(FAR const char *name);
/****************************************************************************
+ * Name: inode_root_reserve
+ *
+ * Description:
+ * Reserve the root node for the pseudo file system.
+ *
+ ****************************************************************************/
+
+void inode_root_reserve(void);
+
+/****************************************************************************
* Name: inode_reserve
*
* Description:
diff --git a/fs/vfs/fs_rename.c b/fs/vfs/fs_rename.c
index cabc8ba..0007ada 100644
--- a/fs/vfs/fs_rename.c
+++ b/fs/vfs/fs_rename.c
@@ -65,40 +65,8 @@ static int pseudorename(FAR const char *oldpath, FAR struct inode *oldinode,
struct inode_search_s newdesc;
FAR struct inode *newinode;
FAR char *subdir = NULL;
- FAR const char *name;
int ret;
- /* Special case the root directory. There is no root inode and there is
- * no name for the root. inode_find() will fail to the find the root
- * inode -- because there isn't one.
- */
-
- name = newpath;
- while (*name == '/')
- {
- name++;
- }
-
- if (*name == '\0')
- {
- FAR char *subdirname;
-
- /* In the newpath is the root directory, the target of the rename must
- * be a directory entry under the root.
- */
-
- subdirname = basename((FAR char *)oldpath);
-
- asprintf(&subdir, "/%s", subdirname);
- if (subdir == NULL)
- {
- ret = -ENOMEM;
- goto errout;
- }
-
- newpath = subdir;
- }
-
/* According to POSIX, any old inode at this path should be removed
* first, provided that it is not a directory.
*/
diff --git a/fs/vfs/fs_stat.c b/fs/vfs/fs_stat.c
index de62586..c1a6b54 100644
--- a/fs/vfs/fs_stat.c
+++ b/fs/vfs/fs_stat.c
@@ -57,7 +57,6 @@
* Private Function Prototypes
****************************************************************************/
-static inline int statroot(FAR struct stat *buf);
static int stat_recursive(FAR const char *path,
FAR struct stat *buf, int resolve);
@@ -66,19 +65,6 @@ static int stat_recursive(FAR const char *path,
****************************************************************************/
/****************************************************************************
- * Name: statroot
- ****************************************************************************/
-
-static inline int statroot(FAR struct stat *buf)
-{
- /* There is no inode associated with the fake root directory */
-
- RESET_BUF(buf);
- buf->st_mode = S_IFDIR | S_IROTH | S_IRGRP | S_IRUSR;
- return OK;
-}
-
-/****************************************************************************
* Name: stat_recursive
*
* Returned Value:
@@ -187,13 +173,6 @@ int nx_stat(FAR const char *path, FAR struct stat *buf, int resolve)
return -ENOENT;
}
- /* Check for the fake root directory (which has no inode) */
-
- if (strcmp(path, "/") == 0)
- {
- return statroot(buf);
- }
-
/* The perform the stat() operation on the path. This is potentially
* recursive if soft link support is enabled.
*/
diff --git a/fs/vfs/fs_statfs.c b/fs/vfs/fs_statfs.c
index ce7e5d2..8d84463 100644
--- a/fs/vfs/fs_statfs.c
+++ b/fs/vfs/fs_statfs.c
@@ -104,13 +104,6 @@ int statfs(FAR const char *path, FAR struct statfs *buf)
goto errout;
}
- /* Check for the fake root directory (which has no inode) */
-
- if (strcmp(path, "/") == 0)
- {
- return statpseudofs(NULL, buf);
- }
-
/* Get an inode for this file */
SETUP_SEARCH(&desc, path, false);