]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
sfdisk: remove broken step alignment for --move
authorKarel Zak <kzak@redhat.com>
Thu, 23 Jan 2020 14:07:32 +0000 (15:07 +0100)
committerKarel Zak <kzak@redhat.com>
Thu, 23 Jan 2020 14:07:32 +0000 (15:07 +0100)
* 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 <kzak@redhat.com>
disk-utils/sfdisk.c

index 8f2edb87f79325b3926c8183a830d4f47155de97..bb6e1c6df0569a5ec56c748f4ceef3a2431e83a0 100644 (file)
@@ -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>: <from> <to> (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);