mirror of
				https://github.com/eledio-devices/thirdparty-littlefs.git
				synced 2025-10-31 00:32:38 +01:00 
			
		
		
		
	Added optional block-level caching
This adds caching of the most recent read/program blocks, allowing support of devices that don't have byte-level read+writes, along with reduced device access on devices that do support byte-level read+writes. Note: The current implementation is a bit eager to drop caches where it simplifies the cache layer. This layer is already complex enough. Note: It may be worthwhile to add a compile switch for caching to reduce code size, note sure. Note: This does add a dependency on malloc, which could have a porting layer, but I'm just using the functions from stdlib for now. These can be overwritten with noops if the user controls the system, and keeps things simple for now.
This commit is contained in:
		
							
								
								
									
										13
									
								
								lfs.h
									
									
									
									
									
								
							
							
						
						
									
										13
									
								
								lfs.h
									
									
									
									
									
								
							| @@ -20,6 +20,7 @@ enum lfs_error { | ||||
|     LFS_ERROR_IS_DIR   = -7, | ||||
|     LFS_ERROR_INVALID  = -8, | ||||
|     LFS_ERROR_NO_SPACE = -9, | ||||
|     LFS_ERROR_NO_MEM   = -10, | ||||
| }; | ||||
|  | ||||
| enum lfs_type { | ||||
| @@ -74,6 +75,12 @@ struct lfs_config { | ||||
|  | ||||
|     // Number of erasable blocks on the device. | ||||
|     lfs_size_t block_count; | ||||
|  | ||||
|     // Optional, statically allocated read buffer. Must be read sized. | ||||
|     void *read_buffer; | ||||
|  | ||||
|     // Optional, statically allocated program buffer. Must be program sized. | ||||
|     void *prog_buffer; | ||||
| }; | ||||
|  | ||||
| // File info structure | ||||
| @@ -159,6 +166,12 @@ typedef struct lfs { | ||||
|         lfs_block_t end; | ||||
|     } free; | ||||
|  | ||||
|     struct { | ||||
|         lfs_block_t block; | ||||
|         lfs_off_t off; | ||||
|         uint8_t *buffer; | ||||
|     } rcache, pcache; | ||||
|  | ||||
|     uint32_t lookahead[LFS_CFG_LOOKAHEAD/32]; | ||||
| } lfs_t; | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user