Added scripts/dbglfs.py for debugging the filesystem tree

Currently this can show:

- The filesystem tree:

    $ ./scripts/dbglfs.py disk -B4096
    littlefs v2.0 0x{0,1}.bd4, rev 1, weight 41
    mdir         ids      name                        type
    {00ce,00cf}:      0.1 dir0000                     dir 0x1070c73
    {0090,0091}:     2.30 |-> child0000               dir 0x8ec7fb2
    {0042,0043}:    24.35 |   |-> grandchild0000      dir 0x32d990b
    {0009,000a}:     25.0 |   |-> grandchild0001      dir 0x1461a08
                     25.1 |   |-> grandchild0002      dir 0x216e9fc
                     25.2 |   |-> grandchild0003      dir 0x7d6aff
                     25.3 |   |-> grandchild0004      dir 0x4b70e14
                     25.4 |   |-> grandchild0005      dir 0x6dc8d17
                     25.5 |   |-> grandchild0006      dir 0x58c7ee3
                     25.6 |   '-> grandchild0007      dir 0x7e7fde0
    {0090,0091}:     2.31 |-> child0001               dir 0xa87fcb1
    {0077,0078}:     29.1 |   |-> grandchild0000      dir 0x12194f5
                     29.2 |   |-> grandchild0001      dir 0x34a17f6
    ...

- The on-disk filesystem config:

    $ ./scripts/dbglfs.py disk -B4096 -c
    littlefs v2.0 0x{0,1}.bd4, rev 1, weight 41
    mdir         ids      tag                     data (truncated)
         config: major_version 2                  02                       .
                 minor_version 0                  00                       .
                 csum_type 2                      02                       .
                 flags 0                          00                       .
                 block_size 4096                  80 20                    .
                 block_count 256                  80 02                    ..
    ...

- Any global-state on-disk:

    $ ./scripts/dbglfs.py disk -B4096 -g -d
    littlefs v2.0 0x{0,1}.bd4, rev 1, weight 41
    mdir         ids      tag                     data (truncated)
         gstate: grm none                         00 00 00 cc 05 57 ff 7f .....W..
    {0000,0001}:       -1 grm 8                   01 03 24 cc 05 57 ff 7f ..$..W..
    {00ce,00cf}:        0 grm 3                   00 2f 1b                ./.
    {00d0,00d1}:        1 grm 3                   01 04 01                ...

  Note this already reveals a bug, since grm none should be all zeros.

Also made some other minor tweaks to dbg scripts for consistency.
This commit is contained in:
Christopher Haster
2023-07-12 13:19:58 -05:00
parent 61c51b699a
commit b98ac119c7
4 changed files with 1159 additions and 15 deletions
+6 -2
View File
@@ -3505,7 +3505,7 @@ static int lfsr_rbyd_dnamelookup(lfs_t *lfs, const lfsr_rbyd_t *rbyd,
// bisect search space // bisect search space
if (lfs_cmp(cmp) > 0) { if (lfs_cmp(cmp) > 0) {
upper = id__-weight__ + 1; upper = id__ - (weight__-1);
} else if (lfs_cmp(cmp) < 0) { } else if (lfs_cmp(cmp) < 0) {
lower = id__ + 1; lower = id__ + 1;
@@ -7459,14 +7459,18 @@ int lfsr_dir_read(lfs_t *lfs, lfsr_dir_t *dir, struct lfs_info *info) {
/// Prepare the filesystem for mutation /// /// Prepare the filesystem for mutation ///
static int lfsr_fs_fixgrm(lfs_t *lfs) { static int lfsr_fs_fixgrm(lfs_t *lfs) {
LFS_ASSERT(lfs->grm_.mid != LFSR_MID_RM);
// find our mdir // find our mdir
lfsr_mdir_t mdir; lfsr_mdir_t mdir;
LFS_ASSERT((lfs_size_t)lfs->grm_.mid < lfs->mtree.weight);
int err = lfsr_mtree_lookup(lfs, lfs->grm_.mid, &mdir); int err = lfsr_mtree_lookup(lfs, lfs->grm_.mid, &mdir);
if (err) { if (err) {
return err; return err;
} }
// remove the rid while also zeroing our grm // remove the rid while also zeroing our grm
LFS_ASSERT(lfs->grm_.rid < mdir.rbyd.weight);
err = lfsr_mdir_commit(lfs, &mdir, (lfs_ssize_t*)&lfs->grm_.rid, LFSR_ATTRS( err = lfsr_mdir_commit(lfs, &mdir, (lfs_ssize_t*)&lfs->grm_.rid, LFSR_ATTRS(
LFSR_ATTR(lfs->grm_.rid, UNR, -1, NULL, 0), LFSR_ATTR(lfs->grm_.rid, UNR, -1, NULL, 0),
LFSR_ATTR(-1, GRM, 0, NULL, 0))); LFSR_ATTR(-1, GRM, 0, NULL, 0)));
@@ -7478,7 +7482,7 @@ static int lfsr_fs_fixgrm(lfs_t *lfs) {
static int lfsr_fs_preparemutation(lfs_t *lfs) { static int lfsr_fs_preparemutation(lfs_t *lfs) {
// fix pending grms // fix pending grms
if (lfs->grm_.mid >= 0) { if (lfs->grm_.mid != LFSR_MID_RM) {
LFS_DEBUG("Fixing grm (0x%"PRIx32".%"PRIx32")", LFS_DEBUG("Fixing grm (0x%"PRIx32".%"PRIx32")",
lfs->grm_.mid, lfs->grm_.mid,
lfs->grm_.rid); lfs->grm_.rid);
+6 -5
View File
@@ -201,15 +201,15 @@ class Rbyd:
self.off = off self.off = off
self.trunk = trunk self.trunk = trunk
self.weight = weight self.weight = weight
self.other_blocks = [] self.redund_blocks = []
def addr(self): def addr(self):
if not self.other_blocks: if not self.redund_blocks:
return '0x%x.%x' % (self.block, self.trunk) return '0x%x.%x' % (self.block, self.trunk)
else: else:
return '0x{%x,%s}.%x' % ( return '0x{%x,%s}.%x' % (
self.block, self.block,
','.join('%x' % block for block in self.other_blocks), ','.join('%x' % block for block in self.redund_blocks),
self.trunk) self.trunk)
@classmethod @classmethod
@@ -232,7 +232,7 @@ class Rbyd:
i = i_ i = i_
# keep track of the other blocks # keep track of the other blocks
rbyd = rbyds[i] rbyd = rbyds[i]
rbyd.other_blocks = [rbyds[(i+1+j) % len(rbyds)].block rbyd.redund_blocks = [rbyds[(i+1+j) % len(rbyds)].block
for j in range(len(rbyds)-1)] for j in range(len(rbyds)-1)]
return rbyd return rbyd
else: else:
@@ -835,7 +835,6 @@ def main(disk, roots=None, *,
else bid if w > 0 else bid if w > 0
else '', else '',
tagrepr(tag, w if i == 0 else 0, len(data), None), tagrepr(tag, w if i == 0 else 0, len(data), None),
# note we render names a bit different here
next(xxd(data, 8), '') if not args.get('no_truncate') next(xxd(data, 8), '') if not args.get('no_truncate')
else '')) else ''))
prbyd = rbyd prbyd = rbyd
@@ -986,7 +985,9 @@ if __name__ == "__main__":
help="Show the underlying B-tree.") help="Show the underlying B-tree.")
parser.add_argument( parser.add_argument(
'-Z', '--depth', '-Z', '--depth',
nargs='?',
type=lambda x: int(x, 0), type=lambda x: int(x, 0),
const=0,
help="Depth of tree to show.") help="Depth of tree to show.")
parser.add_argument( parser.add_argument(
'-e', '--error-on-corrupt', '-e', '--error-on-corrupt',
+1135
View File
File diff suppressed because it is too large Load Diff
+12 -8
View File
@@ -209,15 +209,15 @@ class Rbyd:
self.off = off self.off = off
self.trunk = trunk self.trunk = trunk
self.weight = weight self.weight = weight
self.other_blocks = [] self.redund_blocks = []
def addr(self): def addr(self):
if not self.other_blocks: if not self.redund_blocks:
return '0x%x.%x' % (self.block, self.trunk) return '0x%x.%x' % (self.block, self.trunk)
else: else:
return '0x{%x,%s}.%x' % ( return '0x{%x,%s}.%x' % (
self.block, self.block,
','.join('%x' % block for block in self.other_blocks), ','.join('%x' % block for block in self.redund_blocks),
self.trunk) self.trunk)
@classmethod @classmethod
@@ -240,7 +240,7 @@ class Rbyd:
i = i_ i = i_
# keep track of the other blocks # keep track of the other blocks
rbyd = rbyds[i] rbyd = rbyds[i]
rbyd.other_blocks = [rbyds[(i+1+j) % len(rbyds)].block rbyd.redund_blocks = [rbyds[(i+1+j) % len(rbyds)].block
for j in range(len(rbyds)-1)] for j in range(len(rbyds)-1)]
return rbyd return rbyd
else: else:
@@ -1293,7 +1293,7 @@ def main(disk, mroots=None, *,
print('%12s %s%-57s' % ( print('%12s %s%-57s' % (
'{%s}:' % ','.join('%04x' % block '{%s}:' % ','.join('%04x' % block
for block in it.chain([mdir.block], for block in it.chain([mdir.block],
mdir.other_blocks)) mdir.redund_blocks))
if i == 0 else '', if i == 0 else '',
treerepr(mid, 1, md, 0, rid, tag) treerepr(mid, 1, md, 0, rid, tag)
if args.get('tree') or args.get('btree') else '', if args.get('tree') or args.get('btree') else '',
@@ -1393,6 +1393,8 @@ def main(disk, mroots=None, *,
line)) line))
#### actual debugging begins here
# print some information about the mtree # print some information about the mtree
print('mtree %s, rev %d, weight %d' % ( print('mtree %s, rev %d, weight %d' % (
mroot.addr(), mroot.rev, mweight)) mroot.addr(), mroot.rev, mweight))
@@ -1421,7 +1423,7 @@ def main(disk, mroots=None, *,
print('{%s}: %s%s%s' % ( print('{%s}: %s%s%s' % (
','.join('%04x' % block ','.join('%04x' % block
for block in it.chain([mroot.block], for block in it.chain([mroot.block],
mroot.other_blocks)), mroot.redund_blocks)),
'\x1b[31m' if color else '', '\x1b[31m' if color else '',
'(corrupted mroot %s)' % mroot.addr(), '(corrupted mroot %s)' % mroot.addr(),
'\x1b[m' if color else '')) '\x1b[m' if color else ''))
@@ -1456,7 +1458,7 @@ def main(disk, mroots=None, *,
print('{%s}: %s%s%s' % ( print('{%s}: %s%s%s' % (
','.join('%04x' % block ','.join('%04x' % block
for block in it.chain([mdir.block], for block in it.chain([mdir.block],
mdir.other_blocks)), mdir.redund_blocks)),
'\x1b[31m' if color else '', '\x1b[31m' if color else '',
'(corrupted mdir %s)' % mdir.addr(), '(corrupted mdir %s)' % mdir.addr(),
'\x1b[m' if color else '')) '\x1b[m' if color else ''))
@@ -1553,7 +1555,7 @@ def main(disk, mroots=None, *,
print('{%s}: %*s%s%s%s' % ( print('{%s}: %*s%s%s%s' % (
','.join('%04x' % block ','.join('%04x' % block
for block in it.chain([mdir_.block], for block in it.chain([mdir_.block],
mdir_.other_blocks)), mdir_.redund_blocks)),
t_width, '', t_width, '',
'\x1b[31m' if color else '', '\x1b[31m' if color else '',
'(corrupted mdir %s)' % mdir_.addr(), '(corrupted mdir %s)' % mdir_.addr(),
@@ -1619,7 +1621,9 @@ if __name__ == "__main__":
help="Show the underlying B-tree.") help="Show the underlying B-tree.")
parser.add_argument( parser.add_argument(
'-Z', '--depth', '-Z', '--depth',
nargs='?',
type=lambda x: int(x, 0), type=lambda x: int(x, 0),
const=0,
help="Depth of tree to show.") help="Depth of tree to show.")
parser.add_argument( parser.add_argument(
'-e', '--error-on-corrupt', '-e', '--error-on-corrupt',