int fd, flags = O_RDWR;
char *path;
+ assert(file->links);
+
path = dir_path(file->links->parent, file->links->name);
if (random_no(100) == 1)
flags |= O_SYNC;
return 0;
}
+static const char *get_file_name(struct file_info *file)
+{
+ if (file->links)
+ return file->links->name;
+ return "(unlinked file, no names)";
+}
+
/*
* Write random 'size' bytes of random data to offset 'offset'. Seed the random
* gererator with 'seed'. Return amount of written data on success and -1 on
}
pcv("failed to write %zu bytes to offset %llu of file %s",
block, (unsigned long long)(offset + actual),
- file->links->name);
+ get_file_name(file));
return -1;
}
remains -= written;
return 1;
} else
pcv("cannot truncate file %s to %llu",
- file->links->name, (unsigned long long)new_length);
+ get_file_name(file),
+ (unsigned long long)new_length);
return -1;
}
len = 1 << 24;
/* Open it */
+ assert(file->links);
path = dir_path(file->links->parent, file->links->name);
fd = open(path, O_RDWR);
if (fd == -1) {
if (random_no(100) >= 50) {
ret = fsync(fd);
if (ret)
- pcv("fsync failed for %s", file->links->name);
+ pcv("fsync failed for %s", get_file_name(file));
} else {
ret = fdatasync(fd);
if (ret)
pcv("fdatasync failed for %s",
- file->links->name);
+ get_file_name(file));
}
file->clean = 1;
}
int fd, ret;
char *path;
+ assert(file->links);
path = dir_path(file->links->parent, file->links->name);
fd = open(path, O_RDWR);
if (fd == -1) {
char *path;
int ret;
+ assert(file->links);
path = dir_path(file->links->parent, file->links->name);
fd = open(path, O_WRONLY);
if (fd == -1) {
/* Open file to save contents to */
strcpy(name, "/tmp/");
- strcat(name, file->links->name);
+ strcat(name, get_file_name(file));
strcat(name, ".integ.sav.read");
normsg("Saving %sn", name);
w_fd = open(name, O_CREAT | O_WRONLY, 0777);
/* Open file to save contents to */
strcpy(name, "/tmp/");
- strcat(name, file->links->name);
+ strcat(name, get_file_name(file));
strcat(name, ".integ.sav.written");
normsg("Saving %s", name);
w_fd = open(name, O_CREAT | O_WRONLY, 0777);
open_and_close = 1;
if (open_and_close) {
/* Open file */
- path = dir_path(file->links->parent, file->links->name);
+ assert(file->links);
+ path = dir_path(file->links->parent, get_file_name(file));
fd = open(path, O_RDONLY);
CHECK(fd != -1);
}