diff options
author | Karel Zak <kzak@redhat.com> | 2012-07-23 23:09:41 +0200 |
---|---|---|
committer | Karel Zak <kzak@redhat.com> | 2012-07-23 23:09:41 +0200 |
commit | c0175e6185ac81843cbad33cbea75abd033f0e66 (patch) | |
tree | 7e92d77134bbc12d79344e5606c3d7f0f640174e | |
parent | ffec577fbc5615199a55e7770a69273351b0e6c1 (diff) | |
download | util-linux-playground-stable/v2.21.tar.gz |
fdisk: don't ignore 1MiB granularity on 512-byte sector devicesstable/v2.21
Note that +10MB is 100000 (10^N) and relative values (+<size>
convention) should be be aligned to the default grain (= 1 MiB).
Old version:
Last sector, +sectors or +size{K,M,G} (2048-2047999, default 2047999): +10MB
Partition 1 of type Linux and of size 9.5 MiB is set
...
/dev/loop0p1 2048 21578 9765+ 83 Linux
/dev/loop0p2 21579 43062 10742 83 Linux
New version:
Last sector, +sectors or +size{K,M,G} (2048-2047999, default 2047999): +10MB
Partition 1 of type Linux and of size 10 MiB is set
...
/dev/loop0p1 2048 22527 10240 83 Linux
/dev/loop0p2 22528 43007 10240 83 Linux
Addresses: http://thread.gmane.org/gmane.linux.kernel.device-mapper.dm-crypt/5913/focus=5929
Reported-by: Milan Broz <mbroz@redhat.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
-rw-r--r-- | fdisk/fdisk.c | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/fdisk/fdisk.c b/fdisk/fdisk.c index 8893a01749..b65703f88a 100644 --- a/fdisk/fdisk.c +++ b/fdisk/fdisk.c @@ -569,6 +569,19 @@ static int lba_is_aligned(unsigned long long lba) { unsigned int granularity = max(phy_sector_size, min_io_size); + unsigned long long offset; + + if (grain > granularity) + granularity = grain; + offset = (lba * sector_size) & (granularity - 1); + + return !((granularity + alignment_offset - offset) & (granularity - 1)); +} + +static int +lba_is_phy_aligned(unsigned long long lba) +{ + unsigned int granularity = max(phy_sector_size, min_io_size); unsigned long long offset = (lba * sector_size) & (granularity - 1); return !((granularity + alignment_offset - offset) & (granularity - 1)); @@ -1808,7 +1821,7 @@ static void check_consistency(struct partition *p, int partition) { static void check_alignment(unsigned long long lba, int partition) { - if (!lba_is_aligned(lba)) + if (!lba_is_phy_aligned(lba)) printf(_("Partition %i does not start on physical sector boundary.\n"), partition + 1); } |