Skip to content

Commit

Permalink
Merge pull request ARMmbed#76 from ARMmbed/fix-corrupt-read
Browse files Browse the repository at this point in the history
Add handling for corrupt as initial state of blocks
  • Loading branch information
geky authored Jul 18, 2018
2 parents 16318d0 + 041e90a commit 11ad3a2
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions lfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -417,11 +417,14 @@ static int lfs_dir_alloc(lfs_t *lfs, lfs_dir_t *dir) {
// rather than clobbering one of the blocks we just pretend
// the revision may be valid
int err = lfs_bd_read(lfs, dir->pair[0], 0, &dir->d.rev, 4);
dir->d.rev = lfs_fromle32(dir->d.rev);
if (err) {
if (err && err != LFS_ERR_CORRUPT) {
return err;
}

if (err != LFS_ERR_CORRUPT) {
dir->d.rev = lfs_fromle32(dir->d.rev);
}

// set defaults
dir->d.rev += 1;
dir->d.size = sizeof(dir->d)+4;
Expand All @@ -445,6 +448,9 @@ static int lfs_dir_fetch(lfs_t *lfs,
int err = lfs_bd_read(lfs, tpair[i], 0, &test, sizeof(test));
lfs_dir_fromle32(&test);
if (err) {
if (err == LFS_ERR_CORRUPT) {
continue;
}
return err;
}

Expand All @@ -464,6 +470,9 @@ static int lfs_dir_fetch(lfs_t *lfs,
err = lfs_bd_crc(lfs, tpair[i], sizeof(test),
(0x7fffffff & test.size) - sizeof(test), &crc);
if (err) {
if (err == LFS_ERR_CORRUPT) {
continue;
}
return err;
}

Expand Down

0 comments on commit 11ad3a2

Please sign in to comment.