/src/util-linux/include/partx.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * No copyright is claimed. This code is in the public domain; do with |
3 | | * it what you wish. |
4 | | */ |
5 | | #ifndef UTIL_LINUX_PARTX_H |
6 | | #define UTIL_LINUX_PARTX_H |
7 | | |
8 | | #include <sys/ioctl.h> |
9 | | #include <linux/blkpg.h> |
10 | | #include <stdint.h> |
11 | | |
12 | | #ifndef BLKPG_ADD_PARTITION |
13 | | # define BLKPG_ADD_PARTITION 1 |
14 | | #endif |
15 | | |
16 | | #ifndef BLKPG_DEL_PARTITION |
17 | | # define BLKPG_DEL_PARTITION 2 |
18 | | #endif |
19 | | |
20 | | #ifndef BLKPG_RESIZE_PARTITION |
21 | | # define BLKPG_RESIZE_PARTITION 3 /* since Linux 3.6 */ |
22 | | #endif |
23 | | |
24 | | |
25 | 0 | #define INIT_BLKPG_PARTITION(_partno, _start, _size) { \ |
26 | 0 | .pno = (_partno), \ |
27 | 0 | .start = (_start) << 9, \ |
28 | 0 | .length = (_size) << 9, \ |
29 | 0 | .devname[0] = 0, \ |
30 | 0 | .volname[0] = 0 \ |
31 | 0 | } |
32 | | |
33 | 0 | #define INIT_BLKPG_ARG(_action, _part) { \ |
34 | 0 | .op = (_action), \ |
35 | 0 | .flags = 0, \ |
36 | 0 | .datalen = sizeof(*(_part)), \ |
37 | 0 | .data = (_part) \ |
38 | 0 | } |
39 | | |
40 | | |
41 | | static inline int partx_del_partition(int fd, unsigned int partno) |
42 | 0 | { |
43 | 0 | struct blkpg_partition p = INIT_BLKPG_PARTITION(partno, 0, 0); |
44 | 0 | struct blkpg_ioctl_arg a = INIT_BLKPG_ARG(BLKPG_DEL_PARTITION, &p); |
45 | |
|
46 | 0 | return ioctl(fd, BLKPG, &a); |
47 | 0 | } |
48 | | |
49 | | static inline int partx_add_partition(int fd, int partno, |
50 | | uint64_t start, uint64_t size) |
51 | 0 | { |
52 | 0 | struct blkpg_partition p = INIT_BLKPG_PARTITION(partno, start, size); |
53 | 0 | struct blkpg_ioctl_arg a = INIT_BLKPG_ARG(BLKPG_ADD_PARTITION, &p); |
54 | |
|
55 | 0 | return ioctl(fd, BLKPG, &a); |
56 | 0 | } |
57 | | |
58 | | static inline int partx_resize_partition(int fd, int partno, |
59 | | uint64_t start, uint64_t size) |
60 | 0 | { |
61 | 0 | struct blkpg_partition p = INIT_BLKPG_PARTITION(partno, start, size); |
62 | 0 | struct blkpg_ioctl_arg a = INIT_BLKPG_ARG(BLKPG_RESIZE_PARTITION, &p); |
63 | |
|
64 | 0 | return ioctl(fd, BLKPG, &a); |
65 | 0 | } |
66 | | |
67 | | #endif /* UTIL_LINUX_PARTX_H */ |