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:
@@ -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) {
|
||||
|
||||
@@ -426,16 +426,16 @@ code = '''
|
||||
|
||||
// try reading our root as a file
|
||||
lfsr_file_t file;
|
||||
lfsr_file_open(&lfs, &file, "/", LFS_O_RDONLY) => LFS_ERR_ISDIR;
|
||||
lfsr_file_open(&lfs, &file, "/", LFS_O_RDONLY) => LFS_ERR_INVAL;
|
||||
|
||||
// try writing our root as a file
|
||||
lfsr_file_open(&lfs, &file, "/", LFS_O_WRONLY) => LFS_ERR_ISDIR;
|
||||
lfsr_file_open(&lfs, &file, "/", LFS_O_WRONLY) => LFS_ERR_INVAL;
|
||||
lfsr_file_open(&lfs, &file, "/",
|
||||
LFS_O_WRONLY | LFS_O_TRUNC) => LFS_ERR_ISDIR;
|
||||
LFS_O_WRONLY | LFS_O_TRUNC) => LFS_ERR_INVAL;
|
||||
lfsr_file_open(&lfs, &file, "/",
|
||||
LFS_O_WRONLY | LFS_O_CREAT) => LFS_ERR_ISDIR;
|
||||
LFS_O_WRONLY | LFS_O_CREAT) => LFS_ERR_INVAL;
|
||||
lfsr_file_open(&lfs, &file, "/",
|
||||
LFS_O_WRONLY | LFS_O_CREAT | LFS_O_TRUNC) => LFS_ERR_ISDIR;
|
||||
LFS_O_WRONLY | LFS_O_CREAT | LFS_O_TRUNC) => LFS_ERR_INVAL;
|
||||
|
||||
// try rename a file on top of our directory
|
||||
lfsr_file_open(&lfs, &file, "not_hello",
|
||||
@@ -446,7 +446,7 @@ code = '''
|
||||
lfsr_file_write(&lfs, &file, wbuf, wsize) => wsize;
|
||||
lfsr_file_close(&lfs, &file) => 0;
|
||||
|
||||
lfsr_rename(&lfs, "not_hello", "/") => LFS_ERR_ISDIR;
|
||||
lfsr_rename(&lfs, "not_hello", "/") => LFS_ERR_INVAL;
|
||||
|
||||
// remount?
|
||||
if (REMOUNT) {
|
||||
@@ -1734,7 +1734,7 @@ code = '''
|
||||
}
|
||||
|
||||
// rename the file
|
||||
lfsr_rename(&lfs, "amethyst", "/") => LFS_ERR_ISDIR;
|
||||
lfsr_rename(&lfs, "amethyst", "/") => LFS_ERR_INVAL;
|
||||
|
||||
// remount?
|
||||
if (REMOUNT) {
|
||||
|
||||
Reference in New Issue
Block a user