mschorm / rpms / util-linux

Forked from rpms/util-linux 2 years ago
Clone
4bd7206
--- util-linux-2.13-pre6/disk-utils/blockdev.c.rmparts	2006-02-08 14:10:48.000000000 -0500
4bd7206
+++ util-linux-2.13-pre6/disk-utils/blockdev.c	2006-02-08 14:19:31.000000000 -0500
4bd7206
@@ -29,6 +29,28 @@
4bd7206
 #define BLKGETSIZE64 _IOR(0x12,114,size_t)
4bd7206
 #endif
4bd7206
 
4bd7206
+#ifndef BLKPG
4bd7206
+#define BLKPG _IO(0x12,105)
4bd7206
+#define BLKPG_DEL_PARTITION 2
4bd7206
+#define BLKPG_DEVNAMELTH 64
4bd7206
+#define BLKPG_VOLNAMELTH 64
4bd7206
+
4bd7206
+struct blkpg_partition {
4bd7206
+	long long start;
4bd7206
+	long long length;
4bd7206
+	long long pno;
4bd7206
+	char devname[BLKPG_DEVNAMELTH];
4bd7206
+	char volname[BLKPG_VOLNAMELTH];
4bd7206
+};
4bd7206
+
4bd7206
+struct blkpg_ioctl_arg {
4bd7206
+	int op;
4bd7206
+	int flags;
4bd7206
+	int datalen;
4bd7206
+	void *data;
4bd7206
+};
4bd7206
+#endif
4bd7206
+
4bd7206
 /* Maybe <linux/hdreg.h> could be included */
4bd7206
 #ifndef HDIO_GETGEO
4bd7206
 #define HDIO_GETGEO 0x0301
4bd7206
@@ -93,6 +115,10 @@
4bd7206
 	{ "--rereadpt", "BLKRRPART", BLKRRPART, ARGNONE, 0, NULL,
4bd7206
 	  N_("reread partition table") },
4bd7206
 #endif
4bd7206
+#ifdef BLKPG
4bd7206
+	{ "--rmpart", "BLKPG", BLKPG, ARGINTAP, 0, "PARTNO", N_("disable partition") },
4bd7206
+	{ "--rmparts", "BLKPG", BLKPG, ARGNONE, 0, NULL, N_("disable all partitions") },
4bd7206
+#endif
4bd7206
 };
4bd7206
 
4bd7206
 #define SIZE(a)	(sizeof(a)/sizeof((a)[0]))
4bd7206
@@ -144,6 +170,35 @@
4bd7206
 	return 0;
4bd7206
 }
4bd7206
 
4bd7206
+#ifdef BLKPG
4bd7206
+static int
4bd7206
+disable_partition(int fd, int partno) {
4bd7206
+	struct blkpg_partition part = {
4bd7206
+		.pno = partno,
4bd7206
+	};
4bd7206
+	struct blkpg_ioctl_arg io = {
4bd7206
+		.op = BLKPG_DEL_PARTITION,
4bd7206
+		.datalen = sizeof(part),
4bd7206
+		.data = &part,
4bd7206
+	};
4bd7206
+	int res;
4bd7206
+
4bd7206
+	res = ioctl(fd, BLKPG, &io);
4bd7206
+	if (res < 0)
4bd7206
+		return 0;
4bd7206
+	return 1;
4bd7206
+}
4bd7206
+
4bd7206
+static int
4bd7206
+disable_partitions(int fd) {
4bd7206
+	int p, res = 0;
4bd7206
+
4bd7206
+	for (p = 1; p <= 256; p++)
4bd7206
+		res += disable_partition(fd, p);
4bd7206
+	return res ? 0 : -1;
4bd7206
+}
4bd7206
+#endif
4bd7206
+
4bd7206
 void do_commands(int fd, char **argv, int d);
4bd7206
 void report_header(void);
4bd7206
 void report_device(char *device, int quiet);
4bd7206
@@ -259,6 +314,12 @@
4bd7206
 		switch(bdcms[j].argtype) {
4bd7206
 		default:
4bd7206
 		case ARGNONE:
4bd7206
+#ifdef BLKPG
4bd7206
+			if (bdcms[j].ioc == BLKPG) {
4bd7206
+				res = disable_partitions(fd);
4bd7206
+				break;
4bd7206
+			}
4bd7206
+#endif
4bd7206
 			res = ioctl(fd, bdcms[j].ioc, 0);
4bd7206
 			break;
4bd7206
 		case ARGINTA:
4bd7206
@@ -276,6 +337,13 @@
4bd7206
 					bdcms[j].name);
4bd7206
 				usage();
4bd7206
 			}
4bd7206
+#ifdef BLKPG
4bd7206
+			if (bdcms[j].ioc == BLKPG) {
4bd7206
+				iarg = atoi(argv[++i]);
4bd7206
+				res = disable_partition(fd, iarg) ? 0 : -1;
4bd7206
+				break;
4bd7206
+			}
4bd7206
+#endif
4bd7206
 			iarg = atoi(argv[++i]);
4bd7206
 			res = ioctl(fd, bdcms[j].ioc, &iarg);
4bd7206
 			break;