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