mirror of
https://github.com/littlefs-project/littlefs.git
synced 2025-12-01 12:20:02 +00:00
Adopted LFS3_ERR_BUSY for root-related errors
Now that we use LFS3_ERR_BUSY for traversals, we no longer have an excuse for not returning LFS3_ERR_BUSY on root-related errors: - lfs3_remove(&lfs3, "/") => LFS3_ERR_BUSY - lfs3_rename(&lfs3, "/", *) => LFS3_ERR_BUSY - lfs3_rename(&lfs3, *, "/") => LFS3_ERR_BUSY This better aligns with POSIX. Arguably we should have defined LFS3_ERR_BUSY for this case anyways, it's not like additional error codes cost much. No code changes.
This commit is contained in:
6
lfs3.c
6
lfs3.c
@ -11635,7 +11635,7 @@ int lfs3_remove(lfs3_t *lfs3, const char *path) {
|
||||
|
||||
// trying to remove the root dir?
|
||||
if (mdir.mid == -1) {
|
||||
return LFS3_ERR_INVAL;
|
||||
return LFS3_ERR_BUSY;
|
||||
}
|
||||
|
||||
// if we're removing a directory, we need to also remove the
|
||||
@ -11756,7 +11756,7 @@ int lfs3_rename(lfs3_t *lfs3, const char *old_path, const char *new_path) {
|
||||
|
||||
// trying to rename the root?
|
||||
if (old_mdir.mid == -1) {
|
||||
return LFS3_ERR_INVAL;
|
||||
return LFS3_ERR_BUSY;
|
||||
}
|
||||
|
||||
// lookup new entry
|
||||
@ -11786,7 +11786,7 @@ int lfs3_rename(lfs3_t *lfs3, const char *old_path, const char *new_path) {
|
||||
} else {
|
||||
// trying to rename the root?
|
||||
if (new_mdir.mid == -1) {
|
||||
return LFS3_ERR_INVAL;
|
||||
return LFS3_ERR_BUSY;
|
||||
}
|
||||
|
||||
// we allow reg <-> stickynote renaming, but renaming a non-dir
|
||||
|
||||
@ -2595,7 +2595,7 @@ code = '''
|
||||
}
|
||||
|
||||
// try to remove root, which doesn't really make sense
|
||||
lfs3_remove(&lfs3, "/") => LFS3_ERR_INVAL;
|
||||
lfs3_remove(&lfs3, "/") => LFS3_ERR_BUSY;
|
||||
|
||||
// make a directory
|
||||
err = lfs3_mkdir(&lfs3, "ardvark");
|
||||
@ -2605,7 +2605,7 @@ code = '''
|
||||
//
|
||||
// it doesn't really matter which error returns first, so accept both
|
||||
err = lfs3_remove(&lfs3, "/");
|
||||
assert(err == LFS3_ERR_NOTEMPTY || err == LFS3_ERR_INVAL);
|
||||
assert(err == LFS3_ERR_NOTEMPTY || err == LFS3_ERR_BUSY);
|
||||
|
||||
for (int remount = 0; remount < 2; remount++) {
|
||||
// remount?
|
||||
@ -4830,14 +4830,14 @@ code = '''
|
||||
}
|
||||
|
||||
// try to rename root, which doesn't really make sense
|
||||
lfs3_rename(&lfs3, "/", "notroot") => LFS3_ERR_INVAL;
|
||||
lfs3_rename(&lfs3, "/", "notroot") => LFS3_ERR_BUSY;
|
||||
|
||||
// make a directory
|
||||
err = lfs3_mkdir(&lfs3, "ardvark");
|
||||
assert(!err || (TEST_PLS && err == LFS3_ERR_EXIST));
|
||||
|
||||
// try to rename root, which doesn't really make sense
|
||||
lfs3_rename(&lfs3, "/", "notroot") => LFS3_ERR_INVAL;
|
||||
lfs3_rename(&lfs3, "/", "notroot") => LFS3_ERR_BUSY;
|
||||
|
||||
for (int remount = 0; remount < 2; remount++) {
|
||||
// remount?
|
||||
|
||||
@ -523,7 +523,7 @@ code = '''
|
||||
lfs3_file_write(&lfs3, &file, wbuf, wsize) => wsize;
|
||||
lfs3_file_close(&lfs3, &file) => 0;
|
||||
|
||||
lfs3_rename(&lfs3, "not_hello", "/") => LFS3_ERR_INVAL;
|
||||
lfs3_rename(&lfs3, "not_hello", "/") => LFS3_ERR_BUSY;
|
||||
|
||||
for (int remount = 0; remount < 2; remount++) {
|
||||
// remount?
|
||||
@ -2247,7 +2247,7 @@ code = '''
|
||||
}
|
||||
|
||||
// rename the file
|
||||
lfs3_rename(&lfs3, "amethyst", "/") => LFS3_ERR_INVAL;
|
||||
lfs3_rename(&lfs3, "amethyst", "/") => LFS3_ERR_BUSY;
|
||||
|
||||
for (int remount = 0; remount < 2; remount++) {
|
||||
// remount?
|
||||
|
||||
@ -2170,7 +2170,7 @@ code = '''
|
||||
"espresso/latte") => LFS3_ERR_INVAL;
|
||||
lfs3_rename(&lfs3,
|
||||
"coffee/vietnamese/../..",
|
||||
"espresso/cappuccino") => LFS3_ERR_INVAL;
|
||||
"espresso/cappuccino") => LFS3_ERR_BUSY;
|
||||
// this one works
|
||||
lfs3_rename(&lfs3,
|
||||
"coffee/thai/..",
|
||||
@ -2195,7 +2195,7 @@ code = '''
|
||||
}
|
||||
lfs3_rename(&lfs3,
|
||||
"coffee/coldbrew",
|
||||
"espresso/americano/../..") => LFS3_ERR_INVAL;
|
||||
"espresso/americano/../..") => LFS3_ERR_BUSY;
|
||||
lfs3_rename(&lfs3,
|
||||
"coffee/turkish",
|
||||
"espresso/macchiato/../../..") => LFS3_ERR_INVAL;
|
||||
@ -2224,14 +2224,14 @@ code = '''
|
||||
"espresso/latte/../../../..") => LFS3_ERR_INVAL;
|
||||
lfs3_rename(&lfs3,
|
||||
"coffee/vietnamese/../..",
|
||||
"espresso/cappuccino/../../../../..") => LFS3_ERR_INVAL;
|
||||
"espresso/cappuccino/../../../../..") => LFS3_ERR_BUSY;
|
||||
lfs3_rename(&lfs3,
|
||||
"coffee/thai/..",
|
||||
"espresso/mocha/../../../../../..") => LFS3_ERR_INVAL;
|
||||
|
||||
// remove paths
|
||||
lfs3_remove(&lfs3, "coffee/drip/..") => LFS3_ERR_NOTEMPTY;
|
||||
lfs3_remove(&lfs3, "coffee/coldbrew/../..") => LFS3_ERR_INVAL;
|
||||
lfs3_remove(&lfs3, "coffee/coldbrew/../..") => LFS3_ERR_BUSY;
|
||||
lfs3_remove(&lfs3, "coffee/turkish/../../..") => LFS3_ERR_INVAL;
|
||||
lfs3_remove(&lfs3, "coffee/tubruk/../../../..") => LFS3_ERR_INVAL;
|
||||
lfs3_remove(&lfs3, "coffee/vietnamese/../../../../..") => LFS3_ERR_INVAL;
|
||||
@ -4441,7 +4441,7 @@ code = '''
|
||||
"espresso/latte") => LFS3_ERR_INVAL;
|
||||
lfs3_rename(&lfs3,
|
||||
"coffee/_vietnamese/../..",
|
||||
"espresso/cappuccino") => LFS3_ERR_INVAL;
|
||||
"espresso/cappuccino") => LFS3_ERR_BUSY;
|
||||
// this one works
|
||||
lfs3_rename(&lfs3,
|
||||
"coffee/thai_/..",
|
||||
@ -4485,7 +4485,7 @@ code = '''
|
||||
"espresso/latte/../../../..") => LFS3_ERR_INVAL;
|
||||
lfs3_rename(&lfs3,
|
||||
"coffee/_vietnamese/../..",
|
||||
"espresso/cappuccino/../../../../..") => LFS3_ERR_INVAL;
|
||||
"espresso/cappuccino/../../../../..") => LFS3_ERR_BUSY;
|
||||
lfs3_rename(&lfs3,
|
||||
"coffee/thai_/..",
|
||||
"espresso/mocha/../../../../../..") => LFS3_ERR_INVAL;
|
||||
@ -4505,14 +4505,14 @@ code = '''
|
||||
"coffee/tub_uk/../../..") => LFS3_ERR_INVAL;
|
||||
lfs3_rename(&lfs3,
|
||||
"coffee/_vietnamese/../..",
|
||||
"coffee/_vietnamese/../..") => LFS3_ERR_INVAL;
|
||||
"coffee/_vietnamese/../..") => LFS3_ERR_BUSY;
|
||||
lfs3_rename(&lfs3,
|
||||
"coffee/thai_/..",
|
||||
"coffee/thai_/..") => 0;
|
||||
|
||||
// remove paths
|
||||
lfs3_remove(&lfs3, "coffee/_rip/..") => LFS3_ERR_NOTEMPTY;
|
||||
lfs3_remove(&lfs3, "coffee/c_ldbrew/../..") => LFS3_ERR_INVAL;
|
||||
lfs3_remove(&lfs3, "coffee/c_ldbrew/../..") => LFS3_ERR_BUSY;
|
||||
lfs3_remove(&lfs3, "coffee/tu_kish/../../..") => LFS3_ERR_INVAL;
|
||||
lfs3_remove(&lfs3, "coffee/tub_uk/../../../..") => LFS3_ERR_INVAL;
|
||||
lfs3_remove(&lfs3, "coffee/_vietnamese/../../../../..") => LFS3_ERR_INVAL;
|
||||
@ -5621,7 +5621,7 @@ code = '''
|
||||
"espresso/latte") => LFS3_ERR_INVAL;
|
||||
lfs3_rename(&lfs3,
|
||||
"coffee/vietnamese/../..",
|
||||
"espresso/cappuccino") => LFS3_ERR_INVAL;
|
||||
"espresso/cappuccino") => LFS3_ERR_BUSY;
|
||||
// this one works
|
||||
lfs3_rename(&lfs3,
|
||||
"coffee/thai/..",
|
||||
@ -5636,7 +5636,7 @@ code = '''
|
||||
"espresso/espresso/..") => LFS3_ERR_ISDIR;
|
||||
lfs3_rename(&lfs3,
|
||||
"coffee/coldbrew",
|
||||
"espresso/americano/../..") => LFS3_ERR_INVAL;
|
||||
"espresso/americano/../..") => LFS3_ERR_BUSY;
|
||||
lfs3_rename(&lfs3,
|
||||
"coffee/turkish",
|
||||
"espresso/macchiato/../../..") => LFS3_ERR_INVAL;
|
||||
@ -5665,7 +5665,7 @@ code = '''
|
||||
"espresso/latte/../../../..") => LFS3_ERR_INVAL;
|
||||
lfs3_rename(&lfs3,
|
||||
"coffee/vietnamese/../..",
|
||||
"espresso/cappuccino/../../../../..") => LFS3_ERR_INVAL;
|
||||
"espresso/cappuccino/../../../../..") => LFS3_ERR_BUSY;
|
||||
lfs3_rename(&lfs3,
|
||||
"coffee/thai/..",
|
||||
"espresso/mocha/../../../../../..") => LFS3_ERR_INVAL;
|
||||
@ -5685,14 +5685,14 @@ code = '''
|
||||
"coffee/tubruk/../../..") => LFS3_ERR_INVAL;
|
||||
lfs3_rename(&lfs3,
|
||||
"coffee/vietnamese/../..",
|
||||
"coffee/vietnamese/../..") => LFS3_ERR_INVAL;
|
||||
"coffee/vietnamese/../..") => LFS3_ERR_BUSY;
|
||||
lfs3_rename(&lfs3,
|
||||
"coffee/thai/..",
|
||||
"coffee/thai/..") => 0;
|
||||
|
||||
// remove paths
|
||||
lfs3_remove(&lfs3, "coffee/drip/..") => LFS3_ERR_NOTEMPTY;
|
||||
lfs3_remove(&lfs3, "coffee/coldbrew/../..") => LFS3_ERR_INVAL;
|
||||
lfs3_remove(&lfs3, "coffee/coldbrew/../..") => LFS3_ERR_BUSY;
|
||||
lfs3_remove(&lfs3, "coffee/turkish/../../..") => LFS3_ERR_INVAL;
|
||||
lfs3_remove(&lfs3, "coffee/tubruk/../../../..") => LFS3_ERR_INVAL;
|
||||
lfs3_remove(&lfs3, "coffee/vietnamese/../../../../..") => LFS3_ERR_INVAL;
|
||||
@ -5833,13 +5833,13 @@ code = '''
|
||||
lfs3_dir_close(&lfs3, &dir) => 0;
|
||||
|
||||
// rename root, this should error
|
||||
lfs3_rename(&lfs3, "/", "coffee") => LFS3_ERR_INVAL;
|
||||
lfs3_rename(&lfs3, "/", "coffee") => LFS3_ERR_BUSY;
|
||||
|
||||
lfs3_mkdir(&lfs3, "coffee") => 0;
|
||||
lfs3_rename(&lfs3, "coffee", "/") => LFS3_ERR_INVAL;
|
||||
lfs3_rename(&lfs3, "coffee", "/") => LFS3_ERR_BUSY;
|
||||
lfs3_remove(&lfs3, "coffee") => 0;
|
||||
|
||||
lfs3_rename(&lfs3, "/", "/") => LFS3_ERR_INVAL;
|
||||
lfs3_rename(&lfs3, "/", "/") => LFS3_ERR_BUSY;
|
||||
|
||||
// stat root
|
||||
lfs3_stat(&lfs3, "/", &info) => 0;
|
||||
@ -5847,7 +5847,7 @@ code = '''
|
||||
assert(info.type == LFS3_TYPE_DIR);
|
||||
|
||||
// remove root, this should error
|
||||
lfs3_remove(&lfs3, "/") => LFS3_ERR_INVAL;
|
||||
lfs3_remove(&lfs3, "/") => LFS3_ERR_BUSY;
|
||||
|
||||
// stat root
|
||||
lfs3_stat(&lfs3, "/", &info) => 0;
|
||||
@ -5953,26 +5953,26 @@ code = '''
|
||||
lfs3_dir_close(&lfs3, &dir) => 0;
|
||||
|
||||
// rename root, this should error
|
||||
lfs3_rename(&lfs3, "/", "coffee") => LFS3_ERR_INVAL;
|
||||
lfs3_rename(&lfs3, ".", "coffee") => LFS3_ERR_INVAL;
|
||||
lfs3_rename(&lfs3, "./", "coffee") => LFS3_ERR_INVAL;
|
||||
lfs3_rename(&lfs3, "/.", "coffee") => LFS3_ERR_INVAL;
|
||||
lfs3_rename(&lfs3, "//", "coffee") => LFS3_ERR_INVAL;
|
||||
lfs3_rename(&lfs3, "/", "coffee") => LFS3_ERR_BUSY;
|
||||
lfs3_rename(&lfs3, ".", "coffee") => LFS3_ERR_BUSY;
|
||||
lfs3_rename(&lfs3, "./", "coffee") => LFS3_ERR_BUSY;
|
||||
lfs3_rename(&lfs3, "/.", "coffee") => LFS3_ERR_BUSY;
|
||||
lfs3_rename(&lfs3, "//", "coffee") => LFS3_ERR_BUSY;
|
||||
|
||||
lfs3_mkdir(&lfs3, "coffee") => 0;
|
||||
lfs3_rename(&lfs3, "coffee", "/") => LFS3_ERR_INVAL;
|
||||
lfs3_rename(&lfs3, "coffee", ".") => LFS3_ERR_INVAL;
|
||||
lfs3_rename(&lfs3, "coffee", "./") => LFS3_ERR_INVAL;
|
||||
lfs3_rename(&lfs3, "coffee", "/.") => LFS3_ERR_INVAL;
|
||||
lfs3_rename(&lfs3, "coffee", "//") => LFS3_ERR_INVAL;
|
||||
lfs3_rename(&lfs3, "coffee", "/") => LFS3_ERR_BUSY;
|
||||
lfs3_rename(&lfs3, "coffee", ".") => LFS3_ERR_BUSY;
|
||||
lfs3_rename(&lfs3, "coffee", "./") => LFS3_ERR_BUSY;
|
||||
lfs3_rename(&lfs3, "coffee", "/.") => LFS3_ERR_BUSY;
|
||||
lfs3_rename(&lfs3, "coffee", "//") => LFS3_ERR_BUSY;
|
||||
lfs3_remove(&lfs3, "coffee") => 0;
|
||||
|
||||
lfs3_rename(&lfs3, "/", "/") => LFS3_ERR_INVAL;
|
||||
lfs3_rename(&lfs3, ".", ".") => LFS3_ERR_INVAL;
|
||||
lfs3_rename(&lfs3, "/", "/") => LFS3_ERR_BUSY;
|
||||
lfs3_rename(&lfs3, ".", ".") => LFS3_ERR_BUSY;
|
||||
lfs3_rename(&lfs3, "..", "..") => LFS3_ERR_INVAL;
|
||||
lfs3_rename(&lfs3, "./", "./") => LFS3_ERR_INVAL;
|
||||
lfs3_rename(&lfs3, "/.", "/.") => LFS3_ERR_INVAL;
|
||||
lfs3_rename(&lfs3, "//", "//") => LFS3_ERR_INVAL;
|
||||
lfs3_rename(&lfs3, "./", "./") => LFS3_ERR_BUSY;
|
||||
lfs3_rename(&lfs3, "/.", "/.") => LFS3_ERR_BUSY;
|
||||
lfs3_rename(&lfs3, "//", "//") => LFS3_ERR_BUSY;
|
||||
|
||||
// stat root
|
||||
lfs3_stat(&lfs3, "/", &info) => 0;
|
||||
@ -5992,11 +5992,11 @@ code = '''
|
||||
assert(info.type == LFS3_TYPE_DIR);
|
||||
|
||||
// remove root, this should error
|
||||
lfs3_remove(&lfs3, "/") => LFS3_ERR_INVAL;
|
||||
lfs3_remove(&lfs3, ".") => LFS3_ERR_INVAL;
|
||||
lfs3_remove(&lfs3, "./") => LFS3_ERR_INVAL;
|
||||
lfs3_remove(&lfs3, "/.") => LFS3_ERR_INVAL;
|
||||
lfs3_remove(&lfs3, "//") => LFS3_ERR_INVAL;
|
||||
lfs3_remove(&lfs3, "/") => LFS3_ERR_BUSY;
|
||||
lfs3_remove(&lfs3, ".") => LFS3_ERR_BUSY;
|
||||
lfs3_remove(&lfs3, "./") => LFS3_ERR_BUSY;
|
||||
lfs3_remove(&lfs3, "/.") => LFS3_ERR_BUSY;
|
||||
lfs3_remove(&lfs3, "//") => LFS3_ERR_BUSY;
|
||||
|
||||
// stat root
|
||||
lfs3_stat(&lfs3, "/", &info) => 0;
|
||||
|
||||
@ -2447,7 +2447,7 @@ code = '''
|
||||
// well, because of the root really, but also because of the
|
||||
// stickynote
|
||||
//
|
||||
lfs3_rename(&lfs3, "batman", "/") => LFS3_ERR_INVAL;
|
||||
lfs3_rename(&lfs3, "batman", "/") => LFS3_ERR_BUSY;
|
||||
|
||||
// we should still be able to read our uncreat
|
||||
lfs3_file_rewind(&lfs3, &uncreat) => 0;
|
||||
|
||||
Reference in New Issue
Block a user