mirror of
https://github.com/AltraMayor/f3.git
synced 2025-08-05 11:35:56 -04:00
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:
parent
1aff91a44a
commit
0acac543f1
2
f3read.c
2
f3read.c
@ -434,6 +434,8 @@ int main(int argc, char **argv)
|
|||||||
argp_parse(&argp, argc, argv, 0, NULL, &args);
|
argp_parse(&argp, argc, argv, 0, NULL, &args);
|
||||||
print_header(stdout, "read");
|
print_header(stdout, "read");
|
||||||
|
|
||||||
|
adjust_dev_path(&args.dev_path);
|
||||||
|
|
||||||
files = ls_my_files(args.dev_path, args.start_at, args.end_at);
|
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,
|
iterate_files(args.dev_path, files, args.start_at, args.end_at,
|
||||||
|
@ -368,6 +368,8 @@ int main(int argc, char **argv)
|
|||||||
argp_parse(&argp, argc, argv, 0, NULL, &args);
|
argp_parse(&argp, argc, argv, 0, NULL, &args);
|
||||||
print_header(stdout, "write");
|
print_header(stdout, "write");
|
||||||
|
|
||||||
|
adjust_dev_path(&args.dev_path);
|
||||||
|
|
||||||
unlink_old_files(args.dev_path, args.start_at, args.end_at);
|
unlink_old_files(args.dev_path, args.start_at, args.end_at);
|
||||||
|
|
||||||
return fill_fs(args.dev_path, args.start_at, args.end_at,
|
return fill_fs(args.dev_path, args.start_at, args.end_at,
|
||||||
|
12
utils.c
12
utils.c
@ -18,10 +18,20 @@
|
|||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <err.h>
|
#include <err.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
#include "version.h"
|
#include "version.h"
|
||||||
#include "utils.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 *adjust_unit(double *ptr_bytes)
|
||||||
{
|
{
|
||||||
const char *units[] = { "Byte", "KB", "MB", "GB", "TB", "PB", "EB" };
|
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__)
|
#if (__APPLE__ && __MACH__) || defined(__OpenBSD__)
|
||||||
|
|
||||||
#include <unistd.h> /* For usleep(). */
|
|
||||||
|
|
||||||
void msleep(double wait_ms)
|
void msleep(double wait_ms)
|
||||||
{
|
{
|
||||||
assert(!usleep(wait_ms * 1000));
|
assert(!usleep(wait_ms * 1000));
|
||||||
|
2
utils.h
2
utils.h
@ -9,6 +9,8 @@
|
|||||||
#define SECTOR_SIZE (512)
|
#define SECTOR_SIZE (512)
|
||||||
#define GIGABYTES (1024 * 1024 * 1024)
|
#define GIGABYTES (1024 * 1024 * 1024)
|
||||||
|
|
||||||
|
void adjust_dev_path(const char **dev_path);
|
||||||
|
|
||||||
const char *adjust_unit(double *ptr_bytes);
|
const char *adjust_unit(double *ptr_bytes);
|
||||||
|
|
||||||
/* Return true if @filename matches the regex /^[0-9]+\.h2w$/ */
|
/* Return true if @filename matches the regex /^[0-9]+\.h2w$/ */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user