@@ -126,6 +126,83 @@ code = '''
126126    lfs_unmount(&lfs) => 0; 
127127''' 
128128
129+ #  test that we can persist gstate with lfs_fs_mkconsistent
130+ [cases .test_orphans_mkconsistent_no_orphans ]
131+ in  = ' lfs.c' 
132+ code  = ''' 
133+     lfs_t lfs; 
134+     lfs_format(&lfs, cfg) => 0; 
135+ 
136+     lfs_mount(&lfs, cfg) => 0; 
137+     // mark the filesystem as having orphans 
138+     lfs_fs_preporphans(&lfs, +1) => 0; 
139+     lfs_mdir_t mdir; 
140+     lfs_dir_fetch(&lfs, &mdir, (lfs_block_t[2]){0, 1}) => 0; 
141+     lfs_dir_commit(&lfs, &mdir, NULL, 0) => 0; 
142+ 
143+     // we should have orphans at this state 
144+     assert(lfs_gstate_hasorphans(&lfs.gstate)); 
145+     lfs_unmount(&lfs) => 0; 
146+ 
147+     // mount 
148+     lfs_mount(&lfs, cfg) => 0; 
149+     // we should detect orphans 
150+     assert(lfs_gstate_hasorphans(&lfs.gstate)); 
151+     // force consistency 
152+     lfs_fs_mkconsistent(&lfs) => 0; 
153+     // we should no longer have orphans 
154+     assert(!lfs_gstate_hasorphans(&lfs.gstate)); 
155+ 
156+     // remount 
157+     lfs_unmount(&lfs) => 0; 
158+     lfs_mount(&lfs, cfg) => 0; 
159+     // we should still have no orphans 
160+     assert(!lfs_gstate_hasorphans(&lfs.gstate)); 
161+     lfs_unmount(&lfs) => 0; 
162+ ''' 
163+ 
164+ [cases .test_orphans_mkconsistent_one_orphan ]
165+ in  = ' lfs.c' 
166+ code  = ''' 
167+     lfs_t lfs; 
168+     lfs_format(&lfs, cfg) => 0; 
169+ 
170+     lfs_mount(&lfs, cfg) => 0; 
171+     // create an orphan 
172+     lfs_mdir_t orphan; 
173+     lfs_alloc_ack(&lfs); 
174+     lfs_dir_alloc(&lfs, &orphan) => 0; 
175+     lfs_dir_commit(&lfs, &orphan, NULL, 0) => 0; 
176+ 
177+     // append our orphan and mark the filesystem as having orphans 
178+     lfs_fs_preporphans(&lfs, +1) => 0; 
179+     lfs_mdir_t mdir; 
180+     lfs_dir_fetch(&lfs, &mdir, (lfs_block_t[2]){0, 1}) => 0; 
181+     lfs_pair_tole32(orphan.pair); 
182+     lfs_dir_commit(&lfs, &mdir, LFS_MKATTRS( 
183+             {LFS_MKTAG(LFS_TYPE_SOFTTAIL, 0x3ff, 8), orphan.pair})) => 0; 
184+ 
185+     // we should have orphans at this state 
186+     assert(lfs_gstate_hasorphans(&lfs.gstate)); 
187+     lfs_unmount(&lfs) => 0; 
188+ 
189+     // mount 
190+     lfs_mount(&lfs, cfg) => 0; 
191+     // we should detect orphans 
192+     assert(lfs_gstate_hasorphans(&lfs.gstate)); 
193+     // force consistency 
194+     lfs_fs_mkconsistent(&lfs) => 0; 
195+     // we should no longer have orphans 
196+     assert(!lfs_gstate_hasorphans(&lfs.gstate)); 
197+ 
198+     // remount 
199+     lfs_unmount(&lfs) => 0; 
200+     lfs_mount(&lfs, cfg) => 0; 
201+     // we should still have no orphans 
202+     assert(!lfs_gstate_hasorphans(&lfs.gstate)); 
203+     lfs_unmount(&lfs) => 0; 
204+ ''' 
205+ 
129206#  reentrant testing for orphans, basically just spam mkdir/remove
130207[cases .test_orphans_reentrant ]
131208reentrant  = true 
0 commit comments