1[cases.test_attrs_get_set]
2code = '''
3    lfs_t lfs;
4    lfs_format(&lfs, cfg) => 0;
5    lfs_mount(&lfs, cfg) => 0;
6    lfs_mkdir(&lfs, "hello") => 0;
7    lfs_file_t file;
8    lfs_file_open(&lfs, &file, "hello/hello", LFS_O_WRONLY | LFS_O_CREAT) => 0;
9    lfs_file_write(&lfs, &file, "hello", strlen("hello")) => strlen("hello");
10    lfs_file_close(&lfs, &file);
11    lfs_unmount(&lfs) => 0;
12
13    lfs_mount(&lfs, cfg) => 0;
14    uint8_t buffer[1024];
15    memset(buffer, 0, sizeof(buffer));
16    lfs_setattr(&lfs, "hello", 'A', "aaaa",   4) => 0;
17    lfs_setattr(&lfs, "hello", 'B', "bbbbbb", 6) => 0;
18    lfs_setattr(&lfs, "hello", 'C', "ccccc",  5) => 0;
19    lfs_getattr(&lfs, "hello", 'A', buffer,    4) => 4;
20    lfs_getattr(&lfs, "hello", 'B', buffer+4,  6) => 6;
21    lfs_getattr(&lfs, "hello", 'C', buffer+10, 5) => 5;
22    memcmp(buffer,    "aaaa",   4) => 0;
23    memcmp(buffer+4,  "bbbbbb", 6) => 0;
24    memcmp(buffer+10, "ccccc",  5) => 0;
25
26    lfs_setattr(&lfs, "hello", 'B', "", 0) => 0;
27    lfs_getattr(&lfs, "hello", 'A', buffer,    4) => 4;
28    lfs_getattr(&lfs, "hello", 'B', buffer+4,  6) => 0;
29    lfs_getattr(&lfs, "hello", 'C', buffer+10, 5) => 5;
30    memcmp(buffer,    "aaaa",         4) => 0;
31    memcmp(buffer+4,  "\0\0\0\0\0\0", 6) => 0;
32    memcmp(buffer+10, "ccccc",        5) => 0;
33
34    lfs_removeattr(&lfs, "hello", 'B') => 0;
35    lfs_getattr(&lfs, "hello", 'A', buffer,    4) => 4;
36    lfs_getattr(&lfs, "hello", 'B', buffer+4,  6) => LFS_ERR_NOATTR;
37    lfs_getattr(&lfs, "hello", 'C', buffer+10, 5) => 5;
38    memcmp(buffer,    "aaaa",         4) => 0;
39    memcmp(buffer+4,  "\0\0\0\0\0\0", 6) => 0;
40    memcmp(buffer+10, "ccccc",        5) => 0;
41
42    lfs_setattr(&lfs, "hello", 'B', "dddddd", 6) => 0;
43    lfs_getattr(&lfs, "hello", 'A', buffer,    4) => 4;
44    lfs_getattr(&lfs, "hello", 'B', buffer+4,  6) => 6;
45    lfs_getattr(&lfs, "hello", 'C', buffer+10, 5) => 5;
46    memcmp(buffer,    "aaaa",   4) => 0;
47    memcmp(buffer+4,  "dddddd", 6) => 0;
48    memcmp(buffer+10, "ccccc",  5) => 0;
49
50    lfs_setattr(&lfs, "hello", 'B', "eee", 3) => 0;
51    lfs_getattr(&lfs, "hello", 'A', buffer,    4) => 4;
52    lfs_getattr(&lfs, "hello", 'B', buffer+4,  6) => 3;
53    lfs_getattr(&lfs, "hello", 'C', buffer+10, 5) => 5;
54    memcmp(buffer,    "aaaa",      4) => 0;
55    memcmp(buffer+4,  "eee\0\0\0", 6) => 0;
56    memcmp(buffer+10, "ccccc",     5) => 0;
57
58    lfs_setattr(&lfs, "hello", 'A', buffer, LFS_ATTR_MAX+1) => LFS_ERR_NOSPC;
59    lfs_setattr(&lfs, "hello", 'B', "fffffffff", 9) => 0;
60    lfs_getattr(&lfs, "hello", 'A', buffer,    4) => 4;
61    lfs_getattr(&lfs, "hello", 'B', buffer+4,  6) => 9;
62    lfs_getattr(&lfs, "hello", 'C', buffer+10, 5) => 5;
63
64    lfs_unmount(&lfs) => 0;
65
66    lfs_mount(&lfs, cfg) => 0;
67    memset(buffer, 0, sizeof(buffer));
68    lfs_getattr(&lfs, "hello", 'A', buffer,    4) => 4;
69    lfs_getattr(&lfs, "hello", 'B', buffer+4,  9) => 9;
70    lfs_getattr(&lfs, "hello", 'C', buffer+13, 5) => 5;
71    memcmp(buffer,    "aaaa",      4) => 0;
72    memcmp(buffer+4,  "fffffffff", 9) => 0;
73    memcmp(buffer+13, "ccccc",     5) => 0;
74
75    lfs_file_open(&lfs, &file, "hello/hello", LFS_O_RDONLY) => 0;
76    lfs_file_read(&lfs, &file, buffer, sizeof(buffer)) => strlen("hello");
77    memcmp(buffer, "hello", strlen("hello")) => 0;
78    lfs_file_close(&lfs, &file);
79    lfs_unmount(&lfs) => 0;
80'''
81
82[cases.test_attrs_get_set_root]
83code = '''
84    lfs_t lfs;
85    lfs_format(&lfs, cfg) => 0;
86    lfs_mount(&lfs, cfg) => 0;
87    lfs_mkdir(&lfs, "hello") => 0;
88    lfs_file_t file;
89    lfs_file_open(&lfs, &file, "hello/hello", LFS_O_WRONLY | LFS_O_CREAT) => 0;
90    lfs_file_write(&lfs, &file, "hello", strlen("hello")) => strlen("hello");
91    lfs_file_close(&lfs, &file);
92    lfs_unmount(&lfs) => 0;
93
94    lfs_mount(&lfs, cfg) => 0;
95    uint8_t buffer[1024];
96    memset(buffer, 0, sizeof(buffer));
97    lfs_setattr(&lfs, "/", 'A', "aaaa",   4) => 0;
98    lfs_setattr(&lfs, "/", 'B', "bbbbbb", 6) => 0;
99    lfs_setattr(&lfs, "/", 'C', "ccccc",  5) => 0;
100    lfs_getattr(&lfs, "/", 'A', buffer,    4) => 4;
101    lfs_getattr(&lfs, "/", 'B', buffer+4,  6) => 6;
102    lfs_getattr(&lfs, "/", 'C', buffer+10, 5) => 5;
103    memcmp(buffer,    "aaaa",   4) => 0;
104    memcmp(buffer+4,  "bbbbbb", 6) => 0;
105    memcmp(buffer+10, "ccccc",  5) => 0;
106
107    lfs_setattr(&lfs, "/", 'B', "", 0) => 0;
108    lfs_getattr(&lfs, "/", 'A', buffer,    4) => 4;
109    lfs_getattr(&lfs, "/", 'B', buffer+4,  6) => 0;
110    lfs_getattr(&lfs, "/", 'C', buffer+10, 5) => 5;
111    memcmp(buffer,    "aaaa",         4) => 0;
112    memcmp(buffer+4,  "\0\0\0\0\0\0", 6) => 0;
113    memcmp(buffer+10, "ccccc",        5) => 0;
114
115    lfs_removeattr(&lfs, "/", 'B') => 0;
116    lfs_getattr(&lfs, "/", 'A', buffer,    4) => 4;
117    lfs_getattr(&lfs, "/", 'B', buffer+4,  6) => LFS_ERR_NOATTR;
118    lfs_getattr(&lfs, "/", 'C', buffer+10, 5) => 5;
119    memcmp(buffer,    "aaaa",         4) => 0;
120    memcmp(buffer+4,  "\0\0\0\0\0\0", 6) => 0;
121    memcmp(buffer+10, "ccccc",        5) => 0;
122
123    lfs_setattr(&lfs, "/", 'B', "dddddd", 6) => 0;
124    lfs_getattr(&lfs, "/", 'A', buffer,    4) => 4;
125    lfs_getattr(&lfs, "/", 'B', buffer+4,  6) => 6;
126    lfs_getattr(&lfs, "/", 'C', buffer+10, 5) => 5;
127    memcmp(buffer,    "aaaa",   4) => 0;
128    memcmp(buffer+4,  "dddddd", 6) => 0;
129    memcmp(buffer+10, "ccccc",  5) => 0;
130
131    lfs_setattr(&lfs, "/", 'B', "eee", 3) => 0;
132    lfs_getattr(&lfs, "/", 'A', buffer,    4) => 4;
133    lfs_getattr(&lfs, "/", 'B', buffer+4,  6) => 3;
134    lfs_getattr(&lfs, "/", 'C', buffer+10, 5) => 5;
135    memcmp(buffer,    "aaaa",      4) => 0;
136    memcmp(buffer+4,  "eee\0\0\0", 6) => 0;
137    memcmp(buffer+10, "ccccc",     5) => 0;
138
139    lfs_setattr(&lfs, "/", 'A', buffer, LFS_ATTR_MAX+1) => LFS_ERR_NOSPC;
140    lfs_setattr(&lfs, "/", 'B', "fffffffff", 9) => 0;
141    lfs_getattr(&lfs, "/", 'A', buffer,    4) => 4;
142    lfs_getattr(&lfs, "/", 'B', buffer+4,  6) => 9;
143    lfs_getattr(&lfs, "/", 'C', buffer+10, 5) => 5;
144    lfs_unmount(&lfs) => 0;
145
146    lfs_mount(&lfs, cfg) => 0;
147    memset(buffer, 0, sizeof(buffer));
148    lfs_getattr(&lfs, "/", 'A', buffer,    4) => 4;
149    lfs_getattr(&lfs, "/", 'B', buffer+4,  9) => 9;
150    lfs_getattr(&lfs, "/", 'C', buffer+13, 5) => 5;
151    memcmp(buffer,    "aaaa",      4) => 0;
152    memcmp(buffer+4,  "fffffffff", 9) => 0;
153    memcmp(buffer+13, "ccccc",     5) => 0;
154
155    lfs_file_open(&lfs, &file, "hello/hello", LFS_O_RDONLY) => 0;
156    lfs_file_read(&lfs, &file, buffer, sizeof(buffer)) => strlen("hello");
157    memcmp(buffer, "hello", strlen("hello")) => 0;
158    lfs_file_close(&lfs, &file);
159    lfs_unmount(&lfs) => 0;
160'''
161
162[cases.test_attrs_get_set_file]
163code = '''
164    lfs_t lfs;
165    lfs_format(&lfs, cfg) => 0;
166    lfs_mount(&lfs, cfg) => 0;
167    lfs_mkdir(&lfs, "hello") => 0;
168    lfs_file_t file;
169    lfs_file_open(&lfs, &file, "hello/hello", LFS_O_WRONLY | LFS_O_CREAT) => 0;
170    lfs_file_write(&lfs, &file, "hello", strlen("hello")) => strlen("hello");
171    lfs_file_close(&lfs, &file);
172    lfs_unmount(&lfs) => 0;
173
174    lfs_mount(&lfs, cfg) => 0;
175    uint8_t buffer[1024];
176    memset(buffer, 0, sizeof(buffer));
177    struct lfs_attr attrs1[] = {
178        {'A', buffer,    4},
179        {'B', buffer+4,  6},
180        {'C', buffer+10, 5},
181    };
182    struct lfs_file_config cfg1 = {.attrs=attrs1, .attr_count=3};
183
184    lfs_file_opencfg(&lfs, &file, "hello/hello", LFS_O_WRONLY, &cfg1) => 0;
185    memcpy(buffer,    "aaaa",   4);
186    memcpy(buffer+4,  "bbbbbb", 6);
187    memcpy(buffer+10, "ccccc",  5);
188    lfs_file_close(&lfs, &file) => 0;
189    memset(buffer, 0, 15);
190    lfs_file_opencfg(&lfs, &file, "hello/hello", LFS_O_RDONLY, &cfg1) => 0;
191    lfs_file_close(&lfs, &file) => 0;
192    memcmp(buffer,    "aaaa",   4) => 0;
193    memcmp(buffer+4,  "bbbbbb", 6) => 0;
194    memcmp(buffer+10, "ccccc",  5) => 0;
195
196    attrs1[1].size = 0;
197    lfs_file_opencfg(&lfs, &file, "hello/hello", LFS_O_WRONLY, &cfg1) => 0;
198    lfs_file_close(&lfs, &file) => 0;
199    memset(buffer, 0, 15);
200    attrs1[1].size = 6;
201    lfs_file_opencfg(&lfs, &file, "hello/hello", LFS_O_RDONLY, &cfg1) => 0;
202    lfs_file_close(&lfs, &file) => 0;
203    memcmp(buffer,    "aaaa",         4) => 0;
204    memcmp(buffer+4,  "\0\0\0\0\0\0", 6) => 0;
205    memcmp(buffer+10, "ccccc",        5) => 0;
206
207    attrs1[1].size = 6;
208    lfs_file_opencfg(&lfs, &file, "hello/hello", LFS_O_WRONLY, &cfg1) => 0;
209    memcpy(buffer+4,  "dddddd", 6);
210    lfs_file_close(&lfs, &file) => 0;
211    memset(buffer, 0, 15);
212    attrs1[1].size = 6;
213    lfs_file_opencfg(&lfs, &file, "hello/hello", LFS_O_RDONLY, &cfg1) => 0;
214    lfs_file_close(&lfs, &file) => 0;
215    memcmp(buffer,    "aaaa",   4) => 0;
216    memcmp(buffer+4,  "dddddd", 6) => 0;
217    memcmp(buffer+10, "ccccc",  5) => 0;
218
219    attrs1[1].size = 3;
220    lfs_file_opencfg(&lfs, &file, "hello/hello", LFS_O_WRONLY, &cfg1) => 0;
221    memcpy(buffer+4,  "eee", 3);
222    lfs_file_close(&lfs, &file) => 0;
223    memset(buffer, 0, 15);
224    attrs1[1].size = 6;
225    lfs_file_opencfg(&lfs, &file, "hello/hello", LFS_O_RDONLY, &cfg1) => 0;
226    lfs_file_close(&lfs, &file) => 0;
227    memcmp(buffer,    "aaaa",      4) => 0;
228    memcmp(buffer+4,  "eee\0\0\0", 6) => 0;
229    memcmp(buffer+10, "ccccc",     5) => 0;
230
231    attrs1[0].size = LFS_ATTR_MAX+1;
232    lfs_file_opencfg(&lfs, &file, "hello/hello", LFS_O_WRONLY, &cfg1)
233        => LFS_ERR_NOSPC;
234
235    struct lfs_attr attrs2[] = {
236        {'A', buffer,    4},
237        {'B', buffer+4,  9},
238        {'C', buffer+13, 5},
239    };
240    struct lfs_file_config cfg2 = {.attrs=attrs2, .attr_count=3};
241    lfs_file_opencfg(&lfs, &file, "hello/hello", LFS_O_RDWR, &cfg2) => 0;
242    memcpy(buffer+4,  "fffffffff", 9);
243    lfs_file_close(&lfs, &file) => 0;
244    attrs1[0].size = 4;
245    lfs_file_opencfg(&lfs, &file, "hello/hello", LFS_O_RDONLY, &cfg1) => 0;
246    lfs_file_close(&lfs, &file) => 0;
247
248    lfs_unmount(&lfs) => 0;
249
250    lfs_mount(&lfs, cfg) => 0;
251    memset(buffer, 0, sizeof(buffer));
252    struct lfs_attr attrs3[] = {
253        {'A', buffer,    4},
254        {'B', buffer+4,  9},
255        {'C', buffer+13, 5},
256    };
257    struct lfs_file_config cfg3 = {.attrs=attrs3, .attr_count=3};
258
259    lfs_file_opencfg(&lfs, &file, "hello/hello", LFS_O_RDONLY, &cfg3) => 0;
260    lfs_file_close(&lfs, &file) => 0;
261    memcmp(buffer,    "aaaa",      4) => 0;
262    memcmp(buffer+4,  "fffffffff", 9) => 0;
263    memcmp(buffer+13, "ccccc",     5) => 0;
264
265    lfs_file_open(&lfs, &file, "hello/hello", LFS_O_RDONLY) => 0;
266    lfs_file_read(&lfs, &file, buffer, sizeof(buffer)) => strlen("hello");
267    memcmp(buffer, "hello", strlen("hello")) => 0;
268    lfs_file_close(&lfs, &file);
269    lfs_unmount(&lfs) => 0;
270'''
271
272[cases.test_attrs_deferred_file]
273code = '''
274    lfs_t lfs;
275    lfs_format(&lfs, cfg) => 0;
276    lfs_mount(&lfs, cfg) => 0;
277    lfs_mkdir(&lfs, "hello") => 0;
278    lfs_file_t file;
279    lfs_file_open(&lfs, &file, "hello/hello", LFS_O_WRONLY | LFS_O_CREAT) => 0;
280    lfs_file_write(&lfs, &file, "hello", strlen("hello")) => strlen("hello");
281    lfs_file_close(&lfs, &file);
282    lfs_unmount(&lfs) => 0;
283
284    lfs_mount(&lfs, cfg) => 0;
285    lfs_setattr(&lfs, "hello/hello", 'B', "fffffffff",  9) => 0;
286    lfs_setattr(&lfs, "hello/hello", 'C', "ccccc",      5) => 0;
287
288    uint8_t buffer[1024];
289    memset(buffer, 0, sizeof(buffer));
290    struct lfs_attr attrs1[] = {
291        {'B', "gggg", 4},
292        {'C', "",     0},
293        {'D', "hhhh", 4},
294    };
295    struct lfs_file_config cfg1 = {.attrs=attrs1, .attr_count=3};
296
297    lfs_file_opencfg(&lfs, &file, "hello/hello", LFS_O_WRONLY, &cfg1) => 0;
298
299    lfs_getattr(&lfs, "hello/hello", 'B', buffer,    9) => 9;
300    lfs_getattr(&lfs, "hello/hello", 'C', buffer+9,  9) => 5;
301    lfs_getattr(&lfs, "hello/hello", 'D', buffer+18, 9) => LFS_ERR_NOATTR;
302    memcmp(buffer,    "fffffffff",          9) => 0;
303    memcmp(buffer+9,  "ccccc\0\0\0\0",      9) => 0;
304    memcmp(buffer+18, "\0\0\0\0\0\0\0\0\0", 9) => 0;
305
306    lfs_file_sync(&lfs, &file) => 0;
307    lfs_getattr(&lfs, "hello/hello", 'B', buffer,    9) => 4;
308    lfs_getattr(&lfs, "hello/hello", 'C', buffer+9,  9) => 0;
309    lfs_getattr(&lfs, "hello/hello", 'D', buffer+18, 9) => 4;
310    memcmp(buffer,    "gggg\0\0\0\0\0",     9) => 0;
311    memcmp(buffer+9,  "\0\0\0\0\0\0\0\0\0", 9) => 0;
312    memcmp(buffer+18, "hhhh\0\0\0\0\0",     9) => 0;
313
314    lfs_file_close(&lfs, &file) => 0;
315    lfs_unmount(&lfs) => 0;
316'''
317