]> code.delx.au - refind/blob - refind/lib.h
c908c11d2ed088de3d7bf8c3f9609d28663f06b5
[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 // Partition names to be ignored when setting volume name
83 #define IGNORE_PARTITION_NAMES L"Microsoft basic data,Linux filesystem,Apple HFS/HFS+"
84
85 EFI_STATUS InitRefitLib(IN EFI_HANDLE ImageHandle);
86 VOID UninitRefitLib(VOID);
87 EFI_STATUS ReinitRefitLib(VOID);
88
89 EFI_STATUS EfivarGetRaw(EFI_GUID *vendor, CHAR16 *name, CHAR8 **buffer, UINTN *size);
90 EFI_STATUS EfivarSetRaw(EFI_GUID *vendor, CHAR16 *name, CHAR8 *buf, UINTN size, BOOLEAN persistent);
91
92 VOID CleanUpPathNameSlashes(IN OUT CHAR16 *PathName);
93 VOID CreateList(OUT VOID ***ListPtr, OUT UINTN *ElementCount, IN UINTN InitialElementCount);
94 VOID AddListElement(IN OUT VOID ***ListPtr, IN OUT UINTN *ElementCount, IN VOID *NewElement);
95 VOID FreeList(IN OUT VOID ***ListPtr, IN OUT UINTN *ElementCount);
96
97 VOID ExtractLegacyLoaderPaths(EFI_DEVICE_PATH **PathList, UINTN MaxPaths, EFI_DEVICE_PATH **HardcodedPathList);
98
99 VOID SetVolumeBadgeIcon(REFIT_VOLUME *Volume);
100 VOID ScanVolumes(VOID);
101
102 BOOLEAN FileExists(IN EFI_FILE *BaseDir, IN CHAR16 *RelativePath);
103
104 EFI_STATUS DirNextEntry(IN EFI_FILE *Directory, IN OUT EFI_FILE_INFO **DirEntry, IN UINTN FilterMode);
105
106 VOID DirIterOpen(IN EFI_FILE *BaseDir, IN CHAR16 *RelativePath OPTIONAL, OUT REFIT_DIR_ITER *DirIter);
107 BOOLEAN DirIterNext(IN OUT REFIT_DIR_ITER *DirIter, IN UINTN FilterMode, IN CHAR16 *FilePattern OPTIONAL, OUT EFI_FILE_INFO **DirEntry);
108 EFI_STATUS DirIterClose(IN OUT REFIT_DIR_ITER *DirIter);
109
110 CHAR16 * Basename(IN CHAR16 *Path);
111 CHAR16 * StripEfiExtension(CHAR16 *FileName);
112
113 INTN FindMem(IN VOID *Buffer, IN UINTN BufferLength, IN VOID *SearchString, IN UINTN SearchStringLength);
114 VOID ReinitVolumes(VOID);
115
116 BOOLEAN StriSubCmp(IN CHAR16 *TargetStr, IN CHAR16 *BigStr);
117 VOID MergeStrings(IN OUT CHAR16 **First, IN CHAR16 *Second, CHAR16 AddChar);
118 CHAR16 *FindExtension(IN CHAR16 *Path);
119 CHAR16 *FindLastDirName(IN CHAR16 *Path);
120 CHAR16 *FindPath(IN CHAR16* FullPath);
121 BOOLEAN LimitStringLength(CHAR16 *TheString, UINTN Limit);
122 VOID FindVolumeAndFilename(IN EFI_DEVICE_PATH *loadpath, OUT REFIT_VOLUME **DeviceVolume, OUT CHAR16 **loader);
123 BOOLEAN SplitVolumeAndFilename(IN OUT CHAR16 **Path, OUT CHAR16 **VolName);
124 CHAR16 *FindNumbers(IN CHAR16 *InString);
125 CHAR16 *FindCommaDelimited(IN CHAR16 *InString, IN UINTN Index);
126 INTN FindSubString(IN CHAR16 *SmallString, IN CHAR16 *BigString);
127 VOID SplitPathName(CHAR16 *InPath, CHAR16 **VolName, CHAR16 **Path, CHAR16 **Filename);
128 BOOLEAN IsIn(IN CHAR16 *Filename, IN CHAR16 *List);
129 BOOLEAN IsInSubstring(IN CHAR16 *BigString, IN CHAR16 *List);
130 BOOLEAN FilenameIn(IN REFIT_VOLUME *Volume, IN CHAR16 *Directory, IN CHAR16 *Filename, IN CHAR16 *List);
131 BOOLEAN VolumeNumberToName(REFIT_VOLUME *Volume, CHAR16 **VolName);
132 VOID MyFreePool(IN OUT VOID *Pointer);
133
134 BOOLEAN EjectMedia(VOID);
135
136 UINT64 StrToHex(CHAR16 *Input, UINTN Position, UINTN NumChars);
137 BOOLEAN IsGuid(CHAR16 *UnknownString);
138 CHAR16 * GuidAsString(EFI_GUID *GuidData);
139 EFI_GUID StringAsGuid(CHAR16 * InString);
140 BOOLEAN GuidsAreEqual(EFI_GUID *Guid1, EFI_GUID *Guid2);
141
142 #endif