]> git.proxmox.com Git - systemd.git/blob - src/boot/efi/util.h
New upstream version 240
[systemd.git] / src / boot / efi / util.h
1 /* SPDX-License-Identifier: LGPL-2.1+ */
2 #pragma once
3
4 #include <efi.h>
5 #include <efilib.h>
6
7 #define ELEMENTSOF(x) (sizeof(x)/sizeof((x)[0]))
8 #define OFFSETOF(x,y) __builtin_offsetof(x,y)
9
10 static inline const CHAR16 *yes_no(BOOLEAN b) {
11 return b ? L"yes" : L"no";
12 }
13
14 EFI_STATUS parse_boolean(const CHAR8 *v, BOOLEAN *b);
15
16 UINT64 ticks_read(void);
17 UINT64 ticks_freq(void);
18 UINT64 time_usec(void);
19
20 EFI_STATUS efivar_set(const CHAR16 *name, const CHAR16 *value, BOOLEAN persistent);
21 EFI_STATUS efivar_set_raw(const EFI_GUID *vendor, const CHAR16 *name, const VOID *buf, UINTN size, BOOLEAN persistent);
22 EFI_STATUS efivar_set_int(CHAR16 *name, UINTN i, BOOLEAN persistent);
23 VOID efivar_set_time_usec(CHAR16 *name, UINT64 usec);
24
25 EFI_STATUS efivar_get(const CHAR16 *name, CHAR16 **value);
26 EFI_STATUS efivar_get_raw(const EFI_GUID *vendor, const CHAR16 *name, CHAR8 **buffer, UINTN *size);
27 EFI_STATUS efivar_get_int(const CHAR16 *name, UINTN *i);
28
29 CHAR8 *strchra(CHAR8 *s, CHAR8 c);
30 CHAR16 *stra_to_path(CHAR8 *stra);
31 CHAR16 *stra_to_str(CHAR8 *stra);
32
33 EFI_STATUS file_read(EFI_FILE_HANDLE dir, const CHAR16 *name, UINTN off, UINTN size, CHAR8 **content, UINTN *content_size);
34
35 static inline void FreePoolp(void *p) {
36 void *q = *(void**) p;
37
38 if (!q)
39 return;
40
41 FreePool(q);
42 }
43
44 #define _cleanup_(x) __attribute__((__cleanup__(x)))
45 #define _cleanup_freepool_ _cleanup_(FreePoolp)
46
47 static inline void FileHandleClosep(EFI_FILE_HANDLE *handle) {
48 if (!*handle)
49 return;
50
51 uefi_call_wrapper((*handle)->Close, 1, *handle);
52 }
53
54 const EFI_GUID loader_guid;
55
56 #define UINTN_MAX (~(UINTN)0)
57 #define INTN_MAX ((INTN)(UINTN_MAX>>1))