Merge pull request #9406 from geky/littlefs-validate-all-dirs

Extended mount to check all metadata-pairs
pull/9428/head
Martin Kojtal 2019-01-18 11:34:38 +01:00 committed by GitHub
commit 6c6ebc6b80
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 13 additions and 1 deletions

View File

@ -2206,6 +2206,10 @@ int lfs_mount(lfs_t *lfs, const struct lfs_config *cfg) {
lfs->root[0] = superblock.d.root[0];
lfs->root[1] = superblock.d.root[1];
if (lfs_paircmp(lfs->root, dir.d.tail) != 0) {
err = LFS_ERR_CORRUPT;
goto cleanup;
}
}
if (err || memcmp(superblock.d.magic, "littlefs", 8) != 0) {
@ -2223,10 +2227,18 @@ int lfs_mount(lfs_t *lfs, const struct lfs_config *cfg) {
goto cleanup;
}
// verify that no metadata pairs are corrupt
while (!lfs_pairisnull(dir.d.tail)) {
err = lfs_dir_fetch(lfs, &dir, dir.d.tail);
if (err) {
goto cleanup;
}
}
// succuessfully mounted
return 0;
cleanup:
lfs_deinit(lfs);
return err;
}