Skip to content

Commit

Permalink
fs/inode: using inode reference to indicate unlink and simply code
Browse files Browse the repository at this point in the history
Signed-off-by: dongjiuzhu1 <[email protected]>
  • Loading branch information
Donny9 authored and xiaoxiang781216 committed Sep 9, 2024
1 parent c6815bb commit 43d0d95
Show file tree
Hide file tree
Showing 12 changed files with 14 additions and 20 deletions.
2 changes: 1 addition & 1 deletion fs/inode/fs_inoderelease.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ void inode_release(FAR struct inode *inode)
* now.
*/

if (inode->i_crefs <= 0 && (inode->i_flags & FSNODEFLAG_DELETED) != 0)
if (inode->i_crefs <= 0)
{
/* If the inode has been properly unlinked, then the peer pointer
* should be NULL.
Expand Down
6 changes: 1 addition & 5 deletions fs/inode/fs_inoderemove.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ static FAR struct inode *inode_unlink(FAR const char *path)

node->i_peer = NULL;
node->i_parent = NULL;
node->i_crefs--;
}

RELEASE_SEARCH(&desc);
Expand Down Expand Up @@ -135,11 +136,6 @@ int inode_remove(FAR const char *path)

if (node->i_crefs)
{
/* In that case, we will mark it deleted, when the filesystem
* releases the inode, we will then, finally delete the subtree
*/

node->i_flags |= FSNODEFLAG_DELETED;
return -EBUSY;
}
else
Expand Down
1 change: 1 addition & 0 deletions fs/inode/fs_inodereserve.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ static FAR struct inode *inode_alloc(FAR const char *name, mode_t mode)
if (node)
{
node->i_ino = g_ino++;
node->i_crefs = 1;
#ifdef CONFIG_PSEUDOFS_ATTRIBUTES
node->i_mode = mode;
clock_gettime(CLOCK_REALTIME, &node->i_atime);
Expand Down
2 changes: 0 additions & 2 deletions fs/mount/fs_mount.c
Original file line number Diff line number Diff line change
Expand Up @@ -507,9 +507,7 @@ int nx_mount(FAR const char *source, FAR const char *target,
/* A lot of goto's! But they make the error handling much simpler */

errout_with_mountpt:
inode_release(mountpt_inode);
inode_remove(target);

errout_with_lock:
inode_unlock();
#ifndef CONFIG_DISABLE_PSEUDOFS_OPERATIONS
Expand Down
4 changes: 2 additions & 2 deletions fs/mqueue/mq_open.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ static int nxmq_file_close(FAR struct file *filep)
{
FAR struct inode *inode = filep->f_inode;

if (inode->i_crefs <= 1 && (inode->i_flags & FSNODEFLAG_DELETED))
if (inode->i_crefs <= 0)
{
FAR struct mqueue_inode_s *msgq = inode->i_private;

Expand Down Expand Up @@ -322,7 +322,7 @@ static int file_mq_vopen(FAR struct file *mq, FAR const char *mq_name,

/* Set the initial reference count on this inode to one */

inode->i_crefs = 1;
inode->i_crefs++;

if (created)
{
Expand Down
4 changes: 2 additions & 2 deletions fs/mqueue/mq_unlink.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,8 @@ int file_mq_unlink(FAR const char *mq_name)
}

/* Remove the old inode from the tree. Because we hold a reference count
* on the inode, it will not be deleted now. This will set the
* FSNODEFLAG_DELETED bit in the inode flags.
* on the inode, it will not be deleted now. This will put reference of
* inode.
*/

ret = inode_remove(fullpath);
Expand Down
2 changes: 1 addition & 1 deletion fs/semaphore/sem_close.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ int nxsem_close(FAR sem_t *sem)
* now.
*/

if (inode->i_crefs <= 0 && (inode->i_flags & FSNODEFLAG_DELETED) != 0)
if (inode->i_crefs <= 0)
{
/* Destroy the semaphore and free the container */

Expand Down
2 changes: 1 addition & 1 deletion fs/semaphore/sem_open.c
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ int nxsem_open(FAR sem_t **sem, FAR const char *name, int oflags, ...)
/* Initialize the inode */

INODE_SET_NAMEDSEM(inode);
inode->i_crefs = 1;
inode->i_crefs++;

/* Initialize the semaphore */

Expand Down
4 changes: 2 additions & 2 deletions fs/semaphore/sem_unlink.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@ int nxsem_unlink(FAR const char *name)
}

/* Remove the old inode from the tree. Because we hold a reference count
* on the inode, it will not be deleted now. This will set the
* FSNODEFLAG_DELETED bit in the inode flags.
* on the inode, it will not be deleted now. This will put reference of
* inode.
*/

ret = inode_remove(fullpath);
Expand Down
2 changes: 1 addition & 1 deletion fs/shm/shm_open.c
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ static int file_shm_open(FAR struct file *shm, FAR const char *name,
INODE_SET_SHM(inode);
inode->u.i_ops = &g_shmfs_operations;
inode->i_private = NULL;
inode->i_crefs = 1;
inode->i_crefs++;
}

/* Associate the inode with a file structure */
Expand Down
4 changes: 2 additions & 2 deletions fs/shm/shm_unlink.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ static int file_shm_unlink(FAR const char *name)
#endif

/* Remove the old inode from the tree. If we hold a reference count
* on the inode, it will not be deleted now. This will set the
* FSNODEFLAG_DELETED bit in the inode flags.
* on the inode, it will not be deleted now. This will put reference of
* inode.
*/

ret = inode_remove(fullpath);
Expand Down
1 change: 0 additions & 1 deletion include/nuttx/fs/fs.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@
#define FSNODEFLAG_TYPE_SOFTLINK 0x00000008 /* Soft link */
#define FSNODEFLAG_TYPE_SOCKET 0x00000009 /* Socket */
#define FSNODEFLAG_TYPE_PIPE 0x0000000a /* Pipe */
#define FSNODEFLAG_DELETED 0x00000010 /* Unlinked */

#define INODE_IS_TYPE(i,t) \
(((i)->i_flags & FSNODEFLAG_TYPE_MASK) == (t))
Expand Down

0 comments on commit 43d0d95

Please sign in to comment.