]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/boot/efi/disk.c
9a908188473636e697b8578a7de1181b66f68e87
[thirdparty/systemd.git] / src / boot / efi / disk.c
1 /* SPDX-License-Identifier: LGPL-2.1+ */
2 /*
3 * This program is free software; you can redistribute it and/or modify it
4 * under the terms of the GNU Lesser General Public License as published by
5 * the Free Software Foundation; either version 2.1 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Lesser General Public License for more details.
12 *
13 * Copyright (C) 2015 Kay Sievers <kay@vrfy.org>
14 */
15
16 #include <efi.h>
17 #include <efilib.h>
18
19 #include "util.h"
20
21 EFI_STATUS disk_get_part_uuid(EFI_HANDLE *handle, CHAR16 uuid[37]) {
22 EFI_DEVICE_PATH *device_path;
23
24 /* export the device path this image is started from */
25 device_path = DevicePathFromHandle(handle);
26 if (device_path) {
27 _cleanup_freepool_ EFI_DEVICE_PATH *paths = NULL;
28 EFI_DEVICE_PATH *path;
29
30 paths = UnpackDevicePath(device_path);
31 for (path = paths; !IsDevicePathEnd(path); path = NextDevicePathNode(path)) {
32 HARDDRIVE_DEVICE_PATH *drive;
33
34 if (DevicePathType(path) != MEDIA_DEVICE_PATH)
35 continue;
36 if (DevicePathSubType(path) != MEDIA_HARDDRIVE_DP)
37 continue;
38 drive = (HARDDRIVE_DEVICE_PATH *)path;
39 if (drive->SignatureType != SIGNATURE_TYPE_GUID)
40 continue;
41
42 GuidToString(uuid, (EFI_GUID *)&drive->Signature);
43 return EFI_SUCCESS;
44 }
45 }
46
47 return EFI_NOT_FOUND;
48 }