[PATCH 1/1] sfdisk: returns non-zero on failed BLKRRPART ioctl

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxx>
---
 fdisk/sfdisk.c |   25 +++++++++++++++++--------
 1 files changed, 17 insertions(+), 8 deletions(-)

diff --git a/fdisk/sfdisk.c b/fdisk/sfdisk.c
index b81e7ca..c38128a 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"
-- 
1.7.0.4

--
To unsubscribe from this list: send the line "unsubscribe util-linux" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux