1 | /* $Id: efiguid.cpp 93115 2022-01-01 11:31:46Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * IPRT - EFI GUID conversion helpers.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2021-2022 Oracle Corporation
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | *
|
---|
17 | * The contents of this file may alternatively be used under the terms
|
---|
18 | * of the Common Development and Distribution License Version 1.0
|
---|
19 | * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
|
---|
20 | * VirtualBox OSE distribution, in which case the provisions of the
|
---|
21 | * CDDL are applicable instead of those of the GPL.
|
---|
22 | *
|
---|
23 | * You may elect to license modified versions of this file under the
|
---|
24 | * terms and conditions of either the GPL or the CDDL or both.
|
---|
25 | */
|
---|
26 |
|
---|
27 |
|
---|
28 | /*********************************************************************************************************************************
|
---|
29 | * Header Files *
|
---|
30 | *********************************************************************************************************************************/
|
---|
31 | #define LOG_GROUP RTLOGGROUP_DEFAULT
|
---|
32 | #include <iprt/efi.h>
|
---|
33 |
|
---|
34 | #include <iprt/cdefs.h>
|
---|
35 | #include <iprt/string.h>
|
---|
36 |
|
---|
37 |
|
---|
38 | /*********************************************************************************************************************************
|
---|
39 | * Defined Constants And Macros *
|
---|
40 | *********************************************************************************************************************************/
|
---|
41 |
|
---|
42 |
|
---|
43 | /*********************************************************************************************************************************
|
---|
44 | * Structures and Typedefs *
|
---|
45 | *********************************************************************************************************************************/
|
---|
46 |
|
---|
47 |
|
---|
48 | /*********************************************************************************************************************************
|
---|
49 | * Internal Functions *
|
---|
50 | *********************************************************************************************************************************/
|
---|
51 |
|
---|
52 | RTDECL(PRTUUID) RTEfiGuidToUuid(PRTUUID pUuid, PCEFI_GUID pEfiGuid)
|
---|
53 | {
|
---|
54 | pUuid->Gen.u32TimeLow = RT_LE2H_U32(pEfiGuid->u32Data1);
|
---|
55 | pUuid->Gen.u16TimeMid = RT_LE2H_U16(pEfiGuid->u16Data2);
|
---|
56 | pUuid->Gen.u16TimeHiAndVersion = RT_LE2H_U16(pEfiGuid->u16Data3);
|
---|
57 | pUuid->Gen.u8ClockSeqHiAndReserved = pEfiGuid->abData4[0];
|
---|
58 | pUuid->Gen.u8ClockSeqLow = pEfiGuid->abData4[1];
|
---|
59 | pUuid->Gen.au8Node[0] = pEfiGuid->abData4[2];
|
---|
60 | pUuid->Gen.au8Node[1] = pEfiGuid->abData4[3];
|
---|
61 | pUuid->Gen.au8Node[2] = pEfiGuid->abData4[4];
|
---|
62 | pUuid->Gen.au8Node[3] = pEfiGuid->abData4[5];
|
---|
63 | pUuid->Gen.au8Node[4] = pEfiGuid->abData4[6];
|
---|
64 | pUuid->Gen.au8Node[5] = pEfiGuid->abData4[7];
|
---|
65 | return pUuid;
|
---|
66 | }
|
---|
67 |
|
---|
68 |
|
---|
69 | RTDECL(PEFI_GUID) RTEfiGuidFromUuid(PEFI_GUID pEfiGuid, PCRTUUID pUuid)
|
---|
70 | {
|
---|
71 | pEfiGuid->u32Data1 = RT_H2LE_U32(pUuid->Gen.u32TimeLow);
|
---|
72 | pEfiGuid->u16Data2 = RT_H2LE_U16(pUuid->Gen.u16TimeMid);
|
---|
73 | pEfiGuid->u16Data3 = RT_H2LE_U16(pUuid->Gen.u16TimeHiAndVersion);
|
---|
74 | pEfiGuid->abData4[0] = pUuid->Gen.u8ClockSeqHiAndReserved;
|
---|
75 | pEfiGuid->abData4[1] = pUuid->Gen.u8ClockSeqLow;
|
---|
76 | pEfiGuid->abData4[2] = pUuid->Gen.au8Node[0];
|
---|
77 | pEfiGuid->abData4[3] = pUuid->Gen.au8Node[1];
|
---|
78 | pEfiGuid->abData4[4] = pUuid->Gen.au8Node[2];
|
---|
79 | pEfiGuid->abData4[5] = pUuid->Gen.au8Node[3];
|
---|
80 | pEfiGuid->abData4[6] = pUuid->Gen.au8Node[4];
|
---|
81 | pEfiGuid->abData4[7] = pUuid->Gen.au8Node[5];
|
---|
82 | return pEfiGuid;
|
---|
83 | }
|
---|
84 |
|
---|
85 |
|
---|
86 | RTDECL(int) RTEfiGuidCompare(PCEFI_GUID pGuid1, PCEFI_GUID pGuid2)
|
---|
87 | {
|
---|
88 | /*
|
---|
89 | * Special cases.
|
---|
90 | */
|
---|
91 | if (pGuid1 == pGuid2)
|
---|
92 | return 0;
|
---|
93 | AssertPtrReturn(pGuid1, -1);
|
---|
94 | AssertPtrReturn(pGuid2, 1);
|
---|
95 |
|
---|
96 | /*
|
---|
97 | * Standard cases.
|
---|
98 | */
|
---|
99 | if (pGuid1->u32Data1 != pGuid2->u32Data1)
|
---|
100 | return pGuid1->u32Data1 < pGuid2->u32Data1 ? -1 : 1;
|
---|
101 | if (pGuid1->u16Data2 != pGuid2->u16Data2)
|
---|
102 | return pGuid1->u16Data2 < pGuid2->u16Data2 ? -1 : 1;
|
---|
103 | if (pGuid1->u16Data3 != pGuid2->u16Data3)
|
---|
104 | return pGuid1->u16Data3 < pGuid2->u16Data3 ? -1 : 1;
|
---|
105 | if (pGuid1->abData4[0] != pGuid2->abData4[0])
|
---|
106 | return pGuid1->abData4[0] < pGuid2->abData4[0] ? -1 : 1;
|
---|
107 | if (pGuid1->abData4[1] != pGuid2->abData4[1])
|
---|
108 | return pGuid1->abData4[1] < pGuid2->abData4[1] ? -1 : 1;
|
---|
109 | if (pGuid1->abData4[2] != pGuid2->abData4[2])
|
---|
110 | return pGuid1->abData4[2] < pGuid2->abData4[2] ? -1 : 1;
|
---|
111 | if (pGuid1->abData4[3] != pGuid2->abData4[3])
|
---|
112 | return pGuid1->abData4[3] < pGuid2->abData4[3] ? -1 : 1;
|
---|
113 | if (pGuid1->abData4[4] != pGuid2->abData4[4])
|
---|
114 | return pGuid1->abData4[4] < pGuid2->abData4[4] ? -1 : 1;
|
---|
115 | if (pGuid1->abData4[5] != pGuid2->abData4[5])
|
---|
116 | return pGuid1->abData4[5] < pGuid2->abData4[5] ? -1 : 1;
|
---|
117 | if (pGuid1->abData4[6] != pGuid2->abData4[6])
|
---|
118 | return pGuid1->abData4[6] < pGuid2->abData4[6] ? -1 : 1;
|
---|
119 | if (pGuid1->abData4[7] != pGuid2->abData4[7])
|
---|
120 | return pGuid1->abData4[7] < pGuid2->abData4[7] ? -1 : 1;
|
---|
121 | return 0;
|
---|
122 | }
|
---|
123 |
|
---|