]> git.ipfire.org Git - thirdparty/util-linux.git/blame - include/partx.h
libblkid: check status for the current CDROM slot
[thirdparty/util-linux.git] / include / partx.h
CommitLineData
c4ecaf21
DB
1#ifndef UTIL_LINUX_PARTX_H
2#define UTIL_LINUX_PARTX_H
3
4#include <sys/ioctl.h>
5#include <linux/blkpg.h>
e163adb8 6#include <stdint.h>
c4ecaf21 7
8863a802
KZ
8#ifndef BLKPG_ADD_PARTITION
9# define BLKPG_ADD_PARTITION 1
10#endif
11
12#ifndef BLKPG_DEL_PARTITION
13# define BLKPG_DEL_PARTITION 2
14#endif
15
16#ifndef BLKPG_RESIZE_PARTITION
17# define BLKPG_RESIZE_PARTITION 3 /* since Linux 3.6 */
18#endif
19
24b7db7e
KZ
20
21#define INIT_BLKPG_PARTITION(_partno, _start, _size) { \
22 .pno = (_partno), \
23 .start = (_start) << 9, \
24 .length = (_size) << 9, \
25 .devname[0] = 0, \
26 .volname[0] = 0 \
27}
28
29#define INIT_BLKPG_ARG(_action, _part) { \
30 .op = (_action), \
31 .flags = 0, \
32 .datalen = sizeof(*(_part)), \
33 .data = (_part) \
34}
35
36
659e5f5b 37static inline int partx_del_partition(int fd, unsigned int partno)
c4ecaf21 38{
24b7db7e
KZ
39 struct blkpg_partition p = INIT_BLKPG_PARTITION(partno, 0, 0);
40 struct blkpg_ioctl_arg a = INIT_BLKPG_ARG(BLKPG_DEL_PARTITION, &p);
c4ecaf21
DB
41
42 return ioctl(fd, BLKPG, &a);
43}
22853e4a 44
c4ecaf21 45static inline int partx_add_partition(int fd, int partno,
659e5f5b 46 uint64_t start, uint64_t size)
c4ecaf21 47{
24b7db7e
KZ
48 struct blkpg_partition p = INIT_BLKPG_PARTITION(partno, start, size);
49 struct blkpg_ioctl_arg a = INIT_BLKPG_ARG(BLKPG_ADD_PARTITION, &p);
c4ecaf21
DB
50
51 return ioctl(fd, BLKPG, &a);
22853e4a 52}
1d4ad1de 53
8863a802
KZ
54static inline int partx_resize_partition(int fd, int partno,
55 uint64_t start, uint64_t size)
56{
24b7db7e
KZ
57 struct blkpg_partition p = INIT_BLKPG_PARTITION(partno, start, size);
58 struct blkpg_ioctl_arg a = INIT_BLKPG_ARG(BLKPG_RESIZE_PARTITION, &p);
8863a802
KZ
59
60 return ioctl(fd, BLKPG, &a);
61}
62
c4ecaf21 63#endif /* UTIL_LINUX_PARTX_H */