dcavalca / rpms / util-linux

Forked from rpms/util-linux 2 years ago
Clone
531551
diff -up util-linux-2.23.2/misc-utils/wipefs.8.kzak util-linux-2.23.2/misc-utils/wipefs.8
531551
--- util-linux-2.23.2/misc-utils/wipefs.8.kzak	2013-07-30 10:39:26.232738496 +0200
531551
+++ util-linux-2.23.2/misc-utils/wipefs.8	2014-01-23 11:07:54.390022299 +0100
531551
@@ -23,6 +23,9 @@ does not erase the filesystem itself nor
531551
 When used without options \fB-a\fR or \fB-o\fR, it lists all visible filesystems
531551
 and the offsets of their basic signatures.
531551
 
531551
+.B wipefs
531551
+calls BLKRRPART ioctl when erase partition table to inform kernel about the change.
531551
+
531551
 Note that some filesystems or some partition tables store more magic strings on
531551
 the devices.  The
531551
 .B wipefs
531551
diff -up util-linux-2.23.2/misc-utils/wipefs.c.kzak util-linux-2.23.2/misc-utils/wipefs.c
531551
--- util-linux-2.23.2/misc-utils/wipefs.c.kzak	2013-07-30 10:39:26.232738496 +0200
531551
+++ util-linux-2.23.2/misc-utils/wipefs.c	2014-01-23 11:12:26.786860550 +0100
531551
@@ -40,21 +40,24 @@
531551
 #include "c.h"
531551
 #include "closestream.h"
531551
 #include "optutils.h"
531551
+#include "blkdev.h"
531551
 
531551
 struct wipe_desc {
531551
 	loff_t		offset;		/* magic string offset */
531551
 	size_t		len;		/* length of magic string */
531551
 	unsigned char	*magic;		/* magic string */
531551
 
531551
-	int		zap;		/* zap this offset? */
531551
 	char		*usage;		/* raid, filesystem, ... */
531551
 	char		*type;		/* FS type */
531551
 	char		*label;		/* FS label */
531551
 	char		*uuid;		/* FS uuid */
531551
 
531551
-	int		on_disk;
531551
-
531551
 	struct wipe_desc	*next;
531551
+
531551
+	unsigned int	zap : 1,
531551
+			on_disk : 1,
531551
+			is_parttable : 1;
531551
+
531551
 };
531551
 
531551
 enum {
531551
@@ -72,7 +75,7 @@ print_pretty(struct wipe_desc *wp, int l
531551
 		printf("----------------------------------------------------------------\n");
531551
 	}
531551
 
531551
-	printf("0x%-17jx  %s   [%s]", wp->offset, wp->type, wp->usage);
531551
+	printf("0x%-17jx  %s   [%s]", wp->offset, wp->type, _(wp->usage));
531551
 
531551
 	if (wp->label && *wp->label)
531551
 		printf("\n%27s %s", "LABEL:", wp->label);
531551
@@ -141,7 +144,7 @@ add_offset(struct wipe_desc *wp0, loff_t
531551
 	wp = xcalloc(1, sizeof(struct wipe_desc));
531551
 	wp->offset = offset;
531551
 	wp->next = wp0;
531551
-	wp->zap = zap;
531551
+	wp->zap = zap ? 1 : 0;
531551
 	return wp;
531551
 }
531551
 
531551
@@ -164,7 +167,7 @@ get_desc_for_probe(struct wipe_desc *wp,
531551
 	const char *off, *type, *mag, *p, *usage = NULL;
531551
 	size_t len;
531551
 	loff_t offset;
531551
-	int rc;
531551
+	int rc, ispt = 0;
531551
 
531551
 	/* superblocks */
531551
 	if (blkid_probe_lookup_value(pr, "TYPE", &type, NULL) == 0) {
531551
@@ -181,7 +184,8 @@ get_desc_for_probe(struct wipe_desc *wp,
531551
 			rc = blkid_probe_lookup_value(pr, "PTMAGIC", &mag, &len;;
531551
 		if (rc)
531551
 			return wp;
531551
-		usage = "partition table";
531551
+		usage = N_("partition table");
531551
+		ispt = 1;
531551
 	} else
531551
 		return wp;
531551
 
531551
@@ -199,6 +203,7 @@ get_desc_for_probe(struct wipe_desc *wp,
531551
 
531551
 	wp->type = xstrdup(type);
531551
 	wp->on_disk = 1;
531551
+	wp->is_parttable = ispt ? 1 : 0;
531551
 
531551
 	wp->magic = xmalloc(len);
531551
 	memcpy(wp->magic, mag, len);
531551
@@ -309,10 +314,25 @@ static void do_wipe_real(blkid_probe pr,
531551
 	putchar('\n');
531551
 }
531551
 
531551
+
531551
+static void rereadpt(int fd, const char *devname)
531551
+{
531551
+#ifdef BLKRRPART
531551
+	struct stat st;
531551
+
531551
+	if (fstat(fd, &st) || !S_ISBLK(st.st_mode))
531551
+		return;
531551
+
531551
+	errno = 0;
531551
+	ioctl(fd, BLKRRPART);
531551
+	printf(_("%s: calling ioclt to re-read partition table: %m\n"), devname);
531551
+#endif
531551
+}
531551
+
531551
 static struct wipe_desc *
531551
 do_wipe(struct wipe_desc *wp, const char *devname, int noact, int all, int quiet, int force)
531551
 {
531551
-	int flags;
531551
+	int flags, reread = 0;
531551
 	blkid_probe pr;
531551
 	struct wipe_desc *w, *wp0;
531551
 	int zap = all ? 1 : wp->zap;
531551
@@ -345,8 +365,11 @@ do_wipe(struct wipe_desc *wp, const char
531551
 		if (!wp->on_disk)
531551
 			continue;
531551
 
531551
-		if (zap)
531551
+		if (zap) {
531551
 			do_wipe_real(pr, devname, wp, noact, quiet);
531551
+			if (wp->is_parttable)
531551
+				reread = 1;
531551
+		}
531551
 	}
531551
 
531551
 	for (w = wp0; w != NULL; w = w->next) {
531551
@@ -355,6 +378,10 @@ do_wipe(struct wipe_desc *wp, const char
531551
 	}
531551
 
531551
 	fsync(blkid_probe_get_fd(pr));
531551
+
531551
+	if (reread)
531551
+		rereadpt(blkid_probe_get_fd(pr), devname);
531551
+
531551
 	close(blkid_probe_get_fd(pr));
531551
 	blkid_free_probe(pr);
531551
 	free_wipe(wp0);