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 182ab25ef1a fs/vfs: update child parents after renaming a pseudoFS
directory
182ab25ef1a is described below
commit 182ab25ef1a51c6197ec8308bb8f8930460b25ef
Author: jingfei <[email protected]>
AuthorDate: Fri Nov 27 01:41:55 2026 +0800
fs/vfs: update child parents after renaming a pseudoFS directory
pseudorename copies the child list to a new directory inode but leaves
each child's i_parent pointing at the old inode. Releasing the old
directory then leaves dangling parent pointers, and FIOC_FILEPATH on
an open child already returns a stale path while the old inode is held.
Retarget the immediate children after the old name is successfully
removed and before releasing the inode tree lock. The grandchildren
keep their existing parents and the children's references are unchanged.
Signed-off-by: jingfei <[email protected]>
---
fs/vfs/fs_rename.c | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/fs/vfs/fs_rename.c b/fs/vfs/fs_rename.c
index aae551ecba1..a1d621bdca6 100644
--- a/fs/vfs/fs_rename.c
+++ b/fs/vfs/fs_rename.c
@@ -70,6 +70,7 @@ static int pseudorename(FAR const char *oldpath, FAR struct
inode *oldinode,
{
struct inode_search_s newdesc;
FAR struct inode *newinode;
+ FAR struct inode *child;
bool isdir = INODE_IS_PSEUDODIR(oldinode);
size_t oldlen;
int ret;
@@ -240,6 +241,15 @@ static int pseudorename(FAR const char *oldpath, FAR
struct inode *oldinode,
goto errout_with_newsearch;
}
+ /* Children must not retain a parent that will be freed when the old
+ * directory's last reference is released.
+ */
+
+ for (child = newinode->i_child; child != NULL; child = child->i_peer)
+ {
+ child->i_parent = newinode;
+ }
+
/* Remove all of the children from the unlinked inode */
oldinode->i_child = NULL;