[parted-devel] [PATCH] fix handling of disks that can't be partitioned
Colin Watson
cjwatson at ubuntu.com
Wed Oct 22 11:48:40 UTC 2008
Don't try to call BLKPG ioctls or tell device-mapper to create
partitions on disks that can't be partitioned. This fixes the creation
of bogus "/dev/mapper/vg-lvp1"-type devices for LVM logical volumes.
Signed-off-by: Colin Watson <cjwatson at ubuntu.com>
diff --git a/libparted/arch/linux.c b/libparted/arch/linux.c
index 83e24c8..a2af223 100644
--- a/libparted/arch/linux.c
+++ b/libparted/arch/linux.c
@@ -2166,6 +2166,18 @@ linux_partition_is_busy (const PedPartition* part)
}
static int
+_has_partitions (const PedDisk* disk)
+{
+ PED_ASSERT(disk != NULL, return 0);
+
+ /* Some devices can't be partitioned. */
+ if (!strcmp (disk->type->name, "loop"))
+ return 0;
+
+ return 1;
+}
+
+static int
_blkpg_part_command (PedDevice* dev, struct blkpg_partition* part, int op)
{
LinuxSpecific* arch_specific = LINUX_SPECIFIC (dev);
@@ -2190,6 +2202,9 @@ _blkpg_add_partition (PedDisk* disk, const PedPartition *part)
PED_ASSERT(disk->dev->sector_size % PED_SECTOR_SIZE_DEFAULT == 0,
return 0);
+ if (!_has_partitions (disk))
+ return 0;
+
if (ped_disk_type_check_feature (disk->type,
PED_DISK_TYPE_PARTITION_NAME))
vol_name = ped_partition_get_name (part);
@@ -2238,6 +2253,9 @@ _blkpg_remove_partition (PedDisk* disk, int n)
{
struct blkpg_partition linux_part;
+ if (!_has_partitions (disk))
+ return 0;
+
memset (&linux_part, 0, sizeof (linux_part));
linux_part.pno = n;
return _blkpg_part_command (disk->dev, &linux_part,
@@ -2421,6 +2439,9 @@ _dm_add_partition (PedDisk* disk, PedPartition* part)
char* dev_name = NULL;
char* params = NULL;
+ if (!_has_partitions(disk))
+ return 0;
+
dev_name = _device_get_part_path (disk->dev, part->num);
if (!dev_name)
return 0;
--
Colin Watson [cjwatson at ubuntu.com]
More information about the parted-devel
mailing list