]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
fdisk: always skips zeros in dumps
authorKarel Zak <kzak@redhat.com>
Thu, 8 Apr 2021 10:42:36 +0000 (12:42 +0200)
committerKarel Zak <kzak@redhat.com>
Thu, 8 Apr 2021 10:42:36 +0000 (12:42 +0200)
The expert command 'D'ump skips zeros when print label hexdump on
terminal, but for non-terminal it prints all buffer. It seems
better to use the same semantic everywhere and skip zeros.

Signed-off-by: Karel Zak <kzak@redhat.com>
disk-utils/fdisk.c

index c6d78922a6371bbc4a632e4f9f9e4fd60786e889..4e790c1b3ec102ad321216d37c98649159ae3b3d 100644 (file)
@@ -729,7 +729,7 @@ static size_t skip_empty(const unsigned char *buf, size_t i, size_t sz)
        return next == i + 16 ? i : next;
 }
 
-static void dump_buffer(off_t base, unsigned char *buf, size_t sz, int all)
+static void dump_buffer(off_t base, unsigned char *buf, size_t sz)
 {
        size_t i, l, next = 0;
 
@@ -737,7 +737,7 @@ static void dump_buffer(off_t base, unsigned char *buf, size_t sz, int all)
                return;
        for (i = 0, l = 0; i < sz; i++, l++) {
                if (l == 0) {
-                       if (all == 0 && !next)
+                       if (!next)
                                next = skip_empty(buf, i, sz);
                        printf("%08jx ", (intmax_t)base + i);
                }
@@ -759,7 +759,7 @@ static void dump_buffer(off_t base, unsigned char *buf, size_t sz, int all)
 }
 
 static void dump_blkdev(struct fdisk_context *cxt, const char *name,
-                       uint64_t offset, size_t size, int all)
+                       uint64_t offset, size_t size)
 {
        int fd = fdisk_get_devfd(cxt);
 
@@ -776,23 +776,20 @@ static void dump_blkdev(struct fdisk_context *cxt, const char *name,
                if (read_all(fd, (char *) buf, size) != (ssize_t) size)
                        fdisk_warn(cxt, _("cannot read"));
                else
-                       dump_buffer(offset, buf, size, all);
+                       dump_buffer(offset, buf, size);
                free(buf);
        }
 }
 
 void dump_firstsector(struct fdisk_context *cxt)
 {
-       int all = !isatty(STDOUT_FILENO);
-
        assert(cxt);
 
-       dump_blkdev(cxt, _("First sector"), 0, fdisk_get_sector_size(cxt), all);
+       dump_blkdev(cxt, _("First sector"), 0, fdisk_get_sector_size(cxt));
 }
 
 void dump_disklabel(struct fdisk_context *cxt)
 {
-       int all = !isatty(STDOUT_FILENO);
        int i = 0;
        const char *name = NULL;
        uint64_t offset = 0;
@@ -801,7 +798,7 @@ void dump_disklabel(struct fdisk_context *cxt)
        assert(cxt);
 
        while (fdisk_locate_disklabel(cxt, i++, &name, &offset, &size) == 0 && size)
-               dump_blkdev(cxt, name, offset, size, all);
+               dump_blkdev(cxt, name, offset, size);
 }
 
 static fdisk_sector_t get_dev_blocks(char *dev)