]>
Commit | Line | Data |
---|---|---|
7eda085c KZ |
1 | /* very primitive wrapper around the `add partition' ioctl */ |
2 | #include <stdio.h> | |
3 | #include <fcntl.h> | |
4 | #include <stdlib.h> | |
5 | #include <sys/ioctl.h> | |
48d7b13a KZ |
6 | #ifdef HAVE_LINUX_COMPILER_H |
7 | #include <linux/compiler.h> | |
8 | #endif | |
7eda085c KZ |
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 != 5) { | |
18 | fprintf(stderr, | |
19 | "usage: %s diskdevice partitionnr start length\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]); | |
b425b18b TF |
28 | p.start = 512 * atoll(argv[3]); |
29 | p.length = 512 * atoll(argv[4]); | |
7eda085c KZ |
30 | p.devname[0] = 0; |
31 | p.volname[0] = 0; | |
32 | a.op = BLKPG_ADD_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 | } |