]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
fdisk: get_boot() has to die (step I.)
authorKarel Zak <kzak@redhat.com>
Mon, 23 Jul 2012 08:56:06 +0000 (10:56 +0200)
committerKarel Zak <kzak@redhat.com>
Mon, 23 Jul 2012 08:56:06 +0000 (10:56 +0200)
 - move generic stuff around "create disklabel" operation to API

Signed-off-by: Karel Zak <kzak@redhat.com>
fdisks/fdisk.c
fdisks/fdisk.h
fdisks/fdiskdoslabel.c
fdisks/fdiskdoslabel.h
fdisks/fdisksunlabel.c
fdisks/fdisksunlabel.h
fdisks/utils.c

index a7787c6a2aa0c19f8e9e566c8d2f516d85e54434..e24dd3bf45df9210b9e1c766eb304f9ccab85f9d 100644 (file)
@@ -523,14 +523,6 @@ static int get_boot(struct fdisk_context *cxt, int try_only) {
        if (disklabel == ANY_LABEL) {
                if (try_only)
                        return -1;
-
-               fprintf(stderr,
-                       _("Device does not contain a recognized partition table\n"));
-#ifdef __sparc__
-               create_sunlabel(cxt);
-#else
-               create_doslabel(cxt);
-#endif
        }
        return 0;
 }
@@ -2072,7 +2064,12 @@ int main(int argc, char **argv)
                       cxt->sector_size, DEFAULT_SECTOR_SIZE);
 
        gpt_warning(cxt->dev_path);
-       get_boot(cxt, 0);
+
+       if (!fdisk_dev_has_disklabel(cxt)) {
+               fprintf(stderr,
+                       _("Device does not contain a recognized partition table\n"));
+               fdisk_create_default_disklabel(cxt);
+       }
 
        command_prompt(cxt);
 
index 9eead15f2ec1deaff2f6fcc0785cf4afaee23834..3783f827329faec44d798974bf0c3459d09b4165 100644 (file)
@@ -146,6 +146,7 @@ extern const struct fdisk_label sgi_label;
 
 extern struct fdisk_context *fdisk_new_context_from_filename(const char *fname, int readonly);
 extern int fdisk_dev_has_topology(struct fdisk_context *cxt);
+extern int fdisk_dev_has_disklabel(struct fdisk_context *cxt);
 extern int fdisk_dev_sectsz_is_default(struct fdisk_context *cxt);
 extern void fdisk_free_context(struct fdisk_context *cxt);
 extern void fdisk_mbr_zeroize(struct fdisk_context *cxt);
@@ -153,6 +154,7 @@ extern int fdisk_context_force_sector_size(struct fdisk_context *cxt, sector_t s
 extern int fdisk_context_set_user_geometry(struct fdisk_context *cxt,
                            unsigned int cylinders, unsigned int heads,
                            unsigned int sectors);
+extern int fdisk_create_default_disklabel(struct fdisk_context *cxt);
 
 /* prototypes for fdisk.c */
 extern char *disk_device, *line_ptr;
index a115e66157a21741485da7c5fbb7435e206fe193..b181fb3530dd0aba4d2303f979aea255e6970115 100644 (file)
@@ -219,7 +219,7 @@ void dos_print_mbr_id(struct fdisk_context *cxt)
        printf(_("Disk identifier: 0x%08x\n"), dos_read_mbr_id(cxt->mbr));
 }
 
-void create_doslabel(struct fdisk_context *cxt)
+int create_doslabel(struct fdisk_context *cxt)
 {
        unsigned int id;
 
@@ -238,6 +238,7 @@ void create_doslabel(struct fdisk_context *cxt)
 
        /* Put MBR signature */
        write_part_table_flag(cxt->mbr);
+       return 0;
 }
 
 void dos_set_mbr_id(struct fdisk_context *cxt)
index 608e3f700373037dbb67b1369cb703990aa8b7ef..a8fab5289461821158af040ee04e0b0a85dd62ce 100644 (file)
@@ -43,7 +43,7 @@ static inline sector_t get_partition_start(struct pte *pe)
        return pe->offset + get_start_sect(pe->part_table);
 }
 
-extern void create_doslabel(struct fdisk_context *cxt);
+extern int create_doslabel(struct fdisk_context *cxt);
 extern void dos_print_mbr_id(struct fdisk_context *cxt);
 extern void dos_set_mbr_id(struct fdisk_context *cxt);
 extern void dos_delete_partition(int i);
index 909f159e4c539af29844d13836a0d42450c5a155..6a0c31b15a0b8b31b92b27c4bea093c0a2a0171d 100644 (file)
@@ -144,7 +144,7 @@ static int sun_probe_label(struct fdisk_context *cxt)
        return 1;
 }
 
-void create_sunlabel(struct fdisk_context *cxt)
+int create_sunlabel(struct fdisk_context *cxt)
 {
        struct hd_geometry geometry;
        sector_t llsectors, llcyls;
@@ -234,6 +234,8 @@ void create_sunlabel(struct fdisk_context *cxt)
 
        set_all_unchanged();
        set_changed(0);
+
+       return 0;
 }
 
 void toggle_sunflags(struct fdisk_context *cxt, int i, uint16_t mask)
index 9779e22f3392a14d38883b86b2c867a0f735c0b0..fa12a1d2a78ce17004cdff4762d6de378b165bd9 100644 (file)
@@ -77,7 +77,7 @@ struct sun_disk_label {
 
 /* fdisksunlabel.c */
 extern struct systypes sun_sys_types[];
-extern void create_sunlabel(struct fdisk_context *cxt);
+extern int create_sunlabel(struct fdisk_context *cxt);
 extern void sun_delete_partition(struct fdisk_context *cxt, int i);
 extern int sun_change_sysid(struct fdisk_context *cxt, int i, uint16_t sys);
 extern void sun_list_table(struct fdisk_context *cxt, int xtra);
index f1a9f3da1b84c9f3d8237a0604aa10efa72eb33c..07348d3803099baff596c6a2760a39ea3b02e55c 100644 (file)
@@ -29,6 +29,9 @@
 #include "common.h"
 #include "fdisk.h"
 
+#include "fdiskdoslabel.h"
+#include "fdisksunlabel.h"
+
 int fdisk_debug_mask;
 
 /*
@@ -274,6 +277,38 @@ int fdisk_dev_has_topology(struct fdisk_context *cxt)
        return 0;
 }
 
+/**
+ * fdisk_dev_has_disklabel:
+ * @cxt: fdisk context
+ *
+ * Returns: return 1 if there is label on the device.
+ */
+int fdisk_dev_has_disklabel(struct fdisk_context *cxt)
+{
+       return cxt && disklabel != ANY_LABEL;
+}
+
+/**
+ * fdisk_create_default_disklabel:
+ * @cxt: fdisk context
+ *
+ * Creates (in memory) disk label which is usual default for the system. For
+ * example sun label on sparcs, gpt on UEFI machines (TODO), DOS on another
+ * machines, ...etc.
+ *
+ * Returns: 0 on sucess, < 0 on error.
+ */
+int fdisk_create_default_disklabel(struct fdisk_context *cxt)
+{
+       if (!cxt)
+               return -EINVAL;
+#ifdef __sparc__
+       return create_sunlabel(cxt);
+#else
+       return create_doslabel(cxt);
+#endif
+}
+
 /**
  * fdisk_init_debug:
  * @mask: debug mask (0xffff to enable full debuging)