]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libfdisk: support GPT partition name (label) change
authorKarel Zak <kzak@redhat.com>
Tue, 21 May 2013 14:12:10 +0000 (16:12 +0200)
committerKarel Zak <kzak@redhat.com>
Mon, 16 Sep 2013 14:46:56 +0000 (16:46 +0200)
Signed-off-by: Karel Zak <kzak@redhat.com>
fdisks/fdisk-menu.c
libfdisk/src/gpt.c
libfdisk/src/libfdisk.h

index 0ea3dc1d31b4217cb2380ac13e00c873d0d61c7e..474a06af369d3b00b2ef6fe42f30bcbe85f1a213 100644 (file)
@@ -381,8 +381,7 @@ static int gpt_menu_cb(struct fdisk_context *cxt,
                rc = fdisk_gpt_partition_set_uuid(cxt, n);
                break;
        case 'n':
-               /* not implemented yet
-               rc = fdisk_gpt_partition_set_name(cxt, n);*/
+               rc = fdisk_gpt_partition_set_name(cxt, n);
                break;
        }
        return rc;
index 4a992f0c38b10f11f04dc0eadea328d75f88503e..9cce053f8ca2e90b398f9a19d931165ab8534ea8 100644 (file)
@@ -1566,12 +1566,6 @@ static int gpt_create_new_partition(struct fdisk_context *cxt,
 
        gpt_entry_set_type(e, type);
 
-       /* deal with partition name
-       for (i = 0; i < GPT_PART_NAME_LEN; i++)
-               e->name[i] =
-                       cpu_to_le16((uint16_t) gpt_sys_types[sys].name[i]);
-       */
-
        /*
         * Any time a new partition entry is created a new GUID must be
         * generated for that partition, and every partition is guaranteed
@@ -1875,7 +1869,7 @@ int fdisk_gpt_partition_set_uuid(struct fdisk_context *cxt, size_t i)
        assert(cxt->label);
        assert(fdisk_is_disklabel(cxt, GPT));
 
-       DBG(LABEL, dbgprint("UUID change requested parno=%zd", i));
+       DBG(LABEL, dbgprint("UUID change requested partno=%zd", i));
 
        gpt = self_label(cxt);
 
@@ -1907,6 +1901,52 @@ int fdisk_gpt_partition_set_uuid(struct fdisk_context *cxt, size_t i)
        return 0;
 }
 
+int fdisk_gpt_partition_set_name(struct fdisk_context *cxt, size_t i)
+{
+       struct fdisk_gpt_label *gpt;
+       struct gpt_entry *e;
+       char *str, *old, name[GPT_PART_NAME_LEN] = { 0 };
+       size_t sz;
+
+       assert(cxt);
+       assert(cxt->label);
+       assert(fdisk_is_disklabel(cxt, GPT));
+
+       DBG(LABEL, dbgprint("NAME change requested partno=%zd", i));
+
+       gpt = self_label(cxt);
+
+       if ((uint32_t) i >= le32_to_cpu(gpt->pheader->npartition_entries))
+               return -EINVAL;
+
+       if (fdisk_ask_string(cxt, _("New name"), &str))
+               return -EINVAL;
+
+       e = &gpt->ents[i];
+       old = encode_to_utf8((unsigned char *)e->name, sizeof(e->name));
+
+       fdisk_info(cxt, _("Changing partition name from '%s' to '%.*s'"),
+                               old, GPT_PART_NAME_LEN, str);
+       sz = strlen(str);
+       if (sz) {
+               if (sz > GPT_PART_NAME_LEN)
+                       sz = GPT_PART_NAME_LEN;
+               memcpy(name, str, sz);
+       }
+       free(str);
+       free(old);
+
+       for (i = 0; i < GPT_PART_NAME_LEN; i++)
+               e->name[i] = cpu_to_le16((uint16_t) name[i]);
+
+       gpt_recompute_crc(gpt->pheader, gpt->ents);
+       gpt_recompute_crc(gpt->bheader, gpt->ents);
+
+       fdisk_label_set_changed(cxt->label, 1);
+       return 0;
+}
+
+
 /*
  * Deinitialize fdisk-specific variables
  */
index 284e24e026558d899519f6e91b9ac688e02f1d34..049420d7ead8d6692943201a32ff4ebe8c46ac87 100644 (file)
@@ -144,6 +144,7 @@ extern int fdisk_dos_is_compatible(struct fdisk_label *lb);
 
 /* gpt */
 extern int fdisk_gpt_partition_set_uuid(struct fdisk_context *cxt, size_t i);
+extern int fdisk_gpt_partition_set_name(struct fdisk_context *cxt, size_t i);
 
 /* ask.c */
 #define fdisk_is_ask(a, x) (fdisk_ask_get_type(a) == FDISK_ASKTYPE_ ## x)