From 9fabc6d5fae3da9106d41c40af6fbef6265ae11b Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Thu, 23 Jan 2020 15:07:32 +0100 Subject: [PATCH] sfdisk: remove broken step alignment for --move * remove unnecessary and broken step alignment * improve reported information in move log * improve final progress bar update Addresses: https://github.com/karelzak/util-linux/issues/938 Signed-off-by: Karel Zak --- disk-utils/sfdisk.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/disk-utils/sfdisk.c b/disk-utils/sfdisk.c index 8f2edb87f7..bb6e1c6df0 100644 --- a/disk-utils/sfdisk.c +++ b/disk-utils/sfdisk.c @@ -430,11 +430,6 @@ static int move_partition_data(struct sfdisk *sf, size_t partno, struct fdisk_pa step_bytes = io; step = step_bytes / ss; - - /* align the step (note that nsectors does not have to be power of 2) */ - while (nsectors % step) - step--; - nbytes = nsectors * ss; DBG(MISC, ul_debug(" step: %ju (%zu bytes)", (uintmax_t)step, step_bytes)); @@ -485,15 +480,15 @@ static int move_partition_data(struct sfdisk *sf, size_t partno, struct fdisk_pa fprintf(f, "# Disk: %s\n", devname); fprintf(f, "# Partition: %zu\n", partno + 1); fprintf(f, "# Operation: move data\n"); + fprintf(f, "# Sector size: %zu\n", ss); fprintf(f, "# Original start offset (sectors/bytes): %ju/%ju\n", (uintmax_t)from, (uintmax_t)from * ss); fprintf(f, "# New start offset (sectors/bytes): %ju/%ju\n", (uintmax_t)to, (uintmax_t)to * ss); fprintf(f, "# Area size (sectors/bytes): %ju/%ju\n", (uintmax_t)nsectors, (uintmax_t)nsectors * ss); - fprintf(f, "# Sector size: %zu\n", ss); - fprintf(f, "# Step size (in bytes): %zu\n", step_bytes); - fprintf(f, "# Steps: %ju\n", (uintmax_t)(nsectors / step)); + fprintf(f, "# Step size (sectors/bytes): %zu/%zu\n", step, step_bytes); + fprintf(f, "# Steps: %ju\n", ((uintmax_t) nsectors / step) + 1); fprintf(f, "#\n"); fprintf(f, "# : (step offsets in bytes)\n"); } @@ -584,7 +579,7 @@ static int move_partition_data(struct sfdisk *sf, size_t partno, struct fdisk_pa fputc(' ', stdout); fflush(stdout); fputc('\r', stdout); - fprintf(stdout, _("Moved %ju from %ju sectors (%.3f%%)."), + fprintf(stdout, _("Moved %ju from %ju sectors (%.0f%%)."), i, nsectors, 100.0 / ((double) nsectors/(i+1))); fputc('\n', stdout); -- 2.39.2