diff --git a/lfs.c b/lfs.c index 8d607e23..5998fdb2 100644 --- a/lfs.c +++ b/lfs.c @@ -5640,9 +5640,9 @@ static int lfsr_mdir_commit(lfs_t *lfs, lfsr_mdir_t *mdir, "-> 0x{%"PRIx32",%"PRIx32"}" ", 0x{%"PRIx32",%"PRIx32"}", mdir->mid.bid, - mdir->u.m.blocks[1], mdir->u.m.blocks[0], - mdir_.u.m.blocks[1], mdir_.u.m.blocks[0], - msibling_.u.m.blocks[1], msibling_.u.m.blocks[0]); + mdir->u.m.blocks[0], mdir->u.m.blocks[1], + mdir_.u.m.blocks[0], mdir_.u.m.blocks[1], + msibling_.u.m.blocks[0], msibling_.u.m.blocks[1]); // because of defered commits, both children can still be reduced // to zero, need to catch this here @@ -5651,10 +5651,10 @@ static int lfsr_mdir_commit(lfs_t *lfs, lfsr_mdir_t *mdir, if (mdir_.u.m.weight == 0 && msibling_.u.m.weight == 0) { LFS_DEBUG("Dropping mdir %"PRId16" 0x{%"PRIx32",%"PRIx32"}", mdir_.mid.bid, - mdir_.u.m.blocks[1], mdir_.u.m.blocks[0]); + mdir_.u.m.blocks[0], mdir_.u.m.blocks[1]); LFS_DEBUG("Dropping mdir %"PRId16" 0x{%"PRIx32",%"PRIx32"}", msibling_.mid.bid, - msibling_.u.m.blocks[1], msibling_.u.m.blocks[0]); + msibling_.u.m.blocks[0], msibling_.u.m.blocks[1]); // mark as dropped mdir_.u.r.rbyd.trunk = 0; msibling_.u.r.rbyd.trunk = 0; @@ -5669,7 +5669,7 @@ static int lfsr_mdir_commit(lfs_t *lfs, lfsr_mdir_t *mdir, } else if (mdir_.u.m.weight == 0) { LFS_DEBUG("Dropping mdir %"PRId16" 0x{%"PRIx32",%"PRIx32"}", mdir_.mid.bid, - mdir_.u.m.blocks[1], mdir_.u.m.blocks[0]); + mdir_.u.m.blocks[0], mdir_.u.m.blocks[1]); // mark as dropped mdir_.u.r.rbyd.trunk = 0; @@ -5691,7 +5691,7 @@ static int lfsr_mdir_commit(lfs_t *lfs, lfsr_mdir_t *mdir, } else if (msibling_.u.m.weight == 0) { LFS_DEBUG("Dropping mdir %"PRId16" 0x{%"PRIx32",%"PRIx32"}", msibling_.mid.bid, - msibling_.u.m.blocks[1], msibling_.u.m.blocks[0]); + msibling_.u.m.blocks[0], msibling_.u.m.blocks[1]); // mark as dropped msibling_.u.r.rbyd.trunk = 0; @@ -5758,7 +5758,7 @@ static int lfsr_mdir_commit(lfs_t *lfs, lfsr_mdir_t *mdir, } else if (mdir->mid.bid != -1 && mdir_.u.m.weight == 0) { LFS_DEBUG("Dropping mdir %"PRId16" 0x{%"PRIx32",%"PRIx32"}", mdir->mid.bid, - mdir->u.m.blocks[1], mdir->u.m.blocks[0]); + mdir->u.m.blocks[0], mdir->u.m.blocks[1]); // mark as dropped mdir_.u.r.rbyd.trunk = 0; @@ -5784,8 +5784,8 @@ static int lfsr_mdir_commit(lfs_t *lfs, lfsr_mdir_t *mdir, LFS_DEBUG("Relocating mdir %"PRId16" 0x{%"PRIx32",%"PRIx32"} " "-> 0x{%"PRIx32",%"PRIx32"}", mdir->mid.bid, - mdir->u.m.blocks[1], mdir->u.m.blocks[0], - mdir_.u.m.blocks[1], mdir_.u.m.blocks[0]); + mdir->u.m.blocks[0], mdir->u.m.blocks[1], + mdir_.u.m.blocks[0], mdir_.u.m.blocks[1]); // update our mtree uint8_t buf[LFSR_MDIR_DSIZE]; @@ -5918,8 +5918,8 @@ static int lfsr_mdir_commit(lfs_t *lfs, lfsr_mdir_t *mdir, LFS_DEBUG("Relocating mroot 0x{%"PRIx32",%"PRIx32"} " "-> 0x{%"PRIx32",%"PRIx32"}", - mchildroot.u.m.blocks[1], mchildroot.u.m.blocks[0], - mchildroot_[1], mchildroot_[0]); + mchildroot.u.m.blocks[0], mchildroot.u.m.blocks[1], + mchildroot_[0], mchildroot_[1]); // commit mrootchild uint8_t buf[LFSR_MDIR_DSIZE]; @@ -5951,9 +5951,9 @@ static int lfsr_mdir_commit(lfs_t *lfs, lfsr_mdir_t *mdir, LFS_DEBUG("Extending mroot 0x{%"PRIx32",%"PRIx32"}" " -> 0x{%"PRIx32",%"PRIx32"}" ", 0x{%"PRIx32",%"PRIx32"}", - mchildroot.u.m.blocks[1], mchildroot.u.m.blocks[0], - mchildroot.u.m.blocks[1], mchildroot.u.m.blocks[0], - mchildroot_[1], mchildroot_[0]); + mchildroot.u.m.blocks[0], mchildroot.u.m.blocks[1], + mchildroot.u.m.blocks[0], mchildroot.u.m.blocks[1], + mchildroot_[0], mchildroot_[1]); // copy magic/config from current mroot lfsr_data_t magic; @@ -6534,7 +6534,7 @@ cycle_detect:; traversal->tortoise_blocks) == 0) { LFS_ERROR("Cycle detected during mtree traversal " "(0x{%"PRIx32",%"PRIx32"})", - traversal->mdir.u.m.blocks[1], traversal->mdir.u.m.blocks[0]); + traversal->mdir.u.m.blocks[0], traversal->mdir.u.m.blocks[1]); return LFS_ERR_CORRUPT; } if (traversal->tortoise_step diff --git a/lfs.h b/lfs.h index 947ede2e..e1005424 100644 --- a/lfs.h +++ b/lfs.h @@ -346,8 +346,6 @@ typedef struct lfs_cache { // TODO do we get ram savings with a lfsr_rorbyd_t substruct? need to measure typedef struct lfsr_rbyd { - // note this lines up with arrays of redundant blocks in other structures - lfs_block_t block; // note this lines up with weight in lfsr_btree_t lfs_size_t weight; // off=0, trunk=0 => not yet committed @@ -356,6 +354,8 @@ typedef struct lfsr_rbyd { lfs_off_t trunk; lfs_off_t off; uint32_t crc; + // note this lines up with arrays of redundant blocks in lfsr_mdir_t + lfs_block_t block; } lfsr_rbyd_t; // The maximum size of inlined pointers in a btree, this depends on littlefs's @@ -372,20 +372,15 @@ typedef struct lfsr_btree { // weight is common to both representations and its sign-bit indicates // if the btree is inlined struct { - lfs_size_t _padding; lfs_size_t weight; } b; struct { - // TODO complex ifdefs here to handle tag/size > 1/2 a word? - lfsr_tag_t tag; - uint8_t size; - uint8_t _padding; lfs_size_t weight; + lfsr_tag_t tag; + uint16_t size; uint8_t buffer[LFSR_BTREE_INLINESIZE]; } i; struct { - // note the sign bit of the rbyd.block indicates if the btree is - // inlined or a normal btree lfsr_rbyd_t rbyd; } r; } u; @@ -397,12 +392,15 @@ typedef struct lfsr_mdir { // here we make sure to line up our block array so it overlaps with // the block stored as the first entry in the rbyd struct { - lfs_block_t blocks[2]; lfs_size_t weight; + lfs_off_t trunk; + lfs_off_t off; + uint32_t crc; + lfs_block_t blocks[2]; } m; struct { - lfs_block_t redund_block; lfsr_rbyd_t rbyd; + lfs_block_t redund_block; } r; } u; } lfsr_mdir_t; diff --git a/tests/test_mtree.toml b/tests/test_mtree.toml index a4d29dbe..1c171d0f 100644 --- a/tests/test_mtree.toml +++ b/tests/test_mtree.toml @@ -3506,7 +3506,7 @@ code = ''' mid_.bid, mid_.rid, tag_, - mdir->u.m.blocks[1], mdir->u.m.blocks[0]); + mdir->u.m.blocks[0], mdir->u.m.blocks[1]); // keep track of seen blocks seen[mdir->u.m.blocks[1] / 8] |= 1 << (mdir->u.m.blocks[1] % 8); @@ -3631,7 +3631,7 @@ code = ''' mid_.bid, mid_.rid, tag_, - mdir->u.m.blocks[1], mdir->u.m.blocks[0]); + mdir->u.m.blocks[0], mdir->u.m.blocks[1]); // keep track of seen blocks seen[mdir->u.m.blocks[1] / 8] |= 1 << (mdir->u.m.blocks[1] % 8); @@ -3767,7 +3767,7 @@ code = ''' mid_.bid, mid_.rid, tag_, - mdir->u.m.blocks[1], mdir->u.m.blocks[0]); + mdir->u.m.blocks[0], mdir->u.m.blocks[1]); // keep track of seen blocks seen[mdir->u.m.blocks[1] / 8] |= 1 << (mdir->u.m.blocks[1] % 8); @@ -3895,7 +3895,7 @@ code = ''' mid_.bid, mid_.rid, tag_, - mdir->u.m.blocks[1], mdir->u.m.blocks[0]); + mdir->u.m.blocks[0], mdir->u.m.blocks[1]); // keep track of seen blocks seen[mdir->u.m.blocks[1] / 8] |= 1 << (mdir->u.m.blocks[1] % 8); @@ -4031,7 +4031,7 @@ code = ''' mid_.bid, mid_.rid, tag_, - mdir->u.m.blocks[1], mdir->u.m.blocks[0]); + mdir->u.m.blocks[0], mdir->u.m.blocks[1]); // keep track of seen blocks seen[mdir->u.m.blocks[1] / 8] |= 1 << (mdir->u.m.blocks[1] % 8); @@ -4194,7 +4194,7 @@ code = ''' mid_.bid, mid_.rid, tag_, - mdir->u.m.blocks[1], mdir->u.m.blocks[0]); + mdir->u.m.blocks[0], mdir->u.m.blocks[1]); // keep track of seen blocks seen[mdir->u.m.blocks[1] / 8] |= 1 << (mdir->u.m.blocks[1] % 8); @@ -4298,7 +4298,7 @@ code = ''' mid_.bid, mid_.rid, tag_, - mdir->u.m.blocks[1], mdir->u.m.blocks[0]); + mdir->u.m.blocks[0], mdir->u.m.blocks[1]); } else { // this shouldn't happen printf("traversal: %d.%d 0x%x %d\n",