summaryrefslogtreecommitdiffstats
path: root/partx/addpart.c
diff options
context:
space:
mode:
authorKarel Zak2010-12-09 21:56:13 +0100
committerKarel Zak2010-12-09 21:56:13 +0100
commit74a782e2a24b307177f9635af77dac56d0769b1a (patch)
treeea51b5c2796d8824f6f0054badf0f352fb14899a /partx/addpart.c
parentpartx: complete rewrite (diff)
downloadkernel-qcow2-util-linux-74a782e2a24b307177f9635af77dac56d0769b1a.tar.gz
kernel-qcow2-util-linux-74a782e2a24b307177f9635af77dac56d0769b1a.tar.xz
kernel-qcow2-util-linux-74a782e2a24b307177f9635af77dac56d0769b1a.zip
addpart: code consolidation
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'partx/addpart.c')
-rw-r--r--partx/addpart.c30
1 files changed, 9 insertions, 21 deletions
diff --git a/partx/addpart.c b/partx/addpart.c
index 112a2860c..52c780c4a 100644
--- a/partx/addpart.c
+++ b/partx/addpart.c
@@ -1,18 +1,13 @@
-/* very primitive wrapper around the `add partition' ioctl */
#include <stdio.h>
-#include <fcntl.h>
#include <stdlib.h>
-#include <sys/ioctl.h>
-#ifdef HAVE_LINUX_COMPILER_H
-#include <linux/compiler.h>
-#endif
-#include <linux/blkpg.h>
+#include <fcntl.h>
+
+#include "partx.h"
int
-main(int argc, char **argv){
+main(int argc, char **argv)
+{
int fd;
- struct blkpg_ioctl_arg a;
- struct blkpg_partition p;
if (argc != 5) {
fprintf(stderr,
@@ -24,20 +19,13 @@ main(int argc, char **argv){
perror(argv[1]);
exit(1);
}
- p.pno = atoi(argv[2]);
- p.start = 512 * atoll(argv[3]);
- p.length = 512 * atoll(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) {
+ if (partx_add_partition(fd, atoi(argv[2]),
+ 512 * atoll(argv[3]),
+ 512 * atoll(argv[4]))) {
perror("BLKPG");
exit(1);
}
-
+
return 0;
}