Removed the mtree param from lfsr_mtree_* functions
There's only one mtree in a given filesystem. With the recent
lfsr_mdir_commit restructure, it makes more sense for the mtree to be
implicit.
code stack
before: 31096 2480
after: 31016 (-0.3%) 2480 (+0.0%)
This commit is contained in:
@@ -1839,8 +1839,8 @@ static lfsr_data_t lfsr_data_fromgrm(const lfsr_grm_t *grm,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// required by lfsr_data_readgrm
|
// required by lfsr_data_readgrm
|
||||||
static inline bool lfsr_mtree_isnull(const lfsr_mtree_t *mtree);
|
static inline bool lfsr_mtree_isnull(lfs_t *lfs);
|
||||||
static inline lfsr_mid_t lfsr_mtree_weight(const lfsr_mtree_t *mtree);
|
static inline lfsr_mid_t lfsr_mtree_weight(lfs_t *lfs);
|
||||||
|
|
||||||
static int lfsr_data_readgrm(lfs_t *lfs, lfsr_data_t *data,
|
static int lfsr_data_readgrm(lfs_t *lfs, lfsr_data_t *data,
|
||||||
lfsr_grm_t *grm) {
|
lfsr_grm_t *grm) {
|
||||||
@@ -1867,7 +1867,7 @@ static int lfsr_data_readgrm(lfs_t *lfs, lfsr_data_t *data,
|
|||||||
}
|
}
|
||||||
|
|
||||||
LFS_ASSERT(grm->rms[i] < lfs_smax32(
|
LFS_ASSERT(grm->rms[i] < lfs_smax32(
|
||||||
lfsr_mtree_weight(&lfs->mtree),
|
lfsr_mtree_weight(lfs),
|
||||||
lfsr_mleafweight(lfs)));
|
lfsr_mleafweight(lfs)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -5188,40 +5188,26 @@ static int lfsr_fs_consumegdelta(lfs_t *lfs, const lfsr_mdir_t *mdir) {
|
|||||||
.u.mptr.weight=(LFSR_MTREE_ISMPTR | (_weight)), \
|
.u.mptr.weight=(LFSR_MTREE_ISMPTR | (_weight)), \
|
||||||
.u.mptr.mptr=_mptr})
|
.u.mptr.mptr=_mptr})
|
||||||
|
|
||||||
static inline bool lfsr_mtree_isnull(const lfsr_mtree_t *mtree) {
|
static inline bool lfsr_mtree_isnull(lfs_t *lfs) {
|
||||||
return (lfsr_mid_t)mtree->u.weight == (LFSR_MTREE_ISMPTR | 0);
|
return (lfsr_mid_t)lfs->mtree.u.weight == (LFSR_MTREE_ISMPTR | 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline bool lfsr_mtree_ismptr(const lfsr_mtree_t *mtree) {
|
static inline bool lfsr_mtree_ismptr(lfs_t *lfs) {
|
||||||
return mtree->u.weight & LFSR_MTREE_ISMPTR;
|
return lfs->mtree.u.weight & LFSR_MTREE_ISMPTR;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline bool lfsr_mtree_isbtree(const lfsr_mtree_t *mtree) {
|
static inline bool lfsr_mtree_isbtree(lfs_t *lfs) {
|
||||||
return !(mtree->u.weight & LFSR_MTREE_ISMPTR);
|
return !(lfs->mtree.u.weight & LFSR_MTREE_ISMPTR);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline lfsr_mid_t lfsr_mtree_weight(const lfsr_mtree_t *mtree) {
|
static inline lfsr_mid_t lfsr_mtree_weight(lfs_t *lfs) {
|
||||||
return mtree->u.weight & ~LFSR_MTREE_ISMPTR;
|
return lfs->mtree.u.weight & ~LFSR_MTREE_ISMPTR;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int lfsr_mtree_cmp(
|
static int lfsr_mtree_lookup(lfs_t *lfs, lfsr_smid_t mid,
|
||||||
const lfsr_mtree_t *a,
|
lfsr_mdir_t *mdir_) {
|
||||||
const lfsr_mtree_t *b) {
|
|
||||||
if (a->u.weight != b->u.weight) {
|
|
||||||
return a->u.weight - b->u.weight;
|
|
||||||
} else if (lfsr_mtree_isnull(a)) {
|
|
||||||
return 0;
|
|
||||||
} else if (lfsr_mtree_ismptr(a)) {
|
|
||||||
return lfsr_mptr_cmp(&a->u.mptr.mptr, &b->u.mptr.mptr);
|
|
||||||
} else {
|
|
||||||
return lfsr_btree_cmp(&a->u.btree, &b->u.btree);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static int lfsr_mtree_lookup(lfs_t *lfs, const lfsr_mtree_t *mtree,
|
|
||||||
lfsr_smid_t mid, lfsr_mdir_t *mdir_) {
|
|
||||||
// looking up mroot?
|
// looking up mroot?
|
||||||
if (lfsr_mtree_isnull(mtree)) {
|
if (lfsr_mtree_isnull(lfs)) {
|
||||||
LFS_ASSERT(mid >= 0);
|
LFS_ASSERT(mid >= 0);
|
||||||
LFS_ASSERT(mid < (lfsr_smid_t)lfsr_mleafweight(lfs));
|
LFS_ASSERT(mid < (lfsr_smid_t)lfsr_mleafweight(lfs));
|
||||||
mdir_->mid = mid;
|
mdir_->mid = mid;
|
||||||
@@ -5229,21 +5215,21 @@ static int lfsr_mtree_lookup(lfs_t *lfs, const lfsr_mtree_t *mtree,
|
|||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
// looking up direct mdir?
|
// looking up direct mdir?
|
||||||
} else if (lfsr_mtree_ismptr(mtree)) {
|
} else if (lfsr_mtree_ismptr(lfs)) {
|
||||||
LFS_ASSERT(mid >= 0);
|
LFS_ASSERT(mid >= 0);
|
||||||
LFS_ASSERT(mid < (lfsr_smid_t)lfsr_mleafweight(lfs));
|
LFS_ASSERT(mid < (lfsr_smid_t)lfsr_mleafweight(lfs));
|
||||||
|
|
||||||
// fetch mdir
|
// fetch mdir
|
||||||
return lfsr_mdir_fetch(lfs, mdir_, mid, &mtree->u.mptr.mptr);
|
return lfsr_mdir_fetch(lfs, mdir_, mid, &lfs->mtree.u.mptr.mptr);
|
||||||
|
|
||||||
// look up mdir in actual mtree
|
// look up mdir in actual mtree
|
||||||
} else {
|
} else {
|
||||||
LFS_ASSERT(mid >= 0);
|
LFS_ASSERT(mid >= 0);
|
||||||
LFS_ASSERT(mid < (lfsr_smid_t)lfsr_mtree_weight(mtree));
|
LFS_ASSERT(mid < (lfsr_smid_t)lfsr_mtree_weight(lfs));
|
||||||
lfsr_bid_t bid;
|
lfsr_bid_t bid;
|
||||||
lfsr_tag_t tag;
|
lfsr_tag_t tag;
|
||||||
lfsr_data_t data;
|
lfsr_data_t data;
|
||||||
int err = lfsr_btree_lookupnext(lfs, &mtree->u.btree, mid,
|
int err = lfsr_btree_lookupnext(lfs, &lfs->mtree.u.btree, mid,
|
||||||
&bid, &tag, NULL, &data);
|
&bid, &tag, NULL, &data);
|
||||||
if (err) {
|
if (err) {
|
||||||
return err;
|
return err;
|
||||||
@@ -5263,8 +5249,7 @@ static int lfsr_mtree_lookup(lfs_t *lfs, const lfsr_mtree_t *mtree,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int lfsr_mtree_seek(lfs_t *lfs, const lfsr_mtree_t *mtree,
|
static int lfsr_mtree_seek(lfs_t *lfs, lfsr_mdir_t *mdir, lfs_off_t off) {
|
||||||
lfsr_mdir_t *mdir, lfs_off_t off) {
|
|
||||||
// upper layers should handle removed mdirs
|
// upper layers should handle removed mdirs
|
||||||
LFS_ASSERT(mdir->mid >= 0);
|
LFS_ASSERT(mdir->mid >= 0);
|
||||||
|
|
||||||
@@ -5276,7 +5261,7 @@ static int lfsr_mtree_seek(lfs_t *lfs, const lfsr_mtree_t *mtree,
|
|||||||
// we don't know how many rids are in each mdir until we fetch
|
// we don't know how many rids are in each mdir until we fetch
|
||||||
while (rid >= mdir->u.m.weight) {
|
while (rid >= mdir->u.m.weight) {
|
||||||
// end of mtree?
|
// end of mtree?
|
||||||
if (bid+lfsr_mleafweight(lfs) >= lfsr_mtree_weight(mtree)) {
|
if (bid+lfsr_mleafweight(lfs) >= lfsr_mtree_weight(lfs)) {
|
||||||
// if we hit the end of the mtree, park the mdir so all future
|
// if we hit the end of the mtree, park the mdir so all future
|
||||||
// seeks return noent
|
// seeks return noent
|
||||||
mdir->mid = bid + mdir->u.m.weight;
|
mdir->mid = bid + mdir->u.m.weight;
|
||||||
@@ -5285,7 +5270,7 @@ static int lfsr_mtree_seek(lfs_t *lfs, const lfsr_mtree_t *mtree,
|
|||||||
|
|
||||||
bid += lfsr_mleafweight(lfs);
|
bid += lfsr_mleafweight(lfs);
|
||||||
rid -= mdir->u.m.weight;
|
rid -= mdir->u.m.weight;
|
||||||
int err = lfsr_mtree_lookup(lfs, mtree, bid, mdir);
|
int err = lfsr_mtree_lookup(lfs, bid, mdir);
|
||||||
if (err) {
|
if (err) {
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
@@ -5558,7 +5543,7 @@ static int lfsr_mdir_commit__(lfs_t *lfs, lfsr_mdir_t *mdir,
|
|||||||
// upper layers.
|
// upper layers.
|
||||||
if (mdir_.u.m.weight == 0
|
if (mdir_.u.m.weight == 0
|
||||||
// unless we are an mroot
|
// unless we are an mroot
|
||||||
&& !(mdir_.mid == -1 || lfsr_mtree_isnull(&lfs->mtree))) {
|
&& !(mdir_.mid == -1 || lfsr_mtree_isnull(lfs))) {
|
||||||
// mark weight as zero, but note! we can not longer read from this mdir
|
// mark weight as zero, but note! we can not longer read from this mdir
|
||||||
// as our pcache may get clobbered
|
// as our pcache may get clobbered
|
||||||
mdir->u.m.weight = 0;
|
mdir->u.m.weight = 0;
|
||||||
@@ -6206,13 +6191,11 @@ static int lfsr_mroot_commit_(lfs_t *lfs,
|
|||||||
//
|
//
|
||||||
// this is atomic and propagates any mroot changes up the mroot chain
|
// this is atomic and propagates any mroot changes up the mroot chain
|
||||||
//
|
//
|
||||||
// TODO remove mtree param?
|
static int lfsr_mtree_commit(lfs_t *lfs,
|
||||||
//
|
|
||||||
static int lfsr_mtree_commit(lfs_t *lfs, lfsr_mtree_t *mtree,
|
|
||||||
const lfsr_attr_t *attrs, lfs_size_t attr_count) {
|
const lfsr_attr_t *attrs, lfs_size_t attr_count) {
|
||||||
lfsr_btree_t mtree_;
|
lfsr_btree_t mtree_;
|
||||||
// new mtree?
|
// new mtree?
|
||||||
if (lfsr_mtree_ismptr(mtree)) {
|
if (lfsr_mtree_ismptr(lfs)) {
|
||||||
int err = lfsr_btree_alloc(lfs, &mtree_);
|
int err = lfsr_btree_alloc(lfs, &mtree_);
|
||||||
if (err) {
|
if (err) {
|
||||||
return err;
|
return err;
|
||||||
@@ -6220,10 +6203,10 @@ static int lfsr_mtree_commit(lfs_t *lfs, lfsr_mtree_t *mtree,
|
|||||||
|
|
||||||
} else {
|
} else {
|
||||||
// create a copy
|
// create a copy
|
||||||
mtree_ = mtree->u.btree;
|
mtree_ = lfs->mtree.u.btree;
|
||||||
|
|
||||||
// mark as unerased in case of failure
|
// mark as unerased in case of failure
|
||||||
lfsr_btree_unerase(&mtree->u.btree);
|
lfsr_btree_unerase(&lfs->mtree.u.btree);
|
||||||
}
|
}
|
||||||
|
|
||||||
// commit to mtree
|
// commit to mtree
|
||||||
@@ -6254,7 +6237,7 @@ static int lfsr_mtree_commit(lfs_t *lfs, lfsr_mtree_t *mtree,
|
|||||||
// success? update in-device state, we must not error at this point
|
// success? update in-device state, we must not error at this point
|
||||||
|
|
||||||
// save our new mtree
|
// save our new mtree
|
||||||
mtree->u.btree = mtree_;
|
lfs->mtree.u.btree = mtree_;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -6265,7 +6248,7 @@ static int lfsr_mtree_commit(lfs_t *lfs, lfsr_mtree_t *mtree,
|
|||||||
static int lfsr_mdir_commit(lfs_t *lfs, lfsr_mdir_t *mdir,
|
static int lfsr_mdir_commit(lfs_t *lfs, lfsr_mdir_t *mdir,
|
||||||
const lfsr_attr_t *attrs, lfs_size_t attr_count) {
|
const lfsr_attr_t *attrs, lfs_size_t attr_count) {
|
||||||
LFS_ASSERT(mdir->mid == -1
|
LFS_ASSERT(mdir->mid == -1
|
||||||
|| lfsr_mtree_isnull(&lfs->mtree)
|
|| lfsr_mtree_isnull(lfs)
|
||||||
|| mdir->u.m.weight > 0);
|
|| mdir->u.m.weight > 0);
|
||||||
LFS_ASSERT(mdir->mid == -1
|
LFS_ASSERT(mdir->mid == -1
|
||||||
|| (mdir->mid & lfsr_midrmask(lfs)) <= mdir->u.m.weight);
|
|| (mdir->mid & lfsr_midrmask(lfs)) <= mdir->u.m.weight);
|
||||||
@@ -6352,14 +6335,14 @@ static int lfsr_mdir_commit(lfs_t *lfs, lfsr_mdir_t *mdir,
|
|||||||
// need to split?
|
// need to split?
|
||||||
if (err == LFS_ERR_RANGE) {
|
if (err == LFS_ERR_RANGE) {
|
||||||
// this should not happen unless we can't fit our mroot's metadata
|
// this should not happen unless we can't fit our mroot's metadata
|
||||||
LFS_ASSERT(mdir->mid != -1 || lfsr_mtree_isnull(&lfs->mtree));
|
LFS_ASSERT(mdir->mid != -1 || lfsr_mtree_isnull(lfs));
|
||||||
|
|
||||||
// if we're not the mroot, we need to consume the gstate so
|
// if we're not the mroot, we need to consume the gstate so
|
||||||
// we don't lose any info during the split
|
// we don't lose any info during the split
|
||||||
//
|
//
|
||||||
// we do this here so we don't have to worry about corner cases
|
// we do this here so we don't have to worry about corner cases
|
||||||
// with dropping mdirs during a split
|
// with dropping mdirs during a split
|
||||||
if (!lfsr_mtree_isnull(&lfs->mtree)) {
|
if (!lfsr_mtree_isnull(lfs)) {
|
||||||
err = lfsr_fs_consumegdelta(lfs, mdir);
|
err = lfsr_fs_consumegdelta(lfs, mdir);
|
||||||
if (err) {
|
if (err) {
|
||||||
return err;
|
return err;
|
||||||
@@ -6509,10 +6492,10 @@ static int lfsr_mdir_commit(lfs_t *lfs, lfsr_mdir_t *mdir,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// new mtree?
|
// new mtree?
|
||||||
if (lfsr_mtree_ismptr(&lfs->mtree)) {
|
if (lfsr_mtree_ismptr(lfs)) {
|
||||||
uint8_t mdir_buf[LFSR_MPTR_DSIZE];
|
uint8_t mdir_buf[LFSR_MPTR_DSIZE];
|
||||||
uint8_t msibling_buf[LFSR_MPTR_DSIZE];
|
uint8_t msibling_buf[LFSR_MPTR_DSIZE];
|
||||||
err = lfsr_mtree_commit(lfs, &lfs->mtree, LFSR_ATTRS(
|
err = lfsr_mtree_commit(lfs, LFSR_ATTRS(
|
||||||
LFSR_ATTR(0,
|
LFSR_ATTR(0,
|
||||||
MDIR, +lfsr_mleafweight(lfs),
|
MDIR, +lfsr_mleafweight(lfs),
|
||||||
FROMMPTR(lfsr_mdir_mptr(&mdir_), mdir_buf)),
|
FROMMPTR(lfsr_mdir_mptr(&mdir_), mdir_buf)),
|
||||||
@@ -6529,7 +6512,7 @@ static int lfsr_mdir_commit(lfs_t *lfs, lfsr_mdir_t *mdir,
|
|||||||
} else {
|
} else {
|
||||||
uint8_t mdir_buf[LFSR_MPTR_DSIZE];
|
uint8_t mdir_buf[LFSR_MPTR_DSIZE];
|
||||||
uint8_t msibling_buf[LFSR_MPTR_DSIZE];
|
uint8_t msibling_buf[LFSR_MPTR_DSIZE];
|
||||||
err = lfsr_mtree_commit(lfs, &lfs->mtree, LFSR_ATTRS(
|
err = lfsr_mtree_commit(lfs, LFSR_ATTRS(
|
||||||
LFSR_ATTR(mdir_.mid | lfsr_midrmask(lfs),
|
LFSR_ATTR(mdir_.mid | lfsr_midrmask(lfs),
|
||||||
MDIR, 0, FROMMPTR(lfsr_mdir_mptr(&mdir_), mdir_buf)),
|
MDIR, 0, FROMMPTR(lfsr_mdir_mptr(&mdir_), mdir_buf)),
|
||||||
LFSR_ATTR((mdir_.mid | lfsr_midrmask(lfs))+1,
|
LFSR_ATTR((mdir_.mid | lfsr_midrmask(lfs))+1,
|
||||||
@@ -6593,7 +6576,7 @@ static int lfsr_mdir_commit(lfs_t *lfs, lfsr_mdir_t *mdir,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// direct mdir?
|
// direct mdir?
|
||||||
if (lfsr_mtree_ismptr(&lfs->mtree)) {
|
if (lfsr_mtree_ismptr(lfs)) {
|
||||||
err = lfsr_mroot_commit_(lfs, -1, 0, NULL, LFSR_ATTRS(
|
err = lfsr_mroot_commit_(lfs, -1, 0, NULL, LFSR_ATTRS(
|
||||||
LFSR_ATTR(-1,
|
LFSR_ATTR(-1,
|
||||||
RM(WIDE(STRUCT)), 0, NULL)));
|
RM(WIDE(STRUCT)), 0, NULL)));
|
||||||
@@ -6605,7 +6588,7 @@ static int lfsr_mdir_commit(lfs_t *lfs, lfsr_mdir_t *mdir,
|
|||||||
|
|
||||||
// update our mtree
|
// update our mtree
|
||||||
} else {
|
} else {
|
||||||
err = lfsr_mtree_commit(lfs, &lfs->mtree, LFSR_ATTRS(
|
err = lfsr_mtree_commit(lfs, LFSR_ATTRS(
|
||||||
LFSR_ATTR(mdir_.mid | lfsr_midrmask(lfs),
|
LFSR_ATTR(mdir_.mid | lfsr_midrmask(lfs),
|
||||||
RM, -lfsr_mleafweight(lfs), NULL)));
|
RM, -lfsr_mleafweight(lfs), NULL)));
|
||||||
if (err) {
|
if (err) {
|
||||||
@@ -6615,7 +6598,7 @@ static int lfsr_mdir_commit(lfs_t *lfs, lfsr_mdir_t *mdir,
|
|||||||
|
|
||||||
// need to relocate?
|
// need to relocate?
|
||||||
} else if (lfsr_mdir_cmp(mdir, &mdir_) != 0
|
} else if (lfsr_mdir_cmp(mdir, &mdir_) != 0
|
||||||
&& !(mdir->mid == -1 || lfsr_mtree_isnull(&lfs->mtree))) {
|
&& !(mdir->mid == -1 || lfsr_mtree_isnull(lfs))) {
|
||||||
LFS_DEBUG("Relocating mdir %"PRId32" "
|
LFS_DEBUG("Relocating mdir %"PRId32" "
|
||||||
"0x{%"PRIx32",%"PRIx32"} -> 0x{%"PRIx32",%"PRIx32"}",
|
"0x{%"PRIx32",%"PRIx32"} -> 0x{%"PRIx32",%"PRIx32"}",
|
||||||
mdir->mid >> lfs->mleaf_bits,
|
mdir->mid >> lfs->mleaf_bits,
|
||||||
@@ -6624,7 +6607,7 @@ static int lfsr_mdir_commit(lfs_t *lfs, lfsr_mdir_t *mdir,
|
|||||||
|
|
||||||
relocate:;
|
relocate:;
|
||||||
// new mtree?
|
// new mtree?
|
||||||
if (lfsr_mtree_ismptr(&lfs->mtree)) {
|
if (lfsr_mtree_ismptr(lfs)) {
|
||||||
uint8_t mdir_buf[LFSR_MPTR_DSIZE];
|
uint8_t mdir_buf[LFSR_MPTR_DSIZE];
|
||||||
err = lfsr_mroot_commit_(lfs, -1, 0, NULL, LFSR_ATTRS(
|
err = lfsr_mroot_commit_(lfs, -1, 0, NULL, LFSR_ATTRS(
|
||||||
LFSR_ATTR(-1,
|
LFSR_ATTR(-1,
|
||||||
@@ -6641,7 +6624,7 @@ static int lfsr_mdir_commit(lfs_t *lfs, lfsr_mdir_t *mdir,
|
|||||||
} else {
|
} else {
|
||||||
// update our mtree
|
// update our mtree
|
||||||
uint8_t mdir_buf[LFSR_MPTR_DSIZE];
|
uint8_t mdir_buf[LFSR_MPTR_DSIZE];
|
||||||
err = lfsr_mtree_commit(lfs, &lfs->mtree, LFSR_ATTRS(
|
err = lfsr_mtree_commit(lfs, LFSR_ATTRS(
|
||||||
LFSR_ATTR(mdir_.mid | lfsr_midrmask(lfs),
|
LFSR_ATTR(mdir_.mid | lfsr_midrmask(lfs),
|
||||||
MDIR, 0, FROMMPTR(lfsr_mdir_mptr(&mdir_), mdir_buf))));
|
MDIR, 0, FROMMPTR(lfsr_mdir_mptr(&mdir_), mdir_buf))));
|
||||||
if (err) {
|
if (err) {
|
||||||
@@ -6828,19 +6811,19 @@ static int lfsr_mdir_namelookup(lfs_t *lfs, const lfsr_mdir_t *mdir,
|
|||||||
// lookup names in our mtree
|
// lookup names in our mtree
|
||||||
//
|
//
|
||||||
// if not found, rid will be the best place to insert
|
// if not found, rid will be the best place to insert
|
||||||
static int lfsr_mtree_namelookup(lfs_t *lfs, const lfsr_mtree_t *mtree,
|
static int lfsr_mtree_namelookup(lfs_t *lfs,
|
||||||
lfsr_did_t did, const char *name, lfs_size_t name_size,
|
lfsr_did_t did, const char *name, lfs_size_t name_size,
|
||||||
lfsr_mdir_t *mdir_, lfsr_tag_t *tag_, lfsr_data_t *data_) {
|
lfsr_mdir_t *mdir_, lfsr_tag_t *tag_, lfsr_data_t *data_) {
|
||||||
// do we only have mroot?
|
// do we only have mroot?
|
||||||
lfsr_mdir_t mdir;
|
lfsr_mdir_t mdir;
|
||||||
if (lfsr_mtree_isnull(mtree)) {
|
if (lfsr_mtree_isnull(lfs)) {
|
||||||
mdir = lfs->mroot;
|
mdir = lfs->mroot;
|
||||||
// treat inlined mdir as mid=0
|
// treat inlined mdir as mid=0
|
||||||
mdir.mid = 0;
|
mdir.mid = 0;
|
||||||
|
|
||||||
// direct mdir?
|
// direct mdir?
|
||||||
} else if (lfsr_mtree_ismptr(mtree)) {
|
} else if (lfsr_mtree_ismptr(lfs)) {
|
||||||
int err = lfsr_mdir_fetch(lfs, &mdir, 0, &mtree->u.mptr.mptr);
|
int err = lfsr_mdir_fetch(lfs, &mdir, 0, &lfs->mtree.u.mptr.mptr);
|
||||||
if (err) {
|
if (err) {
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
@@ -6908,8 +6891,7 @@ enum {
|
|||||||
//
|
//
|
||||||
// if not found, mdir_/did_/name_ will at least be set up
|
// if not found, mdir_/did_/name_ will at least be set up
|
||||||
// with what should be the parent
|
// with what should be the parent
|
||||||
static int lfsr_mtree_pathlookup(lfs_t *lfs, const lfsr_mtree_t *mtree,
|
static int lfsr_mtree_pathlookup(lfs_t *lfs, const char *path,
|
||||||
const char *path,
|
|
||||||
// TODO originally path itself was a double pointer, is that a
|
// TODO originally path itself was a double pointer, is that a
|
||||||
// better design?
|
// better design?
|
||||||
lfsr_mdir_t *mdir_, lfsr_tag_t *tag_,
|
lfsr_mdir_t *mdir_, lfsr_tag_t *tag_,
|
||||||
@@ -6997,7 +6979,7 @@ static int lfsr_mtree_pathlookup(lfs_t *lfs, const lfsr_mtree_t *mtree,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// lookup up this name in the mtree
|
// lookup up this name in the mtree
|
||||||
int err = lfsr_mtree_namelookup(lfs, mtree, did, name, name_size,
|
int err = lfsr_mtree_namelookup(lfs, did, name, name_size,
|
||||||
&mdir, &tag, NULL);
|
&mdir, &tag, NULL);
|
||||||
if (err && err != LFS_ERR_NOENT) {
|
if (err && err != LFS_ERR_NOENT) {
|
||||||
return err;
|
return err;
|
||||||
@@ -7248,7 +7230,7 @@ static int lfsr_traversal_read(lfs_t *lfs, lfsr_traversal_t *traversal,
|
|||||||
// traverse the mtree, including both inner btree nodes and mdirs
|
// traverse the mtree, including both inner btree nodes and mdirs
|
||||||
case LFSR_TRAVERSAL_MTREE:;
|
case LFSR_TRAVERSAL_MTREE:;
|
||||||
// no mtree? transition to traversing any opened mdirs
|
// no mtree? transition to traversing any opened mdirs
|
||||||
if (lfsr_mtree_ismptr(&lfs->mtree)) {
|
if (lfsr_mtree_ismptr(lfs)) {
|
||||||
traversal->u.opened = lfs->opened[LFS_TYPE_REG-LFS_TYPE_REG];
|
traversal->u.opened = lfs->opened[LFS_TYPE_REG-LFS_TYPE_REG];
|
||||||
traversal->state = LFSR_TRAVERSAL_OPENEDBLOCK;
|
traversal->state = LFSR_TRAVERSAL_OPENEDBLOCK;
|
||||||
continue;
|
continue;
|
||||||
@@ -8038,7 +8020,7 @@ static int lfsr_mountinited(lfs_t *lfs) {
|
|||||||
|
|
||||||
} else {
|
} else {
|
||||||
// found a direct mdir? keep track of this as our "mtree"
|
// found a direct mdir? keep track of this as our "mtree"
|
||||||
if (lfsr_mtree_isnull(&lfs->mtree)) {
|
if (lfsr_mtree_isnull(lfs)) {
|
||||||
lfs->mtree = LFSR_MTREE_MPTR(
|
lfs->mtree = LFSR_MTREE_MPTR(
|
||||||
*lfsr_mdir_mptr(&tinfo.u.mdir),
|
*lfsr_mdir_mptr(&tinfo.u.mdir),
|
||||||
lfsr_mleafweight(lfs));
|
lfsr_mleafweight(lfs));
|
||||||
@@ -8054,7 +8036,7 @@ static int lfsr_mountinited(lfs_t *lfs) {
|
|||||||
// found an mtree inner-node?
|
// found an mtree inner-node?
|
||||||
} else if (tinfo.tag == LFSR_TAG_BRANCH) {
|
} else if (tinfo.tag == LFSR_TAG_BRANCH) {
|
||||||
// found the root of the mtree?
|
// found the root of the mtree?
|
||||||
if (lfsr_mtree_isnull(&lfs->mtree)) {
|
if (lfsr_mtree_isnull(lfs)) {
|
||||||
lfs->mtree.u.btree = tinfo.u.rbyd;
|
lfs->mtree.u.btree = tinfo.u.rbyd;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -8177,7 +8159,7 @@ int lfsr_mount(lfs_t *lfs, const struct lfs_config *cfg) {
|
|||||||
lfs->mroot.u.m.blocks[0],
|
lfs->mroot.u.m.blocks[0],
|
||||||
lfs->mroot.u.m.blocks[1],
|
lfs->mroot.u.m.blocks[1],
|
||||||
lfs->mroot.u.m.trunk,
|
lfs->mroot.u.m.trunk,
|
||||||
lfsr_mtree_weight(&lfs->mtree) / lfsr_mleafweight(lfs),
|
lfsr_mtree_weight(lfs) / lfsr_mleafweight(lfs),
|
||||||
lfsr_mleafweight(lfs),
|
lfsr_mleafweight(lfs),
|
||||||
lfs->cfg->block_size,
|
lfs->cfg->block_size,
|
||||||
lfs->cfg->block_count);
|
lfs->cfg->block_count);
|
||||||
@@ -8366,9 +8348,9 @@ static int lfsr_fs_fixgrm(lfs_t *lfs) {
|
|||||||
// find our mdir
|
// find our mdir
|
||||||
lfsr_mdir_t mdir;
|
lfsr_mdir_t mdir;
|
||||||
LFS_ASSERT(lfs->grm.rms[0] < lfs_smax32(
|
LFS_ASSERT(lfs->grm.rms[0] < lfs_smax32(
|
||||||
lfsr_mtree_weight(&lfs->mtree),
|
lfsr_mtree_weight(lfs),
|
||||||
lfsr_mleafweight(lfs)));
|
lfsr_mleafweight(lfs)));
|
||||||
int err = lfsr_mtree_lookup(lfs, &lfs->mtree, lfs->grm.rms[0],
|
int err = lfsr_mtree_lookup(lfs, lfs->grm.rms[0],
|
||||||
&mdir);
|
&mdir);
|
||||||
if (err) {
|
if (err) {
|
||||||
return err;
|
return err;
|
||||||
@@ -8443,7 +8425,7 @@ int lfsr_mkdir(lfs_t *lfs, const char *path) {
|
|||||||
lfsr_did_t did;
|
lfsr_did_t did;
|
||||||
const char *name;
|
const char *name;
|
||||||
lfs_size_t name_size;
|
lfs_size_t name_size;
|
||||||
err = lfsr_mtree_pathlookup(lfs, &lfs->mtree, path,
|
err = lfsr_mtree_pathlookup(lfs, path,
|
||||||
&mdir, NULL,
|
&mdir, NULL,
|
||||||
&did, &name, &name_size);
|
&did, &name, &name_size);
|
||||||
if (err && (err != LFS_ERR_NOENT || lfsr_mdir_isroot(&mdir))) {
|
if (err && (err != LFS_ERR_NOENT || lfsr_mdir_isroot(&mdir))) {
|
||||||
@@ -8487,7 +8469,7 @@ int lfsr_mkdir(lfs_t *lfs, const char *path) {
|
|||||||
// Note we also need to be careful to catch integer overflow.
|
// Note we also need to be careful to catch integer overflow.
|
||||||
//
|
//
|
||||||
lfsr_did_t dmask = (1 << lfs_min32(
|
lfsr_did_t dmask = (1 << lfs_min32(
|
||||||
lfs_nlog2(lfsr_mtree_weight(&lfs->mtree))
|
lfs_nlog2(lfsr_mtree_weight(lfs))
|
||||||
+ lfs_nlog2(lfs->cfg->block_size/32),
|
+ lfs_nlog2(lfs->cfg->block_size/32),
|
||||||
32)) - 1;
|
32)) - 1;
|
||||||
lfsr_did_t did_ = lfs_crc32c(0, path, strlen(path)) & dmask;
|
lfsr_did_t did_ = lfs_crc32c(0, path, strlen(path)) & dmask;
|
||||||
@@ -8496,7 +8478,7 @@ int lfsr_mkdir(lfs_t *lfs, const char *path) {
|
|||||||
// available did
|
// available did
|
||||||
lfsr_openedmdir_t bookmark;
|
lfsr_openedmdir_t bookmark;
|
||||||
while (true) {
|
while (true) {
|
||||||
err = lfsr_mtree_namelookup(lfs, &lfs->mtree, did_, NULL, 0,
|
err = lfsr_mtree_namelookup(lfs, did_, NULL, 0,
|
||||||
&bookmark.mdir, NULL, NULL);
|
&bookmark.mdir, NULL, NULL);
|
||||||
if (err) {
|
if (err) {
|
||||||
if (err == LFS_ERR_NOENT) {
|
if (err == LFS_ERR_NOENT) {
|
||||||
@@ -8568,7 +8550,7 @@ int lfsr_remove(lfs_t *lfs, const char *path) {
|
|||||||
// lookup our entry
|
// lookup our entry
|
||||||
lfsr_mdir_t mdir;
|
lfsr_mdir_t mdir;
|
||||||
lfsr_tag_t tag;
|
lfsr_tag_t tag;
|
||||||
err = lfsr_mtree_pathlookup(lfs, &lfs->mtree, path,
|
err = lfsr_mtree_pathlookup(lfs, path,
|
||||||
&mdir, &tag,
|
&mdir, &tag,
|
||||||
NULL, NULL, NULL);
|
NULL, NULL, NULL);
|
||||||
if (err) {
|
if (err) {
|
||||||
@@ -8595,7 +8577,7 @@ int lfsr_remove(lfs_t *lfs, const char *path) {
|
|||||||
|
|
||||||
// then lookup the bookmark entry
|
// then lookup the bookmark entry
|
||||||
lfsr_mdir_t bookmark_mdir;
|
lfsr_mdir_t bookmark_mdir;
|
||||||
err = lfsr_mtree_namelookup(lfs, &lfs->mtree, did, NULL, 0,
|
err = lfsr_mtree_namelookup(lfs, did, NULL, 0,
|
||||||
&bookmark_mdir, NULL, NULL);
|
&bookmark_mdir, NULL, NULL);
|
||||||
if (err) {
|
if (err) {
|
||||||
LFS_ASSERT(err != LFS_ERR_NOENT);
|
LFS_ASSERT(err != LFS_ERR_NOENT);
|
||||||
@@ -8606,7 +8588,7 @@ int lfsr_remove(lfs_t *lfs, const char *path) {
|
|||||||
lfsr_grm_pushrm(&grm, bookmark_mdir.mid);
|
lfsr_grm_pushrm(&grm, bookmark_mdir.mid);
|
||||||
|
|
||||||
// check that the directory is empty
|
// check that the directory is empty
|
||||||
err = lfsr_mtree_seek(lfs, &lfs->mtree, &bookmark_mdir, 1);
|
err = lfsr_mtree_seek(lfs, &bookmark_mdir, 1);
|
||||||
if (err && err != LFS_ERR_NOENT) {
|
if (err && err != LFS_ERR_NOENT) {
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
@@ -8656,7 +8638,7 @@ int lfsr_rename(lfs_t *lfs, const char *old_path, const char *new_path) {
|
|||||||
// lookup old entry
|
// lookup old entry
|
||||||
lfsr_mdir_t old_mdir;
|
lfsr_mdir_t old_mdir;
|
||||||
lfsr_tag_t old_tag;
|
lfsr_tag_t old_tag;
|
||||||
err = lfsr_mtree_pathlookup(lfs, &lfs->mtree, old_path,
|
err = lfsr_mtree_pathlookup(lfs, old_path,
|
||||||
&old_mdir, &old_tag,
|
&old_mdir, &old_tag,
|
||||||
NULL, NULL, NULL);
|
NULL, NULL, NULL);
|
||||||
if (err) {
|
if (err) {
|
||||||
@@ -8673,7 +8655,7 @@ int lfsr_rename(lfs_t *lfs, const char *old_path, const char *new_path) {
|
|||||||
lfsr_did_t new_did;
|
lfsr_did_t new_did;
|
||||||
const char *new_name;
|
const char *new_name;
|
||||||
lfs_size_t new_name_size;
|
lfs_size_t new_name_size;
|
||||||
err = lfsr_mtree_pathlookup(lfs, &lfs->mtree, new_path,
|
err = lfsr_mtree_pathlookup(lfs, new_path,
|
||||||
&new_mdir, &new_tag,
|
&new_mdir, &new_tag,
|
||||||
&new_did, &new_name, &new_name_size);
|
&new_did, &new_name, &new_name_size);
|
||||||
if (err && (err != LFS_ERR_NOENT || lfsr_mdir_isroot(&new_mdir))) {
|
if (err && (err != LFS_ERR_NOENT || lfsr_mdir_isroot(&new_mdir))) {
|
||||||
@@ -8728,7 +8710,7 @@ int lfsr_rename(lfs_t *lfs, const char *old_path, const char *new_path) {
|
|||||||
|
|
||||||
// then lookup the bookmark entry
|
// then lookup the bookmark entry
|
||||||
lfsr_mdir_t bookmark_mdir;
|
lfsr_mdir_t bookmark_mdir;
|
||||||
err = lfsr_mtree_namelookup(lfs, &lfs->mtree, did, NULL, 0,
|
err = lfsr_mtree_namelookup(lfs, did, NULL, 0,
|
||||||
&bookmark_mdir, NULL, NULL);
|
&bookmark_mdir, NULL, NULL);
|
||||||
if (err) {
|
if (err) {
|
||||||
LFS_ASSERT(err != LFS_ERR_NOENT);
|
LFS_ASSERT(err != LFS_ERR_NOENT);
|
||||||
@@ -8739,7 +8721,7 @@ int lfsr_rename(lfs_t *lfs, const char *old_path, const char *new_path) {
|
|||||||
lfsr_grm_pushrm(&grm, bookmark_mdir.mid);
|
lfsr_grm_pushrm(&grm, bookmark_mdir.mid);
|
||||||
|
|
||||||
// check that the directory is empty
|
// check that the directory is empty
|
||||||
err = lfsr_mtree_seek(lfs, &lfs->mtree, &bookmark_mdir, 1);
|
err = lfsr_mtree_seek(lfs, &bookmark_mdir, 1);
|
||||||
if (err && err != LFS_ERR_NOENT) {
|
if (err && err != LFS_ERR_NOENT) {
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
@@ -8855,7 +8837,7 @@ int lfsr_stat(lfs_t *lfs, const char *path, struct lfs_info *info) {
|
|||||||
lfsr_tag_t tag;
|
lfsr_tag_t tag;
|
||||||
const char *name;
|
const char *name;
|
||||||
lfs_size_t name_size;
|
lfs_size_t name_size;
|
||||||
int err = lfsr_mtree_pathlookup(lfs, &lfs->mtree, path,
|
int err = lfsr_mtree_pathlookup(lfs, path,
|
||||||
&mdir, &tag,
|
&mdir, &tag,
|
||||||
NULL, &name, &name_size);
|
NULL, &name, &name_size);
|
||||||
if (err && err != LFS_ERR_INVAL) {
|
if (err && err != LFS_ERR_INVAL) {
|
||||||
@@ -8877,7 +8859,7 @@ int lfsr_dir_open(lfs_t *lfs, lfsr_dir_t *dir, const char *path) {
|
|||||||
// lookup our directory
|
// lookup our directory
|
||||||
lfsr_mdir_t mdir;
|
lfsr_mdir_t mdir;
|
||||||
lfsr_tag_t tag;
|
lfsr_tag_t tag;
|
||||||
int err = lfsr_mtree_pathlookup(lfs, &lfs->mtree, path,
|
int err = lfsr_mtree_pathlookup(lfs, path,
|
||||||
&mdir, &tag,
|
&mdir, &tag,
|
||||||
NULL, NULL, NULL);
|
NULL, NULL, NULL);
|
||||||
if (err && err != LFS_ERR_INVAL) {
|
if (err && err != LFS_ERR_INVAL) {
|
||||||
@@ -8944,7 +8926,7 @@ int lfsr_dir_read(lfs_t *lfs, lfsr_dir_t *dir, struct lfs_info *info) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// seek in case our mdir was dropped
|
// seek in case our mdir was dropped
|
||||||
int err = lfsr_mtree_seek(lfs, &lfs->mtree, &dir->m.mdir, 0);
|
int err = lfsr_mtree_seek(lfs, &dir->m.mdir, 0);
|
||||||
if (err) {
|
if (err) {
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
@@ -8958,7 +8940,7 @@ int lfsr_dir_read(lfs_t *lfs, lfsr_dir_t *dir, struct lfs_info *info) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// eagerly look up the next entry
|
// eagerly look up the next entry
|
||||||
err = lfsr_mtree_seek(lfs, &lfs->mtree, &dir->m.mdir, 1);
|
err = lfsr_mtree_seek(lfs, &dir->m.mdir, 1);
|
||||||
if (err && err != LFS_ERR_NOENT) {
|
if (err && err != LFS_ERR_NOENT) {
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
@@ -8984,7 +8966,7 @@ int lfsr_dir_seek(lfs_t *lfs, lfsr_dir_t *dir, lfs_soff_t off) {
|
|||||||
//
|
//
|
||||||
// note the -2 to adjust for dot entries
|
// note the -2 to adjust for dot entries
|
||||||
if (off > 2) {
|
if (off > 2) {
|
||||||
err = lfsr_mtree_seek(lfs, &lfs->mtree, &dir->m.mdir, off - 2);
|
err = lfsr_mtree_seek(lfs, &dir->m.mdir, off - 2);
|
||||||
if (err && err != LFS_ERR_NOENT) {
|
if (err && err != LFS_ERR_NOENT) {
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
@@ -9006,7 +8988,7 @@ int lfsr_dir_rewind(lfs_t *lfs, lfsr_dir_t *dir) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// lookup our bookmark in the mtree
|
// lookup our bookmark in the mtree
|
||||||
int err = lfsr_mtree_namelookup(lfs, &lfs->mtree, dir->did, NULL, 0,
|
int err = lfsr_mtree_namelookup(lfs, dir->did, NULL, 0,
|
||||||
&dir->m.mdir, NULL, NULL);
|
&dir->m.mdir, NULL, NULL);
|
||||||
if (err) {
|
if (err) {
|
||||||
LFS_ASSERT(err != LFS_ERR_NOENT);
|
LFS_ASSERT(err != LFS_ERR_NOENT);
|
||||||
@@ -9020,7 +9002,7 @@ int lfsr_dir_rewind(lfs_t *lfs, lfsr_dir_t *dir) {
|
|||||||
// eagerly lookup the next entry
|
// eagerly lookup the next entry
|
||||||
//
|
//
|
||||||
// this makes handling of corner cases with mixed removes/dir reads easier
|
// this makes handling of corner cases with mixed removes/dir reads easier
|
||||||
err = lfsr_mtree_seek(lfs, &lfs->mtree, &dir->m.mdir, 1);
|
err = lfsr_mtree_seek(lfs, &dir->m.mdir, 1);
|
||||||
if (err && err != LFS_ERR_NOENT) {
|
if (err && err != LFS_ERR_NOENT) {
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
@@ -9167,7 +9149,7 @@ int lfsr_file_opencfg(lfs_t *lfs, lfsr_file_t *file,
|
|||||||
lfsr_did_t did;
|
lfsr_did_t did;
|
||||||
const char *name;
|
const char *name;
|
||||||
lfs_size_t name_size;
|
lfs_size_t name_size;
|
||||||
int err = lfsr_mtree_pathlookup(lfs, &lfs->mtree, path,
|
int err = lfsr_mtree_pathlookup(lfs, path,
|
||||||
&file->m.mdir, &tag,
|
&file->m.mdir, &tag,
|
||||||
&did, &name, &name_size);
|
&did, &name, &name_size);
|
||||||
if (err && err != LFS_ERR_NOENT) {
|
if (err && err != LFS_ERR_NOENT) {
|
||||||
|
|||||||
+210
-210
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user