vfs: Create a node as the root of pseudo file system

to remove the special process for root

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
This commit is contained in:
Xiang Xiao
2020-09-15 17:42:42 +08:00
committed by David Sidrane
parent e2fd1fdd84
commit b76c4672d6
9 changed files with 57 additions and 146 deletions
+4
View File
@@ -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
+5 -12
View File
@@ -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);
+18 -14
View File
@@ -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,22 +118,13 @@ 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.
*/
else if (parent)
{
node->i_peer = parent->i_child;
parent->i_child = node;
}
/* Otherwise, this must be the new root_inode */
/* Then it must go at the head of parent's list of children. */
else
{
node->i_peer = g_root_inode;
g_root_inode = node;
DEBUGASSERT(parent != NULL);
node->i_peer = parent->i_child;
parent->i_child = node;
}
}
@@ -141,6 +132,19 @@ static void inode_insert(FAR struct inode *node,
* Public Functions
****************************************************************************/
/****************************************************************************
* 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
*
+4 -20
View File
@@ -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 <gnutt@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);
+10
View File
@@ -283,6 +283,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
*