]> code.delx.au - refind/blob - refind/lib.h
Added new "csr_rotate" option for "showtools", and matching
[refind] / refind / lib.h
1 /*
2 * refit/lib.h
3 * General header file
4 *
5 * Copyright (c) 2006-2009 Christoph Pfisterer
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are
10 * met:
11 *
12 * * Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * * Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the
18 * distribution.
19 *
20 * * Neither the name of Christoph Pfisterer nor the names of the
21 * contributors may be used to endorse or promote products derived
22 * from this software without specific prior written permission.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
27 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
28 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
29 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
30 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
31 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
32 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
33 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
34 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 */
36 /*
37 * Modifications copyright (c) 2012-2015 Roderick W. Smith
38 *
39 * Modifications distributed under the terms of the GNU General Public
40 * License (GPL) version 3 (GPLv3), a copy of which must be distributed
41 * with this source code or binaries made from it.
42 *
43 */
44
45 #ifndef __LIB_H_
46 #define __LIB_H_
47
48 #ifdef __MAKEWITH_GNUEFI
49 #include "efi.h"
50 #include "efilib.h"
51 #define EFI_DEVICE_PATH_PROTOCOL EFI_DEVICE_PATH
52 #else
53 #include "../include/tiano_includes.h"
54 #endif
55
56 #include "global.h"
57
58 #include "libeg.h"
59
60 //
61 // lib module
62 //
63
64 // types
65
66 typedef struct {
67 EFI_STATUS LastStatus;
68 EFI_FILE_HANDLE DirHandle;
69 BOOLEAN CloseDirHandle;
70 EFI_FILE_INFO *LastFileInfo;
71 } REFIT_DIR_ITER;
72
73 #define DISK_KIND_INTERNAL (0)
74 #define DISK_KIND_EXTERNAL (1)
75 #define DISK_KIND_OPTICAL (2)
76 #define DISK_KIND_NET (3)
77
78 #define VOL_UNREADABLE 999
79
80 #define IS_EXTENDED_PART_TYPE(type) ((type) == 0x05 || (type) == 0x0f || (type) == 0x85)
81
82 // GPT attributes of interest to us for Freedesktop.org Discoverable
83 // Partitions Specification....
84 #define GPT_READ_ONLY 0x1000000000000000
85 #define GPT_NO_AUTOMOUNT 0x8000000000000000
86
87 // Partition names to be ignored when setting volume name
88 #define IGNORE_PARTITION_NAMES L"Microsoft basic data,Linux filesystem,Apple HFS/HFS+"
89
90 extern EFI_GUID gFreedesktopRootGuid;
91
92 EFI_STATUS InitRefitLib(IN EFI_HANDLE ImageHandle);
93 VOID UninitRefitLib(VOID);
94 EFI_STATUS ReinitRefitLib(VOID);
95
96 EFI_STATUS EfivarGetRaw(EFI_GUID *vendor, CHAR16 *name, CHAR8 **buffer, UINTN *size);
97 EFI_STATUS EfivarSetRaw(EFI_GUID *vendor, CHAR16 *name, CHAR8 *buf, UINTN size, BOOLEAN persistent);
98
99 VOID CleanUpPathNameSlashes(IN OUT CHAR16 *PathName);
100 VOID CreateList(OUT VOID ***ListPtr, OUT UINTN *ElementCount, IN UINTN InitialElementCount);
101 VOID AddListElement(IN OUT VOID ***ListPtr, IN OUT UINTN *ElementCount, IN VOID *NewElement);
102 VOID FreeList(IN OUT VOID ***ListPtr, IN OUT UINTN *ElementCount);
103
104 VOID SetVolumeBadgeIcon(REFIT_VOLUME *Volume);
105 VOID ScanVolumes(VOID);
106
107 BOOLEAN FileExists(IN EFI_FILE *BaseDir, IN CHAR16 *RelativePath);
108
109 EFI_STATUS DirNextEntry(IN EFI_FILE *Directory, IN OUT EFI_FILE_INFO **DirEntry, IN UINTN FilterMode);
110
111 VOID DirIterOpen(IN EFI_FILE *BaseDir, IN CHAR16 *RelativePath OPTIONAL, OUT REFIT_DIR_ITER *DirIter);
112 BOOLEAN DirIterNext(IN OUT REFIT_DIR_ITER *DirIter, IN UINTN FilterMode, IN CHAR16 *FilePattern OPTIONAL, OUT EFI_FILE_INFO **DirEntry);
113 EFI_STATUS DirIterClose(IN OUT REFIT_DIR_ITER *DirIter);
114
115 CHAR16 * Basename(IN CHAR16 *Path);
116 CHAR16 * StripEfiExtension(CHAR16 *FileName);
117
118 INTN FindMem(IN VOID *Buffer, IN UINTN BufferLength, IN VOID *SearchString, IN UINTN SearchStringLength);
119 VOID ReinitVolumes(VOID);
120
121 BOOLEAN StriSubCmp(IN CHAR16 *TargetStr, IN CHAR16 *BigStr);
122 BOOLEAN MyStriCmp(IN CONST CHAR16 *String1, IN CONST CHAR16 *String2);
123 CHAR16* MyStrStr (IN CHAR16 *String, IN CHAR16 *StrCharSet);
124 VOID ToLower(CHAR16 * MyString);
125 VOID MergeStrings(IN OUT CHAR16 **First, IN CHAR16 *Second, CHAR16 AddChar);
126 VOID MergeWords(CHAR16 **MergeTo, CHAR16 *InString, CHAR16 AddChar);
127 CHAR16 *FindExtension(IN CHAR16 *Path);
128 CHAR16 *FindLastDirName(IN CHAR16 *Path);
129 CHAR16 *FindPath(IN CHAR16* FullPath);
130 BOOLEAN LimitStringLength(CHAR16 *TheString, UINTN Limit);
131 VOID FindVolumeAndFilename(IN EFI_DEVICE_PATH *loadpath, OUT REFIT_VOLUME **DeviceVolume, OUT CHAR16 **loader);
132 BOOLEAN SplitVolumeAndFilename(IN OUT CHAR16 **Path, OUT CHAR16 **VolName);
133 CHAR16 *FindNumbers(IN CHAR16 *InString);
134 CHAR16 *FindCommaDelimited(IN CHAR16 *InString, IN UINTN Index);
135 VOID SplitPathName(CHAR16 *InPath, CHAR16 **VolName, CHAR16 **Path, CHAR16 **Filename);
136 BOOLEAN IsIn(IN CHAR16 *SmallString, IN CHAR16 *List);
137 BOOLEAN IsInSubstring(IN CHAR16 *BigString, IN CHAR16 *List);
138 BOOLEAN FilenameIn(IN REFIT_VOLUME *Volume, IN CHAR16 *Directory, IN CHAR16 *Filename, IN CHAR16 *List);
139 BOOLEAN VolumeNumberToName(REFIT_VOLUME *Volume, CHAR16 **VolName);
140 VOID MyFreePool(IN OUT VOID *Pointer);
141
142 BOOLEAN EjectMedia(VOID);
143
144 UINT64 StrToHex(CHAR16 *Input, UINTN Position, UINTN NumChars);
145 BOOLEAN IsGuid(CHAR16 *UnknownString);
146 CHAR16 * GuidAsString(EFI_GUID *GuidData);
147 EFI_GUID StringAsGuid(CHAR16 * InString);
148 BOOLEAN GuidsAreEqual(EFI_GUID *Guid1, EFI_GUID *Guid2);
149
150 #endif