From 7e96ff4dbd7c15b58d62017956bb24766e5590fe Mon Sep 17 00:00:00 2001 From: Christopher Haster Date: Thu, 20 Jun 2024 10:12:48 -0500 Subject: [PATCH] t: Adopted blocks={-1,-1} for clobbered/invalid mdirs blocks={0,0} technically worked, but only because the only mdirs allowed at block 0 are mroot blocks. In theory, an mdir at block 0 could match blocks={0,0} and clobber incorrectly, but it's not possible for such an mdir to be in a non-trivial mtree, since blocks={0,1} are reserved for the mrootanchor. But bleh, that's complicated. Setting blocks={-1,-1} makes the mdir truely invalid/unmatchable and provides a stronger invariant at a minor code cost. Code changes: code stack before: 34554 2624 after: 34566 (+0.0%) 2624 (+0.0%) --- lfs.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lfs.c b/lfs.c index 599721f4..71f39805 100644 --- a/lfs.c +++ b/lfs.c @@ -7834,7 +7834,7 @@ enum { .o.state=LFSR_TSTATE_MROOTANCHOR, \ .o.flags=_flags, \ .o.mdir.mid=-1, \ - .o.mdir.rbyd.blocks={0,0}, \ + .o.mdir.rbyd.blocks={-1,-1}, \ .ot=NULL, \ .u.mtortoise.mptr={{0, 0}}, \ .u.mtortoise.step=0, \ @@ -7883,8 +7883,8 @@ static void lfsr_fs_traverserewind(lfs_t *lfs, lfsr_mtraversal_t *mt) { mt->o.flags &= ~LFS_F_DIRTY; mt->o.state = LFSR_TSTATE_MROOTANCHOR; mt->o.mdir.mid = -1; - mt->o.mdir.rbyd.blocks[0] = 0; - mt->o.mdir.rbyd.blocks[1] = 0; + mt->o.mdir.rbyd.blocks[0] = -1; + mt->o.mdir.rbyd.blocks[1] = -1; mt->ot = NULL; mt->u.mtortoise.mptr.blocks[0] = 0; mt->u.mtortoise.mptr.blocks[1] = 0; @@ -7899,8 +7899,8 @@ static void lfsr_fs_traverseclobber(lfs_t *lfs, lfsr_mtraversal_t *mt, // increment the mid (to make progress) and reset to mdir iteration mt->o.state = LFSR_TSTATE_MDIRS; mt->o.mdir.mid = mid; - mt->o.mdir.rbyd.blocks[0] = 0; - mt->o.mdir.rbyd.blocks[1] = 0; + mt->o.mdir.rbyd.blocks[0] = -1; + mt->o.mdir.rbyd.blocks[1] = -1; mt->ot = NULL; } else { // move to next omdir