summaryrefslogtreecommitdiffstats
path: root/disk-utils/partx.h
diff options
context:
space:
mode:
authorKarel Zak2015-10-06 19:50:56 +0200
committerKarel Zak2015-10-09 12:18:28 +0200
commit24b7db7e4e0d7bb026d2d80c95ecdcfc476a9b45 (patch)
tree5649111535d5189493aff8f66914529c9e55caff /disk-utils/partx.h
parentuuidd: add debug message for timeout (diff)
downloadkernel-qcow2-util-linux-24b7db7e4e0d7bb026d2d80c95ecdcfc476a9b45.tar.gz
kernel-qcow2-util-linux-24b7db7e4e0d7bb026d2d80c95ecdcfc476a9b45.tar.xz
kernel-qcow2-util-linux-24b7db7e4e0d7bb026d2d80c95ecdcfc476a9b45.zip
partx: prevent code duplication
Reported-by: Alexander Kuleshov <kuleshovmail@gmail.com> Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'disk-utils/partx.h')
-rw-r--r--disk-utils/partx.h59
1 files changed, 23 insertions, 36 deletions
diff --git a/disk-utils/partx.h b/disk-utils/partx.h
index 254cd85cc..96206bd7c 100644
--- a/disk-utils/partx.h
+++ b/disk-utils/partx.h
@@ -16,20 +16,27 @@
# 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_ioctl_arg a;
- struct blkpg_partition p;
-
- p.pno = partno;
- p.start = 0;
- p.length = 0;
- p.devname[0] = 0;
- p.volname[0] = 0;
- a.op = BLKPG_DEL_PARTITION;
- a.flags = 0;
- a.datalen = sizeof(p);
- a.data = &p;
+ 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);
}
@@ -37,18 +44,8 @@ static inline int partx_del_partition(int fd, unsigned int partno)
static inline int partx_add_partition(int fd, int partno,
uint64_t start, uint64_t size)
{
- struct blkpg_ioctl_arg a;
- struct blkpg_partition p;
-
- p.pno = partno;
- p.start = start << 9;
- p.length = size << 9;
- p.devname[0] = 0;
- p.volname[0] = 0;
- a.op = BLKPG_ADD_PARTITION;
- a.flags = 0;
- a.datalen = sizeof(p);
- a.data = &p;
+ 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);
}
@@ -56,18 +53,8 @@ static inline int partx_add_partition(int fd, int partno,
static inline int partx_resize_partition(int fd, int partno,
uint64_t start, uint64_t size)
{
- struct blkpg_ioctl_arg a;
- struct blkpg_partition p;
-
- p.pno = partno;
- p.start = start << 9;
- p.length = size << 9;
- p.devname[0] = 0;
- p.volname[0] = 0;
- a.op = BLKPG_RESIZE_PARTITION;
- a.flags = 0;
- a.datalen = sizeof(p);
- a.data = &p;
+ 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);
}