forked from Imagelibrary/littlefs
Added a separate tag encoding for the mtree
This helps with debugging and can avoid weird issues if a file btree ever accidentally ends up attached to id -1 (due to fs bug). Though a separate encoding isn't strictly necessary, maybe this should be reverted at some point.
This commit is contained in:
@@ -11,7 +11,6 @@ import struct
|
||||
TAG_NULL = 0x0000
|
||||
TAG_SUPERMAGIC = 0x0003
|
||||
TAG_SUPERCONFIG = 0x0004
|
||||
TAG_MROOT = 0x0304
|
||||
TAG_NAME = 0x0100
|
||||
TAG_BRANCH = 0x0100
|
||||
TAG_REG = 0x0101
|
||||
@@ -20,7 +19,9 @@ TAG_STRUCT = 0x0300
|
||||
TAG_INLINED = 0x0300
|
||||
TAG_BLOCK = 0x0302
|
||||
TAG_BTREE = 0x0303
|
||||
TAG_MROOT = 0x0304
|
||||
TAG_MDIR = 0x0305
|
||||
TAG_MTREE = 0x0306
|
||||
TAG_UATTR = 0x0400
|
||||
TAG_ALT = 0x4000
|
||||
TAG_ALTA = 0x6000
|
||||
@@ -145,8 +146,9 @@ def tagrepr(tag, w, size, off=None):
|
||||
'inlined' if tag == TAG_INLINED
|
||||
else 'block' if tag == TAG_BLOCK
|
||||
else 'btree' if tag == TAG_BTREE
|
||||
else 'mdir' if tag == TAG_MROOT
|
||||
else 'mroot' if tag == TAG_MROOT
|
||||
else 'mdir' if tag == TAG_MDIR
|
||||
else 'mtree' if tag == TAG_MTREE
|
||||
else 'struct 0x%02x' % (tag & 0xff),
|
||||
' w%d' % w if w else '',
|
||||
size)
|
||||
@@ -785,8 +787,8 @@ def main(disk, mroots=None, *,
|
||||
# fetch the actual mtree, if there is one
|
||||
mtree = None
|
||||
if not args.get('depth') or mdepth < args.get('depth'):
|
||||
done, rid, tag, w, j, d, data, _ = mroot.lookup(-1, TAG_BTREE)
|
||||
if not done and rid == -1 and tag == TAG_BTREE:
|
||||
done, rid, tag, w, j, d, data, _ = mroot.lookup(-1, TAG_MTREE)
|
||||
if not done and rid == -1 and tag == TAG_MTREE:
|
||||
w, trunk, block, crc = frombtree(data)
|
||||
mtree = Rbyd.fetch(f, block_size, block, trunk)
|
||||
|
||||
@@ -796,7 +798,8 @@ def main(disk, mroots=None, *,
|
||||
mid = -1
|
||||
while True:
|
||||
done, mid, w, rbyd, rid, tags, path = mtree.btree_lookup(
|
||||
f, block_size, mid+1, depth=args.get('depth')-mdepth)
|
||||
f, block_size, mid+1,
|
||||
depth=args.get('depth', mdepth)-mdepth)
|
||||
if done:
|
||||
break
|
||||
|
||||
@@ -915,7 +918,7 @@ def main(disk, mroots=None, *,
|
||||
if mtree:
|
||||
tree_, tdepth = mtree.btree_tree(
|
||||
f, block_size,
|
||||
depth=args.get('depth')-mdepth,
|
||||
depth=args.get('depth', mdepth)-mdepth,
|
||||
inner=args.get('inner'))
|
||||
|
||||
# connect a branch to the root of the tree
|
||||
@@ -923,7 +926,7 @@ def main(disk, mroots=None, *,
|
||||
if root:
|
||||
r_bid, r_bd, r_rid, r_tag = root.a
|
||||
tree.add(TBranch(
|
||||
a=(-1, d, 0, -1, TAG_BTREE),
|
||||
a=(-1, d, 0, -1, TAG_MTREE),
|
||||
b=(r_bid, r_bd, r_rid, 0, r_tag),
|
||||
d=d_-1,
|
||||
c='b',
|
||||
@@ -945,7 +948,8 @@ def main(disk, mroots=None, *,
|
||||
mid = -1
|
||||
while True:
|
||||
done, mid, w, rbyd, rid, tags, path = mtree.btree_lookup(
|
||||
f, block_size, mid+1, depth=args.get('depth')-mdepth)
|
||||
f, block_size, mid+1,
|
||||
depth=args.get('depth', mdepth)-mdepth)
|
||||
if done:
|
||||
break
|
||||
|
||||
@@ -974,7 +978,8 @@ def main(disk, mroots=None, *,
|
||||
mid = -1
|
||||
while True:
|
||||
done, mid, w, rbyd, rid, tags, path = mtree.btree_lookup(
|
||||
f, block_size, mid+1, depth=args.get('depth')-mdepth)
|
||||
f, block_size, mid+1,
|
||||
depth=args.get('depth', mdepth)-mdepth)
|
||||
if done:
|
||||
break
|
||||
|
||||
@@ -1132,7 +1137,7 @@ def main(disk, mroots=None, *,
|
||||
if mtree:
|
||||
tree_, tdepth = mtree.btree_btree(
|
||||
f, block_size,
|
||||
depth=args.get('depth')-mdepth,
|
||||
depth=args.get('depth', mdepth)-mdepth,
|
||||
inner=args.get('inner'))
|
||||
|
||||
# connect a branch to the root of the tree
|
||||
@@ -1140,7 +1145,7 @@ def main(disk, mroots=None, *,
|
||||
if root:
|
||||
r_bid, r_bd, r_rid, r_tag = root.a
|
||||
tree.add(TBranch(
|
||||
a=(-1, d, 0, -1, TAG_BTREE),
|
||||
a=(-1, d, 0, -1, TAG_MTREE),
|
||||
b=(r_bid, r_bd, r_rid, 0, r_tag),
|
||||
d=0,
|
||||
c='b',
|
||||
@@ -1164,7 +1169,7 @@ def main(disk, mroots=None, *,
|
||||
done, mid, w, rbyd, rid, tags, path = (
|
||||
mtree.btree_lookup(
|
||||
f, block_size, mid+1,
|
||||
depth=args.get('depth')-mdepth))
|
||||
depth=args.get('depth', mdepth)-mdepth))
|
||||
if done:
|
||||
break
|
||||
|
||||
@@ -1459,8 +1464,8 @@ def main(disk, mroots=None, *,
|
||||
|
||||
# fetch the actual mtree, if there is one
|
||||
if not args.get('depth') or mdepth < args.get('depth'):
|
||||
done, rid, tag, w, j, d, data, _ = mroot.lookup(-1, TAG_BTREE)
|
||||
if not done and rid == -1 and tag == TAG_BTREE:
|
||||
done, rid, tag, w, j, d, data, _ = mroot.lookup(-1, TAG_MTREE)
|
||||
if not done and rid == -1 and tag == TAG_MTREE:
|
||||
w, trunk, block, crc = frombtree(data)
|
||||
mtree = Rbyd.fetch(f, block_size, block, trunk)
|
||||
|
||||
@@ -1468,7 +1473,8 @@ def main(disk, mroots=None, *,
|
||||
mid = -1
|
||||
while True:
|
||||
done, mid, w, rbyd, rid, tags, path = mtree.btree_lookup(
|
||||
f, block_size, mid+1, depth=args.get('depth')-mdepth)
|
||||
f, block_size, mid+1,
|
||||
depth=args.get('depth', mdepth)-mdepth)
|
||||
if done:
|
||||
break
|
||||
|
||||
|
||||
Reference in New Issue
Block a user