]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
fdisk: get rid of get_boot(create_empty_sun) call
authorFrancesco Cosoleto <cosoleto@gmail.com>
Thu, 15 Dec 2011 19:02:43 +0000 (20:02 +0100)
committerKarel Zak <kzak@redhat.com>
Fri, 16 Dec 2011 13:04:04 +0000 (14:04 +0100)
create_sunlabel() should create a new empty SUN disklabel without checking data
itself writes to memory and initialize internal related fdisk variables.

Signed-off-by: Francesco Cosoleto <cosoleto@gmail.com>
fdisk/fdisk.c
fdisk/fdisk.h
fdisk/fdisksunlabel.c

index ab2e68d49b7254a8d14189a844a3e73c4db3d9af..aacd73f590e20c9483b5fe08c9ddadcaa6188e37 100644 (file)
@@ -51,6 +51,7 @@
 
 #include "gpt.h"
 
+static int get_boot(enum action what);
 static void delete_partition(int i);
 
 #define hex_val(c)     ({ \
@@ -1090,7 +1091,7 @@ void zeroize_mbr_buffer(void)
  *    0: found or created label
  *    1: I/O error
  */
-int
+static int
 get_boot(enum action what) {
        int i;
 
@@ -1108,9 +1109,6 @@ get_boot(enum action what) {
                pe->changed = (what == create_empty_dos);
        }
 
-       if (what == create_empty_sun && check_sun_label())
-               return 0;
-
        memset(MBRbuffer, 0, 512);
 
        if (what == create_empty_dos)
@@ -1175,7 +1173,6 @@ got_dos_table:
                case try_only:
                        return -1;
                case create_empty_dos:
-               case create_empty_sun:
                        break;
                default:
                        fprintf(stderr, _("Internal error\n"));
index 67642cd21ec4797152fff5f406a068a8cf0066be..66418806f42692547b18d6ae8681bc5f9098ca1d 100644 (file)
@@ -54,7 +54,7 @@ enum failure {ioctl_error,
        unable_to_open, unable_to_read, unable_to_seek,
        unable_to_write};
 
-enum action {fdisk, try_only, create_empty_dos, create_empty_sun};
+enum action {fdisk, try_only, create_empty_dos};
 
 struct geom {
        unsigned int heads;
@@ -69,7 +69,6 @@ extern unsigned int display_in_cyl_units, units_per_sector;
 extern void change_units(void);
 extern void fatal(enum failure why);
 extern void get_geometry(int fd, struct geom *);
-extern int get_boot(enum action what);
 extern int  get_partition(int warn, int max);
 extern void list_types(struct systypes *sys);
 extern int read_line (int *asked);
index 80408dd10d9caa4a72172a234d4c4f4ff9aa2930..4fd8545c3002c93a6c94525728c1ecbc046624bd 100644 (file)
@@ -109,6 +109,12 @@ static void set_sun_partition(int i, uint32_t start, uint32_t stop, uint16_t sys
        print_partition_size(i + 1, start, stop, sysid);
 }
 
+static void init(void)
+{
+       disklabel = SUN_LABEL;
+       partitions = SUN_NUM_PARTITIONS;
+}
+
 void sun_nolabel(void)
 {
        sunlabel->magic = 0;
@@ -125,6 +131,8 @@ int check_sun_label(void)
                other_endian = 0;
                return 0;
        }
+
+       init();
        other_endian = (sunlabel->magic == SUN_LABEL_MAGIC_SWAPPED);
 
        ush = ((unsigned short *) (sunlabel + 1)) - 1;
@@ -176,8 +184,6 @@ int check_sun_label(void)
                }
        }
        update_units();
-       disklabel = SUN_LABEL;
-       partitions = SUN_NUM_PARTITIONS;
        return 1;
 }
 
@@ -195,7 +201,10 @@ void create_sunlabel(void)
 #else
        other_endian = 0;
 #endif
+
+       init();
        zeroize_mbr_buffer();
+
        sunlabel->magic = SSWAP16(SUN_LABEL_MAGIC);
        sunlabel->sanity = SSWAP32(SUN_LABEL_SANE);
        sunlabel->version = SSWAP32(SUN_LABEL_VERSION);
@@ -249,9 +258,6 @@ void create_sunlabel(void)
        } else
                ndiv = cylinders * 2 / 3;
 
-       /* Make sure print_partition_size() uses correct sysid names */
-       disklabel = SUN_LABEL;
-
        set_sun_partition(0, 0, ndiv * heads * sectors,
                          SUN_TAG_LINUX_NATIVE);
        set_sun_partition(1, ndiv * heads * sectors,
@@ -270,7 +276,6 @@ void create_sunlabel(void)
        }
 
        set_all_unchanged();
-       get_boot(create_empty_sun);
        set_changed(0);
 }