diff -up util-linux-ng-2.13/disk-utils/blockdev.c.kzak util-linux-ng-2.13/disk-utils/blockdev.c --- util-linux-ng-2.13/disk-utils/blockdev.c.kzak 2007-09-04 15:43:33.000000000 +0200 +++ util-linux-ng-2.13/disk-utils/blockdev.c 2007-10-31 11:14:32.000000000 +0100 @@ -10,6 +10,7 @@ #include #include #include +#include #include "nls.h" @@ -32,6 +33,14 @@ #define BLKGETSIZE64 _IOR(0x12,114,size_t) #endif +#ifndef BLKPG +#define BLKPG _IO(0x12,105) +#define BLKPG_DEL_PARTITION 2 +#define BLKPG_DEVNAMELTH 64 +#define BLKPG_VOLNAMELTH 64 + +#endif + /* Maybe could be included */ #ifndef HDIO_GETGEO #define HDIO_GETGEO 0x0301 @@ -104,6 +113,10 @@ struct bdc { { "--rereadpt", "BLKRRPART", BLKRRPART, ARGNONE, 0, NULL, N_("reread partition table") }, #endif +#ifdef BLKPG + { "--rmpart", "BLKPG", BLKPG, ARGINTAP, 0, "PARTNO", N_("disable partition") }, + { "--rmparts", "BLKPG", BLKPG, ARGNONE, 0, NULL, N_("disable all partitions") }, +#endif }; #define SIZE(a) (sizeof(a)/sizeof((a)[0])) @@ -163,6 +176,40 @@ getsize(int fd, long long *sectors) { return 0; } +#ifdef BLKPG +static int +disable_partition(int fd, int partno) { + struct blkpg_partition part = { + .pno = partno, + .start = 0, + .length = 0, + .devname[0] = 0, + .volname[0] = 0, + }; + struct blkpg_ioctl_arg io = { + .op = BLKPG_DEL_PARTITION, + .datalen = sizeof(part), + .data = &part, + .flags = 0, + }; + int res; + + res = ioctl(fd, BLKPG, &io); + if (res < 0) + return 0; + return 1; +} + +static int +disable_partitions(int fd) { + int p, res = 0; + + for (p = 1; p <= 256; p++) + res += disable_partition(fd, p); + return res ? 0 : -1; +} +#endif + void do_commands(int fd, char **argv, int d); void report_header(void); void report_device(char *device, int quiet); @@ -280,6 +327,12 @@ do_commands(int fd, char **argv, int d) switch(bdcms[j].argtype) { default: case ARGNONE: +#ifdef BLKPG + if (bdcms[j].ioc == BLKPG) { + res = disable_partitions(fd); + break; + } +#endif res = ioctl(fd, bdcms[j].ioc, 0); break; case ARGINTA: @@ -297,6 +350,13 @@ do_commands(int fd, char **argv, int d) bdcms[j].name); usage(); } +#ifdef BLKPG + if (bdcms[j].ioc == BLKPG) { + iarg = atoi(argv[++i]); + res = disable_partition(fd, iarg) ? 0 : -1; + break; + } +#endif iarg = atoi(argv[++i]); res = ioctl(fd, bdcms[j].ioc, &iarg); break;