bmap: Added error propagation to ckpoints and cleaned up test TODOs

The main change is error propagation in lfs3_alloc_ckpoint. Since
lfs3_alloc_ckpoint writes to disk during bmap rebuilds, it can now fail
in all sorts of ways. Fortunately lfs3_alloc_ckpoint should only ever be
called by write operations, where these errors are be expected.

With bmap rebuild errors now reported correctly, this unblocks most of
the remaining test TODOs:

- Passing test_badblocks
- Passing test_ck
- Passing test_trvs

With this, LFS3_YES_BMAP is now passing all but two tests, which are
still ifndef-disabled as a temporary measure:

- test_btree - We make some low-level assumptions about the lookahead
  allocator when testing btrees. It's probably not worth trying to get
  this passing with the bmap allocator.

- test_grow - This one does need fixing! We currently don't update
  on-disk bmaps correctly when growing the filesystem.

Code changes minimal:

                code          stack          ctx
  before:      36912           2368          684
  after:       36912 (+0.0%)   2368 (+0.0%)  684 (+0.0%)

                code          stack          ctx
  bmap before: 38456           2400          812
  bmap after:  38512 (+0.1%)   2400 (+0.0%)  812 (+0.0%)
This commit is contained in:
Christopher Haster
2025-07-30 11:44:36 -05:00
parent 41be512272
commit 27e3e10634
6 changed files with 580 additions and 172 deletions
+131 -41
View File
@@ -2380,7 +2380,7 @@ static inline bool lfs3_alloc_iserase(uint32_t flags) {
// blocks are allocated at most once, and never reallocated, between
// checkpoints
#if !defined(LFS3_RDONLY)
static inline void lfs3_alloc_ckpoint(lfs3_t *lfs3);
static inline int lfs3_alloc_ckpoint(lfs3_t *lfs3);
#endif
// discard any lookahead state, this is necessary if block_count changes
@@ -10494,7 +10494,11 @@ dropped:;
: lfs3->cfg->block_size - lfs3->cfg->block_size/8);
// checkpoint the allocator
lfs3_alloc_ckpoint(lfs3);
err = lfs3_alloc_ckpoint(lfs3);
if (err) {
return err;
}
// compact the mdir
err = lfs3_mdir_compact(lfs3, mdir);
if (err) {
@@ -10810,7 +10814,7 @@ static int lfs3_alloc_rebuildbmap(lfs3_t *lfs3);
// blocks are allocated at most once, and never reallocated, between
// checkpoints
#if !defined(LFS3_RDONLY)
static inline void lfs3_alloc_ckpoint(lfs3_t *lfs3) {
static inline int lfs3_alloc_ckpoint(lfs3_t *lfs3) {
#ifndef LFS3_2BONLY
// checkpoint the allocator
lfs3->lookahead.ckpoint = lfs3->block_count;
@@ -10820,14 +10824,15 @@ static inline void lfs3_alloc_ckpoint(lfs3_t *lfs3) {
lfs3->cfg->bmap_scan_thresh,
lfs3->block_count)) {
int err = lfs3_alloc_rebuildbmap(lfs3);
// TODO lfs3_alloc_ckpoint should propagate errors
LFS3_ASSERT(!err);
// // checkpoint the allocator again after rebuilding the bmap
// lfs3->lookahead.ckpoint = lfs3->block_count;
if (err) {
return err;
}
}
#endif
return 0;
#else
(void)lfs3;
return 0;
#endif
}
#endif
@@ -11477,8 +11482,13 @@ int lfs3_mkdir(lfs3_t *lfs3, const char *path) {
// This is done automatically by lfs3_mdir_commit to avoid issues with
// mid updates, since the mid technically doesn't exist yet...
// checkpoint the allocator
err = lfs3_alloc_ckpoint(lfs3);
if (err) {
return err;
}
// commit our bookmark and a grm to self-remove in case of powerloss
lfs3_alloc_ckpoint(lfs3);
err = lfs3_mdir_commit(lfs3, &mdir, LFS3_RATTRS(
LFS3_RATTR_NAME(
LFS3_TAG_BOOKMARK, +1, did_, NULL, 0),
@@ -11500,10 +11510,15 @@ int lfs3_mkdir(lfs3_t *lfs3, const char *path) {
? tag_ >= 0
: tag_ == LFS3_ERR_NOENT);
// checkpoint the allocator
err = lfs3_alloc_ckpoint(lfs3);
if (err) {
return err;
}
// commit our new directory into our parent, zeroing the grm in the
// process
lfs3_grm_pop(lfs3);
lfs3_alloc_ckpoint(lfs3);
err = lfs3_mdir_commit(lfs3, &mdir, LFS3_RATTRS(
LFS3_RATTR_NAME(
LFS3_TAG_MASK12 | LFS3_TAG_DIR,
@@ -11648,8 +11663,13 @@ int lfs3_remove(lfs3_t *lfs3, const char *path) {
// are we removing an opened file?
bool zombie = lfs3_mid_isopen(lfs3, mdir.mid, -1);
// checkpoint the allocator
err = lfs3_alloc_ckpoint(lfs3);
if (err) {
return err;
}
// remove the metadata entry
lfs3_alloc_ckpoint(lfs3);
err = lfs3_mdir_commit(lfs3, &mdir, LFS3_RATTRS(
// create a stickynote if zombied
//
@@ -11828,9 +11848,14 @@ int lfs3_rename(lfs3_t *lfs3, const char *old_path, const char *new_path) {
// mark old entry for removal with a grm
lfs3_grm_push(lfs3, old_mdir.mid);
// checkpoint the allocator
err = lfs3_alloc_ckpoint(lfs3);
if (err) {
return err;
}
// rename our entry, copying all tags associated with the old rid to the
// new rid, while also marking the old rid for removal
lfs3_alloc_ckpoint(lfs3);
err = lfs3_mdir_commit(lfs3, &new_mdir, LFS3_RATTRS(
LFS3_RATTR_NAME(
LFS3_TAG_MASK12 | old_tag,
@@ -12269,8 +12294,13 @@ int lfs3_setattr(lfs3_t *lfs3, const char *path, uint8_t type,
return err;
}
// checkpoint the allocator
err = lfs3_alloc_ckpoint(lfs3);
if (err) {
return err;
}
// commit our attr
lfs3_alloc_ckpoint(lfs3);
err = lfs3_mdir_commit(lfs3, &mdir, LFS3_RATTRS(
LFS3_RATTR_DATA(
LFS3_TAG_ATTR(type), 0,
@@ -12325,8 +12355,13 @@ int lfs3_removeattr(lfs3_t *lfs3, const char *path, uint8_t type) {
return err;
}
// checkpoint the allocator
err = lfs3_alloc_ckpoint(lfs3);
if (err) {
return err;
}
// commit our removal
lfs3_alloc_ckpoint(lfs3);
err = lfs3_mdir_commit(lfs3, &mdir, LFS3_RATTRS(
LFS3_RATTR(
LFS3_TAG_RM | LFS3_TAG_ATTR(type), 0)));
@@ -12623,9 +12658,14 @@ int lfs3_file_opencfg_(lfs3_t *lfs3, lfs3_file_t *file,
}
} else {
// checkpoint the allocator
err = lfs3_alloc_ckpoint(lfs3);
if (err) {
return err;
}
// create a stickynote entry if we don't have one, this
// reserves the mid until first sync
lfs3_alloc_ckpoint(lfs3);
err = lfs3_mdir_commit(lfs3, &file->b.h.mdir, LFS3_RATTRS(
LFS3_RATTR_NAME(
LFS3_TAG_STICKYNOTE, +1,
@@ -13578,9 +13618,13 @@ static int lfs3_file_crystallize(lfs3_t *lfs3, lfs3_file_t *file) {
LFS3_ASSERT(lfs3_o_isunsync(file->b.h.flags));
// checkpoint the allocator
lfs3_alloc_ckpoint(lfs3);
int err = lfs3_alloc_ckpoint(lfs3);
if (err) {
return err;
}
// finish crystallizing
int err = lfs3_file_crystallize_(lfs3, file,
err = lfs3_file_crystallize_(lfs3, file,
file->leaf.pos - lfs3_bptr_off(&file->leaf.bptr), -1, -1,
0, NULL, 0);
if (err) {
@@ -13600,7 +13644,10 @@ static int lfs3_file_flushset_(lfs3_t *lfs3, lfs3_file_t *file,
lfs3_off_t pos = 0;
while (size > 0) {
// checkpoint the allocator
lfs3_alloc_ckpoint(lfs3);
int err = lfs3_alloc_ckpoint(lfs3);
if (err) {
return err;
}
// enough data for a block?
#ifndef LFS3_2BONLY
@@ -13619,7 +13666,7 @@ static int lfs3_file_flushset_(lfs3_t *lfs3, lfs3_file_t *file,
// write our data
uint32_t cksum = 0;
int err = lfs3_bd_prog(lfs3, block, 0, buffer, d,
err = lfs3_bd_prog(lfs3, block, 0, buffer, d,
&cksum, true);
if (err) {
// bad prog? try another block
@@ -13665,7 +13712,7 @@ static int lfs3_file_flushset_(lfs3_t *lfs3, lfs3_file_t *file,
lfs3_ssize_t d = lfs3_min(size, lfs3->cfg->fragment_size);
// commit to bshrub/btree
int err = lfs3_file_commit(lfs3, file, pos, LFS3_RATTRS(
err = lfs3_file_commit(lfs3, file, pos, LFS3_RATTRS(
LFS3_RATTR_DATA(
LFS3_TAG_DATA, +d,
&LFS3_DATA_BUF(buffer, d))));
@@ -13700,7 +13747,10 @@ static int lfs3_file_flush_(lfs3_t *lfs3, lfs3_file_t *file,
#ifndef LFS3_2BONLY
while (size > 0) {
// checkpoint the allocator
lfs3_alloc_ckpoint(lfs3);
int err = lfs3_alloc_ckpoint(lfs3);
if (err) {
return err;
}
// mid-crystallization? can we just resume crystallizing?
//
@@ -13721,7 +13771,7 @@ static int lfs3_file_flush_(lfs3_t *lfs3, lfs3_file_t *file,
// mark as uncrystallized
file->b.h.flags |= LFS3_o_UNCRYST;
// crystallize
int err = lfs3_file_crystallize_(lfs3, file,
err = lfs3_file_crystallize_(lfs3, file,
block_start, -1, (pos + size) - block_start,
pos, buffer, size);
if (err) {
@@ -13769,7 +13819,7 @@ static int lfs3_file_flush_(lfs3_t *lfs3, lfs3_file_t *file,
lfs3_bid_t bid;
lfs3_bid_t weight;
lfs3_bptr_t bptr;
int err = lfs3_file_lookupnext(lfs3, file, poke,
err = lfs3_file_lookupnext(lfs3, file, poke,
&bid, &weight, &bptr);
if (err) {
LFS3_ASSERT(err != LFS3_ERR_NOENT);
@@ -13802,7 +13852,7 @@ static int lfs3_file_flush_(lfs3_t *lfs3, lfs3_file_t *file,
lfs3_bid_t bid;
lfs3_bid_t weight;
lfs3_bptr_t bptr;
int err = lfs3_file_lookupnext(lfs3, file, poke,
err = lfs3_file_lookupnext(lfs3, file, poke,
&bid, &weight, &bptr);
if (err) {
LFS3_ASSERT(err != LFS3_ERR_NOENT);
@@ -13850,7 +13900,7 @@ static int lfs3_file_flush_(lfs3_t *lfs3, lfs3_file_t *file,
// mark as uncrystallized
file->b.h.flags |= LFS3_o_UNCRYST;
// crystallize
int err = lfs3_file_crystallize_(lfs3, file,
err = lfs3_file_crystallize_(lfs3, file,
block_start, -1, crystal_end - block_start,
pos, buffer, size);
if (err) {
@@ -13874,7 +13924,7 @@ static int lfs3_file_flush_(lfs3_t *lfs3, lfs3_file_t *file,
// and graft it into our bshrub/btree
if (lfs3_o_isuncryst(file->b.h.flags)) {
// finish crystallizing
int err = lfs3_file_crystallize_(lfs3, file,
err = lfs3_file_crystallize_(lfs3, file,
file->leaf.pos - lfs3_bptr_off(&file->leaf.bptr), -1, -1,
0, NULL, 0);
if (err) {
@@ -13895,7 +13945,7 @@ static int lfs3_file_flush_(lfs3_t *lfs3, lfs3_file_t *file,
lfs3_bid_t bid;
lfs3_bid_t weight;
lfs3_bptr_t bptr;
int err = lfs3_file_lookupnext(lfs3, file,
err = lfs3_file_lookupnext(lfs3, file,
lfs3_min(
crystal_start-1,
file->b.shrub.r.weight-1),
@@ -13923,7 +13973,7 @@ static int lfs3_file_flush_(lfs3_t *lfs3, lfs3_file_t *file,
// start crystallizing!
//
// lfs3_file_crystallize_ handles block allocation/relocation
int err = lfs3_file_crystallize_(lfs3, file,
err = lfs3_file_crystallize_(lfs3, file,
crystal_start, -1, crystal_end - crystal_start,
pos, buffer, size);
if (err) {
@@ -13949,7 +13999,10 @@ fragment:;
// iteratively write fragments (inlined leaves)
while (size > 0) {
// checkpoint the allocator
lfs3_alloc_ckpoint(lfs3);
int err = lfs3_alloc_ckpoint(lfs3);
if (err) {
return err;
}
// do we need to discard our leaf? we need to discard fragments
// in case the underlying rbyd compacts, and we need to discard
@@ -13986,7 +14039,7 @@ fragment:;
lfs3_bid_t bid;
lfs3_bid_t weight;
lfs3_bptr_t bptr;
int err = lfs3_file_lookupnext(lfs3, file,
err = lfs3_file_lookupnext(lfs3, file,
fragment_start-1,
&bid, &weight, &bptr);
if (err) {
@@ -14020,7 +14073,7 @@ fragment:;
lfs3_bid_t bid;
lfs3_bid_t weight;
lfs3_bptr_t bptr;
int err = lfs3_file_lookupnext(lfs3, file,
err = lfs3_file_lookupnext(lfs3, file,
fragment_end,
&bid, &weight, &bptr);
if (err) {
@@ -14046,7 +14099,7 @@ fragment:;
// once we've figured out what fragment to write, graft it into
// our tree
int err = lfs3_file_graft_(lfs3, file,
err = lfs3_file_graft_(lfs3, file,
fragment_start, fragment_end - fragment_start, 0,
datas, data_count);
if (err) {
@@ -14446,10 +14499,15 @@ static int lfs3_file_sync_(lfs3_t *lfs3, lfs3_file_t *file,
if (rattr_count > 0) {
// make sure we don't overflow our rattr buffer
LFS3_ASSERT(rattr_count <= sizeof(rattrs)/sizeof(lfs3_rattr_t));
// checkpoint the allocator
lfs3_alloc_ckpoint(lfs3);
int err = lfs3_alloc_ckpoint(lfs3);
if (err) {
return err;
}
// and commit!
int err = lfs3_mdir_commit(lfs3, &file->b.h.mdir,
err = lfs3_mdir_commit(lfs3, &file->b.h.mdir,
rattrs, rattr_count);
if (err) {
return err;
@@ -14743,7 +14801,11 @@ int lfs3_file_truncate(lfs3_t *lfs3, lfs3_file_t *file, lfs3_off_t size_) {
file->b.h.flags |= LFS3_o_UNSYNC;
// checkpoint the allocator
lfs3_alloc_ckpoint(lfs3);
err = lfs3_alloc_ckpoint(lfs3);
if (err) {
return err;
}
// truncate our btree
err = lfs3_file_graft_(lfs3, file,
lfs3_min(size, size_), size - lfs3_min(size, size_),
@@ -14825,7 +14887,11 @@ int lfs3_file_fruncate(lfs3_t *lfs3, lfs3_file_t *file, lfs3_off_t size_) {
file->b.h.flags |= LFS3_o_UNSYNC;
// checkpoint the allocator
lfs3_alloc_ckpoint(lfs3);
err = lfs3_alloc_ckpoint(lfs3);
if (err) {
return err;
}
// fruncate our btree
err = lfs3_file_graft_(lfs3, file,
0, lfs3_smax(size - size_, 0),
@@ -16197,6 +16263,10 @@ static int lfs3_formatbmap(lfs3_t *lfs3) {
#endif
// TODO should we try multiple blocks?
//
// TODO if we try multiple blocks we should update test_badblocks
// to test block 3 when bmap is present
//
// assume we can write bmap to block 2
lfs3->gbmap.window = 3;
lfs3->gbmap.known = lfs3->cfg->block_count;
@@ -16562,8 +16632,13 @@ static int lfs3_fs_fixgrm(lfs3_t *lfs3) {
// mark grm as taken care of
lfs3_grm_pop(lfs3);
// checkpoint the allocator
lfs3_alloc_ckpoint(lfs3);
err = lfs3_alloc_ckpoint(lfs3);
if (err) {
return err;
}
// remove the rid while atomically updating our grm
err = lfs3_mdir_commit(lfs3, &mdir, LFS3_RATTRS(
LFS3_RATTR(LFS3_TAG_RM, -1)));
@@ -16616,7 +16691,11 @@ static int lfs3_mdir_mkconsistent(lfs3_t *lfs3, lfs3_mdir_t *mdir) {
lfs3_dbgmrid(lfs3, mdir->mid));
// checkpoint the allocator
lfs3_alloc_ckpoint(lfs3);
err = lfs3_alloc_ckpoint(lfs3);
if (err) {
return err;
}
// remove the orphaned stickynote
err = lfs3_mdir_commit(lfs3, mdir, LFS3_RATTRS(
LFS3_RATTR(LFS3_TAG_RM, -1)));
@@ -16769,7 +16848,10 @@ static int lfs3_fs_gc_(lfs3_t *lfs3, lfs3_trv_t *trv,
while (pending && (lfs3_off_t)steps > 0) {
// checkpoint the allocator to maximize any lookahead scans
#ifndef LFS3_RDONLY
lfs3_alloc_ckpoint(lfs3);
int err = lfs3_alloc_ckpoint(lfs3);
if (err) {
return err;
}
#endif
// start a new traversal?
@@ -16908,9 +16990,14 @@ int lfs3_fs_grow(lfs3_t *lfs3, lfs3_size_t block_count_) {
// discard stale lookahead buffer
lfs3_alloc_discard(lfs3);
// checkpoint the allocator
int err = lfs3_alloc_ckpoint(lfs3);
if (err) {
return err;
}
// update our on-disk config
lfs3_alloc_ckpoint(lfs3);
int err = lfs3_mdir_commit(lfs3, &lfs3->mroot, LFS3_RATTRS(
err = lfs3_mdir_commit(lfs3, &lfs3->mroot, LFS3_RATTRS(
LFS3_RATTR_GEOMETRY(
LFS3_TAG_GEOMETRY, 0,
(&(lfs3_geometry_t){
@@ -17008,7 +17095,10 @@ int lfs3_trv_read(lfs3_t *lfs3, lfs3_trv_t *trv,
// checkpoint the allocator to maximize any lookahead scans
#ifndef LFS3_RDONLY
lfs3_alloc_ckpoint(lfs3);
int err = lfs3_alloc_ckpoint(lfs3);
if (err) {
return err;
}
#endif
while (true) {
+5 -9
View File
@@ -9,11 +9,7 @@
#
after = ['test_mtree', 'test_bmap', 'test_dirs', 'test_files']
# TODO should we rename these to test_lookahead?
# TODO or extend to test the bmap as well?
#
# these are really tuned to test the lookahead allocator
#ifndef = 'LFS3_BMAP'
defines.INIT_BLOCKS = 'LFS3_IFDEF_BMAP(3, 2)'
# test that we can alloc
[cases.test_alloc_alloc]
@@ -26,7 +22,7 @@ defines.COUNT = [
'2',
]
defines.ERASE = [false, true]
if = 'COUNT >= LFS3_IFDEF_BMAP(3, 2)'
if = 'COUNT >= INIT_BLOCKS'
in = 'lfs3.c'
code = '''
// test various block counts
@@ -73,7 +69,7 @@ defines.COUNT = [
'2',
]
defines.ERASE = [false, true]
if = 'COUNT >= LFS3_IFDEF_BMAP(3, 2)'
if = 'COUNT >= INIT_BLOCKS'
in = 'lfs3.c'
code = '''
// test various block counts
@@ -659,7 +655,7 @@ defines.COUNT = [
'5',
'2',
]
if = 'COUNT >= LFS3_IFDEF_BMAP(3, 2)'
if = 'COUNT >= INIT_BLOCKS'
code = '''
// test various block counts
struct lfs3_cfg cfg = *CFG;
@@ -742,7 +738,7 @@ defines.SIZE = [
'2*BLOCK_SIZE',
'8*BLOCK_SIZE',
]
if = 'COUNT >= LFS3_IFDEF_BMAP(3, 2)'
if = 'COUNT >= INIT_BLOCKS'
code = '''
// test various block counts
struct lfs3_cfg cfg = *CFG;
+36 -37
View File
@@ -11,8 +11,7 @@ after = [
'test_compat',
]
# TODO bmap workaround?
ifndef = 'LFS3_BMAP'
defines.INIT_BLOCKS = 'LFS3_IFDEF_BMAP(3, 2)'
## Single-block badblock tests
@@ -150,7 +149,7 @@ defines.N = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512]
if = 'LFS3_IFDEF_CKPROGS(true, !CKPROGS)'
code = '''
// test all possible bad blocks
for (lfs3_size_t i = 2;
for (lfs3_size_t i = INIT_BLOCKS;
i < ((BADBLOCK == -1) ? BLOCK_COUNT : 1);
i++) {
lfs3_size_t badblock = (BADBLOCK == -1) ? i : BADBLOCK;
@@ -268,7 +267,7 @@ fuzz = 'SEED'
if = 'LFS3_IFDEF_CKPROGS(true, !CKPROGS)'
code = '''
// test all possible bad blocks
for (lfs3_size_t i = 2;
for (lfs3_size_t i = INIT_BLOCKS;
i < ((BADBLOCK == -1) ? BLOCK_COUNT : 1);
i++) {
lfs3_size_t badblock = (BADBLOCK == -1) ? i : BADBLOCK;
@@ -463,7 +462,7 @@ if = [
]
code = '''
// test all possible bad blocks
for (lfs3_size_t i = 2;
for (lfs3_size_t i = INIT_BLOCKS;
i < ((BADBLOCK == -1) ? BLOCK_COUNT : 1);
i++) {
lfs3_size_t badblock = (BADBLOCK == -1) ? i : BADBLOCK;
@@ -577,7 +576,7 @@ if = [
]
code = '''
// test all possible bad blocks
for (lfs3_size_t i = 2;
for (lfs3_size_t i = INIT_BLOCKS;
i < ((BADBLOCK == -1) ? BLOCK_COUNT : 1);
i++) {
lfs3_size_t badblock = (BADBLOCK == -1) ? i : BADBLOCK;
@@ -834,7 +833,7 @@ if = [
]
code = '''
// test all possible bad blocks
for (lfs3_size_t i = 2;
for (lfs3_size_t i = INIT_BLOCKS;
i < ((BADBLOCK == -1) ? BLOCK_COUNT : 1);
i++) {
lfs3_size_t badblock = (BADBLOCK == -1) ? i : BADBLOCK;
@@ -997,7 +996,7 @@ if = [
]
code = '''
// test all possible bad blocks
for (lfs3_size_t i = 2;
for (lfs3_size_t i = INIT_BLOCKS;
i < ((BADBLOCK == -1) ? BLOCK_COUNT : 1);
i++) {
lfs3_size_t badblock = (BADBLOCK == -1) ? i : BADBLOCK;
@@ -1449,7 +1448,7 @@ if = [
]
code = '''
// test all possible bad blocks
for (lfs3_size_t i = 2;
for (lfs3_size_t i = INIT_BLOCKS;
i < ((BADBLOCK == -1) ? BLOCK_COUNT : 1);
i++) {
lfs3_size_t badblock = (BADBLOCK == -1) ? i : BADBLOCK;
@@ -2104,11 +2103,11 @@ code = '''
for (lfs3_size_t i = 0; i < BLOCK_COUNT/2; i++) {
// mark our badblock as bad
if (!MIRROR) {
if (i >= 2) {
if (i >= INIT_BLOCKS) {
lfs3_emubd_markbad(CFG, i) => 0;
}
} else {
if (i+BLOCK_COUNT/2 >= 2) {
if (i+BLOCK_COUNT/2 >= INIT_BLOCKS) {
lfs3_emubd_markbad(CFG, i+BLOCK_COUNT/2) => 0;
}
}
@@ -2223,11 +2222,11 @@ code = '''
for (lfs3_size_t i = 0; i < BLOCK_COUNT/2; i++) {
// mark our badblock as bad
if (!MIRROR) {
if (i >= 2) {
if (i >= INIT_BLOCKS) {
lfs3_emubd_markbad(CFG, i) => 0;
}
} else {
if (i+BLOCK_COUNT/2 >= 2) {
if (i+BLOCK_COUNT/2 >= INIT_BLOCKS) {
lfs3_emubd_markbad(CFG, i+BLOCK_COUNT/2) => 0;
}
}
@@ -2419,11 +2418,11 @@ code = '''
for (lfs3_size_t i = 0; i < BLOCK_COUNT/2; i++) {
// mark our badblock as bad
if (!MIRROR) {
if (i >= 2) {
if (i >= INIT_BLOCKS) {
lfs3_emubd_markbad(CFG, i) => 0;
}
} else {
if (i+BLOCK_COUNT/2 >= 2) {
if (i+BLOCK_COUNT/2 >= INIT_BLOCKS) {
lfs3_emubd_markbad(CFG, i+BLOCK_COUNT/2) => 0;
}
}
@@ -2534,11 +2533,11 @@ code = '''
for (lfs3_size_t i = 0; i < BLOCK_COUNT/2; i++) {
// mark our badblock as bad
if (!MIRROR) {
if (i >= 2) {
if (i >= INIT_BLOCKS) {
lfs3_emubd_markbad(CFG, i) => 0;
}
} else {
if (i+BLOCK_COUNT/2 >= 2) {
if (i+BLOCK_COUNT/2 >= INIT_BLOCKS) {
lfs3_emubd_markbad(CFG, i+BLOCK_COUNT/2) => 0;
}
}
@@ -2792,11 +2791,11 @@ code = '''
for (lfs3_size_t i = 0; i < BLOCK_COUNT/2; i++) {
// mark our badblock as bad
if (!MIRROR) {
if (i >= 2) {
if (i >= INIT_BLOCKS) {
lfs3_emubd_markbad(CFG, i) => 0;
}
} else {
if (i+BLOCK_COUNT/2 >= 2) {
if (i+BLOCK_COUNT/2 >= INIT_BLOCKS) {
lfs3_emubd_markbad(CFG, i+BLOCK_COUNT/2) => 0;
}
}
@@ -2956,11 +2955,11 @@ code = '''
for (lfs3_size_t i = 0; i < BLOCK_COUNT/2; i++) {
// mark our badblock as bad
if (!MIRROR) {
if (i >= 2) {
if (i >= INIT_BLOCKS) {
lfs3_emubd_markbad(CFG, i) => 0;
}
} else {
if (i+BLOCK_COUNT/2 >= 2) {
if (i+BLOCK_COUNT/2 >= INIT_BLOCKS) {
lfs3_emubd_markbad(CFG, i+BLOCK_COUNT/2) => 0;
}
}
@@ -3409,11 +3408,11 @@ code = '''
for (lfs3_size_t i = 0; i < BLOCK_COUNT/2; i++) {
// mark our badblock as bad
if (!MIRROR) {
if (i >= 2) {
if (i >= INIT_BLOCKS) {
lfs3_emubd_markbad(CFG, i) => 0;
}
} else {
if (i+BLOCK_COUNT/2 >= 2) {
if (i+BLOCK_COUNT/2 >= INIT_BLOCKS) {
lfs3_emubd_markbad(CFG, i+BLOCK_COUNT/2) => 0;
}
}
@@ -4061,11 +4060,11 @@ code = '''
for (lfs3_size_t i = 0; i < BLOCK_COUNT/2; i++) {
// mark our badblock as bad
if (!MIRROR) {
if (2*i+0 >= 2) {
if (2*i+0 >= INIT_BLOCKS) {
lfs3_emubd_markbad(CFG, 2*i+0) => 0;
}
} else {
if (2*i+1 >= 2) {
if (2*i+1 >= INIT_BLOCKS) {
lfs3_emubd_markbad(CFG, 2*i+1) => 0;
}
}
@@ -4180,11 +4179,11 @@ code = '''
for (lfs3_size_t i = 0; i < BLOCK_COUNT/2; i++) {
// mark our badblock as bad
if (!MIRROR) {
if (2*i+0 >= 2) {
if (2*i+0 >= INIT_BLOCKS) {
lfs3_emubd_markbad(CFG, 2*i+0) => 0;
}
} else {
if (2*i+1 >= 2) {
if (2*i+1 >= INIT_BLOCKS) {
lfs3_emubd_markbad(CFG, 2*i+1) => 0;
}
}
@@ -4376,11 +4375,11 @@ code = '''
for (lfs3_size_t i = 0; i < BLOCK_COUNT/2; i++) {
// mark our badblock as bad
if (!MIRROR) {
if (2*i+0 >= 2) {
if (2*i+0 >= INIT_BLOCKS) {
lfs3_emubd_markbad(CFG, 2*i+0) => 0;
}
} else {
if (2*i+1 >= 2) {
if (2*i+1 >= INIT_BLOCKS) {
lfs3_emubd_markbad(CFG, 2*i+1) => 0;
}
}
@@ -4491,11 +4490,11 @@ code = '''
for (lfs3_size_t i = 0; i < BLOCK_COUNT/2; i++) {
// mark our badblock as bad
if (!MIRROR) {
if (2*i+0 >= 2) {
if (2*i+0 >= INIT_BLOCKS) {
lfs3_emubd_markbad(CFG, 2*i+0) => 0;
}
} else {
if (2*i+1 >= 2) {
if (2*i+1 >= INIT_BLOCKS) {
lfs3_emubd_markbad(CFG, 2*i+1) => 0;
}
}
@@ -4749,11 +4748,11 @@ code = '''
for (lfs3_size_t i = 0; i < BLOCK_COUNT/2; i++) {
// mark our badblock as bad
if (!MIRROR) {
if (2*i+0 >= 2) {
if (2*i+0 >= INIT_BLOCKS) {
lfs3_emubd_markbad(CFG, 2*i+0) => 0;
}
} else {
if (2*i+1 >= 2) {
if (2*i+1 >= INIT_BLOCKS) {
lfs3_emubd_markbad(CFG, 2*i+1) => 0;
}
}
@@ -4911,11 +4910,11 @@ code = '''
for (lfs3_size_t i = 0; i < BLOCK_COUNT/2; i++) {
// mark our badblock as bad
if (!MIRROR) {
if (2*i+0 >= 2) {
if (2*i+0 >= INIT_BLOCKS) {
lfs3_emubd_markbad(CFG, 2*i+0) => 0;
}
} else {
if (2*i+1 >= 2) {
if (2*i+1 >= INIT_BLOCKS) {
lfs3_emubd_markbad(CFG, 2*i+1) => 0;
}
}
@@ -5364,11 +5363,11 @@ code = '''
for (lfs3_size_t i = 0; i < BLOCK_COUNT/2; i++) {
// mark our badblock as bad
if (!MIRROR) {
if (2*i+0 >= 2) {
if (2*i+0 >= INIT_BLOCKS) {
lfs3_emubd_markbad(CFG, 2*i+0) => 0;
}
} else {
if (2*i+1 >= 2) {
if (2*i+1 >= INIT_BLOCKS) {
lfs3_emubd_markbad(CFG, 2*i+1) => 0;
}
}
+14 -9
View File
@@ -1,9 +1,6 @@
# Test checksum validation things
after = ['test_trvs', 'test_gc', 'test_mount']
# TODO bmap workaround?
ifndef = 'LFS3_BMAP'
code = '''
// naive crc32c
@@ -988,6 +985,7 @@ defines.SIZE = [
'2*BLOCK_SIZE',
'8*BLOCK_SIZE',
]
in = 'lfs3.c'
code = '''
for (lfs3_block_t i = 0;; i++) {
// a bit hacky, but this catches infinite loops
@@ -1026,7 +1024,8 @@ code = '''
goto done;
}
if (tinfo.btype == LFS3_BTYPE_BTREE) {
if (tinfo.btype == LFS3_BTYPE_BTREE
&& lfs3_t_tstate(trv.b.h.flags) != LFS3_TSTATE_BMAP) {
if (k == i) {
// clobber this block
printf("clobbering 0x%x\n", tinfo.block);
@@ -1085,6 +1084,7 @@ defines.SIZE = [
'2*BLOCK_SIZE',
'8*BLOCK_SIZE',
]
in = 'lfs3.c'
code = '''
for (lfs3_block_t i = 0;; i++) {
// a bit hacky, but this catches infinite loops
@@ -1123,8 +1123,9 @@ code = '''
goto done;
}
if (tinfo.btype == LFS3_BTYPE_BTREE
|| tinfo.btype == LFS3_BTYPE_DATA) {
if ((tinfo.btype == LFS3_BTYPE_BTREE
|| tinfo.btype == LFS3_BTYPE_DATA)
&& lfs3_t_tstate(trv.b.h.flags) != LFS3_TSTATE_BMAP) {
if (k == i) {
// clobber this block
printf("clobbering 0x%x\n", tinfo.block);
@@ -1188,6 +1189,7 @@ defines.SIZE = [
defines.SEED = 42
defines.M = 100
fuzz = 'SEED'
in = 'lfs3.c'
code = '''
uint32_t prng_ = SEED;
for (lfs3_block_t i = 0;; i++) {
@@ -1228,7 +1230,8 @@ code = '''
goto done;
}
if (tinfo.btype == LFS3_BTYPE_BTREE) {
if (tinfo.btype == LFS3_BTYPE_BTREE
&& lfs3_t_tstate(trv.b.h.flags) != LFS3_TSTATE_BMAP) {
// found an interesting block?
if (k == i) {
badblock = tinfo.block;
@@ -1336,6 +1339,7 @@ defines.SIZE = [
defines.SEED = 42
defines.M = 100
fuzz = 'SEED'
in = 'lfs3.c'
code = '''
uint32_t prng_ = SEED;
for (lfs3_block_t i = 0;; i++) {
@@ -1376,8 +1380,9 @@ code = '''
goto done;
}
if (tinfo.btype == LFS3_BTYPE_BTREE
|| tinfo.btype == LFS3_BTYPE_DATA) {
if ((tinfo.btype == LFS3_BTYPE_BTREE
|| tinfo.btype == LFS3_BTYPE_DATA)
&& lfs3_t_tstate(trv.b.h.flags) != LFS3_TSTATE_BMAP) {
// found an interesting block?
if (k == i) {
badblock = tinfo.block;
+1 -1
View File
@@ -8,7 +8,7 @@ after = [
'test_mount',
]
# TODO bmap workaround?
# TODO!! lfs3_fs_grow needs to be able to adjust an on-disk bmaps
ifndef = 'LFS3_BMAP'
+393 -75
View File
File diff suppressed because it is too large Load Diff