fs: fs_unmount will return -ENOTSUP if not implemented by driver

The commit changes error handling by fs_unmount; the function will
return -EINVAL if mount point, described by mp, is not mounted or
-ENNOTSUP when unmounting is not supported by the driver; in the second
case it will also log error.

Additionally to the above changes, checks for correct mnt_path and
mnt_path, within fs_unmount, have been removed as they are not needed;
only the fs_mount_t->fs pointer is needed to decide whether system is
mounted or not.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
This commit is contained in:
Dominik Ermel 2020-10-15 13:26:59 +00:00 committed by Carles Cufí
commit e7886c6634
3 changed files with 17 additions and 10 deletions

View file

@ -416,7 +416,9 @@ int fs_mount(struct fs_mount_t *mp);
* @param mp Pointer to the fs_mount_t structure * @param mp Pointer to the fs_mount_t structure
* *
* @retval 0 on success; * @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); int fs_unmount(struct fs_mount_t *mp);

View file

@ -657,16 +657,21 @@ int fs_unmount(struct fs_mount_t *mp)
{ {
int rc = -EINVAL; int rc = -EINVAL;
if ((mp == NULL) || (mp->mnt_point == NULL) || if (mp == NULL) {
(strlen(mp->mnt_point) <= 1)) { return rc;
LOG_ERR("invalid mount point!!");
return -EINVAL;
} }
k_mutex_lock(&mutex, K_FOREVER); k_mutex_lock(&mutex, K_FOREVER);
if ((mp->fs == NULL) || mp->fs->unmount == NULL) {
LOG_ERR("fs ops functions not set!!"); if (mp->fs == NULL) {
rc = -EINVAL; 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; goto unmount_err;
} }

View file

@ -119,7 +119,7 @@ void test_unmount(void)
TC_PRINT("\nunmount file system that has never been mounted:\n"); TC_PRINT("\nunmount file system that has never been mounted:\n");
ret = fs_unmount(&test_fs_mnt_unsupported_fs); 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"); TC_PRINT("\nunmount file system multiple times:\n");
ret = fs_unmount(&test_fs_mnt_1); ret = fs_unmount(&test_fs_mnt_1);
@ -127,7 +127,7 @@ void test_unmount(void)
test_fs_mnt_1.fs = &temp_fs; test_fs_mnt_1.fs = &temp_fs;
ret = fs_unmount(&test_fs_mnt_1); ret = fs_unmount(&test_fs_mnt_1);
zassert_not_equal(ret, 0, "Unmount a unmounted fs"); zassert_equal(ret, -EINVAL, "Unmount a unmounted fs");
} }
/** /**