mirror of
				https://github.com/eledio-devices/thirdparty-littlefs.git
				synced 2025-10-31 16:14:16 +01:00 
			
		
		
		
	In writing the initial allocator, I ran into the rather difficult problem of trying to iterate through the entire filesystem cheaply and with only constant memory consumption (which prohibits recursive functions). The solution was to simply thread all directory blocks onto a massive linked-list that spans the entire filesystem. With the linked-list it was easy to create a traverse function for all blocks in use on the filesystem (which has potential for other utility), and add the rudimentary block allocator using a bit-vector. While the linked-list may add complexity (especially where needing to maintain atomic operations), the linked-list helps simplify what is currently the most expensive operation in the filesystem, with no cost to space (the linked-list can reuse the pointers used for chained directory blocks).
		
			
				
	
	
		
			39 lines
		
	
	
		
			794 B
		
	
	
	
		
			C
		
	
	
	
	
	
			
		
		
	
	
			39 lines
		
	
	
		
			794 B
		
	
	
	
		
			C
		
	
	
	
	
	
| /*
 | |
|  * Configuration and type definitions
 | |
|  *
 | |
|  * Copyright (c) 2017 Christopher Haster
 | |
|  * Distributed under the MIT license
 | |
|  */
 | |
| #ifndef LFS_CONFIG_H
 | |
| #define LFS_CONFIG_H
 | |
| 
 | |
| #include <stdint.h>
 | |
| 
 | |
| // Type definitions
 | |
| typedef uint32_t lfs_size_t;
 | |
| typedef uint32_t lfs_off_t;
 | |
| 
 | |
| typedef int32_t  lfs_ssize_t;
 | |
| typedef int32_t  lfs_soff_t;
 | |
| 
 | |
| typedef uint32_t lfs_block_t;
 | |
| 
 | |
| // Maximum length of file name
 | |
| #ifndef LFS_NAME_MAX
 | |
| #define LFS_NAME_MAX 255
 | |
| #endif
 | |
| 
 | |
| // Lookahead distance
 | |
| #ifndef LFS_CFG_LOOKAHEAD
 | |
| #define LFS_CFG_LOOKAHEAD 128
 | |
| #endif
 | |
| 
 | |
| // Logging operations
 | |
| #include <stdio.h>
 | |
| #define LFS_ERROR(fmt, ...) printf("lfs error: " fmt "\n", __VA_ARGS__)
 | |
| #define LFS_WARN(fmt, ...)  printf("lfs warn: " fmt "\n", __VA_ARGS__)
 | |
| #define LFS_INFO(fmt, ...)  printf("lfs info: " fmt "\n", __VA_ARGS__)
 | |
| 
 | |
| 
 | |
| #endif
 |