diff --git a/fs/inode/fs_inoderemove.c b/fs/inode/fs_inoderemove.c index 44232b360e..a9ce4cc0d5 100644 --- a/fs/inode/fs_inoderemove.c +++ b/fs/inode/fs_inoderemove.c @@ -94,7 +94,8 @@ FAR struct inode *inode_unlink(FAR const char *path) desc.parent->i_child = node->i_peer; } - node->i_peer = NULL; + node->i_peer = NULL; + node->i_parent = NULL; } RELEASE_SEARCH(&desc); diff --git a/fs/inode/fs_inodereserve.c b/fs/inode/fs_inodereserve.c index 07a6e0d7f3..17b82cce5e 100644 --- a/fs/inode/fs_inodereserve.c +++ b/fs/inode/fs_inodereserve.c @@ -98,8 +98,9 @@ static void inode_insert(FAR struct inode *node, if (peer) { - node->i_peer = peer->i_peer; - peer->i_peer = node; + node->i_peer = peer->i_peer; + node->i_parent = parent; + peer->i_peer = node; } /* Then it must go at the head of parent's list of children. */ @@ -108,6 +109,7 @@ static void inode_insert(FAR struct inode *node, { DEBUGASSERT(parent != NULL); node->i_peer = parent->i_child; + node->i_parent = parent; parent->i_child = node; } } diff --git a/fs/vfs/fs_rename.c b/fs/vfs/fs_rename.c index 173d26f525..c180b2b23f 100644 --- a/fs/vfs/fs_rename.c +++ b/fs/vfs/fs_rename.c @@ -231,7 +231,8 @@ next_subdir: /* Remove all of the children from the unlinked inode */ - oldinode->i_child = NULL; + oldinode->i_child = NULL; + oldinode->i_parent = NULL; ret = OK; errout_with_sem: diff --git a/include/nuttx/fs/fs.h b/include/nuttx/fs/fs.h index af6157e758..7bdf79c8d0 100644 --- a/include/nuttx/fs/fs.h +++ b/include/nuttx/fs/fs.h @@ -347,6 +347,7 @@ union inode_ops_u struct inode { + FAR struct inode *i_parent; /* Link to parent level inode */ FAR struct inode *i_peer; /* Link to same level inode */ FAR struct inode *i_child; /* Link to lower level inode */ int16_t i_crefs; /* References to inode */