Pass the umount2() flags to every unbind() implementation. That is where the the decision to umount or not will be made.

This commit is contained in:
Gregory Nutt 2015-03-14 17:22:02 -06:00
parent f932b26db1
commit 8055ba4d03
10 changed files with 78 additions and 37 deletions

View File

@ -1,7 +1,7 @@
/****************************************************************************
* fs/binfs/fs_binfs.c
*
* Copyright (C) 2011-2013 Gregory Nutt. All rights reserved.
* Copyright (C) 2011-2013, 2015 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@ -370,7 +370,8 @@ static int binfs_bind(FAR struct inode *blkdriver, const void *data,
*
****************************************************************************/
static int binfs_unbind(void *handle, FAR struct inode **blkdriver)
static int binfs_unbind(FAR void *handle, FAR struct inode **blkdriver,
unsigned int flags)
{
fvdbg("Entry\n");
return OK;

View File

@ -1,7 +1,7 @@
/****************************************************************************
* fs/fat/fs_fat32.c
*
* Copyright (C) 2007-2009, 2011-2014 Gregory Nutt. All rights reserved.
* Copyright (C) 2007-2009, 2011-2015 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* References:
@ -97,7 +97,8 @@ static int fat_rewinddir(struct inode *mountpt, struct fs_dirent_s *dir);
static int fat_bind(FAR struct inode *blkdriver, const void *data,
void **handle);
static int fat_unbind(void *handle, FAR struct inode **blkdriver);
static int fat_unbind(void *handle, FAR struct inode **blkdriver,
unsigned int flags);
static int fat_statfs(struct inode *mountpt, struct statfs *buf);
static int fat_unlink(struct inode *mountpt, const char *relpath);
@ -116,7 +117,7 @@ static int fat_stat(struct inode *mountpt, const char *relpath, struct stat
* Public Variables
****************************************************************************/
/* See fs_mount.c -- this structure is explicitly externed there.
/* See fs_mount.c -- this structure is explicitly extern'ed there.
* We use the old-fashioned kind of initializers so that this will compile
* with any compiler.
*/
@ -197,7 +198,7 @@ static int fat_open(FAR struct file *filep, const char *relpath,
ret = fat_finddirentry(fs, &dirinfo, relpath);
/* Three possibililities: (1) a node exists for the relpath and
/* Three possibilities: (1) a node exists for the relpath and
* dirinfo describes the directory entry of the entity, (2) the
* node does not exist, or (3) some error occurred.
*/
@ -1795,7 +1796,8 @@ static int fat_bind(FAR struct inode *blkdriver, const void *data,
*
****************************************************************************/
static int fat_unbind(void *handle, FAR struct inode **blkdriver)
static int fat_unbind(FAR void *handle, FAR struct inode **blkdriver,
unsigned int flags)
{
struct fat_mountpt_s *fs = (struct fat_mountpt_s*)handle;
int ret;
@ -1811,9 +1813,13 @@ static int fat_unbind(void *handle, FAR struct inode **blkdriver)
fat_semtake(fs);
if (fs->fs_head)
{
/* We cannot unmount now.. there are open files */
/* We cannot unmount now.. there are open files
*
* This implementation currently only supports unmounting if there are
* no open file references.
*/
ret = -EBUSY;
ret = (flags != 0) ? -ENOSYS : -EBUSY;
}
else
{

View File

@ -92,7 +92,7 @@ int umount2(FAR const char *target, unsigned int flags)
FAR struct inode *mountpt_inode;
FAR struct inode *blkdrvr_inode = NULL;
int errcode = OK;
int status;
int ret;
/* Verify required pointer arguments */
@ -137,15 +137,16 @@ int umount2(FAR const char *target, unsigned int flags)
*/
inode_semtake(); /* Hold the semaphore through the unbind logic */
status = mountpt_inode->u.i_mops->unbind( mountpt_inode->i_private, &blkdrvr_inode);
if (status < 0)
ret = mountpt_inode->u.i_mops->unbind(mountpt_inode->i_private,
&blkdrvr_inode, flags);
if (ret < 0)
{
/* The inode is unhappy with the blkdrvr for some reason */
errcode = -status;
errcode = -ret;
goto errout_with_semaphore;
}
else if (status > 0)
else if (ret > 0)
{
errcode = EBUSY;
goto errout_with_semaphore;
@ -160,16 +161,16 @@ int umount2(FAR const char *target, unsigned int flags)
* there is still at least reference on it (from the mount)
*/
status = inode_remove(target);
ret = inode_remove(target);
inode_semgive();
/* The return value of -EBUSY is normal (in fact, it should
* not be OK)
*/
if (status != OK && status != -EBUSY)
if (ret != OK && ret != -EBUSY)
{
errcode = -status;
errcode = -ret;
goto errout_with_mountpt;
}

View File

@ -1,7 +1,7 @@
/****************************************************************************
* fs/nfs/nfs_vfsops.c
*
* Copyright (C) 2012-2013 Gregory Nutt. All rights reserved.
* Copyright (C) 2012-2013, 2015 Gregory Nutt. All rights reserved.
* Copyright (C) 2012 Jose Pablo Rojas Vargas. All rights reserved.
* Author: Jose Pablo Rojas Vargas <jrojas@nx-engineering.com>
* Gregory Nutt <gnutt@nuttx.org>
@ -144,7 +144,8 @@ static void nfs_decode_args(FAR struct nfs_mount_parameters *nprmt,
FAR struct nfs_args *argp);
static int nfs_bind(FAR struct inode *blkdriver, const void *data,
void **handle);
static int nfs_unbind(void *handle, FAR struct inode **blkdriver);
static int nfs_unbind(void *handle, FAR struct inode **blkdriver.
unsigned int flags);
static int nfs_statfs(struct inode *mountpt, struct statfs *buf);
static int nfs_remove(struct inode *mountpt, const char *relpath);
static int nfs_mkdir(struct inode *mountpt, const char *relpath,
@ -1872,7 +1873,8 @@ bad:
*
****************************************************************************/
int nfs_unbind(FAR void *handle, FAR struct inode **blkdriver)
int nfs_unbind(FAR void *handle, FAR struct inode **blkdriver,
unsigned int flags)
{
FAR struct nfsmount *nmp = (FAR struct nfsmount *)handle;
int error;
@ -1893,7 +1895,12 @@ int nfs_unbind(FAR void *handle, FAR struct inode **blkdriver)
if (nmp->nm_head != NULL)
{
fdbg("ERROR; There are open files: %p\n", nmp->nm_head);
error = EBUSY;
/* This implementation currently only supports unmounting if there are
* no open file references.
*/
error = (flags != 0) ? ENOSYS : EBUSY;
goto errout_with_semaphore;
}

View File

@ -1,7 +1,7 @@
/****************************************************************************
* fs/nxffs/nxffs.h
*
* Copyright (C) 2011, 2013 Gregory Nutt. All rights reserved.
* Copyright (C) 2011, 2013, 2015 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* References: Linux/Documentation/filesystems/romfs.txt
@ -1098,7 +1098,8 @@ int nxffs_readdir(FAR struct inode *mountpt, FAR struct fs_dirent_s *dir);
int nxffs_rewinddir(FAR struct inode *mountpt, FAR struct fs_dirent_s *dir);
int nxffs_bind(FAR struct inode *blkdriver, FAR const void *data,
FAR void **handle);
int nxffs_unbind(FAR void *handle, FAR struct inode **blkdriver);
int nxffs_unbind(FAR void *handle, FAR struct inode **blkdriver,
unsigned int flags);
int nxffs_statfs(FAR struct inode *mountpt, FAR struct statfs *buf);
int nxffs_stat(FAR struct inode *mountpt, FAR const char *relpath,
FAR struct stat *buf);

View File

@ -1,7 +1,7 @@
/****************************************************************************
* fs/nxffs/nxffs_initialize.c
*
* Copyright (C) 2011, 2013 Gregory Nutt. All rights reserved.
* Copyright (C) 2011, 2013, 2015 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* References: Linux/Documentation/filesystems/romfs.txt
@ -550,11 +550,21 @@ int nxffs_bind(FAR struct inode *blkdriver, FAR const void *data,
*
****************************************************************************/
int nxffs_unbind(FAR void *handle, FAR struct inode **blkdriver)
int nxffs_unbind(FAR void *handle, FAR struct inode **blkdriver,
unsigned int flags)
{
#ifndef CONFIG_NXFFS_PREALLOCATED
# error "No design to support dynamic allocation of volumes"
#else
/* This implementation currently only supports unmounting if there are no
* open file references.
*/
if (flags != 0)
{
return -ENOSYS;
}
return g_volume.ofiles ? -EBUSY : OK;
#endif
}

View File

@ -1,7 +1,7 @@
/****************************************************************************
* fs/procfs/fs_procfs.c
*
* Copyright (C) 2013-2014 Gregory Nutt. All rights reserved.
* Copyright (C) 2013-2015 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@ -170,7 +170,8 @@ static int procfs_rewinddir(FAR struct inode *mountpt,
static int procfs_bind(FAR struct inode *blkdriver,
FAR const void *data, FAR void **handle);
static int procfs_unbind(FAR void *handle, FAR struct inode **blkdriver);
static int procfs_unbind(FAR void *handle, FAR struct inode **blkdriver,
unsigned int flags);
static int procfs_statfs(FAR struct inode *mountpt,
FAR struct statfs *buf);
@ -861,7 +862,8 @@ static int procfs_bind(FAR struct inode *blkdriver, const void *data,
*
****************************************************************************/
static int procfs_unbind(void *handle, FAR struct inode **blkdriver)
static int procfs_unbind(void *handle, FAR struct inode **blkdriver,
unsigned int flags)
{
return OK;
}

View File

@ -92,7 +92,8 @@ static int romfs_rewinddir(FAR struct inode *mountpt,
static int romfs_bind(FAR struct inode *blkdriver, FAR const void *data,
FAR void **handle);
static int romfs_unbind(FAR void *handle, FAR struct inode **blkdriver);
static int romfs_unbind(FAR void *handle, FAR struct inode **blkdriver,
unsigned int flags);
static int romfs_statfs(FAR struct inode *mountpt,
FAR struct statfs *buf);
@ -977,7 +978,8 @@ errout_with_sem:
*
****************************************************************************/
static int romfs_unbind(FAR void *handle, FAR struct inode **blkdriver)
static int romfs_unbind(FAR void *handle, FAR struct inode **blkdriver,
unsigned int flags)
{
FAR struct romfs_mountpt_s *rm = (FAR struct romfs_mountpt_s*)handle;
int ret;
@ -999,7 +1001,12 @@ static int romfs_unbind(FAR void *handle, FAR struct inode **blkdriver)
/* We cannot unmount now.. there are open files */
fdbg("There are open files\n");
ret = -EBUSY;
/* This implementation currently only supports unmounting if there are
* no open file references.
*/
ret = (flags != 0) ? -ENOSYS : -EBUSY;
}
else
{

View File

@ -93,7 +93,8 @@ static int smartfs_rewinddir(struct inode *mountpt, struct fs_dirent_s *dir)
static int smartfs_bind(FAR struct inode *blkdriver, const void *data,
void **handle);
static int smartfs_unbind(void *handle, FAR struct inode **blkdriver);
static int smartfs_unbind(void *handle, FAR struct inode **blkdriver,
unsigned int flags);
static int smartfs_statfs(struct inode *mountpt, struct statfs *buf);
static int smartfs_unlink(struct inode *mountpt, const char *relpath);
@ -1544,7 +1545,8 @@ static int smartfs_bind(FAR struct inode *blkdriver, const void *data,
*
****************************************************************************/
static int smartfs_unbind(void *handle, FAR struct inode **blkdriver)
static int smartfs_unbind(FAR void *handle, FAR struct inode **blkdriver,
unsigned int flags)
{
struct smartfs_mountpt_s *fs = (struct smartfs_mountpt_s*)handle;
int ret;
@ -1564,7 +1566,11 @@ static int smartfs_unbind(void *handle, FAR struct inode **blkdriver)
smartfs_semgive(fs);
ret = -EBUSY;
/* This implementation currently only supports unmounting if there are
* no open file references.
*/
return (flags != 0) ? -ENOSYS : -EBUSY;
}
else
{
@ -1575,7 +1581,6 @@ static int smartfs_unbind(void *handle, FAR struct inode **blkdriver)
smartfs_semgive(fs);
kmm_free(fs);
return ret;
}

View File

@ -1,7 +1,7 @@
/****************************************************************************
* include/nuttx/fs/fs.h
*
* Copyright (C) 2007-2009, 2011-2013 Gregory Nutt. All rights reserved.
* Copyright (C) 2007-2009, 2011-2013, 2015 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@ -196,7 +196,8 @@ struct mountpt_operations
int (*bind)(FAR struct inode *blkdriver, FAR const void *data,
FAR void **handle);
int (*unbind)(FAR void *handle, FAR struct inode **blkdriver);
int (*unbind)(FAR void *handle, FAR struct inode **blkdriver,
unsigned int flags);
int (*statfs)(FAR struct inode *mountpt, FAR struct statfs *buf);
/* Operations on paths */