]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdeModulePkg/UdfDxe: Update GetInfo() for FS VolumeLabel info request
authorHao Wu <hao.a.wu@intel.com>
Fri, 12 Oct 2018 06:49:41 +0000 (14:49 +0800)
committerHao Wu <hao.a.wu@intel.com>
Tue, 23 Oct 2018 06:24:50 +0000 (14:24 +0800)
REF:https://bugzilla.tianocore.org/show_bug.cgi?id=1175

This commit will update the UdfGetInfo() function with the support of
EFI_FILE_SYSTEM_VOLUME_LABEL data information request.

Cc: Ruiyu Ni <ruiyu.ni@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Hao Wu <hao.a.wu@intel.com>
Reviewed-by: Paulo Alcantara <palcantara@suse.de>
Acked-by: Star Zeng <star.zeng@intel.com>
MdeModulePkg/Universal/Disk/UdfDxe/File.c
MdeModulePkg/Universal/Disk/UdfDxe/FileSystemOperations.c
MdeModulePkg/Universal/Disk/UdfDxe/Udf.h
MdeModulePkg/Universal/Disk/UdfDxe/UdfDxe.inf

index 45ce5e51f865122f9eb230b7573f0023b5913bca..60ad3c55ce4a027730edf1fc37e5dd27c55554b7 100644 (file)
@@ -736,12 +736,6 @@ UdfSetPosition (
 /**\r
   Get information about a file.\r
 \r
-  @attention This is boundary function that may receive untrusted input.\r
-  @attention The input is from FileSystem.\r
-\r
-  The File Set Descriptor is external input, so this routine will do basic\r
-  validation for File Set Descriptor and report status.\r
-\r
   @param  This            Protocol instance pointer.\r
   @param  InformationType Type of information to return in Buffer.\r
   @param  BufferSize      On input size of buffer, on output amount of data in\r
@@ -768,19 +762,16 @@ UdfGetInfo (
   OUT     VOID               *Buffer\r
   )\r
 {\r
-  EFI_STATUS                  Status;\r
-  PRIVATE_UDF_FILE_DATA       *PrivFileData;\r
-  PRIVATE_UDF_SIMPLE_FS_DATA  *PrivFsData;\r
-  EFI_FILE_SYSTEM_INFO        *FileSystemInfo;\r
-  UINTN                       FileSystemInfoLength;\r
-  CHAR16                      *String;\r
-  UDF_FILE_SET_DESCRIPTOR     *FileSetDesc;\r
-  UINTN                       Index;\r
-  UINT8                       *OstaCompressed;\r
-  UINT8                       CompressionId;\r
-  UINT64                      VolumeSize;\r
-  UINT64                      FreeSpaceSize;\r
-  CHAR16                      VolumeLabel[64];\r
+  EFI_STATUS                    Status;\r
+  PRIVATE_UDF_FILE_DATA         *PrivFileData;\r
+  PRIVATE_UDF_SIMPLE_FS_DATA    *PrivFsData;\r
+  EFI_FILE_SYSTEM_INFO          *FileSystemInfo;\r
+  UINTN                         FileSystemInfoLength;\r
+  UINT64                        VolumeSize;\r
+  UINT64                        FreeSpaceSize;\r
+  EFI_FILE_SYSTEM_VOLUME_LABEL  *FileSystemVolumeLabel;\r
+  UINTN                         FileSystemVolumeLabelLength;\r
+  CHAR16                        VolumeLabel[64];\r
 \r
   if (This == NULL || InformationType == NULL || BufferSize == NULL ||\r
       (*BufferSize != 0 && Buffer == NULL)) {\r
@@ -802,50 +793,10 @@ UdfGetInfo (
       Buffer\r
       );\r
   } else if (CompareGuid (InformationType, &gEfiFileSystemInfoGuid)) {\r
-    String = VolumeLabel;\r
-\r
-    FileSetDesc = &PrivFsData->Volume.FileSetDesc;\r
-\r
-    OstaCompressed = &FileSetDesc->LogicalVolumeIdentifier[0];\r
-\r
-    CompressionId = OstaCompressed[0];\r
-    if (!IS_VALID_COMPRESSION_ID (CompressionId)) {\r
-      return EFI_VOLUME_CORRUPTED;\r
-    }\r
-\r
-    for (Index = 1; Index < 128; Index++) {\r
-      if (CompressionId == 16) {\r
-        *String = *(UINT8 *)(OstaCompressed + Index) << 8;\r
-        Index++;\r
-      } else {\r
-        if (Index > ARRAY_SIZE (VolumeLabel)) {\r
-          return EFI_VOLUME_CORRUPTED;\r
-        }\r
-\r
-        *String = 0;\r
-      }\r
-\r
-      if (Index < 128) {\r
-        *String |= (CHAR16)(*(UINT8 *)(OstaCompressed + Index));\r
-      }\r
-\r
-      //\r
-      // Unlike FID Identifiers, Logical Volume Identifier is stored in a\r
-      // NULL-terminated OSTA compressed format, so we must check for the NULL\r
-      // character.\r
-      //\r
-      if (*String == L'\0') {\r
-        break;\r
-      }\r
-\r
-      String++;\r
-    }\r
-\r
-    Index = ((UINTN)String - (UINTN)VolumeLabel) / sizeof (CHAR16);\r
-    if (Index > ARRAY_SIZE (VolumeLabel) - 1) {\r
-      Index = ARRAY_SIZE (VolumeLabel) - 1;\r
+    Status = GetVolumeLabel (&PrivFsData->Volume, ARRAY_SIZE (VolumeLabel), VolumeLabel);\r
+    if (EFI_ERROR (Status)) {\r
+      return Status;\r
     }\r
-    VolumeLabel[Index] = L'\0';\r
 \r
     FileSystemInfoLength = StrSize (VolumeLabel) +\r
                            sizeof (EFI_FILE_SYSTEM_INFO);\r
@@ -857,7 +808,7 @@ UdfGetInfo (
     FileSystemInfo = (EFI_FILE_SYSTEM_INFO *)Buffer;\r
     StrCpyS (\r
       FileSystemInfo->VolumeLabel,\r
-      (*BufferSize - OFFSET_OF (EFI_FILE_SYSTEM_INFO, VolumeLabel)) / sizeof (CHAR16),\r
+      (*BufferSize - SIZE_OF_EFI_FILE_SYSTEM_INFO) / sizeof (CHAR16),\r
       VolumeLabel\r
       );\r
     Status = GetVolumeSize (\r
@@ -880,6 +831,26 @@ UdfGetInfo (
 \r
     *BufferSize = FileSystemInfoLength;\r
     Status = EFI_SUCCESS;\r
+  } else if (CompareGuid (InformationType, &gEfiFileSystemVolumeLabelInfoIdGuid)) {\r
+    Status = GetVolumeLabel (&PrivFsData->Volume, ARRAY_SIZE (VolumeLabel), VolumeLabel);\r
+    if (EFI_ERROR (Status)) {\r
+      return Status;\r
+    }\r
+\r
+    FileSystemVolumeLabelLength = StrSize (VolumeLabel) +\r
+                                  sizeof (EFI_FILE_SYSTEM_VOLUME_LABEL);\r
+    if (*BufferSize < FileSystemVolumeLabelLength) {\r
+      *BufferSize = FileSystemVolumeLabelLength;\r
+      return EFI_BUFFER_TOO_SMALL;\r
+    }\r
+\r
+    FileSystemVolumeLabel = (EFI_FILE_SYSTEM_VOLUME_LABEL *)Buffer;\r
+    StrCpyS (\r
+      FileSystemVolumeLabel->VolumeLabel,\r
+      (*BufferSize - SIZE_OF_EFI_FILE_SYSTEM_VOLUME_LABEL) / sizeof (CHAR16),\r
+      VolumeLabel\r
+      );\r
+    Status = EFI_SUCCESS;\r
   }\r
 \r
   return Status;\r
index c55dcf1301768039171ef3a96b435d05b17640d2..f1205bbb8eed2b890367beabbe563ece04a71292 100644 (file)
@@ -2530,6 +2530,90 @@ SetFileInfo (
   return EFI_SUCCESS;\r
 }\r
 \r
+/**\r
+  Get volume label of an UDF volume.\r
+\r
+  @attention This is boundary function that may receive untrusted input.\r
+  @attention The input is from FileSystem.\r
+\r
+  The File Set Descriptor is external input, so this routine will do basic\r
+  validation for File Set Descriptor and report status.\r
+\r
+  @param[in]   Volume   Volume information pointer.\r
+  @param[in]   CharMax  The maximum number of Unicode char in String,\r
+                        including terminating null char.\r
+  @param[out]  String   String buffer pointer to store the volume label.\r
+\r
+  @retval EFI_SUCCESS           Volume label is returned.\r
+  @retval EFI_VOLUME_CORRUPTED  The file system structures are corrupted.\r
+  @retval EFI_BUFFER_TOO_SMALL  The string buffer String cannot hold the\r
+                                volume label.\r
+\r
+**/\r
+EFI_STATUS\r
+GetVolumeLabel (\r
+  IN   UDF_VOLUME_INFO  *Volume,\r
+  IN   UINTN            CharMax,\r
+  OUT  CHAR16           *String\r
+  )\r
+{\r
+  UDF_FILE_SET_DESCRIPTOR  *FileSetDesc;\r
+  UINTN                    Index;\r
+  UINT8                    *OstaCompressed;\r
+  UINT8                    CompressionId;\r
+  CHAR16                   *StringBak;\r
+\r
+  FileSetDesc = &Volume->FileSetDesc;\r
+\r
+  OstaCompressed = &FileSetDesc->LogicalVolumeIdentifier[0];\r
+\r
+  CompressionId = OstaCompressed[0];\r
+  if (!IS_VALID_COMPRESSION_ID (CompressionId)) {\r
+    return EFI_VOLUME_CORRUPTED;\r
+  }\r
+\r
+  StringBak = String;\r
+  for (Index = 1; Index < 128; Index++) {\r
+    if (CompressionId == 16) {\r
+      if ((Index >> 1) > CharMax) {\r
+        return EFI_BUFFER_TOO_SMALL;\r
+      }\r
+\r
+      *String = *(UINT8 *)(OstaCompressed + Index) << 8;\r
+      Index++;\r
+    } else {\r
+      if (Index > CharMax) {\r
+        return EFI_BUFFER_TOO_SMALL;\r
+      }\r
+\r
+      *String = 0;\r
+    }\r
+\r
+    if (Index < 128) {\r
+      *String |= (CHAR16)(*(UINT8 *)(OstaCompressed + Index));\r
+    }\r
+\r
+    //\r
+    // Unlike FID Identifiers, Logical Volume Identifier is stored in a\r
+    // NULL-terminated OSTA compressed format, so we must check for the NULL\r
+    // character.\r
+    //\r
+    if (*String == L'\0') {\r
+      break;\r
+    }\r
+\r
+    String++;\r
+  }\r
+\r
+  Index = ((UINTN)String - (UINTN)StringBak) / sizeof (CHAR16);\r
+  if (Index > CharMax - 1) {\r
+    Index = CharMax - 1;\r
+  }\r
+  StringBak[Index] = L'\0';\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
 /**\r
   Get volume and free space size information of an UDF volume.\r
 \r
index b054c623e5a56683a76e3fd2f632e5454c1a020f..a8a3bed62c22adc7c7d4e5e7b2e79a4a62bde56d 100644 (file)
@@ -900,6 +900,33 @@ SetFileInfo (
   OUT     VOID           *Buffer\r
   );\r
 \r
+/**\r
+  Get volume label of an UDF volume.\r
+\r
+  @attention This is boundary function that may receive untrusted input.\r
+  @attention The input is from FileSystem.\r
+\r
+  The File Set Descriptor is external input, so this routine will do basic\r
+  validation for File Set Descriptor and report status.\r
+\r
+  @param[in]   Volume   Volume information pointer.\r
+  @param[in]   CharMax  The maximum number of Unicode char in String,\r
+                        including terminating null char.\r
+  @param[out]  String   String buffer pointer to store the volume label.\r
+\r
+  @retval EFI_SUCCESS           Volume label is returned.\r
+  @retval EFI_VOLUME_CORRUPTED  The file system structures are corrupted.\r
+  @retval EFI_BUFFER_TOO_SMALL  The string buffer String cannot hold the\r
+                                volume label.\r
+\r
+**/\r
+EFI_STATUS\r
+GetVolumeLabel (\r
+  IN   UDF_VOLUME_INFO  *Volume,\r
+  IN   UINTN            CharMax,\r
+  OUT  CHAR16           *String\r
+  );\r
+\r
 /**\r
   Get volume and free space size information of an UDF volume.\r
 \r
index c8bfc880ed2a5e34e6af299ed0d73300a1624a7c..4f435140e96d70997c86b95fbad9c50a99d90266 100644 (file)
@@ -58,6 +58,7 @@
 [Guids]\r
   gEfiFileInfoGuid                              ## SOMETIMES_CONSUMES ## Protocol\r
   gEfiFileSystemInfoGuid                        ## SOMETIMES_CONSUMES ## Protocol\r
+  gEfiFileSystemVolumeLabelInfoIdGuid           ## SOMETIMES_CONSUMES ## Protocol\r
 \r
 \r
 [Protocols]\r