summaryrefslogtreecommitdiffstats
path: root/fdisks/gpt.c
diff options
context:
space:
mode:
authorKarel Zak2013-01-18 11:43:56 +0100
committerKarel Zak2013-03-11 12:47:29 +0100
commit9fcd49d5517dffa1b98d29faff5090e88e9a68f0 (patch)
treee6446a89c309a8784ecb396ebafe7cda4ff200ad /fdisks/gpt.c
parentfdisk: (gpt) remove global variables, cleanup header verification (diff)
downloadkernel-qcow2-util-linux-9fcd49d5517dffa1b98d29faff5090e88e9a68f0.tar.gz
kernel-qcow2-util-linux-9fcd49d5517dffa1b98d29faff5090e88e9a68f0.tar.xz
kernel-qcow2-util-linux-9fcd49d5517dffa1b98d29faff5090e88e9a68f0.zip
libfdisk: (gpt) introduce driver independent partitions counters
label->nparts_{max,cur} to later replace global variable partitions Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'fdisks/gpt.c')
-rw-r--r--fdisks/gpt.c33
1 files changed, 15 insertions, 18 deletions
diff --git a/fdisks/gpt.c b/fdisks/gpt.c
index 566e7ffa1..ba7d257d2 100644
--- a/fdisks/gpt.c
+++ b/fdisks/gpt.c
@@ -1024,17 +1024,6 @@ done:
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;
@@ -1069,7 +1058,10 @@ static int gpt_probe_label(struct fdisk_context *cxt, struct fdisk_label *lb)
/* 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"));
@@ -1428,8 +1420,8 @@ static int gpt_verify_disklabel(struct fdisk_context *cxt, struct fdisk_label *l
/* 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;
@@ -1446,6 +1438,7 @@ static int gpt_delete_partition(struct fdisk_context *cxt,
else {
gpt_recompute_crc(gpt->pheader, gpt->ents);
gpt_recompute_crc(gpt->bheader, gpt->ents);
+ lb->nparts_cur--;
}
return 0;
@@ -1610,8 +1603,10 @@ static int gpt_add_partition(
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;
}
@@ -1619,8 +1614,7 @@ static int gpt_add_partition(
/*
* 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;
@@ -1661,7 +1655,10 @@ static int gpt_create_disklabel(struct fdisk_context *cxt,
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 "