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

View file

@ -246,32 +246,23 @@ mount_findfs(FAR const struct fsmap_t *fstab, FAR const char *filesystemtype)
****************************************************************************/
/****************************************************************************
* Name: mount
* Name: nx_mount
*
* Description:
* mount() attaches the filesystem specified by the 'source' block device
* name into the root file system at the path specified by 'target.'
* 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; -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
* Zero is returned on success; a negated value is returned on any failure.
*
****************************************************************************/
int mount(FAR const char *source, FAR const char *target,
FAR const char *filesystemtype, unsigned long mountflags,
FAR const void *data)
int nx_mount(FAR const char *source, FAR const char *target,
FAR const char *filesystemtype, unsigned long mountflags,
FAR const void *data)
{
#if defined(BDFS_SUPPORT) || defined(MDFS_SUPPORT) || defined(NODFS_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;
#endif
void *fshandle;
int errcode;
int ret;
/* Verify required pointer arguments */
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
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",
filesystemtype);
errcode = ENODEV;
ret = -ENODEV;
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",
filesystemtype);
errcode = ENODEV;
ret = -ENODEV;
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);
errcode = ENOTBLK;
ret = -ENOTBLK;
goto errout;
}
ret = inode_semtake();
if (ret < 0)
{
errcode = -ret;
goto errout_with_inode;
}
@ -369,7 +358,7 @@ int mount(FAR const char *source, FAR const char *target,
if (INODE_IS_SPECIAL(mountpt_inode))
{
ferr("ERROR: target %s exists and is a special node\n", target);
errcode = -ENOTDIR;
ret = -ENOTDIR;
inode_release(mountpt_inode);
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);
errcode = -ret;
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 ??? */
ferr("ERROR: Filesystem does not support bind\n");
errcode = EINVAL;
ret = -EINVAL;
goto errout_with_mountpt;
}
@ -453,7 +441,6 @@ int mount(FAR const char *source, FAR const char *target,
}
#endif
errcode = -ret;
goto errout_with_mountpt;
}
@ -510,13 +497,51 @@ errout_with_inode:
#endif
errout:
set_errno(errcode);
return ERROR;
return ret;
#else
ferr("ERROR: No filesystems enabled\n");
set_errno(ENOSYS);
return ERROR;
return -ENOSYS;
#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;
}

View file

@ -38,36 +38,32 @@
****************************************************************************/
/****************************************************************************
* Name: umount2
* Name: nx_umount2
*
* Description:
* umount() detaches the filesystem mounted at the path specified by
* 'target.'
* 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; -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.
* Zero is returned on success; a negated value is returned on any failure.
*
****************************************************************************/
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 *blkdrvr_inode = NULL;
struct inode_search_s desc;
int errcode = OK;
int ret;
/* Verify required pointer arguments */
if (!target)
{
errcode = EFAULT;
ret = -EFAULT;
goto errout;
}
@ -78,7 +74,6 @@ int umount2(FAR const char *target, unsigned int flags)
ret = inode_find(&desc);
if (ret < 0)
{
errcode = ENOENT;
goto errout_with_search;
}
@ -91,7 +86,7 @@ int umount2(FAR const char *target, unsigned int flags)
if (!INODE_IS_MOUNTPT(mountpt_inode))
{
errcode = EINVAL;
ret = -EINVAL;
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 ??? */
errcode = EINVAL;
ret = -EINVAL;
goto errout_with_mountpt;
}
@ -117,7 +112,6 @@ int umount2(FAR const char *target, unsigned int flags)
ret = inode_semtake();
if (ret < 0)
{
errcode = -ret;
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 */
errcode = -ret;
goto errout_with_semaphore;
}
else if (ret > 0)
{
errcode = EBUSY;
ret = -EBUSY;
goto errout_with_semaphore;
}
@ -171,7 +164,6 @@ int umount2(FAR const char *target, unsigned int flags)
if (ret != OK && ret != -EBUSY)
{
errcode = -ret;
goto errout_with_mountpt;
}
@ -209,6 +201,37 @@ errout_with_search:
RELEASE_SEARCH(&desc);
errout:
set_errno(errcode);
return ERROR;
return ret;
}
/****************************************************************************
* 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;
}

View file

@ -188,6 +188,10 @@
#define OPEN_SETFD(f) ((f) | OPEN_MAGIC)
#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
****************************************************************************/
@ -678,6 +682,46 @@ int register_mtdpartition(FAR const char *partition,
int unregister_mtddriver(FAR const char *path);
#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
*

View file

@ -81,7 +81,7 @@
#define MNT_EXPIRE (1 << 2)
#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)