mirror of
				https://github.com/eledio-devices/thirdparty-littlefs.git
				synced 2025-10-31 00:32:38 +01:00 
			
		
		
		
	Added support for handling corrupted blocks
This provides a limited form of wear leveling. While wear is not actually balanced across blocks, the filesystem can recover from corrupted blocks and extend the lifetime of a device nearly as much as dynamic wear leveling. For use-cases where wear is important, it would be better to use a full form of dynamic wear-leveling at the block level. (or consider a logging filesystem). Corrupted block handling was simply added on top of the existing logic in place for the filesystem, so it's a bit more noodly than it may have to be, but it gets the work done.
This commit is contained in:
		
							
								
								
									
										9
									
								
								lfs.h
									
									
									
									
									
								
							
							
						
						
									
										9
									
								
								lfs.h
									
									
									
									
									
								
							| @@ -43,7 +43,7 @@ enum lfs_error { | ||||
| enum lfs_type { | ||||
|     LFS_TYPE_REG        = 0x01, | ||||
|     LFS_TYPE_DIR        = 0x02, | ||||
|     LFS_TYPE_SUPERBLOCK = 0x10, | ||||
|     LFS_TYPE_SUPERBLOCK = 0x12, | ||||
| }; | ||||
|  | ||||
| enum lfs_open_flags { | ||||
| @@ -193,15 +193,16 @@ typedef struct lfs_superblock { | ||||
|     struct lfs_disk_superblock { | ||||
|         uint16_t type; | ||||
|         uint16_t len; | ||||
|         lfs_block_t root[2]; | ||||
|         uint32_t version; | ||||
|         char magic[8]; | ||||
|         uint32_t block_size; | ||||
|         uint32_t block_count; | ||||
|         lfs_block_t root[2]; | ||||
|     } d; | ||||
| } lfs_superblock_t; | ||||
|  | ||||
| typedef struct lfs_free { | ||||
|     lfs_block_t end; | ||||
|     lfs_block_t start; | ||||
|     lfs_block_t off; | ||||
|     uint32_t *lookahead; | ||||
| @@ -212,8 +213,8 @@ typedef struct lfs { | ||||
|     const struct lfs_config *cfg; | ||||
|  | ||||
|     lfs_block_t root[2]; | ||||
|     lfs_dir_t *scratch; | ||||
|     lfs_file_t *files; | ||||
|     bool deorphaned; | ||||
|  | ||||
|     lfs_cache_t rcache; | ||||
|     lfs_cache_t pcache; | ||||
| @@ -257,8 +258,8 @@ int lfs_file_rewind(lfs_t *lfs, lfs_file_t *file); | ||||
| lfs_soff_t lfs_file_size(lfs_t *lfs, lfs_file_t *file); | ||||
|  | ||||
| // miscellaneous lfs specific operations | ||||
| int lfs_deorphan(lfs_t *lfs); | ||||
| int lfs_traverse(lfs_t *lfs, int (*cb)(void*, lfs_block_t), void *data); | ||||
| int lfs_deorphan(lfs_t *lfs); | ||||
|  | ||||
|  | ||||
| #endif | ||||
|   | ||||
		Reference in New Issue
	
	Block a user