]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
fdisk: (dos) use ask API to change disk ID
authorKarel Zak <kzak@redhat.com>
Tue, 11 Jun 2013 10:03:12 +0000 (12:03 +0200)
committerKarel Zak <kzak@redhat.com>
Mon, 16 Sep 2013 14:47:00 +0000 (16:47 +0200)
Signed-off-by: Karel Zak <kzak@redhat.com>
fdisks/fdiskdoslabel.c
fdisks/fdiskdoslabel.h

index 44dc40e12b7577f53624d041929d641d4ea6f06f..a63d649bf278c210ee0376db6327c96bc270ed00 100644 (file)
@@ -358,26 +358,32 @@ static int dos_create_disklabel(struct fdisk_context *cxt)
        return 0;
 }
 
-void dos_set_mbr_id(struct fdisk_context *cxt)
+int dos_set_mbr_id(struct fdisk_context *cxt)
 {
-       unsigned long new_id;
-       char *ep;
-       char ps[64];
+       char *end = NULL, *str = NULL;
+       unsigned int id, old;
+       int rc;
 
-       snprintf(ps, sizeof ps, _("New disk identifier (current 0x%08x): "),
-                mbr_get_id(cxt->firstsector));
+       old = mbr_get_id(cxt->firstsector);
+       rc = fdisk_ask_string(cxt,
+                       _("Enter of the new disk identifier"), &str);
+       if (rc)
+               return rc;
 
-       if (read_chars(cxt, ps) == '\n')
-               return;
+       errno = 0;
+       id = strtoul(str, &end, 0);
+       if (errno || str == end || (end && *end)) {
+               fdisk_warnx(cxt, _("Incorrect value."));
+               return -EINVAL;
+       }
 
-       new_id = strtoul(line_ptr, &ep, 0);
-       if (*ep != '\n')
-               return;
+       fdisk_info(cxt, _("Changing disk identifier from 0x%08x to 0x%08x."),
+                       old, id);
 
-       mbr_set_id(cxt->firstsector, new_id);
+       mbr_set_id(cxt->firstsector, id);
        MBRbuffer_changed = 1;
        fdisk_label_set_changed(cxt->label, 1);
-       dos_print_mbr_id(cxt);
+       return 0;
 }
 
 static void get_partition_table_geometry(struct fdisk_context *cxt,
index 1a1144286327d2011201465f548f8206cc8105c2..02185bddec1cf7dc282db566ea06c3038f4db7b6 100644 (file)
@@ -43,7 +43,7 @@ static inline int is_cleared_partition(struct partition *p)
 }
 
 extern void dos_print_mbr_id(struct fdisk_context *cxt);
-extern void dos_set_mbr_id(struct fdisk_context *cxt);
+extern int 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);