]>
git.ipfire.org Git - thirdparty/util-linux.git/blob - include/partx.h
2 * No copyright is claimed. This code is in the public domain; do with
5 #ifndef UTIL_LINUX_PARTX_H
6 #define UTIL_LINUX_PARTX_H
9 #include <linux/blkpg.h>
12 #ifndef BLKPG_ADD_PARTITION
13 # define BLKPG_ADD_PARTITION 1
16 #ifndef BLKPG_DEL_PARTITION
17 # define BLKPG_DEL_PARTITION 2
20 #ifndef BLKPG_RESIZE_PARTITION
21 # define BLKPG_RESIZE_PARTITION 3 /* since Linux 3.6 */
25 #define INIT_BLKPG_PARTITION(_partno, _start, _size) { \
27 .start = (_start) << 9, \
28 .length = (_size) << 9, \
33 #define INIT_BLKPG_ARG(_action, _part) { \
36 .datalen = sizeof(*(_part)), \
41 static inline int partx_del_partition(int fd
, unsigned int partno
)
43 struct blkpg_partition p
= INIT_BLKPG_PARTITION(partno
, 0, 0);
44 struct blkpg_ioctl_arg a
= INIT_BLKPG_ARG(BLKPG_DEL_PARTITION
, &p
);
46 return ioctl(fd
, BLKPG
, &a
);
49 static inline int partx_add_partition(int fd
, int partno
,
50 uint64_t start
, uint64_t size
)
52 struct blkpg_partition p
= INIT_BLKPG_PARTITION(partno
, start
, size
);
53 struct blkpg_ioctl_arg a
= INIT_BLKPG_ARG(BLKPG_ADD_PARTITION
, &p
);
55 return ioctl(fd
, BLKPG
, &a
);
58 static inline int partx_resize_partition(int fd
, int partno
,
59 uint64_t start
, uint64_t size
)
61 struct blkpg_partition p
= INIT_BLKPG_PARTITION(partno
, start
, size
);
62 struct blkpg_ioctl_arg a
= INIT_BLKPG_ARG(BLKPG_RESIZE_PARTITION
, &p
);
64 return ioctl(fd
, BLKPG
, &a
);
67 #endif /* UTIL_LINUX_PARTX_H */