Reworked lfsr_mtree_pathlookup a bit to better leverage internal errors

This avoids implicit info, mid.mid=-1 implying a bad path, and mid.mid=0
implying the root directory, at a tradeoff of potentially making the
returned error codes a bit confusing (0 means the file is NOT found!).

Here are the now possible return codes, aside from lower-level errors
(IO, CORRUPT, etc):

- 0      => path is valid, file NOT found
- EXIST  => path is valid, file found
- INVAL  => path is valid, but points to root
- NOENT  => path is NOT valid, intermediate dir missing
- NOTDIR => path is NOT valid, intermediate dir is not a dir

Since the root has no real mdir entry, I think the special INVAL return
code is warranted. It needs special behavior in relevant functions
anyways.

Note that orphaned files still need special handling.

Code changes:

            code          stack
  before:  33944           2944
  after:   34036 (+0.3%)   2944 (+0.0%)
This commit is contained in:
Christopher Haster
2024-01-18 15:16:00 -06:00
parent a17b5e3cd6
commit 942427dc8c
3 changed files with 102 additions and 113 deletions
+2 -2
View File
@@ -281,14 +281,14 @@ code = '''
}
// try to make root, which doesn't make sense
lfsr_mkdir(&lfs, "/") => LFS_ERR_EXIST;
lfsr_mkdir(&lfs, "/") => LFS_ERR_INVAL;
// make a directory
err = lfsr_mkdir(&lfs, "ardvark");
assert(!err || (TEST_PLS && err == LFS_ERR_EXIST));
// try to make root, which doesn't make sense
lfsr_mkdir(&lfs, "/") => LFS_ERR_EXIST;
lfsr_mkdir(&lfs, "/") => LFS_ERR_INVAL;
// remount?
if (REMOUNT) {