]> code.delx.au - refind/blobdiff - refind/lib.c
Display partition label, if available, for BIOS-mode boot from
[refind] / refind / lib.c
index 057026589c502b104180d336c3a8cb2771b85b81..893f62c35b53a93919436175cb5f0eab22a4acf6 100644 (file)
@@ -751,42 +751,45 @@ static CHAR16 *SizeInIEEEUnits(UINT64 SizeInBytes) {
 // The calling function is responsible for freeing the memory allocated
 // for the name string.
 static CHAR16 *GetVolumeName(REFIT_VOLUME *Volume) {
-   EFI_FILE_SYSTEM_INFO    *FileSystemInfoPtr;
+   EFI_FILE_SYSTEM_INFO    *FileSystemInfoPtr = NULL;
    CHAR16                  *FoundName = NULL;
    CHAR16                  *SISize, *TypeName;
 
-   FileSystemInfoPtr = LibFileSystemInfo(Volume->RootDir);
-   if (FileSystemInfoPtr != NULL) { // we have filesystem information (size, label)....
-       if ((FileSystemInfoPtr->VolumeLabel != NULL) && (StrLen(FileSystemInfoPtr->VolumeLabel) > 0)) {
-          FoundName = StrDuplicate(FileSystemInfoPtr->VolumeLabel);
-       }
-
-       // Special case: Old versions of the rEFInd HFS+ driver always returns label of "HFS+ volume", so wipe
-       // this so that we can build a new name that includes the size....
-       if ((FoundName != NULL) && (StrCmp(FoundName, L"HFS+ volume") == 0) && (Volume->FSType == FS_TYPE_HFSPLUS)) {
-          MyFreePool(FoundName);
-          FoundName = NULL;
-       } // if rEFInd HFS+ driver suspected
-
-       // If no filesystem name, try to use the partition name....
-       if ((FoundName == NULL) && (Volume->PartName != NULL) && (StrLen(Volume->PartName) > 0) &&
-           !IsIn(Volume->PartName, IGNORE_PARTITION_NAMES)) {
-          FoundName = StrDuplicate(Volume->PartName);
-       } // if use partition name
-
-       // No filesystem or acceptable partition name, so use fs type and size
-       if (FoundName == NULL) {
-          FoundName = AllocateZeroPool(sizeof(CHAR16) * 256);
-          if (FoundName != NULL) {
-             SISize = SizeInIEEEUnits(FileSystemInfoPtr->VolumeSize);
-             SPrint(FoundName, 255, L"%s%s volume", SISize, FSTypeName(Volume->FSType));
-             MyFreePool(SISize);
-          } // if allocated memory OK
-       } // if (FoundName == NULL)
-
-       FreePool(FileSystemInfoPtr);
-
-   } else { // fs driver not returning info; fall back on our own information....
+   if (Volume->RootDir != NULL) {
+      FileSystemInfoPtr = LibFileSystemInfo(Volume->RootDir);
+   }
+
+   if ((FileSystemInfoPtr != NULL) && (FileSystemInfoPtr->VolumeLabel != NULL) &&
+       (StrLen(FileSystemInfoPtr->VolumeLabel) > 0)) {
+      FoundName = StrDuplicate(FileSystemInfoPtr->VolumeLabel);
+   }
+
+   // Special case: Old versions of the rEFInd HFS+ driver always returns label of "HFS+ volume", so wipe
+   // this so that we can build a new name that includes the size....
+   if ((FoundName != NULL) && (StrCmp(FoundName, L"HFS+ volume") == 0) && (Volume->FSType == FS_TYPE_HFSPLUS)) {
+      MyFreePool(FoundName);
+      FoundName = NULL;
+   } // if rEFInd HFS+ driver suspected
+
+   // If no filesystem name, try to use the partition name....
+   if ((FoundName == NULL) && (Volume->PartName != NULL) && (StrLen(Volume->PartName) > 0) &&
+       !IsIn(Volume->PartName, IGNORE_PARTITION_NAMES)) {
+      FoundName = StrDuplicate(Volume->PartName);
+   } // if use partition name
+
+   // No filesystem or acceptable partition name, so use fs type and size
+   if ((FoundName == NULL) && (FileSystemInfoPtr != NULL)) {
+      FoundName = AllocateZeroPool(sizeof(CHAR16) * 256);
+      if (FoundName != NULL) {
+         SISize = SizeInIEEEUnits(FileSystemInfoPtr->VolumeSize);
+         SPrint(FoundName, 255, L"%s%s volume", SISize, FSTypeName(Volume->FSType));
+         MyFreePool(SISize);
+      } // if allocated memory OK
+   } // if (FoundName == NULL)
+
+   MyFreePool(FileSystemInfoPtr);
+
+   if (FoundName == NULL) {
       FoundName = AllocateZeroPool(sizeof(CHAR16) * 256);
       if (FoundName != NULL) {
          TypeName = FSTypeName(Volume->FSType); // NOTE: Don't free TypeName; function returns constant
@@ -799,7 +802,6 @@ static CHAR16 *GetVolumeName(REFIT_VOLUME *Volume) {
 
    // TODO: Above could be improved/extended, in case filesystem name is not found,
    // such as:
-   //  - use partition label
    //  - use or add disk/partition number (e.g., "(hd0,2)")
 
    // Desperate fallback name....
@@ -942,6 +944,8 @@ VOID ScanVolume(REFIT_VOLUME *Volume)
     // Set volume icon based on .VolumeBadge icon or disk kind
     SetVolumeBadgeIcon(Volume);
 
+    Volume->VolName = GetVolumeName(Volume);
+
     if (Volume->RootDir == NULL) {
         Volume->IsReadable = FALSE;
         return;
@@ -949,8 +953,6 @@ VOID ScanVolume(REFIT_VOLUME *Volume)
         Volume->IsReadable = TRUE;
     }
 
-    Volume->VolName = GetVolumeName(Volume);
-
     // get custom volume icons if present
     if (!Volume->VolIconImage)
        Volume->VolIconImage = egLoadIconAnyType(Volume->RootDir, L"", L".VolumeIcon", GlobalConfig.IconSizes[ICON_SIZE_BIG]);