fs/inode: using inode reference to indicate unlink and simply code
Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
This commit is contained in:
parent
c6815bba3b
commit
43d0d95f81
@ -76,7 +76,7 @@ void inode_release(FAR struct inode *inode)
|
|||||||
* now.
|
* 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
|
/* If the inode has been properly unlinked, then the peer pointer
|
||||||
* should be NULL.
|
* should be NULL.
|
||||||
|
@ -96,6 +96,7 @@ static FAR struct inode *inode_unlink(FAR const char *path)
|
|||||||
|
|
||||||
node->i_peer = NULL;
|
node->i_peer = NULL;
|
||||||
node->i_parent = NULL;
|
node->i_parent = NULL;
|
||||||
|
node->i_crefs--;
|
||||||
}
|
}
|
||||||
|
|
||||||
RELEASE_SEARCH(&desc);
|
RELEASE_SEARCH(&desc);
|
||||||
@ -135,11 +136,6 @@ int inode_remove(FAR const char *path)
|
|||||||
|
|
||||||
if (node->i_crefs)
|
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;
|
return -EBUSY;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -85,6 +85,7 @@ static FAR struct inode *inode_alloc(FAR const char *name, mode_t mode)
|
|||||||
if (node)
|
if (node)
|
||||||
{
|
{
|
||||||
node->i_ino = g_ino++;
|
node->i_ino = g_ino++;
|
||||||
|
node->i_crefs = 1;
|
||||||
#ifdef CONFIG_PSEUDOFS_ATTRIBUTES
|
#ifdef CONFIG_PSEUDOFS_ATTRIBUTES
|
||||||
node->i_mode = mode;
|
node->i_mode = mode;
|
||||||
clock_gettime(CLOCK_REALTIME, &node->i_atime);
|
clock_gettime(CLOCK_REALTIME, &node->i_atime);
|
||||||
|
@ -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 */
|
/* A lot of goto's! But they make the error handling much simpler */
|
||||||
|
|
||||||
errout_with_mountpt:
|
errout_with_mountpt:
|
||||||
inode_release(mountpt_inode);
|
|
||||||
inode_remove(target);
|
inode_remove(target);
|
||||||
|
|
||||||
errout_with_lock:
|
errout_with_lock:
|
||||||
inode_unlock();
|
inode_unlock();
|
||||||
#ifndef CONFIG_DISABLE_PSEUDOFS_OPERATIONS
|
#ifndef CONFIG_DISABLE_PSEUDOFS_OPERATIONS
|
||||||
|
@ -74,7 +74,7 @@ static int nxmq_file_close(FAR struct file *filep)
|
|||||||
{
|
{
|
||||||
FAR struct inode *inode = filep->f_inode;
|
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;
|
FAR struct mqueue_inode_s *msgq = inode->i_private;
|
||||||
|
|
||||||
@ -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 */
|
/* Set the initial reference count on this inode to one */
|
||||||
|
|
||||||
inode->i_crefs = 1;
|
inode->i_crefs++;
|
||||||
|
|
||||||
if (created)
|
if (created)
|
||||||
{
|
{
|
||||||
|
@ -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
|
/* 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
|
* on the inode, it will not be deleted now. This will put reference of
|
||||||
* FSNODEFLAG_DELETED bit in the inode flags.
|
* inode.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
ret = inode_remove(fullpath);
|
ret = inode_remove(fullpath);
|
||||||
|
@ -105,7 +105,7 @@ int nxsem_close(FAR sem_t *sem)
|
|||||||
* now.
|
* now.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (inode->i_crefs <= 0 && (inode->i_flags & FSNODEFLAG_DELETED) != 0)
|
if (inode->i_crefs <= 0)
|
||||||
{
|
{
|
||||||
/* Destroy the semaphore and free the container */
|
/* Destroy the semaphore and free the container */
|
||||||
|
|
||||||
|
@ -211,7 +211,7 @@ int nxsem_open(FAR sem_t **sem, FAR const char *name, int oflags, ...)
|
|||||||
/* Initialize the inode */
|
/* Initialize the inode */
|
||||||
|
|
||||||
INODE_SET_NAMEDSEM(inode);
|
INODE_SET_NAMEDSEM(inode);
|
||||||
inode->i_crefs = 1;
|
inode->i_crefs++;
|
||||||
|
|
||||||
/* Initialize the semaphore */
|
/* Initialize the semaphore */
|
||||||
|
|
||||||
|
@ -115,8 +115,8 @@ int nxsem_unlink(FAR const char *name)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Remove the old inode from the tree. Because we hold a reference count
|
/* 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
|
* on the inode, it will not be deleted now. This will put reference of
|
||||||
* FSNODEFLAG_DELETED bit in the inode flags.
|
* inode.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
ret = inode_remove(fullpath);
|
ret = inode_remove(fullpath);
|
||||||
|
@ -137,7 +137,7 @@ static int file_shm_open(FAR struct file *shm, FAR const char *name,
|
|||||||
INODE_SET_SHM(inode);
|
INODE_SET_SHM(inode);
|
||||||
inode->u.i_ops = &g_shmfs_operations;
|
inode->u.i_ops = &g_shmfs_operations;
|
||||||
inode->i_private = NULL;
|
inode->i_private = NULL;
|
||||||
inode->i_crefs = 1;
|
inode->i_crefs++;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Associate the inode with a file structure */
|
/* Associate the inode with a file structure */
|
||||||
|
@ -117,8 +117,8 @@ static int file_shm_unlink(FAR const char *name)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Remove the old inode from the tree. If we hold a reference count
|
/* 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
|
* on the inode, it will not be deleted now. This will put reference of
|
||||||
* FSNODEFLAG_DELETED bit in the inode flags.
|
* inode.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
ret = inode_remove(fullpath);
|
ret = inode_remove(fullpath);
|
||||||
|
@ -118,7 +118,6 @@
|
|||||||
#define FSNODEFLAG_TYPE_SOFTLINK 0x00000008 /* Soft link */
|
#define FSNODEFLAG_TYPE_SOFTLINK 0x00000008 /* Soft link */
|
||||||
#define FSNODEFLAG_TYPE_SOCKET 0x00000009 /* Socket */
|
#define FSNODEFLAG_TYPE_SOCKET 0x00000009 /* Socket */
|
||||||
#define FSNODEFLAG_TYPE_PIPE 0x0000000a /* Pipe */
|
#define FSNODEFLAG_TYPE_PIPE 0x0000000a /* Pipe */
|
||||||
#define FSNODEFLAG_DELETED 0x00000010 /* Unlinked */
|
|
||||||
|
|
||||||
#define INODE_IS_TYPE(i,t) \
|
#define INODE_IS_TYPE(i,t) \
|
||||||
(((i)->i_flags & FSNODEFLAG_TYPE_MASK) == (t))
|
(((i)->i_flags & FSNODEFLAG_TYPE_MASK) == (t))
|
||||||
|
Loading…
Reference in New Issue
Block a user