Upload Tizen:Base source
[framework/base/util-linux-ng.git] / partx / delpart.c
1 /* very primitive wrapper around the `delete partition' ioctl */
2 #include <stdio.h>
3 #include <fcntl.h>
4 #include <stdlib.h>
5 #include <sys/ioctl.h>
6 #ifdef HAVE_LINUX_COMPILER_H
7 #include <linux/compiler.h>
8 #endif
9 #include <linux/blkpg.h>
10
11 int
12 main(int argc, char **argv){
13         int fd;
14         struct blkpg_ioctl_arg a;
15         struct blkpg_partition p;
16
17         if (argc != 3) {
18                 fprintf(stderr,
19                         "usage: %s diskdevice partitionnr\n",
20                         argv[0]);
21                 exit(1);
22         }
23         if ((fd = open(argv[1], O_RDONLY)) < 0) {
24                 perror(argv[1]);
25                 exit(1);
26         }
27         p.pno = atoi(argv[2]);
28         p.start = 0;
29         p.length = 0;
30         p.devname[0] = 0;
31         p.volname[0] = 0;
32         a.op = BLKPG_DEL_PARTITION;
33         a.flags = 0;
34         a.datalen = sizeof(p);
35         a.data = &p;
36
37         if (ioctl(fd, BLKPG, &a) == -1) {
38                 perror("BLKPG");
39                 exit(1);
40         }
41             
42         return 0;
43 }