diff options
author | Karel Zak | 2013-01-21 12:01:44 +0100 |
---|---|---|
committer | Karel Zak | 2013-03-11 12:47:30 +0100 |
commit | 6d864a495c57d0ac9ebd286b18fbe2937727291e (patch) | |
tree | e3da8c95219641494ff0e0dca586c4e777afcef8 /fdisks | |
parent | fdisk: use libfdisk label->changed (diff) | |
download | kernel-qcow2-util-linux-6d864a495c57d0ac9ebd286b18fbe2937727291e.tar.gz kernel-qcow2-util-linux-6d864a495c57d0ac9ebd286b18fbe2937727291e.tar.xz kernel-qcow2-util-linux-6d864a495c57d0ac9ebd286b18fbe2937727291e.zip |
fdisk: (dos) move list table code to fdiskdoslabe.c
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'fdisks')
-rw-r--r-- | fdisks/fdisk.c | 77 | ||||
-rw-r--r-- | fdisks/fdisk.h | 2 | ||||
-rw-r--r-- | fdisks/fdiskdoslabel.c | 85 | ||||
-rw-r--r-- | fdisks/fdiskdoslabel.h | 2 |
4 files changed, 92 insertions, 74 deletions
diff --git a/fdisks/fdisk.c b/fdisks/fdisk.c index 58b945281..ee4c3ca07 100644 --- a/fdisks/fdisk.c +++ b/fdisks/fdisk.c @@ -176,20 +176,6 @@ get_part_table(int i) { return ptes[i].part_table; } -static int -is_garbage_table(void) { - int i; - - for (i = 0; i < 4; i++) { - struct pte *pe = &ptes[i]; - struct partition *p = pe->part_table; - - if (p->boot_ind != 0 && p->boot_ind != 0x80) - return 1; - } - return 0; -} - void print_menu(struct fdisk_context *cxt, enum menutype menu) { size_t i; @@ -813,7 +799,7 @@ list_disk_geometry(struct fdisk_context *cxt) { * Return 0 if OK. Return i if partition i should have been earlier. * Two separate checks: primary and logical partitions. */ -static int +int wrong_p_order(int *prev) { struct pte *pe; struct partition *p; @@ -945,9 +931,6 @@ fix_partition_table_order(void) { static void list_table(struct fdisk_context *cxt, int xtra) { - struct partition *p; - int i, w; - if (fdisk_is_disklabel(cxt, SUN)) { sun_list_table(cxt, xtra); return; @@ -970,62 +953,8 @@ static void list_table(struct fdisk_context *cxt, int xtra) return; } - if (is_garbage_table()) { - printf(_("This doesn't look like a partition table\n" - "Probably you selected the wrong device.\n\n")); - } - - /* Heuristic: we list partition 3 of /dev/foo as /dev/foo3, - but if the device name ends in a digit, say /dev/foo1, - then the partition is called /dev/foo1p3. */ - w = strlen(cxt->dev_path); - if (w && isdigit(cxt->dev_path[w-1])) - w++; - if (w < 5) - w = 5; - - printf(_("%*s Boot Start End Blocks Id System\n"), - w+1, _("Device")); - - for (i = 0; i < partitions; i++) { - struct pte *pe = &ptes[i]; - - p = pe->part_table; - if (p && !is_cleared_partition(p)) { - unsigned int psects = get_nr_sects(p); - unsigned int pblocks = psects; - unsigned int podd = 0; - struct fdisk_parttype *type = - fdisk_get_parttype_from_code(cxt, p->sys_ind); - - if (cxt->sector_size < 1024) { - pblocks /= (1024 / cxt->sector_size); - podd = psects % (1024 / cxt->sector_size); - } - if (cxt->sector_size > 1024) - pblocks *= (cxt->sector_size / 1024); - printf( - "%s %c %11lu %11lu %11lu%c %2x %s\n", - partname(cxt->dev_path, i+1, w+2), -/* boot flag */ !p->boot_ind ? ' ' : p->boot_ind == ACTIVE_FLAG - ? '*' : '?', -/* start */ (unsigned long) cround(get_partition_start(pe)), -/* end */ (unsigned long) cround(get_partition_start(pe) + psects - - (psects ? 1 : 0)), -/* odd flag on end */ (unsigned long) pblocks, podd ? '+' : ' ', -/* type id */ p->sys_ind, -/* type name */ type ? type->name : _("Unknown")); - check_consistency(cxt, p, i); - fdisk_warn_alignment(cxt, get_partition_start(pe), i); - } - } - - /* Is partition table in disk order? It need not be, but... */ - /* partition table entries are not checked for correct order if this - is a sgi, sun or aix labeled disk... */ - if (fdisk_is_disklabel(cxt, DOS) && wrong_p_order(NULL)) { - printf(_("\nPartition table entries are not in disk order\n")); - } + if (fdisk_is_disklabel(cxt, DOS)) + dos_list_table(cxt, xtra); } static void diff --git a/fdisks/fdisk.h b/fdisks/fdisk.h index ae9d3a127..0217bdfd4 100644 --- a/fdisks/fdisk.h +++ b/fdisks/fdisk.h @@ -93,6 +93,8 @@ extern unsigned int read_int_with_suffix(struct fdisk_context *cxt, unsigned int base, char *mesg, int *is_suffix_used); extern int get_partition_dflt(struct fdisk_context *cxt, int warn, int max, int dflt); +extern int wrong_p_order(int *prev); + #define PLURAL 0 #define SINGULAR 1 extern const char * str_units(int); diff --git a/fdisks/fdiskdoslabel.c b/fdisks/fdiskdoslabel.c index 3a3b71018..da6526e3f 100644 --- a/fdisks/fdiskdoslabel.c +++ b/fdisks/fdiskdoslabel.c @@ -964,6 +964,91 @@ static int dos_set_parttype( return 0; } + +static int is_garbage_table(void) +{ + int i; + + for (i = 0; i < 4; i++) { + struct pte *pe = &ptes[i]; + struct partition *p = pe->part_table; + + if (p->boot_ind != 0 && p->boot_ind != 0x80) + return 1; + } + return 0; +} + +int dos_list_table(struct fdisk_context *cxt, + int xtra __attribute__ ((__unused__))) +{ + struct partition *p; + int i, w; + + assert(cxt); + assert(fdisk_is_disklabel(cxt, DOS)); + + if (is_garbage_table()) { + printf(_("This doesn't look like a partition table\n" + "Probably you selected the wrong device.\n\n")); + } + + /* Heuristic: we list partition 3 of /dev/foo as /dev/foo3, + but if the device name ends in a digit, say /dev/foo1, + then the partition is called /dev/foo1p3. */ + w = strlen(cxt->dev_path); + if (w && isdigit(cxt->dev_path[w-1])) + w++; + if (w < 5) + w = 5; + + printf(_("%*s Boot Start End Blocks Id System\n"), + w+1, _("Device")); + + for (i = 0; i < partitions; i++) { + struct pte *pe = &ptes[i]; + + p = pe->part_table; + if (p && !is_cleared_partition(p)) { + unsigned int psects = get_nr_sects(p); + unsigned int pblocks = psects; + unsigned int podd = 0; + struct fdisk_parttype *type = + fdisk_get_parttype_from_code(cxt, p->sys_ind); + + if (cxt->sector_size < 1024) { + pblocks /= (1024 / cxt->sector_size); + podd = psects % (1024 / cxt->sector_size); + } + if (cxt->sector_size > 1024) + pblocks *= (cxt->sector_size / 1024); + printf( + "%s %c %11lu %11lu %11lu%c %2x %s\n", + partname(cxt->dev_path, i+1, w+2), +/* boot flag */ !p->boot_ind ? ' ' : p->boot_ind == ACTIVE_FLAG + ? '*' : '?', +/* start */ (unsigned long) cround(get_partition_start(pe)), +/* end */ (unsigned long) cround(get_partition_start(pe) + psects + - (psects ? 1 : 0)), +/* odd flag on end */ (unsigned long) pblocks, podd ? '+' : ' ', +/* type id */ p->sys_ind, +/* type name */ type ? type->name : _("Unknown")); + check_consistency(cxt, p, i); + fdisk_warn_alignment(cxt, get_partition_start(pe), i); + } + } + + /* Is partition table in disk order? It need not be, but... */ + /* partition table entries are not checked for correct order if this + is a sgi, sun or aix labeled disk... */ + if (wrong_p_order(NULL)) + printf(_("\nPartition table entries are not in disk order\n")); + + return 0; +} + + + static const struct fdisk_label_operations dos_operations = { .probe = dos_probe_label, diff --git a/fdisks/fdiskdoslabel.h b/fdisks/fdiskdoslabel.h index 41a253bb3..cf20124ca 100644 --- a/fdisks/fdiskdoslabel.h +++ b/fdisks/fdiskdoslabel.h @@ -40,6 +40,8 @@ extern void dos_print_mbr_id(struct fdisk_context *cxt); extern void dos_set_mbr_id(struct fdisk_context *cxt); extern void dos_init(struct fdisk_context *cxt); +extern int dos_list_table(struct fdisk_context *cxt, int xtra); + extern int mbr_is_valid_magic(unsigned char *b); extern void change_units(struct fdisk_context *cxt); |