VFS: Add an unlink method to the character driver interface. This is important because if the character driver inode is unlinked and there are no open references to the driver, then the driver resources will be stranded. On the unlink call, the driver has the opportunity (1) check if there an any open references, and (2) if not free the driver resources
This commit is contained in:
parent
0fc8d2fcc5
commit
62e588a0a4
@ -161,6 +161,26 @@ int unlink(FAR const char *pathname)
|
|||||||
goto errout_with_inode;
|
goto errout_with_inode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Notify the character driver that it has been unlinked. If
|
||||||
|
* there are no open references to the driver instance, then the
|
||||||
|
* driver should clean release all resources because it is no
|
||||||
|
* longer accessible.
|
||||||
|
*/
|
||||||
|
|
||||||
|
if (INODE_IS_DRIVER(inode) && inode->u.i_ops->unlink)
|
||||||
|
{
|
||||||
|
/* The value passed to the driver is the same value that was
|
||||||
|
* provided to register_driver();
|
||||||
|
*/
|
||||||
|
|
||||||
|
ret = inode->u.i_ops->unlink(inode->i_private);
|
||||||
|
if (ret < 0)
|
||||||
|
{
|
||||||
|
errcode = -ret;
|
||||||
|
goto errout_with_inode;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* Remove the old inode. Because we hold a reference count on the
|
/* Remove the old inode. Because we hold a reference count on the
|
||||||
* inode, it will not be deleted now. It will be deleted when all
|
* inode, it will not be deleted now. It will be deleted when all
|
||||||
* of the references to to the inode have been released (perhaps
|
* of the references to to the inode have been released (perhaps
|
||||||
|
@ -91,11 +91,13 @@ struct file_operations
|
|||||||
ssize_t (*write)(FAR struct file *filep, FAR const char *buffer, size_t buflen);
|
ssize_t (*write)(FAR struct file *filep, FAR const char *buffer, size_t buflen);
|
||||||
off_t (*seek)(FAR struct file *filep, off_t offset, int whence);
|
off_t (*seek)(FAR struct file *filep, off_t offset, int whence);
|
||||||
int (*ioctl)(FAR struct file *filep, int cmd, unsigned long arg);
|
int (*ioctl)(FAR struct file *filep, int cmd, unsigned long arg);
|
||||||
|
|
||||||
|
/* The two structures need not be common after this point */
|
||||||
|
|
||||||
#ifndef CONFIG_DISABLE_POLL
|
#ifndef CONFIG_DISABLE_POLL
|
||||||
int (*poll)(FAR struct file *filep, struct pollfd *fds, bool setup);
|
int (*poll)(FAR struct file *filep, struct pollfd *fds, bool setup);
|
||||||
#endif
|
#endif
|
||||||
|
int (*unlink)(FAR void *priv);
|
||||||
/* The two structures need not be common after this point */
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/* This structure provides information about the state of a block driver */
|
/* This structure provides information about the state of a block driver */
|
||||||
@ -234,7 +236,6 @@ union inode_ops_u
|
|||||||
#ifndef CONFIG_DISABLE_MQUEUE
|
#ifndef CONFIG_DISABLE_MQUEUE
|
||||||
FAR struct mqueue_inode_s *i_mqueue; /* POSIX message queue */
|
FAR struct mqueue_inode_s *i_mqueue; /* POSIX message queue */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/* This structure represents one inode in the Nuttx pseudo-file system */
|
/* This structure represents one inode in the Nuttx pseudo-file system */
|
||||||
|
Loading…
Reference in New Issue
Block a user