aboutsummaryrefslogtreecommitdiff
path: root/tests/fs-tests
diff options
context:
space:
mode:
authorArtem Bityutskiy <Artem.Bityutskiy@nokia.com>2011-04-14 12:42:39 +0300
committerArtem Bityutskiy <Artem.Bityutskiy@nokia.com>2011-04-22 14:29:50 +0300
commit99d35f31fccfe7812c56ac290168c6a79f6c8864 (patch)
tree6a6180fd4b1f60a1ed8d44b5c56668d01b9073c8 /tests/fs-tests
parentb50ed19f935d833cbbb3b165a0509aa7545cfe7f (diff)
fs-tests: integck: check deletion errors in rm_minus_rf_dir
Modify the 'rm_minus_rf_dir()' function to return -1 in case of any errors during deletions. Make 'integck()' handle the errors. Also introduce a 'pcv()' function to print error message if -v command line option was specified. Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
Diffstat (limited to 'tests/fs-tests')
-rw-r--r--tests/fs-tests/integrity/integck.c54
1 files changed, 40 insertions, 14 deletions
diff --git a/tests/fs-tests/integrity/integck.c b/tests/fs-tests/integrity/integck.c
index 73b6622..dd1ba1c 100644
--- a/tests/fs-tests/integrity/integck.c
+++ b/tests/fs-tests/integrity/integck.c
@@ -62,6 +62,15 @@
} \
} while(0)
+#define pcv(fmt, ...) do { \
+ if (args.power_cut_mode) { \
+ int _err = errno; \
+ errmsg(fmt, ##__VA_ARGS__); \
+ errmsg("error %d (%s) at %s:%d\n", \
+ _err, strerror(_err), __FILE__, __LINE__); \
+ } \
+} while(0)
+
/* The variables below are set by command line arguments */
static struct {
long repeat_cnt;
@@ -1989,10 +1998,11 @@ static void create_test_data(void)
/*
* Recursively remove a directory, just like "rm -rf" shell command.
*/
-void rm_minus_rf_dir(const char *dir_name)
+static int rm_minus_rf_dir(const char *dir_name)
{
+ int ret;
DIR *dir;
- struct dirent *entry;
+ struct dirent *dent;
char buf[PATH_MAX];
dir = opendir(dir_name);
@@ -2002,24 +2012,34 @@ void rm_minus_rf_dir(const char *dir_name)
for (;;) {
errno = 0;
- entry = readdir(dir);
- if (!entry) {
+ dent = readdir(dir);
+ if (!dent) {
CHECK(errno == 0);
break;
}
- if (strcmp(entry->d_name, ".") &&
- strcmp(entry->d_name, "..")) {
- if (entry->d_type == DT_DIR)
- rm_minus_rf_dir(entry->d_name);
- else
- CHECK(unlink(entry->d_name) == 0);
+ if (strcmp(dent->d_name, ".") &&
+ strcmp(dent->d_name, "..")) {
+ if (dent->d_type == DT_DIR)
+ rm_minus_rf_dir(dent->d_name);
+ else {
+ ret = unlink(dent->d_name);
+ if (ret) {
+ pcv("cannot unlink %s", dent->d_name);
+ return -1;
+ }
+ }
}
}
CHECK(chdir(buf) == 0);
CHECK(closedir(dir) == 0);
- CHECK(rmdir(dir_name) == 0);
+ ret = rmdir(dir_name);
+ if (ret) {
+ pcv("cannot remove directory %s", dir_name);
+ return -1;
+ }
+ return 0;
}
static void update_test_data(void)
@@ -2146,13 +2166,18 @@ void remount_tested_fs(void)
*/
static int integck(void)
{
+ int ret;
int64_t rpt;
+ CHECK(chdir(fsinfo.mount_point) == 0);
+
/* Create our top directory */
if (chdir(fsinfo.test_dir) == 0) {
/* Remove it if it is already there */
CHECK(chdir("..") == 0);
- rm_minus_rf_dir(fsinfo.test_dir);
+ ret = rm_minus_rf_dir(fsinfo.test_dir);
+ if (ret)
+ return -1;
}
top_dir = dir_new(NULL, fsinfo.test_dir);
@@ -2187,7 +2212,9 @@ static int integck(void)
/* Tidy up by removing everything */
close_open_files();
- rm_minus_rf_dir(fsinfo.test_dir);
+ ret = rm_minus_rf_dir(fsinfo.test_dir);
+ if (ret)
+ return -1;
return 0;
}
@@ -2403,7 +2430,6 @@ static int parse_opts(int argc, char * const argv[])
fprintf(stderr, "%s\n\n", doc);
fprintf(stderr, "%s\n", optionsstr);
exit(EXIT_SUCCESS);
-
case ':':
return errmsg("parameter is missing");