mirror of
				https://github.com/eledio-devices/thirdparty-littlefs.git
				synced 2025-10-31 16:14:16 +01:00 
			
		
		
		
	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.
This commit is contained in:
		
							
								
								
									
										2
									
								
								lfs.c
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								lfs.c
									
									
									
									
									
								
							| @@ -1237,7 +1237,7 @@ relocate: | |||||||
|         // can't relocate superblock, filesystem is now frozen |         // can't relocate superblock, filesystem is now frozen | ||||||
|         if (lfs_pair_cmp(oldpair, (const lfs_block_t[2]){0, 1}) == 0) { |         if (lfs_pair_cmp(oldpair, (const lfs_block_t[2]){0, 1}) == 0) { | ||||||
|             LFS_WARN("Superblock %"PRIu32" has become unwritable", oldpair[1]); |             LFS_WARN("Superblock %"PRIu32" has become unwritable", oldpair[1]); | ||||||
|             return LFS_ERR_CORRUPT; |             return LFS_ERR_NOSPC; | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         // relocate half of pair |         // relocate half of pair | ||||||
|   | |||||||
| @@ -22,7 +22,7 @@ echo "--- Invalid superblocks ---" | |||||||
| ln -f -s /dev/zero blocks/0 | ln -f -s /dev/zero blocks/0 | ||||||
| ln -f -s /dev/zero blocks/1 | ln -f -s /dev/zero blocks/1 | ||||||
| tests/test.py << TEST | tests/test.py << TEST | ||||||
|     lfs_format(&lfs, &cfg) => LFS_ERR_CORRUPT; |     lfs_format(&lfs, &cfg) => LFS_ERR_NOSPC; | ||||||
| TEST | TEST | ||||||
| rm blocks/0 blocks/1 | rm blocks/0 blocks/1 | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user