err(EX_DATAERR, "unknown type of file");
}
-static void nuke(int fd, off_t offset, off_t max_size, unsigned char pattern)
+static void nuke(int fd, off_t block_size, off_t offset, off_t max_size, off_t flush_count, unsigned char pattern)
{
- static char mem[1024 * 1024];
+ char mem[block_size];
memset(mem, pattern, sizeof(mem));
if (pattern)
printf("Writing 0x%X to the output\n", pattern);
/* This will round up to sizeof(mem) ... */
ret = write(fd, mem, sizeof(mem));
pos += ret;
- if (ret != sizeof(mem)) {
+ if (ret != block_size) {
if (pos != max_size)
printf("\nread() returned %zi (wanted %zu)\n%'llu MB/s over entire run\n",
ret, sizeof(mem), mbps(&itime, &etime, pos));
}
unsigned long long eta = speed ? (max_size - pos) / (speed * 1000 * 1000) : 0;
- printf("\r\e[2K%'llu bytes %u%% (%'llu MB/s) (ETA ~%llum%llus)",
+ printf("\r%'llu bytes %u%% (%'llu MB/s) (ETA ~%llum%llus)\e[K",
(unsigned long long)pos, (unsigned)((pos * 100) / max_size), speed,
eta / 60, eta % 60);
- if ((++fsync_pos % 32) == 0) {
+ if ((++fsync_pos % flush_count) == 0) {
speed = mbps(&stime, &etime, pos - last_pos);
last_pos = pos;
fflush(stdout);
"Options:\n"
" -q Run quietly\n"
" -y Assume yes to all prompts\n"
+ " -b <size> How many bytes to write at once. (default: 1Mib)\n"
+ " -f <count> How many blocks to write before flush (stdout & disk). (default: 32)\n"
" -o <offset> Position to start writing\n"
" -r Write three times: 0x00, then 0xaa, then 0x55\n"
);
int main(int argc, char *argv[])
{
+ off_t block_size = 1024 * 1024;
+ off_t flush_count = 32;
off_t offset = 0;
const char *file;
bool quiet = false;
setlocale(LC_NUMERIC, "en_US");
- while ((o = getopt(argc, argv, "ho:qry")) != -1) {
+ while ((o = getopt(argc, argv, "hb:f:o:qry")) != -1) {
switch (o) {
+ case 'b':
+ block_size = atoll(optarg);
+ break;
+ case 'f':
+ flush_count = atoll(optarg);
+ break;
case 'o':
offset = atoll(optarg);
break;
off_t max_size = get_size(fd);
- nuke(fd, offset, max_size, 0x00);
+ nuke(fd, block_size, offset, max_size, flush_count, 0x00);
if (random) {
- nuke(fd, offset, max_size, 0xaa);
- nuke(fd, offset, max_size, 0x55);
+ nuke(fd, block_size, offset, max_size, flush_count, 0xaa);
+ nuke(fd, block_size, offset, max_size, flush_count, 0x55);
}
return EX_OK;