mirror of
				https://github.com/eledio-devices/thirdparty-littlefs.git
				synced 2025-10-31 16:14:16 +01:00 
			
		
		
		
	Before, the lfs had multiple paths to determine config options: - lfs_config struct passed during initialization - lfs_bd_info struct passed during block device initialization - compile time options This allowed different developers to provide their own needs to the filesystem, such as the block device capabilities and the higher level user's own tweaks. However, this comes with additional complexity and action required when the configurations are incompatible. For now, this has been reduced to all information (including block device function pointers) being passed through the lfs_config struct. We just defer more complicated handling of configuration options to the top level user. This simplifies configuration handling and gives the top level user the responsibility to handle configuration, which they probably would have wanted to do anyways.
		
			
				
	
	
		
			95 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			Plaintext
		
	
	
	
	
	
			
		
		
	
	
			95 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			Plaintext
		
	
	
	
	
	
| /// AUTOGENERATED TEST ///
 | |
| #include "lfs.h"
 | |
| #include "emubd/lfs_emubd.h"
 | |
| #include <stdio.h>
 | |
| #include <string.h>
 | |
| #include <stdlib.h>
 | |
| 
 | |
| 
 | |
| // test stuff
 | |
| void test_log(const char *s, uintmax_t v) {{
 | |
|     printf("%s: %jd\n", s, v);
 | |
| }}
 | |
| 
 | |
| void test_assert(const char *file, unsigned line,
 | |
|         const char *s, uintmax_t v, uintmax_t e) {{
 | |
|     static const char *last[2] = {{0, 0}};
 | |
|     if (v != e || !(last[0] == s || last[1] == s)) {{
 | |
|         test_log(s, v);
 | |
|         last[0] = last[1];
 | |
|         last[1] = s;
 | |
|     }}
 | |
| 
 | |
|     if (v != e) {{
 | |
|         printf("\033[31m%s:%u: assert %s failed, expected %jd\033[0m\n",
 | |
|                 file, line, s, e);
 | |
|         exit(-2);
 | |
|     }}
 | |
| }}
 | |
| 
 | |
| #define test_assert(s, v, e) test_assert(__FILE__, __LINE__, s, v, e)
 | |
| 
 | |
| 
 | |
| // utility functions for traversals
 | |
| int test_count(void *p, lfs_block_t b) {{
 | |
|     unsigned *u = (unsigned*)p;
 | |
|     *u += 1;
 | |
|     return 0;
 | |
| }}
 | |
| 
 | |
| 
 | |
| // lfs declarations
 | |
| lfs_t lfs;
 | |
| lfs_emubd_t bd;
 | |
| lfs_file_t file[4];
 | |
| lfs_dir_t dir[4];
 | |
| struct lfs_info info;
 | |
| 
 | |
| uint8_t buffer[1024];
 | |
| uint8_t wbuffer[1024];
 | |
| uint8_t rbuffer[1024];
 | |
| lfs_size_t size;
 | |
| lfs_size_t wsize;
 | |
| lfs_size_t rsize;
 | |
| 
 | |
| uintmax_t res;
 | |
| 
 | |
| #ifndef LFS_READ_SIZE
 | |
| #define LFS_READ_SIZE 1
 | |
| #endif
 | |
| 
 | |
| #ifndef LFS_PROG_SIZE
 | |
| #define LFS_PROG_SIZE 1
 | |
| #endif
 | |
| 
 | |
| #ifndef LFS_BLOCK_SIZE
 | |
| #define LFS_BLOCK_SIZE 512
 | |
| #endif
 | |
| 
 | |
| #ifndef LFS_BLOCK_COUNT
 | |
| #define LFS_BLOCK_COUNT 1024
 | |
| #endif
 | |
| 
 | |
| const struct lfs_config cfg = {{
 | |
|     .context = &bd,
 | |
|     .read  = &lfs_emubd_read,
 | |
|     .prog  = &lfs_emubd_prog,
 | |
|     .erase = &lfs_emubd_erase,
 | |
|     .sync  = &lfs_emubd_sync,
 | |
| 
 | |
|     .read_size   = LFS_READ_SIZE,
 | |
|     .prog_size   = LFS_PROG_SIZE,
 | |
|     .block_size  = LFS_BLOCK_SIZE,
 | |
|     .block_count = LFS_BLOCK_COUNT,
 | |
| }};
 | |
| 
 | |
| 
 | |
| // Entry point
 | |
| int main() {{
 | |
|     lfs_emubd_create(&cfg, "blocks");
 | |
| 
 | |
| {tests}
 | |
| 
 | |
|     lfs_emubd_destroy(&cfg);
 | |
| }}
 |