2010-12-09 14:54:17 -06:00
|
|
|
#ifndef UTIL_LINUX_PARTX_H
|
|
|
|
#define UTIL_LINUX_PARTX_H
|
|
|
|
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <linux/blkpg.h>
|
2017-09-19 06:48:52 -05:00
|
|
|
#include <stdint.h>
|
2010-12-09 14:54:17 -06:00
|
|
|
|
2012-08-13 15:10:14 -05:00
|
|
|
#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
|
|
|
|
|
2015-10-06 12:50:56 -05:00
|
|
|
|
|
|
|
#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) \
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-05-15 10:44:51 -05:00
|
|
|
static inline int partx_del_partition(int fd, unsigned int partno)
|
2010-12-09 14:54:17 -06:00
|
|
|
{
|
2015-10-06 12:50:56 -05:00
|
|
|
struct blkpg_partition p = INIT_BLKPG_PARTITION(partno, 0, 0);
|
|
|
|
struct blkpg_ioctl_arg a = INIT_BLKPG_ARG(BLKPG_DEL_PARTITION, &p);
|
2010-12-09 14:54:17 -06:00
|
|
|
|
|
|
|
return ioctl(fd, BLKPG, &a);
|
|
|
|
}
|
2006-12-06 17:25:43 -06:00
|
|
|
|
2010-12-09 14:54:17 -06:00
|
|
|
static inline int partx_add_partition(int fd, int partno,
|
2012-05-15 10:44:51 -05:00
|
|
|
uint64_t start, uint64_t size)
|
2010-12-09 14:54:17 -06:00
|
|
|
{
|
2015-10-06 12:50:56 -05:00
|
|
|
struct blkpg_partition p = INIT_BLKPG_PARTITION(partno, start, size);
|
|
|
|
struct blkpg_ioctl_arg a = INIT_BLKPG_ARG(BLKPG_ADD_PARTITION, &p);
|
2010-12-09 14:54:17 -06:00
|
|
|
|
|
|
|
return ioctl(fd, BLKPG, &a);
|
2006-12-06 17:25:43 -06:00
|
|
|
}
|
2006-12-06 17:25:54 -06:00
|
|
|
|
2012-08-13 15:10:14 -05:00
|
|
|
static inline int partx_resize_partition(int fd, int partno,
|
|
|
|
uint64_t start, uint64_t size)
|
|
|
|
{
|
2015-10-06 12:50:56 -05:00
|
|
|
struct blkpg_partition p = INIT_BLKPG_PARTITION(partno, start, size);
|
|
|
|
struct blkpg_ioctl_arg a = INIT_BLKPG_ARG(BLKPG_RESIZE_PARTITION, &p);
|
2012-08-13 15:10:14 -05:00
|
|
|
|
|
|
|
return ioctl(fd, BLKPG, &a);
|
|
|
|
}
|
|
|
|
|
2010-12-09 14:54:17 -06:00
|
|
|
#endif /* UTIL_LINUX_PARTX_H */
|