From: Mike Frysinger Date: Thu, 2 Jun 2016 15:07:42 +0000 (-0400) Subject: ddnuke: handle final write better, fix initial seek, and improve help X-Git-Url: https://git.wh0rd.org/?a=commitdiff_plain;h=64f2ae36a6d0138fa8dd651bdc9555bd86fc1d0b;p=home.git ddnuke: handle final write better, fix initial seek, and improve help --- diff --git a/ddnuke.c b/ddnuke.c index 03ac789..8e0abdb 100644 --- a/ddnuke.c +++ b/ddnuke.c @@ -73,6 +73,9 @@ static void nuke(int fd, off_t offset, off_t max_size, unsigned char pattern) if (pattern) printf("Writing 0x%X to the output\n", pattern); + if (lseek(fd, offset, SEEK_SET) != offset) + errp("lseek(%"PRIu64"u) failed", offset); + unsigned long long speed = 0; struct timespec stime, etime, itime; clock_gettime(CLOCK_MONOTONIC, &stime); @@ -86,15 +89,16 @@ static void nuke(int fd, off_t offset, off_t max_size, unsigned char pattern) ret = write(fd, mem, sizeof(mem)); pos += ret; if (ret != sizeof(mem)) { - printf("\nread() returned %zi (wanted %zu)\n%'llu MB/s over entire run\n", - ret, sizeof(mem), mbps(&itime, &etime, pos)); + 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)); return; } printf("%'llu bytes %u%% (%'llu MB/s)%20s\r", (unsigned long long)pos, (unsigned)((pos * 100) / max_size), speed, ""); - if ((++fsync_pos % 16) == 0) { + if ((++fsync_pos % 32) == 0) { speed = mbps(&stime, &etime, pos - last_pos); last_pos = pos; fflush(stdout); @@ -111,9 +115,9 @@ static void usage(int status) status ? stderr : stdout, "Usage: ddnuke [options] \n" "\n" - "Options:" + "Options:\n" " -o Position to start writing\n" - " -r Write random garbage to the device\n" + " -r Write three times: 0x00, then 0xaa, then 0x55\n" ); exit(status); } @@ -149,9 +153,6 @@ int main(int argc, char *argv[]) off_t max_size = get_size(fd); - if (lseek(fd, offset, SEEK_SET) != offset) - errp("lseek(%"PRIu64"u) failed", offset); - nuke(fd, offset, max_size, 0x00); if (random) { nuke(fd, offset, max_size, 0xaa);