diff options
author | Karel Zak | 2006-12-07 00:25:39 +0100 |
---|---|---|
committer | Karel Zak | 2006-12-07 00:25:39 +0100 |
commit | 7eda085c41faa3445b4b168ce78ab18dab87d98a (patch) | |
tree | eb8da4baebd0af68fa84818d3d51b4a3714667fc /fdisk/addpart.c | |
parent | Imported from util-linux-2.9i tarball. (diff) | |
download | kernel-qcow2-util-linux-7eda085c41faa3445b4b168ce78ab18dab87d98a.tar.gz kernel-qcow2-util-linux-7eda085c41faa3445b4b168ce78ab18dab87d98a.tar.xz kernel-qcow2-util-linux-7eda085c41faa3445b4b168ce78ab18dab87d98a.zip |
Imported from util-linux-2.9v tarball.
Diffstat (limited to 'fdisk/addpart.c')
-rw-r--r-- | fdisk/addpart.c | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/fdisk/addpart.c b/fdisk/addpart.c new file mode 100644 index 000000000..11d4305b9 --- /dev/null +++ b/fdisk/addpart.c @@ -0,0 +1,40 @@ +/* very primitive wrapper around the `add partition' ioctl */ +#include <stdio.h> +#include <fcntl.h> +#include <stdlib.h> +#include <sys/ioctl.h> +#include <linux/blkpg.h> + +int +main(int argc, char **argv){ + int fd; + struct blkpg_ioctl_arg a; + struct blkpg_partition p; + + if (argc != 5) { + fprintf(stderr, + "usage: %s diskdevice partitionnr start length\n", + argv[0]); + exit(1); + } + if ((fd = open(argv[1], O_RDONLY)) < 0) { + perror(argv[1]); + exit(1); + } + p.pno = atoi(argv[2]); + p.start = 512 * ((long long) atol(argv[3])); + p.length = 512 * ((long long) atol(argv[4])); + p.devname[0] = 0; + p.volname[0] = 0; + a.op = BLKPG_ADD_PARTITION; + a.flags = 0; + a.datalen = sizeof(p); + a.data = &p; + + if (ioctl(fd, BLKPG, &a) == -1) { + perror("BLKPG"); + exit(1); + } + + return 0; +} |