1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-01-18 12:52:44 +01:00

vfs: do not umount fs which is not mounted

This commit is contained in:
Vincent Dupont 2018-01-02 18:36:47 +01:00
parent 5ede5db234
commit d5bce2440b

View File

@ -425,7 +425,7 @@ static int check_mount(vfs_mount_t *mountp)
DEBUG("vfs_mount: -> \"%s\" (%p), %p\n",
mountp->mount_point, (void *)mountp->mount_point, mountp->private_data);
if (mountp->mount_point[0] != '/') {
DEBUG("vfs_mount: not absolute mount_point path\n");
DEBUG("vfs: check_mount: not absolute mount_point path\n");
return -EINVAL;
}
mountp->mount_point_len = strlen(mountp->mount_point);
@ -435,7 +435,7 @@ static int check_mount(vfs_mount_t *mountp)
if (found != NULL) {
/* Same mount is already mounted */
mutex_unlock(&_mount_mutex);
DEBUG("vfs_mount: Already mounted\n");
DEBUG("vfs: check_mount: Already mounted\n");
return -EBUSY;
}
@ -491,10 +491,19 @@ int vfs_mount(vfs_mount_t *mountp)
int vfs_umount(vfs_mount_t *mountp)
{
DEBUG("vfs_umount: %p\n", (void *)mountp);
if ((mountp == NULL) || (mountp->mount_point == NULL)) {
int ret = check_mount(mountp);
switch (ret) {
case 0:
DEBUG("vfs_umount: not mounted\n");
mutex_unlock(&_mount_mutex);
return -EINVAL;
case -EBUSY:
/* -EBUSY returned when fs is mounted, just continue */
break;
default:
DEBUG("vfs_umount: invalid fs\n");
return -EINVAL;
}
mutex_lock(&_mount_mutex);
DEBUG("vfs_umount: -> \"%s\" open=%d\n", mountp->mount_point, atomic_load(&mountp->open_files));
if (atomic_load(&mountp->open_files) > 0) {
mutex_unlock(&_mount_mutex);