.SH NAME
vbig \- create or verify a large but pseudo-random file
.SH SYNOPSIS
-\fBvbig \fR[\fB--seed \fRSEED\fR] \fB--create\fR|\fB--verify \fIPATH \fR[\fISIZE\fR]
+\fBvbig \fR[\fB--seed \fRSEED\fR] \fB--both\fR|\fB--create\fR|\fB--verify\fR \fIPATH \fR[\fISIZE\fR]
.br
\fBvbig --help
.br
\fBvbig --version
.SH DESCRIPTION
-\fBvbig\fR either creates a file of specified size full of predictable
-psuedo-random data, or verifies that it has the expected contents.
+\fBvbig\fR creates a file of specified size full of predictable
+psuedo-random data, and/or verifies that it has the expected contents.
The intended use is to test whether storage media really do what they
say on the tin.
.PP
\fISIZE\fR may end with \fBK\fR, \fBM\fR or \fBG\fR to select (binary)
kilobytes, megabytes or gigabytes.
The size is mandatory when creating a file but optional when verifying
-it, unless \-\-entire is specified.
+it, unless \-\-entire is specified. If \fBSIZE\fR not specified when
+writing-then-verifying, it is as if \fB\-\-entire\fR was specified.
.SH OPTIONS
.TP
.B --seed\fR, \fB-s \fISEED
Specifies the random seed to use.
Optional.
.TP
+.B --both\fR, \fB-b
+Selects both mode.
+\fIPATH\fR will be filled with \fISIZE\fR psuedo-random bytes and
+then read to check that it contains the data just written.
+.TP
.B --create\fR, \fB-c
Selects create mode.
\fIPATH\fR will be filled with \fISIZE\fR psuedo-random bytes.
// Command line options
const struct option opts[] = {
{ "seed", required_argument, 0, 's' },
+ { "both", no_argument, 0, 'b' },
{ "verify", no_argument, 0, 'v' },
{ "create", no_argument, 0, 'c' },
{ "flush", no_argument, 0, 'f' },
enum mode_type {
NONE,
VERIFY,
- CREATE
+ CREATE,
+ BOTH
};
// Report an error and exit
#endif
}
-static void execute(mode_type mode, bool entire, const char *show);
+static long long execute(mode_type mode, bool entire, const char *show);
static const char *seed = "hexapodia as the key insight";
static const char *path;
while((n = getopt_long(argc, argv, "+s:vcefhV", opts, 0)) >= 0) {
switch(n) {
case 's': seed = optarg; break;
+ case 'b': mode = BOTH; break;
case 'v': mode = VERIFY; break;
case 'c': mode = CREATE; break;
case 'e': entireopt = true; break;
fatal(0, "must specify one of --verify or --create");
if(argc > 2)
fatal(0, "excess arguments");
+ if(argc == 1 && mode == BOTH)
+ entireopt = true;
if(entireopt) {
if(argc != 1)
fatal(0, "with --entire, size should not be specified");
size = sb.st_size;
}
const char *show = entireopt ? (mode == CREATE ? "written" : "verified") : 0;
- execute(mode, entireopt, show);
+ if(mode == BOTH) {
+ size = execute(CREATE, entireopt, 0);
+ execute(VERIFY, false, show);
+ } else {
+ execute(mode, entireopt, show);
+ }
return 0;
}
-static void execute(mode_type mode, bool entire, const char *show) {
+static long long execute(mode_type mode, bool entire, const char *show) {
Arcfour rng(seed, strlen(seed));
FILE *fp = fopen(path, mode == VERIFY ? "rb" : "wb");
if(!fp)
if(ferror(stdout) || fflush(stdout))
fatal(errno, "flush stdout");
}
+ return done;
}