diff options
| author | Karel Zak <kzak@redhat.com> | 2019-09-06 15:05:21 +0200 |
|---|---|---|
| committer | Karel Zak <kzak@redhat.com> | 2019-09-06 15:07:59 +0200 |
| commit | 4bf424188ddb69718801f41a8d005c43283fad8a (patch) | |
| tree | 936a354601da9ca8c2f0fac711d029d6f3f5e24f /disk-utils/sfdisk.c | |
| parent | e4e0b1a6f054e3553772ca65874a6b4b0921d76f (diff) | |
| download | util-linux-4bf424188ddb69718801f41a8d005c43283fad8a.tar.gz | |
sfdisk: (--move-data) add simple progress bar
Addresses: https://github.com/karelzak/util-linux/issues/848
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'disk-utils/sfdisk.c')
| -rw-r--r-- | disk-utils/sfdisk.c | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/disk-utils/sfdisk.c b/disk-utils/sfdisk.c index cbae88b9a3..53ae310102 100644 --- a/disk-utils/sfdisk.c +++ b/disk-utils/sfdisk.c @@ -373,7 +373,7 @@ static int move_partition_data(struct sfdisk *sf, size_t partno, struct fdisk_pa fdisk_sector_t nsectors, from, to, step, i; size_t io, ss, step_bytes, cc; uintmax_t src, dst; - int errsv; + int errsv, progress = 0; assert(sf->movedata); @@ -452,6 +452,9 @@ static int move_partition_data(struct sfdisk *sf, size_t partno, struct fdisk_pa printf(_(" step size: %zu bytes\n"), step_bytes); putchar('\n'); fflush(stdout); + + if (isatty(fileno(stdout))) + progress = 1; } if (sf->interactive) { @@ -523,6 +526,14 @@ static int move_partition_data(struct sfdisk *sf, size_t partno, struct fdisk_pa /* write log */ if (f) fprintf(f, "%05zu: %12ju %12ju\n", cc, src, dst); + if (progress) { + fprintf(stdout, _("Moved %ju from %ju sectors (%.3f%%)."), + i + 1, nsectors, + 100.0 / ((double) nsectors/(i+1))); + fflush(stdout); + fputc('\r', stdout); + } + #if defined(POSIX_FADV_DONTNEED) && defined(HAVE_POSIX_FADVISE) if (!sf->noact) @@ -532,6 +543,12 @@ static int move_partition_data(struct sfdisk *sf, size_t partno, struct fdisk_pa src += step_bytes, dst += step_bytes; } + if (progress) { + fprintf(stdout, _("Moved %ju from %ju sectors (%.3f%%)."), + i, nsectors, + 100.0 / ((double) nsectors/(i+1))); + fputc('\n', stdout); + } if (f) fclose(f); free(buf); |
