summaryrefslogtreecommitdiffstats
path: root/fdisks/gpt.c
diff options
context:
space:
mode:
authorKarel Zak2012-12-11 12:56:27 +0100
committerKarel Zak2013-03-11 12:47:29 +0100
commit0c5d095e46306ed4d6009f56e0339857d733d72e (patch)
treeea751328b6a158c199c7595faf3200a8039dd176 /fdisks/gpt.c
parentlibfdisk: cleanup the rest of fdisks/utils.c stuff (diff)
downloadkernel-qcow2-util-linux-0c5d095e46306ed4d6009f56e0339857d733d72e.tar.gz
kernel-qcow2-util-linux-0c5d095e46306ed4d6009f56e0339857d733d72e.tar.xz
kernel-qcow2-util-linux-0c5d095e46306ed4d6009f56e0339857d733d72e.zip
libfdisk: split label and label operations
Changes: - fdisk_label is a private label driver struct - generic header of the fdisk_label points to fdisk_label_operations - the private fdisk_label stuff is always allocated for all drivers during fdisk_context initialization - context->labels[] contains pointers to all supported labels (drivers) - context->label is a pointer to the currently used label This change allows to: - store label specific global settings (e.g. dos compatible mode, display units, ...) independently on the current label - add label specific function to the API Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'fdisks/gpt.c')
-rw-r--r--fdisks/gpt.c54
1 files changed, 41 insertions, 13 deletions
diff --git a/fdisks/gpt.c b/fdisks/gpt.c
index 0784d639a..4f70f962d 100644
--- a/fdisks/gpt.c
+++ b/fdisks/gpt.c
@@ -45,6 +45,14 @@
#include "strutils.h"
#include "all-io.h"
+/*
+ * in-memory fdisk GPT stuff
+ */
+struct fdisk_gpt_label {
+ struct fdisk_label head; /* generic part */
+};
+
+
#define GPT_HEADER_SIGNATURE 0x5452415020494645LL /* EFI PART */
#define GPT_HEADER_REVISION_V1_02 0x00010200
#define GPT_HEADER_REVISION_V1_00 0x00010000
@@ -1655,18 +1663,38 @@ static int gpt_set_partition_type(struct fdisk_context *cxt, int i,
return 0;
}
-const struct fdisk_label gpt_label =
+static const struct fdisk_label_operations gpt_operations =
{
- .name = "gpt",
- .parttypes = gpt_parttypes,
- .nparttypes = ARRAY_SIZE(gpt_parttypes),
-
- .probe = gpt_probe_label,
- .write = gpt_write_disklabel,
- .verify = gpt_verify_disklabel,
- .create = gpt_create_disklabel,
- .part_add = gpt_add_partition,
- .part_delete = gpt_delete_partition,
- .part_get_type = gpt_get_partition_type,
- .part_set_type = gpt_set_partition_type
+ .probe = gpt_probe_label,
+ .write = gpt_write_disklabel,
+ .verify = gpt_verify_disklabel,
+ .create = gpt_create_disklabel,
+ .part_add = gpt_add_partition,
+ .part_delete = gpt_delete_partition,
+ .part_get_type = gpt_get_partition_type,
+ .part_set_type = gpt_set_partition_type
};
+
+/*
+ * allocates GPT in-memory stuff
+ */
+struct fdisk_label *fdisk_new_gpt_label(struct fdisk_context *cxt)
+{
+ struct fdisk_label *lb;
+ struct fdisk_gpt_label *gpt;
+
+ assert(cxt);
+
+ gpt = calloc(1, sizeof(*gpt));
+ if (!gpt)
+ return NULL;
+
+ /* initialize generic part of the driver */
+ lb = (struct fdisk_label *) gpt;
+ lb->name = "gpt";
+ lb->op = &gpt_operations;
+ lb->parttypes = gpt_parttypes;
+ lb->nparttypes = ARRAY_SIZE(gpt_parttypes);
+
+ return lb;
+}