mirror of
				https://github.com/eledio-devices/thirdparty-littlefs.git
				synced 2025-10-31 08:42:40 +01:00 
			
		
		
		
	Changed custom attribute descriptors to used arrays
While linked-lists do have some minor benefits, arrays are more idiomatic in C and may provide a more intuitive API. Initially the linked-list approach was more beneficial than it is now, since it allowed custom attributes to be chained to internal linked lists of attributes. However, this was dropped because exposing the internal attribute list in this way created a rather messy user interface that required strictly encoding the attributes with the on-disk tag format. Minor downside, users can no longer introduce custom attributes in different layers (think OS vs app). Minor upside, the code size and stack usage was reduced a bit. Fortunately, this API can always be changed in the future without breaking anything (except maybe API compatibility).
This commit is contained in:
		| @@ -156,10 +156,12 @@ TEST | ||||
| echo "--- Set/get file attribute ---" | ||||
| tests/test.py << TEST | ||||
|     lfs_mount(&lfs, &cfg) => 0; | ||||
|     struct lfs_attr a1 = {'A', buffer,    4}; | ||||
|     struct lfs_attr b1 = {'B', buffer+4,  6, &a1}; | ||||
|     struct lfs_attr c1 = {'C', buffer+10, 5, &b1}; | ||||
|     struct lfs_file_config cfg1 = {.attrs = &c1}; | ||||
|     struct lfs_attr attrs1[] = { | ||||
|         {'A', buffer,    4}, | ||||
|         {'B', buffer+4,  6}, | ||||
|         {'C', buffer+10, 5}, | ||||
|     }; | ||||
|     struct lfs_file_config cfg1 = {.attrs=attrs1, .attr_count=3}; | ||||
|  | ||||
|     lfs_file_opencfg(&lfs, &file[0], "hello/hello", LFS_O_WRONLY, &cfg1) => 0; | ||||
|     memcpy(buffer,    "aaaa",   4); | ||||
| @@ -173,53 +175,55 @@ tests/test.py << TEST | ||||
|     memcmp(buffer+4,  "bbbbbb", 6) => 0; | ||||
|     memcmp(buffer+10, "ccccc",  5) => 0; | ||||
|  | ||||
|     b1.size = 0; | ||||
|     attrs1[1].size = 0; | ||||
|     lfs_file_opencfg(&lfs, &file[0], "hello/hello", LFS_O_WRONLY, &cfg1) => 0; | ||||
|     lfs_file_close(&lfs, &file[0]) => 0; | ||||
|     memset(buffer, 0, 15); | ||||
|     b1.size = 6; | ||||
|     attrs1[1].size = 6; | ||||
|     lfs_file_opencfg(&lfs, &file[0], "hello/hello", LFS_O_RDONLY, &cfg1) => 0; | ||||
|     lfs_file_close(&lfs, &file[0]) => 0; | ||||
|     memcmp(buffer,    "aaaa",         4) => 0; | ||||
|     memcmp(buffer+4,  "\0\0\0\0\0\0", 6) => 0; | ||||
|     memcmp(buffer+10, "ccccc",        5) => 0; | ||||
|  | ||||
|     b1.size = 6; | ||||
|     attrs1[1].size = 6; | ||||
|     lfs_file_opencfg(&lfs, &file[0], "hello/hello", LFS_O_WRONLY, &cfg1) => 0; | ||||
|     memcpy(buffer+4,  "dddddd", 6); | ||||
|     lfs_file_close(&lfs, &file[0]) => 0; | ||||
|     memset(buffer, 0, 15); | ||||
|     b1.size = 6; | ||||
|     attrs1[1].size = 6; | ||||
|     lfs_file_opencfg(&lfs, &file[0], "hello/hello", LFS_O_RDONLY, &cfg1) => 0; | ||||
|     lfs_file_close(&lfs, &file[0]) => 0; | ||||
|     memcmp(buffer,    "aaaa",   4) => 0; | ||||
|     memcmp(buffer+4,  "dddddd", 6) => 0; | ||||
|     memcmp(buffer+10, "ccccc",  5) => 0; | ||||
|  | ||||
|     b1.size = 3; | ||||
|     attrs1[1].size = 3; | ||||
|     lfs_file_opencfg(&lfs, &file[0], "hello/hello", LFS_O_WRONLY, &cfg1) => 0; | ||||
|     memcpy(buffer+4,  "eee", 3); | ||||
|     lfs_file_close(&lfs, &file[0]) => 0; | ||||
|     memset(buffer, 0, 15); | ||||
|     b1.size = 6; | ||||
|     attrs1[1].size = 6; | ||||
|     lfs_file_opencfg(&lfs, &file[0], "hello/hello", LFS_O_RDONLY, &cfg1) => 0; | ||||
|     lfs_file_close(&lfs, &file[0]) => 0; | ||||
|     memcmp(buffer,    "aaaa",      4) => 0; | ||||
|     memcmp(buffer+4,  "eee\0\0\0", 6) => 0; | ||||
|     memcmp(buffer+10, "ccccc",     5) => 0; | ||||
|  | ||||
|     a1.size = LFS_ATTR_MAX+1; | ||||
|     attrs1[0].size = LFS_ATTR_MAX+1; | ||||
|     lfs_file_opencfg(&lfs, &file[0], "hello/hello", LFS_O_WRONLY, &cfg1) | ||||
|         => LFS_ERR_NOSPC; | ||||
|  | ||||
|     struct lfs_attr a2 = {'A', buffer,    4}; | ||||
|     struct lfs_attr b2 = {'B', buffer+4,  9, &a2}; | ||||
|     struct lfs_attr c2 = {'C', buffer+13, 5, &b2}; | ||||
|     struct lfs_file_config cfg2 = {.attrs = &c2}; | ||||
|     struct lfs_attr attrs2[] = { | ||||
|         {'A', buffer,    4}, | ||||
|         {'B', buffer+4,  9}, | ||||
|         {'C', buffer+13, 5}, | ||||
|     }; | ||||
|     struct lfs_file_config cfg2 = {.attrs=attrs2, .attr_count=3}; | ||||
|     lfs_file_opencfg(&lfs, &file[0], "hello/hello", LFS_O_RDWR, &cfg2) => 0; | ||||
|     memcpy(buffer+4,  "fffffffff", 9); | ||||
|     lfs_file_close(&lfs, &file[0]) => 0; | ||||
|     a1.size = 4; | ||||
|     attrs1[0].size = 4; | ||||
|     lfs_file_opencfg(&lfs, &file[0], "hello/hello", LFS_O_RDONLY, &cfg1) => 0; | ||||
|     lfs_file_close(&lfs, &file[0]) => 0; | ||||
|  | ||||
| @@ -227,10 +231,12 @@ tests/test.py << TEST | ||||
| TEST | ||||
| tests/test.py << TEST | ||||
|     lfs_mount(&lfs, &cfg) => 0; | ||||
|     struct lfs_attr a2 = {'A', buffer,    4}; | ||||
|     struct lfs_attr b2 = {'B', buffer+4,  9, &a2}; | ||||
|     struct lfs_attr c2 = {'C', buffer+13, 5, &b2}; | ||||
|     struct lfs_file_config cfg2 = {.attrs = &c2}; | ||||
|     struct lfs_attr attrs2[] = { | ||||
|         {'A', buffer,    4}, | ||||
|         {'B', buffer+4,  9}, | ||||
|         {'C', buffer+13, 5}, | ||||
|     }; | ||||
|     struct lfs_file_config cfg2 = {.attrs=attrs2, .attr_count=3}; | ||||
|  | ||||
|     lfs_file_opencfg(&lfs, &file[0], "hello/hello", LFS_O_RDONLY, &cfg2) => 0; | ||||
|     lfs_file_close(&lfs, &file[0]) => 0; | ||||
| @@ -248,10 +254,12 @@ TEST | ||||
| echo "--- Deferred file attributes ---" | ||||
| tests/test.py << TEST | ||||
|     lfs_mount(&lfs, &cfg) => 0; | ||||
|     struct lfs_attr a1 = {'B', "gggg", 4}; | ||||
|     struct lfs_attr b1 = {'C', "",     0, &a1}; | ||||
|     struct lfs_attr c1 = {'D', "hhhh", 4, &b1}; | ||||
|     struct lfs_file_config cfg1 = {.attrs = &c1}; | ||||
|     struct lfs_attr attrs1[] = { | ||||
|         {'B', "gggg", 4}, | ||||
|         {'C', "",     0}, | ||||
|         {'D', "hhhh", 4}, | ||||
|     }; | ||||
|     struct lfs_file_config cfg1 = {.attrs=attrs1, .attr_count=3}; | ||||
|  | ||||
|     lfs_file_opencfg(&lfs, &file[0], "hello/hello", LFS_O_WRONLY, &cfg1) => 0; | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user