diff --git a/include/fs/fs.h b/include/fs/fs.h index 06543a700da..48bb13495aa 100644 --- a/include/fs/fs.h +++ b/include/fs/fs.h @@ -416,7 +416,9 @@ int fs_mount(struct fs_mount_t *mp); * @param mp Pointer to the fs_mount_t structure * * @retval 0 on success; - * @retval <0 negative errno code on error. + * @retval -EINVAL if no system has been mounted at given mount point; + * @retval -ENOTSUP when not supported by underlying file system driver; + * @retval <0 an other negative errno code on error. */ int fs_unmount(struct fs_mount_t *mp); diff --git a/subsys/fs/fs.c b/subsys/fs/fs.c index 4854d80fedf..6e6635d6bd3 100644 --- a/subsys/fs/fs.c +++ b/subsys/fs/fs.c @@ -657,16 +657,21 @@ int fs_unmount(struct fs_mount_t *mp) { int rc = -EINVAL; - if ((mp == NULL) || (mp->mnt_point == NULL) || - (strlen(mp->mnt_point) <= 1)) { - LOG_ERR("invalid mount point!!"); - return -EINVAL; + if (mp == NULL) { + return rc; } k_mutex_lock(&mutex, K_FOREVER); - if ((mp->fs == NULL) || mp->fs->unmount == NULL) { - LOG_ERR("fs ops functions not set!!"); - rc = -EINVAL; + + if (mp->fs == NULL) { + LOG_ERR("fs not mounted (mp == %p)", mp); + goto unmount_err; + } + + if (mp->fs->unmount == NULL) { + LOG_ERR("mount path %s is not unmountable", + log_strdup(mp->mnt_point)); + rc = -ENOTSUP; goto unmount_err; } diff --git a/tests/subsys/fs/fs_api/src/test_fs_dir_file.c b/tests/subsys/fs/fs_api/src/test_fs_dir_file.c index 5b83870f24e..99e379ec864 100644 --- a/tests/subsys/fs/fs_api/src/test_fs_dir_file.c +++ b/tests/subsys/fs/fs_api/src/test_fs_dir_file.c @@ -119,7 +119,7 @@ void test_unmount(void) TC_PRINT("\nunmount file system that has never been mounted:\n"); ret = fs_unmount(&test_fs_mnt_unsupported_fs); - zassert_not_equal(ret, 0, "Unmount a never mounted fs"); + zassert_equal(ret, -EINVAL, "Unmount a never mounted fs"); TC_PRINT("\nunmount file system multiple times:\n"); ret = fs_unmount(&test_fs_mnt_1); @@ -127,7 +127,7 @@ void test_unmount(void) test_fs_mnt_1.fs = &temp_fs; ret = fs_unmount(&test_fs_mnt_1); - zassert_not_equal(ret, 0, "Unmount a unmounted fs"); + zassert_equal(ret, -EINVAL, "Unmount a unmounted fs"); } /**