Created
August 29, 2018 13:17
-
-
Save tai/8e814ce736807c19add2c1cb26c34d92 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /*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