X-Git-Url: https://code.delx.au/refind/blobdiff_plain/5cef5a4a05120d224fc8d6d72743c3432c546904..e07b72471fa62945801b4a4e3bcac662a1b4888d:/refind/lib.c diff --git a/refind/lib.c b/refind/lib.c index db3a6dd..5960f36 100644 --- a/refind/lib.c +++ b/refind/lib.c @@ -34,12 +34,12 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* - * Modifications copyright (c) 2012 Roderick W. Smith + * Modifications copyright (c) 2012-2013 Roderick W. Smith * * Modifications distributed under the terms of the GNU General Public * License (GPL) version 3 (GPLv3), a copy of which must be distributed * with this source code or binaries made from it. - * + * */ #include "global.h" @@ -48,6 +48,7 @@ #include "screen.h" #include "../include/refit_call_wrapper.h" #include "../include/RemovableMedia.h" +//#include "../include/UsbMass.h" #ifdef __MAKEWITH_GNUEFI #define EfiReallocatePool ReallocatePool @@ -72,6 +73,7 @@ EFI_DEVICE_PATH EndDevicePath[] = { #define REISERFS_SUPER_MAGIC_STRING "ReIsErFs" #define REISER2FS_SUPER_MAGIC_STRING "ReIsEr2Fs" #define REISER2FS_JR_SUPER_MAGIC_STRING "ReIsEr3Fs" +#define BTRFS_SIGNATURE "_BHRfS_M" // variables @@ -92,9 +94,6 @@ UINTN VolumesCount = 0; // and identify its boot loader, and hence probable BIOS-mode OS installation #define SAMPLE_SIZE 69632 /* 68 KiB -- ReiserFS superblock begins at 64 KiB */ -// Default names for volume badges (mini-icon to define disk type) and icons -#define VOLUME_BADGE_NAMES L".VolumeBadge.icns,.VolumeBadge.png" -#define VOLUME_ICON_NAMES L".VolumeIcon.icns,.VolumeIcon.png" // functions @@ -153,24 +152,26 @@ VOID CleanUpPathNameSlashes(IN OUT CHAR16 *PathName) { // after that string (after some cleanup) as the return value, and truncating the original // input value. // If InString contains no ")" character, this function leaves the original input string -// unmodified and also returns that string. +// unmodified and also returns that string. If InString is NULL, this function returns NULL. static CHAR16* SplitDeviceString(IN OUT CHAR16 *InString) { INTN i; CHAR16 *FileName = NULL; BOOLEAN Found = FALSE; - i = StrLen(InString) - 1; - while ((i >= 0) && (!Found)) { - if (InString[i] == L')') { - Found = TRUE; - FileName = StrDuplicate(&InString[i + 1]); - CleanUpPathNameSlashes(FileName); - InString[i + 1] = '\0'; - } // if - i--; - } // while - if (FileName == NULL) - FileName = StrDuplicate(InString); + if (InString != NULL) { + i = StrLen(InString) - 1; + while ((i >= 0) && (!Found)) { + if (InString[i] == L')') { + Found = TRUE; + FileName = StrDuplicate(&InString[i + 1]); + CleanUpPathNameSlashes(FileName); + InString[i + 1] = '\0'; + } // if + i--; + } // while + if (FileName == NULL) + FileName = StrDuplicate(InString); + } // if return FileName; } // static CHAR16* SplitDeviceString() @@ -407,6 +408,9 @@ static CHAR16 *FSTypeName(IN UINT32 TypeCode) { case FS_TYPE_REISERFS: retval = L" ReiserFS"; break; + case FS_TYPE_BTRFS: + retval = L" Btrfs"; + break; case FS_TYPE_ISO9660: retval = L" ISO-9660"; break; @@ -458,6 +462,12 @@ static UINT32 IdentifyFilesystemType(IN UINT8 *Buffer, IN UINTN BufferSize) { } // if } // search for ReiserFS magic + if (BufferSize >= (65536 + 64 + 8)) { + MagicString = (char*) (Buffer + 65536 + 64); + if (CompareMem(MagicString, BTRFS_SIGNATURE, 8) == 0) + return FS_TYPE_BTRFS; + } // search for Btrfs magic + if (BufferSize >= (1024 + 2)) { Magic16 = (UINT16*) (Buffer + 1024); if ((*Magic16 == HFSPLUS_MAGIC1) || (*Magic16 == HFSPLUS_MAGIC2)) { @@ -467,7 +477,7 @@ static UINT32 IdentifyFilesystemType(IN UINT8 *Buffer, IN UINTN BufferSize) { } // if (Buffer != NULL) return FoundType; -} +} // UINT32 IdentifyFilesystemType() static VOID ScanVolumeBootcode(REFIT_VOLUME *Volume, BOOLEAN *Bootable) { @@ -850,9 +860,9 @@ VOID ScanVolume(REFIT_VOLUME *Volume) // get custom volume icon if present if (!Volume->VolBadgeImage) - Volume->VolBadgeImage = LoadIcns(Volume->RootDir, VOLUME_BADGE_NAMES, 32); + Volume->VolBadgeImage = egLoadIconAnyType(Volume->RootDir, L"", L".VolumeBadge", 32); if (!Volume->VolIconImage) - Volume->VolIconImage = LoadIcns(Volume->RootDir, VOLUME_ICON_NAMES, 128); + Volume->VolIconImage = egLoadIconAnyType(Volume->RootDir, L"", L".VolumeIcon", 128); } // ScanVolume() static VOID ScanExtendedPartition(REFIT_VOLUME *WholeDiskVolume, MBR_PARTITION_INFO *MbrEntry) @@ -1151,13 +1161,15 @@ EFI_STATUS DirNextEntry(IN EFI_FILE *Directory, IN OUT EFI_FILE_INFO **DirEntry, LastBufferSize = BufferSize; } if (EFI_ERROR(Status)) { - FreePool(Buffer); + MyFreePool(Buffer); + Buffer = NULL; break; } // check for end of listing if (BufferSize == 0) { // end of directory listing - FreePool(Buffer); + MyFreePool(Buffer); + Buffer = NULL; break; } @@ -1277,7 +1289,7 @@ BOOLEAN DirIterNext(IN OUT REFIT_DIR_ITER *DirIter, IN UINTN FilterMode, IN CHAR // else continue loop } else break; - } while (KeepGoing); + } while (KeepGoing && FilePattern); *DirEntry = DirIter->LastFileInfo; return TRUE; @@ -1336,21 +1348,6 @@ CHAR16 * StripEfiExtension(CHAR16 *FileName) { return Copy; } // CHAR16 * StripExtension() -// Replaces a filename extension of ".efi" with the specified string -// (Extension). If the input Path doesn't end in ".efi", Extension -// is added to the existing filename. -// VOID ReplaceEfiExtension(IN OUT CHAR16 *Path, IN CHAR16 *Extension) -// { -// UINTN PathLen; -// -// PathLen = StrLen(Path); -// // Note: Do StriCmp() twice to work around Gigabyte Hybrid EFI case-sensitivity bug.... -// if ((PathLen >= 4) && ((StriCmp(&Path[PathLen - 4], L".efi") == 0) || (StriCmp(&Path[PathLen - 4], L".EFI") == 0))) { -// Path[PathLen - 4] = 0; -// } // if -// StrCat(Path, Extension); -// } // VOID ReplaceEfiExtension() - // // memory string search // @@ -1442,7 +1439,7 @@ VOID MergeStrings(IN OUT CHAR16 **First, IN CHAR16 *Second, CHAR16 AddChar) { CHAR16 *FindExtension(IN CHAR16 *Path) { CHAR16 *Extension; BOOLEAN Found = FALSE, FoundSlash = FALSE; - UINTN i; + INTN i; Extension = AllocateZeroPool(sizeof(CHAR16)); if (Path) { @@ -1471,6 +1468,9 @@ CHAR16 *FindLastDirName(IN CHAR16 *Path) { UINTN i, StartOfElement = 0, EndOfElement = 0, PathLength, CopyLength; CHAR16 *Found = NULL; + if (Path == NULL) + return NULL; + PathLength = StrLen(Path); // Find start & end of target element for (i = 0; i < PathLength; i++) { @@ -1501,14 +1501,16 @@ CHAR16 *FindLastDirName(IN CHAR16 *Path) { // freeing the returned string's memory. CHAR16 *FindPath(IN CHAR16* FullPath) { UINTN i, LastBackslash = 0; - CHAR16 *PathOnly; + CHAR16 *PathOnly = NULL; - for (i = 0; i < StrLen(FullPath); i++) { - if (FullPath[i] == '\\') - LastBackslash = i; - } // for - PathOnly = StrDuplicate(FullPath); - PathOnly[LastBackslash] = 0; + if (FullPath != NULL) { + for (i = 0; i < StrLen(FullPath); i++) { + if (FullPath[i] == '\\') + LastBackslash = i; + } // for + PathOnly = StrDuplicate(FullPath); + PathOnly[LastBackslash] = 0; + } // if return (PathOnly); } @@ -1581,6 +1583,9 @@ CHAR16 *FindNumbers(IN CHAR16 *InString) { UINTN i, StartOfElement, EndOfElement = 0, InLength, CopyLength; CHAR16 *Found = NULL; + if (InString == NULL) + return NULL; + InLength = StartOfElement = StrLen(InString); // Find start & end of target element for (i = 0; i < InLength; i++) {