From 975b321b5dae3b73346886e4d44fc1e4d6a2862b Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Thu, 22 Aug 2019 14:00:32 +0200 Subject: [PATCH] libfidk: (dos) fix tiny partitions calculation 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 --- libfdisk/src/dos.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/libfdisk/src/dos.c b/libfdisk/src/dos.c index fc5bcc6512..28a9bafd46 100644 --- a/libfdisk/src/dos.c +++ b/libfdisk/src/dos.c @@ -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)); -- 2.39.2