} while(0)
#define pcv(fmt, ...) do { \
- if (!args.power_cut_mode || (args.power_cut_mode && args.verbose)) \
+ if (!args.power_cut_mode || args.verbose) \
normsg(fmt " (line %d, error %d (%s))", \
##__VA_ARGS__, __LINE__, errno, strerror(errno)); \
CHECK_ERRNO(); \
} while(0)
+#define v(fmt, ...) do { \
+ if (args.verbose) \
+ normsg(fmt " (line %d)", ##__VA_ARGS__, __LINE__); \
+} while(0)
+
/* The variables below are set by command line arguments */
static struct {
long repeat_cnt;
void *addresses[128];
fflush(stdout);
+ fflush(stderr);
errmsg("condition '%s' failed in %s() at %s:%d",
cond, func, file, line);
normsg("error %d (%s)", error, strerror(error));
assert(parent);
path = dir_path(parent, name);
+ v("creating dir %s", path);
if (mkdir(path, 0777) != 0) {
if (errno == ENOSPC) {
full = 1;
path = dir_path(parent, name);
mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH;
+ v("creating file %s", path);
fd = open(path, O_CREAT | O_EXCL | O_RDWR, mode);
if (fd == -1) {
if (errno == ENOSPC) {
if (args.verify_ops)
CHECK(lstat(target, &st1) == 0);
+ v("creating hardlink %s ---> %s", path, target);
ret = link(target, path);
if (ret != 0) {
if (errno == ENOSPC) {
remains = size;
actual = 0;
written = IO_BUFFER_SIZE;
+ v("write %zd bytes, offset %llu, file %s",
+ size, (unsigned long long)offset, get_file_name(file));
while (remains) {
/* Fill up buffer with random data */
if (written < IO_BUFFER_SIZE) {
/* Sync sometimes */
if (random_no(100) >= 99) {
if (random_no(100) >= 50) {
+ v("fsyncing file %s", get_file_name(file));
ret = fsync(fd);
if (ret)
pcv("fsync failed for %s", get_file_name(file));
} else {
+ v("fdatasyncing file %s", get_file_name(file));
ret = fdatasync(fd);
if (ret)
pcv("fdatasync failed for %s",
open_and_close = 1;
assert(file->links);
path = dir_path(file->links->parent, get_file_name(file));
+ v("checking file %s", path);
fd = open(path, O_RDONLY);
CHECK(fd != -1);
- }
+ } else
+ v("checking file %s", get_file_name(file));
+
/* Check length */
pos = lseek(fd, 0, SEEK_END);
if (pos != file->length) {
return;
path = dir_path(symlink->entry->parent, symlink->entry->name);
+
+ v("checking symlink %s", path);
CHECK(lstat(path, &st1) == 0);
CHECK(S_ISLNK(st1.st_mode));
CHECK(st1.st_nlink == 1);
+
len = readlink(path, buf, 8192);
+
CHECK(len > 0 && len < 8192);
buf[len] = '\0';
CHECK(strlen(symlink->target_pathname) == len);
CHECK(strncmp(symlink->target_pathname, buf, len) == 0);
+
/* Check symlink points where it should */
ret1 = stat(path, &st1);
target = symlink_path(path, symlink->target_pathname);
/* Go through directory on file system checking entries match */
path = dir_path(dir->parent, dir->entry->name);
+
+ v("checking dir %s", path);
+
d = opendir(path);
if (!d) {
+ if (args.power_cut_mode && !dir->clean)
+ /*
+ * We are doing power cut testing and the directory
+ * was not synchronized, which means it might not
+ * exist.
+ */
+ return;
+
errmsg("cannot open directory %s", path);
CHECK(0);
}
+
for (;;) {
errno = 0;
ent = readdir(d);
}
CHECK(stat(path, &st) == 0);
- CHECK(link_count == st.st_nlink);
+
+ if (link_count != st.st_nlink) {
+ errmsg("calculated link count %d, FS reports %d for dir %s",
+ link_count, (int)st.st_nlink, path);
+ CHECK(0);
+ }
free(entry_array);
free(path);
if (args.verify_ops)
CHECK(lstat(path, &st1) == 0);
+ if (rename_entry)
+ v("moving %s (type %c) inoto %s (type %c)",
+ path, entry->type, to, rename_entry->type);
+ else
+ v("renaming %s (type %c) to %s", path, entry->type, to);
+
ret = rename(path, to);
if (ret != 0) {
ret = 0;
*/
path = dir_path(dir, name);
target = pick_symlink_target(path);
+ v("creating symlink %s ---> %s", path, target);
if (symlink(target, path) != 0) {
int ret = 0;
}
if (random_no(100) >= 50) {
+ v("fsyncing dir %s", path);
ret = fsync(fd);
if (ret)
pcv("directory fsync failed for %s", path);
} else {
+ v("fdatasyncing dir %s", path);
ret = fdatasync(fd);
if (ret)
pcv("directory fdatasync failed for %s", path);
struct dirent *dent;
char buf[PATH_MAX];
+ v("removing all files");
dir = opendir(dir_name);
CHECK(dir != NULL);
CHECK(getcwd(buf, PATH_MAX) != NULL);
unsigned int rorw1, um, um_ro, um_rorw, rorw2;
CHECK(chdir("/") == 0);
+ v("remounting file-system");
/* Choose what to do */
rorw1 = random_no(2);
static void check_tested_fs(void)
{
+ v("checking the file-sytem");
check_run_no += 1;
dir_check(top_dir);
check_deleted_files();
char buf[PATH_MAX];
assert(args.power_cut_mode);
+ v("reading all files");
dir = opendir(dir_name);
if (!dir) {
return -1;
}
+ v("creating top dir %s", fsinfo.test_dir);
ret = mkdir(fsinfo.test_dir, 0777);
if (ret) {
pcv("cannot create top test directory %s", fsinfo.test_dir);
"-e, --verify-ops verify all operations, e.g., every time a file is written\n"
" to, read the data back and verify it, every time a\n"
" directory is created, check that it exists, etc\n"
-"-v, --verbose be verbose about failures during power cut testing\n"
+"-v, --verbose be verbose\n"
"-m, --reattach=<mtd> re-attach mtd device number <mtd> (only if doing UBIFS power\n"
" cut emulation testing)\n"
"-h, -?, --help print help message\n"