]> code.delx.au - refind/blobdiff - refind/lib.c
New config file option: "also_scan_dirs".
[refind] / refind / lib.c
index 3c61782570ea7777bf587d886b2b1b91bf6f1cb0..f5037c5f65f7dd8d41709b24142118b98216d99f 100644 (file)
@@ -79,8 +79,9 @@ static VOID UninitVolumes(VOID);
 
 // Converts forward slashes to backslashes and removes duplicate slashes.
 // Necessary because some (buggy?) EFI implementations produce "\/" strings
-// in pathnames.
-static VOID CleanUpPathNameSlashes(IN OUT CHAR16 *PathName) {
+// in pathnames and because some user inputs can produce duplicate directory
+// separators
+VOID CleanUpPathNameSlashes(IN OUT CHAR16 *PathName) {
    CHAR16   *NewName;
    UINTN    i, j = 0;
    BOOLEAN  LastWasSlash = FALSE;
@@ -293,11 +294,11 @@ VOID ExtractLegacyLoaderPaths(EFI_DEVICE_PATH **PathList, UINTN MaxPaths, EFI_DE
         }
         if (Seen)
             continue;
-        
+
         PathList[PathCount++] = AppendDevicePath(DevicePath, LegacyLoaderMediaPath);
     }
     FreePool(Handles);
-    
+
     if (HardcodedPathList) {
         for (HardcodedIndex = 0; HardcodedPathList[HardcodedIndex] && PathCount < MaxPaths; HardcodedIndex++)
             PathList[PathCount++] = HardcodedPathList[HardcodedIndex];
@@ -316,17 +317,17 @@ static VOID ScanVolumeBootcode(IN OUT REFIT_VOLUME *Volume, OUT BOOLEAN *Bootabl
     UINTN                   i;
     MBR_PARTITION_INFO      *MbrTable;
     BOOLEAN                 MbrTableFound;
-    
+
     Volume->HasBootCode = FALSE;
     Volume->OSIconName = NULL;
     Volume->OSName = NULL;
     *Bootable = FALSE;
-    
+
     if (Volume->BlockIO == NULL)
         return;
     if (Volume->BlockIO->Media->BlockSize > SECTOR_SIZE)
         return;   // our buffer is too small...
-    
+
     // look at the boot sector (this is used for both hard disks and El Torito images!)
     Status = refit_call5_wrapper(Volume->BlockIO->ReadBlocks,
                                  Volume->BlockIO, Volume->BlockIO->Media->MediaId,
@@ -579,7 +580,10 @@ static VOID ScanVolume(IN OUT REFIT_VOLUME *Volume)
     // open the root directory of the volume
     Volume->RootDir = LibOpenRoot(Volume->DeviceHandle);
     if (Volume->RootDir == NULL) {
+        Volume->IsReadable = FALSE;
         return;
+    } else {
+        Volume->IsReadable = TRUE;
     }
 
     // get volume name
@@ -1073,8 +1077,8 @@ VOID MergeStrings(IN OUT CHAR16 **First, IN CHAR16 *Second, CHAR16 AddChar) {
    if (Second != NULL)
       Length2 = StrLen(Second);
    NewString = AllocatePool(sizeof(CHAR16) * (Length1 + Length2 + 2));
-   NewString[0] = L'\0';
    if (NewString != NULL) {
+      NewString[0] = L'\0';
       if (*First != NULL) {
          StrCat(NewString, *First);
          if (AddChar) {
@@ -1082,7 +1086,7 @@ VOID MergeStrings(IN OUT CHAR16 **First, IN CHAR16 *Second, CHAR16 AddChar) {
             NewString[Length1 + 1] = 0;
          } // if (AddChar)
       } // if (*First != NULL)
-      if (First != NULL)
+      if (Second != NULL)
          StrCat(NewString, Second);
       FreePool(*First);
       *First = NewString;
@@ -1171,7 +1175,7 @@ CHAR16 *FindNumbers(IN CHAR16 *InString) {
 
 // Find the #Index element (numbered from 0) in a comma-delimited string
 // of elements.
-// Returns the found element, or NULL if Index is out of range of InString
+// Returns the found element, or NULL if Index is out of range or InString
 // is NULL.
 CHAR16 *FindCommaDelimited(IN CHAR16 *InString, IN UINTN Index) {
    UINTN    StartPos = 0, CurPos = 0;
@@ -1194,10 +1198,10 @@ CHAR16 *FindCommaDelimited(IN CHAR16 *InString, IN UINTN Index) {
          else
             CurPos++;
       } // while
+      if (Index == 0)
+         FoundString = StrDuplicate(&InString[StartPos]);
+      if (FoundString != NULL)
+         FoundString[CurPos - StartPos] = 0;
    } // if
-   if (Index == 0)
-      FoundString = StrDuplicate(&InString[StartPos]);
-   if (FoundString != NULL)
-      FoundString[CurPos - StartPos] = 0;
    return (FoundString);
 } // CHAR16 *FindCommaDelimited()