Tweaked dbg scripts to resize tag repr based on weight

This a compromise between padding the tag repr correctly and parsing
speed.

If we don't have to traverse an rbyd (for, say, tree printing), we don't
want to since parsing rbyds can get quite slow when things get big
(remember this is a filesystem!). This makes tag padding a bit of a hard
sell.

Previously this was hardcoded to 22 characters, but with the new file
struct printing it quickly became apparently this would be a problematic
limit:

  12288-15711 block w3424 0x1a.0 3424  67 64 79 70 61 69 6e 71  gdypainq

It's interesting to note that this has only become an issue for large
trees, where the weight/size in the tag can be arbitrarily large.

Fortunately we already have the weight of the rbyd after fetch, so we
can use a heuristic similar to the id padding:

  tag padding = 21 + nlog10(max(weight,1)+1)

---

Also dropped extra information with the -x/--device flag. It hasn't
really been useful and was implemented inconsistently. Maybe -x/--device
should just be dropped completely...
This commit is contained in:
Christopher Haster
2023-10-10 15:34:04 -05:00
parent c8b60f173e
commit b936e33643
4 changed files with 134 additions and 212 deletions
+12 -14
View File
@@ -845,7 +845,7 @@ def main(disk, roots=None, *,
# dynamically size the id field # dynamically size the id field
w_width = 2*m.ceil(m.log10(max(1, btree.weight)+1))+1 w_width = m.ceil(m.log10(max(1, btree.weight)+1))
# prbyd here means the last rendered rbyd, we update # prbyd here means the last rendered rbyd, we update
# in dbg_branch to always print interleaved addresses # in dbg_branch to always print interleaved addresses
@@ -855,32 +855,30 @@ def main(disk, roots=None, *,
# show human-readable representation # show human-readable representation
for i, (tag, j, d, data) in enumerate(tags): for i, (tag, j, d, data) in enumerate(tags):
print('%10s %s%*s %-22s %s' % ( print('%10s %s%*s %-*s %s' % (
'%04x.%04x:' % (rbyd.block, rbyd.trunk) '%04x.%04x:' % (rbyd.block, rbyd.trunk)
if prbyd is None or rbyd != prbyd if prbyd is None or rbyd != prbyd
else '', else '',
treerepr(bid, w, bd, rid, tag) treerepr(bid, w, bd, rid, tag)
if args.get('tree') or args.get('btree') else '', if args.get('tree') or args.get('btree') else '',
w_width, '' if i != 0 2*w_width+1, '' if i != 0
else '%d-%d' % (bid-(w-1), bid) if w > 1 else '%d-%d' % (bid-(w-1), bid) if w > 1
else bid if w > 0 else bid if w > 0
else '', else '',
tagrepr(tag, w if i == 0 else 0, len(data), None), 21+w_width, tagrepr(
next(xxd(data, 8), '') if not args.get('no_truncate') tag, w if i == 0 else 0, len(data), None),
next(xxd(data, 8), '')
if not args.get('raw') and not args.get('no_truncate')
else '')) else ''))
prbyd = rbyd prbyd = rbyd
# show in-device representation # show in-device representation
if args.get('device'): if args.get('device'):
print('%9s %*s%*s %-22s%s' % ( print('%9s %*s%*s %04x %08x %07x' % (
'', '',
t_width, '', t_width, '',
w_width, '', 2*w_width+1, '',
'%04x %08x %07x' % (tag, w if i == 0 else 0, len(data)), tag, w if i == 0 else 0, len(data)))
' %s' % ' '.join(
'%08x' % fromle32(
rbyd.data[j+d+i*4 : j+d + min(i*4+4,len(data))])
for i in range(min(m.ceil(len(data)/4), 3)))[:23]))
# show on-disk encoding of tags/data # show on-disk encoding of tags/data
if args.get('raw'): if args.get('raw'):
@@ -888,14 +886,14 @@ def main(disk, roots=None, *,
print('%9s: %*s%*s %s' % ( print('%9s: %*s%*s %s' % (
'%04x' % (j + o*16), '%04x' % (j + o*16),
t_width, '', t_width, '',
w_width, '', 2*w_width+1, '',
line)) line))
if args.get('raw') or args.get('no_truncate'): if args.get('raw') or args.get('no_truncate'):
for o, line in enumerate(xxd(data)): for o, line in enumerate(xxd(data)):
print('%9s: %*s%*s %s' % ( print('%9s: %*s%*s %s' % (
'%04x' % (j+d + o*16), '%04x' % (j+d + o*16),
t_width, '', t_width, '',
w_width, '', 2*w_width+1, '',
line)) line))
+71 -124
View File
@@ -1345,8 +1345,7 @@ def dbg_fstruct(f, block_size, btree, inlined=False, *,
# dynamically size the id field # dynamically size the id field
w_width = 0 if inlined else 2*m.ceil(m.log10(max(1, btree.weight)+1))+1 w_width = m.ceil(m.log10(max(1, btree.weight)+1))
i_width = 0 if inlined else 1
# prbyd here means the last rendered rbyd, we update # prbyd here means the last rendered rbyd, we update
# in dbg_branch to always print interleaved addresses # in dbg_branch to always print interleaved addresses
@@ -1356,55 +1355,48 @@ def dbg_fstruct(f, block_size, btree, inlined=False, *,
# show human-readable representation # show human-readable representation
for i, (tag, j, d, data) in enumerate(tags): for i, (tag, j, d, data) in enumerate(tags):
print('%12s %*s %s%*s%*s%-22s %s' % ( print('%12s %*s %s%s%-*s %s' % (
'%04x.%04x:' % (rbyd.block, rbyd.trunk) '%04x.%04x:' % (rbyd.block, rbyd.trunk)
if prbyd is None or rbyd != prbyd if prbyd is None or rbyd != prbyd
else '', else '',
m_width, '', m_width, '',
treerepr(bid, w, bd, rid, tag, False) treerepr(bid, w, bd, rid, tag, False)
if args.get('tree') or args.get('btree') else '', if args.get('tree') or args.get('btree') else '',
w_width, '' if i != 0 '%*s ' % (2*w_width+1, '' if i != 0
else '%d-%d' % (bid-(w-1), bid) if w > 1 else '%d-%d' % (bid-(w-1), bid) if w > 1
else bid if w > 0 else bid if w > 0
else '', else '') if not inlined else '',
i_width, '', 21+w_width, tagrepr(tag, w if i == 0 else 0, len(data), None),
tagrepr(tag, w if i == 0 else 0, len(data), None), next(xxd(data, 8), '')
next(xxd(data, 8), '') if not args.get('no_truncate') if not args.get('raw') and not args.get('no_truncate')
else '')) else ''))
prbyd = rbyd prbyd = rbyd
# show in-device representation # show in-device representation
if args.get('device'): if args.get('device'):
print('%11s %*s %*s%*s%*s%-22s%s' % ( print('%11s %*s %*s%s%04x %08x %07x' % (
'', '',
m_width, '', m_width, '',
t_width, '', t_width, '',
w_width, '', '%*s ' % (2*w_width+1, '') if not inlined else '',
i_width, '', tag, w if i == 0 else 0, len(data)))
'%04x %08x %07x' % (tag, w if i == 0 else 0, len(data)),
' %s' % ' '.join(
'%08x' % fromle32(
rbyd.data[j+d+i*4 : j+d + min(i*4+4,len(data))])
for i in range(min(m.ceil(len(data)/4), 3)))[:23]))
# show on-disk encoding of tags/data # show on-disk encoding of tags/data
if args.get('raw'): if args.get('raw'):
for o, line in enumerate(xxd(rbyd.data[j:j+d])): for o, line in enumerate(xxd(rbyd.data[j:j+d])):
print('%11s: %*s %*s%*s%*s%s' % ( print('%11s: %*s %*s%s%s' % (
'%04x' % (j + o*16), '%04x' % (j + o*16),
m_width, '', m_width, '',
t_width, '', t_width, '',
w_width, '', '%*s ' % (2*w_width+1, '') if not inlined else '',
i_width, '',
line)) line))
if args.get('raw') or args.get('no_truncate'): if args.get('raw') or args.get('no_truncate'):
for o, line in enumerate(xxd(data)): for o, line in enumerate(xxd(data)):
print('%11s: %*s %*s%*s%*s%s' % ( print('%11s: %*s %*s%s%s' % (
'%04x' % (j+d + o*16), '%04x' % (j+d + o*16),
m_width, '', m_width, '',
t_width, '', t_width, '',
w_width, '', '%*s ' % (2*w_width+1, '') if not inlined else '',
i_width, '',
line)) line))
def dbg_block(bid, w, rbyd, rid, bptr, block, off, size, data, bd): def dbg_block(bid, w, rbyd, rid, bptr, block, off, size, data, bd):
@@ -1412,69 +1404,61 @@ def dbg_fstruct(f, block_size, btree, inlined=False, *,
tag, _, _, _ = bptr tag, _, _, _ = bptr
# show human-readable representation # show human-readable representation
print('%12s %*s %s%*s%*s%-22s %s' % ( print('%12s %*s %s%s%-*s %s' % (
'%04x.%04x:' % (rbyd.block, rbyd.trunk) '%04x.%04x:' % (rbyd.block, rbyd.trunk)
if prbyd is None or rbyd != prbyd if prbyd is None or rbyd != prbyd
else '', else '',
m_width, '', m_width, '',
treerepr(bid, w, bd, rid, tag, True) treerepr(bid, w, bd, rid, tag, True)
if args.get('tree') or args.get('btree') else '', if args.get('tree') or args.get('btree') else '',
w_width, '%d-%d' % (bid-(w-1), bid) if w > 1 '%*s ' % (2*w_width+1, '%d-%d' % (bid-(w-1), bid) if w > 1
else bid if w > 0 else bid if w > 0
else '', else '') if not inlined else '',
i_width, '', 21+w_width, 'block%s 0x%x.%x %d' % (
'block%s 0x%x.%x %d' % (
' w%d' % w if w else '', ' w%d' % w if w else '',
block, off, size), block, off, size),
next(xxd(data, 8), '') if not args.get('no_truncate') next(xxd(data, 8), '')
if not args.get('raw') and not args.get('no_truncate')
else '')) else ''))
prbyd = rbyd prbyd = rbyd
# show in-device representation # show in-device representation
if args.get('device'): if args.get('device'):
_, j, d, data_ = bptr _, j, d, data_ = bptr
print('%11s %*s %*s%*s%*s%-22s%s' % ( print('%11s %*s %*s%s%04x %08x %07x' % (
'', '',
m_width, '', m_width, '',
t_width, '', t_width, '',
w_width, '', '%*s ' % (2*w_width+1, '') if not inlined else '',
i_width, '', tag, w, len(data_)))
'%04x %08x %07x' % (tag, w, len(data_)),
' %s' % ' '.join(
'%08x' % fromle32(
rbyd.data[j+d+i*4 : j+d + min(i*4+4,len(data_))])
for i in range(min(m.ceil(len(data_)/4), 3)))[:23]))
# show on-disk encoding of tags/bptr/data # show on-disk encoding of tags/bptr/data
if args.get('raw'): if args.get('raw'):
_, j, d, data_ = bptr _, j, d, data_ = bptr
for o, line in enumerate(xxd(rbyd.data[j:j+d])): for o, line in enumerate(xxd(rbyd.data[j:j+d])):
print('%11s: %*s %*s%*s%*s%s' % ( print('%11s: %*s %*s%s%s' % (
'%04x' % (j + o*16), '%04x' % (j + o*16),
m_width, '', m_width, '',
t_width, '', t_width, '',
w_width, '', '%*s ' % (2*w_width+1, '') if not inlined else '',
i_width, '',
line)) line))
if args.get('raw'): if args.get('raw'):
_, j, d, data_ = bptr _, j, d, data_ = bptr
for o, line in enumerate(xxd(data_)): for o, line in enumerate(xxd(data_)):
print('%11s: %*s %*s%*s%*s%s' % ( print('%11s: %*s %*s%s%s' % (
'%04x' % (j+d + o*16), '%04x' % (j+d + o*16),
m_width, '', m_width, '',
t_width, '', t_width, '',
w_width, '', '%*s ' % (2*w_width+1, '') if not inlined else '',
i_width, '',
line)) line))
if args.get('raw') or args.get('no_truncate'): if args.get('raw') or args.get('no_truncate'):
for o, line in enumerate(xxd(data)): for o, line in enumerate(xxd(data)):
print('%11s: %*s %*s%*s%*s%s' % ( print('%11s: %*s %*s%s%s' % (
'%04x.%04x' % (block, off + o*16) if o == 0 '%04x.%04x' % (block, off + o*16) if o == 0
else '%04x' % (off + o*16), else '%04x' % (off + o*16),
m_width, '', m_width, '',
t_width, '', t_width, '',
w_width, '', '%*s ' % (2*w_width+1, '') if not inlined else '',
i_width, '',
line)) line))
# if we show non-truncated file contents we need to # if we show non-truncated file contents we need to
# reset the rbyd address # reset the rbyd address
@@ -1782,40 +1766,35 @@ def main(disk, mroots=None, *,
mroot.addr(), mroot.rev, bweight//mleaf_weight, 1*mleaf_weight)) mroot.addr(), mroot.rev, bweight//mleaf_weight, 1*mleaf_weight))
# dynamically size the id field # dynamically size the id field
w_width = (m.ceil(m.log10(max(1, bweight//mleaf_weight)+1)) w_width = max(
+ 2*m.ceil(m.log10(max(1, rweight)+1)) m.ceil(m.log10(max(1, bweight//mleaf_weight)+1)),
+ 2) m.ceil(m.log10(max(1, rweight)+1)),
# in case of -1.-1
2)
# print config? # print config?
if args.get('config'): if args.get('config'):
for i, (repr_, tag, j, data) in enumerate(config.repr()): for i, (repr_, tag, j, data) in enumerate(config.repr()):
print('%12s %-*s %s' % ( print('%12s %-*s %s' % (
'config:' if i == 0 else '', 'config:' if i == 0 else '',
w_width + 23, repr_, 2*w_width+1 + 21+w_width + 1, repr_,
next(xxd(data, 8), '') next(xxd(data, 8), '')
if not args.get('no_truncate') else '')) if not args.get('raw')
and not args.get('no_truncate') else ''))
# show in-device representation # show in-device representation
if args.get('device'): if args.get('device'):
print('%11s %*s %s' % ( print('%11s %*s %04x %08x %07x' % (
'', '',
w_width, '', 2*w_width+1, '',
'%-22s%s' % ( tag, 0, len(data)))
'%04x %08x %07x' % (tag, 0, len(data)),
' %s' % ' '.join(
'%08x' % fromle32(
data[i*4 : min(i*4+4,len(data))])
for i in range(
min(m.ceil(len(data)/4),
3)))[:23]
if not args.get('no_truncate') else '')))
# show on-disk encoding # show on-disk encoding
if args.get('raw') or args.get('no_truncate'): if args.get('raw') or args.get('no_truncate'):
for o, line in enumerate(xxd(data)): for o, line in enumerate(xxd(data)):
print('%11s: %*s %s' % ( print('%11s: %*s %s' % (
'%04x' % (j + o*16), '%04x' % (j + o*16),
w_width, '', 2*w_width+1, '',
line)) line))
# print gstate? # print gstate?
@@ -1823,76 +1802,53 @@ def main(disk, mroots=None, *,
for i, (repr_, tag, data) in enumerate(gstate.repr()): for i, (repr_, tag, data) in enumerate(gstate.repr()):
print('%12s %-*s %s' % ( print('%12s %-*s %s' % (
'gstate:' if i == 0 else '', 'gstate:' if i == 0 else '',
w_width + 23, repr_, 2*w_width+1 + 21+w_width + 1, repr_,
next(xxd(data, 8), '') next(xxd(data, 8), '')
if not args.get('no_truncate') else '')) if not args.get('raw')
and not args.get('no_truncate') else ''))
# show in-device representation
if args.get('device'):
print('%11s %*s %s' % (
'',
w_width, '',
'%-22s%s' % (
'',
' %s' % ' '.join(
'%08x' % fromle32(
data[i*4 : min(i*4+4,len(data))])
for i in range(
min(m.ceil(len(data)/4),
3)))[:23]
if not args.get('no_truncate') else '')))
# show on-disk encoding # show on-disk encoding
if args.get('raw') or args.get('no_truncate'): if args.get('raw') or args.get('no_truncate'):
for o, line in enumerate(xxd(data)): for o, line in enumerate(xxd(data)):
print('%11s: %*s %s' % ( print('%11s: %*s %s' % (
'%04x' % (o*16), '%04x' % (o*16),
w_width, '', 2*w_width+1, '',
line)) line))
# print gdeltas? # print gdeltas?
if args.get('gdelta'): if args.get('gdelta'):
for mbid, mw, mdir, j, d, data in gstate.gdelta[tag]: for mbid, mw, mdir, j, d, data in gstate.gdelta[tag]:
print('%s{%s}: %*s %-22s %s%s' % ( print('%s{%s}: %*s %-*s %s%s' % (
'\x1b[90m' if color else '', '\x1b[90m' if color else '',
','.join('%04x' % block ','.join('%04x' % block
for block in it.chain([mdir.block], for block in it.chain([mdir.block],
mdir.redund_blocks)), mdir.redund_blocks)),
w_width, mbid//mleaf_weight, 2*w_width+1, mbid//mleaf_weight,
tagrepr(tag, 0, len(data)), 21+w_width, tagrepr(tag, 0, len(data)),
next(xxd(data, 8), '') next(xxd(data, 8), '')
if not args.get('no_truncate') else '', if not args.get('raw')
and not args.get('no_truncate') else '',
'\x1b[m' if color else '')) '\x1b[m' if color else ''))
# show in-device representation # show in-device representation
if args.get('device'): if args.get('device'):
print('%11s %*s %s' % ( print('%11s %*s %04x %08x %07x' % (
'', '',
w_width, '', 2*w_width+1, '',
'%-22s%s' % ( tag, 0, len(data)))
'%04x %08x %07x' % (tag, 0, len(data)),
' %s' % ' '.join(
'%08x' % fromle32(
data[i*4
: min(i*4+4,len(data))])
for i in range(
min(m.ceil(len(data)/4),
3)))[:23]
if not args.get('no_truncate')
else '')))
# show on-disk encoding # show on-disk encoding
if args.get('raw'): if args.get('raw'):
for o, line in enumerate(xxd(mdir.data[j:j+d])): for o, line in enumerate(xxd(mdir.data[j:j+d])):
print('%11s: %*s %s' % ( print('%11s: %*s %s' % (
'%04x' % (j + o*16), '%04x' % (j + o*16),
w_width, '', 2*w_width+1, '',
line)) line))
if args.get('raw') or args.get('no_truncate'): if args.get('raw') or args.get('no_truncate'):
for o, line in enumerate(xxd(data)): for o, line in enumerate(xxd(data)):
print('%11s: %*s %s' % ( print('%11s: %*s %s' % (
'%04x' % (j+d + o*16), '%04x' % (j+d + o*16),
w_width, '', 2*w_width+1, '',
line)) line))
# print dtree? # print dtree?
@@ -1960,7 +1916,7 @@ def main(disk, mroots=None, *,
for block in it.chain([mdir.block], for block in it.chain([mdir.block],
mdir.redund_blocks)) mdir.redund_blocks))
if mbid != pmbid else '', if mbid != pmbid else '',
w_width, '%d.%d-%d' % ( 2*w_width+1, '%d.%d-%d' % (
mbid//mleaf_weight, rid-(w-1), rid) mbid//mleaf_weight, rid-(w-1), rid)
if w > 1 else '%d.%d' % (mbid//mleaf_weight, rid) if w > 1 else '%d.%d' % (mbid//mleaf_weight, rid)
if w > 0 else '', if w > 0 else '',
@@ -1986,43 +1942,34 @@ def main(disk, mroots=None, *,
if done or rid_ != rid: if done or rid_ != rid:
break break
print('%12s %*s %-22s %s' % ( print('%12s %*s %-*s %s' % (
'', '',
w_width, '', 2*w_width+1, '',
tagrepr(tag_, w_, len(data)), 21+w_width, tagrepr(tag_, w_, len(data)),
next(xxd(data, 8), '') next(xxd(data, 8), '')
if not args.get('no_truncate') else '')) if not args.get('raw')
and not args.get('no_truncate')
else ''))
# show in-device representation # show in-device representation
if args.get('device'): if args.get('device'):
print('%11s %*s %s' % ( print('%11s %*s %04x %08x %07x' % (
'', '',
w_width, '', 2*w_width+1, '',
'%-22s%s' % ( tag_, w_, len(data)))
'%04x %08x %07x' % (
tag_, w_, len(data)),
' %s' % ' '.join(
'%08x' % fromle32(
data[i*4
: min(i*4+4,len(data))])
for i in range(
min(m.ceil(len(data)/4),
3)))[:23]
if not args.get('no_truncate')
else '')))
# show on-disk encoding # show on-disk encoding
if args.get('raw'): if args.get('raw'):
for o, line in enumerate(xxd(mdir.data[j:j+d])): for o, line in enumerate(xxd(mdir.data[j:j+d])):
print('%11s: %*s %s' % ( print('%11s: %*s %s' % (
'%04x' % (j + o*16), '%04x' % (j + o*16),
w_width, '', 2*w_width+1, '',
line)) line))
if args.get('raw') or args.get('no_truncate'): if args.get('raw') or args.get('no_truncate'):
for o, line in enumerate(xxd(data)): for o, line in enumerate(xxd(data)):
print('%11s: %*s %s' % ( print('%11s: %*s %s' % (
'%04x' % (j+d + o*16), '%04x' % (j+d + o*16),
w_width, '', 2*w_width+1, '',
line)) line))
# print file contents? # print file contents?
@@ -2042,7 +1989,7 @@ def main(disk, mroots=None, *,
j, j,
0), 0),
inlined=True, inlined=True,
m_width=w_width, m_width=2*w_width+1,
color=color, color=color,
args=args) args=args)
@@ -2055,7 +2002,7 @@ def main(disk, mroots=None, *,
weight, d_ = fromleb128(data[d:]); d += d_ weight, d_ = fromleb128(data[d:]); d += d_
dbg_fstruct(f, block_size, dbg_fstruct(f, block_size,
Rbyd.fetch(f, block_size, mdir.block, trunk), Rbyd.fetch(f, block_size, mdir.block, trunk),
m_width=w_width, m_width=2*w_width+1,
color=color, color=color,
args=args) args=args)
@@ -2074,7 +2021,7 @@ def main(disk, mroots=None, *,
j, j,
0), 0),
inlined=True, inlined=True,
m_width=w_width, m_width=2*w_width+1,
color=color, color=color,
args=args) args=args)
@@ -2089,7 +2036,7 @@ def main(disk, mroots=None, *,
cksum = fromle32(data[d:]); d += 4 cksum = fromle32(data[d:]); d += 4
dbg_fstruct(f, block_size, dbg_fstruct(f, block_size,
Rbyd.fetch(f, block_size, block, trunk), Rbyd.fetch(f, block_size, block, trunk),
m_width=w_width, m_width=2*w_width+1,
color=color, color=color,
args=args) args=args)
+28 -37
View File
@@ -1337,39 +1337,31 @@ def main(disk, mroots=None, *,
def dbg_mdir(mdir, mbid, mw, md): def dbg_mdir(mdir, mbid, mw, md):
for i, (rid, tag, w, j, d, data) in enumerate(mdir): for i, (rid, tag, w, j, d, data) in enumerate(mdir):
# show human-readable tag representation # show human-readable tag representation
print('%12s %s%-57s' % ( print('%12s %s%s' % (
'{%s}:' % ','.join('%04x' % block '{%s}:' % ','.join('%04x' % block
for block in it.chain([mdir.block], for block in it.chain([mdir.block],
mdir.redund_blocks)) mdir.redund_blocks))
if i == 0 else '', if i == 0 else '',
treerepr(mbid-max(mw-1, 0), 0, md, 0, rid, tag) treerepr(mbid-max(mw-1, 0), 0, md, 0, rid, tag)
if args.get('tree') or args.get('btree') else '', if args.get('tree') or args.get('btree') else '',
'%*s %-22s%s' % ( '%*s %-*s%s' % (
w_width, '%d.%d-%d' % ( 2*w_width+1, '%d.%d-%d' % (
mbid//mleaf_weight, rid-(w-1), rid) mbid//mleaf_weight, rid-(w-1), rid)
if w > 1 else '%d.%d' % (mbid//mleaf_weight, rid) if w > 1 else '%d.%d' % (mbid//mleaf_weight, rid)
if w > 0 or i == 0 else '', if w > 0 or i == 0 else '',
tagrepr(tag, w, len(data), j), 21+w_width, tagrepr(tag, w, len(data), j),
' %s' % next(xxd(data, 8), '') ' %s' % next(xxd(data, 8), '')
if not args.get('no_truncate') else ''))) if not args.get('raw')
and not args.get('no_truncate')
else '')))
# show in-device representation # show in-device representation
if args.get('device'): if args.get('device'):
print('%11s %*s%*s %s' % ( print('%11s %*s%*s %04x %08x %07x' % (
'', '',
t_width, '', t_width, '',
w_width, '', 2*w_width+1, '',
'%-22s%s' % ( tag, w, len(data)));
'%04x %08x %07x' % (tag, w, len(data)),
' %s' % ' '.join(
'%08x' % fromle32(
mdir.data[j+d+i*4
: j+d+min(i*4+4,len(data))])
for i in range(
min(m.ceil(len(data)/4),
3)))[:23]
if not args.get('no_truncate')
and not tag & TAG_ALT else '')))
# show on-disk encoding of tags # show on-disk encoding of tags
if args.get('raw'): if args.get('raw'):
@@ -1377,7 +1369,7 @@ def main(disk, mroots=None, *,
print('%11s: %*s%*s %s' % ( print('%11s: %*s%*s %s' % (
'%04x' % (j + o*16), '%04x' % (j + o*16),
t_width, '', t_width, '',
w_width, '', 2*w_width+1, '',
line)) line))
if args.get('raw') or args.get('no_truncate'): if args.get('raw') or args.get('no_truncate'):
if not tag & TAG_ALT: if not tag & TAG_ALT:
@@ -1385,7 +1377,7 @@ def main(disk, mroots=None, *,
print('%11s: %*s%*s %s' % ( print('%11s: %*s%*s %s' % (
'%04x' % (j+d + o*16), '%04x' % (j+d + o*16),
t_width, '', t_width, '',
w_width, '', 2*w_width+1, '',
line)) line))
# prbyd here means the last rendered rbyd, we update # prbyd here means the last rendered rbyd, we update
@@ -1396,36 +1388,33 @@ def main(disk, mroots=None, *,
# show human-readable representation # show human-readable representation
for i, (tag, j, d, data) in enumerate(tags): for i, (tag, j, d, data) in enumerate(tags):
print('%12s %s%*s %-22s %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 prbyd is None or rbyd != prbyd
else '', else '',
treerepr(bid, w, bd, rid, 0, tag) treerepr(bid, w, bd, rid, 0, tag)
if args.get('tree') or args.get('btree') else '', if args.get('tree') or args.get('btree') else '',
w_width, '' if i != 0 2*w_width+1, '' if i != 0
else '%d-%d' % ( else '%d-%d' % (
(bid-(w-1))//mleaf_weight, (bid-(w-1))//mleaf_weight,
bid//mleaf_weight) bid//mleaf_weight)
if (w//mleaf_weight) > 1 if (w//mleaf_weight) > 1
else bid//mleaf_weight if w > 0 else bid//mleaf_weight if w > 0
else '', else '',
tagrepr(tag, w if i == 0 else 0, len(data), None), 21+w_width, tagrepr(
# note we render names a bit different here tag, w if i == 0 else 0, len(data), None),
next(xxd(data, 8), '') if not args.get('no_truncate') next(xxd(data, 8), '')
if not args.get('raw') and not args.get('no_truncate')
else '')) else ''))
prbyd = rbyd prbyd = rbyd
# show in-device representation # show in-device representation
if args.get('device'): if args.get('device'):
print('%11s %*s%*s %-22s%s' % ( print('%11s %*s%*s %04x %08x %07x' % (
'', '',
t_width, '', t_width, '',
w_width, '', 2*w_width+1, '',
'%04x %08x %07x' % (tag, w if i == 0 else 0, len(data)), tag, w if i == 0 else 0, len(data)));
' %s' % ' '.join(
'%08x' % fromle32(
rbyd.data[j+d+i*4 : j+d + min(i*4+4,len(data))])
for i in range(min(m.ceil(len(data)/4), 3)))[:23]))
# show on-disk encoding of tags/data # show on-disk encoding of tags/data
if args.get('raw'): if args.get('raw'):
@@ -1433,14 +1422,14 @@ def main(disk, mroots=None, *,
print('%11s: %*s%*s %s' % ( print('%11s: %*s%*s %s' % (
'%04x' % (j + o*16), '%04x' % (j + o*16),
t_width, '', t_width, '',
w_width, '', 2*w_width+1, '',
line)) line))
if args.get('raw') or args.get('no_truncate'): if args.get('raw') or args.get('no_truncate'):
for o, line in enumerate(xxd(data)): for o, line in enumerate(xxd(data)):
print('%11s: %*s%*s %s' % ( print('%11s: %*s%*s %s' % (
'%04x' % (j+d + o*16), '%04x' % (j+d + o*16),
t_width, '', t_width, '',
w_width, '', 2*w_width+1, '',
line)) line))
@@ -1451,9 +1440,11 @@ def main(disk, mroots=None, *,
mroot.addr(), mroot.rev, bweight//mleaf_weight, 1*mleaf_weight)) mroot.addr(), mroot.rev, bweight//mleaf_weight, 1*mleaf_weight))
# dynamically size the id field # dynamically size the id field
w_width = (m.ceil(m.log10(max(1, bweight//mleaf_weight)+1)) w_width = max(
+ 2*m.ceil(m.log10(max(1, rweight)+1)) m.ceil(m.log10(max(1, bweight//mleaf_weight)+1)),
+ 2) m.ceil(m.log10(max(1, rweight)+1)),
# in case of -1.-1
2)
# show each mroot # show each mroot
prbyd = None prbyd = None
+23 -37
View File
@@ -478,14 +478,14 @@ def dbg_log(data, block_size, rev, eoff, weight, *,
# found new weight? # found new weight?
weight_ = max(weight_, weight__) weight_ = max(weight_, weight__)
w_width = 2*m.ceil(m.log10(max(1, weight_)+1))+1 w_width = m.ceil(m.log10(max(1, weight_)+1))
# print revision count # print revision count
if args.get('raw'): if args.get('raw'):
print('%8s: %*s%*s %s' % ( print('%8s: %*s%*s %s' % (
'%04x' % 0, '%04x' % 0,
lifetime_width, '', lifetime_width, '',
w_width, '', 2*w_width+1, '',
next(xxd(data[0:4])))) next(xxd(data[0:4]))))
# print tags # print tags
@@ -530,20 +530,20 @@ def dbg_log(data, block_size, rev, eoff, weight, *,
rid = lower_ + w-1 rid = lower_ + w-1
# show human-readable tag representation # show human-readable tag representation
print('%s%08x:%s %*s%s%*s %-57s%s%s' % ( print('%s%08x:%s %*s%s%*s %-*s%s%s' % (
'\x1b[90m' if color and j >= eoff else '', '\x1b[90m' if color and j >= eoff else '',
j, j,
'\x1b[m' if color and j >= eoff else '', '\x1b[m' if color and j >= eoff else '',
lifetime_width, lifetimerepr(j) if args.get('lifetimes') else '', lifetime_width, lifetimerepr(j) if args.get('lifetimes') else '',
'\x1b[90m' if color and j >= eoff else '', '\x1b[90m' if color and j >= eoff else '',
w_width, '' if (tag & 0xe000) != 0x0000 2*w_width+1, '' if (tag & 0xe000) != 0x0000
else '%d-%d' % (rid-(w-1), rid) if w > 1 else '%d-%d' % (rid-(w-1), rid) if w > 1
else rid, else rid,
'%-22s%s' % ( 56+w_width, '%-*s%s' % (
tagrepr(tag, w, size, j), 21+w_width, tagrepr(tag, w, size, j),
' %s' % next(xxd( ' %s' % next(xxd(
data[j+d:j+d+min(size, 8)], 8), '') data[j+d:j+d+min(size, 8)], 8), '')
if not args.get('no_truncate') if not args.get('raw') and not args.get('no_truncate')
and not tag & TAG_ALT else ''), and not tag & TAG_ALT else ''),
'\x1b[m' if color and j >= eoff else '', '\x1b[m' if color and j >= eoff else '',
' (%s)' % ', '.join(notes) if notes ' (%s)' % ', '.join(notes) if notes
@@ -554,19 +554,12 @@ def dbg_log(data, block_size, rev, eoff, weight, *,
# show in-device representation, including some extra # show in-device representation, including some extra
# cksum/parity info # cksum/parity info
if args.get('device'): if args.get('device'):
print('%s%8s %*s%*s %-47s %08x %x%s' % ( print('%s%8s %*s%*s %-*s %08x %x%s' % (
'\x1b[90m' if color and j >= eoff else '', '\x1b[90m' if color and j >= eoff else '',
'', '',
lifetime_width, '', lifetime_width, '',
w_width, '', 2*w_width+1, '',
'%-22s%s' % ( 21+w_width, '%04x %08x %07x' % (tag, w, size),
'%04x %08x %07x' % (tag, w, size),
' %s' % ' '.join(
'%08x' % fromle32(
data[j+d+i*4:j+d+min(i*4+4,size)])
for i in range(min(m.ceil(size/4), 3)))[:23]
if not args.get('no_truncate')
and not tag & TAG_ALT else ''),
cksum, cksum,
popc(cksum) & 1, popc(cksum) & 1,
'\x1b[m' if color and j >= eoff else '')) '\x1b[m' if color and j >= eoff else ''))
@@ -578,7 +571,7 @@ def dbg_log(data, block_size, rev, eoff, weight, *,
'\x1b[90m' if color and j >= eoff else '', '\x1b[90m' if color and j >= eoff else '',
'%04x' % (j + o*16), '%04x' % (j + o*16),
lifetime_width, '', lifetime_width, '',
w_width, '', 2*w_width+1, '',
line, line,
'\x1b[m' if color and j >= eoff else '')) '\x1b[m' if color and j >= eoff else ''))
if args.get('raw') or args.get('no_truncate'): if args.get('raw') or args.get('no_truncate'):
@@ -588,7 +581,7 @@ def dbg_log(data, block_size, rev, eoff, weight, *,
'\x1b[90m' if color and j >= eoff else '', '\x1b[90m' if color and j >= eoff else '',
'%04x' % (j+d + o*16), '%04x' % (j+d + o*16),
lifetime_width, '', lifetime_width, '',
w_width, '', 2*w_width+1, '',
line, line,
'\x1b[m' if color and j >= eoff else '')) '\x1b[m' if color and j >= eoff else ''))
@@ -800,7 +793,7 @@ def dbg_tree(data, block_size, rev, trunk, weight, *,
# dynamically size the id field # dynamically size the id field
w_width = 2*m.ceil(m.log10(max(1, weight)+1))+1 w_width = m.ceil(m.log10(max(1, weight)+1))
rid, tag = -1, 0 rid, tag = -1, 0
for i in it.count(): for i in it.count():
@@ -810,33 +803,26 @@ def dbg_tree(data, block_size, rev, trunk, weight, *,
break break
# show human-readable tag representation # show human-readable tag representation
print('%08x: %s%-57s' % ( print('%08x: %s%s' % (
j, j,
treerepr(rid, tag) if args.get('tree') else '', treerepr(rid, tag) if args.get('tree') else '',
'%*s %-22s%s' % ( '%*s %-*s%s' % (
w_width, '%d-%d' % (rid-(w-1), rid) 2*w_width+1, '%d-%d' % (rid-(w-1), rid)
if w > 1 else rid if w > 1 else rid
if w > 0 or i == 0 else '', if w > 0 or i == 0 else '',
tagrepr(tag, w, size, j), 21+w_width, tagrepr(tag, w, size, j),
' %s' % next(xxd( ' %s' % next(xxd(
data[j+d:j+d+min(size, 8)], 8), '') data[j+d:j+d+min(size, 8)], 8), '')
if not args.get('no_truncate') if not args.get('raw') and not args.get('no_truncate')
and not tag & TAG_ALT else ''))) and not tag & TAG_ALT else '')))
# show in-device representation # show in-device representation
if args.get('device'): if args.get('device'):
print('%8s %*s%*s %s' % ( print('%8s %*s%*s %04x %08x %07x' % (
'', '',
t_width, '', t_width, '',
w_width, '', 2*w_width+1, '',
'%-22s%s' % ( tag, w, size))
'%04x %08x %07x' % (tag, w, size),
' %s' % ' '.join(
'%08x' % fromle32(
data[j+d+i*4:j+d+min(i*4+4,size)])
for i in range(min(m.ceil(size/4), 3)))[:23]
if not args.get('no_truncate')
and not tag & TAG_ALT else '')))
# show on-disk encoding of tags # show on-disk encoding of tags
if args.get('raw'): if args.get('raw'):
@@ -844,7 +830,7 @@ def dbg_tree(data, block_size, rev, trunk, weight, *,
print('%8s: %*s%*s %s' % ( print('%8s: %*s%*s %s' % (
'%04x' % (j + o*16), '%04x' % (j + o*16),
t_width, '', t_width, '',
w_width, '', 2*w_width+1, '',
line)) line))
if args.get('raw') or args.get('no_truncate'): if args.get('raw') or args.get('no_truncate'):
if not tag & TAG_ALT: if not tag & TAG_ALT:
@@ -852,7 +838,7 @@ def dbg_tree(data, block_size, rev, trunk, weight, *,
print('%8s: %*s%*s %s' % ( print('%8s: %*s%*s %s' % (
'%04x' % (j+d + o*16), '%04x' % (j+d + o*16),
t_width, '', t_width, '',
w_width, '', 2*w_width+1, '',
line)) line))