]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
fdisk: use libfdisk to ask for partition type
authorKarel Zak <kzak@redhat.com>
Wed, 12 Jun 2013 15:09:28 +0000 (17:09 +0200)
committerKarel Zak <kzak@redhat.com>
Mon, 16 Sep 2013 14:47:01 +0000 (16:47 +0200)
Signed-off-by: Karel Zak <kzak@redhat.com>
fdisks/fdisk-ask.c
fdisks/fdisk.c
fdisks/fdisk.h
fdisks/fdiskbsdlabel.c
libfdisk/src/libfdisk.h
libfdisk/src/parttype.c

index 0c4e200f14cb12000dccc1af4b26bd9413f3c1fb..a7e86e1c3351f5fcf3080510217169777682c252 100644 (file)
@@ -220,3 +220,30 @@ int ask_callback(struct fdisk_context *cxt, struct fdisk_ask *ask,
        }
        return rc;
 }
+
+
+struct fdisk_parttype *ask_partition_type(struct fdisk_context *cxt)
+{
+       const char *q;
+
+       if (!cxt || !cxt->label || !cxt->label->nparttypes)
+               return NULL;
+
+        q = fdisk_is_parttype_string(cxt) ?
+               _("Partition type (type L to list all types): ") :
+               _("Hex code (type L to list all codes): ");
+       do {
+               char buf[256];
+               int rc = get_user_reply(cxt, q, buf, sizeof(buf));
+
+               if (rc)
+                       break;
+
+               if (buf[1] == '\0' && toupper(*buf) == 'L')
+                       list_partition_types(cxt);
+               else if (*buf)
+                       return fdisk_parse_parttype(cxt, buf);
+        } while (1);
+
+       return NULL;
+}
index d9c1753294eb8819f39217cd31ee338314b9120d..4d804e4be037ac03019edf5d2cedcfb4915c8d42 100644 (file)
@@ -280,33 +280,6 @@ char read_chars(struct fdisk_context *cxt, char *mesg)
        return *line_ptr;
 }
 
-struct fdisk_parttype *read_partition_type(struct fdisk_context *cxt)
-{
-       if (!cxt || !cxt->label || !cxt->label->nparttypes)
-               return NULL;
-
-        do {
-               size_t sz;
-
-               if (cxt->label->parttypes[0].typestr)
-                       read_chars(cxt, _("Partition type (type L to list all types): "));
-               else
-                       read_chars(cxt, _("Hex code (type L to list all codes): "));
-
-               sz = strlen(line_ptr);
-               if (!sz || line_ptr[sz - 1] != '\n' || sz == 1)
-                       continue;
-               line_ptr[sz - 1] = '\0';
-
-               if (tolower(*line_ptr) == 'l')
-                       list_partition_types(cxt);
-               else
-                       return fdisk_parse_parttype(cxt, line_ptr);
-        } while (1);
-
-       return NULL;
-}
-
 /* deprecated in favour of fdisk_ask_number() */
 unsigned int
 read_int_with_suffix(struct fdisk_context *cxt,
@@ -453,6 +426,7 @@ read_int(struct fdisk_context *cxt,
        return read_int_with_suffix(cxt, low, dflt, high, base, mesg, NULL);
 }
 
+
 static void toggle_dos_compatibility_flag(struct fdisk_context *cxt)
 {
        struct fdisk_label *lb = fdisk_context_get_label(cxt, "dos");
@@ -501,7 +475,7 @@ static void change_partition_type(struct fdisk_context *cxt)
                 printf(_("Partition %zu does not exist yet!\n"), i + 1);
 
         else do {
-               t = read_partition_type(cxt);
+               t = ask_partition_type(cxt);
                if (!t)
                        continue;
 
index 32d6a2afbbcaadb8476708cd4606d6d6ecc0262c..1d15c8213bcc564b37da375e4d24148de3b6431c 100644 (file)
@@ -74,7 +74,8 @@ extern char *line_ptr;
 extern void list_partition_types(struct fdisk_context *cxt);
 extern int read_line(struct fdisk_context *cxt, int *asked);
 extern char read_char(struct fdisk_context *cxt, char *mesg);
-extern struct fdisk_parttype *read_partition_type(struct fdisk_context *cxt);
+
+extern struct fdisk_parttype *ask_partition_type(struct fdisk_context *cxt);
 extern void reread_partition_table(struct fdisk_context *cxt, int leave);
 extern struct partition *get_part_table(int);
 extern unsigned int read_int(struct fdisk_context *cxt,
index 4a8bf48dbc2c269a76d55124d8d98c9bb7af0d1e..8f891b0da41c5ffa6ff34de5aa1ad040d40c5030 100644 (file)
@@ -674,7 +674,7 @@ static void xbsd_change_fstype (struct fdisk_context *cxt)
 
   if (xbsd_get_part_index(cxt, xbsd_dlabel.d_npartitions, &i))
          return;
-  t = read_partition_type(cxt);
+  t = ask_partition_type(cxt);
 
   if (t) {
     xbsd_dlabel.d_partitions[i].p_fstype = t->type;
index cfcc62b812a09f2c9d3eeea9d00100e35ee98104..bd3fc60dfcecb282d34aee9f1f9c6a01f4ea3862 100644 (file)
@@ -108,6 +108,8 @@ extern struct fdisk_parttype *fdisk_new_unknown_parttype(unsigned int type, cons
 extern void fdisk_free_parttype(struct fdisk_parttype *type);
 extern size_t fdisk_get_nparttypes(struct fdisk_context *cxt);
 
+extern int fdisk_is_parttype_string(struct fdisk_context *cxt);
+
 /* label.c */
 extern int fdisk_dev_has_disklabel(struct fdisk_context *cxt);
 
index e78b355943d1a3dd8dc863b69fd6bffc5b09e0a6..8a13d721178644ae6162f8c00da5bc6872178e6e 100644 (file)
@@ -165,4 +165,19 @@ void fdisk_free_parttype(struct fdisk_parttype *t)
        }
 }
 
+/**
+ * fdisk_is_parttype_string:
+ * @cxt: context
+ *
+ * Returns: 1 if the current label uses strings as partition type
+ *          identifiers (e.g. GPT UUIDS) or 0.
+ */
+int fdisk_is_parttype_string(struct fdisk_context *cxt)
+{
+       assert(cxt);
+       assert(cxt->label);
 
+       if (cxt->label->parttypes && cxt->label->parttypes[0].typestr)
+               return 1;
+       return 0;
+}