cdown / rpms / util-linux

Forked from rpms/util-linux 2 years ago
Clone

Blame SOURCES/2.25-wipefs-call-BLKRRPART-when-erase-partition-table.patch

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