]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libfidk: (dos) fix tiny partitions calculation
authorKarel Zak <kzak@redhat.com>
Thu, 22 Aug 2019 12:00:32 +0000 (14:00 +0200)
committerKarel Zak <kzak@redhat.com>
Thu, 22 Aug 2019 12:00:32 +0000 (14:00 +0200)
The code uses last_sector -= 1 for tiny partitions. This does not make
sense. This stupidity has been introduced by (my) badly commented commit
09a4ca5e450c5e7cbe860453b76fd68c60fe591f ... sorry.

Fortunately, this issue is visible only for tiny partitions on large
devices (partitions where size < grain; usual grain is 1MiB) if the last
sector is specified by relative notation (+size{siffix}).

Note that "last -= 1" makes sense when the "last" is align to the
optimal I/O boundary; in this case we need to set the end of the
partition one sector before the boundary. For tiny devices it does not
makes sense as we do not align these partitions.

Addresses: https://github.com/karelzak/util-linux/issues/843
Signed-off-by: Karel Zak <kzak@redhat.com>
libfdisk/src/dos.c

index fc5bcc651253c3a4cda5ac2069155ecccae6e446..28a9bafd46ae2de8f431fcd2d2626d9b8983c6b1 100644 (file)
@@ -1313,8 +1313,6 @@ static int add_partition(struct fdisk_context *cxt, size_t n,
        if (isrel && stop - start < (cxt->grain / fdisk_get_sector_size(cxt))) {
                /* Don't try to be smart on very small partitions and don't align so small sizes */
                isrel = 0;
-               if (stop > start)
-                       stop -= 1;
                DBG(LABEL, ul_debug("DOS: don't align end of tiny partition [start=%ju, stop=%ju, grain=%lu]",
                            (uintmax_t)start,  (uintmax_t)stop, cxt->grain));
        }
@@ -1327,7 +1325,7 @@ static int add_partition(struct fdisk_context *cxt, size_t n,
                 */
                stop = fdisk_align_lba_in_range(cxt, stop, start, limit);
                if (stop > start)
-                       stop -= 1;
+                       stop -= 1;      /* end one sector before aligned offset */
                if (stop > limit)
                        stop = limit;
                DBG(LABEL, ul_debug("DOS: aligned stop: %ju", (uintmax_t) stop));