diff options
author | Christopher Haster <chaster@utexas.edu> | 2017-11-16 23:53:45 +0300 |
---|---|---|
committer | Christopher Haster <chaster@utexas.edu> | 2017-11-16 23:53:45 +0300 |
commit | 6664723e18034b3685d7d56374ec53b66cfcf47d (patch) | |
tree | f1382d1c126e0222d5ced794395d40b52e0de515 /lfs.c | |
parent | 3f31c8cba31e0f6cef5b02dba2e050d8df1168b7 (diff) |
Fixed issue with committing directories to bad-blocks that are stuck
This is only an issue in the weird case that are worn down block is
left in the odd state of not being able to change the data that resides
on the block. That being said, this does pop up often when simulating
wear on block devices.
Currently, directory commits checked if the write succeeded by crcing the
block to avoid the additional RAM cost for another buffer. However,
before this commit, directory commits just checked if the block crc was
valid, rather than comparing to the expected crc. This would usually
work, unless the block was stuck in a state with valid crc.
The fix is to simply compare with the expected crc to find errors.
Diffstat (limited to 'lfs.c')
-rw-r--r-- | lfs.c | 9 |
1 files changed, 5 insertions, 4 deletions
@@ -531,18 +531,19 @@ static int lfs_dir_commit(lfs_t *lfs, lfs_dir_t *dir, } // successful commit, check checksum to make sure - crc = 0xffffffff; + uint32_t ncrc = 0xffffffff; err = lfs_bd_crc(lfs, dir->pair[0], 0, - 0x7fffffff & dir->d.size, &crc); + (0x7fffffff & dir->d.size)-4, &ncrc); if (err) { return err; } - if (crc == 0) { - break; + if (ncrc != crc) { + goto relocate; } } + break; relocate: //commit was corrupted LFS_DEBUG("Bad block at %d", dir->pair[0]); |