From: Karel Zak Date: Tue, 11 Jun 2013 10:03:12 +0000 (+0200) Subject: fdisk: (dos) use ask API to change disk ID X-Git-Tag: v2.24-rc1~197 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=0a49e5d581f30c00b7898e26ec14fe0e8b177da7;p=thirdparty%2Futil-linux.git fdisk: (dos) use ask API to change disk ID Signed-off-by: Karel Zak --- diff --git a/fdisks/fdiskdoslabel.c b/fdisks/fdiskdoslabel.c index 44dc40e12b..a63d649bf2 100644 --- a/fdisks/fdiskdoslabel.c +++ b/fdisks/fdiskdoslabel.c @@ -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, diff --git a/fdisks/fdiskdoslabel.h b/fdisks/fdiskdoslabel.h index 1a11442863..02185bddec 100644 --- a/fdisks/fdiskdoslabel.h +++ b/fdisks/fdiskdoslabel.h @@ -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);