From: Karel Zak Date: Mon, 3 Dec 2012 15:22:17 +0000 (+0100) Subject: fdisk: move DOS units stuff to fdiskdoslabel.c X-Git-Tag: v2.23-rc1~461 X-Git-Url: http://git.ipfire.org/gitweb/gitweb.cgi?a=commitdiff_plain;h=3c88fb56b6c2862e0d3d4f50149242e58681cb0f;p=thirdparty%2Futil-linux.git fdisk: move DOS units stuff to fdiskdoslabel.c Signed-off-by: Karel Zak --- diff --git a/fdisks/fdisk.c b/fdisks/fdisk.c index 6ceb7620d4..fb2073ab89 100644 --- a/fdisks/fdisk.c +++ b/fdisks/fdisk.c @@ -132,7 +132,6 @@ int nowarn = 0, /* no warnings for fdisk -l/-s */ partitions = 4; /* maximum partition + 1 */ unsigned int user_cylinders, user_heads, user_sectors; -unsigned int units_per_sector = 1, display_in_cyl_units = 0; static void __attribute__ ((__noreturn__)) usage(FILE *out) { @@ -374,16 +373,6 @@ int warn_geometry(struct fdisk_context *cxt) return 1; } -void update_units(struct fdisk_context *cxt) -{ - int cyl_units = cxt->geom.heads * cxt->geom.sectors; - - if (display_in_cyl_units && cyl_units) - units_per_sector = cyl_units; - else - units_per_sector = 1; /* in sectors */ -} - void warn_limits(struct fdisk_context *cxt) { if (cxt->total_sectors > UINT_MAX && !nowarn) { @@ -403,29 +392,6 @@ void warn_limits(struct fdisk_context *cxt) } } -void warn_alignment(struct fdisk_context *cxt) -{ - if (nowarn) - return; - - if (cxt->sector_size != cxt->phy_sector_size) - fprintf(stderr, _("\n" -"The device presents a logical sector size that is smaller than\n" -"the physical sector size. Aligning to a physical sector (or optimal\n" -"I/O) size boundary is recommended, or performance may be impacted.\n")); - - if (dos_compatible_flag) - fprintf(stderr, _("\n" -"WARNING: DOS-compatible mode is deprecated. It's strongly recommended to\n" -" switch off the mode (with command 'c').")); - - if (display_in_cyl_units) - fprintf(stderr, _("\n" -"WARNING: cylinders as display units are deprecated. Use command 'u' to\n" -" change units to sectors.\n")); - -} - static int is_partition_table_changed(void) { int i; @@ -741,17 +707,6 @@ str_units(int n) return P_("sector", "sectors", n); } -void change_units(struct fdisk_context *cxt) -{ - display_in_cyl_units = !display_in_cyl_units; - update_units(cxt); - - if (display_in_cyl_units) - printf(_("Changing display/entry units to cylinders (DEPRECATED!)\n")); - else - printf(_("Changing display/entry units to sectors\n")); -} - static void toggle_active(int i) { struct pte *pe = &ptes[i]; @@ -1442,7 +1397,6 @@ expert_command_prompt(struct fdisk_context *cxt) user_heads = read_int(cxt, 1, cxt->geom.heads, 256, 0, _("Number of heads")); fdisk_context_set_user_geometry(cxt, user_cylinders, user_heads, user_sectors); - update_units(cxt); break; case 'i': if (fdisk_is_disklabel(cxt, SUN)) @@ -1472,7 +1426,6 @@ expert_command_prompt(struct fdisk_context *cxt) "sector offset for DOS " "compatibility\n")); fdisk_context_set_user_geometry(cxt, user_cylinders, user_heads, user_sectors); - update_units(cxt); break; case 'v': verify(cxt); @@ -1522,6 +1475,7 @@ static void print_partition_table_from_option(char *device, unsigned long sector /* * Try BSD -- TODO: move to list_table() too */ + update_units(cxt); list_disk_geometry(cxt); if (!fdisk_is_disklabel(cxt, AIX) && !fdisk_is_disklabel(cxt, MAC)) @@ -1825,6 +1779,7 @@ int main(int argc, char **argv) cxt->sector_size, DEFAULT_SECTOR_SIZE); if (!fdisk_dev_has_disklabel(cxt)) { + update_units(cxt); /* to provide compatible 'p'rint output */ fprintf(stderr, _("Device does not contain a recognized partition table\n")); fdisk_create_disklabel(cxt, NULL); diff --git a/fdisks/fdisk.h b/fdisks/fdisk.h index 4433eaef96..15cae812b3 100644 --- a/fdisks/fdisk.h +++ b/fdisks/fdisk.h @@ -256,7 +256,6 @@ extern void check_consistency(struct fdisk_context *cxt, struct partition *p, in extern void check_alignment(struct fdisk_context *cxt, sector_t lba, int partition); extern void check(struct fdisk_context *cxt, int n, unsigned int h, unsigned int s, unsigned int c, unsigned int start); -extern void change_units(struct fdisk_context *cxt); extern void fatal(struct fdisk_context *cxt, enum failure why); extern int get_partition(struct fdisk_context *cxt, int warn, int max); extern void list_partition_types(struct fdisk_context *cxt); @@ -274,13 +273,11 @@ extern void print_partition_size(struct fdisk_context *cxt, int num, sector_t st extern void fill_bounds(sector_t *first, sector_t *last); extern char *partition_type(struct fdisk_context *cxt, unsigned char type); -extern void update_units(struct fdisk_context *cxt); extern char read_chars(char *mesg); extern void set_changed(int); extern void set_all_unchanged(void); extern int warn_geometry(struct fdisk_context *cxt); extern void warn_limits(struct fdisk_context *cxt); -extern void warn_alignment(struct fdisk_context *cxt); extern unsigned int read_int_with_suffix(struct fdisk_context *cxt, unsigned int low, unsigned int dflt, unsigned int high, unsigned int base, char *mesg, int *is_suffix_used); @@ -293,6 +290,7 @@ extern const char * str_units(int); extern sector_t get_nr_sects(struct partition *p); +extern int nowarn; extern int MBRbuffer_changed; /* start_sect and nr_sects are stored little endian on all machines */ diff --git a/fdisks/fdiskbsdlabel.c b/fdisks/fdiskbsdlabel.c index 54c0327c4e..c3b76a3377 100644 --- a/fdisks/fdiskbsdlabel.c +++ b/fdisks/fdiskbsdlabel.c @@ -60,6 +60,7 @@ #define NETBSD_PARTITION 0xa9 #define DKTYPENAMES #include "fdiskbsdlabel.h" +#include "fdiskdoslabel.h" static int xbsd_delete_part (struct fdisk_context *cxt, int partnum); static void xbsd_edit_disklabel (void); diff --git a/fdisks/fdiskdoslabel.c b/fdisks/fdiskdoslabel.c index b310acf895..897bc0e1bf 100644 --- a/fdisks/fdiskdoslabel.c +++ b/fdisks/fdiskdoslabel.c @@ -32,6 +32,53 @@ struct pte ptes[MAXIMUM_PARTS]; sector_t extended_offset; int ext_index; +unsigned int units_per_sector = 1, display_in_cyl_units = 0; + +void update_units(struct fdisk_context *cxt) +{ + int cyl_units = cxt->geom.heads * cxt->geom.sectors; + + if (display_in_cyl_units && cyl_units) + units_per_sector = cyl_units; + else + units_per_sector = 1; /* in sectors */ +} + +void change_units(struct fdisk_context *cxt) +{ + display_in_cyl_units = !display_in_cyl_units; + update_units(cxt); + + if (display_in_cyl_units) + printf(_("Changing display/entry units to cylinders (DEPRECATED!)\n")); + else + printf(_("Changing display/entry units to sectors\n")); +} + + +static void warn_alignment(struct fdisk_context *cxt) +{ + if (nowarn) + return; + + if (cxt->sector_size != cxt->phy_sector_size) + fprintf(stderr, _("\n" +"The device presents a logical sector size that is smaller than\n" +"the physical sector size. Aligning to a physical sector (or optimal\n" +"I/O) size boundary is recommended, or performance may be impacted.\n")); + + if (dos_compatible_flag) + fprintf(stderr, _("\n" +"WARNING: DOS-compatible mode is deprecated. It's strongly recommended to\n" +" switch off the mode (with command 'c').")); + + if (display_in_cyl_units) + fprintf(stderr, _("\n" +"WARNING: cylinders as display units are deprecated. Use command 'u' to\n" +" change units to sectors.\n")); + +} + static int get_nonexisting_partition(struct fdisk_context *cxt, int warn, int max) { int pno = -1; diff --git a/fdisks/fdiskdoslabel.h b/fdisks/fdiskdoslabel.h index 60190ed5b5..0e377d3aed 100644 --- a/fdisks/fdiskdoslabel.h +++ b/fdisks/fdiskdoslabel.h @@ -43,4 +43,7 @@ extern void dos_init(struct fdisk_context *cxt); extern int mbr_is_valid_magic(unsigned char *b); +extern void change_units(struct fdisk_context *cxt); +extern void update_units(struct fdisk_context *cxt); /* called from sunlabel too */ + #endif diff --git a/fdisks/fdisksunlabel.c b/fdisks/fdisksunlabel.c index 5bb141d3b0..cb22ffcec1 100644 --- a/fdisks/fdisksunlabel.c +++ b/fdisks/fdisksunlabel.c @@ -24,6 +24,7 @@ #include "common.h" #include "fdisk.h" #include "fdisksunlabel.h" +#include "fdiskdoslabel.h" static int other_endian = 0; @@ -140,7 +141,6 @@ static int sun_probe_label(struct fdisk_context *cxt) set_changed(0); } } - update_units(cxt); return 1; } @@ -676,6 +676,14 @@ static int sun_set_parttype(struct fdisk_context *cxt, int i, return 0; } + +static int sun_reset_alignment(struct fdisk_context *cxt) +{ + /* this is shared with DOS ... */ + update_units(cxt); + return 0; +} + const struct fdisk_label sun_label = { .name = "sun", @@ -690,5 +698,5 @@ const struct fdisk_label sun_label = .part_delete = sun_delete_partition, .part_get_type = sun_get_parttype, .part_set_type = sun_set_parttype, - + .reset_alignment = sun_reset_alignment, }; diff --git a/fdisks/utils.c b/fdisks/utils.c index 8acd19a41e..d1ea819594 100644 --- a/fdisks/utils.c +++ b/fdisks/utils.c @@ -134,7 +134,6 @@ static int __probe_labels(struct fdisk_context *cxt) size_t i; cxt->disklabel = FDISK_DISKLABEL_ANY; - update_units(cxt); for (i = 0; i < ARRAY_SIZE(labels); i++) { if (!labels[i]->probe || labels[i]->probe(cxt) != 1)