]> git.ipfire.org Git - thirdparty/util-linux.git/blob - include/partx.h
include: add DragonFlyBSD GPT partition types
[thirdparty/util-linux.git] / include / partx.h
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 #define INIT_BLKPG_PARTITION(_partno, _start, _size) { \
26 .pno = (_partno), \
27 .start = (_start) << 9, \
28 .length = (_size) << 9, \
29 .devname[0] = 0, \
30 .volname[0] = 0 \
31 }
32
33 #define INIT_BLKPG_ARG(_action, _part) { \
34 .op = (_action), \
35 .flags = 0, \
36 .datalen = sizeof(*(_part)), \
37 .data = (_part) \
38 }
39
40
41 static inline int partx_del_partition(int fd, unsigned int partno)
42 {
43 struct blkpg_partition p = INIT_BLKPG_PARTITION(partno, 0, 0);
44 struct blkpg_ioctl_arg a = INIT_BLKPG_ARG(BLKPG_DEL_PARTITION, &p);
45
46 return ioctl(fd, BLKPG, &a);
47 }
48
49 static inline int partx_add_partition(int fd, int partno,
50 uint64_t start, uint64_t size)
51 {
52 struct blkpg_partition p = INIT_BLKPG_PARTITION(partno, start, size);
53 struct blkpg_ioctl_arg a = INIT_BLKPG_ARG(BLKPG_ADD_PARTITION, &p);
54
55 return ioctl(fd, BLKPG, &a);
56 }
57
58 static inline int partx_resize_partition(int fd, int partno,
59 uint64_t start, uint64_t size)
60 {
61 struct blkpg_partition p = INIT_BLKPG_PARTITION(partno, start, size);
62 struct blkpg_ioctl_arg a = INIT_BLKPG_ARG(BLKPG_RESIZE_PARTITION, &p);
63
64 return ioctl(fd, BLKPG, &a);
65 }
66
67 #endif /* UTIL_LINUX_PARTX_H */