mirror of
				https://github.com/eledio-devices/thirdparty-littlefs.git
				synced 2025-10-31 08:42:40 +01:00 
			
		
		
		
	Squished in-flight files/dirs into single list
This is an effort to try to consolidate the handling of in-flight files and dirs opened by the user (and possibly opened internally). Both files and dirs have metadata state that need to be kept in sync by the commit logic. This metadata state is mostly contained in the lfs_mdir_t type, which is present in both the lfs_file_t and lfs_dir_t. Unfortunately both of these structs have some relatively unrelated metadata that needs to be kept in sync: - Files store an id representing the open file - Dirs store an id during iteration While these take up the same space, they unfortunately need to be managed differently by the commit logic. The best solution I can come up with is to simple store a general purpose list and tag both structures with LFS_TYPE_REG and LFS_TYPE_DIR respectively. This is kinda funky, but wins out over duplicated the commit logic.
This commit is contained in:
		
							
								
								
									
										45
									
								
								lfs.h
									
									
									
									
									
								
							
							
						
						
									
										45
									
								
								lfs.h
									
									
									
									
									
								
							| @@ -280,6 +280,12 @@ typedef struct lfs_mattr { | |||||||
|     const struct lfs_mattr *next; |     const struct lfs_mattr *next; | ||||||
| } lfs_mattr_t; | } lfs_mattr_t; | ||||||
|  |  | ||||||
|  | typedef struct lfs_cache { | ||||||
|  |     lfs_block_t block; | ||||||
|  |     lfs_off_t off; | ||||||
|  |     uint8_t *buffer; | ||||||
|  | } lfs_cache_t; | ||||||
|  |  | ||||||
| typedef union lfs_global { | typedef union lfs_global { | ||||||
|     uint16_t u16[5]; |     uint16_t u16[5]; | ||||||
| } lfs_global_t; | } lfs_global_t; | ||||||
| @@ -288,24 +294,37 @@ typedef struct lfs_mdir { | |||||||
|     lfs_block_t pair[2]; |     lfs_block_t pair[2]; | ||||||
|     lfs_block_t tail[2]; |     lfs_block_t tail[2]; | ||||||
|     uint32_t rev; |     uint32_t rev; | ||||||
|     lfs_off_t off; |  | ||||||
|     uint32_t etag; |     uint32_t etag; | ||||||
|  |     lfs_off_t off; | ||||||
|     uint16_t count; |     uint16_t count; | ||||||
|     bool erased; |     bool erased; | ||||||
|     bool split; |     bool split; | ||||||
|     lfs_global_t locals; |     lfs_global_t locals; | ||||||
| } lfs_mdir_t; | } lfs_mdir_t; | ||||||
|  |  | ||||||
| typedef struct lfs_cache { | typedef struct lfs_mlist { | ||||||
|     lfs_block_t block; |     struct lfs_mlist *next; | ||||||
|     lfs_off_t off; |     uint16_t id; | ||||||
|     uint8_t *buffer; |     uint8_t type; | ||||||
| } lfs_cache_t; |     lfs_mdir_t m; | ||||||
|  | } lfs_mlist_t; | ||||||
|  |  | ||||||
|  | typedef struct lfs_dir { | ||||||
|  |     struct lfs_dir *next; | ||||||
|  |     uint16_t id; | ||||||
|  |     uint8_t type; | ||||||
|  |     lfs_mdir_t m; | ||||||
|  |  | ||||||
|  |     lfs_off_t pos; | ||||||
|  |     lfs_block_t head[2]; | ||||||
|  | } lfs_dir_t; | ||||||
|  |  | ||||||
| typedef struct lfs_file { | typedef struct lfs_file { | ||||||
|     struct lfs_file *next; |     struct lfs_file *next; | ||||||
|     uint16_t id; |     uint16_t id; | ||||||
|     lfs_block_t pair[2]; |     uint8_t type; | ||||||
|  |     lfs_mdir_t m; | ||||||
|  |  | ||||||
|     struct lfs_ctz { |     struct lfs_ctz { | ||||||
|         lfs_block_t head; |         lfs_block_t head; | ||||||
|         lfs_size_t size; |         lfs_size_t size; | ||||||
| @@ -320,15 +339,6 @@ typedef struct lfs_file { | |||||||
|     const struct lfs_file_config *cfg; |     const struct lfs_file_config *cfg; | ||||||
| } lfs_file_t; | } lfs_file_t; | ||||||
|  |  | ||||||
| typedef struct lfs_dir { |  | ||||||
|     struct lfs_dir *next; |  | ||||||
|     uint16_t id; |  | ||||||
|     struct lfs_mdir m; |  | ||||||
|  |  | ||||||
|     lfs_block_t head[2]; |  | ||||||
|     lfs_off_t pos; |  | ||||||
| } lfs_dir_t; |  | ||||||
|  |  | ||||||
| typedef struct lfs_superblock { | typedef struct lfs_superblock { | ||||||
|     char magic[8]; |     char magic[8]; | ||||||
|     uint32_t version; |     uint32_t version; | ||||||
| @@ -355,8 +365,7 @@ typedef struct lfs { | |||||||
|     lfs_cache_t pcache; |     lfs_cache_t pcache; | ||||||
|  |  | ||||||
|     lfs_block_t root[2]; |     lfs_block_t root[2]; | ||||||
|     lfs_file_t *files; |     lfs_mlist_t *mlist; | ||||||
|     lfs_dir_t *dirs; |  | ||||||
|  |  | ||||||
|     lfs_global_t globals; |     lfs_global_t globals; | ||||||
|     lfs_global_t locals; |     lfs_global_t locals; | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user