+// Returns FALSE if the specified file/volume matches the GlobalConfig.DontScanDirs
+// or GlobalConfig.DontScanVolumes specification, or if Path points to a volume
+// other than the one specified by Volume, or if the specified path is SelfDir.
+// Returns TRUE if none of these conditions is met -- that is, if the path is
+// eligible for scanning.
+static BOOLEAN ShouldScan(REFIT_VOLUME *Volume, CHAR16 *Path) {
+ CHAR16 *VolName = NULL, *DontScanDir;
+ UINTN i = 0, VolNum;
+ BOOLEAN ScanIt = TRUE;
+
+ if (IsIn(Volume->VolName, GlobalConfig.DontScanVolumes))
+ return FALSE;
+
+ if ((StriCmp(Path, SelfDirPath) == 0) && (Volume->DeviceHandle == SelfVolume->DeviceHandle))
+ return FALSE;
+
+ while ((DontScanDir = FindCommaDelimited(GlobalConfig.DontScanDirs, i++)) && ScanIt) {
+ SplitVolumeAndFilename(&DontScanDir, &VolName);
+ CleanUpPathNameSlashes(DontScanDir);
+ if (VolName != NULL) {
+ if ((StriCmp(VolName, Volume->VolName) == 0) && (StriCmp(DontScanDir, Path) == 0))
+ ScanIt = FALSE;
+ if ((StrLen(VolName) > 2) && (VolName[0] == L'f') && (VolName[1] == L's') && (VolName[2] >= L'0') && (VolName[2] <= L'9')) {
+ VolNum = Atoi(VolName + 2);
+ if ((VolNum == Volume->VolNumber) && (StriCmp(DontScanDir, Path) == 0))
+ ScanIt = FALSE;
+ }
+ } else {
+ if (StriCmp(DontScanDir, Path) == 0)
+ ScanIt = FALSE;
+ }
+ MyFreePool(DontScanDir);
+ DontScanDir = NULL;
+ }
+ return ScanIt;
+} // BOOLEAN ShouldScan()
+
+// Returns TRUE if the file is byte-for-byte identical with the fallback file
+// on the volume AND if the file is not itself the fallback file; returns
+// FALSE if the file is not identical to the fallback file OR if the file
+// IS the fallback file. Intended for use in excluding the fallback boot
+// loader when it's a duplicate of another boot loader.
+static BOOLEAN DuplicatesFallback(IN REFIT_VOLUME *Volume, IN CHAR16 *FileName) {
+ CHAR8 *FileContents, *FallbackContents;
+ EFI_FILE_HANDLE FileHandle, FallbackHandle;
+ EFI_FILE_INFO *FileInfo, *FallbackInfo;
+ UINTN FileSize = 0, FallbackSize = 0;
+ EFI_STATUS Status;
+ BOOLEAN AreIdentical = FALSE;
+
+ if (!FileExists(Volume->RootDir, FileName) || !FileExists(Volume->RootDir, FALLBACK_FULLNAME))
+ return FALSE;
+
+ CleanUpPathNameSlashes(FileName);
+
+ if (StriCmp(FileName, FALLBACK_FULLNAME) == 0)
+ return FALSE; // identical filenames, so not a duplicate....
+
+ Status = refit_call5_wrapper(Volume->RootDir->Open, Volume->RootDir, &FileHandle, FileName, EFI_FILE_MODE_READ, 0);
+ if (Status == EFI_SUCCESS) {
+ FileInfo = LibFileInfo(FileHandle);
+ FileSize = FileInfo->FileSize;
+ } else {
+ return FALSE;
+ }
+
+ Status = refit_call5_wrapper(Volume->RootDir->Open, Volume->RootDir, &FallbackHandle, FALLBACK_FULLNAME, EFI_FILE_MODE_READ, 0);
+ if (Status == EFI_SUCCESS) {
+ FallbackInfo = LibFileInfo(FallbackHandle);
+ FallbackSize = FallbackInfo->FileSize;
+ } else {
+ refit_call1_wrapper(FileHandle->Close, FileHandle);
+ return FALSE;
+ }
+
+ if (FallbackSize != FileSize) { // not same size, so can't be identical
+ AreIdentical = FALSE;
+ } else { // could be identical; do full check....
+ FileContents = AllocatePool(FileSize);
+ FallbackContents = AllocatePool(FallbackSize);
+ if (FileContents && FallbackContents) {
+ Status = refit_call3_wrapper(FileHandle->Read, FileHandle, &FileSize, FileContents);
+ if (Status == EFI_SUCCESS) {
+ Status = refit_call3_wrapper(FallbackHandle->Read, FallbackHandle, &FallbackSize, FallbackContents);
+ }
+ if (Status == EFI_SUCCESS) {
+ AreIdentical = (CompareMem(FileContents, FallbackContents, FileSize) == 0);
+ } // if
+ } // if
+ MyFreePool(FileContents);
+ MyFreePool(FallbackContents);
+ } // if/else
+
+ // BUG ALERT: Some systems (e.g., DUET, some Macs with large displays) crash if the
+ // following two calls are reversed. Go figure....
+ refit_call1_wrapper(FileHandle->Close, FallbackHandle);
+ refit_call1_wrapper(FileHandle->Close, FileHandle);
+ return AreIdentical;
+} // BOOLEAN DuplicatesFallback()
+