xref: /freebsd/lib/libefivar/uefi-dplib.h (revision 60de142cfc6cd444969b4ce11eff2f94ff4627e7)
1 /*-
2  * Copyright (c) 2017 Netflix, Inc.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23  * SUCH DAMAGE.
24  *
25  * $FreeBSD$
26  */
27 
28 /*
29  * Taken from MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.h
30  */
31 
32 /** @file
33   Definition for Device Path library.
34 
35 Copyright (c) 2013 - 2018, Intel Corporation. All rights reserved.<BR>
36 SPDX-License-Identifier: BSD-2-Clause-Patent
37 
38 **/
39 
40 #ifndef _UEFI_DEVICE_PATH_LIB_H_
41 #define _UEFI_DEVICE_PATH_LIB_H_
42 #include <Uefi.h>
43 #include <Protocol/DevicePathUtilities.h>
44 #include <Protocol/DebugPort.h>
45 #include <Protocol/DevicePathToText.h>
46 #include <Protocol/DevicePathFromText.h>
47 #include <Guid/PcAnsi.h>
48 #include <Library/DebugLib.h>
49 #include <Library/PrintLib.h>
50 #include <Library/BaseLib.h>
51 #include <Library/BaseMemoryLib.h>
52 #include <Library/MemoryAllocationLib.h>
53 #include <Library/UefiBootServicesTableLib.h>
54 #include <Library/DevicePathLib.h>
55 #include <Library/PcdLib.h>
56 #include <IndustryStandard/Bluetooth.h>
57 
58 #define IS_COMMA(a)                ((a) == ',')
59 #define IS_HYPHEN(a)               ((a) == '-')
60 #define IS_DOT(a)                  ((a) == '.')
61 #define IS_LEFT_PARENTH(a)         ((a) == '(')
62 #define IS_RIGHT_PARENTH(a)        ((a) == ')')
63 #define IS_SLASH(a)                ((a) == '/')
64 #define IS_NULL(a)                 ((a) == '\0')
65 
66 
67 //
68 // Private Data structure
69 //
70 typedef struct {
71   char  *Str;
72   UINTN   Count;
73   UINTN   Capacity;
74 } POOL_PRINT;
75 
76 typedef
77 EFI_DEVICE_PATH_PROTOCOL  *
78 (*DEVICE_PATH_FROM_TEXT) (
79   IN char *Str
80   );
81 
82 typedef
83 VOID
84 (*DEVICE_PATH_TO_TEXT) (
85   IN OUT POOL_PRINT  *Str,
86   IN VOID            *DevicePath,
87   IN BOOLEAN         DisplayOnly,
88   IN BOOLEAN         AllowShortcuts
89   );
90 
91 typedef struct {
92   UINT8                Type;
93   UINT8                SubType;
94   DEVICE_PATH_TO_TEXT  Function;
95 } DEVICE_PATH_TO_TEXT_TABLE;
96 
97 typedef struct {
98   UINT8                Type;
99   const char          *Text;
100 } DEVICE_PATH_TO_TEXT_GENERIC_TABLE;
101 
102 typedef struct {
103   const char                *DevicePathNodeText;
104   DEVICE_PATH_FROM_TEXT     Function;
105 } DEVICE_PATH_FROM_TEXT_TABLE;
106 
107 typedef struct {
108   BOOLEAN ClassExist;
109   UINT8   Class;
110   BOOLEAN SubClassExist;
111   UINT8   SubClass;
112 } USB_CLASS_TEXT;
113 
114 #define USB_CLASS_AUDIO            1
115 #define USB_CLASS_CDCCONTROL       2
116 #define USB_CLASS_HID              3
117 #define USB_CLASS_IMAGE            6
118 #define USB_CLASS_PRINTER          7
119 #define USB_CLASS_MASS_STORAGE     8
120 #define USB_CLASS_HUB              9
121 #define USB_CLASS_CDCDATA          10
122 #define USB_CLASS_SMART_CARD       11
123 #define USB_CLASS_VIDEO            14
124 #define USB_CLASS_DIAGNOSTIC       220
125 #define USB_CLASS_WIRELESS         224
126 
127 #define USB_CLASS_RESERVE          254
128 #define USB_SUBCLASS_FW_UPDATE     1
129 #define USB_SUBCLASS_IRDA_BRIDGE   2
130 #define USB_SUBCLASS_TEST          3
131 
132 #define RFC_1700_UDP_PROTOCOL      17
133 #define RFC_1700_TCP_PROTOCOL      6
134 
135 #pragma pack(1)
136 
137 typedef struct {
138   EFI_DEVICE_PATH_PROTOCOL  Header;
139   EFI_GUID                  Guid;
140   UINT8                     VendorDefinedData[1];
141 } VENDOR_DEFINED_HARDWARE_DEVICE_PATH;
142 
143 typedef struct {
144   EFI_DEVICE_PATH_PROTOCOL  Header;
145   EFI_GUID                  Guid;
146   UINT8                     VendorDefinedData[1];
147 } VENDOR_DEFINED_MESSAGING_DEVICE_PATH;
148 
149 typedef struct {
150   EFI_DEVICE_PATH_PROTOCOL  Header;
151   EFI_GUID                  Guid;
152   UINT8                     VendorDefinedData[1];
153 } VENDOR_DEFINED_MEDIA_DEVICE_PATH;
154 
155 typedef struct {
156   EFI_DEVICE_PATH_PROTOCOL  Header;
157   UINT32                    Hid;
158   UINT32                    Uid;
159   UINT32                    Cid;
160   CHAR8                     HidUidCidStr[3];
161 } ACPI_EXTENDED_HID_DEVICE_PATH_WITH_STR;
162 
163 typedef struct {
164   EFI_DEVICE_PATH_PROTOCOL  Header;
165   UINT16                    NetworkProtocol;
166   UINT16                    LoginOption;
167   UINT64                    Lun;
168   UINT16                    TargetPortalGroupTag;
169   CHAR8                     TargetName[1];
170 } ISCSI_DEVICE_PATH_WITH_NAME;
171 
172 typedef struct {
173   EFI_DEVICE_PATH_PROTOCOL  Header;
174   EFI_GUID                  Guid;
175   UINT8                     VendorDefinedData[1];
176 } VENDOR_DEVICE_PATH_WITH_DATA;
177 
178 #pragma pack()
179 
180 #ifdef FreeBSD		/* Remove these on FreeBSD */
181 
182 /**
183   Returns the size of a device path in bytes.
184 
185   This function returns the size, in bytes, of the device path data structure
186   specified by DevicePath including the end of device path node.
187   If DevicePath is NULL or invalid, then 0 is returned.
188 
189   @param  DevicePath  A pointer to a device path data structure.
190 
191   @retval 0           If DevicePath is NULL or invalid.
192   @retval Others      The size of a device path in bytes.
193 
194 **/
195 UINTN
196 EFIAPI
197 UefiDevicePathLibGetDevicePathSize (
198   IN CONST EFI_DEVICE_PATH_PROTOCOL  *DevicePath
199   );
200 
201 /**
202   Creates a new copy of an existing device path.
203 
204   This function allocates space for a new copy of the device path specified by DevicePath.
205   If DevicePath is NULL, then NULL is returned.  If the memory is successfully
206   allocated, then the contents of DevicePath are copied to the newly allocated
207   buffer, and a pointer to that buffer is returned.  Otherwise, NULL is returned.
208   The memory for the new device path is allocated from EFI boot services memory.
209   It is the responsibility of the caller to free the memory allocated.
210 
211   @param  DevicePath    A pointer to a device path data structure.
212 
213   @retval NULL          DevicePath is NULL or invalid.
214   @retval Others        A pointer to the duplicated device path.
215 
216 **/
217 EFI_DEVICE_PATH_PROTOCOL *
218 EFIAPI
219 UefiDevicePathLibDuplicateDevicePath (
220   IN CONST EFI_DEVICE_PATH_PROTOCOL  *DevicePath
221   );
222 
223 /**
224   Creates a new device path by appending a second device path to a first device path.
225 
226   This function creates a new device path by appending a copy of SecondDevicePath
227   to a copy of FirstDevicePath in a newly allocated buffer.  Only the end-of-device-path
228   device node from SecondDevicePath is retained. The newly created device path is
229   returned. If FirstDevicePath is NULL, then it is ignored, and a duplicate of
230   SecondDevicePath is returned.  If SecondDevicePath is NULL, then it is ignored,
231   and a duplicate of FirstDevicePath is returned. If both FirstDevicePath and
232   SecondDevicePath are NULL, then a copy of an end-of-device-path is returned.
233 
234   If there is not enough memory for the newly allocated buffer, then NULL is returned.
235   The memory for the new device path is allocated from EFI boot services memory.
236   It is the responsibility of the caller to free the memory allocated.
237 
238   @param  FirstDevicePath            A pointer to a device path data structure.
239   @param  SecondDevicePath           A pointer to a device path data structure.
240 
241   @retval NULL      If there is not enough memory for the newly allocated buffer.
242   @retval NULL      If FirstDevicePath or SecondDevicePath is invalid.
243   @retval Others    A pointer to the new device path if success.
244                     Or a copy an end-of-device-path if both FirstDevicePath and SecondDevicePath are NULL.
245 
246 **/
247 EFI_DEVICE_PATH_PROTOCOL *
248 EFIAPI
249 UefiDevicePathLibAppendDevicePath (
250   IN CONST EFI_DEVICE_PATH_PROTOCOL  *FirstDevicePath   OPTIONAL,
251   IN CONST EFI_DEVICE_PATH_PROTOCOL  *SecondDevicePath  OPTIONAL
252   );
253 
254 /**
255   Creates a new path by appending the device node to the device path.
256 
257   This function creates a new device path by appending a copy of the device node
258   specified by DevicePathNode to a copy of the device path specified by DevicePath
259   in an allocated buffer. The end-of-device-path device node is moved after the
260   end of the appended device node.
261   If DevicePathNode is NULL then a copy of DevicePath is returned.
262   If DevicePath is NULL then a copy of DevicePathNode, followed by an end-of-device
263   path device node is returned.
264   If both DevicePathNode and DevicePath are NULL then a copy of an end-of-device-path
265   device node is returned.
266   If there is not enough memory to allocate space for the new device path, then
267   NULL is returned.
268   The memory is allocated from EFI boot services memory. It is the responsibility
269   of the caller to free the memory allocated.
270 
271   @param  DevicePath                 A pointer to a device path data structure.
272   @param  DevicePathNode             A pointer to a single device path node.
273 
274   @retval NULL      If there is not enough memory for the new device path.
275   @retval Others    A pointer to the new device path if success.
276                     A copy of DevicePathNode followed by an end-of-device-path node
277                     if both FirstDevicePath and SecondDevicePath are NULL.
278                     A copy of an end-of-device-path node if both FirstDevicePath
279                     and SecondDevicePath are NULL.
280 
281 **/
282 EFI_DEVICE_PATH_PROTOCOL *
283 EFIAPI
284 UefiDevicePathLibAppendDevicePathNode (
285   IN CONST EFI_DEVICE_PATH_PROTOCOL  *DevicePath      OPTIONAL,
286   IN CONST EFI_DEVICE_PATH_PROTOCOL  *DevicePathNode  OPTIONAL
287   );
288 
289 /**
290   Creates a new device path by appending the specified device path instance to the specified device
291   path.
292 
293   This function creates a new device path by appending a copy of the device path
294   instance specified by DevicePathInstance to a copy of the device path specified
295   by DevicePath in a allocated buffer.
296   The end-of-device-path device node is moved after the end of the appended device
297   path instance and a new end-of-device-path-instance node is inserted between.
298   If DevicePath is NULL, then a copy if DevicePathInstance is returned.
299   If DevicePathInstance is NULL, then NULL is returned.
300   If DevicePath or DevicePathInstance is invalid, then NULL is returned.
301   If there is not enough memory to allocate space for the new device path, then
302   NULL is returned.
303   The memory is allocated from EFI boot services memory. It is the responsibility
304   of the caller to free the memory allocated.
305 
306   @param  DevicePath                 A pointer to a device path data structure.
307   @param  DevicePathInstance         A pointer to a device path instance.
308 
309   @return A pointer to the new device path.
310 
311 **/
312 EFI_DEVICE_PATH_PROTOCOL *
313 EFIAPI
314 UefiDevicePathLibAppendDevicePathInstance (
315   IN CONST EFI_DEVICE_PATH_PROTOCOL  *DevicePath         OPTIONAL,
316   IN CONST EFI_DEVICE_PATH_PROTOCOL  *DevicePathInstance OPTIONAL
317   );
318 
319 /**
320   Creates a copy of the current device path instance and returns a pointer to the next device path
321   instance.
322 
323   This function creates a copy of the current device path instance. It also updates
324   DevicePath to point to the next device path instance in the device path (or NULL
325   if no more) and updates Size to hold the size of the device path instance copy.
326   If DevicePath is NULL, then NULL is returned.
327   If DevicePath points to a invalid device path, then NULL is returned.
328   If there is not enough memory to allocate space for the new device path, then
329   NULL is returned.
330   The memory is allocated from EFI boot services memory. It is the responsibility
331   of the caller to free the memory allocated.
332   If Size is NULL, then ASSERT().
333 
334   @param  DevicePath                 On input, this holds the pointer to the current
335                                      device path instance. On output, this holds
336                                      the pointer to the next device path instance
337                                      or NULL if there are no more device path
338                                      instances in the device path pointer to a
339                                      device path data structure.
340   @param  Size                       On output, this holds the size of the device
341                                      path instance, in bytes or zero, if DevicePath
342                                      is NULL.
343 
344   @return A pointer to the current device path instance.
345 
346 **/
347 EFI_DEVICE_PATH_PROTOCOL *
348 EFIAPI
349 UefiDevicePathLibGetNextDevicePathInstance (
350   IN OUT EFI_DEVICE_PATH_PROTOCOL    **DevicePath,
351   OUT UINTN                          *Size
352   );
353 
354 /**
355   Creates a device node.
356 
357   This function creates a new device node in a newly allocated buffer of size
358   NodeLength and initializes the device path node header with NodeType and NodeSubType.
359   The new device path node is returned.
360   If NodeLength is smaller than a device path header, then NULL is returned.
361   If there is not enough memory to allocate space for the new device path, then
362   NULL is returned.
363   The memory is allocated from EFI boot services memory. It is the responsibility
364   of the caller to free the memory allocated.
365 
366   @param  NodeType                   The device node type for the new device node.
367   @param  NodeSubType                The device node sub-type for the new device node.
368   @param  NodeLength                 The length of the new device node.
369 
370   @return The new device path.
371 
372 **/
373 EFI_DEVICE_PATH_PROTOCOL *
374 EFIAPI
375 UefiDevicePathLibCreateDeviceNode (
376   IN UINT8                           NodeType,
377   IN UINT8                           NodeSubType,
378   IN UINT16                          NodeLength
379   );
380 
381 /**
382   Determines if a device path is single or multi-instance.
383 
384   This function returns TRUE if the device path specified by DevicePath is
385   multi-instance.
386   Otherwise, FALSE is returned.
387   If DevicePath is NULL or invalid, then FALSE is returned.
388 
389   @param  DevicePath                 A pointer to a device path data structure.
390 
391   @retval  TRUE                      DevicePath is multi-instance.
392   @retval  FALSE                     DevicePath is not multi-instance, or DevicePath
393                                      is NULL or invalid.
394 
395 **/
396 BOOLEAN
397 EFIAPI
398 UefiDevicePathLibIsDevicePathMultiInstance (
399   IN CONST EFI_DEVICE_PATH_PROTOCOL  *DevicePath
400   );
401 
402 
403 /**
404   Converts a device path to its text representation.
405 
406   @param DevicePath      A Pointer to the device to be converted.
407   @param DisplayOnly     If DisplayOnly is TRUE, then the shorter text representation
408                          of the display node is used, where applicable. If DisplayOnly
409                          is FALSE, then the longer text representation of the display node
410                          is used.
411   @param AllowShortcuts  If AllowShortcuts is TRUE, then the shortcut forms of text
412                          representation for a device node can be used, where applicable.
413 
414   @return A pointer to the allocated text representation of the device path or
415           NULL if DeviceNode is NULL or there was insufficient memory.
416 
417 **/
418 CHAR16 *
419 EFIAPI
420 UefiDevicePathLibConvertDevicePathToText (
421   IN CONST EFI_DEVICE_PATH_PROTOCOL   *DevicePath,
422   IN BOOLEAN                          DisplayOnly,
423   IN BOOLEAN                          AllowShortcuts
424   );
425 
426 /**
427   Converts a device node to its string representation.
428 
429   @param DeviceNode        A Pointer to the device node to be converted.
430   @param DisplayOnly       If DisplayOnly is TRUE, then the shorter text representation
431                            of the display node is used, where applicable. If DisplayOnly
432                            is FALSE, then the longer text representation of the display node
433                            is used.
434   @param AllowShortcuts    If AllowShortcuts is TRUE, then the shortcut forms of text
435                            representation for a device node can be used, where applicable.
436 
437   @return A pointer to the allocated text representation of the device node or NULL if DeviceNode
438           is NULL or there was insufficient memory.
439 
440 **/
441 CHAR16 *
442 EFIAPI
443 UefiDevicePathLibConvertDeviceNodeToText (
444   IN CONST EFI_DEVICE_PATH_PROTOCOL  *DeviceNode,
445   IN BOOLEAN                         DisplayOnly,
446   IN BOOLEAN                         AllowShortcuts
447   );
448 
449 /**
450   Convert text to the binary representation of a device node.
451 
452   @param TextDeviceNode  TextDeviceNode points to the text representation of a device
453                          node. Conversion starts with the first character and continues
454                          until the first non-device node character.
455 
456   @return A pointer to the EFI device node or NULL if TextDeviceNode is NULL or there was
457           insufficient memory or text unsupported.
458 
459 **/
460 EFI_DEVICE_PATH_PROTOCOL *
461 EFIAPI
462 UefiDevicePathLibConvertTextToDeviceNode (
463   IN CONST CHAR16 *TextDeviceNode
464   );
465 
466 /**
467   Convert text to the binary representation of a device path.
468 
469 
470   @param TextDevicePath  TextDevicePath points to the text representation of a device
471                          path. Conversion starts with the first character and continues
472                          until the first non-device node character.
473 
474   @return A pointer to the allocated device path or NULL if TextDeviceNode is NULL or
475           there was insufficient memory.
476 
477 **/
478 EFI_DEVICE_PATH_PROTOCOL *
479 EFIAPI
480 UefiDevicePathLibConvertTextToDevicePath (
481   IN CONST CHAR16 *TextDevicePath
482   );
483 #else
484 
485 /*
486  * Small FreeBSD shim layer. Fast and lose hacks to make this code work with FreeBSD.
487  */
488 
489 #include <ctype.h>
490 
491 #define _PCD_GET_MODE_32_PcdMaximumDevicePathNodeCount 1000
492 #define MAX_UINTN UINTPTR_MAX
493 
494 #define AllocatePool(x) malloc(x)
495 #define AllocateZeroPool(x) calloc(1,x)
496 #define AsciiStrLen(s) strlen(s)
497 #define CopyGuid(dst, src) memcpy(dst, src, sizeof(uuid_t))
498 #define CopyMem(d, s, l) memcpy(d, s, l)
499 #define FreePool(x) free(x)
500 #define LShiftU64(x, s) ((x) << s)
501 #define ReadUnaligned64(x)    le64dec(x)
502 #define ReallocatePool(old, new, ptr) realloc(ptr, new)
503 /*
504  * Quirky StrCmp returns 0 if equal, 1 if not. This is what the code
505  * expects, though that expectation is likely a bug (it casts the
506  * return value. EDK2's StrCmp returns values just like C's strcmp,
507  * but the parse code casts this to an UINTN, which is bogus. This
508  * definition papers over that bogusness to do the right thing.  If
509  * iSCSI protocol string processing is ever fixed, we can remove this
510  * bletcherous kludge.
511  */
512 #define StrCmp(a, b) (strcmp(a, b) != 0)
513 #define StrCpyS(d, l, s) strcpy(d, s)
514 #define StrHexToUint64(x) strtoll(x, NULL, 16)
515 #define StrHexToUintn(x) strtoll(x, NULL, 16)
516 #define StrLen(x) strlen(x)
517 #define StrSize(x) (strlen(x) + 1)
518 #define StrnCatS(d, l, s, len) strncat(d, s, len)
519 #define StrnCmp(a, b, n) strncmp(a, b, n)
520 #define StrnLenS(str, max) strlen(str)
521 #define Strtoi(x) strtol(x, NULL, 0)
522 #define Strtoi64(x, y) *(long long *)y = strtoll(x, NULL, 0)
523 #define SwapBytes64(u64) bswap64(u64)
524 #define UnicodeStrToAsciiStrS(src, dest, len) strlcpy(dest, src, len)
525 #define ZeroMem(p,l) memset(p, 0, l)
526 
527 #undef ASSERT
528 #define ASSERT(x)
529 
530 /*
531  * Define AllocateCopyPool and others so that we "forget" about the
532  * previous non-static deifnition since we want these to be static
533  * inlines.
534  */
535 #define AllocateCopyPool AllocateCopyPoolFreeBSD
536 #define CompareGuid CompareGuidFreeBSD
537 #define StrHexToBytes StrHexToBytesFreeBSD
538 #define StrToGuid StrToGuidFreeBSD
539 #define WriteUnaligned64 WriteUnaligned64FreeBSD
540 
541 static inline void *
542 AllocateCopyPool(size_t l, const void *p)
543 {
544 	void *rv;
545 
546 	rv = malloc(l);
547 	if (rv == NULL)
548 		return NULL;
549 	memcpy(rv, p, l);
550 	return (rv);
551 }
552 
553 static inline BOOLEAN
554 CompareGuid (const GUID *g1, const GUID *g2)
555 {
556 	uint32_t ignored_status;
557 
558 	return (uuid_compare((const uuid_t *)g1, (const uuid_t *)g2,
559 	    &ignored_status) == 0);
560 }
561 
562 static inline int
563 StrHexToBytes(const char *str, size_t len, uint8_t *buf, size_t buflen)
564 {
565 	size_t i;
566 	char hex[3];
567 
568 	/*
569 	 * Sanity check preconditions.
570 	 */
571 	if (buflen != len / 2 || (len % 2) == 1)
572 		return 1;
573 	for (i = 0; i < len; i += 2) {
574 		if (!isxdigit(str[i]) || !isxdigit(str[i + 1]))
575 			return 1;
576 		hex[0] = str[i];
577 		hex[1] = str[i + 1];
578 		hex[2] = '\0';
579 		buf[i / 2] = strtol(hex, NULL, 16);
580 	}
581 	return 0;
582 }
583 
584 static inline void
585 StrToGuid(const char *str, GUID *guid)
586 {
587 	uint32_t status;
588 
589 	uuid_from_string(str, (uuid_t *)guid, &status);
590 }
591 
592 static inline void
593 WriteUnaligned64(void *ptr, uint64_t val)
594 {
595 	memcpy(ptr, &val, sizeof(val));
596 }
597 
598 /*
599  * Hack to allow converting %g to %s in printfs. Hack because
600  * it's single entry, uses a static buffer, etc. Sufficient for
601  * the day for this file though. IF you ever have to convert
602  * two %g's in one format, punt. Did I mention this was super lame.
603  * Not to mention it's name.... Also, the error GUID is horrific.
604  */
605 static inline const char *
606 guid_str(const GUID *g)
607 {
608 	static char buf[36 + 1];
609 	char *str = NULL;
610 	int32_t ignored_status;
611 
612 	uuid_to_string((const uuid_t *)g, &str, &ignored_status);
613 	if (str != NULL)
614 		strlcpy(buf, str, sizeof(buf));
615 	else
616 		strlcpy(buf, "groot-cannot-decode-guid-groot-smash",
617 		    sizeof(buf)); /* ^^^^^^^ 36 characters ^^^^^^^ */
618 	free(str);
619 	return buf;
620 }
621 #define G(x) guid_str((const GUID *)(const void *)x)
622 #endif
623 
624 #undef GLOBAL_REMOVE_IF_UNREFERENCED
625 #define GLOBAL_REMOVE_IF_UNREFERENCED static
626 
627 #endif
628