Skip to content

Commit 6c6ebc6

Browse files
authored
Merge pull request #9406 from geky/littlefs-validate-all-dirs
Extended mount to check all metadata-pairs
2 parents 40f40ac + 9d6e309 commit 6c6ebc6

File tree

1 file changed

+13
-1
lines changed
  • features/storage/filesystem/littlefs/littlefs

1 file changed

+13
-1
lines changed

features/storage/filesystem/littlefs/littlefs/lfs.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2206,6 +2206,10 @@ int lfs_mount(lfs_t *lfs, const struct lfs_config *cfg) {
22062206

22072207
lfs->root[0] = superblock.d.root[0];
22082208
lfs->root[1] = superblock.d.root[1];
2209+
if (lfs_paircmp(lfs->root, dir.d.tail) != 0) {
2210+
err = LFS_ERR_CORRUPT;
2211+
goto cleanup;
2212+
}
22092213
}
22102214

22112215
if (err || memcmp(superblock.d.magic, "littlefs", 8) != 0) {
@@ -2223,10 +2227,18 @@ int lfs_mount(lfs_t *lfs, const struct lfs_config *cfg) {
22232227
goto cleanup;
22242228
}
22252229

2230+
// verify that no metadata pairs are corrupt
2231+
while (!lfs_pairisnull(dir.d.tail)) {
2232+
err = lfs_dir_fetch(lfs, &dir, dir.d.tail);
2233+
if (err) {
2234+
goto cleanup;
2235+
}
2236+
}
2237+
2238+
// succuessfully mounted
22262239
return 0;
22272240

22282241
cleanup:
2229-
22302242
lfs_deinit(lfs);
22312243
return err;
22322244
}

0 commit comments

Comments
 (0)