From db8872781a7bc110b2a84b67c5fe818e9708e68a Mon Sep 17 00:00:00 2001 From: Christopher Haster Date: Wed, 27 Dec 2017 11:47:48 -0600 Subject: [PATCH] Added error code LFS_ERR_NOTEMPTY As noted by itayzafrir, removing a non-empty directory should error with ENOTEMPTY, not EINVAL --- lfs.c | 2 +- lfs.h | 21 +++++++++++---------- tests/test_dirs.sh | 8 ++++---- 3 files changed, 16 insertions(+), 15 deletions(-) diff --git a/lfs.c b/lfs.c index 7f1f437ca3b..4fe66bbbed0 100644 --- a/lfs.c +++ b/lfs.c @@ -1740,7 +1740,7 @@ int lfs_remove(lfs_t *lfs, const char *path) { if (err) { return err; } else if (dir.d.size != sizeof(dir.d)+4) { - return LFS_ERR_INVAL; + return LFS_ERR_NOTEMPTY; } } diff --git a/lfs.h b/lfs.h index 3bfeab915cc..b612f62cd5a 100644 --- a/lfs.h +++ b/lfs.h @@ -41,16 +41,17 @@ typedef uint32_t lfs_block_t; // Possible error codes, these are negative to allow // valid positive return values enum lfs_error { - LFS_ERR_OK = 0, // No error - LFS_ERR_IO = -5, // Error during device operation - LFS_ERR_CORRUPT = -52, // Corrupted - LFS_ERR_NOENT = -2, // No directory entry - LFS_ERR_EXIST = -17, // Entry already exists - LFS_ERR_NOTDIR = -20, // Entry is not a dir - LFS_ERR_ISDIR = -21, // Entry is a dir - LFS_ERR_INVAL = -22, // Invalid parameter - LFS_ERR_NOSPC = -28, // No space left on device - LFS_ERR_NOMEM = -12, // No more memory available + LFS_ERR_OK = 0, // No error + LFS_ERR_IO = -5, // Error during device operation + LFS_ERR_CORRUPT = -52, // Corrupted + LFS_ERR_NOENT = -2, // No directory entry + LFS_ERR_EXIST = -17, // Entry already exists + LFS_ERR_NOTDIR = -20, // Entry is not a dir + LFS_ERR_ISDIR = -21, // Entry is a dir + LFS_ERR_NOTEMPTY = -39, // Dir is not empty + LFS_ERR_INVAL = -22, // Invalid parameter + LFS_ERR_NOSPC = -28, // No space left on device + LFS_ERR_NOMEM = -12, // No more memory available }; // File types diff --git a/tests/test_dirs.sh b/tests/test_dirs.sh index 431889007a6..197d0f5bf2d 100755 --- a/tests/test_dirs.sh +++ b/tests/test_dirs.sh @@ -126,7 +126,7 @@ TEST echo "--- Directory remove ---" tests/test.py << TEST lfs_mount(&lfs, &cfg) => 0; - lfs_remove(&lfs, "potato") => LFS_ERR_INVAL; + lfs_remove(&lfs, "potato") => LFS_ERR_NOTEMPTY; lfs_remove(&lfs, "potato/sweet") => 0; lfs_remove(&lfs, "potato/baked") => 0; lfs_remove(&lfs, "potato/fried") => 0; @@ -255,7 +255,7 @@ tests/test.py << TEST lfs_rename(&lfs, "warmpotato/baked", "coldpotato/baked") => 0; lfs_rename(&lfs, "warmpotato/sweet", "coldpotato/sweet") => 0; lfs_rename(&lfs, "warmpotato/fried", "coldpotato/fried") => 0; - lfs_remove(&lfs, "coldpotato") => LFS_ERR_INVAL; + lfs_remove(&lfs, "coldpotato") => LFS_ERR_NOTEMPTY; lfs_remove(&lfs, "warmpotato") => 0; lfs_unmount(&lfs) => 0; TEST @@ -285,7 +285,7 @@ TEST echo "--- Recursive remove ---" tests/test.py << TEST lfs_mount(&lfs, &cfg) => 0; - lfs_remove(&lfs, "coldpotato") => LFS_ERR_INVAL; + lfs_remove(&lfs, "coldpotato") => LFS_ERR_NOTEMPTY; lfs_dir_open(&lfs, &dir[0], "coldpotato") => 0; lfs_dir_read(&lfs, &dir[0], &info) => 1; @@ -328,7 +328,7 @@ TEST echo "--- Multi-block remove ---" tests/test.py << TEST lfs_mount(&lfs, &cfg) => 0; - lfs_remove(&lfs, "cactus") => LFS_ERR_INVAL; + lfs_remove(&lfs, "cactus") => LFS_ERR_NOTEMPTY; for (int i = 0; i < $LARGESIZE; i++) { sprintf((char*)buffer, "cactus/test%d", i);