return rc;
}
+char *fdisk_ask_string_get_result(struct fdisk_ask *ask)
+{
+ assert(ask);
+ assert(fdisk_is_ask(ask, STRING));
+ return ask->data.str.result;
+}
+
+/*
+ * The @result has to be poiter to the allocated buffer.
+ */
+int fdisk_ask_string_set_result(struct fdisk_ask *ask, char *result)
+{
+ assert(ask);
+ ask->data.str.result = result;
+ return 0;
+}
+
+/*
+ * Don't forget to deallocate @result.
+ */
+int fdisk_ask_string(struct fdisk_context *cxt,
+ const char *query,
+ char **result)
+{
+ struct fdisk_ask *ask;
+ int rc;
+
+ assert(cxt);
+
+ ask = fdisk_new_ask();
+ if (!ask)
+ return -ENOMEM;
+
+ rc = fdisk_ask_set_type(ask, FDISK_ASKTYPE_STRING);
+ if (!rc)
+ fdisk_ask_set_query(ask, query);
+ if (!rc)
+ rc = fdisk_do_ask(cxt, ask);
+ if (!rc)
+ *result = fdisk_ask_string_get_result(ask);
+
+ fdisk_free_ask(ask);
+ DBG(ASK, dbgprint("result: %s [rc=%d]\n", *result, rc));
+ return rc;
+}
+
int fdisk_ask_yesno(struct fdisk_context *cxt,
const char *query,
int *result)
struct ask_yesno {
int result; /* TRUE or FALSE */
} yesno;
+ /* FDISK_ASKTYPE_STRING */
+ struct ask_string {
+ char *result; /* allocated */
+ } str;
/* FDISK_ASKTYPE_TABLE, see include/tt.h */
struct tt *table;
} data;
return 0;
}
+int fdisk_gpt_partition_set_uuid(struct fdisk_context *cxt, size_t i)
+{
+ struct fdisk_gpt_label *gpt;
+ struct gpt_entry *e;
+ struct gpt_guid uuid;
+ char *str, new_u[37], old_u[37];
+ int rc;
+
+ assert(cxt);
+ assert(cxt->label);
+ assert(fdisk_is_disklabel(cxt, GPT));
+
+ DBG(LABEL, dbgprint("UUID change requested parno=%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 UUID (in 8-4-4-4-12 format)"), &str))
+ return -EINVAL;
+
+ rc = string_to_guid(str, &uuid);
+ free(str);
+
+ if (rc)
+ return rc;
+
+ e = &gpt->ents[i];
+
+ guid_to_string(&e->unique_partition_guid, old_u);
+ guid_to_string(&uuid, new_u);
+ fdisk_info(cxt, _("Changing partition UUID from %s to %s"),
+ old_u, new_u);
+
+ e->unique_partition_guid = uuid;
+ 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
FDISK_ASKTYPE_WARNX,
FDISK_ASKTYPE_INFO,
FDISK_ASKTYPE_YESNO,
- FDISK_ASKTYPE_TABLE
+ FDISK_ASKTYPE_TABLE,
+ FDISK_ASKTYPE_STRING
};
extern int fdisk_dos_enable_compatible(struct fdisk_label *lb, int enable);
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);
+
/* ask.c */
#define fdisk_is_ask(a, x) (fdisk_ask_get_type(a) == FDISK_ASKTYPE_ ## x)
const char *query,
uintmax_t *result);
+extern int fdisk_ask_string(struct fdisk_context *cxt,
+ const char *query,
+ char **result);
+
+extern char *fdisk_ask_string_get_result(struct fdisk_ask *ask);
+extern int fdisk_ask_string_set_result(struct fdisk_ask *ask, char *result);
+
extern int fdisk_ask_yesno(struct fdisk_context *cxt, const char *query, int *result);
extern uint64_t fdisk_ask_yesno_get_result(struct fdisk_ask *ask);
extern int fdisk_ask_yesno_set_result(struct fdisk_ask *ask, uint64_t result);