Skip to content

Commit 09dd8c7

Browse files
manuarguecarlescufi
authored andcommitted
littlefs: translate error code when mount fails
When lfs mount fails and there is no formatting requested, the return code must be translated to errno before being passed to the application layer. Additionally, only log a warning that the FS will be formatted, when the system is not read-only. Fixes #56378 Signed-off-by: Manuel Arguelles <[email protected]>
1 parent a0ffaa7 commit 09dd8c7

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

subsys/fs/littlefs_fs.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -855,8 +855,8 @@ static int littlefs_mount(struct fs_mount_t *mountp)
855855
ret = lfs_mount(&fs->lfs, &fs->cfg);
856856
if (ret < 0 &&
857857
(mountp->flags & FS_MOUNT_FLAG_NO_FORMAT) == 0) {
858-
LOG_WRN("can't mount (LFS %d); formatting", ret);
859858
if ((mountp->flags & FS_MOUNT_FLAG_READ_ONLY) == 0) {
859+
LOG_WRN("can't mount (LFS %d); formatting", ret);
860860
ret = lfs_format(&fs->lfs, &fs->cfg);
861861
if (ret < 0) {
862862
LOG_ERR("format failed (LFS %d)", ret);
@@ -875,6 +875,9 @@ static int littlefs_mount(struct fs_mount_t *mountp)
875875
ret = lfs_to_errno(ret);
876876
goto out;
877877
}
878+
} else {
879+
ret = lfs_to_errno(ret);
880+
goto out;
878881
}
879882

880883
LOG_INF("%s mounted", mountp->mnt_point);

tests/subsys/fs/common/test_fs_mkfs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ void test_fs_mkfs_simple(void)
2626
ret = fs_mount(fs_mkfs_mp);
2727

2828
if (fs_mkfs_mp->type == FS_LITTLEFS) {
29-
zassert_equal(ret, -EILSEQ, "Expected EILSEQ got %d", ret);
29+
zassert_equal(ret, -EFAULT, "Expected EFAULT got %d", ret);
3030
} else if (fs_mkfs_mp->type == FS_FATFS) {
3131
zassert_equal(ret, -ENODEV, "Expected ENODEV got %d", ret);
3232
}

0 commit comments

Comments
 (0)