mirror of
				https://github.com/eledio-devices/thirdparty-littlefs.git
				synced 2025-10-31 00:32:38 +01:00 
			
		
		
		
	Shoehorned in hacky implementation of inline files
Proof-of-concept implementation of inline files that stores the file's content directly in its parent's directory pair. Inline files are indicated by a different type stored in an entry's struct field, and take advantage of resizable entries. Where a normal file's entry would normally hold the reference to the CTZ skip-list, an inline file's entry contains the contents of the actual file. Unfortunately, storing the inline file on disk is the easy part. We also need to manage inline files in the internals of littlefs and provide the same operations that we do on normal files, all while reusing as much code as possible to avoid a significant increase in code cost. There is a relatively simple, though maybe a bit hacky, solution here. If a file fits entirely in a cache line, the file logic never actually has to go to disk. This means we can just give the file a "pretend" block (hopefully one that would assert if ever written to), and carry out file operations as normal, as long as we catch the file before it exceeds the cache line and write out the file to an actual disk.
This commit is contained in:
		
							
								
								
									
										28
									
								
								lfs.h
									
									
									
									
									
								
							
							
						
						
									
										28
									
								
								lfs.h
									
									
									
									
									
								
							| @@ -55,6 +55,10 @@ typedef uint32_t lfs_block_t; | ||||
| #define LFS_NAME_MAX 255 | ||||
| #endif | ||||
|  | ||||
| #ifndef LFS_INLINE_MAX | ||||
| #define LFS_INLINE_MAX 255 | ||||
| #endif | ||||
|  | ||||
| // Possible error codes, these are negative to allow | ||||
| // valid positive return values | ||||
| enum lfs_error { | ||||
| @@ -82,25 +86,27 @@ enum lfs_type { | ||||
|     // on disk structure | ||||
|     LFS_STRUCT_CTZ      = 0x10, | ||||
|     LFS_STRUCT_DIR      = 0x20, | ||||
|     LFS_STRUCT_INLINE   = 0x30, | ||||
|     LFS_STRUCT_MOVED    = 0x80, | ||||
| }; | ||||
|  | ||||
| // File open flags | ||||
| enum lfs_open_flags { | ||||
|     // open flags | ||||
|     LFS_O_RDONLY = 1,        // Open a file as read only | ||||
|     LFS_O_WRONLY = 2,        // Open a file as write only | ||||
|     LFS_O_RDWR   = 3,        // Open a file as read and write | ||||
|     LFS_O_CREAT  = 0x0100,   // Create a file if it does not exist | ||||
|     LFS_O_EXCL   = 0x0200,   // Fail if a file already exists | ||||
|     LFS_O_TRUNC  = 0x0400,   // Truncate the existing file to zero size | ||||
|     LFS_O_APPEND = 0x0800,   // Move to end of file on every write | ||||
|     LFS_O_RDONLY = 1,         // Open a file as read only | ||||
|     LFS_O_WRONLY = 2,         // Open a file as write only | ||||
|     LFS_O_RDWR   = 3,         // Open a file as read and write | ||||
|     LFS_O_CREAT  = 0x0100,    // Create a file if it does not exist | ||||
|     LFS_O_EXCL   = 0x0200,    // Fail if a file already exists | ||||
|     LFS_O_TRUNC  = 0x0400,    // Truncate the existing file to zero size | ||||
|     LFS_O_APPEND = 0x0800,    // Move to end of file on every write | ||||
|  | ||||
|     // internally used flags | ||||
|     LFS_F_DIRTY   = 0x10000, // File does not match storage | ||||
|     LFS_F_WRITING = 0x20000, // File has been written since last flush | ||||
|     LFS_F_READING = 0x40000, // File has been read since last flush | ||||
|     LFS_F_ERRED   = 0x80000, // An error occured during write | ||||
|     LFS_F_DIRTY   = 0x10000,  // File does not match storage | ||||
|     LFS_F_WRITING = 0x20000,  // File has been written since last flush | ||||
|     LFS_F_READING = 0x40000,  // File has been read since last flush | ||||
|     LFS_F_ERRED   = 0x80000,  // An error occured during write | ||||
|     LFS_F_INLINE  = 0x100000, // Currently inlined in directory entry | ||||
| }; | ||||
|  | ||||
| // File seek flags | ||||
|   | ||||
		Reference in New Issue
	
	Block a user