summaryrefslogtreecommitdiffstats
path: root/fdisk
diff options
context:
space:
mode:
authorMike Frysinger2007-07-14 19:32:37 +0200
committerKarel Zak2007-07-16 23:03:45 +0200
commitcc2ce9454a150fc21fa2e73723b13f7dc287325a (patch)
tree0ca7b24d1261c151ced4e7c1d47a0bb7cc5b3147 /fdisk
parentschedutils: fix chrt docs and pid=0 usage (diff)
downloadkernel-qcow2-util-linux-cc2ce9454a150fc21fa2e73723b13f7dc287325a.tar.gz
kernel-qcow2-util-linux-cc2ce9454a150fc21fa2e73723b13f7dc287325a.tar.xz
kernel-qcow2-util-linux-cc2ce9454a150fc21fa2e73723b13f7dc287325a.zip
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 <vapier@gentoo.org>
Diffstat (limited to 'fdisk')
-rw-r--r--fdisk/fdisk.c20
-rw-r--r--fdisk/fdisksgilabel.c7
-rw-r--r--fdisk/fdisksgilabel.h2
-rw-r--r--fdisk/fdisksunlabel.c5
-rw-r--r--fdisk/fdisksunlabel.h2
5 files changed, 21 insertions, 15 deletions
diff --git a/fdisk/fdisk.c b/fdisk/fdisk.c
index 5010d7db3..f2faa7fbc 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 e1b3829cb..7e189fb3f 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 fe757bf1c..02b3e9d55 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 f67aa261a..60ade06d5 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 c8e069804..fba67f725 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);