X-Git-Url: https://code.delx.au/refind/blobdiff_plain/75afe82dbf9803baa447499a1e7942a4ca342535..10335a19c6c23286bfe5908081d515b22d5ad41a:/refind/lib.c diff --git a/refind/lib.c b/refind/lib.c index 1930e07..f0b0e6f 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 @@ -116,10 +115,11 @@ static VOID UninitVolumes(VOID); // isn't present. VOID CleanUpPathNameSlashes(IN OUT CHAR16 *PathName) { CHAR16 *NewName; - UINTN i, FinalChar = 0; + UINTN i, Length, FinalChar = 0; BOOLEAN LastWasSlash = FALSE; - NewName = AllocateZeroPool(sizeof(CHAR16) * (StrLen(PathName) + 2)); + Length = StrLen(PathName); + NewName = AllocateZeroPool(sizeof(CHAR16) * (Length + 2)); if (NewName != NULL) { for (i = 0; i < StrLen(PathName); i++) { if ((PathName[i] == L'/') || (PathName[i] == L'\\')) { @@ -409,6 +409,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; @@ -460,6 +463,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)) { @@ -469,7 +478,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) { @@ -628,21 +637,27 @@ static VOID ScanVolumeBootcode(REFIT_VOLUME *Volume, BOOLEAN *Bootable) } } /* VOID ScanVolumeBootcode() */ -// default volume badge icon based on disk kind -static VOID ScanVolumeDefaultIcon(IN OUT REFIT_VOLUME *Volume) +// Set default volume badge icon based on /.VolumeBadge.{icns|png} file or disk kind +static VOID SetVolumeBadgeIcon(IN OUT REFIT_VOLUME *Volume) { - switch (Volume->DiskKind) { - case DISK_KIND_INTERNAL: - Volume->VolBadgeImage = BuiltinIcon(BUILTIN_ICON_VOL_INTERNAL); - break; - case DISK_KIND_EXTERNAL: - Volume->VolBadgeImage = BuiltinIcon(BUILTIN_ICON_VOL_EXTERNAL); - break; - case DISK_KIND_OPTICAL: - Volume->VolBadgeImage = BuiltinIcon(BUILTIN_ICON_VOL_OPTICAL); - break; - } // switch() -} + if (Volume->VolBadgeImage == NULL) { + Volume->VolBadgeImage = egLoadIconAnyType(Volume->RootDir, L"", L".VolumeBadge", 128); + } + + if (Volume->VolBadgeImage == NULL) { + switch (Volume->DiskKind) { + case DISK_KIND_INTERNAL: + Volume->VolBadgeImage = BuiltinIcon(BUILTIN_ICON_VOL_INTERNAL); + break; + case DISK_KIND_EXTERNAL: + Volume->VolBadgeImage = BuiltinIcon(BUILTIN_ICON_VOL_EXTERNAL); + break; + case DISK_KIND_OPTICAL: + Volume->VolBadgeImage = BuiltinIcon(BUILTIN_ICON_VOL_OPTICAL); + break; + } // switch() + } +} // VOID SetVolumeBadgeIcon() // Return a string representing the input size in IEEE-1541 units. // The calling function is responsible for freeing the allocated memory. @@ -836,9 +851,6 @@ VOID ScanVolume(REFIT_VOLUME *Volume) Volume->HasBootCode = FALSE; } - // default volume icon based on disk kind - ScanVolumeDefaultIcon(Volume); - // open the root directory of the volume Volume->RootDir = LibOpenRoot(Volume->DeviceHandle); if (Volume->RootDir == NULL) { @@ -850,11 +862,12 @@ VOID ScanVolume(REFIT_VOLUME *Volume) Volume->VolName = GetVolumeName(Volume); - // get custom volume icon if present - if (!Volume->VolBadgeImage) - Volume->VolBadgeImage = LoadIcns(Volume->RootDir, VOLUME_BADGE_NAMES, 32); + // Set volume icon based on .VolumeBadge icon or disk kind + SetVolumeBadgeIcon(Volume); + + // get custom volume icons if present 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) @@ -910,7 +923,7 @@ static VOID ScanExtendedPartition(REFIT_VOLUME *WholeDiskVolume, MBR_PARTITION_I if (!Bootable) Volume->HasBootCode = FALSE; - ScanVolumeDefaultIcon(Volume); + SetVolumeBadgeIcon(Volume); AddListElement((VOID ***) &Volumes, &VolumesCount, Volume); @@ -1153,13 +1166,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; } @@ -1275,7 +1290,6 @@ BOOLEAN DirIterNext(IN OUT REFIT_DIR_ITER *DirIter, IN UINTN FilterMode, IN CHAR while (KeepGoing && (OnePattern = FindCommaDelimited(FilePattern, i++)) != NULL) { if (MetaiMatch(DirIter->LastFileInfo->FileName, OnePattern)) KeepGoing = FALSE; -// Print(L"%s did%s match %s\n", DirIter->LastFileInfo->FileName, KeepGoing ? L" not" : L"", OnePattern); } // while // else continue loop } else @@ -1430,7 +1444,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) {