}
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;
+}
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,
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");
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;
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,
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;
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);
}
}
+/**
+ * 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;
+}