Skip to content

Commit e196be5

Browse files
committed
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.
1 parent 4010afe commit e196be5

File tree

5 files changed

+47
-47
lines changed

5 files changed

+47
-47
lines changed

lfs3.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11635,7 +11635,7 @@ int lfs3_remove(lfs3_t *lfs3, const char *path) {
1163511635

1163611636
// trying to remove the root dir?
1163711637
if (mdir.mid == -1) {
11638-
return LFS3_ERR_INVAL;
11638+
return LFS3_ERR_BUSY;
1163911639
}
1164011640

1164111641
// 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) {
1175611756

1175711757
// trying to rename the root?
1175811758
if (old_mdir.mid == -1) {
11759-
return LFS3_ERR_INVAL;
11759+
return LFS3_ERR_BUSY;
1176011760
}
1176111761

1176211762
// lookup new entry
@@ -11786,7 +11786,7 @@ int lfs3_rename(lfs3_t *lfs3, const char *old_path, const char *new_path) {
1178611786
} else {
1178711787
// trying to rename the root?
1178811788
if (new_mdir.mid == -1) {
11789-
return LFS3_ERR_INVAL;
11789+
return LFS3_ERR_BUSY;
1179011790
}
1179111791

1179211792
// we allow reg <-> stickynote renaming, but renaming a non-dir

tests/test_dirs.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2595,7 +2595,7 @@ code = '''
25952595
}
25962596
25972597
// try to remove root, which doesn't really make sense
2598-
lfs3_remove(&lfs3, "/") => LFS3_ERR_INVAL;
2598+
lfs3_remove(&lfs3, "/") => LFS3_ERR_BUSY;
25992599
26002600
// make a directory
26012601
err = lfs3_mkdir(&lfs3, "ardvark");
@@ -2605,7 +2605,7 @@ code = '''
26052605
//
26062606
// it doesn't really matter which error returns first, so accept both
26072607
err = lfs3_remove(&lfs3, "/");
2608-
assert(err == LFS3_ERR_NOTEMPTY || err == LFS3_ERR_INVAL);
2608+
assert(err == LFS3_ERR_NOTEMPTY || err == LFS3_ERR_BUSY);
26092609
26102610
for (int remount = 0; remount < 2; remount++) {
26112611
// remount?
@@ -4830,14 +4830,14 @@ code = '''
48304830
}
48314831
48324832
// try to rename root, which doesn't really make sense
4833-
lfs3_rename(&lfs3, "/", "notroot") => LFS3_ERR_INVAL;
4833+
lfs3_rename(&lfs3, "/", "notroot") => LFS3_ERR_BUSY;
48344834
48354835
// make a directory
48364836
err = lfs3_mkdir(&lfs3, "ardvark");
48374837
assert(!err || (TEST_PLS && err == LFS3_ERR_EXIST));
48384838
48394839
// try to rename root, which doesn't really make sense
4840-
lfs3_rename(&lfs3, "/", "notroot") => LFS3_ERR_INVAL;
4840+
lfs3_rename(&lfs3, "/", "notroot") => LFS3_ERR_BUSY;
48414841
48424842
for (int remount = 0; remount < 2; remount++) {
48434843
// remount?

tests/test_files.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,7 @@ code = '''
523523
lfs3_file_write(&lfs3, &file, wbuf, wsize) => wsize;
524524
lfs3_file_close(&lfs3, &file) => 0;
525525
526-
lfs3_rename(&lfs3, "not_hello", "/") => LFS3_ERR_INVAL;
526+
lfs3_rename(&lfs3, "not_hello", "/") => LFS3_ERR_BUSY;
527527
528528
for (int remount = 0; remount < 2; remount++) {
529529
// remount?
@@ -2247,7 +2247,7 @@ code = '''
22472247
}
22482248
22492249
// rename the file
2250-
lfs3_rename(&lfs3, "amethyst", "/") => LFS3_ERR_INVAL;
2250+
lfs3_rename(&lfs3, "amethyst", "/") => LFS3_ERR_BUSY;
22512251
22522252
for (int remount = 0; remount < 2; remount++) {
22532253
// remount?

tests/test_paths.toml

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -2170,7 +2170,7 @@ code = '''
21702170
"espresso/latte") => LFS3_ERR_INVAL;
21712171
lfs3_rename(&lfs3,
21722172
"coffee/vietnamese/../..",
2173-
"espresso/cappuccino") => LFS3_ERR_INVAL;
2173+
"espresso/cappuccino") => LFS3_ERR_BUSY;
21742174
// this one works
21752175
lfs3_rename(&lfs3,
21762176
"coffee/thai/..",
@@ -2195,7 +2195,7 @@ code = '''
21952195
}
21962196
lfs3_rename(&lfs3,
21972197
"coffee/coldbrew",
2198-
"espresso/americano/../..") => LFS3_ERR_INVAL;
2198+
"espresso/americano/../..") => LFS3_ERR_BUSY;
21992199
lfs3_rename(&lfs3,
22002200
"coffee/turkish",
22012201
"espresso/macchiato/../../..") => LFS3_ERR_INVAL;
@@ -2224,14 +2224,14 @@ code = '''
22242224
"espresso/latte/../../../..") => LFS3_ERR_INVAL;
22252225
lfs3_rename(&lfs3,
22262226
"coffee/vietnamese/../..",
2227-
"espresso/cappuccino/../../../../..") => LFS3_ERR_INVAL;
2227+
"espresso/cappuccino/../../../../..") => LFS3_ERR_BUSY;
22282228
lfs3_rename(&lfs3,
22292229
"coffee/thai/..",
22302230
"espresso/mocha/../../../../../..") => LFS3_ERR_INVAL;
22312231
22322232
// remove paths
22332233
lfs3_remove(&lfs3, "coffee/drip/..") => LFS3_ERR_NOTEMPTY;
2234-
lfs3_remove(&lfs3, "coffee/coldbrew/../..") => LFS3_ERR_INVAL;
2234+
lfs3_remove(&lfs3, "coffee/coldbrew/../..") => LFS3_ERR_BUSY;
22352235
lfs3_remove(&lfs3, "coffee/turkish/../../..") => LFS3_ERR_INVAL;
22362236
lfs3_remove(&lfs3, "coffee/tubruk/../../../..") => LFS3_ERR_INVAL;
22372237
lfs3_remove(&lfs3, "coffee/vietnamese/../../../../..") => LFS3_ERR_INVAL;
@@ -4441,7 +4441,7 @@ code = '''
44414441
"espresso/latte") => LFS3_ERR_INVAL;
44424442
lfs3_rename(&lfs3,
44434443
"coffee/_vietnamese/../..",
4444-
"espresso/cappuccino") => LFS3_ERR_INVAL;
4444+
"espresso/cappuccino") => LFS3_ERR_BUSY;
44454445
// this one works
44464446
lfs3_rename(&lfs3,
44474447
"coffee/thai_/..",
@@ -4485,7 +4485,7 @@ code = '''
44854485
"espresso/latte/../../../..") => LFS3_ERR_INVAL;
44864486
lfs3_rename(&lfs3,
44874487
"coffee/_vietnamese/../..",
4488-
"espresso/cappuccino/../../../../..") => LFS3_ERR_INVAL;
4488+
"espresso/cappuccino/../../../../..") => LFS3_ERR_BUSY;
44894489
lfs3_rename(&lfs3,
44904490
"coffee/thai_/..",
44914491
"espresso/mocha/../../../../../..") => LFS3_ERR_INVAL;
@@ -4505,14 +4505,14 @@ code = '''
45054505
"coffee/tub_uk/../../..") => LFS3_ERR_INVAL;
45064506
lfs3_rename(&lfs3,
45074507
"coffee/_vietnamese/../..",
4508-
"coffee/_vietnamese/../..") => LFS3_ERR_INVAL;
4508+
"coffee/_vietnamese/../..") => LFS3_ERR_BUSY;
45094509
lfs3_rename(&lfs3,
45104510
"coffee/thai_/..",
45114511
"coffee/thai_/..") => 0;
45124512
45134513
// remove paths
45144514
lfs3_remove(&lfs3, "coffee/_rip/..") => LFS3_ERR_NOTEMPTY;
4515-
lfs3_remove(&lfs3, "coffee/c_ldbrew/../..") => LFS3_ERR_INVAL;
4515+
lfs3_remove(&lfs3, "coffee/c_ldbrew/../..") => LFS3_ERR_BUSY;
45164516
lfs3_remove(&lfs3, "coffee/tu_kish/../../..") => LFS3_ERR_INVAL;
45174517
lfs3_remove(&lfs3, "coffee/tub_uk/../../../..") => LFS3_ERR_INVAL;
45184518
lfs3_remove(&lfs3, "coffee/_vietnamese/../../../../..") => LFS3_ERR_INVAL;
@@ -5621,7 +5621,7 @@ code = '''
56215621
"espresso/latte") => LFS3_ERR_INVAL;
56225622
lfs3_rename(&lfs3,
56235623
"coffee/vietnamese/../..",
5624-
"espresso/cappuccino") => LFS3_ERR_INVAL;
5624+
"espresso/cappuccino") => LFS3_ERR_BUSY;
56255625
// this one works
56265626
lfs3_rename(&lfs3,
56275627
"coffee/thai/..",
@@ -5636,7 +5636,7 @@ code = '''
56365636
"espresso/espresso/..") => LFS3_ERR_ISDIR;
56375637
lfs3_rename(&lfs3,
56385638
"coffee/coldbrew",
5639-
"espresso/americano/../..") => LFS3_ERR_INVAL;
5639+
"espresso/americano/../..") => LFS3_ERR_BUSY;
56405640
lfs3_rename(&lfs3,
56415641
"coffee/turkish",
56425642
"espresso/macchiato/../../..") => LFS3_ERR_INVAL;
@@ -5665,7 +5665,7 @@ code = '''
56655665
"espresso/latte/../../../..") => LFS3_ERR_INVAL;
56665666
lfs3_rename(&lfs3,
56675667
"coffee/vietnamese/../..",
5668-
"espresso/cappuccino/../../../../..") => LFS3_ERR_INVAL;
5668+
"espresso/cappuccino/../../../../..") => LFS3_ERR_BUSY;
56695669
lfs3_rename(&lfs3,
56705670
"coffee/thai/..",
56715671
"espresso/mocha/../../../../../..") => LFS3_ERR_INVAL;
@@ -5685,14 +5685,14 @@ code = '''
56855685
"coffee/tubruk/../../..") => LFS3_ERR_INVAL;
56865686
lfs3_rename(&lfs3,
56875687
"coffee/vietnamese/../..",
5688-
"coffee/vietnamese/../..") => LFS3_ERR_INVAL;
5688+
"coffee/vietnamese/../..") => LFS3_ERR_BUSY;
56895689
lfs3_rename(&lfs3,
56905690
"coffee/thai/..",
56915691
"coffee/thai/..") => 0;
56925692
56935693
// remove paths
56945694
lfs3_remove(&lfs3, "coffee/drip/..") => LFS3_ERR_NOTEMPTY;
5695-
lfs3_remove(&lfs3, "coffee/coldbrew/../..") => LFS3_ERR_INVAL;
5695+
lfs3_remove(&lfs3, "coffee/coldbrew/../..") => LFS3_ERR_BUSY;
56965696
lfs3_remove(&lfs3, "coffee/turkish/../../..") => LFS3_ERR_INVAL;
56975697
lfs3_remove(&lfs3, "coffee/tubruk/../../../..") => LFS3_ERR_INVAL;
56985698
lfs3_remove(&lfs3, "coffee/vietnamese/../../../../..") => LFS3_ERR_INVAL;
@@ -5833,21 +5833,21 @@ code = '''
58335833
lfs3_dir_close(&lfs3, &dir) => 0;
58345834
58355835
// rename root, this should error
5836-
lfs3_rename(&lfs3, "/", "coffee") => LFS3_ERR_INVAL;
5836+
lfs3_rename(&lfs3, "/", "coffee") => LFS3_ERR_BUSY;
58375837
58385838
lfs3_mkdir(&lfs3, "coffee") => 0;
5839-
lfs3_rename(&lfs3, "coffee", "/") => LFS3_ERR_INVAL;
5839+
lfs3_rename(&lfs3, "coffee", "/") => LFS3_ERR_BUSY;
58405840
lfs3_remove(&lfs3, "coffee") => 0;
58415841
5842-
lfs3_rename(&lfs3, "/", "/") => LFS3_ERR_INVAL;
5842+
lfs3_rename(&lfs3, "/", "/") => LFS3_ERR_BUSY;
58435843
58445844
// stat root
58455845
lfs3_stat(&lfs3, "/", &info) => 0;
58465846
assert(strcmp(info.name, "/") == 0);
58475847
assert(info.type == LFS3_TYPE_DIR);
58485848
58495849
// remove root, this should error
5850-
lfs3_remove(&lfs3, "/") => LFS3_ERR_INVAL;
5850+
lfs3_remove(&lfs3, "/") => LFS3_ERR_BUSY;
58515851
58525852
// stat root
58535853
lfs3_stat(&lfs3, "/", &info) => 0;
@@ -5953,26 +5953,26 @@ code = '''
59535953
lfs3_dir_close(&lfs3, &dir) => 0;
59545954
59555955
// rename root, this should error
5956-
lfs3_rename(&lfs3, "/", "coffee") => LFS3_ERR_INVAL;
5957-
lfs3_rename(&lfs3, ".", "coffee") => LFS3_ERR_INVAL;
5958-
lfs3_rename(&lfs3, "./", "coffee") => LFS3_ERR_INVAL;
5959-
lfs3_rename(&lfs3, "/.", "coffee") => LFS3_ERR_INVAL;
5960-
lfs3_rename(&lfs3, "//", "coffee") => LFS3_ERR_INVAL;
5956+
lfs3_rename(&lfs3, "/", "coffee") => LFS3_ERR_BUSY;
5957+
lfs3_rename(&lfs3, ".", "coffee") => LFS3_ERR_BUSY;
5958+
lfs3_rename(&lfs3, "./", "coffee") => LFS3_ERR_BUSY;
5959+
lfs3_rename(&lfs3, "/.", "coffee") => LFS3_ERR_BUSY;
5960+
lfs3_rename(&lfs3, "//", "coffee") => LFS3_ERR_BUSY;
59615961
59625962
lfs3_mkdir(&lfs3, "coffee") => 0;
5963-
lfs3_rename(&lfs3, "coffee", "/") => LFS3_ERR_INVAL;
5964-
lfs3_rename(&lfs3, "coffee", ".") => LFS3_ERR_INVAL;
5965-
lfs3_rename(&lfs3, "coffee", "./") => LFS3_ERR_INVAL;
5966-
lfs3_rename(&lfs3, "coffee", "/.") => LFS3_ERR_INVAL;
5967-
lfs3_rename(&lfs3, "coffee", "//") => LFS3_ERR_INVAL;
5963+
lfs3_rename(&lfs3, "coffee", "/") => LFS3_ERR_BUSY;
5964+
lfs3_rename(&lfs3, "coffee", ".") => LFS3_ERR_BUSY;
5965+
lfs3_rename(&lfs3, "coffee", "./") => LFS3_ERR_BUSY;
5966+
lfs3_rename(&lfs3, "coffee", "/.") => LFS3_ERR_BUSY;
5967+
lfs3_rename(&lfs3, "coffee", "//") => LFS3_ERR_BUSY;
59685968
lfs3_remove(&lfs3, "coffee") => 0;
59695969
5970-
lfs3_rename(&lfs3, "/", "/") => LFS3_ERR_INVAL;
5971-
lfs3_rename(&lfs3, ".", ".") => LFS3_ERR_INVAL;
5970+
lfs3_rename(&lfs3, "/", "/") => LFS3_ERR_BUSY;
5971+
lfs3_rename(&lfs3, ".", ".") => LFS3_ERR_BUSY;
59725972
lfs3_rename(&lfs3, "..", "..") => LFS3_ERR_INVAL;
5973-
lfs3_rename(&lfs3, "./", "./") => LFS3_ERR_INVAL;
5974-
lfs3_rename(&lfs3, "/.", "/.") => LFS3_ERR_INVAL;
5975-
lfs3_rename(&lfs3, "//", "//") => LFS3_ERR_INVAL;
5973+
lfs3_rename(&lfs3, "./", "./") => LFS3_ERR_BUSY;
5974+
lfs3_rename(&lfs3, "/.", "/.") => LFS3_ERR_BUSY;
5975+
lfs3_rename(&lfs3, "//", "//") => LFS3_ERR_BUSY;
59765976
59775977
// stat root
59785978
lfs3_stat(&lfs3, "/", &info) => 0;
@@ -5992,11 +5992,11 @@ code = '''
59925992
assert(info.type == LFS3_TYPE_DIR);
59935993
59945994
// remove root, this should error
5995-
lfs3_remove(&lfs3, "/") => LFS3_ERR_INVAL;
5996-
lfs3_remove(&lfs3, ".") => LFS3_ERR_INVAL;
5997-
lfs3_remove(&lfs3, "./") => LFS3_ERR_INVAL;
5998-
lfs3_remove(&lfs3, "/.") => LFS3_ERR_INVAL;
5999-
lfs3_remove(&lfs3, "//") => LFS3_ERR_INVAL;
5995+
lfs3_remove(&lfs3, "/") => LFS3_ERR_BUSY;
5996+
lfs3_remove(&lfs3, ".") => LFS3_ERR_BUSY;
5997+
lfs3_remove(&lfs3, "./") => LFS3_ERR_BUSY;
5998+
lfs3_remove(&lfs3, "/.") => LFS3_ERR_BUSY;
5999+
lfs3_remove(&lfs3, "//") => LFS3_ERR_BUSY;
60006000
60016001
// stat root
60026002
lfs3_stat(&lfs3, "/", &info) => 0;

tests/test_stickynotes.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2447,7 +2447,7 @@ code = '''
24472447
// well, because of the root really, but also because of the
24482448
// stickynote
24492449
//
2450-
lfs3_rename(&lfs3, "batman", "/") => LFS3_ERR_INVAL;
2450+
lfs3_rename(&lfs3, "batman", "/") => LFS3_ERR_BUSY;
24512451
24522452
// we should still be able to read our uncreat
24532453
lfs3_file_rewind(&lfs3, &uncreat) => 0;

0 commit comments

Comments
 (0)