--- util-linux-ng-2.13/disk-utils/blockdev.c.fix12 2007-11-12 02:23:51 +0300 +++ util-linux-ng-2.13/disk-utils/blockdev.c 2007-11-12 02:30:31 +0300 @@ -48,8 +48,12 @@ struct bdc { { "--getfra", "BLKFRAGET", BLKFRAGET, ARGLINTG, -1, NULL, N_("get filesystem readahead") }, { "--flushbufs", "BLKFLSBUF", BLKFLSBUF, ARGNONE, 0, NULL, N_("flush buffers") }, { "--rereadpt", "BLKRRPART", BLKRRPART, ARGNONE, 0, NULL, N_("reread partition table") }, +#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])) @@ -88,8 +92,37 @@ find_cmd(char *s) { return j; return -1; } +#ifdef BLKPG +static int +disable_partition(int fd, int partno) { + struct blkpg_partition part = { + .pno = partno, + }; + struct blkpg_ioctl_arg io = { + .op = BLKPG_DEL_PARTITION, + .datalen = sizeof(part), + .data = &part, + }; + 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); void report_all_devices(void); @@ -205,8 +238,14 @@ 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: if (i == d-1) { @@ -222,8 +261,15 @@ do_commands(int fd, char **argv, int d) fprintf(stderr, _("%s requires an argument\n"), 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; case ARGINTP: