@@ -14,6 +14,24 @@ code = '''
14
14
lfs_unmount(&lfs) => 0;
15
15
'''
16
16
17
+ # make sure the magic string "littlefs" is always at offset=8
18
+ [cases .test_superblocks_magic ]
19
+ code = '''
20
+ lfs_t lfs;
21
+ lfs_format(&lfs, cfg) => 0;
22
+
23
+ // check our magic string
24
+ //
25
+ // note if we lose power we may not have the magic string in both blocks!
26
+ // but we don't lose power in this test so we can assert the magic string
27
+ // is present in both
28
+ uint8_t magic[lfs_max(16, READ_SIZE)];
29
+ cfg->read(cfg, 0, 0, magic, lfs_max(16, READ_SIZE)) => 0;
30
+ assert(memcmp(&magic[8], "littlefs", 8) == 0);
31
+ cfg->read(cfg, 1, 0, magic, lfs_max(16, READ_SIZE)) => 0;
32
+ assert(memcmp(&magic[8], "littlefs", 8) == 0);
33
+ '''
34
+
17
35
# mount/unmount from interpretting a previous superblock block_count
18
36
[cases .test_superblocks_mount_unknown_block_count ]
19
37
code = '''
@@ -28,7 +46,6 @@ code = '''
28
46
lfs_unmount(&lfs) => 0;
29
47
'''
30
48
31
-
32
49
# reentrant format
33
50
[cases .test_superblocks_reentrant_format ]
34
51
reentrant = true
@@ -135,6 +152,39 @@ code = '''
135
152
lfs_unmount(&lfs) => 0;
136
153
'''
137
154
155
+ # make sure the magic string "littlefs" is always at offset=8
156
+ [cases .test_superblocks_magic_expand ]
157
+ defines.BLOCK_CYCLES = [32 , 33 , 1 ]
158
+ defines.N = [10 , 100 , 1000 ]
159
+ code = '''
160
+ lfs_t lfs;
161
+ lfs_format(&lfs, cfg) => 0;
162
+ lfs_mount(&lfs, cfg) => 0;
163
+ for (int i = 0; i < N; i++) {
164
+ lfs_file_t file;
165
+ lfs_file_open(&lfs, &file, "dummy",
166
+ LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
167
+ lfs_file_close(&lfs, &file) => 0;
168
+ struct lfs_info info;
169
+ lfs_stat(&lfs, "dummy", &info) => 0;
170
+ assert(strcmp(info.name, "dummy") == 0);
171
+ assert(info.type == LFS_TYPE_REG);
172
+ lfs_remove(&lfs, "dummy") => 0;
173
+ }
174
+ lfs_unmount(&lfs) => 0;
175
+
176
+ // check our magic string
177
+ //
178
+ // note if we lose power we may not have the magic string in both blocks!
179
+ // but we don't lose power in this test so we can assert the magic string
180
+ // is present in both
181
+ uint8_t magic[lfs_max(16, READ_SIZE)];
182
+ cfg->read(cfg, 0, 0, magic, lfs_max(16, READ_SIZE)) => 0;
183
+ assert(memcmp(&magic[8], "littlefs", 8) == 0);
184
+ cfg->read(cfg, 1, 0, magic, lfs_max(16, READ_SIZE)) => 0;
185
+ assert(memcmp(&magic[8], "littlefs", 8) == 0);
186
+ '''
187
+
138
188
# expanding superblock with power cycle
139
189
[cases .test_superblocks_expand_power_cycle ]
140
190
defines.BLOCK_CYCLES = [32 , 33 , 1 ]
@@ -221,6 +271,7 @@ code = '''
221
271
lfs_unmount(&lfs) => 0;
222
272
'''
223
273
274
+
224
275
# mount with unknown block_count
225
276
[cases .test_superblocks_unknown_blocks ]
226
277
code = '''
0 commit comments