]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
fdisk: (gpt) use topology to define FirstUsableLBA
authorKarel Zak <kzak@redhat.com>
Tue, 4 Dec 2012 13:49:17 +0000 (14:49 +0100)
committerKarel Zak <kzak@redhat.com>
Tue, 4 Dec 2012 13:49:17 +0000 (14:49 +0100)
Signed-off-by: Karel Zak <kzak@redhat.com>
fdisks/gpt.c

index cc20ba937afa40a235d6f3781e024cfdb49be1ed..21a7cad67d51bc528f5760e915b090e8700d2a30 100644 (file)
@@ -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);