do_an_operation();
}
+/*
+ * Recursively remove a directory, just like "rm -rf" shell command.
+ */
+void rm_minus_rf_dir(const char *dir_name)
+{
+ DIR *dir;
+ struct dirent *entry;
+ char buf[PATH_MAX];
+
+ dir = opendir(dir_name);
+ CHECK(dir != NULL);
+ CHECK(getcwd(buf, PATH_MAX) != NULL);
+ CHECK(chdir(dir_name) == 0);
+
+ for (;;) {
+ errno = 0;
+ entry = readdir(dir);
+ if (!entry) {
+ 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);
+ }
+ }
+
+ CHECK(chdir(buf) == 0);
+ CHECK(closedir(dir) == 0);
+ CHECK(rmdir(dir_name) == 0);
+}
+
static void update_test_data(void)
{
uint64_t i, n;
{
int64_t rpt;
- /* Make our top directory */
- if (chdir(fsinfo.test_dir) != -1) {
+ /* Create our top directory */
+ if (chdir(fsinfo.test_dir) == 0) {
/* Remove it if it is already there */
- tests_clear_dir(".");
- CHECK(chdir("..") != -1);
- CHECK(rmdir(fsinfo.test_dir) != -1);
+ CHECK(chdir("..") == 0);
+ rm_minus_rf_dir(fsinfo.test_dir);
}
- top_dir = dir_new(NULL, fsinfo.test_dir);
+ top_dir = dir_new(NULL, fsinfo.test_dir);
if (!top_dir)
return -1;
- srand(getpid());
create_test_data();
if (!tests_fs_is_rootfs()) {
/* Tidy up by removing everything */
close_open_files();
- tests_clear_dir(fsinfo.test_dir);
- CHECK(rmdir(fsinfo.test_dir) != -1);
+ rm_minus_rf_dir(fsinfo.test_dir);
return 0;
}
tests_file_system_mount_dir = (void *)fsinfo.mount_point;
tests_file_system_type = (void *)fsinfo.fstype;
+ /* Seed the random generator with out PID */
+ srand(getpid());
+
/* Do the actual test */
ret = integck();
if (ret)