summaryrefslogtreecommitdiffstats
path: root/fdisks/fdisk.c
diff options
context:
space:
mode:
authorKarel Zak2012-07-23 23:09:41 +0200
committerKarel Zak2012-07-24 12:28:35 +0200
commit594304d56d2238315ebc64347a963acab398b83d (patch)
treee6dd098773b216c82401ab09bfd913dcfe8d7903 /fdisks/fdisk.c
parentfdisk: remove unused variables (diff)
downloadkernel-qcow2-util-linux-594304d56d2238315ebc64347a963acab398b83d.tar.gz
kernel-qcow2-util-linux-594304d56d2238315ebc64347a963acab398b83d.tar.xz
kernel-qcow2-util-linux-594304d56d2238315ebc64347a963acab398b83d.zip
fdisk: don't ignore 1MiB granularity on 512-byte sector devices
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>
Diffstat (limited to 'fdisks/fdisk.c')
-rw-r--r--fdisks/fdisk.c17
1 files changed, 15 insertions, 2 deletions
diff --git a/fdisks/fdisk.c b/fdisks/fdisk.c
index 997ee946c..4731918b8 100644
--- a/fdisks/fdisk.c
+++ b/fdisks/fdisk.c
@@ -297,7 +297,20 @@ static int
lba_is_aligned(struct fdisk_context *cxt, sector_t lba)
{
unsigned int granularity = max(cxt->phy_sector_size, cxt->min_io_size);
- sector_t offset = (lba * cxt->sector_size) & (granularity - 1);
+ unsigned long long offset;
+
+ if (grain > granularity)
+ granularity = grain;
+ offset = (lba * cxt->sector_size) & (granularity - 1);
+
+ return !((granularity + cxt->alignment_offset - offset) & (granularity - 1));
+}
+
+static int
+lba_is_phy_aligned(struct fdisk_context *cxt, unsigned long long lba)
+{
+ unsigned int granularity = max(cxt->phy_sector_size, cxt->min_io_size);
+ unsigned long long offset = (lba * cxt->sector_size) & (granularity - 1);
return !((granularity + cxt->alignment_offset - offset) & (granularity - 1));
}
@@ -973,7 +986,7 @@ void check_consistency(struct fdisk_context *cxt, struct partition *p, int parti
void check_alignment(struct fdisk_context *cxt, sector_t lba, int partition)
{
- if (!lba_is_aligned(cxt, lba))
+ if (!lba_is_phy_aligned(cxt, lba))
printf(_("Partition %i does not start on physical sector boundary.\n"),
partition + 1);
}