From: Karel Zak Date: Mon, 15 Feb 2010 14:55:22 +0000 (+0100) Subject: fdisk: use 1MiB offset and grain always when possible X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3bceed942a0bd982c7f49cf721a12b123d6de87f;p=util-linux fdisk: use 1MiB offset and grain always when possible It would be nice to minimize dependence between the disk layout and disk topology. We have to follow disk topology for alignment_offset and huge (> 1MiB) I/O sizes only. For all others disks we can use 1MiB grain and 1MiB offset. Reported-by: "H. Peter Anvin" Signed-off-by: Karel Zak --- diff --git a/fdisk/fdisk.c b/fdisk/fdisk.c index b752d9b9..196f76d4 100644 --- a/fdisk/fdisk.c +++ b/fdisk/fdisk.c @@ -1080,17 +1080,26 @@ update_sector_offset(void) * device where the offset is quarter of of whole size * of the device). */ - unsigned long long x; + unsigned long long x = 0; - if (has_topology) - x = alignment_offset ? alignment_offset : io_size; - else - x = grain = 2048 * 512; + if (has_topology) { + if (alignment_offset) + x = alignment_offset; + else if (io_size > 2048 * 512) + x = io_size; + } + /* default to 1MiB */ + if (!x) + x = 2048 * 512; sector_offset = x / sector_size; if (total_number_of_sectors <= sector_offset * 4) sector_offset = phy_sector_size / sector_size; + + /* use 1MiB grain always when possible */ + if (grain < 2048 * 512) + grain = 2048 * 512; } }