From 87d04a3339252c023bf9025c38c0ec7d3f5ee817 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Thu, 13 Jul 2017 13:46:52 +0200 Subject: partx: move partx.h to include/ Let's make the ioctls usable also for libfdisk. Signed-off-by: Karel Zak --- include/Makemodule.am | 1 + include/partx.h | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 include/partx.h (limited to 'include') diff --git a/include/Makemodule.am b/include/Makemodule.am index 7ea1a4824..237400b05 100644 --- a/include/Makemodule.am +++ b/include/Makemodule.am @@ -34,6 +34,7 @@ dist_noinst_HEADERS += \ include/optutils.h \ include/pager.h \ include/pamfail.h \ + include/partx.h \ include/path.h \ include/pathnames.h \ include/plymouth-ctrl.h \ diff --git a/include/partx.h b/include/partx.h new file mode 100644 index 000000000..96206bd7c --- /dev/null +++ b/include/partx.h @@ -0,0 +1,62 @@ +#ifndef UTIL_LINUX_PARTX_H +#define UTIL_LINUX_PARTX_H + +#include +#include + +#ifndef BLKPG_ADD_PARTITION +# define BLKPG_ADD_PARTITION 1 +#endif + +#ifndef BLKPG_DEL_PARTITION +# define BLKPG_DEL_PARTITION 2 +#endif + +#ifndef BLKPG_RESIZE_PARTITION +# define BLKPG_RESIZE_PARTITION 3 /* since Linux 3.6 */ +#endif + + +#define INIT_BLKPG_PARTITION(_partno, _start, _size) { \ + .pno = (_partno), \ + .start = (_start) << 9, \ + .length = (_size) << 9, \ + .devname[0] = 0, \ + .volname[0] = 0 \ +} + +#define INIT_BLKPG_ARG(_action, _part) { \ + .op = (_action), \ + .flags = 0, \ + .datalen = sizeof(*(_part)), \ + .data = (_part) \ +} + + +static inline int partx_del_partition(int fd, unsigned int partno) +{ + struct blkpg_partition p = INIT_BLKPG_PARTITION(partno, 0, 0); + struct blkpg_ioctl_arg a = INIT_BLKPG_ARG(BLKPG_DEL_PARTITION, &p); + + return ioctl(fd, BLKPG, &a); +} + +static inline int partx_add_partition(int fd, int partno, + uint64_t start, uint64_t size) +{ + struct blkpg_partition p = INIT_BLKPG_PARTITION(partno, start, size); + struct blkpg_ioctl_arg a = INIT_BLKPG_ARG(BLKPG_ADD_PARTITION, &p); + + return ioctl(fd, BLKPG, &a); +} + +static inline int partx_resize_partition(int fd, int partno, + uint64_t start, uint64_t size) +{ + struct blkpg_partition p = INIT_BLKPG_PARTITION(partno, start, size); + struct blkpg_ioctl_arg a = INIT_BLKPG_ARG(BLKPG_RESIZE_PARTITION, &p); + + return ioctl(fd, BLKPG, &a); +} + +#endif /* UTIL_LINUX_PARTX_H */ -- cgit v1.2.3-55-g7522