summaryrefslogtreecommitdiffstats
path: root/fdisk/sfdisk.c
diff options
context:
space:
mode:
authorAndrea Galbusera2011-05-03 15:47:38 +0200
committerKarel Zak2011-05-06 13:03:43 +0200
commite82810c6cf3fe94d2cf70d485a59c411ccb601b3 (patch)
tree44fcfb1daa719b929092fbcbc7f64833605b3201 /fdisk/sfdisk.c
parentlibblkid: ignore hfsplus superblocks with blocksize < 512 (diff)
downloadkernel-qcow2-util-linux-e82810c6cf3fe94d2cf70d485a59c411ccb601b3.tar.gz
kernel-qcow2-util-linux-e82810c6cf3fe94d2cf70d485a59c411ccb601b3.tar.xz
kernel-qcow2-util-linux-e82810c6cf3fe94d2cf70d485a59c411ccb601b3.zip
sfdisk: returns non-zero on failed BLKRRPART ioctl
Make sfdisk(8) return non-zero value on failed BLKRRPART ioctl(). This will happen for either partition table re-reads after partition changes or on explicit use of -R switch. The function reread_disk_partition() was changed from 'void' to 'int' and now returns a result to let the calling functions decide to exit(1). Signed-off-by: Andrea Galbusera <gizero@gmail.com>
Diffstat (limited to 'fdisk/sfdisk.c')
-rw-r--r--fdisk/sfdisk.c25
1 files changed, 17 insertions, 8 deletions
diff --git a/fdisk/sfdisk.c b/fdisk/sfdisk.c
index b81e7ca9f..c38128a84 100644
--- a/fdisk/sfdisk.c
+++ b/fdisk/sfdisk.c
@@ -322,7 +322,7 @@ err:
return 0;
}
-static void reread_disk_partition(char *dev, int fd);
+static int reread_disk_partition(char *dev, int fd);
static int
restore_sectors(char *dev) {
@@ -381,7 +381,8 @@ restore_sectors(char *dev) {
}
free(ss0);
- reread_disk_partition(dev, fdout);
+ if (!reread_disk_partition(dev, fdout))
+ goto err;
close(fdin);
return 1;
@@ -806,22 +807,27 @@ is_blockdev(int fd) {
}
/* reread after writing */
-static void
+static int
reread_disk_partition(char *dev, int fd) {
printf(_("Re-reading the partition table ...\n"));
fflush(stdout);
sync();
- if (reread_ioctl(fd) && is_blockdev(fd))
+ if (reread_ioctl(fd) && is_blockdev(fd)) {
do_warn(_("The command to re-read the partition table failed.\n"
"Run partprobe(8), kpartx(8) or reboot your system now,\n"
"before using mkfs\n"));
+ return 0;
+ }
if (fsync(fd) || close(fd)) {
- perror(dev);
- do_warn(_("Error closing %s\n"), dev);
+ perror(dev);
+ do_warn(_("Error closing %s\n"), dev);
+ return 0;
}
printf("\n");
+
+ return 1;
}
/* find Linux name of this partition, assuming that it will have a name */
@@ -3006,8 +3012,10 @@ do_reread(char *dev) {
int fd;
fd = my_open(dev, 0, 0);
- if (reread_ioctl(fd))
+ if (reread_ioctl(fd)) {
do_warn(_("This disk is currently in use.\n"));
+ exit(1);
+ }
close(fd);
}
@@ -3106,7 +3114,8 @@ do_fdisk(char *dev){
else
exit_status = 1;
- reread_disk_partition(dev, fd);
+ if (!reread_disk_partition(dev, fd))
+ exit_status = 1;
my_warn(_("If you created or changed a DOS partition, /dev/foo7, say, then use dd(1)\n"
"to zero the first 512 bytes: dd if=/dev/zero of=/dev/foo7 bs=512 count=1\n"