From 7bc0771e7f63c8c42d817cca3fef16a7a6c4fdf0 Mon Sep 17 00:00:00 2001 From: Marcin Szewczyk Date: Thu, 22 Dec 2011 16:25:02 +0100 Subject: [PATCH] BLKRRPART instead of BLKPG for extended partitions Use BLKRRPART instead of BLKPG after creating an extended partition. BLKPG returns with the "Device or resource busy" error. --- src/helpers/job-create-partition.c | 48 +++++++++++++++++++++++------------ 1 files changed, 31 insertions(+), 17 deletions(-) diff --git a/src/helpers/job-create-partition.c b/src/helpers/job-create-partition.c index 80277b8..818309b 100644 --- a/src/helpers/job-create-partition.c +++ b/src/helpers/job-create-partition.c @@ -141,25 +141,39 @@ main (int argc, g_printerr ("Cannot open %s: %m\n", device); goto out; } - memset (&a, '\0', sizeof(struct blkpg_ioctl_arg)); - memset (&p, '\0', sizeof(struct blkpg_partition)); - p.pno = out_num; - p.start = out_start; - p.length = out_size; - a.op = BLKPG_ADD_PARTITION; - a.datalen = sizeof(p); - a.data = &p; - if (ioctl (fd, BLKPG, &a) == -1) + + if (*endp == '\0' && (n == 0x05 || n == 0x0f || n == 0x85)) { - g_printerr ("Error doing BLKPG ioctl with BLKPG_ADD_PARTITION for partition %d " - "of size %" G_GUINT64_FORMAT " at offset %" G_GUINT64_FORMAT " on %s: %m\n", - out_num, - out_start, - out_size, - device); - close (fd); - goto out; + if (ioctl (fd, BLKRRPART) == -1) + { + g_printerr ("Error doing BLKRRPART ioctl on %s: %m\n", + device); + close (fd); + goto out; + } } + else + { + memset (&a, '\0', sizeof(struct blkpg_ioctl_arg)); + memset (&p, '\0', sizeof(struct blkpg_partition)); + p.pno = out_num; + p.start = out_start; + p.length = out_size; + a.op = BLKPG_ADD_PARTITION; + a.datalen = sizeof(p); + a.data = &p; + if (ioctl (fd, BLKPG, &a) == -1) + { + g_printerr ("Error doing BLKPG ioctl with BLKPG_ADD_PARTITION for partition %d " + "of size %" G_GUINT64_FORMAT " at offset %" G_GUINT64_FORMAT " on %s: %m\n", + out_num, + out_start, + out_size, + device); + close (fd); + goto out; + } + } close (fd); } -- 1.7.7.3