mirror of
				https://github.com/eledio-devices/thirdparty-littlefs.git
				synced 2025-10-31 16:14:16 +01:00 
			
		
		
		
	Cleaned up attributes and related logic
The biggest change here is to make littlefs less obsessed with the lfs_mattr_t struct. It was limiting our flexibility and can be entirely replaced by passing the tag + data explicitly. The remaining use of lfs_mattr_t is specific to the commit logic, where it replaces the lfs_mattrlist_t struct. Other changes: - Added global lfs_diskoff struct for embedding disk references inside the lfs_mattr_t. - Reordered lfs_mattrlist_t to squeeze out some code savings - Added commit_get for explicit access to entries from unfinished metadata-pairs - Parameterized the "stop_at_commit" flag instead of hackily storing it in the lfs_mdir_t temporarily - Changed return value of lfs_pred to error-only with ENOENT representing a missing predecessor - Adopted const where possible
This commit is contained in:
		
							
								
								
									
										36
									
								
								lfs.h
									
									
									
									
									
								
							
							
						
						
									
										36
									
								
								lfs.h
									
									
									
									
									
								
							| @@ -118,7 +118,7 @@ enum lfs_type { | |||||||
|     // internal chip sources |     // internal chip sources | ||||||
|     LFS_FROM_REGION         = 0x000, |     LFS_FROM_REGION         = 0x000, | ||||||
|     LFS_FROM_DISK           = 0x200, |     LFS_FROM_DISK           = 0x200, | ||||||
|     LFS_FROM_DIR            = 0x030, |     LFS_FROM_MOVE           = 0x030, | ||||||
| }; | }; | ||||||
|  |  | ||||||
| // File open flags | // File open flags | ||||||
| @@ -263,32 +263,11 @@ struct lfs_attr { | |||||||
|  |  | ||||||
| /// littlefs data structures /// | /// littlefs data structures /// | ||||||
| typedef struct lfs_mattr { | typedef struct lfs_mattr { | ||||||
|  |     struct lfs_mattr *next; | ||||||
|     int32_t tag; |     int32_t tag; | ||||||
|     union { |     const void *buffer; | ||||||
|         void *buffer; |  | ||||||
|         lfs_block_t pair[2]; |  | ||||||
|         struct { |  | ||||||
|             lfs_block_t head; |  | ||||||
|             lfs_size_t size; |  | ||||||
|         } ctz; |  | ||||||
|         struct { |  | ||||||
|             lfs_block_t block; |  | ||||||
|             lfs_off_t off; |  | ||||||
|         } d; |  | ||||||
|         struct lfs_mdir *dir; |  | ||||||
|     } u; |  | ||||||
| } lfs_mattr_t; | } lfs_mattr_t; | ||||||
|  |  | ||||||
| typedef struct lfs_mattrlist { |  | ||||||
|     lfs_mattr_t e; |  | ||||||
|     struct lfs_mattrlist *next; |  | ||||||
| } lfs_mattrlist_t; |  | ||||||
|  |  | ||||||
| //typedef struct lfs_entry { |  | ||||||
| //    lfs_block_t pair[2]; |  | ||||||
| //    uint16_t id; |  | ||||||
| //} lfs_entry_t; |  | ||||||
|  |  | ||||||
| typedef struct lfs_globals { | typedef struct lfs_globals { | ||||||
|     struct lfs_move { |     struct lfs_move { | ||||||
|         lfs_block_t pair[2]; |         lfs_block_t pair[2]; | ||||||
| @@ -305,7 +284,6 @@ typedef struct lfs_mdir { | |||||||
|     uint16_t count; |     uint16_t count; | ||||||
|     bool erased; |     bool erased; | ||||||
|     bool split; |     bool split; | ||||||
|     bool stop_at_commit; // TODO hmmm |  | ||||||
|     lfs_globals_t globals; |     lfs_globals_t globals; | ||||||
| } lfs_mdir_t; | } lfs_mdir_t; | ||||||
|  |  | ||||||
| @@ -319,8 +297,10 @@ typedef struct lfs_file { | |||||||
|     struct lfs_file *next; |     struct lfs_file *next; | ||||||
|     lfs_block_t pair[2]; |     lfs_block_t pair[2]; | ||||||
|     uint16_t id; |     uint16_t id; | ||||||
|     lfs_block_t head; |     struct lfs_ctz { | ||||||
|     lfs_size_t size; |         lfs_block_t head; | ||||||
|  |         lfs_size_t size; | ||||||
|  |     } ctz; | ||||||
|  |  | ||||||
|     uint32_t flags; |     uint32_t flags; | ||||||
|     lfs_off_t pos; |     lfs_off_t pos; | ||||||
| @@ -328,7 +308,7 @@ typedef struct lfs_file { | |||||||
|     lfs_off_t off; |     lfs_off_t off; | ||||||
|     lfs_cache_t cache; |     lfs_cache_t cache; | ||||||
|  |  | ||||||
|     lfs_mattrlist_t *attrs; |     lfs_mattr_t *attrs; | ||||||
| } lfs_file_t; | } lfs_file_t; | ||||||
|  |  | ||||||
| typedef struct lfs_dir { | typedef struct lfs_dir { | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user