summaryrefslogtreecommitdiffstats
path: root/fdisks/gpt.c
diff options
context:
space:
mode:
authorKarel Zak2012-12-04 14:49:17 +0100
committerKarel Zak2012-12-04 14:49:17 +0100
commitb41846909f7ea7f2445f71c5cbedcb140410d1fd (patch)
treedcf0406d9396d6eb125d7959e2b8be07ef616274 /fdisks/gpt.c
parentvipw: remove unused set{uid,gid} calls (diff)
downloadkernel-qcow2-util-linux-b41846909f7ea7f2445f71c5cbedcb140410d1fd.tar.gz
kernel-qcow2-util-linux-b41846909f7ea7f2445f71c5cbedcb140410d1fd.tar.xz
kernel-qcow2-util-linux-b41846909f7ea7f2445f71c5cbedcb140410d1fd.zip
fdisk: (gpt) use topology to define FirstUsableLBA
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'fdisks/gpt.c')
-rw-r--r--fdisks/gpt.c14
1 files changed, 11 insertions, 3 deletions
diff --git a/fdisks/gpt.c b/fdisks/gpt.c
index cc20ba937..21a7cad67 100644
--- a/fdisks/gpt.c
+++ b/fdisks/gpt.c
@@ -390,7 +390,7 @@ static int gpt_mknew_header_from_bkp(struct fdisk_context *cxt,
static int gpt_mknew_header(struct fdisk_context *cxt,
struct gpt_header *header, uint64_t lba)
{
- uint64_t esz = 0;
+ uint64_t esz = 0, first, last;
if (!cxt || !header)
return -ENOSYS;
@@ -407,8 +407,16 @@ static int gpt_mknew_header(struct fdisk_context *cxt,
*/
header->npartition_entries = cpu_to_le32(GPT_NPARTITIONS);
header->sizeof_partition_entry = cpu_to_le32(sizeof(struct gpt_entry));
- header->first_usable_lba = cpu_to_le64(esz + 2);
- header->last_usable_lba = cpu_to_le64(cxt->total_sectors - 2 - esz);
+
+ last = cxt->total_sectors - 2 - esz;
+ first = esz + 2;
+
+ if (first < cxt->first_lba && cxt->first_lba < last)
+ /* Align according to topology */
+ first = cxt->first_lba;
+
+ header->first_usable_lba = cpu_to_le64(first);
+ header->last_usable_lba = cpu_to_le64(last);
gpt_mknew_header_common(cxt, header, lba);
uuid_generate_random((unsigned char *) &header->disk_guid);