mirror of
				https://github.com/eledio-devices/thirdparty-littlefs.git
				synced 2025-11-01 00:38:29 +01:00 
			
		
		
		
	As an embedded library, littlefs's configuration straddles two worlds.
In most cases the configuration is usually constant at build time, but
when integrated into OSs, the configuration needs to be dynamically
configurable.
To help with this, littlefs has a separate lfs_config struct that can be
placed into ROM when possible.
But you know what's better than ROM configuration? Truely inlinable
static configuration known at compile-time. In addition to avoiding the
RAM cost, compile-time configuration allows for additional compiler
optimizations, such as constexpr-elimination and removal of unused
code-paths.
So how to enable static configuration?
1. define LFS_STATICCFG
2. implement callbacks as global functions:
   - lfs_read
   - lfs_prog
   - lfs_erase
   - lfs_sync
2. define the now-required constants that configure littlefs:
   - LFS_READ_SIZE
   - LFS_PROG_SIZE
   - LFS_BLOCK_SIZE
   - LFS_BLOCK_COUNT
   - LFS_BLOCK_CYCLES
   - LFS_CACHE_SIZE
   - LFS_LOOKAHEAD_SIZE
   - LFS_READ_BUFFER (optional)
   - LFS_PROG_BUFFER (optional)
   - LFS_LOOKAHEAD_BUFFER (optional)
   - LFS_NAME_MAX (optional)
   - LFS_FILE_MAX (optional)
   - LFS_ATTR_MAX (optional)
Note, there is a separate configuration for the file configuration, this
can be enabled/disabled independently of LFS_STATICCFG. You will likely
want to define this as well if you are looking for the smallest code
size.
In order to avoid a mess of #ifdefs, the internals of littlefs use a
simple macro that redirects to either the dynamic or static config at
compile time:
    #ifdef LFS_STATICCFG
    #define LFS_CFG_READ_SIZE(lfs) ((void)lfs, LFS_READ_SIZE)
    #else
    #define LFS_CFG_READ_SIZE(lfs) lfs->cfg->read_size
    #endif
Unfortunately it does look like there still may be a lot of issues
related to warnings of comparisons against constants... If only C had
a way to ignore warnings on individual statements...
Original idea by apmorton
		
	
		
			
				
	
	
		
			839 lines
		
	
	
		
			27 KiB
		
	
	
	
		
			TOML
		
	
	
	
	
	
			
		
		
	
	
			839 lines
		
	
	
		
			27 KiB
		
	
	
	
		
			TOML
		
	
	
	
	
	
| [[case]] # root
 | |
| code = '''
 | |
|     lfs_formatcfg(&lfs, &cfg) => 0;
 | |
|     lfs_mountcfg(&lfs, &cfg) => 0;
 | |
|     lfs_dir_open(&lfs, &dir, "/") => 0;
 | |
|     lfs_dir_read(&lfs, &dir, &info) => 1;
 | |
|     assert(info.type == LFS_TYPE_DIR);
 | |
|     assert(strcmp(info.name, ".") == 0);
 | |
|     lfs_dir_read(&lfs, &dir, &info) => 1;
 | |
|     assert(info.type == LFS_TYPE_DIR);
 | |
|     assert(strcmp(info.name, "..") == 0);
 | |
|     lfs_dir_read(&lfs, &dir, &info) => 0;
 | |
|     lfs_dir_close(&lfs, &dir) => 0;
 | |
|     lfs_unmount(&lfs) => 0;
 | |
| '''
 | |
| 
 | |
| [[case]] # many directory creation
 | |
| define.N = 'range(0, 100, 3)'
 | |
| code = '''
 | |
|     lfs_formatcfg(&lfs, &cfg) => 0;
 | |
| 
 | |
|     lfs_mountcfg(&lfs, &cfg) => 0;
 | |
|     for (int i = 0; i < N; i++) {
 | |
|         sprintf(path, "dir%03d", i);
 | |
|         lfs_mkdir(&lfs, path) => 0;
 | |
|     }
 | |
|     lfs_unmount(&lfs) => 0;
 | |
| 
 | |
|     lfs_mountcfg(&lfs, &cfg) => 0;
 | |
|     lfs_dir_open(&lfs, &dir, "/") => 0;
 | |
|     lfs_dir_read(&lfs, &dir, &info) => 1;
 | |
|     assert(info.type == LFS_TYPE_DIR);
 | |
|     assert(strcmp(info.name, ".") == 0);
 | |
|     lfs_dir_read(&lfs, &dir, &info) => 1;
 | |
|     assert(info.type == LFS_TYPE_DIR);
 | |
|     assert(strcmp(info.name, "..") == 0);
 | |
|     for (int i = 0; i < N; i++) {
 | |
|         sprintf(path, "dir%03d", i);
 | |
|         lfs_dir_read(&lfs, &dir, &info) => 1;
 | |
|         assert(info.type == LFS_TYPE_DIR);
 | |
|         assert(strcmp(info.name, path) == 0);
 | |
|     }
 | |
|     lfs_dir_read(&lfs, &dir, &info) => 0;
 | |
|     lfs_dir_close(&lfs, &dir) => 0;
 | |
|     lfs_unmount(&lfs) => 0;
 | |
| '''
 | |
| 
 | |
| [[case]] # many directory removal
 | |
| define.N = 'range(3, 100, 11)'
 | |
| code = '''
 | |
|     lfs_formatcfg(&lfs, &cfg) => 0;
 | |
| 
 | |
|     lfs_mountcfg(&lfs, &cfg) => 0;
 | |
|     for (int i = 0; i < N; i++) {
 | |
|         sprintf(path, "removeme%03d", i);
 | |
|         lfs_mkdir(&lfs, path) => 0;
 | |
|     }
 | |
|     lfs_unmount(&lfs) => 0;
 | |
| 
 | |
|     lfs_mountcfg(&lfs, &cfg) => 0;
 | |
|     lfs_dir_open(&lfs, &dir, "/") => 0;
 | |
|     lfs_dir_read(&lfs, &dir, &info) => 1;
 | |
|     assert(info.type == LFS_TYPE_DIR);
 | |
|     assert(strcmp(info.name, ".") == 0);
 | |
|     lfs_dir_read(&lfs, &dir, &info) => 1;
 | |
|     assert(info.type == LFS_TYPE_DIR);
 | |
|     assert(strcmp(info.name, "..") == 0);
 | |
|     for (int i = 0; i < N; i++) {
 | |
|         sprintf(path, "removeme%03d", i);
 | |
|         lfs_dir_read(&lfs, &dir, &info) => 1;
 | |
|         assert(info.type == LFS_TYPE_DIR);
 | |
|         assert(strcmp(info.name, path) == 0);
 | |
|     }
 | |
|     lfs_dir_read(&lfs, &dir, &info) => 0;
 | |
|     lfs_dir_close(&lfs, &dir) => 0;
 | |
|     lfs_unmount(&lfs);
 | |
| 
 | |
|     lfs_mountcfg(&lfs, &cfg) => 0;
 | |
|     for (int i = 0; i < N; i++) {
 | |
|         sprintf(path, "removeme%03d", i);
 | |
|         lfs_remove(&lfs, path) => 0;
 | |
|     }
 | |
|     lfs_unmount(&lfs);
 | |
| 
 | |
|     lfs_mountcfg(&lfs, &cfg) => 0;
 | |
|     lfs_dir_open(&lfs, &dir, "/") => 0;
 | |
|     lfs_dir_read(&lfs, &dir, &info) => 1;
 | |
|     assert(info.type == LFS_TYPE_DIR);
 | |
|     assert(strcmp(info.name, ".") == 0);
 | |
|     lfs_dir_read(&lfs, &dir, &info) => 1;
 | |
|     assert(info.type == LFS_TYPE_DIR);
 | |
|     assert(strcmp(info.name, "..") == 0);
 | |
|     lfs_dir_read(&lfs, &dir, &info) => 0;
 | |
|     lfs_dir_close(&lfs, &dir) => 0;
 | |
|     lfs_unmount(&lfs) => 0;
 | |
| '''
 | |
| 
 | |
| [[case]] # many directory rename
 | |
| define.N = 'range(3, 100, 11)'
 | |
| code = '''
 | |
|     lfs_formatcfg(&lfs, &cfg) => 0;
 | |
| 
 | |
|     lfs_mountcfg(&lfs, &cfg) => 0;
 | |
|     for (int i = 0; i < N; i++) {
 | |
|         sprintf(path, "test%03d", i);
 | |
|         lfs_mkdir(&lfs, path) => 0;
 | |
|     }
 | |
|     lfs_unmount(&lfs) => 0;
 | |
| 
 | |
|     lfs_mountcfg(&lfs, &cfg) => 0;
 | |
|     lfs_dir_open(&lfs, &dir, "/") => 0;
 | |
|     lfs_dir_read(&lfs, &dir, &info) => 1;
 | |
|     assert(info.type == LFS_TYPE_DIR);
 | |
|     assert(strcmp(info.name, ".") == 0);
 | |
|     lfs_dir_read(&lfs, &dir, &info) => 1;
 | |
|     assert(info.type == LFS_TYPE_DIR);
 | |
|     assert(strcmp(info.name, "..") == 0);
 | |
|     for (int i = 0; i < N; i++) {
 | |
|         sprintf(path, "test%03d", i);
 | |
|         lfs_dir_read(&lfs, &dir, &info) => 1;
 | |
|         assert(info.type == LFS_TYPE_DIR);
 | |
|         assert(strcmp(info.name, path) == 0);
 | |
|     }
 | |
|     lfs_dir_read(&lfs, &dir, &info) => 0;
 | |
|     lfs_dir_close(&lfs, &dir) => 0;
 | |
|     lfs_unmount(&lfs);
 | |
| 
 | |
|     lfs_mountcfg(&lfs, &cfg) => 0;
 | |
|     for (int i = 0; i < N; i++) {
 | |
|         char oldpath[128];
 | |
|         char newpath[128];
 | |
|         sprintf(oldpath, "test%03d", i);
 | |
|         sprintf(newpath, "tedd%03d", i);
 | |
|         lfs_rename(&lfs, oldpath, newpath) => 0;
 | |
|     }
 | |
|     lfs_unmount(&lfs);
 | |
| 
 | |
|     lfs_mountcfg(&lfs, &cfg) => 0;
 | |
|     lfs_dir_open(&lfs, &dir, "/") => 0;
 | |
|     lfs_dir_read(&lfs, &dir, &info) => 1;
 | |
|     assert(info.type == LFS_TYPE_DIR);
 | |
|     assert(strcmp(info.name, ".") == 0);
 | |
|     lfs_dir_read(&lfs, &dir, &info) => 1;
 | |
|     assert(info.type == LFS_TYPE_DIR);
 | |
|     assert(strcmp(info.name, "..") == 0);
 | |
|     for (int i = 0; i < N; i++) {
 | |
|         sprintf(path, "tedd%03d", i);
 | |
|         lfs_dir_read(&lfs, &dir, &info) => 1;
 | |
|         assert(info.type == LFS_TYPE_DIR);
 | |
|         assert(strcmp(info.name, path) == 0);
 | |
|     }
 | |
|     lfs_dir_read(&lfs, &dir, &info) => 0;
 | |
|     lfs_dir_close(&lfs, &dir) => 0;
 | |
|     lfs_unmount(&lfs);
 | |
| '''
 | |
| 
 | |
| [[case]] # reentrant many directory creation/rename/removal
 | |
| define.N = [5, 11]
 | |
| reentrant = true
 | |
| code = '''
 | |
|     err = lfs_mountcfg(&lfs, &cfg);
 | |
|     if (err) {
 | |
|         lfs_formatcfg(&lfs, &cfg) => 0;
 | |
|         lfs_mountcfg(&lfs, &cfg) => 0;
 | |
|     }
 | |
| 
 | |
|     for (int i = 0; i < N; i++) {
 | |
|         sprintf(path, "hi%03d", i);
 | |
|         err = lfs_mkdir(&lfs, path);
 | |
|         assert(err == 0 || err == LFS_ERR_EXIST);
 | |
|     }
 | |
| 
 | |
|     for (int i = 0; i < N; i++) {
 | |
|         sprintf(path, "hello%03d", i);
 | |
|         err = lfs_remove(&lfs, path);
 | |
|         assert(err == 0 || err == LFS_ERR_NOENT);
 | |
|     }
 | |
| 
 | |
|     lfs_dir_open(&lfs, &dir, "/") => 0;
 | |
|     lfs_dir_read(&lfs, &dir, &info) => 1;
 | |
|     assert(info.type == LFS_TYPE_DIR);
 | |
|     assert(strcmp(info.name, ".") == 0);
 | |
|     lfs_dir_read(&lfs, &dir, &info) => 1;
 | |
|     assert(info.type == LFS_TYPE_DIR);
 | |
|     assert(strcmp(info.name, "..") == 0);
 | |
|     for (int i = 0; i < N; i++) {
 | |
|         sprintf(path, "hi%03d", i);
 | |
|         lfs_dir_read(&lfs, &dir, &info) => 1;
 | |
|         assert(info.type == LFS_TYPE_DIR);
 | |
|         assert(strcmp(info.name, path) == 0);
 | |
|     }
 | |
|     lfs_dir_read(&lfs, &dir, &info) => 0;
 | |
|     lfs_dir_close(&lfs, &dir) => 0;
 | |
| 
 | |
|     for (int i = 0; i < N; i++) {
 | |
|         char oldpath[128];
 | |
|         char newpath[128];
 | |
|         sprintf(oldpath, "hi%03d", i);
 | |
|         sprintf(newpath, "hello%03d", i);
 | |
|         // YES this can overwrite an existing newpath
 | |
|         lfs_rename(&lfs, oldpath, newpath) => 0;
 | |
|     }
 | |
| 
 | |
|     lfs_dir_open(&lfs, &dir, "/") => 0;
 | |
|     lfs_dir_read(&lfs, &dir, &info) => 1;
 | |
|     assert(info.type == LFS_TYPE_DIR);
 | |
|     assert(strcmp(info.name, ".") == 0);
 | |
|     lfs_dir_read(&lfs, &dir, &info) => 1;
 | |
|     assert(info.type == LFS_TYPE_DIR);
 | |
|     assert(strcmp(info.name, "..") == 0);
 | |
|     for (int i = 0; i < N; i++) {
 | |
|         sprintf(path, "hello%03d", i);
 | |
|         lfs_dir_read(&lfs, &dir, &info) => 1;
 | |
|         assert(info.type == LFS_TYPE_DIR);
 | |
|         assert(strcmp(info.name, path) == 0);
 | |
|     }
 | |
|     lfs_dir_read(&lfs, &dir, &info) => 0;
 | |
|     lfs_dir_close(&lfs, &dir) => 0;
 | |
| 
 | |
|     for (int i = 0; i < N; i++) {
 | |
|         sprintf(path, "hello%03d", i);
 | |
|         lfs_remove(&lfs, path) => 0;
 | |
|     }
 | |
| 
 | |
|     lfs_dir_open(&lfs, &dir, "/") => 0;
 | |
|     lfs_dir_read(&lfs, &dir, &info) => 1;
 | |
|     assert(info.type == LFS_TYPE_DIR);
 | |
|     assert(strcmp(info.name, ".") == 0);
 | |
|     lfs_dir_read(&lfs, &dir, &info) => 1;
 | |
|     assert(info.type == LFS_TYPE_DIR);
 | |
|     assert(strcmp(info.name, "..") == 0);
 | |
|     lfs_dir_read(&lfs, &dir, &info) => 0;
 | |
|     lfs_dir_close(&lfs, &dir) => 0;
 | |
|     lfs_unmount(&lfs) => 0;
 | |
| '''
 | |
| 
 | |
| [[case]] # file creation
 | |
| define.N = 'range(3, 100, 11)'
 | |
| code = '''
 | |
|     lfs_formatcfg(&lfs, &cfg) => 0;
 | |
| 
 | |
|     lfs_mountcfg(&lfs, &cfg) => 0;
 | |
|     for (int i = 0; i < N; i++) {
 | |
|         sprintf(path, "file%03d", i);
 | |
|         lfs_file_open(&lfs, &file, path,
 | |
|                 LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
 | |
|         lfs_file_close(&lfs, &file) => 0;
 | |
|     }
 | |
|     lfs_unmount(&lfs) => 0;
 | |
| 
 | |
|     lfs_mountcfg(&lfs, &cfg) => 0;
 | |
|     lfs_dir_open(&lfs, &dir, "/") => 0;
 | |
|     lfs_dir_read(&lfs, &dir, &info) => 1;
 | |
|     assert(info.type == LFS_TYPE_DIR);
 | |
|     assert(strcmp(info.name, ".") == 0);
 | |
|     lfs_dir_read(&lfs, &dir, &info) => 1;
 | |
|     assert(info.type == LFS_TYPE_DIR);
 | |
|     assert(strcmp(info.name, "..") == 0);
 | |
|     for (int i = 0; i < N; i++) {
 | |
|         sprintf(path, "file%03d", i);
 | |
|         lfs_dir_read(&lfs, &dir, &info) => 1;
 | |
|         assert(info.type == LFS_TYPE_REG);
 | |
|         assert(strcmp(info.name, path) == 0);
 | |
|     }
 | |
|     lfs_dir_read(&lfs, &dir, &info) => 0;
 | |
|     lfs_dir_close(&lfs, &dir) => 0;
 | |
|     lfs_unmount(&lfs);
 | |
| '''
 | |
| 
 | |
| [[case]] # file removal
 | |
| define.N = 'range(0, 100, 3)'
 | |
| code = '''
 | |
|     lfs_formatcfg(&lfs, &cfg) => 0;
 | |
| 
 | |
|     lfs_mountcfg(&lfs, &cfg) => 0;
 | |
|     for (int i = 0; i < N; i++) {
 | |
|         sprintf(path, "removeme%03d", i);
 | |
|         lfs_file_open(&lfs, &file, path,
 | |
|                 LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
 | |
|         lfs_file_close(&lfs, &file) => 0;
 | |
|     }
 | |
|     lfs_unmount(&lfs) => 0;
 | |
| 
 | |
|     lfs_mountcfg(&lfs, &cfg) => 0;
 | |
|     lfs_dir_open(&lfs, &dir, "/") => 0;
 | |
|     lfs_dir_read(&lfs, &dir, &info) => 1;
 | |
|     assert(info.type == LFS_TYPE_DIR);
 | |
|     assert(strcmp(info.name, ".") == 0);
 | |
|     lfs_dir_read(&lfs, &dir, &info) => 1;
 | |
|     assert(info.type == LFS_TYPE_DIR);
 | |
|     assert(strcmp(info.name, "..") == 0);
 | |
|     for (int i = 0; i < N; i++) {
 | |
|         sprintf(path, "removeme%03d", i);
 | |
|         lfs_dir_read(&lfs, &dir, &info) => 1;
 | |
|         assert(info.type == LFS_TYPE_REG);
 | |
|         assert(strcmp(info.name, path) == 0);
 | |
|     }
 | |
|     lfs_dir_read(&lfs, &dir, &info) => 0;
 | |
|     lfs_dir_close(&lfs, &dir) => 0;
 | |
|     lfs_unmount(&lfs);
 | |
| 
 | |
|     lfs_mountcfg(&lfs, &cfg) => 0;
 | |
|     for (int i = 0; i < N; i++) {
 | |
|         sprintf(path, "removeme%03d", i);
 | |
|         lfs_remove(&lfs, path) => 0;
 | |
|     }
 | |
|     lfs_unmount(&lfs);
 | |
| 
 | |
|     lfs_mountcfg(&lfs, &cfg) => 0;
 | |
|     lfs_dir_open(&lfs, &dir, "/") => 0;
 | |
|     lfs_dir_read(&lfs, &dir, &info) => 1;
 | |
|     assert(info.type == LFS_TYPE_DIR);
 | |
|     assert(strcmp(info.name, ".") == 0);
 | |
|     lfs_dir_read(&lfs, &dir, &info) => 1;
 | |
|     assert(info.type == LFS_TYPE_DIR);
 | |
|     assert(strcmp(info.name, "..") == 0);
 | |
|     lfs_dir_read(&lfs, &dir, &info) => 0;
 | |
|     lfs_dir_close(&lfs, &dir) => 0;
 | |
|     lfs_unmount(&lfs) => 0;
 | |
| '''
 | |
| 
 | |
| [[case]] # file rename
 | |
| define.N = 'range(0, 100, 3)'
 | |
| code = '''
 | |
|     lfs_formatcfg(&lfs, &cfg) => 0;
 | |
| 
 | |
|     lfs_mountcfg(&lfs, &cfg) => 0;
 | |
|     for (int i = 0; i < N; i++) {
 | |
|         sprintf(path, "test%03d", i);
 | |
|         lfs_file_open(&lfs, &file, path,
 | |
|                 LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
 | |
|         lfs_file_close(&lfs, &file) => 0;
 | |
|     }
 | |
|     lfs_unmount(&lfs) => 0;
 | |
| 
 | |
|     lfs_mountcfg(&lfs, &cfg) => 0;
 | |
|     lfs_dir_open(&lfs, &dir, "/") => 0;
 | |
|     lfs_dir_read(&lfs, &dir, &info) => 1;
 | |
|     assert(info.type == LFS_TYPE_DIR);
 | |
|     assert(strcmp(info.name, ".") == 0);
 | |
|     lfs_dir_read(&lfs, &dir, &info) => 1;
 | |
|     assert(info.type == LFS_TYPE_DIR);
 | |
|     assert(strcmp(info.name, "..") == 0);
 | |
|     for (int i = 0; i < N; i++) {
 | |
|         sprintf(path, "test%03d", i);
 | |
|         lfs_dir_read(&lfs, &dir, &info) => 1;
 | |
|         assert(info.type == LFS_TYPE_REG);
 | |
|         assert(strcmp(info.name, path) == 0);
 | |
|     }
 | |
|     lfs_dir_read(&lfs, &dir, &info) => 0;
 | |
|     lfs_dir_close(&lfs, &dir) => 0;
 | |
|     lfs_unmount(&lfs);
 | |
| 
 | |
|     lfs_mountcfg(&lfs, &cfg) => 0;
 | |
|     for (int i = 0; i < N; i++) {
 | |
|         char oldpath[128];
 | |
|         char newpath[128];
 | |
|         sprintf(oldpath, "test%03d", i);
 | |
|         sprintf(newpath, "tedd%03d", i);
 | |
|         lfs_rename(&lfs, oldpath, newpath) => 0;
 | |
|     }
 | |
|     lfs_unmount(&lfs);
 | |
| 
 | |
|     lfs_mountcfg(&lfs, &cfg) => 0;
 | |
|     lfs_dir_open(&lfs, &dir, "/") => 0;
 | |
|     lfs_dir_read(&lfs, &dir, &info) => 1;
 | |
|     assert(info.type == LFS_TYPE_DIR);
 | |
|     assert(strcmp(info.name, ".") == 0);
 | |
|     lfs_dir_read(&lfs, &dir, &info) => 1;
 | |
|     assert(info.type == LFS_TYPE_DIR);
 | |
|     assert(strcmp(info.name, "..") == 0);
 | |
|     for (int i = 0; i < N; i++) {
 | |
|         sprintf(path, "tedd%03d", i);
 | |
|         lfs_dir_read(&lfs, &dir, &info) => 1;
 | |
|         assert(info.type == LFS_TYPE_REG);
 | |
|         assert(strcmp(info.name, path) == 0);
 | |
|     }
 | |
|     lfs_dir_read(&lfs, &dir, &info) => 0;
 | |
|     lfs_dir_close(&lfs, &dir) => 0;
 | |
|     lfs_unmount(&lfs);
 | |
| '''
 | |
| 
 | |
| [[case]] # reentrant file creation/rename/removal
 | |
| define.N = [5, 25]
 | |
| reentrant = true
 | |
| code = '''
 | |
|     err = lfs_mountcfg(&lfs, &cfg);
 | |
|     if (err) {
 | |
|         lfs_formatcfg(&lfs, &cfg) => 0;
 | |
|         lfs_mountcfg(&lfs, &cfg) => 0;
 | |
|     }
 | |
| 
 | |
|     for (int i = 0; i < N; i++) {
 | |
|         sprintf(path, "hi%03d", i);
 | |
|         lfs_file_open(&lfs, &file, path, LFS_O_CREAT | LFS_O_WRONLY) => 0;
 | |
|         lfs_file_close(&lfs, &file) => 0;
 | |
|     }
 | |
| 
 | |
|     for (int i = 0; i < N; i++) {
 | |
|         sprintf(path, "hello%03d", i);
 | |
|         err = lfs_remove(&lfs, path);
 | |
|         assert(err == 0 || err == LFS_ERR_NOENT);
 | |
|     }
 | |
| 
 | |
|     lfs_dir_open(&lfs, &dir, "/") => 0;
 | |
|     lfs_dir_read(&lfs, &dir, &info) => 1;
 | |
|     assert(info.type == LFS_TYPE_DIR);
 | |
|     assert(strcmp(info.name, ".") == 0);
 | |
|     lfs_dir_read(&lfs, &dir, &info) => 1;
 | |
|     assert(info.type == LFS_TYPE_DIR);
 | |
|     assert(strcmp(info.name, "..") == 0);
 | |
|     for (int i = 0; i < N; i++) {
 | |
|         sprintf(path, "hi%03d", i);
 | |
|         lfs_dir_read(&lfs, &dir, &info) => 1;
 | |
|         assert(info.type == LFS_TYPE_REG);
 | |
|         assert(strcmp(info.name, path) == 0);
 | |
|     }
 | |
|     lfs_dir_read(&lfs, &dir, &info) => 0;
 | |
|     lfs_dir_close(&lfs, &dir) => 0;
 | |
| 
 | |
|     for (int i = 0; i < N; i++) {
 | |
|         char oldpath[128];
 | |
|         char newpath[128];
 | |
|         sprintf(oldpath, "hi%03d", i);
 | |
|         sprintf(newpath, "hello%03d", i);
 | |
|         // YES this can overwrite an existing newpath
 | |
|         lfs_rename(&lfs, oldpath, newpath) => 0;
 | |
|     }
 | |
| 
 | |
|     lfs_dir_open(&lfs, &dir, "/") => 0;
 | |
|     lfs_dir_read(&lfs, &dir, &info) => 1;
 | |
|     assert(info.type == LFS_TYPE_DIR);
 | |
|     assert(strcmp(info.name, ".") == 0);
 | |
|     lfs_dir_read(&lfs, &dir, &info) => 1;
 | |
|     assert(info.type == LFS_TYPE_DIR);
 | |
|     assert(strcmp(info.name, "..") == 0);
 | |
|     for (int i = 0; i < N; i++) {
 | |
|         sprintf(path, "hello%03d", i);
 | |
|         lfs_dir_read(&lfs, &dir, &info) => 1;
 | |
|         assert(info.type == LFS_TYPE_REG);
 | |
|         assert(strcmp(info.name, path) == 0);
 | |
|     }
 | |
|     lfs_dir_read(&lfs, &dir, &info) => 0;
 | |
|     lfs_dir_close(&lfs, &dir) => 0;
 | |
| 
 | |
|     for (int i = 0; i < N; i++) {
 | |
|         sprintf(path, "hello%03d", i);
 | |
|         lfs_remove(&lfs, path) => 0;
 | |
|     }
 | |
| 
 | |
|     lfs_dir_open(&lfs, &dir, "/") => 0;
 | |
|     lfs_dir_read(&lfs, &dir, &info) => 1;
 | |
|     assert(info.type == LFS_TYPE_DIR);
 | |
|     assert(strcmp(info.name, ".") == 0);
 | |
|     lfs_dir_read(&lfs, &dir, &info) => 1;
 | |
|     assert(info.type == LFS_TYPE_DIR);
 | |
|     assert(strcmp(info.name, "..") == 0);
 | |
|     lfs_dir_read(&lfs, &dir, &info) => 0;
 | |
|     lfs_dir_close(&lfs, &dir) => 0;
 | |
|     lfs_unmount(&lfs) => 0;
 | |
| '''
 | |
| 
 | |
| [[case]] # nested directories
 | |
| code = '''
 | |
|     lfs_formatcfg(&lfs, &cfg) => 0;
 | |
|     lfs_mountcfg(&lfs, &cfg) => 0;
 | |
|     lfs_mkdir(&lfs, "potato") => 0;
 | |
|     lfs_file_open(&lfs, &file, "burito",
 | |
|             LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
 | |
|     lfs_file_close(&lfs, &file) => 0;
 | |
|     lfs_unmount(&lfs) => 0;
 | |
| 
 | |
|     lfs_mountcfg(&lfs, &cfg) => 0;
 | |
|     lfs_mkdir(&lfs, "potato/baked") => 0;
 | |
|     lfs_mkdir(&lfs, "potato/sweet") => 0;
 | |
|     lfs_mkdir(&lfs, "potato/fried") => 0;
 | |
|     lfs_unmount(&lfs) => 0;
 | |
| 
 | |
|     lfs_mountcfg(&lfs, &cfg) => 0;
 | |
|     lfs_dir_open(&lfs, &dir, "potato") => 0;
 | |
|     lfs_dir_read(&lfs, &dir, &info) => 1;
 | |
|     assert(strcmp(info.name, ".") == 0);
 | |
|     info.type => LFS_TYPE_DIR;
 | |
|     lfs_dir_read(&lfs, &dir, &info) => 1;
 | |
|     assert(strcmp(info.name, "..") == 0);
 | |
|     info.type => LFS_TYPE_DIR;
 | |
|     lfs_dir_read(&lfs, &dir, &info) => 1;
 | |
|     assert(strcmp(info.name, "baked") == 0);
 | |
|     info.type => LFS_TYPE_DIR;
 | |
|     lfs_dir_read(&lfs, &dir, &info) => 1;
 | |
|     assert(strcmp(info.name, "fried") == 0);
 | |
|     info.type => LFS_TYPE_DIR;
 | |
|     lfs_dir_read(&lfs, &dir, &info) => 1;
 | |
|     assert(strcmp(info.name, "sweet") == 0);
 | |
|     info.type => LFS_TYPE_DIR;
 | |
|     lfs_dir_read(&lfs, &dir, &info) => 0;
 | |
|     lfs_dir_close(&lfs, &dir) => 0;
 | |
|     lfs_unmount(&lfs) => 0;
 | |
| 
 | |
|     // try removing?
 | |
|     lfs_mountcfg(&lfs, &cfg) => 0;
 | |
|     lfs_remove(&lfs, "potato") => LFS_ERR_NOTEMPTY;
 | |
|     lfs_unmount(&lfs) => 0;
 | |
| 
 | |
|     // try renaming?
 | |
|     lfs_mountcfg(&lfs, &cfg) => 0;
 | |
|     lfs_rename(&lfs, "potato", "coldpotato") => 0;
 | |
|     lfs_unmount(&lfs) => 0;
 | |
| 
 | |
|     lfs_mountcfg(&lfs, &cfg) => 0;
 | |
|     lfs_rename(&lfs, "coldpotato", "warmpotato") => 0;
 | |
|     lfs_rename(&lfs, "warmpotato", "hotpotato") => 0;
 | |
|     lfs_unmount(&lfs) => 0;
 | |
| 
 | |
|     lfs_mountcfg(&lfs, &cfg) => 0;
 | |
|     lfs_remove(&lfs, "potato") => LFS_ERR_NOENT;
 | |
|     lfs_remove(&lfs, "coldpotato") => LFS_ERR_NOENT;
 | |
|     lfs_remove(&lfs, "warmpotato") => LFS_ERR_NOENT;
 | |
|     lfs_remove(&lfs, "hotpotato") => LFS_ERR_NOTEMPTY;
 | |
|     lfs_unmount(&lfs) => 0;
 | |
| 
 | |
|     // try cross-directory renaming
 | |
|     lfs_mountcfg(&lfs, &cfg) => 0;
 | |
|     lfs_mkdir(&lfs, "coldpotato") => 0;
 | |
|     lfs_rename(&lfs, "hotpotato/baked", "coldpotato/baked") => 0;
 | |
|     lfs_rename(&lfs, "coldpotato", "hotpotato") => LFS_ERR_NOTEMPTY;
 | |
|     lfs_remove(&lfs, "coldpotato") => LFS_ERR_NOTEMPTY;
 | |
|     lfs_remove(&lfs, "hotpotato") => LFS_ERR_NOTEMPTY;
 | |
|     lfs_rename(&lfs, "hotpotato/fried", "coldpotato/fried") => 0;
 | |
|     lfs_rename(&lfs, "coldpotato", "hotpotato") => LFS_ERR_NOTEMPTY;
 | |
|     lfs_remove(&lfs, "coldpotato") => LFS_ERR_NOTEMPTY;
 | |
|     lfs_remove(&lfs, "hotpotato") => LFS_ERR_NOTEMPTY;
 | |
|     lfs_rename(&lfs, "hotpotato/sweet", "coldpotato/sweet") => 0;
 | |
|     lfs_rename(&lfs, "coldpotato", "hotpotato") => 0;
 | |
|     lfs_remove(&lfs, "coldpotato") => LFS_ERR_NOENT;
 | |
|     lfs_remove(&lfs, "hotpotato") => LFS_ERR_NOTEMPTY;
 | |
|     lfs_unmount(&lfs) => 0;
 | |
| 
 | |
|     lfs_mountcfg(&lfs, &cfg) => 0;
 | |
|     lfs_dir_open(&lfs, &dir, "hotpotato") => 0;
 | |
|     lfs_dir_read(&lfs, &dir, &info) => 1;
 | |
|     assert(strcmp(info.name, ".") == 0);
 | |
|     info.type => LFS_TYPE_DIR;
 | |
|     lfs_dir_read(&lfs, &dir, &info) => 1;
 | |
|     assert(strcmp(info.name, "..") == 0);
 | |
|     info.type => LFS_TYPE_DIR;
 | |
|     lfs_dir_read(&lfs, &dir, &info) => 1;
 | |
|     assert(strcmp(info.name, "baked") == 0);
 | |
|     info.type => LFS_TYPE_DIR;
 | |
|     lfs_dir_read(&lfs, &dir, &info) => 1;
 | |
|     assert(strcmp(info.name, "fried") == 0);
 | |
|     info.type => LFS_TYPE_DIR;
 | |
|     lfs_dir_read(&lfs, &dir, &info) => 1;
 | |
|     assert(strcmp(info.name, "sweet") == 0);
 | |
|     info.type => LFS_TYPE_DIR;
 | |
|     lfs_dir_read(&lfs, &dir, &info) => 0;
 | |
|     lfs_dir_close(&lfs, &dir) => 0;
 | |
|     lfs_unmount(&lfs) => 0;
 | |
|     
 | |
|     // final remove
 | |
|     lfs_mountcfg(&lfs, &cfg) => 0;
 | |
|     lfs_remove(&lfs, "hotpotato") => LFS_ERR_NOTEMPTY;
 | |
|     lfs_remove(&lfs, "hotpotato/baked") => 0;
 | |
|     lfs_remove(&lfs, "hotpotato") => LFS_ERR_NOTEMPTY;
 | |
|     lfs_remove(&lfs, "hotpotato/fried") => 0;
 | |
|     lfs_remove(&lfs, "hotpotato") => LFS_ERR_NOTEMPTY;
 | |
|     lfs_remove(&lfs, "hotpotato/sweet") => 0;
 | |
|     lfs_remove(&lfs, "hotpotato") => 0;
 | |
|     lfs_unmount(&lfs) => 0;
 | |
| 
 | |
|     lfs_mountcfg(&lfs, &cfg) => 0;
 | |
|     lfs_dir_open(&lfs, &dir, "/") => 0;
 | |
|     lfs_dir_read(&lfs, &dir, &info) => 1;
 | |
|     assert(strcmp(info.name, ".") == 0);
 | |
|     info.type => LFS_TYPE_DIR;
 | |
|     lfs_dir_read(&lfs, &dir, &info) => 1;
 | |
|     assert(strcmp(info.name, "..") == 0);
 | |
|     info.type => LFS_TYPE_DIR;
 | |
|     lfs_dir_read(&lfs, &dir, &info) => 1;
 | |
|     assert(strcmp(info.name, "burito") == 0);
 | |
|     info.type => LFS_TYPE_REG;
 | |
|     lfs_dir_read(&lfs, &dir, &info) => 0;
 | |
|     lfs_dir_close(&lfs, &dir) => 0;
 | |
|     lfs_unmount(&lfs) => 0;
 | |
| '''
 | |
| 
 | |
| [[case]] # recursive remove
 | |
| define.N = [10, 100]
 | |
| code = '''
 | |
|     lfs_formatcfg(&lfs, &cfg) => 0;
 | |
|     lfs_mountcfg(&lfs, &cfg) => 0;
 | |
|     lfs_mkdir(&lfs, "prickly-pear") => 0;
 | |
|     for (int i = 0; i < N; i++) {
 | |
|         sprintf(path, "prickly-pear/cactus%03d", i);
 | |
|         lfs_mkdir(&lfs, path) => 0;
 | |
|     }
 | |
|     lfs_dir_open(&lfs, &dir, "prickly-pear") => 0;
 | |
|     lfs_dir_read(&lfs, &dir, &info) => 1;
 | |
|     assert(info.type == LFS_TYPE_DIR);
 | |
|     assert(strcmp(info.name, ".") == 0);
 | |
|     lfs_dir_read(&lfs, &dir, &info) => 1;
 | |
|     assert(info.type == LFS_TYPE_DIR);
 | |
|     assert(strcmp(info.name, "..") == 0);
 | |
|     for (int i = 0; i < N; i++) {
 | |
|         sprintf(path, "cactus%03d", i);
 | |
|         lfs_dir_read(&lfs, &dir, &info) => 1;
 | |
|         assert(info.type == LFS_TYPE_DIR);
 | |
|         assert(strcmp(info.name, path) == 0);
 | |
|     }
 | |
|     lfs_dir_read(&lfs, &dir, &info) => 0;
 | |
|     lfs_dir_close(&lfs, &dir) => 0;
 | |
|     lfs_unmount(&lfs);
 | |
| 
 | |
|     lfs_mountcfg(&lfs, &cfg) => 0;
 | |
|     lfs_remove(&lfs, "prickly-pear") => LFS_ERR_NOTEMPTY;
 | |
| 
 | |
|     lfs_dir_open(&lfs, &dir, "prickly-pear") => 0;
 | |
|     lfs_dir_read(&lfs, &dir, &info) => 1;
 | |
|     assert(info.type == LFS_TYPE_DIR);
 | |
|     assert(strcmp(info.name, ".") == 0);
 | |
|     lfs_dir_read(&lfs, &dir, &info) => 1;
 | |
|     assert(info.type == LFS_TYPE_DIR);
 | |
|     assert(strcmp(info.name, "..") == 0);
 | |
|     for (int i = 0; i < N; i++) {
 | |
|         sprintf(path, "cactus%03d", i);
 | |
|         lfs_dir_read(&lfs, &dir, &info) => 1;
 | |
|         assert(info.type == LFS_TYPE_DIR);
 | |
|         assert(strcmp(info.name, path) == 0);
 | |
|         sprintf(path, "prickly-pear/%s", info.name);
 | |
|         lfs_remove(&lfs, path) => 0;
 | |
|     }
 | |
|     lfs_dir_read(&lfs, &dir, &info) => 0;
 | |
|     lfs_dir_close(&lfs, &dir) => 0;
 | |
| 
 | |
|     lfs_remove(&lfs, "prickly-pear") => 0;
 | |
|     lfs_remove(&lfs, "prickly-pear") => LFS_ERR_NOENT;
 | |
|     lfs_unmount(&lfs) => 0;
 | |
| 
 | |
|     lfs_mountcfg(&lfs, &cfg) => 0;
 | |
|     lfs_remove(&lfs, "prickly-pear") => LFS_ERR_NOENT;
 | |
|     lfs_unmount(&lfs) => 0;
 | |
| '''
 | |
| 
 | |
| [[case]] # other error cases
 | |
| code = '''
 | |
|     lfs_formatcfg(&lfs, &cfg) => 0;
 | |
|     lfs_mountcfg(&lfs, &cfg) => 0;
 | |
|     lfs_mkdir(&lfs, "potato") => 0;
 | |
|     lfs_file_open(&lfs, &file, "burito",
 | |
|             LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
 | |
|     lfs_file_close(&lfs, &file) => 0;
 | |
|     lfs_unmount(&lfs) => 0;
 | |
| 
 | |
|     lfs_mountcfg(&lfs, &cfg) => 0;
 | |
| 
 | |
|     lfs_mkdir(&lfs, "potato") => LFS_ERR_EXIST;
 | |
|     lfs_mkdir(&lfs, "burito") => LFS_ERR_EXIST;
 | |
|     lfs_file_open(&lfs, &file, "burito",
 | |
|             LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => LFS_ERR_EXIST;
 | |
|     lfs_file_open(&lfs, &file, "potato",
 | |
|             LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => LFS_ERR_EXIST;
 | |
|     lfs_dir_open(&lfs, &dir, "tomato") => LFS_ERR_NOENT;
 | |
|     lfs_dir_open(&lfs, &dir, "burito") => LFS_ERR_NOTDIR;
 | |
|     lfs_file_open(&lfs, &file, "tomato", LFS_O_RDONLY) => LFS_ERR_NOENT;
 | |
|     lfs_file_open(&lfs, &file, "potato", LFS_O_RDONLY) => LFS_ERR_ISDIR;
 | |
|     lfs_file_open(&lfs, &file, "tomato", LFS_O_WRONLY) => LFS_ERR_NOENT;
 | |
|     lfs_file_open(&lfs, &file, "potato", LFS_O_WRONLY) => LFS_ERR_ISDIR;
 | |
|     lfs_file_open(&lfs, &file, "potato",
 | |
|             LFS_O_WRONLY | LFS_O_CREAT) => LFS_ERR_ISDIR;
 | |
| 
 | |
|     lfs_mkdir(&lfs, "/") => LFS_ERR_EXIST;
 | |
|     lfs_file_open(&lfs, &file, "/",
 | |
|             LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => LFS_ERR_EXIST;
 | |
|     lfs_file_open(&lfs, &file, "/", LFS_O_RDONLY) => LFS_ERR_ISDIR;
 | |
|     lfs_file_open(&lfs, &file, "/", LFS_O_WRONLY) => LFS_ERR_ISDIR;
 | |
|     lfs_file_open(&lfs, &file, "/",
 | |
|             LFS_O_WRONLY | LFS_O_CREAT) => LFS_ERR_ISDIR;
 | |
| 
 | |
|     // check that errors did not corrupt directory
 | |
|     lfs_dir_open(&lfs, &dir, "/") => 0;
 | |
|     lfs_dir_read(&lfs, &dir, &info) => 1;
 | |
|     assert(info.type == LFS_TYPE_DIR);
 | |
|     assert(strcmp(info.name, ".") == 0);
 | |
|     lfs_dir_read(&lfs, &dir, &info) => 1;
 | |
|     assert(info.type == LFS_TYPE_DIR);
 | |
|     assert(strcmp(info.name, "..") == 0);
 | |
|     lfs_dir_read(&lfs, &dir, &info) => 1;
 | |
|     assert(info.type == LFS_TYPE_REG);
 | |
|     assert(strcmp(info.name, "burito") == 0);
 | |
|     lfs_dir_read(&lfs, &dir, &info) => 1;
 | |
|     assert(info.type == LFS_TYPE_DIR);
 | |
|     assert(strcmp(info.name, "potato") == 0);
 | |
|     lfs_dir_read(&lfs, &dir, &info) => 0;
 | |
|     lfs_dir_close(&lfs, &dir) => 0;
 | |
| 
 | |
|     lfs_unmount(&lfs) => 0;
 | |
| 
 | |
|     // or on disk
 | |
|     lfs_mountcfg(&lfs, &cfg) => 0;
 | |
|     lfs_dir_open(&lfs, &dir, "/") => 0;
 | |
|     lfs_dir_read(&lfs, &dir, &info) => 1;
 | |
|     assert(info.type == LFS_TYPE_DIR);
 | |
|     assert(strcmp(info.name, ".") == 0);
 | |
|     lfs_dir_read(&lfs, &dir, &info) => 1;
 | |
|     assert(info.type == LFS_TYPE_DIR);
 | |
|     assert(strcmp(info.name, "..") == 0);
 | |
|     lfs_dir_read(&lfs, &dir, &info) => 1;
 | |
|     assert(info.type == LFS_TYPE_REG);
 | |
|     assert(strcmp(info.name, "burito") == 0);
 | |
|     lfs_dir_read(&lfs, &dir, &info) => 1;
 | |
|     assert(info.type == LFS_TYPE_DIR);
 | |
|     assert(strcmp(info.name, "potato") == 0);
 | |
|     lfs_dir_read(&lfs, &dir, &info) => 0;
 | |
|     lfs_dir_close(&lfs, &dir) => 0;
 | |
|     lfs_unmount(&lfs) => 0;
 | |
| '''
 | |
| 
 | |
| [[case]] # directory seek
 | |
| define.COUNT = [4, 128, 132]
 | |
| code = '''
 | |
|     lfs_formatcfg(&lfs, &cfg) => 0;
 | |
|     lfs_mountcfg(&lfs, &cfg) => 0;
 | |
|     lfs_mkdir(&lfs, "hello") => 0;
 | |
|     for (int i = 0; i < COUNT; i++) {
 | |
|         sprintf(path, "hello/kitty%03d", i);
 | |
|         lfs_mkdir(&lfs, path) => 0;
 | |
|     }
 | |
|     lfs_unmount(&lfs) => 0;
 | |
| 
 | |
|     for (int j = 2; j < COUNT; j++) {
 | |
|         lfs_mountcfg(&lfs, &cfg) => 0;
 | |
|         lfs_dir_open(&lfs, &dir, "hello") => 0;
 | |
|         lfs_dir_read(&lfs, &dir, &info) => 1;
 | |
|         assert(strcmp(info.name, ".") == 0);
 | |
|         assert(info.type == LFS_TYPE_DIR);
 | |
|         lfs_dir_read(&lfs, &dir, &info) => 1;
 | |
|         assert(strcmp(info.name, "..") == 0);
 | |
|         assert(info.type == LFS_TYPE_DIR);
 | |
| 
 | |
|         lfs_soff_t pos;
 | |
|         for (int i = 0; i < j; i++) {
 | |
|             sprintf(path, "kitty%03d", i);
 | |
|             lfs_dir_read(&lfs, &dir, &info) => 1;
 | |
|             assert(strcmp(info.name, path) == 0);
 | |
|             assert(info.type == LFS_TYPE_DIR);
 | |
|             pos = lfs_dir_tell(&lfs, &dir);
 | |
|             assert(pos >= 0);
 | |
|         }
 | |
| 
 | |
|         lfs_dir_seek(&lfs, &dir, pos) => 0;
 | |
|         sprintf(path, "kitty%03d", j);
 | |
|         lfs_dir_read(&lfs, &dir, &info) => 1;
 | |
|         assert(strcmp(info.name, path) == 0);
 | |
|         assert(info.type == LFS_TYPE_DIR);
 | |
| 
 | |
|         lfs_dir_rewind(&lfs, &dir) => 0;
 | |
|         sprintf(path, "kitty%03d", 0);
 | |
|         lfs_dir_read(&lfs, &dir, &info) => 1;
 | |
|         assert(strcmp(info.name, ".") == 0);
 | |
|         assert(info.type == LFS_TYPE_DIR);
 | |
|         lfs_dir_read(&lfs, &dir, &info) => 1;
 | |
|         assert(strcmp(info.name, "..") == 0);
 | |
|         assert(info.type == LFS_TYPE_DIR);
 | |
|         lfs_dir_read(&lfs, &dir, &info) => 1;
 | |
|         assert(strcmp(info.name, path) == 0);
 | |
|         assert(info.type == LFS_TYPE_DIR);
 | |
| 
 | |
|         lfs_dir_seek(&lfs, &dir, pos) => 0;
 | |
|         sprintf(path, "kitty%03d", j);
 | |
|         lfs_dir_read(&lfs, &dir, &info) => 1;
 | |
|         assert(strcmp(info.name, path) == 0);
 | |
|         assert(info.type == LFS_TYPE_DIR);
 | |
| 
 | |
|         lfs_dir_close(&lfs, &dir) => 0;
 | |
|         lfs_unmount(&lfs) => 0;
 | |
|     }
 | |
| '''
 | |
| 
 | |
| [[case]] # root seek
 | |
| define.COUNT = [4, 128, 132]
 | |
| code = '''
 | |
|     lfs_formatcfg(&lfs, &cfg) => 0;
 | |
|     lfs_mountcfg(&lfs, &cfg) => 0;
 | |
|     for (int i = 0; i < COUNT; i++) {
 | |
|         sprintf(path, "hi%03d", i);
 | |
|         lfs_mkdir(&lfs, path) => 0;
 | |
|     }
 | |
|     lfs_unmount(&lfs) => 0;
 | |
| 
 | |
|     for (int j = 2; j < COUNT; j++) {
 | |
|         lfs_mountcfg(&lfs, &cfg) => 0;
 | |
|         lfs_dir_open(&lfs, &dir, "/") => 0;
 | |
|         lfs_dir_read(&lfs, &dir, &info) => 1;
 | |
|         assert(strcmp(info.name, ".") == 0);
 | |
|         assert(info.type == LFS_TYPE_DIR);
 | |
|         lfs_dir_read(&lfs, &dir, &info) => 1;
 | |
|         assert(strcmp(info.name, "..") == 0);
 | |
|         assert(info.type == LFS_TYPE_DIR);
 | |
| 
 | |
|         lfs_soff_t pos;
 | |
|         for (int i = 0; i < j; i++) {
 | |
|             sprintf(path, "hi%03d", i);
 | |
|             lfs_dir_read(&lfs, &dir, &info) => 1;
 | |
|             assert(strcmp(info.name, path) == 0);
 | |
|             assert(info.type == LFS_TYPE_DIR);
 | |
|             pos = lfs_dir_tell(&lfs, &dir);
 | |
|             assert(pos >= 0);
 | |
|         }
 | |
| 
 | |
|         lfs_dir_seek(&lfs, &dir, pos) => 0;
 | |
|         sprintf(path, "hi%03d", j);
 | |
|         lfs_dir_read(&lfs, &dir, &info) => 1;
 | |
|         assert(strcmp(info.name, path) == 0);
 | |
|         assert(info.type == LFS_TYPE_DIR);
 | |
| 
 | |
|         lfs_dir_rewind(&lfs, &dir) => 0;
 | |
|         sprintf(path, "hi%03d", 0);
 | |
|         lfs_dir_read(&lfs, &dir, &info) => 1;
 | |
|         assert(strcmp(info.name, ".") == 0);
 | |
|         assert(info.type == LFS_TYPE_DIR);
 | |
|         lfs_dir_read(&lfs, &dir, &info) => 1;
 | |
|         assert(strcmp(info.name, "..") == 0);
 | |
|         assert(info.type == LFS_TYPE_DIR);
 | |
|         lfs_dir_read(&lfs, &dir, &info) => 1;
 | |
|         assert(strcmp(info.name, path) == 0);
 | |
|         assert(info.type == LFS_TYPE_DIR);
 | |
| 
 | |
|         lfs_dir_seek(&lfs, &dir, pos) => 0;
 | |
|         sprintf(path, "hi%03d", j);
 | |
|         lfs_dir_read(&lfs, &dir, &info) => 1;
 | |
|         assert(strcmp(info.name, path) == 0);
 | |
|         assert(info.type == LFS_TYPE_DIR);
 | |
| 
 | |
|         lfs_dir_close(&lfs, &dir) => 0;
 | |
|         lfs_unmount(&lfs) => 0;
 | |
|     }
 | |
| '''
 | |
| 
 |