]> git.wh0rd.org Git - home.git/commitdiff
ddnuke: handle final write better, fix initial seek, and improve help
authorMike Frysinger <vapier@gentoo.org>
Thu, 2 Jun 2016 15:07:42 +0000 (11:07 -0400)
committerMike Frysinger <vapier@gentoo.org>
Thu, 2 Jun 2016 15:07:42 +0000 (11:07 -0400)
ddnuke.c

index 03ac78958fdac7daa83bd1645c172b9dc2ffbc53..8e0abdbaaa5c371e1aab3a15eb0e41a738351310 100644 (file)
--- 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] <dev>\n"
                "\n"
-               "Options:"
+               "Options:\n"
                " -o <offset>   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);