]> git.ipfire.org Git - thirdparty/util-linux.git/blob - disk-utils/partx.h
build-sys: move partx to disk-utils/
[thirdparty/util-linux.git] / disk-utils / partx.h
1 #ifndef UTIL_LINUX_PARTX_H
2 #define UTIL_LINUX_PARTX_H
3
4 #include <sys/ioctl.h>
5 #include <linux/blkpg.h>
6
7 static inline int partx_del_partition(int fd, unsigned int partno)
8 {
9 struct blkpg_ioctl_arg a;
10 struct blkpg_partition p;
11
12 p.pno = partno;
13 p.start = 0;
14 p.length = 0;
15 p.devname[0] = 0;
16 p.volname[0] = 0;
17 a.op = BLKPG_DEL_PARTITION;
18 a.flags = 0;
19 a.datalen = sizeof(p);
20 a.data = &p;
21
22 return ioctl(fd, BLKPG, &a);
23 }
24
25 static inline int partx_add_partition(int fd, int partno,
26 uint64_t start, uint64_t size)
27 {
28 struct blkpg_ioctl_arg a;
29 struct blkpg_partition p;
30
31 p.pno = partno;
32 p.start = start << 9;
33 p.length = size << 9;
34 p.devname[0] = 0;
35 p.volname[0] = 0;
36 a.op = BLKPG_ADD_PARTITION;
37 a.flags = 0;
38 a.datalen = sizeof(p);
39 a.data = &p;
40
41 return ioctl(fd, BLKPG, &a);
42 }
43
44 #endif /* UTIL_LINUX_PARTX_H */