summaryrefslogtreecommitdiff
path: root/libparted
diff options
context:
space:
mode:
Diffstat (limited to 'libparted')
-rw-r--r--libparted/disk.c64
-rw-r--r--libparted/labels/gpt.c40
2 files changed, 103 insertions, 1 deletions
diff --git a/libparted/disk.c b/libparted/disk.c
index a961d65..0ed3d91 100644
--- a/libparted/disk.c
+++ b/libparted/disk.c
@@ -886,6 +886,37 @@ ped_disk_flag_next(PedDiskFlag flag)
return (flag + 1) % (PED_DISK_LAST_FLAG + 1);
}
+static int
+_assert_disk_uuid_feature (const PedDiskType* disk_type)
+{
+ if (!ped_disk_type_check_feature (
+ disk_type, PED_DISK_TYPE_DISK_UUID)) {
+ ped_exception_throw (
+ PED_EXCEPTION_ERROR,
+ PED_EXCEPTION_CANCEL,
+ "%s disk labels do not support disk uuids.",
+ disk_type->name);
+ return 0;
+ }
+ return 1;
+}
+
+/**
+ * Get the uuid of the disk \p disk. This will only work if the disk label
+ * supports it.
+ */
+uint8_t*
+ped_disk_get_uuid (const PedDisk *disk)
+{
+ PED_ASSERT (disk != NULL);
+
+ if (!_assert_disk_uuid_feature (disk->type))
+ return NULL;
+
+ PED_ASSERT (disk->type->ops->disk_get_uuid != NULL);
+ return disk->type->ops->disk_get_uuid (disk);
+}
+
/**
* \internal We turned a really nasty bureaucracy problem into an elegant maths
* problem :-) Basically, there are some constraints to a partition's
@@ -1488,6 +1519,21 @@ _assert_partition_type_uuid_feature (const PedDiskType* disk_type)
return 1;
}
+static int
+_assert_partition_uuid_feature (const PedDiskType* disk_type)
+{
+ if (!ped_disk_type_check_feature (
+ disk_type, PED_DISK_TYPE_PARTITION_UUID)) {
+ ped_exception_throw (
+ PED_EXCEPTION_ERROR,
+ PED_EXCEPTION_CANCEL,
+ "%s disk labels do not support partition uuids.",
+ disk_type->name);
+ return 0;
+ }
+ return 1;
+}
+
/**
* Sets the name of a partition.
*
@@ -1612,6 +1658,24 @@ ped_partition_get_type_uuid (const PedPartition *part)
return part->disk->type->ops->partition_get_type_uuid (part);
}
+/**
+ * Get the uuid of the partition \p part. This will only work if the disk label
+ * supports it.
+ */
+uint8_t*
+ped_partition_get_uuid (const PedPartition *part)
+{
+ PED_ASSERT (part != NULL);
+ PED_ASSERT (part->disk != NULL);
+ PED_ASSERT (ped_partition_is_active (part));
+
+ if (!_assert_partition_uuid_feature (part->disk->type))
+ return NULL;
+
+ PED_ASSERT (part->disk->type->ops->partition_get_uuid != NULL);
+ return part->disk->type->ops->partition_get_uuid (part);
+}
+
/** @} */
/**
diff --git a/libparted/labels/gpt.c b/libparted/labels/gpt.c
index 8e6a37d..1993863 100644
--- a/libparted/labels/gpt.c
+++ b/libparted/labels/gpt.c
@@ -1576,6 +1576,24 @@ gpt_disk_is_flag_available(const PedDisk *disk, PedDiskFlag flag)
}
}
+static uint8_t*
+gpt_disk_get_uuid (const PedDisk *disk)
+{
+ GPTDiskData *gpt_disk_data = disk->disk_specific;
+
+ efi_guid_t uuid = gpt_disk_data->uuid;
+
+ /* uuid is always LE, while uint8_t is always kind of BE */
+
+ uuid.time_low = PED_SWAP32(uuid.time_low);
+ uuid.time_mid = PED_SWAP16(uuid.time_mid);
+ uuid.time_hi_and_version = PED_SWAP16(uuid.time_hi_and_version);
+
+ uint8_t *buf = ped_malloc(sizeof (uuid_t));
+ memcpy(buf, &uuid, sizeof (uuid_t));
+ return buf;
+}
+
static int
gpt_disk_get_flag (const PedDisk *disk, PedDiskFlag flag)
{
@@ -1764,6 +1782,23 @@ gpt_partition_get_type_uuid (const PedPartition *part)
return buf;
}
+static uint8_t*
+gpt_partition_get_uuid (const PedPartition *part)
+{
+ const GPTPartitionData *gpt_part_data = part->disk_specific;
+
+ efi_guid_t uuid = gpt_part_data->uuid;
+
+ /* uuid is always LE, while uint8_t is always kind of BE */
+
+ uuid.time_low = PED_SWAP32(uuid.time_low);
+ uuid.time_mid = PED_SWAP16(uuid.time_mid);
+ uuid.time_hi_and_version = PED_SWAP16(uuid.time_hi_and_version);
+
+ uint8_t *buf = ped_malloc(sizeof (uuid_t));
+ memcpy(buf, &uuid, sizeof (uuid_t));
+ return buf;
+}
static int
gpt_get_max_primary_partition_count (const PedDisk *disk)
@@ -1864,9 +1899,11 @@ static PedDiskOps gpt_disk_ops =
partition_get_type_id: NULL,
partition_set_type_uuid: gpt_partition_set_type_uuid,
partition_get_type_uuid: gpt_partition_get_type_uuid,
+ partition_get_uuid: gpt_partition_get_uuid,
disk_set_flag: gpt_disk_set_flag,
disk_get_flag: gpt_disk_get_flag,
disk_is_flag_available: gpt_disk_is_flag_available,
+ disk_get_uuid: gpt_disk_get_uuid,
PT_op_function_initializers (gpt)
};
@@ -1876,7 +1913,8 @@ static PedDiskType gpt_disk_type =
next: NULL,
name: "gpt",
ops: &gpt_disk_ops,
- features: PED_DISK_TYPE_PARTITION_NAME | PED_DISK_TYPE_PARTITION_TYPE_UUID
+ features: PED_DISK_TYPE_PARTITION_NAME | PED_DISK_TYPE_PARTITION_TYPE_UUID |
+ PED_DISK_TYPE_DISK_UUID | PED_DISK_TYPE_PARTITION_UUID
};
void