diff options
author | Karel Zak | 2012-12-11 12:56:27 +0100 |
---|---|---|
committer | Karel Zak | 2013-03-11 12:47:29 +0100 |
commit | 0c5d095e46306ed4d6009f56e0339857d733d72e (patch) | |
tree | ea751328b6a158c199c7595faf3200a8039dd176 /fdisks/fdiskbsdlabel.c | |
parent | libfdisk: cleanup the rest of fdisks/utils.c stuff (diff) | |
download | kernel-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/fdiskbsdlabel.c')
-rw-r--r-- | fdisks/fdiskbsdlabel.c | 54 |
1 files changed, 41 insertions, 13 deletions
diff --git a/fdisks/fdiskbsdlabel.c b/fdisks/fdiskbsdlabel.c index c3b76a337..ef2047a0a 100644 --- a/fdisks/fdiskbsdlabel.c +++ b/fdisks/fdiskbsdlabel.c @@ -62,6 +62,14 @@ #include "fdiskbsdlabel.h" #include "fdiskdoslabel.h" +/* + * in-memory fdisk BSD stuff + */ +struct fdisk_bsd_label { + struct fdisk_label head; /* generic part */ +}; + + static int xbsd_delete_part (struct fdisk_context *cxt, int partnum); static void xbsd_edit_disklabel (void); static void xbsd_write_bootstrap (struct fdisk_context *cxt); @@ -879,18 +887,38 @@ static int xbsd_set_parttype(struct fdisk_context *cxt, int partnum, return 0; } -const struct fdisk_label bsd_label = +static const struct fdisk_label_operations bsd_operations = { - .name = "bsd", - .parttypes = xbsd_fstypes, - .nparttypes = ARRAY_SIZE(xbsd_fstypes), - - .probe = osf_probe_label, - .write = xbsd_write_disklabel, - .verify = NULL, - .create = xbsd_create_disklabel, - .part_add = xbsd_add_part, - .part_delete = xbsd_delete_part, - .part_get_type = xbsd_get_parttype, - .part_set_type = xbsd_set_parttype, + .probe = osf_probe_label, + .write = xbsd_write_disklabel, + .create = xbsd_create_disklabel, + .part_add = xbsd_add_part, + .part_delete = xbsd_delete_part, + .part_get_type = xbsd_get_parttype, + .part_set_type = xbsd_set_parttype }; + + +/* + * allocates BSD label driver + */ +struct fdisk_label *fdisk_new_bsd_label(struct fdisk_context *cxt) +{ + struct fdisk_label *lb; + struct fdisk_bsd_label *bsd; + + assert(cxt); + + bsd = calloc(1, sizeof(*bsd)); + if (!bsd) + return NULL; + + /* initialize generic part of the driver */ + lb = (struct fdisk_label *) bsd; + lb->name = "bsd"; + lb->op = &bsd_operations; + lb->parttypes = xbsd_fstypes; + lb->nparttypes = ARRAY_SIZE(xbsd_fstypes); + + return lb; +} |