Skip to content

Commit 4db96d4

Browse files
committed
Changed unwritable superblock to ENOSPC for consistency
While ECORRUPT is not a wrong error code, it doesn't match other instances of hitting a corrupt block during write. During writes, if blocks are detected as corrupt their data is evicted and moved to a new clean block. This means that at the end of a disk's lifetime, exhaustion errors will be reported as ENOSPC when littlefs can't find any new block to store the data. This has the benefit of matching behaviour when a new file is written and no more blocks can be found, due to either a small disk or corrupted blocks on disk. To littlefs it's like the disk shrinks in size over time.
1 parent a2532a3 commit 4db96d4

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

lfs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1237,7 +1237,7 @@ static int lfs_dir_compact(lfs_t *lfs,
12371237
// can't relocate superblock, filesystem is now frozen
12381238
if (lfs_pair_cmp(oldpair, (const lfs_block_t[2]){0, 1}) == 0) {
12391239
LFS_WARN("Superblock %"PRIu32" has become unwritable", oldpair[1]);
1240-
return LFS_ERR_CORRUPT;
1240+
return LFS_ERR_NOSPC;
12411241
}
12421242

12431243
// relocate half of pair

tests/test_format.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ echo "--- Invalid superblocks ---"
2222
ln -f -s /dev/zero blocks/0
2323
ln -f -s /dev/zero blocks/1
2424
tests/test.py << TEST
25-
lfs_format(&lfs, &cfg) => LFS_ERR_CORRUPT;
25+
lfs_format(&lfs, &cfg) => LFS_ERR_NOSPC;
2626
TEST
2727
rm blocks/0 blocks/1
2828

0 commit comments

Comments
 (0)