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>
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));
}
*/
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));