5 * Copyright (c) 2006-2009 Christoph Pfisterer
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are
12 * * Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
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
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.
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.
37 * Modifications copyright (c) 2012 Roderick W. Smith
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.
48 #ifdef __MAKEWITH_GNUEFI
54 This protocol can be used on any device handle to obtain generic path/location
55 information concerning the physical device or logical device. If the handle does
56 not logically map to a physical device, the handle may not necessarily support
57 the device path protocol. The device path describes the location of the device
58 the handle is for. The size of the Device Path can be determined from the structures
59 that make up the Device Path.
62 UINT8 Type
; ///< 0x01 Hardware Device Path.
63 ///< 0x02 ACPI Device Path.
64 ///< 0x03 Messaging Device Path.
65 ///< 0x04 Media Device Path.
66 ///< 0x05 BIOS Boot Specification Device Path.
67 ///< 0x7F End of Hardware Device Path.
69 UINT8 SubType
; ///< Varies by Type
70 ///< 0xFF End Entire Device Path, or
71 ///< 0x01 End This Instance of a Device Path and start a new
74 UINT8 Length
[2]; ///< Specific Device Path data. Type and Sub-Type define
75 ///< type of data. Size of data is included in Length.
77 } EFI_DEVICE_PATH_PROTOCOL
;
81 #include "../include/tiano_includes.h"
95 EFI_STATUS LastStatus
;
96 EFI_FILE_HANDLE DirHandle
;
97 BOOLEAN CloseDirHandle
;
98 EFI_FILE_INFO
*LastFileInfo
;
101 #define DISK_KIND_INTERNAL (0)
102 #define DISK_KIND_EXTERNAL (1)
103 #define DISK_KIND_OPTICAL (2)
105 #define VOL_UNREADABLE 999
107 #define IS_EXTENDED_PART_TYPE(type) ((type) == 0x05 || (type) == 0x0f || (type) == 0x85)
109 EFI_STATUS
InitRefitLib(IN EFI_HANDLE ImageHandle
);
110 VOID
UninitRefitLib(VOID
);
111 EFI_STATUS
ReinitRefitLib(VOID
);
113 VOID
CleanUpPathNameSlashes(IN OUT CHAR16
*PathName
);
114 VOID
CreateList(OUT VOID
***ListPtr
, OUT UINTN
*ElementCount
, IN UINTN InitialElementCount
);
115 VOID
AddListElement(IN OUT VOID
***ListPtr
, IN OUT UINTN
*ElementCount
, IN VOID
*NewElement
);
116 VOID
FreeList(IN OUT VOID
***ListPtr
, IN OUT UINTN
*ElementCount
);
118 VOID
ExtractLegacyLoaderPaths(EFI_DEVICE_PATH
**PathList
, UINTN MaxPaths
, EFI_DEVICE_PATH
**HardcodedPathList
);
120 VOID
ScanVolumes(VOID
);
122 BOOLEAN
FileExists(IN EFI_FILE
*BaseDir
, IN CHAR16
*RelativePath
);
123 BOOLEAN
DirectoryExists(IN EFI_FILE
*BaseDir
, IN CHAR16
*RelativePath
);
125 EFI_STATUS
DirNextEntry(IN EFI_FILE
*Directory
, IN OUT EFI_FILE_INFO
**DirEntry
, IN UINTN FilterMode
);
127 VOID
DirIterOpen(IN EFI_FILE
*BaseDir
, IN CHAR16
*RelativePath OPTIONAL
, OUT REFIT_DIR_ITER
*DirIter
);
128 BOOLEAN
DirIterNext(IN OUT REFIT_DIR_ITER
*DirIter
, IN UINTN FilterMode
, IN CHAR16
*FilePattern OPTIONAL
, OUT EFI_FILE_INFO
**DirEntry
);
129 EFI_STATUS
DirIterClose(IN OUT REFIT_DIR_ITER
*DirIter
);
131 CHAR16
* Basename(IN CHAR16
*Path
);
132 CHAR16
* StripEfiExtension(CHAR16
*FileName
);
134 INTN
FindMem(IN VOID
*Buffer
, IN UINTN BufferLength
, IN VOID
*SearchString
, IN UINTN SearchStringLength
);
135 VOID
ReinitVolumes(VOID
);
137 BOOLEAN
StriSubCmp(IN CHAR16
*TargetStr
, IN CHAR16
*BigStr
);
138 VOID
MergeStrings(IN OUT CHAR16
**First
, IN CHAR16
*Second
, CHAR16 AddChar
);
139 CHAR16
*FindExtension(IN CHAR16
*Path
);
140 CHAR16
*FindLastDirName(IN CHAR16
*Path
);
141 CHAR16
*FindPath(IN CHAR16
* FullPath
);
142 VOID
FindVolumeAndFilename(IN EFI_DEVICE_PATH
*loadpath
, OUT REFIT_VOLUME
**DeviceVolume
, OUT CHAR16
**loader
);
143 BOOLEAN
SplitVolumeAndFilename(IN OUT CHAR16
**Path
, OUT CHAR16
**VolName
);
144 CHAR16
*FindNumbers(IN CHAR16
*InString
);
145 CHAR16
*FindCommaDelimited(IN CHAR16
*InString
, IN UINTN Index
);
146 INTN
FindSubString(IN CHAR16
*SmallString
, IN CHAR16
*BigString
);
147 VOID
SplitPathName(CHAR16
*InPath
, CHAR16
**VolName
, CHAR16
**Path
, CHAR16
**Filename
);
148 BOOLEAN
IsIn(IN CHAR16
*Filename
, IN CHAR16
*List
);
149 BOOLEAN
FilenameIn(IN REFIT_VOLUME
*Volume
, IN CHAR16
*Directory
, IN CHAR16
*Filename
, IN CHAR16
*List
);
150 BOOLEAN
VolumeNumberToName(REFIT_VOLUME
*Volume
, CHAR16
**VolName
);
151 VOID
MyFreePool(IN OUT VOID
*Pointer
);
153 BOOLEAN
EjectMedia(VOID
);
155 UINT64
StrToHex(CHAR16
*Input
, UINTN Position
, UINTN NumChars
);
156 BOOLEAN
IsGuid(CHAR16
*UnknownString
);
157 CHAR16
* GuidAsString(EFI_GUID
*GuidData
);
158 EFI_GUID
StringAsGuid(CHAR16
* InString
);
159 BOOLEAN
GuidsAreEqual(EFI_GUID
*Guid1
, EFI_GUID
*Guid2
);