return -EINVAL; /* The terminator was not found */
}
-struct guid {
- uint32_t u1;
- uint16_t u2;
- uint16_t u3;
- uint8_t u4[8];
-} _packed_;
-
-static void efi_guid_to_id128(const void *guid, sd_id128_t *id128) {
- uint32_t u1;
- uint16_t u2, u3;
- const struct guid *uuid = guid;
-
- memcpy(&u1, &uuid->u1, sizeof(uint32_t));
- id128->bytes[0] = (u1 >> 24) & 0xff;
- id128->bytes[1] = (u1 >> 16) & 0xff;
- id128->bytes[2] = (u1 >> 8) & 0xff;
- id128->bytes[3] = u1 & 0xff;
- memcpy(&u2, &uuid->u2, sizeof(uint16_t));
- id128->bytes[4] = (u2 >> 8) & 0xff;
- id128->bytes[5] = u2 & 0xff;
- memcpy(&u3, &uuid->u3, sizeof(uint16_t));
- id128->bytes[6] = (u3 >> 8) & 0xff;
- id128->bytes[7] = u3 & 0xff;
- memcpy(&id128->bytes[8], uuid->u4, sizeof(uuid->u4));
-}
-
int efi_get_boot_option(
uint16_t id,
char **ret_title,
continue;
if (ret_part_uuid)
- efi_guid_to_id128(dpath->drive.signature, &p_uuid);
+ p_uuid = efi_guid_to_id128(dpath->drive.signature);
continue;
}
dest[i] = '\0';
}
-static void id128_to_efi_guid(sd_id128_t id, void *guid) {
- struct guid uuid = {
- .u1 = id.bytes[0] << 24 | id.bytes[1] << 16 | id.bytes[2] << 8 | id.bytes[3],
- .u2 = id.bytes[4] << 8 | id.bytes[5],
- .u3 = id.bytes[6] << 8 | id.bytes[7],
- };
- memcpy(uuid.u4, id.bytes+8, sizeof(uuid.u4));
- memcpy(guid, &uuid, sizeof(uuid));
-}
-
static uint16_t *tilt_slashes(uint16_t *s) {
for (uint16_t *p = s; *p; p++)
if (*p == '/')
memcpy(&devicep->drive.part_nr, &part, sizeof(uint32_t));
memcpy(&devicep->drive.part_start, &pstart, sizeof(uint64_t));
memcpy(&devicep->drive.part_size, &psize, sizeof(uint64_t));
- id128_to_efi_guid(part_uuid, devicep->drive.signature);
+ efi_id128_to_guid(part_uuid, devicep->drive.signature);
devicep->drive.mbr_type = MBR_TYPE_EFI_PARTITION_TABLE_HEADER;
devicep->drive.signature_type = SIGNATURE_TYPE_GUID;
size += devicep->length;
}
#endif
+
+struct efi_guid {
+ uint32_t u1;
+ uint16_t u2;
+ uint16_t u3;
+ uint8_t u4[8];
+} _packed_;
+
+sd_id128_t efi_guid_to_id128(const void *guid) {
+ const struct efi_guid *uuid = ASSERT_PTR(guid); /* cast is safe, because struct efi_guid is packed */
+ sd_id128_t id128;
+
+ id128.bytes[0] = (uuid->u1 >> 24) & 0xff;
+ id128.bytes[1] = (uuid->u1 >> 16) & 0xff;
+ id128.bytes[2] = (uuid->u1 >> 8) & 0xff;
+ id128.bytes[3] = uuid->u1 & 0xff;
+
+ id128.bytes[4] = (uuid->u2 >> 8) & 0xff;
+ id128.bytes[5] = uuid->u2 & 0xff;
+
+ id128.bytes[6] = (uuid->u3 >> 8) & 0xff;
+ id128.bytes[7] = uuid->u3 & 0xff;
+
+ memcpy(&id128.bytes[8], uuid->u4, sizeof(uuid->u4));
+
+ return id128;
+}
+
+void efi_id128_to_guid(sd_id128_t id, void *ret_guid) {
+ assert(ret_guid);
+
+ struct efi_guid uuid = {
+ .u1 = id.bytes[0] << 24 | id.bytes[1] << 16 | id.bytes[2] << 8 | id.bytes[3],
+ .u2 = id.bytes[4] << 8 | id.bytes[5],
+ .u3 = id.bytes[6] << 8 | id.bytes[7],
+ };
+ memcpy(uuid.u4, id.bytes+8, sizeof(uuid.u4));
+ memcpy(ret_guid, &uuid, sizeof(uuid));
+}