f3read, f3write: chdir(2) to source/target dir

This makes the dir non-umount-able for the program's lifetime.
This commit is contained in:
Alexander A. Klimov 2022-11-08 22:14:29 +01:00
parent 1aff91a44a
commit 0acac543f1
4 changed files with 16 additions and 2 deletions

View File

@ -434,6 +434,8 @@ int main(int argc, char **argv)
argp_parse(&argp, argc, argv, 0, NULL, &args);
print_header(stdout, "read");
adjust_dev_path(&args.dev_path);
files = ls_my_files(args.dev_path, args.start_at, args.end_at);
iterate_files(args.dev_path, files, args.start_at, args.end_at,

View File

@ -368,6 +368,8 @@ int main(int argc, char **argv)
argp_parse(&argp, argc, argv, 0, NULL, &args);
print_header(stdout, "write");
adjust_dev_path(&args.dev_path);
unlink_old_files(args.dev_path, args.start_at, args.end_at);
return fill_fs(args.dev_path, args.start_at, args.end_at,

12
utils.c
View File

@ -18,10 +18,20 @@
#include <dirent.h>
#include <errno.h>
#include <err.h>
#include <unistd.h>
#include "version.h"
#include "utils.h"
void adjust_dev_path(const char **dev_path)
{
if (chdir(*dev_path)) {
err(errno, "Can't change working directory to %s at %s()", *dev_path, __func__);
}
*dev_path = ".";
}
const char *adjust_unit(double *ptr_bytes)
{
const char *units[] = { "Byte", "KB", "MB", "GB", "TB", "PB", "EB" };
@ -216,8 +226,6 @@ int posix_fadvise(int fd, off_t offset, off_t len, int advice)
#if (__APPLE__ && __MACH__) || defined(__OpenBSD__)
#include <unistd.h> /* For usleep(). */
void msleep(double wait_ms)
{
assert(!usleep(wait_ms * 1000));

View File

@ -9,6 +9,8 @@
#define SECTOR_SIZE (512)
#define GIGABYTES (1024 * 1024 * 1024)
void adjust_dev_path(const char **dev_path);
const char *adjust_unit(double *ptr_bytes);
/* Return true if @filename matches the regex /^[0-9]+\.h2w$/ */