Tweaked lfsr_format to use 0x00216968 for initial revision count
The main reason is just to avoid using 0x00000000 as the initial
revision count. The is currently the default for B-tree rbyds, and
accidentally writing a B-tree rbyd to an mroot block is both easy
(misconfigured block_count) and something we really want to notice when
debugging.
Fortunately we can still keep our sequence comparison test (0 > -1) by
only setting the top-bits. Though we still need to zero the recycle
counter to avoid premature mroot extension, so this magic number may not
stay intact depending on configuration.
This does add a bit of code, probably to load the magic number from
Thumb's constant pools, but I think it's worth it:
code stack
before: 33430 2640
after: 33458 (+0.1%) 2640 (+0.0%)
This commit is contained in:
@@ -8454,7 +8454,7 @@ static int lfsr_mountinited(lfs_t *lfs) {
|
||||
}
|
||||
|
||||
static int lfsr_formatinited(lfs_t *lfs) {
|
||||
for (int i = 0; i < 2; i++) {
|
||||
for (lfs_size_t i = 0; i < 2; i++) {
|
||||
// write superblock to both rbyds in the root mroot to hopefully
|
||||
// avoid mounting an older filesystem on disk
|
||||
lfsr_rbyd_t rbyd = {.blocks[0]=i, .eoff=0, .trunk=0};
|
||||
@@ -8464,10 +8464,14 @@ static int lfsr_formatinited(lfs_t *lfs) {
|
||||
return err;
|
||||
}
|
||||
|
||||
// note the initial revision count is arbitrary, but we use
|
||||
// -1 and 0 here to help test that our sequence comparison
|
||||
// works correctly
|
||||
err = lfsr_rbyd_appendrev(lfs, &rbyd, (uint32_t)i - 1);
|
||||
// the initial revision count is arbitrary, but it's nice to have
|
||||
// something here to tell the initial mroot apart from btree nodes
|
||||
// (rev=0), it's also useful for start with -1 and 0 in the upper
|
||||
// bits to help test overflow/sequence comparison
|
||||
uint32_t rev = ((i-1) << 28)
|
||||
| (((1 << (28-lfs_smax32(lfs->recycle_bits, 0)))-1)
|
||||
& 0x00216968);
|
||||
err = lfsr_rbyd_appendrev(lfs, &rbyd, rev);
|
||||
if (err) {
|
||||
return err;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user