diff options
author | Karel Zak | 2013-01-22 18:05:18 +0100 |
---|---|---|
committer | Karel Zak | 2013-03-11 13:00:54 +0100 |
commit | 9ffeb235d6d260ad4e61cc892b72f060f820a546 (patch) | |
tree | 4e931ecbc4450c89842cfa7466a760b689c3a574 /fdisks/fdiskbsdlabel.c | |
parent | libfdisk: (gpt) move code from fdisk to libfdisk (diff) | |
download | kernel-qcow2-util-linux-9ffeb235d6d260ad4e61cc892b72f060f820a546.tar.gz kernel-qcow2-util-linux-9ffeb235d6d260ad4e61cc892b72f060f820a546.tar.xz kernel-qcow2-util-linux-9ffeb235d6d260ad4e61cc892b72f060f820a546.zip |
fdisk: remove fdisk_label from API functions, add asserts, use size_t
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'fdisks/fdiskbsdlabel.c')
-rw-r--r-- | fdisks/fdiskbsdlabel.c | 108 |
1 files changed, 63 insertions, 45 deletions
diff --git a/fdisks/fdiskbsdlabel.c b/fdisks/fdiskbsdlabel.c index b5d0b64ea..5ef49cddb 100644 --- a/fdisks/fdiskbsdlabel.c +++ b/fdisks/fdiskbsdlabel.c @@ -70,11 +70,10 @@ struct fdisk_bsd_label { }; -static int xbsd_delete_part (struct fdisk_context *cxt, - struct fdisk_label *lb, int partnum); +static int xbsd_delete_part (struct fdisk_context *cxt, size_t partnum); static void xbsd_edit_disklabel (struct fdisk_context *cxt); static void xbsd_write_bootstrap (struct fdisk_context *cxt); -static void xbsd_change_fstype (struct fdisk_context *cxt, struct fdisk_label *lb); +static void xbsd_change_fstype (struct fdisk_context *cxt); static int xbsd_get_part_index (struct fdisk_context *cxt, int max); static int xbsd_check_new_partition (struct fdisk_context *cxt, int *i); static unsigned short xbsd_dkcksum (struct xbsd_disklabel *lp); @@ -116,16 +115,20 @@ static struct xbsd_disklabel xbsd_dlabel; * so this does not mean that there is a BSD disk label. */ static int -osf_probe_label(struct fdisk_context *cxt, - struct fdisk_label *lb __attribute__((__unused__))) +osf_probe_label(struct fdisk_context *cxt) { + assert(cxt); + assert(cxt->label); + assert(fdisk_is_disklabel(cxt, OSF)); + if (xbsd_readlabel (cxt, NULL, &xbsd_dlabel) == 0) return 0; return 1; } int -btrydev (struct fdisk_context *cxt) { +btrydev (struct fdisk_context *cxt) +{ if (xbsd_readlabel (cxt, NULL, &xbsd_dlabel) == 0) return -1; printf(_("\nBSD label for device: %s\n"), cxt->dev_path); @@ -134,13 +137,13 @@ btrydev (struct fdisk_context *cxt) { } #if !defined (__alpha__) -static int -hidden(int type) { +static int hidden(int type) +{ return type ^ 0x10; } -static int -is_bsd_partition_type(int type) { +static int is_bsd_partition_type(int type) +{ return (type == FREEBSD_PARTITION || type == hidden(FREEBSD_PARTITION) || type == NETBSD_PARTITION || @@ -148,8 +151,7 @@ is_bsd_partition_type(int type) { } #endif -static int xbsd_write_disklabel (struct fdisk_context *cxt, - struct fdisk_label *lb __attribute__((__unused__))) +static int xbsd_write_disklabel (struct fdisk_context *cxt) { #if defined (__alpha__) printf (_("Writing disklabel to %s.\n"), cxt->dev_path); @@ -165,14 +167,17 @@ static int xbsd_write_disklabel (struct fdisk_context *cxt, } static int xbsd_add_part (struct fdisk_context *cxt, - struct fdisk_label *lb, - int partnum __attribute__((__unused__)), + size_t partnum __attribute__((__unused__)), struct fdisk_parttype *t __attribute__((__unused__))) { unsigned int begin, end; char mesg[256]; int i, rc; + assert(cxt); + assert(cxt->label); + assert(fdisk_is_disklabel(cxt, OSF)); + rc = xbsd_check_new_partition(cxt, &i); if (rc) return rc; @@ -204,17 +209,20 @@ static int xbsd_add_part (struct fdisk_context *cxt, xbsd_dlabel.d_partitions[i].p_offset = begin; xbsd_dlabel.d_partitions[i].p_fstype = BSD_FS_UNUSED; - lb->nparts_cur = xbsd_dlabel.d_npartitions; - fdisk_label_set_changed(lb, 1); + cxt->label->nparts_cur = xbsd_dlabel.d_npartitions; + fdisk_label_set_changed(cxt->label, 1); return 0; } -static int xbsd_create_disklabel(struct fdisk_context *cxt, - struct fdisk_label *lb) +static int xbsd_create_disklabel(struct fdisk_context *cxt) { char c; + assert(cxt); + assert(cxt->label); + assert(fdisk_is_disklabel(cxt, OSF)); + #if defined (__alpha__) fprintf (stderr, _("%s contains no disklabel.\n"), cxt->dev_path); #else @@ -234,8 +242,8 @@ static int xbsd_create_disklabel(struct fdisk_context *cxt, #endif ) == 1) { xbsd_print_disklabel (cxt, 1); - lb->nparts_cur = xbsd_dlabel.d_npartitions; - lb->nparts_max = BSD_MAXPARTITIONS; + cxt->label->nparts_cur = xbsd_dlabel.d_npartitions; + cxt->label->nparts_max = BSD_MAXPARTITIONS; return 1; } else return 0; @@ -265,7 +273,7 @@ bsd_command_prompt (struct fdisk_context *cxt) printf (_("Reading disklabel of %s at sector %d.\n"), partname(cxt->dev_path, t+1, 0), ss + BSD_LABELSECTOR); if (xbsd_readlabel (cxt, xbsd_part, &xbsd_dlabel) == 0) - if (xbsd_create_disklabel (cxt, cxt->label) == 0) + if (xbsd_create_disklabel (cxt) == 0) return; break; } @@ -288,8 +296,7 @@ bsd_command_prompt (struct fdisk_context *cxt) putchar ('\n'); switch (tolower (read_char(cxt, _("BSD disklabel command (m for help): ")))) { case 'd': - xbsd_delete_part(cxt, cxt->label, - xbsd_get_part_index(cxt, xbsd_dlabel.d_npartitions)); + xbsd_delete_part(cxt, xbsd_get_part_index(cxt, xbsd_dlabel.d_npartitions)); break; case 'e': xbsd_edit_disklabel (cxt); @@ -301,7 +308,7 @@ bsd_command_prompt (struct fdisk_context *cxt) list_partition_types (cxt); break; case 'n': - xbsd_add_part (cxt, cxt->label, 0, 0); + xbsd_add_part (cxt, 0, 0); break; case 'p': xbsd_print_disklabel (cxt, 0); @@ -315,13 +322,13 @@ bsd_command_prompt (struct fdisk_context *cxt) xbsd_print_disklabel (cxt, 1); break; case 't': - xbsd_change_fstype (cxt, cxt->label); + xbsd_change_fstype (cxt); break; case 'u': change_units(cxt); break; case 'w': - xbsd_write_disklabel (cxt, cxt->label); + xbsd_write_disklabel (cxt); break; #if !defined (__alpha__) case 'x': @@ -336,10 +343,13 @@ bsd_command_prompt (struct fdisk_context *cxt) } static int xbsd_delete_part( - struct fdisk_context *cxt __attribute__((__unused__)), - struct fdisk_label *lb, - int partnum) + struct fdisk_context *cxt, + size_t partnum) { + assert(cxt); + assert(cxt->label); + assert(fdisk_is_disklabel(cxt, OSF)); + xbsd_dlabel.d_partitions[partnum].p_size = 0; xbsd_dlabel.d_partitions[partnum].p_offset = 0; xbsd_dlabel.d_partitions[partnum].p_fstype = BSD_FS_UNUSED; @@ -347,13 +357,14 @@ static int xbsd_delete_part( while (!xbsd_dlabel.d_partitions[xbsd_dlabel.d_npartitions-1].p_size) xbsd_dlabel.d_npartitions--; - lb->nparts_cur = xbsd_dlabel.d_npartitions; - fdisk_label_set_changed(lb, 1); + cxt->label->nparts_cur = xbsd_dlabel.d_npartitions; + fdisk_label_set_changed(cxt->label, 1); return 0; } void -xbsd_print_disklabel (struct fdisk_context *cxt, int show_all) { +xbsd_print_disklabel (struct fdisk_context *cxt, int show_all) +{ struct xbsd_disklabel *lp = &xbsd_dlabel; struct xbsd_partition *pp; FILE *f = stdout; @@ -589,21 +600,22 @@ xbsd_write_bootstrap (struct fdisk_context *cxt) } /* TODO: remove this, use regular change_partition_type() in fdisk.c */ -static void -xbsd_change_fstype ( - struct fdisk_context *cxt, - struct fdisk_label *lb) +static void xbsd_change_fstype (struct fdisk_context *cxt) { int i; struct fdisk_parttype *t; + assert(cxt); + assert(cxt->label); + assert(fdisk_is_disklabel(cxt, OSF)); + i = xbsd_get_part_index (cxt, xbsd_dlabel.d_npartitions); t = read_partition_type(cxt); if (t) { xbsd_dlabel.d_partitions[i].p_fstype = t->type; fdisk_free_parttype(t); - fdisk_label_set_changed(lb, 1); + fdisk_label_set_changed(cxt->label, 1); } } @@ -621,8 +633,8 @@ xbsd_get_part_index(struct fdisk_context *cxt, int max) } static int -xbsd_check_new_partition(struct fdisk_context *cxt, int *i) { - +xbsd_check_new_partition(struct fdisk_context *cxt, int *i) +{ /* room for more? various BSD flavours have different maxima */ if (xbsd_dlabel.d_npartitions == BSD_MAXPARTITIONS) { int t; @@ -886,11 +898,14 @@ alpha_bootblock_checksum (char *boot) static struct fdisk_parttype *xbsd_get_parttype( struct fdisk_context *cxt, - struct fdisk_label *lb __attribute__((__unused__)), - int n) + size_t n) { struct fdisk_parttype *t; + assert(cxt); + assert(cxt->label); + assert(fdisk_is_disklabel(cxt, OSF)); + if (n >= xbsd_dlabel.d_npartitions) return NULL; @@ -901,13 +916,16 @@ static struct fdisk_parttype *xbsd_get_parttype( } static int xbsd_set_parttype( - struct fdisk_context *cxt __attribute__((__unused__)), - struct fdisk_label *lb, - int partnum, + struct fdisk_context *cxt, + size_t partnum, struct fdisk_parttype *t) { struct xbsd_partition *p; + assert(cxt); + assert(cxt->label); + assert(fdisk_is_disklabel(cxt, OSF)); + if (partnum >= xbsd_dlabel.d_npartitions || !t || t->type > UINT8_MAX) return -EINVAL; @@ -916,7 +934,7 @@ static int xbsd_set_parttype( return 0; p->p_fstype = t->type; - fdisk_label_set_changed(lb, 1); + fdisk_label_set_changed(cxt->label, 1); return 0; } |