Skip to content

Instantly share code, notes, and snippets.

@tai
Created August 29, 2018 13:17
Show Gist options
  • Select an option

  • Save tai/8e814ce736807c19add2c1cb26c34d92 to your computer and use it in GitHub Desktop.

Select an option

Save tai/8e814ce736807c19add2c1cb26c34d92 to your computer and use it in GitHub Desktop.
/*BINFMTC: -Wall
*/
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <strings.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <linux/fs.h>
#include <linux/blkpg.h>
int main(int argc, char **argv) {
if (argc != 2) {
fprintf(stderr, "Usage: %s /dev/someblk\n", argv[0]);
return 0;
}
char *dev = argv[1];
int fd = open(dev, O_RDWR);
ioctl(fd, BLKFLSBUF);
struct blkpg_ioctl_arg arg;
struct blkpg_partition pinfo = {0};
for (int pno = 1; pno < 100; pno++) {
pinfo.pno = pno;
sprintf(pinfo.devname, "%sp%d", rindex(dev, '/') + 1, pno);
arg.op = BLKPG_DEL_PARTITION;
arg.flags = 0;
arg.datalen = sizeof(pinfo);
arg.data = &pinfo;
ioctl(fd, BLKPG, &arg);
}
close(fd);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment