From: Mike Frysinger Date: Sat, 14 Jul 2007 17:32:37 +0000 (-0400) Subject: fdisk: check returns in fdisk from partition changes X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=cc2ce9454a150fc21fa2e73723b13f7dc287325a;p=util-linux fdisk: check returns in fdisk from partition changes currently the code in fdisk which changes partition types is a bit fragile ... it assumes the partition type succeeded instead of checking the user input or for errors. ive tweaked the sub functions to return a value indicative of the functions' success and fdisk now checks/reports based on that. Signed-off-by: Mike Frysinger --- diff --git a/fdisk/fdisk.c b/fdisk/fdisk.c index 5010d7db..f2faa7fb 100644 --- a/fdisk/fdisk.c +++ b/fdisk/fdisk.c @@ -1499,17 +1499,21 @@ change_sysid(void) { if (sys == origsys) break; if (sun_label) { - sun_change_sysid(i, sys); + ptes[i].changed = sun_change_sysid(i, sys); } else if (sgi_label) { - sgi_change_sysid(i, sys); - } else + ptes[i].changed = sgi_change_sysid(i, sys); + } else { p->sys_ind = sys; - printf (_("Changed system type of partition %d " - "to %x (%s)\n"), i + 1, sys, - (temp = partition_type(sys)) ? temp : - _("Unknown")); - ptes[i].changed = 1; + ptes[i].changed = 1; + } + temp = partition_type(sys) ? : _("Unknown"); + if (ptes[i].changed) + printf (_("Changed system type of partition %d " + "to %x (%s)\n"), i + 1, sys, temp); + else + printf (_("System type of partition %d is unchanged" + "to %x (%s)\n"), i + 1, sys, temp); if (is_dos_partition(origsys) || is_dos_partition(sys)) dos_changed = 1; diff --git a/fdisk/fdisksgilabel.c b/fdisk/fdisksgilabel.c index e1b3829c..7e189fb3 100644 --- a/fdisk/fdisksgilabel.c +++ b/fdisk/fdisksgilabel.c @@ -537,12 +537,12 @@ verify_sgi(int verbose) return (gap > 0) ? 1 : (gap == 0) ? 0 : -1; } -void +int sgi_change_sysid(int i, int sys) { if (sgi_get_num_sectors(i) == 0) /* caught already before, ... */ { printf(_("Sorry You may change the Tag of non-empty partitions.\n")); - return; + return 0; } if (((sys != ENTIRE_DISK) && (sys != SGI_VOLHDR)) && (sgi_get_start_sector(i)<1)) { @@ -553,9 +553,10 @@ sgi_change_sysid(int i, int sys) "Only the \"SGI volume\" entire disk section may violate this.\n" "Type YES if you are sure about tagging this partition differently.\n")); if (strcmp (line_ptr, _("YES\n"))) - return; + return 0; } sgilabel->partitions[i].id = SSWAP32(sys); + return 1; } /* returns partition index of first entry marked as entire disk */ diff --git a/fdisk/fdisksgilabel.h b/fdisk/fdisksgilabel.h index fe757bf1..02b3e9d5 100644 --- a/fdisk/fdisksgilabel.h +++ b/fdisk/fdisksgilabel.h @@ -112,7 +112,7 @@ extern struct systypes sgi_sys_types[]; extern void sgi_nolabel( void ); extern int check_sgi_label( void ); extern void sgi_list_table( int xtra ); -extern void sgi_change_sysid( int i, int sys ); +extern int sgi_change_sysid( int i, int sys ); extern unsigned int sgi_get_start_sector( int i ); extern unsigned int sgi_get_num_sectors( int i ); extern int sgi_get_sysid( int i ); diff --git a/fdisk/fdisksunlabel.c b/fdisk/fdisksunlabel.c index f67aa261..60ade06d 100644 --- a/fdisk/fdisksunlabel.c +++ b/fdisk/fdisksunlabel.c @@ -530,7 +530,7 @@ void sun_delete_partition(int i) part->num_sectors = 0; } -void sun_change_sysid(int i, __u16 sys) +int sun_change_sysid(int i, __u16 sys) { struct sun_partition *part = &sunlabel->partitions[i]; struct sun_tag_flag *tag = &sunlabel->part_tags[i]; @@ -543,7 +543,7 @@ void sun_change_sysid(int i, __u16 sys) "Type YES if you're very sure you would like that partition\n" "tagged with 82 (Linux swap): ")); if (strcmp (line_ptr, _("YES\n"))) - return; + return 0; } switch (sys) { case SUN_TAG_SWAP: @@ -558,6 +558,7 @@ void sun_change_sysid(int i, __u16 sys) break; } tag->tag = SSWAP16(sys); + return 1; } void sun_list_table(int xtra) diff --git a/fdisk/fdisksunlabel.h b/fdisk/fdisksunlabel.h index c8e06980..fba67f72 100644 --- a/fdisk/fdisksunlabel.h +++ b/fdisk/fdisksunlabel.h @@ -82,7 +82,7 @@ extern int check_sun_label(void); extern void sun_nolabel(void); extern void create_sunlabel(void); extern void sun_delete_partition(int i); -extern void sun_change_sysid(int i, __u16 sys); +extern int sun_change_sysid(int i, __u16 sys); extern void sun_list_table(int xtra); extern void verify_sun(void); extern void add_sun_partition(int n, int sys);