]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
fdisk: move DOS units stuff to fdiskdoslabel.c
authorKarel Zak <kzak@redhat.com>
Mon, 3 Dec 2012 15:22:17 +0000 (16:22 +0100)
committerKarel Zak <kzak@redhat.com>
Mon, 3 Dec 2012 15:22:17 +0000 (16:22 +0100)
Signed-off-by: Karel Zak <kzak@redhat.com>
fdisks/fdisk.c
fdisks/fdisk.h
fdisks/fdiskbsdlabel.c
fdisks/fdiskdoslabel.c
fdisks/fdiskdoslabel.h
fdisks/fdisksunlabel.c
fdisks/utils.c

index 6ceb7620d4e0393fe3f52c08d5d195e3b9dd814e..fb2073ab89d5641b05d8ea542b166c1b4199910e 100644 (file)
@@ -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);
index 4433eaef962d4816c221e3ed4573d12f6050d12f..15cae812b3c709c343d2c3d3a87fb6d377d82441 100644 (file)
@@ -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 */
index 54c0327c4ebad1cd0475e11423b4af02930cbb50..c3b76a3377741f96435ce445ee7bc9d8a98ad66b 100644 (file)
@@ -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);
index b310acf895b1312471b0594a02dcd03b67b063e7..897bc0e1bfe2b0a1581f246ddde00cfa121257a2 100644 (file)
@@ -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;
index 60190ed5b5e8f47de89e08def56b0566d05c238b..0e377d3aedbf923ede8be215f3d312c2841a4bea 100644 (file)
@@ -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
index 5bb141d3b070a3b26a5b3f6a4d3dd6cee47a1a41..cb22ffcec153bad2974f379335042ea7650cab65 100644 (file)
@@ -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,
 };
index 8acd19a41e076aba9142ac58d4416c00687f6fef..d1ea819594c8ee70aa7d6ec28b43a0600653de72 100644 (file)
@@ -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)