{
int partnum = 0;
+ assert(cxt);
+ assert(cxt->label);
+
if (warn_geometry(cxt))
return;
if (fdisk_is_disklabel(cxt, SUN) ||
fdisk_is_disklabel(cxt, SGI) ||
- fdisk_is_disklabel(cxt, GPT))
- partnum = get_partition(cxt, 0, partitions);
+ fdisk_is_disklabel(cxt, GPT)) {
+ size_t dflt = 0;
+
+ /*
+ * TODO: always use label->nparts_cur + 1
+ * (currenly only few drivers maintain label->nparts_* counters)
+ */
+ if (cxt->label->nparts_max)
+ dflt = cxt->label->nparts_cur + 1;
+
+ partnum = get_partition_dflt(cxt, 0, partitions, dflt);
+ }
fdisk_add_partition(cxt, partnum, NULL);
}
return totfound;
}
-/*
- * Initialize fdisk-specific variables - call once probing passes!
- */
-static void gpt_init(struct fdisk_context *cxt)
-{
- struct fdisk_gpt_label *gpt = gpt_label(cxt);
-
- partitions = le32_to_cpu(gpt->pheader->npartition_entries);
-}
-
-
static int gpt_probe_label(struct fdisk_context *cxt, struct fdisk_label *lb)
{
int mbr_type;
/* OK, probing passed, now initialize backup header and fdisk variables. */
gpt->bheader = gpt_read_header(cxt, last_lba(cxt), NULL);
- gpt_init(cxt);
+ lb->nparts_max = le32_to_cpu(gpt->pheader->npartition_entries);
+ lb->nparts_cur = partitions_in_use(gpt->pheader, gpt->ents);
+
+ partitions = lb->nparts_max; /* TODO: deprecated */
printf(_("\nWARNING: fdisk GPT support is currently new, and therefore "
"in an experimental phase. Use at your own discretion.\n\n"));
/* Delete a single GPT partition, specified by partnum. */
static int gpt_delete_partition(struct fdisk_context *cxt,
- struct fdisk_label *lb,
- int partnum)
+ struct fdisk_label *lb,
+ int partnum)
{
struct fdisk_gpt_label *gpt = (struct fdisk_gpt_label *) lb;
else {
gpt_recompute_crc(gpt->pheader, gpt->ents);
gpt_recompute_crc(gpt->bheader, gpt->ents);
+ lb->nparts_cur--;
}
return 0;
if (gpt_create_new_partition(cxt, partnum,
user_f, user_l, &uuid, ents) != 0)
printf(_("Could not create partition %d\n"), partnum + 1);
- else
+ else {
printf(_("Created partition %d\n"), partnum + 1);
+ lb->nparts_cur++;
+ }
return 0;
}
/*
* Create a new GPT disklabel - destroys any previous data.
*/
-static int gpt_create_disklabel(struct fdisk_context *cxt,
- struct fdisk_label *lb)
+static int gpt_create_disklabel(struct fdisk_context *cxt, struct fdisk_label *lb)
{
int rc = 0;
ssize_t entry_sz = 0;
gpt_recompute_crc(gpt->pheader, gpt->ents);
gpt_recompute_crc(gpt->bheader, gpt->ents);
- gpt_init(cxt);
+ lb->nparts_max = le32_to_cpu(gpt->pheader->npartition_entries);
+ lb->nparts_cur = 0;
+
+ partitions = lb->nparts_max; /* TODO: deprecated */
uid = &gpt->pheader->disk_guid;
fprintf(stderr, ("Building a new GPT disklabel "
* Generic label
*/
struct fdisk_label {
- /* persistent information */
- const char *name;
+ const char *name; /* label name */
enum fdisk_labeltype id; /* FDISK_DISKLABEL_* */
- struct fdisk_parttype *parttypes;
+ struct fdisk_parttype *parttypes; /* supported partitions types */
size_t nparttypes; /* number of items in parttypes[] */
- const struct fdisk_label_operations *op;
+ size_t nparts_max; /* maximal number of partitions */
+ size_t nparts_cur; /* number of currently used partitions */
+ const struct fdisk_label_operations *op;
};
/* label allocators */