fdisk: always skips zeros in dumps
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>
This commit is contained in:
parent
22a900a90f
commit
a970c2dd51
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue