From 27370dec6698db2eef37ca53301598c34adb1adf Mon Sep 17 00:00:00 2001 From: Christopher Haster Date: Tue, 1 Apr 2025 14:16:04 -0500 Subject: [PATCH] scripts: Tweaked mdir/shrub address printing This fixes an issue where shrub trunks were never printed even with -i/--internal. While only showing mdir/shrub/btree/bptr addresses on block changes is nice in theory, it results in shrub trunks never being printed because the mdir -> shrub block doesn't change. Also checking for changes in block type avoids this. --- scripts/dbgbtree.py | 4 ++-- scripts/dbglfs.py | 29 ++++++++++++++--------------- scripts/dbgmtree.py | 28 +++++++++++++++------------- 3 files changed, 31 insertions(+), 30 deletions(-) diff --git a/scripts/dbgbtree.py b/scripts/dbgbtree.py index 4320f279..6c5e930d 100755 --- a/scripts/dbgbtree.py +++ b/scripts/dbgbtree.py @@ -1732,7 +1732,7 @@ def main(disk, roots=None, *, # dynamically size the id field w_width = mt.ceil(mt.log10(max(1, btree.weight)+1)) - # prbyd here means the last rendered rbyd, we update + # prbyd keeps track of the last rendered rbyd, we update # in dbg_branch to always print interleaved addresses prbyd = None def dbg_branch(d, bid, rbyd, rid, name): @@ -1797,7 +1797,7 @@ def main(disk, roots=None, *, '\x1b[31m' if color else '', '(corrupted rbyd %s)' % rbyd.addr(), '\x1b[m' if color else '')) - prbyd = rbyd + prbyd = None corrupted = True continue diff --git a/scripts/dbglfs.py b/scripts/dbglfs.py index aff6bee4..35f7ef0a 100755 --- a/scripts/dbglfs.py +++ b/scripts/dbglfs.py @@ -4091,12 +4091,12 @@ def dbg_files(lfs, paths, f_width = max(f_width, 4*len(path) + len(file.name.name)) # only show the mdir/rbyd/block address on mdir change - pblock = None + pmdir = None # recursively print directories def dbg_dir(dir, depth, prefixes=('', '', '', '')): - nonlocal pblock + nonlocal pmdir # first figure out the dir length so we know when the dir ends if prefixes != ('', '', '', ''): @@ -4130,7 +4130,8 @@ def dbg_files(lfs, paths, else '', '{%s}:' % ','.join('%04x' % block for block in file.mdir.blocks) - if pblock is None or file.mdir.block != pblock else '', + if not isinstance(pmdir, Mdir) or file.mdir != pmdir + else '', 2*w_width+1, file.mid.repr(), f_width, '%s%s' % ( prefixes[0+(i==len_-1)], @@ -4141,7 +4142,7 @@ def dbg_files(lfs, paths, '\x1b[m' if color and (notes or file.grmed or file.internal) else '')) - pblock = file.mdir.block + pmdir = file.mdir # print attrs associated with each file? if args.get('attrs'): @@ -4186,7 +4187,7 @@ def dbg_files(lfs, paths, # print file structures def dbg_struct(file): - nonlocal pblock + nonlocal pmdir # no tree? if file.bshrub is None: @@ -4205,12 +4206,12 @@ def dbg_files(lfs, paths, # recursively print bshrub branches def dbg_branch(d, bid, rbyd, rid, name): - nonlocal pblock + nonlocal pmdir for rattr in rbyd.rattrs(rid): print('%12s %*s %s%*s %-*s %s' % ( '%04x.%04x:' % (rbyd.block, rbyd.trunk) - if pblock is None or rbyd.block != pblock + if not isinstance(pmdir, Rbyd) or rbyd != pmdir else '', 2*w_width+1, '', treeart.repr( @@ -4229,7 +4230,7 @@ def dbg_files(lfs, paths, if not args.get('raw') and not args.get('no_truncate') else '')) - pblock = rbyd.block + pmdir = rbyd # show on-disk encoding of tags/data if args.get('raw'): @@ -4251,7 +4252,7 @@ def dbg_files(lfs, paths, # print inlined data, block pointers, etc def dbg_bptr(d, pos, bptr): - nonlocal pblock + nonlocal pmdir # some special situations worth reporting notes = [] # cksum mismatch? @@ -4262,7 +4263,7 @@ def dbg_files(lfs, paths, print('%s%12s%s %*s %s%s%s%-*s%s%s' % ( '\x1b[31m' if color and notes else '', '%04x.%04x:' % (bptr.block, bptr.off) - if pblock is None or bptr.block != pblock + if not isinstance(pmdir, Bptr) or bptr != pmdir else '', '\x1b[0m' if color and notes else '', 2*w_width+1, '', @@ -4285,7 +4286,7 @@ def dbg_files(lfs, paths, else ''), ' (%s)' % ', '.join(notes) if notes else '', '\x1b[m' if color and notes else '')) - pblock = bptr.block + pmdir = bptr # show on-disk encoding of tag/bptr/data if args.get('raw'): @@ -4307,9 +4308,7 @@ def dbg_files(lfs, paths, if args.get('raw') or args.get('no_truncate'): for o, line in enumerate(xxd(bptr.data)): print('%11s: %*s %*s%s%s' % ( - '%04x.%04x' % (bptr.block, bptr.off + o*16) - if o == 0 and bptr.block != pblock - else '%04x' % (bptr.off + o*16), + '%04x' % (bptr.off + o*16), 2*w_width+1, '', bt_width, '', '%*s ' % (2*bw_width+1, ''), @@ -4351,7 +4350,7 @@ def dbg_files(lfs, paths, '\x1b[31m' if color else '', '(corrupted rbyd %s)' % rbyd.addr(), '\x1b[m' if color else '')) - pblock = rbyd.block + pmdir = None continue for rid, name in rbyd.rids(): diff --git a/scripts/dbgmtree.py b/scripts/dbgmtree.py index 7442757d..8ef523f5 100755 --- a/scripts/dbgmtree.py +++ b/scripts/dbgmtree.py @@ -2851,13 +2851,20 @@ def main(disk, mroots=None, *, # in case of -1.-1 2) + # pmdir keeps track of the last rendered mdir/rbyd, we update + # this in dbg_mdir/dbg_branch to always print interleaved + # addresses + pmdir = None def dbg_mdir(d, mdir): + nonlocal pmdir + # show human-readable tag representation for i, (mid, rattr) in enumerate(mdir.rattrs()): print('%12s %s%s' % ( '{%s}:' % ','.join('%04x' % block for block in mdir.blocks) - if i == 0 else '', + if not isinstance(pmdir, Mdir) or mdir != pmdir + else '', treeart.repr((mid, d, rattr.tag), color) if args.get('tree') or args.get('tree_rbyd') @@ -2879,6 +2886,7 @@ def main(disk, mroots=None, *, if not args.get('raw') and not args.get('no_truncate') else ''))) + pmdir = mdir # show on-disk encoding of tags if args.get('raw'): @@ -2896,17 +2904,14 @@ def main(disk, mroots=None, *, 2*w_width+1, '', line)) - # prbyd here means the last rendered rbyd, we update - # in dbg_branch to always print interleaved addresses - prbyd = None def dbg_branch(d, bid, rbyd, rid, name): - nonlocal prbyd + nonlocal pmdir # show human-readable representation for rattr in rbyd.rattrs(rid): print('%12s %s%*s %-*s %s' % ( '%04x.%04x:' % (rbyd.block, rbyd.trunk) - if prbyd is None or rbyd != prbyd + if not isinstance(pmdir, Rbyd) or rbyd != pmdir else '', treeart.repr( (mtree.mid(bid-(name.weight-1), -1), @@ -2927,7 +2932,7 @@ def main(disk, mroots=None, *, if not args.get('raw') and not args.get('no_truncate') else '')) - prbyd = rbyd + pmdir = rbyd # show on-disk encoding of tags/data if args.get('raw'): @@ -2976,8 +2981,8 @@ def main(disk, mroots=None, *, 'mroot' if mdir.mid == -1 else 'mdir', mdir.addr()), '\x1b[m' if color else '')) + pmdir = None corrupted = True - prbyd = None continue # cycle detected? @@ -2989,17 +2994,14 @@ def main(disk, mroots=None, *, '\x1b[31m' if color else '', '(mroot cycle detected %s)' % mdir.addr(), '\x1b[m' if color else '')) + pmdir = None corrupted = True - prbyd = None continue mrootseen.add(mdir) # show the mdir dbg_mdir(len(path), mdir) - # force next btree entry to be shown - prbyd = None - # btree node? else: bid, rbyd = mdir @@ -3011,8 +3013,8 @@ def main(disk, mroots=None, *, '\x1b[31m' if color else '', '(corrupted rbyd %s)' % rbyd.addr(), '\x1b[m' if color else '')) + pmdir = None corrupted = True - prbyd = rbyd continue for rid, name in rbyd.rids():