+// Returns FALSE if two measures of file size are identical for a single file,
+// TRUE if not or if the file can't be opened and the other measure is non-0.
+// Despite the function's name, this isn't really a direct test of symbolic
+// link status, since EFI doesn't officially support symlinks. It does seem
+// to be a reliable indicator, though. (OTOH, some disk errors might cause a
+// file to fail to open, which would return a false positive -- but as I use
+// this function to exclude symbolic links from the list of boot loaders,
+// that would be fine, since such boot loaders wouldn't work.)
+static BOOLEAN IsSymbolicLink(REFIT_VOLUME *Volume, CHAR16 *Path, EFI_FILE_INFO *DirEntry) {
+ EFI_FILE_HANDLE FileHandle;
+ EFI_FILE_INFO *FileInfo = NULL;
+ EFI_STATUS Status;
+ UINTN FileSize2 = 0;
+ CHAR16 *FileName;
+
+ FileName = StrDuplicate(Path);
+ MergeStrings(&FileName, DirEntry->FileName, L'\\');
+ CleanUpPathNameSlashes(FileName);
+
+ Status = refit_call5_wrapper(Volume->RootDir->Open, Volume->RootDir, &FileHandle, FileName, EFI_FILE_MODE_READ, 0);
+ if (Status == EFI_SUCCESS) {
+ FileInfo = LibFileInfo(FileHandle);
+ if (FileInfo != NULL)
+ FileSize2 = FileInfo->FileSize;
+ }
+
+ MyFreePool(FileName);
+ MyFreePool(FileInfo);
+
+ return (DirEntry->FileSize != FileSize2);
+} // BOOLEAN IsSymbolicLink()
+
+// Returns TRUE if a file with the same name as the original but with
+// ".efi.signed" is also present in the same directory. Ubuntu is using
+// this filename as a signed version of the original unsigned kernel, and
+// there's no point in cluttering the display with two kernels that will
+// behave identically on non-SB systems, or when one will fail when SB
+// is active.
+static BOOLEAN HasSignedCounterpart(IN REFIT_VOLUME *Volume, IN CHAR16 *Path, IN CHAR16 *Filename) {
+ CHAR16 *NewFile = NULL;
+ BOOLEAN retval = FALSE;
+
+ MergeStrings(&NewFile, Path, 0);
+ MergeStrings(&NewFile, Filename, L'\\');
+ MergeStrings(&NewFile, L".efi.signed", 0);
+ if (FileExists(Volume->RootDir, NewFile))
+ retval = TRUE;
+ MyFreePool(NewFile);
+
+ return retval;
+} // BOOLEAN HasSignedCounterpart()
+