This is an automated email from the ASF dual-hosted git repository.
GUIDINGLI pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git
The following commit(s) were added to refs/heads/master by this push:
new 763f89ec34a fs/inode: use static storage for the root inode
763f89ec34a is described below
commit 763f89ec34a26566ab62b02ff3f6549c5333a083
Author: ganjing <[email protected]>
AuthorDate: Fri Nov 27 00:14:24 2026 +0800
fs/inode: use static storage for the root inode
Static allocation for root inode with shared inode_init helper to avoid
code duplication.
The root inode cannot be removed and retains its tree reference for the
lifetime of the system. Initialize static storage instead of allocating
it from fs_heap at startup. Keep the initialization of inode numbers,
references, permissions, credentials and timestamps shared with normal
heap-allocated inodes.
Signed-off-by: Gan Jing <[email protected]>
Signed-off-by: jingfei <[email protected]>
---
fs/inode/fs_inodereserve.c | 54 ++++++++++++++++++++++++++++------------------
1 file changed, 33 insertions(+), 21 deletions(-)
diff --git a/fs/inode/fs_inodereserve.c b/fs/inode/fs_inodereserve.c
index 1edba8a30e4..0aedcb4ad5f 100644
--- a/fs/inode/fs_inodereserve.c
+++ b/fs/inode/fs_inodereserve.c
@@ -41,6 +41,7 @@
****************************************************************************/
static ino_t g_ino;
+static struct inode g_root_inode_storage;
/****************************************************************************
* Private Functions
@@ -77,38 +78,48 @@ static void inode_namecpy(FAR char *dest, FAR const char
*src)
}
/****************************************************************************
- * Name: inode_alloc
+ * Name: inode_init
****************************************************************************/
-static FAR struct inode *inode_alloc(FAR const char *name, mode_t mode)
+static void inode_init(FAR struct inode *inode, mode_t mode)
{
- FAR struct inode *inode;
- int namelen;
#if defined(CONFIG_PSEUDOFS_ATTRIBUTES) && defined(CONFIG_SCHED_USER_IDENTITY)
FAR struct tcb_s *rtcb;
#endif
- namelen = inode_namelen(name);
- inode = fs_heap_zalloc(FSNODE_SIZE(namelen));
- if (inode)
- {
- inode->i_ino = ++g_ino;
- atomic_set(&inode->i_crefs, 1);
+ inode->i_ino = ++g_ino;
+ atomic_set(&inode->i_crefs, 1);
#ifdef CONFIG_PSEUDOFS_ATTRIBUTES
- inode->i_mode = mode;
- clock_gettime(CLOCK_REALTIME, &inode->i_atime);
- inode->i_mtime = inode->i_atime;
- inode->i_ctime = inode->i_atime;
+ inode->i_mode = mode;
+ clock_gettime(CLOCK_REALTIME, &inode->i_atime);
+ inode->i_mtime = inode->i_atime;
+ inode->i_ctime = inode->i_atime;
# if defined(CONFIG_SCHED_USER_IDENTITY)
- rtcb = nxsched_self();
- if (rtcb != NULL && rtcb->group != NULL)
- {
- inode->i_owner = rtcb->group->tg_euid;
- inode->i_group = rtcb->group->tg_egid;
- }
+ rtcb = nxsched_self();
+ if (rtcb != NULL && rtcb->group != NULL)
+ {
+ inode->i_owner = rtcb->group->tg_euid;
+ inode->i_group = rtcb->group->tg_egid;
+ }
# endif
#endif
+}
+
+/****************************************************************************
+ * Name: inode_alloc
+ ****************************************************************************/
+
+static FAR struct inode *inode_alloc(FAR const char *name, mode_t mode)
+{
+ FAR struct inode *inode;
+ int namelen;
+
+ namelen = inode_namelen(name);
+ inode = fs_heap_zalloc(FSNODE_SIZE(namelen));
+ if (inode)
+ {
+ inode_init(inode, mode);
inode_namecpy(inode->i_name, name);
}
@@ -159,7 +170,8 @@ static void inode_insert(FAR struct inode *inode,
void inode_root_reserve(void)
{
- g_root_inode = inode_alloc("", 0777);
+ inode_init(&g_root_inode_storage, 0777);
+ g_root_inode = &g_root_inode_storage;
}
/****************************************************************************