]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libfdisk: (gpt) follow label-id from script
authorKarel Zak <kzak@redhat.com>
Mon, 1 Sep 2014 13:01:34 +0000 (15:01 +0200)
committerKarel Zak <kzak@redhat.com>
Mon, 1 Sep 2014 13:01:34 +0000 (15:01 +0200)
Signed-off-by: Karel Zak <kzak@redhat.com>
libfdisk/src/gpt.c
libfdisk/src/script.c

index 5b06159a48bc6770fe250556c8b96879e9aeaf4f..082dcadce7923f04e933717e0c1cdad048e995df 100644 (file)
@@ -505,6 +505,7 @@ static int gpt_mknew_header(struct fdisk_context *cxt,
                            struct gpt_header *header, uint64_t lba)
 {
        uint64_t first, last;
+       int has_id = 0;
 
        if (!cxt || !header)
                return -ENOSYS;
@@ -525,9 +526,17 @@ static int gpt_mknew_header(struct fdisk_context *cxt,
        header->last_usable_lba  = cpu_to_le64(last);
 
        gpt_mknew_header_common(cxt, header, lba);
-       uuid_generate_random((unsigned char *) &header->disk_guid);
-       swap_efi_guid(&header->disk_guid);
 
+       if (cxt->script) {
+               const char *id = fdisk_script_get_header(cxt->script, "label-id");
+               if (id && string_to_guid(id, &header->disk_guid) == 0)
+                       has_id = 1;
+       }
+
+       if (!has_id) {
+               uuid_generate_random((unsigned char *) &header->disk_guid);
+               swap_efi_guid(&header->disk_guid);
+       }
        return 0;
 }
 
index 69efe4113c3f19f38f5ad45296e44355e3223b21..5b0548f7a881a70861d3202bc81d750a73dc9325 100644 (file)
@@ -900,7 +900,7 @@ int test_apply(struct fdisk_test *ts, int argc, char *argv[])
        int rc;
 
        cxt = fdisk_new_context();
-       fdisk_assign_device(cxt, devname, 1);
+       fdisk_assign_device(cxt, devname, 0);
 
        dp = fdisk_new_script_from_file(cxt, scriptname);
        if (!dp)
@@ -925,6 +925,8 @@ int test_apply(struct fdisk_test *ts, int argc, char *argv[])
 done:
        fdisk_free_iter(itr);
        fdisk_unref_table(tb);
+
+       /*fdisk_write_disklabel(cxt);*/
        fdisk_unref_context(cxt);
        return 0;
 }