+/**\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