Added bshrub support to dbgbmap.py

Forgot about this script.
This commit is contained in:
Christopher Haster
2024-01-21 20:06:22 -06:00
parent 991f04a4fb
commit e8b1be17fe
+44 -10
View File
@@ -163,6 +163,12 @@ def frommdir(data):
d += d_ d += d_
return blocks return blocks
def fromshrub(data):
d = 0
weight, d_ = fromleb128(data[d:]); d += d_
trunk, d_ = fromleb128(data[d:]); d += d_
return weight, trunk
def frombranch(data): def frombranch(data):
d = 0 d = 0
block, d_ = fromleb128(data[d:]); d += d_ block, d_ = fromleb128(data[d:]); d += d_
@@ -1214,7 +1220,7 @@ class Rbyd:
done, rid_, tag_, w_, j, d, data, _ = rbyd.lookup(rid, TAG_STRUCT) done, rid_, tag_, w_, j, d, data, _ = rbyd.lookup(rid, TAG_STRUCT)
# found another branch # found another branch
if tag_ == TAG_BRANCH: if tag_ & 0xfff == TAG_BRANCH:
# update our bid # update our bid
bid += rid - (w-1) bid += rid - (w-1)
@@ -1489,8 +1495,11 @@ def main(disk, mroots=None, *,
# find any file btrees in our mroot # find any file btrees in our mroot
for rid, tag, w, j, d, data in mroot: for rid, tag, w, j, d, data in mroot:
if tag == TAG_BLOCK or tag == TAG_BTREE: if (tag == TAG_DATA
btrees__.append((tag, data)) or tag == TAG_BLOCK
or tag == TAG_BSHRUB
or tag == TAG_BTREE):
btrees__.append((mroot, tag, data))
# stop here? # stop here?
if args.get('depth') and mdepth >= args.get('depth'): if args.get('depth') and mdepth >= args.get('depth'):
@@ -1525,8 +1534,11 @@ def main(disk, mroots=None, *,
# find any file btrees in our mdir # find any file btrees in our mdir
for rid, tag, w, j, d, data in mdir: for rid, tag, w, j, d, data in mdir:
if tag == TAG_BLOCK or tag == TAG_BTREE: if (tag == TAG_DATA
btrees__.append((tag, data)) or tag == TAG_BLOCK
or tag == TAG_BSHRUB
or tag == TAG_BTREE):
btrees__.append((mdir, tag, data))
# fetch the actual mtree, if there is one # fetch the actual mtree, if there is one
mtree = None mtree = None
@@ -1599,25 +1611,44 @@ def main(disk, mroots=None, *,
# find any file btrees in our mdir # find any file btrees in our mdir
for rid, tag, w, j, d, data in mdir_: for rid, tag, w, j, d, data in mdir_:
if tag == TAG_BLOCK or tag == TAG_BTREE: if (tag == TAG_DATA
btrees__.append((tag, data)) or tag == TAG_BLOCK
or tag == TAG_BSHRUB
or tag == TAG_BTREE):
btrees__.append((mdir_, tag, data))
# fetch any file btrees we found # fetch any file btrees we found
if not args.get('depth') or mdepth < args.get('depth'): if not args.get('depth') or mdepth < args.get('depth'):
for tag, data in btrees__: for mdir, tag, data in btrees__:
# inlined data?
if tag == TAG_DATA:
# ignore here
continue
# direct block? # direct block?
if tag == TAG_BLOCK: elif tag == TAG_BLOCK:
size, block, off = frombptr(data) size, block, off = frombptr(data)
# mark block in our bmap # mark block in our bmap
bmap.data(block, bmap.data(block,
off if args.get('in_use') else 0, off if args.get('in_use') else 0,
size if args.get('in_use') else block_size) size if args.get('in_use') else block_size)
datas_ += 1 datas_ += 1
continue
# inlined bshrub?
elif tag == TAG_BSHRUB:
weight, trunk = fromshrub(data)
btree = Rbyd.fetch(f, block_size, mdir.block, trunk)
shrub = True
# indirect btree? # indirect btree?
elif tag == TAG_BTREE: elif tag == TAG_BTREE:
w, block, trunk, cksum = frombtree(data) w, block, trunk, cksum = frombtree(data)
btree = Rbyd.fetch(f, block_size, block, trunk) btree = Rbyd.fetch(f, block_size, block, trunk)
shrub = False
else:
assert False
# traverse entries # traverse entries
bid = -1 bid = -1
@@ -1643,6 +1674,9 @@ def main(disk, mroots=None, *,
# mark btree inner nodes in our bmap # mark btree inner nodes in our bmap
d, (mid_, w_, rbyd_, rid_, tags_) = x d, (mid_, w_, rbyd_, rid_, tags_) = x
# ignore bshrub roots
if shrub and d == 0:
continue
for block in rbyd_.blocks: for block in rbyd_.blocks:
bmap.btree(block, bmap.btree(block,
rbyd_.eoff if args.get('in_use') rbyd_.eoff if args.get('in_use')
@@ -1661,7 +1695,7 @@ def main(disk, mroots=None, *,
or mdepth+len(path) < args.get('depth')): or mdepth+len(path) < args.get('depth')):
bptr__ = next(((tag, j, d, data) bptr__ = next(((tag, j, d, data)
for tag, j, d, data in tags for tag, j, d, data in tags
if tag == TAG_BLOCK), if tag & 0xfff == TAG_BLOCK),
None) None)
if bptr__: if bptr__: