X-Git-Url: https://git.wh0rd.org/?a=blobdiff_plain;f=ddnuke.c;fp=ddnuke.c;h=8e0abdbaaa5c371e1aab3a15eb0e41a738351310;hb=64f2ae36a6d0138fa8dd651bdc9555bd86fc1d0b;hp=03ac78958fdac7daa83bd1645c172b9dc2ffbc53;hpb=bd7172bcd5bca2233c9726150e2524b9966ceadf;p=home.git 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);