fs: Add nx_mount/nx_umount2 function

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
This commit is contained in:
Xiang Xiao
2020-05-04 21:49:07 +08:00
committed by patacongo
parent 4a3d28a957
commit de33f86ae3
4 changed files with 148 additions and 56 deletions
+58 -33
View File
@@ -246,32 +246,23 @@ mount_findfs(FAR const struct fsmap_t *fstab, FAR const char *filesystemtype)
****************************************************************************/ ****************************************************************************/
/**************************************************************************** /****************************************************************************
* Name: mount * Name: nx_mount
* *
* Description: * Description:
* mount() attaches the filesystem specified by the 'source' block device * nx_mount() is similar to the standard 'mount' interface except that is
* name into the root file system at the path specified by 'target.' * not a cancellation point and it does not modify the errno variable.
*
* nx_mount() is an internal NuttX interface and should not be called from
* applications.
* *
* Returned Value: * Returned Value:
* Zero is returned on success; -1 is returned on an error and errno is * Zero is returned on success; a negated value is returned on any failure.
* set appropriately:
*
* EACCES A component of a path was not searchable or mounting a read-only
* filesystem was attempted without giving the MS_RDONLY flag.
* EBUSY 'source' is already mounted.
* EFAULT One of the pointer arguments points outside the user address
* space.
* EINVAL 'source' had an invalid superblock.
* ENODEV 'filesystemtype' not configured
* ENOENT A pathname was empty or had a nonexistent component.
* ENOMEM Could not allocate a memory to copy filenames or data into.
* ENOTBLK 'source' is not a block device
* *
****************************************************************************/ ****************************************************************************/
int mount(FAR const char *source, FAR const char *target, int nx_mount(FAR const char *source, FAR const char *target,
FAR const char *filesystemtype, unsigned long mountflags, FAR const char *filesystemtype, unsigned long mountflags,
FAR const void *data) FAR const void *data)
{ {
#if defined(BDFS_SUPPORT) || defined(MDFS_SUPPORT) || defined(NODFS_SUPPORT) #if defined(BDFS_SUPPORT) || defined(MDFS_SUPPORT) || defined(NODFS_SUPPORT)
#if defined(BDFS_SUPPORT) || defined(MDFS_SUPPORT) #if defined(BDFS_SUPPORT) || defined(MDFS_SUPPORT)
@@ -283,14 +274,13 @@ int mount(FAR const char *source, FAR const char *target,
struct inode_search_s desc; struct inode_search_s desc;
#endif #endif
void *fshandle; void *fshandle;
int errcode;
int ret; int ret;
/* Verify required pointer arguments */ /* Verify required pointer arguments */
DEBUGASSERT(target && filesystemtype); DEBUGASSERT(target && filesystemtype);
/* Find the specified filesystem. Try the block driver file systems first */ /* Find the specified filesystem. Try the block driver filesystems first */
#ifdef BDFS_SUPPORT #ifdef BDFS_SUPPORT
if (source != NULL && if (source != NULL &&
@@ -304,7 +294,7 @@ int mount(FAR const char *source, FAR const char *target,
ferr("ERROR: Failed to find block based file system %s\n", ferr("ERROR: Failed to find block based file system %s\n",
filesystemtype); filesystemtype);
errcode = ENODEV; ret = -ENODEV;
goto errout_with_inode; goto errout_with_inode;
} }
} }
@@ -321,7 +311,7 @@ int mount(FAR const char *source, FAR const char *target,
ferr("ERROR: Failed to find MTD based file system %s\n", ferr("ERROR: Failed to find MTD based file system %s\n",
filesystemtype); filesystemtype);
errcode = ENODEV; ret = -ENODEV;
goto errout_with_inode; goto errout_with_inode;
} }
} }
@@ -336,14 +326,13 @@ int mount(FAR const char *source, FAR const char *target,
{ {
ferr("ERROR: Failed to find block driver %s\n", source); ferr("ERROR: Failed to find block driver %s\n", source);
errcode = ENOTBLK; ret = -ENOTBLK;
goto errout; goto errout;
} }
ret = inode_semtake(); ret = inode_semtake();
if (ret < 0) if (ret < 0)
{ {
errcode = -ret;
goto errout_with_inode; goto errout_with_inode;
} }
@@ -369,7 +358,7 @@ int mount(FAR const char *source, FAR const char *target,
if (INODE_IS_SPECIAL(mountpt_inode)) if (INODE_IS_SPECIAL(mountpt_inode))
{ {
ferr("ERROR: target %s exists and is a special node\n", target); ferr("ERROR: target %s exists and is a special node\n", target);
errcode = -ENOTDIR; ret = -ENOTDIR;
inode_release(mountpt_inode); inode_release(mountpt_inode);
goto errout_with_semaphore; goto errout_with_semaphore;
} }
@@ -398,7 +387,6 @@ int mount(FAR const char *source, FAR const char *target,
*/ */
ferr("ERROR: Failed to reserve inode for target %s\n", target); ferr("ERROR: Failed to reserve inode for target %s\n", target);
errcode = -ret;
goto errout_with_semaphore; goto errout_with_semaphore;
} }
} }
@@ -413,7 +401,7 @@ int mount(FAR const char *source, FAR const char *target,
/* The filesystem does not support the bind operation ??? */ /* The filesystem does not support the bind operation ??? */
ferr("ERROR: Filesystem does not support bind\n"); ferr("ERROR: Filesystem does not support bind\n");
errcode = EINVAL; ret = -EINVAL;
goto errout_with_mountpt; goto errout_with_mountpt;
} }
@@ -453,7 +441,6 @@ int mount(FAR const char *source, FAR const char *target,
} }
#endif #endif
errcode = -ret;
goto errout_with_mountpt; goto errout_with_mountpt;
} }
@@ -510,13 +497,51 @@ errout_with_inode:
#endif #endif
errout: errout:
set_errno(errcode); return ret;
return ERROR;
#else #else
ferr("ERROR: No filesystems enabled\n"); ferr("ERROR: No filesystems enabled\n");
set_errno(ENOSYS); return -ENOSYS;
return ERROR;
#endif /* BDFS_SUPPORT || MDFS_SUPPORT || NODFS_SUPPORT */ #endif /* BDFS_SUPPORT || MDFS_SUPPORT || NODFS_SUPPORT */
} }
/****************************************************************************
* Name: mount
*
* Description:
* mount() attaches the filesystem specified by the 'source' block device
* name into the root file system at the path specified by 'target.'
*
* Returned Value:
* Zero is returned on success; -1 is returned on an error and errno is
* set appropriately:
*
* EACCES A component of a path was not searchable or mounting a read-only
* filesystem was attempted without giving the MS_RDONLY flag.
* EBUSY 'source' is already mounted.
* EFAULT One of the pointer arguments points outside the user address
* space.
* EINVAL 'source' had an invalid superblock.
* ENODEV 'filesystemtype' not configured
* ENOENT A pathname was empty or had a nonexistent component.
* ENOMEM Could not allocate a memory to copy filenames or data into.
* ENOTBLK 'source' is not a block device
*
****************************************************************************/
int mount(FAR const char *source, FAR const char *target,
FAR const char *filesystemtype, unsigned long mountflags,
FAR const void *data)
{
int ret;
ret = nx_mount(source, target, filesystemtype, mountflags, data);
if (ret < 0)
{
set_errno(-ret);
ret = ERROR;
}
return ret;
}
+45 -22
View File
@@ -38,36 +38,32 @@
****************************************************************************/ ****************************************************************************/
/**************************************************************************** /****************************************************************************
* Name: umount2 * Name: nx_umount2
* *
* Description: * Description:
* umount() detaches the filesystem mounted at the path specified by * nx_umount2() is similar to the standard 'umount2' interface except that
* 'target.' * is not a cancellation point and it does not modify the errno variable.
*
* nx_umount2() is an internal NuttX interface and should not be called
* from applications.
* *
* Returned Value: * Returned Value:
* Zero is returned on success; -1 is returned on an error and errno is * Zero is returned on success; a negated value is returned on any failure.
* set appropriately:
*
* EACCES A component of a path was not searchable or mounting a read-only
* filesystem was attempted without giving the MS_RDONLY flag.
* EBUSY The target could not be unmounted because it is busy.
* EFAULT The pointer argument points outside the user address space.
* *
****************************************************************************/ ****************************************************************************/
int umount2(FAR const char *target, unsigned int flags) int nx_umount2(FAR const char *target, unsigned int flags)
{ {
FAR struct inode *mountpt_inode; FAR struct inode *mountpt_inode;
FAR struct inode *blkdrvr_inode = NULL; FAR struct inode *blkdrvr_inode = NULL;
struct inode_search_s desc; struct inode_search_s desc;
int errcode = OK;
int ret; int ret;
/* Verify required pointer arguments */ /* Verify required pointer arguments */
if (!target) if (!target)
{ {
errcode = EFAULT; ret = -EFAULT;
goto errout; goto errout;
} }
@@ -78,7 +74,6 @@ int umount2(FAR const char *target, unsigned int flags)
ret = inode_find(&desc); ret = inode_find(&desc);
if (ret < 0) if (ret < 0)
{ {
errcode = ENOENT;
goto errout_with_search; goto errout_with_search;
} }
@@ -91,7 +86,7 @@ int umount2(FAR const char *target, unsigned int flags)
if (!INODE_IS_MOUNTPT(mountpt_inode)) if (!INODE_IS_MOUNTPT(mountpt_inode))
{ {
errcode = EINVAL; ret = -EINVAL;
goto errout_with_mountpt; goto errout_with_mountpt;
} }
@@ -103,7 +98,7 @@ int umount2(FAR const char *target, unsigned int flags)
{ {
/* The filesystem does not support the unbind operation ??? */ /* The filesystem does not support the unbind operation ??? */
errcode = EINVAL; ret = -EINVAL;
goto errout_with_mountpt; goto errout_with_mountpt;
} }
@@ -117,7 +112,6 @@ int umount2(FAR const char *target, unsigned int flags)
ret = inode_semtake(); ret = inode_semtake();
if (ret < 0) if (ret < 0)
{ {
errcode = -ret;
goto errout_with_mountpt; goto errout_with_mountpt;
} }
@@ -127,12 +121,11 @@ int umount2(FAR const char *target, unsigned int flags)
{ {
/* The inode is unhappy with the blkdrvr for some reason */ /* The inode is unhappy with the blkdrvr for some reason */
errcode = -ret;
goto errout_with_semaphore; goto errout_with_semaphore;
} }
else if (ret > 0) else if (ret > 0)
{ {
errcode = EBUSY; ret = -EBUSY;
goto errout_with_semaphore; goto errout_with_semaphore;
} }
@@ -171,7 +164,6 @@ int umount2(FAR const char *target, unsigned int flags)
if (ret != OK && ret != -EBUSY) if (ret != OK && ret != -EBUSY)
{ {
errcode = -ret;
goto errout_with_mountpt; goto errout_with_mountpt;
} }
@@ -209,6 +201,37 @@ errout_with_search:
RELEASE_SEARCH(&desc); RELEASE_SEARCH(&desc);
errout: errout:
set_errno(errcode); return ret;
return ERROR; }
/****************************************************************************
* Name: umount2
*
* Description:
* umount() detaches the filesystem mounted at the path specified by
* 'target.'
*
* Returned Value:
* Zero is returned on success; -1 is returned on an error and errno is
* set appropriately:
*
* EACCES A component of a path was not searchable or mounting a read-only
* filesystem was attempted without giving the MS_RDONLY flag.
* EBUSY The target could not be unmounted because it is busy.
* EFAULT The pointer argument points outside the user address space.
*
****************************************************************************/
int umount2(FAR const char *target, unsigned int flags)
{
int ret;
ret = nx_umount2(target, flags);
if (ret < 0)
{
set_errno(-ret);
ret = ERROR;
}
return ret;
} }
+44
View File
@@ -188,6 +188,10 @@
#define OPEN_SETFD(f) ((f) | OPEN_MAGIC) #define OPEN_SETFD(f) ((f) | OPEN_MAGIC)
#define OPEN_GETFD(r) ((r) & OPEN_MASK) #define OPEN_GETFD(r) ((r) & OPEN_MASK)
/* nx_umount() is equivalent to nx_umount2() with flags = 0 */
#define umount(t) umount2(t,0)
/**************************************************************************** /****************************************************************************
* Public Type Definitions * Public Type Definitions
****************************************************************************/ ****************************************************************************/
@@ -678,6 +682,46 @@ int register_mtdpartition(FAR const char *partition,
int unregister_mtddriver(FAR const char *path); int unregister_mtddriver(FAR const char *path);
#endif #endif
/****************************************************************************
* Name: nx_mount
*
* Description:
* nx_mount() is similar to the standard 'mount' interface except that is
* not a cancellation point and it does not modify the errno variable.
*
* nx_mount() is an internal NuttX interface and should not be called from
* applications.
*
* Returned Value:
* Zero is returned on success; a negated value is returned on any failure.
*
****************************************************************************/
#ifndef CONFIG_DISABLE_MOUNTPOINT
int nx_mount(FAR const char *source, FAR const char *target,
FAR const char *filesystemtype, unsigned long mountflags,
FAR const void *data);
#endif
/****************************************************************************
* Name: nx_umount2
*
* Description:
* nx_umount2() is similar to the standard 'umount2' interface except that
* is not a cancellation point and it does not modify the errno variable.
*
* nx_umount2() is an internal NuttX interface and should not be called
* from applications.
*
* Returned Value:
* Zero is returned on success; a negated value is returned on any failure.
*
****************************************************************************/
#ifndef CONFIG_DISABLE_MOUNTPOINT
int nx_umount2(FAR const char *target, unsigned int flags);
#endif
/**************************************************************************** /****************************************************************************
* Name: files_initlist * Name: files_initlist
* *
+1 -1
View File
@@ -81,7 +81,7 @@
#define MNT_EXPIRE (1 << 2) #define MNT_EXPIRE (1 << 2)
#define UMOUNT_NOFOLLOW (0) #define UMOUNT_NOFOLLOW (0)
/* mount() is equivalent to umount2() with flags = 0 */ /* umount() is equivalent to umount2() with flags = 0 */
#define umount(t) umount2(t,0) #define umount(t) umount2(t,0)