]> git.proxmox.com Git - mirror_edk2.git/blame - BaseTools/Source/C/DevicePath/UefiDevicePathLib.c
BaseTools: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / BaseTools / Source / C / DevicePath / UefiDevicePathLib.c
CommitLineData
7dbc50bd
YZ
1/** @file\r
2 Device Path services. The thing to remember is device paths are built out of\r
3 nodes. The device path is terminated by an end node that is length\r
4 sizeof(EFI_DEVICE_PATH_PROTOCOL). That would be why there is sizeof(EFI_DEVICE_PATH_PROTOCOL)\r
5 all over this file.\r
6\r
7 The only place where multi-instance device paths are supported is in\r
fb0b35e0 8 environment variables. Multi-instance device paths should never be placed\r
7dbc50bd
YZ
9 on a Handle.\r
10\r
11 Copyright (c) 2017, Intel Corporation. All rights reserved.<BR>\r
2e351cbe 12 SPDX-License-Identifier: BSD-2-Clause-Patent\r
7dbc50bd
YZ
13\r
14**/\r
15\r
16\r
17#include "UefiDevicePathLib.h"\r
18\r
19/**\r
20 Returns the size of a device path in bytes.\r
21\r
22 This function returns the size, in bytes, of the device path data structure\r
23 specified by DevicePath including the end of device path node.\r
24 If DevicePath is NULL or invalid, then 0 is returned.\r
25\r
26 @param DevicePath A pointer to a device path data structure.\r
27\r
28 @retval 0 If DevicePath is NULL or invalid.\r
29 @retval Others The size of a device path in bytes.\r
30\r
31**/\r
32UINTN\r
33GetDevicePathSize (\r
34 CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath\r
35 )\r
36{\r
37 return UefiDevicePathLibGetDevicePathSize (DevicePath);\r
38}\r
39\r
40/**\r
41 Creates a new copy of an existing device path.\r
42\r
43 This function allocates space for a new copy of the device path specified by DevicePath.\r
44 If DevicePath is NULL, then NULL is returned. If the memory is successfully\r
45 allocated, then the contents of DevicePath are copied to the newly allocated\r
46 buffer, and a pointer to that buffer is returned. Otherwise, NULL is returned.\r
47 The memory for the new device path is allocated from EFI boot services memory.\r
48 It is the responsibility of the caller to free the memory allocated.\r
49\r
50 @param DevicePath A pointer to a device path data structure.\r
51\r
52 @retval NULL DevicePath is NULL or invalid.\r
53 @retval Others A pointer to the duplicated device path.\r
54\r
55**/\r
56EFI_DEVICE_PATH_PROTOCOL *\r
57DuplicateDevicePath (\r
58 CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath\r
59 )\r
60{\r
61 return UefiDevicePathLibDuplicateDevicePath (DevicePath);\r
62}\r
63\r
64/**\r
65 Creates a new device path by appending a second device path to a first device path.\r
66\r
67 This function creates a new device path by appending a copy of SecondDevicePath\r
68 to a copy of FirstDevicePath in a newly allocated buffer. Only the end-of-device-path\r
69 device node from SecondDevicePath is retained. The newly created device path is\r
70 returned. If FirstDevicePath is NULL, then it is ignored, and a duplicate of\r
71 SecondDevicePath is returned. If SecondDevicePath is NULL, then it is ignored,\r
72 and a duplicate of FirstDevicePath is returned. If both FirstDevicePath and\r
73 SecondDevicePath are NULL, then a copy of an end-of-device-path is returned.\r
74\r
75 If there is not enough memory for the newly allocated buffer, then NULL is returned.\r
76 The memory for the new device path is allocated from EFI boot services memory.\r
77 It is the responsibility of the caller to free the memory allocated.\r
78\r
79 @param FirstDevicePath A pointer to a device path data structure.\r
80 @param SecondDevicePath A pointer to a device path data structure.\r
81\r
82 @retval NULL If there is not enough memory for the newly allocated buffer.\r
83 @retval NULL If FirstDevicePath or SecondDevicePath is invalid.\r
84 @retval Others A pointer to the new device path if success.\r
85 Or a copy an end-of-device-path if both FirstDevicePath and SecondDevicePath are NULL.\r
86\r
87**/\r
88EFI_DEVICE_PATH_PROTOCOL *\r
89AppendDevicePath (\r
90 CONST EFI_DEVICE_PATH_PROTOCOL *FirstDevicePath, OPTIONAL\r
91 CONST EFI_DEVICE_PATH_PROTOCOL *SecondDevicePath OPTIONAL\r
92 )\r
93{\r
94 return UefiDevicePathLibAppendDevicePath (FirstDevicePath, SecondDevicePath);\r
95}\r
96\r
97/**\r
98 Creates a new path by appending the device node to the device path.\r
99\r
100 This function creates a new device path by appending a copy of the device node\r
101 specified by DevicePathNode to a copy of the device path specified by DevicePath\r
102 in an allocated buffer. The end-of-device-path device node is moved after the\r
103 end of the appended device node.\r
104 If DevicePathNode is NULL then a copy of DevicePath is returned.\r
105 If DevicePath is NULL then a copy of DevicePathNode, followed by an end-of-device\r
106 path device node is returned.\r
107 If both DevicePathNode and DevicePath are NULL then a copy of an end-of-device-path\r
108 device node is returned.\r
109 If there is not enough memory to allocate space for the new device path, then\r
110 NULL is returned.\r
111 The memory is allocated from EFI boot services memory. It is the responsibility\r
112 of the caller to free the memory allocated.\r
113\r
114 @param DevicePath A pointer to a device path data structure.\r
115 @param DevicePathNode A pointer to a single device path node.\r
116\r
117 @retval NULL If there is not enough memory for the new device path.\r
118 @retval Others A pointer to the new device path if success.\r
119 A copy of DevicePathNode followed by an end-of-device-path node\r
120 if both FirstDevicePath and SecondDevicePath are NULL.\r
121 A copy of an end-of-device-path node if both FirstDevicePath\r
122 and SecondDevicePath are NULL.\r
123\r
124**/\r
125EFI_DEVICE_PATH_PROTOCOL *\r
126AppendDevicePathNode (\r
127 CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath, OPTIONAL\r
128 CONST EFI_DEVICE_PATH_PROTOCOL *DevicePathNode OPTIONAL\r
129 )\r
130{\r
131 return UefiDevicePathLibAppendDevicePathNode (DevicePath, DevicePathNode);\r
132}\r
133\r
134/**\r
135 Creates a new device path by appending the specified device path instance to the specified device\r
136 path.\r
137\r
138 This function creates a new device path by appending a copy of the device path\r
139 instance specified by DevicePathInstance to a copy of the device path specified\r
140 by DevicePath in a allocated buffer.\r
141 The end-of-device-path device node is moved after the end of the appended device\r
142 path instance and a new end-of-device-path-instance node is inserted between.\r
143 If DevicePath is NULL, then a copy if DevicePathInstance is returned.\r
144 If DevicePathInstance is NULL, then NULL is returned.\r
145 If DevicePath or DevicePathInstance is invalid, then NULL is returned.\r
146 If there is not enough memory to allocate space for the new device path, then\r
147 NULL is returned.\r
148 The memory is allocated from EFI boot services memory. It is the responsibility\r
149 of the caller to free the memory allocated.\r
150\r
151 @param DevicePath A pointer to a device path data structure.\r
152 @param DevicePathInstance A pointer to a device path instance.\r
153\r
154 @return A pointer to the new device path.\r
155\r
156**/\r
157EFI_DEVICE_PATH_PROTOCOL *\r
158AppendDevicePathInstance (\r
159 CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath, OPTIONAL\r
160 CONST EFI_DEVICE_PATH_PROTOCOL *DevicePathInstance OPTIONAL\r
161 )\r
162{\r
163 return UefiDevicePathLibAppendDevicePathInstance (DevicePath, DevicePathInstance);\r
164}\r
165\r
166/**\r
167 Creates a copy of the current device path instance and returns a pointer to the next device path\r
168 instance.\r
169\r
170 This function creates a copy of the current device path instance. It also updates\r
171 DevicePath to point to the next device path instance in the device path (or NULL\r
172 if no more) and updates Size to hold the size of the device path instance copy.\r
173 If DevicePath is NULL, then NULL is returned.\r
174 If DevicePath points to a invalid device path, then NULL is returned.\r
175 If there is not enough memory to allocate space for the new device path, then\r
176 NULL is returned.\r
177 The memory is allocated from EFI boot services memory. It is the responsibility\r
178 of the caller to free the memory allocated.\r
179 If Size is NULL, then ASSERT().\r
180\r
181 @param DevicePath On input, this holds the pointer to the current\r
182 device path instance. On output, this holds\r
183 the pointer to the next device path instance\r
184 or NULL if there are no more device path\r
185 instances in the device path pointer to a\r
186 device path data structure.\r
187 @param Size On output, this holds the size of the device\r
188 path instance, in bytes or zero, if DevicePath\r
189 is NULL.\r
190\r
191 @return A pointer to the current device path instance.\r
192\r
193**/\r
194EFI_DEVICE_PATH_PROTOCOL *\r
195GetNextDevicePathInstance (\r
196 EFI_DEVICE_PATH_PROTOCOL **DevicePath,\r
197 UINTN *Size\r
198 )\r
199{\r
200 return UefiDevicePathLibGetNextDevicePathInstance (DevicePath, Size);\r
201}\r
202\r
203/**\r
204 Creates a device node.\r
205\r
206 This function creates a new device node in a newly allocated buffer of size\r
207 NodeLength and initializes the device path node header with NodeType and NodeSubType.\r
208 The new device path node is returned.\r
209 If NodeLength is smaller than a device path header, then NULL is returned.\r
210 If there is not enough memory to allocate space for the new device path, then\r
211 NULL is returned.\r
212 The memory is allocated from EFI boot services memory. It is the responsibility\r
213 of the caller to free the memory allocated.\r
214\r
215 @param NodeType The device node type for the new device node.\r
216 @param NodeSubType The device node sub-type for the new device node.\r
217 @param NodeLength The length of the new device node.\r
218\r
219 @return The new device path.\r
220\r
221**/\r
222EFI_DEVICE_PATH_PROTOCOL *\r
223CreateDeviceNode (\r
224 UINT8 NodeType,\r
225 UINT8 NodeSubType,\r
226 UINT16 NodeLength\r
227 )\r
228{\r
229 return UefiDevicePathLibCreateDeviceNode (NodeType, NodeSubType, NodeLength);\r
230}\r
231\r
232/**\r
233 Determines if a device path is single or multi-instance.\r
234\r
235 This function returns TRUE if the device path specified by DevicePath is\r
236 multi-instance.\r
237 Otherwise, FALSE is returned.\r
238 If DevicePath is NULL or invalid, then FALSE is returned.\r
239\r
240 @param DevicePath A pointer to a device path data structure.\r
241\r
242 @retval TRUE DevicePath is multi-instance.\r
243 @retval FALSE DevicePath is not multi-instance, or DevicePath\r
244 is NULL or invalid.\r
245\r
246**/\r
247BOOLEAN\r
248IsDevicePathMultiInstance (\r
249 CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath\r
250 )\r
251{\r
252 return UefiDevicePathLibIsDevicePathMultiInstance (DevicePath);\r
253}\r
254\r
255/**\r
256 Convert text to the binary representation of a device node.\r
257\r
258 @param TextDeviceNode TextDeviceNode points to the text representation of a device\r
259 node. Conversion starts with the first character and continues\r
260 until the first non-device node character.\r
261\r
262 @return A pointer to the EFI device node or NULL if TextDeviceNode is NULL or there was\r
263 insufficient memory or text unsupported.\r
264\r
265**/\r
266EFI_DEVICE_PATH_PROTOCOL *\r
267ConvertTextToDeviceNode (\r
268 CONST CHAR16 *TextDeviceNode\r
269 )\r
270{\r
271 return UefiDevicePathLibConvertTextToDeviceNode (TextDeviceNode);\r
272}\r
273\r
274/**\r
275 Convert text to the binary representation of a device path.\r
276\r
277\r
278 @param TextDevicePath TextDevicePath points to the text representation of a device\r
279 path. Conversion starts with the first character and continues\r
280 until the first non-device node character.\r
281\r
282 @return A pointer to the allocated device path or NULL if TextDeviceNode is NULL or\r
283 there was insufficient memory.\r
284\r
285**/\r
286EFI_DEVICE_PATH_PROTOCOL *\r
287ConvertTextToDevicePath (\r
288 CONST CHAR16 *TextDevicePath\r
289 )\r
290{\r
291 return UefiDevicePathLibConvertTextToDevicePath (TextDevicePath);\r
292}\r