bmap: Initial scaffolding for on-disk block map
This is pretty exploratory work, so I'm going to try to be less thorough in commit messages until the dust settles. --- New tag for gbmapdelta: LFS3_TAG_GBMAPDELTA 0x0104 v--- ---1 ---- -1rr New tags for in-bmap block types: LFS3_TAG_BMRANGE 0x033u v--- --11 --11 uuuu LFS3_TAG_BMFREE 0x0330 v--- --11 --11 ---- LFS3_TAG_BMINFLIGHT 0x0331 v--- --11 --11 ---1 LFS3_TAG_BMINUSE 0x0332 v--- --11 --11 --1- LFS3_TAG_BMBAD 0x0333 v--- --11 --11 --11 LFS3_TAG_BMERASED 0x0334 v--- --11 --11 -1-- New gstate decoding for gbmap: .---+- -+- -+- -+- -. cursor: 1 leb128 <=5 bytes | cursor | known: 1 leb128 <=5 bytes +---+- -+- -+- -+- -+ block: 1 leb128 <=5 bytes | known | trunk: 1 leb128 <=4 bytes +---+- -+- -+- -+- -+ cksum: 1 le32 4 bytes | block | total: 23 bytes +---+- -+- -+- -+- -' | trunk | +---+- -+- -+- -+ | cksum | '---+---+---+---' New bmap node revdbg string: vvv---- -111111- -11---1- -11---1- (62 62 7e v0 bb~r) bmap node New mount/format/info flags (still unsure about these): LFS3_M_BMAPMODE 0x03000000 On-disk block map mode LFS3_M_BMAPNONE 0x00000000 Don't use the bmap LFS3_M_BMAPCACHE 0x01000000 Use the bmap to cache lookahead scans LFS3_M_BMAPSLOW 0x02000000 Use the slow bmap algorithm LFS3_M_BMAPFAST 0x03000000 Use the fast bmap algorithm New gbmap wcompat flag: LFS3_WCOMPAT_GBMAP 0x00002000 Global block-map in use
This commit is contained in:
+45
-9
@@ -39,6 +39,7 @@ TAG_NAMELIMIT = 0x0039 # 0x0039 v--- ---- --11 1--1
|
||||
TAG_FILELIMIT = 0x003a # 0x003a v--- ---- --11 1-1-
|
||||
TAG_GDELTA = 0x0100 ## 0x01tt v--- ---1 -ttt ttrr
|
||||
TAG_GRMDELTA = 0x0100 # 0x0100 v--- ---1 ---- ----
|
||||
TAG_GBMAPDELTA = 0x0104 # 0x0104 v--- ---1 ---- -1rr
|
||||
TAG_NAME = 0x0200 ## 0x02tt v--- --1- -ttt tttt
|
||||
TAG_BNAME = 0x0200 # 0x0200 v--- --1- ---- ----
|
||||
TAG_REG = 0x0201 # 0x0201 v--- --1- ---- ---1
|
||||
@@ -56,6 +57,12 @@ TAG_BTREE = 0x031c # 0x031c v--- --11 ---1 11rr
|
||||
TAG_MROOT = 0x0321 # 0x032r v--- --11 --1- --rr
|
||||
TAG_MDIR = 0x0325 # 0x0324 v--- --11 --1- -1rr
|
||||
TAG_MTREE = 0x032c # 0x032c v--- --11 --1- 11rr
|
||||
TAG_BMRANGE = 0x0330 # 0x033u v--- --11 --11 uuuu
|
||||
TAG_BMFREE = 0x0330 # 0x0330 v--- --11 --11 ----
|
||||
TAG_BMINFLIGHT = 0x0331 # 0x0331 v--- --11 --11 ---1
|
||||
TAG_BMINUSE = 0x0332 # 0x0332 v--- --11 --11 --1-
|
||||
TAG_BMBAD = 0x0333 # 0x0333 v--- --11 --11 --11
|
||||
TAG_BMERASED = 0x0334 # 0x0334 v--- --11 --11 -1--
|
||||
TAG_ATTR = 0x0400 ## 0x04aa v--- -1-a -aaa aaaa
|
||||
TAG_UATTR = 0x0400 # 0x04aa v--- -1-- -aaa aaaa
|
||||
TAG_SATTR = 0x0500 # 0x05aa v--- -1-1 -aaa aaaa
|
||||
@@ -340,6 +347,7 @@ def tagrepr(tag, weight=None, size=None, *,
|
||||
return '%s%s%s%s' % (
|
||||
'shrub' if tag & TAG_SHRUB else '',
|
||||
'grmdelta' if (tag & 0xfff) == TAG_GRMDELTA
|
||||
else 'gbmapdelta' if (tag & 0xfff) == TAG_GBMAPDELTA
|
||||
else 'gdelta 0x%02x' % (tag & 0xff),
|
||||
' w%d' % weight if weight else '',
|
||||
' %s' % size if size is not None else '')
|
||||
@@ -369,6 +377,13 @@ def tagrepr(tag, weight=None, size=None, *,
|
||||
else 'mroot' if (tag & 0xfff) == TAG_MROOT
|
||||
else 'mdir' if (tag & 0xfff) == TAG_MDIR
|
||||
else 'mtree' if (tag & 0xfff) == TAG_MTREE
|
||||
else 'bmfree' if (tag & 0xfff) == TAG_BMFREE
|
||||
else 'bminflight' if (tag & 0xfff) == TAG_BMINFLIGHT
|
||||
else 'bminuse' if (tag & 0xfff) == TAG_BMINUSE
|
||||
else 'bmbad' if (tag & 0xfff) == TAG_BMBAD
|
||||
else 'bmerased' if (tag & 0xfff) == TAG_BMERASED
|
||||
else 'bmrange 0x%x' % (tag & 0xf)
|
||||
if (tag & 0xff0) == TAG_BMRANGE
|
||||
else 'struct 0x%02x' % (tag & 0xff),
|
||||
' w%d' % weight if weight else '',
|
||||
' %s' % size if size is not None else '')
|
||||
@@ -2615,8 +2630,9 @@ class Config:
|
||||
|
||||
# lazy gstate object
|
||||
class Gstate:
|
||||
def __init__(self, mtree):
|
||||
def __init__(self, mtree, config):
|
||||
self.mtree = mtree
|
||||
self.config = config
|
||||
|
||||
# lookup a specific tag
|
||||
def lookup(self, tag=None, mask=None):
|
||||
@@ -2692,7 +2708,7 @@ class Gstate:
|
||||
tag = None
|
||||
mask = None
|
||||
|
||||
def __init__(self, mtree, tag, gdeltas):
|
||||
def __init__(self, mtree, config, tag, gdeltas):
|
||||
# replace tag with what we find
|
||||
self.tag = tag
|
||||
# keep track of gdeltas for debugging
|
||||
@@ -2742,8 +2758,8 @@ class Gstate:
|
||||
class Gcksum(Gstate):
|
||||
tag = TAG_GCKSUMDELTA
|
||||
|
||||
def __init__(self, mtree, tag, gdeltas):
|
||||
super().__init__(mtree, tag, gdeltas)
|
||||
def __init__(self, mtree, config, tag, gdeltas):
|
||||
super().__init__(mtree, config, tag, gdeltas)
|
||||
self.gcksum = fromle32(self.data)
|
||||
|
||||
def __int__(self):
|
||||
@@ -2756,8 +2772,8 @@ class Gstate:
|
||||
class Grm(Gstate):
|
||||
tag = TAG_GRMDELTA
|
||||
|
||||
def __init__(self, mtree, tag, gdeltas):
|
||||
super().__init__(mtree, tag, gdeltas)
|
||||
def __init__(self, mtree, config, tag, gdeltas):
|
||||
super().__init__(mtree, config, tag, gdeltas)
|
||||
queue = []
|
||||
d = 0
|
||||
for _ in range(2):
|
||||
@@ -2775,6 +2791,26 @@ class Gstate:
|
||||
def repr(self):
|
||||
return 'grm [%s]' % ', '.join(mid.repr() for mid in self.queue)
|
||||
|
||||
# the global block map
|
||||
class Gbmap(Gstate):
|
||||
tag = TAG_GBMAPDELTA
|
||||
|
||||
def __init__(self, mtree, config, tag, gdeltas):
|
||||
super().__init__(mtree, config, tag, gdeltas)
|
||||
d = 0
|
||||
self.cursor, d_ = fromleb128(self.data, d); d += d_
|
||||
self.known, d_ = fromleb128(self.data, d); d += d_
|
||||
block, trunk, cksum, d_ = frombranch(self.data, d); d += d_
|
||||
self.btree = Btree.fetchck(
|
||||
mtree.bd, block, trunk,
|
||||
config.geometry.block_count,
|
||||
cksum)
|
||||
|
||||
def repr(self):
|
||||
return 'gbmap %s k%s+%s' % (
|
||||
self.btree.addr(),
|
||||
self.known, self.cursor)
|
||||
|
||||
# keep track of known gstate
|
||||
_known = [g for g in Gstate.__subclasses__() if g.tag is not None]
|
||||
|
||||
@@ -2783,10 +2819,10 @@ class Gstate:
|
||||
# known config?
|
||||
for g in self._known:
|
||||
if (g.tag & ~(g.mask or 0)) == (tag & ~(g.mask or 0)):
|
||||
return g(self.mtree, tag, gdeltas)
|
||||
return g(self.mtree, self.config, tag, gdeltas)
|
||||
# otherwise return a marker class
|
||||
else:
|
||||
return Unknown(self.mtree, tag, gdeltas)
|
||||
return self.Unknown(self.mtree, self.config, tag, gdeltas)
|
||||
|
||||
# create cached accessors for known gstate
|
||||
def _parser(g):
|
||||
@@ -2807,7 +2843,7 @@ class Lfs3:
|
||||
|
||||
# create lazy config/gstate objects
|
||||
self.config = config or Config(self.mroot)
|
||||
self.gstate = gstate or Gstate(self.mtree)
|
||||
self.gstate = gstate or Gstate(self.mtree, self.config)
|
||||
|
||||
# go ahead and fetch some expected fields
|
||||
self.version = self.config.version
|
||||
|
||||
Reference in New Issue
Block a user