summaryrefslogtreecommitdiffstats
path: root/include/partx.h
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-14 19:10:49 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-14 19:10:49 +0000
commitcfe5e3905201349e9cf3f95d52ff4bd100bde37d (patch)
treed0baf160cbee3195249d095f85e52d20c21acf02 /include/partx.h
parentInitial commit. (diff)
downloadutil-linux-cfe5e3905201349e9cf3f95d52ff4bd100bde37d.tar.xz
util-linux-cfe5e3905201349e9cf3f95d52ff4bd100bde37d.zip
Adding upstream version 2.39.3.upstream/2.39.3
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'include/partx.h')
-rw-r--r--include/partx.h67
1 files changed, 67 insertions, 0 deletions
diff --git a/include/partx.h b/include/partx.h
new file mode 100644
index 0000000..7924aae
--- /dev/null
+++ b/include/partx.h
@@ -0,0 +1,67 @@
+/*
+ * No copyright is claimed. This code is in the public domain; do with
+ * it what you wish.
+ */
+#ifndef UTIL_LINUX_PARTX_H
+#define UTIL_LINUX_PARTX_H
+
+#include <sys/ioctl.h>
+#include <linux/blkpg.h>
+#include <stdint.h>
+
+#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 */