On Tue, Oct 06, 2015 at 11:50:56PM +0600, Alexander Kuleshov wrote: > The disk-utils/partx.h provides three functions: > partx_{del,add,resize}_partition() that contain almost the same code > - initialization of the blkpg_partition and blkpg_ioctl_arg structs. Good point, > Let's provide INIT_PKG macro that will do all work to prevent code > duplication. but I don't like the implementation :-) > +#define INIT_BLKPG(ioctl_arg, action, partno, start, size) do { \ > + struct blkpg_partition p; \ It's bad manner to hide any struct declaration within a macro if you expect a valid reference to the struct outside the macro scope. My solution (already in git tree): #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_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); } IMHO it's more readable and it does not hide struct blkpg_partition. Hmm.. .devname[0] = 0 and .volname[0] = 0 initialization is unnecessary, unspecified struct members should be automatically zeroized. Karel -- Karel Zak <kzak@xxxxxxxxxx> http://karelzak.blogspot.com -- To unsubscribe from this list: send the line "unsubscribe util-linux" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html