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.
This commit is contained in:
Christopher Haster
2025-04-01 14:16:04 -05:00
parent f550fa9a80
commit 27370dec66
3 changed files with 31 additions and 30 deletions
+2 -2
View File
@@ -1732,7 +1732,7 @@ def main(disk, roots=None, *,
# dynamically size the id field # dynamically size the id field
w_width = mt.ceil(mt.log10(max(1, btree.weight)+1)) 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 # in dbg_branch to always print interleaved addresses
prbyd = None prbyd = None
def dbg_branch(d, bid, rbyd, rid, name): def dbg_branch(d, bid, rbyd, rid, name):
@@ -1797,7 +1797,7 @@ def main(disk, roots=None, *,
'\x1b[31m' if color else '', '\x1b[31m' if color else '',
'(corrupted rbyd %s)' % rbyd.addr(), '(corrupted rbyd %s)' % rbyd.addr(),
'\x1b[m' if color else '')) '\x1b[m' if color else ''))
prbyd = rbyd prbyd = None
corrupted = True corrupted = True
continue continue
+14 -15
View File
@@ -4091,12 +4091,12 @@ def dbg_files(lfs, paths,
f_width = max(f_width, 4*len(path) + len(file.name.name)) f_width = max(f_width, 4*len(path) + len(file.name.name))
# only show the mdir/rbyd/block address on mdir change # only show the mdir/rbyd/block address on mdir change
pblock = None pmdir = None
# recursively print directories # recursively print directories
def dbg_dir(dir, def dbg_dir(dir,
depth, depth,
prefixes=('', '', '', '')): prefixes=('', '', '', '')):
nonlocal pblock nonlocal pmdir
# first figure out the dir length so we know when the dir ends # first figure out the dir length so we know when the dir ends
if prefixes != ('', '', '', ''): if prefixes != ('', '', '', ''):
@@ -4130,7 +4130,8 @@ def dbg_files(lfs, paths,
else '', else '',
'{%s}:' % ','.join('%04x' % block '{%s}:' % ','.join('%04x' % block
for block in file.mdir.blocks) 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(), 2*w_width+1, file.mid.repr(),
f_width, '%s%s' % ( f_width, '%s%s' % (
prefixes[0+(i==len_-1)], prefixes[0+(i==len_-1)],
@@ -4141,7 +4142,7 @@ def dbg_files(lfs, paths,
'\x1b[m' '\x1b[m'
if color and (notes or file.grmed or file.internal) if color and (notes or file.grmed or file.internal)
else '')) else ''))
pblock = file.mdir.block pmdir = file.mdir
# print attrs associated with each file? # print attrs associated with each file?
if args.get('attrs'): if args.get('attrs'):
@@ -4186,7 +4187,7 @@ def dbg_files(lfs, paths,
# print file structures # print file structures
def dbg_struct(file): def dbg_struct(file):
nonlocal pblock nonlocal pmdir
# no tree? # no tree?
if file.bshrub is None: if file.bshrub is None:
@@ -4205,12 +4206,12 @@ def dbg_files(lfs, paths,
# recursively print bshrub branches # recursively print bshrub branches
def dbg_branch(d, bid, rbyd, rid, name): def dbg_branch(d, bid, rbyd, rid, name):
nonlocal pblock nonlocal pmdir
for rattr in rbyd.rattrs(rid): for rattr in rbyd.rattrs(rid):
print('%12s %*s %s%*s %-*s %s' % ( print('%12s %*s %s%*s %-*s %s' % (
'%04x.%04x:' % (rbyd.block, rbyd.trunk) '%04x.%04x:' % (rbyd.block, rbyd.trunk)
if pblock is None or rbyd.block != pblock if not isinstance(pmdir, Rbyd) or rbyd != pmdir
else '', else '',
2*w_width+1, '', 2*w_width+1, '',
treeart.repr( treeart.repr(
@@ -4229,7 +4230,7 @@ def dbg_files(lfs, paths,
if not args.get('raw') if not args.get('raw')
and not args.get('no_truncate') and not args.get('no_truncate')
else '')) else ''))
pblock = rbyd.block pmdir = rbyd
# show on-disk encoding of tags/data # show on-disk encoding of tags/data
if args.get('raw'): if args.get('raw'):
@@ -4251,7 +4252,7 @@ def dbg_files(lfs, paths,
# print inlined data, block pointers, etc # print inlined data, block pointers, etc
def dbg_bptr(d, pos, bptr): def dbg_bptr(d, pos, bptr):
nonlocal pblock nonlocal pmdir
# some special situations worth reporting # some special situations worth reporting
notes = [] notes = []
# cksum mismatch? # cksum mismatch?
@@ -4262,7 +4263,7 @@ def dbg_files(lfs, paths,
print('%s%12s%s %*s %s%s%s%-*s%s%s' % ( print('%s%12s%s %*s %s%s%s%-*s%s%s' % (
'\x1b[31m' if color and notes else '', '\x1b[31m' if color and notes else '',
'%04x.%04x:' % (bptr.block, bptr.off) '%04x.%04x:' % (bptr.block, bptr.off)
if pblock is None or bptr.block != pblock if not isinstance(pmdir, Bptr) or bptr != pmdir
else '', else '',
'\x1b[0m' if color and notes else '', '\x1b[0m' if color and notes else '',
2*w_width+1, '', 2*w_width+1, '',
@@ -4285,7 +4286,7 @@ def dbg_files(lfs, paths,
else ''), else ''),
' (%s)' % ', '.join(notes) if notes else '', ' (%s)' % ', '.join(notes) if notes else '',
'\x1b[m' if color and notes else '')) '\x1b[m' if color and notes else ''))
pblock = bptr.block pmdir = bptr
# show on-disk encoding of tag/bptr/data # show on-disk encoding of tag/bptr/data
if args.get('raw'): if args.get('raw'):
@@ -4307,9 +4308,7 @@ def dbg_files(lfs, paths,
if args.get('raw') or args.get('no_truncate'): if args.get('raw') or args.get('no_truncate'):
for o, line in enumerate(xxd(bptr.data)): for o, line in enumerate(xxd(bptr.data)):
print('%11s: %*s %*s%s%s' % ( print('%11s: %*s %*s%s%s' % (
'%04x.%04x' % (bptr.block, bptr.off + o*16) '%04x' % (bptr.off + o*16),
if o == 0 and bptr.block != pblock
else '%04x' % (bptr.off + o*16),
2*w_width+1, '', 2*w_width+1, '',
bt_width, '', bt_width, '',
'%*s ' % (2*bw_width+1, ''), '%*s ' % (2*bw_width+1, ''),
@@ -4351,7 +4350,7 @@ def dbg_files(lfs, paths,
'\x1b[31m' if color else '', '\x1b[31m' if color else '',
'(corrupted rbyd %s)' % rbyd.addr(), '(corrupted rbyd %s)' % rbyd.addr(),
'\x1b[m' if color else '')) '\x1b[m' if color else ''))
pblock = rbyd.block pmdir = None
continue continue
for rid, name in rbyd.rids(): for rid, name in rbyd.rids():
+15 -13
View File
@@ -2851,13 +2851,20 @@ def main(disk, mroots=None, *,
# in case of -1.-1 # in case of -1.-1
2) 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): def dbg_mdir(d, mdir):
nonlocal pmdir
# show human-readable tag representation # show human-readable tag representation
for i, (mid, rattr) in enumerate(mdir.rattrs()): for i, (mid, rattr) in enumerate(mdir.rattrs()):
print('%12s %s%s' % ( print('%12s %s%s' % (
'{%s}:' % ','.join('%04x' % block '{%s}:' % ','.join('%04x' % block
for block in mdir.blocks) 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) treeart.repr((mid, d, rattr.tag), color)
if args.get('tree') if args.get('tree')
or args.get('tree_rbyd') or args.get('tree_rbyd')
@@ -2879,6 +2886,7 @@ def main(disk, mroots=None, *,
if not args.get('raw') if not args.get('raw')
and not args.get('no_truncate') and not args.get('no_truncate')
else ''))) else '')))
pmdir = mdir
# show on-disk encoding of tags # show on-disk encoding of tags
if args.get('raw'): if args.get('raw'):
@@ -2896,17 +2904,14 @@ def main(disk, mroots=None, *,
2*w_width+1, '', 2*w_width+1, '',
line)) 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): def dbg_branch(d, bid, rbyd, rid, name):
nonlocal prbyd nonlocal pmdir
# show human-readable representation # show human-readable representation
for rattr in rbyd.rattrs(rid): for rattr in rbyd.rattrs(rid):
print('%12s %s%*s %-*s %s' % ( print('%12s %s%*s %-*s %s' % (
'%04x.%04x:' % (rbyd.block, rbyd.trunk) '%04x.%04x:' % (rbyd.block, rbyd.trunk)
if prbyd is None or rbyd != prbyd if not isinstance(pmdir, Rbyd) or rbyd != pmdir
else '', else '',
treeart.repr( treeart.repr(
(mtree.mid(bid-(name.weight-1), -1), (mtree.mid(bid-(name.weight-1), -1),
@@ -2927,7 +2932,7 @@ def main(disk, mroots=None, *,
if not args.get('raw') if not args.get('raw')
and not args.get('no_truncate') and not args.get('no_truncate')
else '')) else ''))
prbyd = rbyd pmdir = rbyd
# show on-disk encoding of tags/data # show on-disk encoding of tags/data
if args.get('raw'): if args.get('raw'):
@@ -2976,8 +2981,8 @@ def main(disk, mroots=None, *,
'mroot' if mdir.mid == -1 else 'mdir', 'mroot' if mdir.mid == -1 else 'mdir',
mdir.addr()), mdir.addr()),
'\x1b[m' if color else '')) '\x1b[m' if color else ''))
pmdir = None
corrupted = True corrupted = True
prbyd = None
continue continue
# cycle detected? # cycle detected?
@@ -2989,17 +2994,14 @@ def main(disk, mroots=None, *,
'\x1b[31m' if color else '', '\x1b[31m' if color else '',
'(mroot cycle detected %s)' % mdir.addr(), '(mroot cycle detected %s)' % mdir.addr(),
'\x1b[m' if color else '')) '\x1b[m' if color else ''))
pmdir = None
corrupted = True corrupted = True
prbyd = None
continue continue
mrootseen.add(mdir) mrootseen.add(mdir)
# show the mdir # show the mdir
dbg_mdir(len(path), mdir) dbg_mdir(len(path), mdir)
# force next btree entry to be shown
prbyd = None
# btree node? # btree node?
else: else:
bid, rbyd = mdir bid, rbyd = mdir
@@ -3011,8 +3013,8 @@ def main(disk, mroots=None, *,
'\x1b[31m' if color else '', '\x1b[31m' if color else '',
'(corrupted rbyd %s)' % rbyd.addr(), '(corrupted rbyd %s)' % rbyd.addr(),
'\x1b[m' if color else '')) '\x1b[m' if color else ''))
pmdir = None
corrupted = True corrupted = True
prbyd = rbyd
continue continue
for rid, name in rbyd.rids(): for rid, name in rbyd.rids():