]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/Disk/UdfDxe/FileSystemOperations.c
MdeModulePkg/UDF: Fix creation of UDF logical partition
[mirror_edk2.git] / MdeModulePkg / Universal / Disk / UdfDxe / FileSystemOperations.c
index 7c83830ec0ea6a945babcb3ed5fa417c1d3a7935..b336ffc553fde30e1b4f426e2429487c4f3a569f 100644 (file)
 \r
 #include "Udf.h"\r
 \r
+//\r
+// Vendor-Defined Device Path GUID for UDF file system\r
+//\r
+EFI_GUID gUdfDevPathGuid = EFI_UDF_DEVICE_PATH_GUID;\r
+\r
+/**\r
+  Find the anchor volume descriptor pointer.\r
+\r
+  @param[in]  BlockIo             BlockIo interface.\r
+  @param[in]  DiskIo              DiskIo interface.\r
+  @param[out] AnchorPoint         Anchor volume descriptor pointer.\r
+\r
+  @retval EFI_SUCCESS             Anchor volume descriptor pointer found.\r
+  @retval EFI_VOLUME_CORRUPTED    The file system structures are corrupted.\r
+  @retval other                   Anchor volume descriptor pointer not found.\r
+\r
+**/\r
 EFI_STATUS\r
 FindAnchorVolumeDescriptorPointer (\r
   IN   EFI_BLOCK_IO_PROTOCOL                 *BlockIo,\r
@@ -21,11 +38,12 @@ FindAnchorVolumeDescriptorPointer (
   OUT  UDF_ANCHOR_VOLUME_DESCRIPTOR_POINTER  *AnchorPoint\r
   )\r
 {\r
-  EFI_STATUS  Status;\r
-  UINT32      BlockSize;\r
-  EFI_LBA     EndLBA;\r
-  EFI_LBA     DescriptorLBAs[4];\r
-  UINTN       Index;\r
+  EFI_STATUS          Status;\r
+  UINT32              BlockSize;\r
+  EFI_LBA             EndLBA;\r
+  EFI_LBA             DescriptorLBAs[4];\r
+  UINTN               Index;\r
+  UDF_DESCRIPTOR_TAG  *DescriptorTag;\r
 \r
   BlockSize = BlockIo->Media->BlockSize;\r
   EndLBA = BlockIo->Media->LastBlock;\r
@@ -45,10 +63,13 @@ FindAnchorVolumeDescriptorPointer (
     if (EFI_ERROR (Status)) {\r
       return Status;\r
     }\r
+\r
+    DescriptorTag = &AnchorPoint->DescriptorTag;\r
+\r
     //\r
     // Check if read LBA has a valid AVDP descriptor.\r
     //\r
-    if (IS_AVDP (AnchorPoint)) {\r
+    if (DescriptorTag->TagIdentifier == UdfAnchorVolumeDescriptorPointer) {\r
       return EFI_SUCCESS;\r
     }\r
   }\r
@@ -58,6 +79,22 @@ FindAnchorVolumeDescriptorPointer (
   return EFI_VOLUME_CORRUPTED;\r
 }\r
 \r
+/**\r
+  Save the content of Logical Volume Descriptors and Partitions Descriptors in\r
+  memory.\r
+\r
+  @param[in]  BlockIo             BlockIo interface.\r
+  @param[in]  DiskIo              DiskIo interface.\r
+  @param[in]  AnchorPoint         Anchor volume descriptor pointer.\r
+  @param[out] Volume              UDF volume information structure.\r
+\r
+  @retval EFI_SUCCESS             The descriptors were saved.\r
+  @retval EFI_OUT_OF_RESOURCES    The descriptors were not saved due to lack of\r
+                                  resources.\r
+  @retval other                   The descriptors were not saved due to\r
+                                  ReadDisk error.\r
+\r
+**/\r
 EFI_STATUS\r
 StartMainVolumeDescriptorSequence (\r
   IN   EFI_BLOCK_IO_PROTOCOL                 *BlockIo,\r
@@ -66,156 +103,112 @@ StartMainVolumeDescriptorSequence (
   OUT  UDF_VOLUME_INFO                       *Volume\r
   )\r
 {\r
-  EFI_STATUS                     Status;\r
-  UINT32                         BlockSize;\r
-  UDF_EXTENT_AD                  *ExtentAd;\r
-  UINT64                         StartingLsn;\r
-  UINT64                         EndingLsn;\r
-  VOID                           *Buffer;\r
-  UDF_LOGICAL_VOLUME_DESCRIPTOR  *LogicalVolDesc;\r
-  UDF_PARTITION_DESCRIPTOR       *PartitionDesc;\r
-  UINTN                          Index;\r
-  UINT32                         LogicalBlockSize;\r
+  EFI_STATUS            Status;\r
+  UINT32                BlockSize;\r
+  UDF_EXTENT_AD         *ExtentAd;\r
+  EFI_LBA               SeqStartBlock;\r
+  EFI_LBA               SeqEndBlock;\r
+  BOOLEAN               StopSequence;\r
+  VOID                  *Buffer;\r
+  UDF_DESCRIPTOR_TAG    *DescriptorTag;\r
+  UINT32                LogicalBlockSize;\r
+\r
+  BlockSize = BlockIo->Media->BlockSize;\r
+  ExtentAd = &AnchorPoint->MainVolumeDescriptorSequenceExtent;\r
 \r
   //\r
-  // We've already found an ADVP on the volume. It contains the extent\r
-  // (MainVolumeDescriptorSequenceExtent) where the Main Volume Descriptor\r
-  // Sequence starts. Therefore, we'll look for Logical Volume Descriptors and\r
-  // Partitions Descriptors and save them in memory, accordingly.\r
-  //\r
-  // Note also that each descriptor will be aligned on a block size (BlockSize)\r
-  // boundary, so we need to read one block at a time.\r
+  // Allocate buffer for reading disk blocks\r
   //\r
-  BlockSize    = BlockIo->Media->BlockSize;\r
-  ExtentAd     = &AnchorPoint->MainVolumeDescriptorSequenceExtent;\r
-  StartingLsn  = (UINT64)ExtentAd->ExtentLocation;\r
-  EndingLsn    = StartingLsn + DivU64x32 (\r
-                                     (UINT64)ExtentAd->ExtentLength,\r
-                                     BlockSize\r
-                                     );\r
-\r
-  Volume->LogicalVolDescs =\r
-    (UDF_LOGICAL_VOLUME_DESCRIPTOR **)AllocateZeroPool (ExtentAd->ExtentLength);\r
-  if (Volume->LogicalVolDescs == NULL) {\r
-    return EFI_OUT_OF_RESOURCES;\r
-  }\r
-\r
-  Volume->PartitionDescs =\r
-    (UDF_PARTITION_DESCRIPTOR **)AllocateZeroPool (ExtentAd->ExtentLength);\r
-  if (Volume->PartitionDescs == NULL) {\r
-    Status = EFI_OUT_OF_RESOURCES;\r
-    goto Error_Alloc_Pds;\r
-  }\r
-\r
-  Buffer = AllocateZeroPool (BlockSize);\r
+  Buffer = AllocateZeroPool ((UINTN)BlockSize);\r
   if (Buffer == NULL) {\r
-    Status = EFI_OUT_OF_RESOURCES;\r
-    goto Error_Alloc_Buf;\r
+    return EFI_OUT_OF_RESOURCES;\r
   }\r
 \r
-  Volume->LogicalVolDescsNo  = 0;\r
-  Volume->PartitionDescsNo   = 0;\r
-\r
-  while (StartingLsn <= EndingLsn) {\r
-    Status = DiskIo->ReadDisk (\r
-      DiskIo,\r
+  //\r
+  // The logical partition created by Partition driver is relative to the main\r
+  // VDS extent location, so we start the Main Volume Descriptor Sequence at\r
+  // LBA 0.\r
+  //\r
+  // We don't need to check again if we have valid Volume Descriptors here since\r
+  // Partition driver already did.\r
+  //\r
+  SeqStartBlock = 0;\r
+  SeqEndBlock = SeqStartBlock + DivU64x32 ((UINT64)ExtentAd->ExtentLength,\r
+                                           BlockSize);\r
+  StopSequence = FALSE;\r
+  for (; SeqStartBlock < SeqEndBlock && !StopSequence; SeqStartBlock++) {\r
+    //\r
+    // Read disk block\r
+    //\r
+    Status = BlockIo->ReadBlocks (\r
+      BlockIo,\r
       BlockIo->Media->MediaId,\r
-      MultU64x32 (StartingLsn, BlockSize),\r
+      SeqStartBlock,\r
       BlockSize,\r
       Buffer\r
       );\r
     if (EFI_ERROR (Status)) {\r
-      goto Error_Read_Disk_Blk;\r
+      goto Out_Free;\r
     }\r
 \r
-    if (IS_TD (Buffer)) {\r
+    DescriptorTag = Buffer;\r
+\r
+    switch (DescriptorTag->TagIdentifier) {\r
+    case UdfPartitionDescriptor:\r
       //\r
-      // Found a Terminating Descriptor. Stop the sequence then.\r
+      // Save Partition Descriptor\r
       //\r
+      CopyMem (&Volume->PartitionDesc, Buffer, sizeof (Volume->PartitionDesc));\r
       break;\r
-    }\r
 \r
-    if (IS_LVD (Buffer)) {\r
+    case UdfLogicalVolumeDescriptor:\r
       //\r
-      // Found a Logical Volume Descriptor.\r
+      // Save Logical Volume Descriptor\r
       //\r
-      LogicalVolDesc =\r
-        (UDF_LOGICAL_VOLUME_DESCRIPTOR *)\r
-        AllocateZeroPool (sizeof (UDF_LOGICAL_VOLUME_DESCRIPTOR));\r
-      if (LogicalVolDesc == NULL) {\r
-        Status = EFI_OUT_OF_RESOURCES;\r
-        goto Error_Alloc_Lvd;\r
-      }\r
+      CopyMem (&Volume->LogicalVolDesc, Buffer, sizeof (Volume->LogicalVolDesc));\r
+      break;\r
 \r
-      CopyMem ((VOID *)LogicalVolDesc, Buffer,\r
-               sizeof (UDF_LOGICAL_VOLUME_DESCRIPTOR));\r
-      Volume->LogicalVolDescs[Volume->LogicalVolDescsNo++] = LogicalVolDesc;\r
-    } else if (IS_PD (Buffer)) {\r
-      //\r
-      // Found a Partition Descriptor.\r
-      //\r
-      PartitionDesc =\r
-        (UDF_PARTITION_DESCRIPTOR *)\r
-        AllocateZeroPool (sizeof (UDF_PARTITION_DESCRIPTOR));\r
-      if (PartitionDesc == NULL) {\r
-        Status = EFI_OUT_OF_RESOURCES;\r
-        goto Error_Alloc_Pd;\r
-      }\r
+    case UdfTerminatingDescriptor:\r
+      StopSequence = TRUE;\r
+      break;\r
 \r
-      CopyMem ((VOID *)PartitionDesc, Buffer,\r
-               sizeof (UDF_PARTITION_DESCRIPTOR));\r
-      Volume->PartitionDescs[Volume->PartitionDescsNo++] = PartitionDesc;\r
+    default:\r
+      ;\r
     }\r
-\r
-    StartingLsn++;\r
   }\r
 \r
   //\r
-  // When an UDF volume (revision 2.00 or higher) contains a File Entry rather\r
-  // than an Extended File Entry (which is not recommended as per spec), we need\r
-  // to make sure the size of a FE will be _at least_ 2048\r
-  // (UDF_LOGICAL_SECTOR_SIZE) bytes long to keep backward compatibility.\r
+  // Determine FE (File Entry) size\r
   //\r
-  LogicalBlockSize = LV_BLOCK_SIZE (Volume, UDF_DEFAULT_LV_NUM);\r
+  LogicalBlockSize = Volume->LogicalVolDesc.LogicalBlockSize;\r
   if (LogicalBlockSize >= UDF_LOGICAL_SECTOR_SIZE) {\r
-    Volume->FileEntrySize = LogicalBlockSize;\r
+    Volume->FileEntrySize = (UINTN)LogicalBlockSize;\r
   } else {\r
     Volume->FileEntrySize = UDF_LOGICAL_SECTOR_SIZE;\r
   }\r
 \r
-  FreePool (Buffer);\r
-\r
-  return EFI_SUCCESS;\r
-\r
-Error_Alloc_Pd:\r
-Error_Alloc_Lvd:\r
-  for (Index = 0; Index < Volume->PartitionDescsNo; Index++) {\r
-    FreePool ((VOID *)Volume->PartitionDescs[Index]);\r
-  }\r
-\r
-  for (Index = 0; Index < Volume->LogicalVolDescsNo; Index++) {\r
-    FreePool ((VOID *)Volume->LogicalVolDescs[Index]);\r
-  }\r
+  Status = EFI_SUCCESS;\r
 \r
-Error_Read_Disk_Blk:\r
+Out_Free:\r
+  //\r
+  // Free block read buffer\r
+  //\r
   FreePool (Buffer);\r
 \r
-Error_Alloc_Buf:\r
-  FreePool ((VOID *)Volume->PartitionDescs);\r
-  Volume->PartitionDescs = NULL;\r
-\r
-Error_Alloc_Pds:\r
-  FreePool ((VOID *)Volume->LogicalVolDescs);\r
-  Volume->LogicalVolDescs = NULL;\r
-\r
   return Status;\r
 }\r
 \r
-//\r
-// Return a Partition Descriptor given a Long Allocation Descriptor. This is\r
-// necessary to calculate the right extent (LongAd) offset which is added up\r
-// with partition's starting location.\r
-//\r
+/**\r
+  Return a Partition Descriptor given a Long Allocation Descriptor. This is\r
+  necessary to calculate the right extent (LongAd) offset which is added up\r
+  with partition's starting location.\r
+\r
+  @param[in]  Volume              Volume information pointer.\r
+  @param[in]  LongAd              Long Allocation Descriptor pointer.\r
+\r
+  @return A pointer to a Partition Descriptor.\r
+\r
+**/\r
 UDF_PARTITION_DESCRIPTOR *\r
 GetPdFromLongAd (\r
   IN UDF_VOLUME_INFO                 *Volume,\r
@@ -223,56 +216,67 @@ GetPdFromLongAd (
   )\r
 {\r
   UDF_LOGICAL_VOLUME_DESCRIPTOR  *LogicalVolDesc;\r
-  UINTN                          Index;\r
-  UDF_PARTITION_DESCRIPTOR       *PartitionDesc;\r
   UINT16                         PartitionNum;\r
 \r
-  LogicalVolDesc = Volume->LogicalVolDescs[UDF_DEFAULT_LV_NUM];\r
+  LogicalVolDesc = &Volume->LogicalVolDesc;\r
 \r
-  switch (LV_UDF_REVISION (LogicalVolDesc)) {\r
+  switch (LogicalVolDesc->DomainIdentifier.Suffix.Domain.UdfRevision) {\r
   case 0x0102:\r
+  case 0x0150:\r
+  case 0x0200:\r
+  case 0x0201:\r
+  case 0x0250:\r
+  case 0x0260:\r
     //\r
-    // As per UDF 1.02 specification:\r
+    // UDF 1.02 specification:\r
     //\r
     // There shall be exactly one prevailing Logical Volume Descriptor recorded\r
     // per Volume Set. The Partition Maps field shall contain only Type 1\r
     // Partition Maps.\r
     //\r
-    PartitionNum = *(UINT16 *)((UINTN)&LogicalVolDesc->PartitionMaps[4]);\r
-    break;\r
-  case 0x0150:\r
+    // UDF 1.50 through 2.60 specs say:\r
     //\r
-    // Ensure Type 1 Partition map. Other types aren't supported in this\r
-    // implementation.\r
+    // For the purpose of interchange partition maps shall be limited to\r
+    // Partition Map type 1, except type 2 maps as described in the document.\r
+    //\r
+    // NOTE: Only one Type 1 (Physical) Partition is supported. It has been\r
+    // checked already in Partition driver for existence of a single Type 1\r
+    // Partition map, so we don't have to double check here.\r
+    //\r
+    // Partition reference number can also be retrieved from\r
+    // LongAd->ExtentLocation.PartitionReferenceNumber, however the spec says\r
+    // it may be 0, so let's not rely on it.\r
     //\r
-    if (LogicalVolDesc->PartitionMaps[0] != 1 ||\r
-        LogicalVolDesc->PartitionMaps[1] != 6) {\r
-      return NULL;\r
-    }\r
     PartitionNum = *(UINT16 *)((UINTN)&LogicalVolDesc->PartitionMaps[4]);\r
     break;\r
-  case 0x0260:\r
+\r
+  default:\r
     //\r
-    // Fall through.\r
+    // Unsupported UDF revision\r
     //\r
-  default:\r
-    PartitionNum = LongAd->ExtentLocation.PartitionReferenceNumber;\r
-    break;\r
+    return NULL;\r
   }\r
 \r
-  for (Index = 0; Index < Volume->PartitionDescsNo; Index++) {\r
-    PartitionDesc = Volume->PartitionDescs[Index];\r
-    if (PartitionDesc->PartitionNumber == PartitionNum) {\r
-      return PartitionDesc;\r
-    }\r
+  //\r
+  // Check if partition number matches Partition Descriptor found in Main Volume\r
+  // Descriptor Sequence.\r
+  //\r
+  if (Volume->PartitionDesc.PartitionNumber == PartitionNum) {\r
+    return &Volume->PartitionDesc;\r
   }\r
 \r
   return NULL;\r
 }\r
 \r
-//\r
-// Return logical sector number of a given Long Allocation Descriptor.\r
-//\r
+/**\r
+  Return logical sector number of a given Long Allocation Descriptor.\r
+\r
+  @param[in]  Volume              Volume information pointer.\r
+  @param[in]  LongAd              Long Allocation Descriptor pointer.\r
+\r
+  @return The logical sector number of a given Long Allocation Descriptor.\r
+\r
+**/\r
 UINT64\r
 GetLongAdLsn (\r
   IN UDF_VOLUME_INFO                 *Volume,\r
@@ -284,139 +288,104 @@ GetLongAdLsn (
   PartitionDesc = GetPdFromLongAd (Volume, LongAd);\r
   ASSERT (PartitionDesc != NULL);\r
 \r
-  return (UINT64)PartitionDesc->PartitionStartingLocation +\r
-                 LongAd->ExtentLocation.LogicalBlockNumber;\r
+  return (UINT64)PartitionDesc->PartitionStartingLocation -\r
+    Volume->MainVdsStartLocation +\r
+    LongAd->ExtentLocation.LogicalBlockNumber;\r
 }\r
 \r
-//\r
-// Return logical sector number of a given Short Allocation Descriptor.\r
-//\r
+/**\r
+  Return logical sector number of a given Short Allocation Descriptor.\r
+\r
+  @param[in]  Volume              Volume pointer.\r
+  @param[in]  PartitionDesc       Partition Descriptor pointer.\r
+  @param[in]  ShortAd             Short Allocation Descriptor pointer.\r
+\r
+  @return The logical sector number of a given Short Allocation Descriptor.\r
+\r
+**/\r
 UINT64\r
 GetShortAdLsn (\r
+  IN UDF_VOLUME_INFO                  *Volume,\r
   IN UDF_PARTITION_DESCRIPTOR         *PartitionDesc,\r
   IN UDF_SHORT_ALLOCATION_DESCRIPTOR  *ShortAd\r
   )\r
 {\r
-  ASSERT (PartitionDesc != NULL);\r
-\r
-  return (UINT64)PartitionDesc->PartitionStartingLocation +\r
-    ShortAd->ExtentPosition;\r
+  return (UINT64)PartitionDesc->PartitionStartingLocation -\r
+    Volume->MainVdsStartLocation + ShortAd->ExtentPosition;\r
 }\r
 \r
-//\r
-// Find File Set Descriptor of a given Logical Volume Descriptor.\r
-//\r
-// The found FSD will contain the extent (LogicalVolumeContentsUse) where our\r
-// root directory is.\r
-//\r
+/**\r
+  Find File Set Descriptor of a given Logical Volume Descriptor.\r
+\r
+  The found FSD will contain the extent (LogicalVolumeContentsUse) where our\r
+  root directory is.\r
+\r
+  @param[in]  BlockIo             BlockIo interface.\r
+  @param[in]  DiskIo              DiskIo interface.\r
+  @param[in]  Volume              Volume information pointer.\r
+\r
+  @retval EFI_SUCCESS             File Set Descriptor pointer found.\r
+  @retval EFI_VOLUME_CORRUPTED    The file system structures are corrupted.\r
+  @retval other                   File Set Descriptor pointer not found.\r
+\r
+**/\r
 EFI_STATUS\r
 FindFileSetDescriptor (\r
   IN   EFI_BLOCK_IO_PROTOCOL    *BlockIo,\r
   IN   EFI_DISK_IO_PROTOCOL     *DiskIo,\r
-  IN   UDF_VOLUME_INFO          *Volume,\r
-  IN   UINTN                    LogicalVolDescNum,\r
-  OUT  UDF_FILE_SET_DESCRIPTOR  *FileSetDesc\r
+  IN   UDF_VOLUME_INFO          *Volume\r
   )\r
 {\r
   EFI_STATUS                     Status;\r
   UINT64                         Lsn;\r
   UDF_LOGICAL_VOLUME_DESCRIPTOR  *LogicalVolDesc;\r
+  UDF_DESCRIPTOR_TAG             *DescriptorTag;\r
 \r
-  LogicalVolDesc = Volume->LogicalVolDescs[LogicalVolDescNum];\r
+  LogicalVolDesc = &Volume->LogicalVolDesc;\r
   Lsn = GetLongAdLsn (Volume, &LogicalVolDesc->LogicalVolumeContentsUse);\r
 \r
   //\r
-  // Read extent (Long Ad).\r
+  // As per UDF 2.60 specification:\r
+  //\r
+  // There shall be exactly one File Set Descriptor recorded per Logical\r
+  // Volume.\r
+  //\r
+  // Read disk block\r
   //\r
   Status = DiskIo->ReadDisk (\r
     DiskIo,\r
     BlockIo->Media->MediaId,\r
     MultU64x32 (Lsn, LogicalVolDesc->LogicalBlockSize),\r
-    sizeof (UDF_FILE_SET_DESCRIPTOR),\r
-    (VOID *)FileSetDesc\r
+    sizeof (Volume->FileSetDesc),\r
+    &Volume->FileSetDesc\r
     );\r
   if (EFI_ERROR (Status)) {\r
     return Status;\r
   }\r
 \r
+  DescriptorTag = &Volume->FileSetDesc.DescriptorTag;\r
+\r
   //\r
-  // Check if the read extent contains a valid FSD's tag identifier.\r
+  // Check if read block is a File Set Descriptor\r
   //\r
-  if (!IS_FSD (FileSetDesc)) {\r
+  if (DescriptorTag->TagIdentifier != UdfFileSetDescriptor) {\r
     return EFI_VOLUME_CORRUPTED;\r
   }\r
 \r
   return EFI_SUCCESS;\r
 }\r
 \r
-//\r
-// Get all File Set Descriptors for each Logical Volume Descriptor.\r
-//\r
-EFI_STATUS\r
-GetFileSetDescriptors (\r
-  IN      EFI_BLOCK_IO_PROTOCOL  *BlockIo,\r
-  IN      EFI_DISK_IO_PROTOCOL   *DiskIo,\r
-  IN OUT  UDF_VOLUME_INFO        *Volume\r
-  )\r
-{\r
-  EFI_STATUS               Status;\r
-  UINTN                    Index;\r
-  UDF_FILE_SET_DESCRIPTOR  *FileSetDesc;\r
-  UINTN                    Count;\r
-\r
-  Volume->FileSetDescs =\r
-    (UDF_FILE_SET_DESCRIPTOR **)AllocateZeroPool (\r
-      Volume->LogicalVolDescsNo * sizeof (UDF_FILE_SET_DESCRIPTOR));\r
-  if (Volume->FileSetDescs == NULL) {\r
-    return EFI_OUT_OF_RESOURCES;\r
-  }\r
-\r
-  for (Index = 0; Index < Volume->LogicalVolDescsNo; Index++) {\r
-    FileSetDesc = AllocateZeroPool (sizeof (UDF_FILE_SET_DESCRIPTOR));\r
-    if (FileSetDesc == NULL) {\r
-      Status = EFI_OUT_OF_RESOURCES;\r
-      goto Error_Alloc_Fsd;\r
-    }\r
-\r
-    //\r
-    // Find a FSD for this LVD.\r
-    //\r
-    Status = FindFileSetDescriptor (\r
-      BlockIo,\r
-      DiskIo,\r
-      Volume,\r
-      Index,\r
-      FileSetDesc\r
-      );\r
-    if (EFI_ERROR (Status)) {\r
-      goto Error_Find_Fsd;\r
-    }\r
-\r
-    //\r
-    // Got one. Save it.\r
-    //\r
-    Volume->FileSetDescs[Index] = FileSetDesc;\r
-  }\r
-\r
-  Volume->FileSetDescsNo = Volume->LogicalVolDescsNo;\r
-  return EFI_SUCCESS;\r
-\r
-Error_Find_Fsd:\r
-  Count = Index + 1;\r
-  for (Index = 0; Index < Count; Index++) {\r
-    FreePool ((VOID *)Volume->FileSetDescs[Index]);\r
-  }\r
+/**\r
+  Read Volume and File Structure on an UDF file system.\r
 \r
-  FreePool ((VOID *)Volume->FileSetDescs);\r
-  Volume->FileSetDescs = NULL;\r
+  @param[in]   BlockIo            BlockIo interface.\r
+  @param[in]   DiskIo             DiskIo interface.\r
+  @param[out]  Volume             Volume information pointer.\r
 \r
-Error_Alloc_Fsd:\r
-  return Status;\r
-}\r
+  @retval EFI_SUCCESS             Volume and File Structure were read.\r
+  @retval other                   Volume and File Structure were not read.\r
 \r
-//\r
-// Read Volume and File Structure on an UDF file system.\r
-//\r
+**/\r
 EFI_STATUS\r
 ReadVolumeFileStructure (\r
   IN   EFI_BLOCK_IO_PROTOCOL  *BlockIo,\r
@@ -426,9 +395,10 @@ ReadVolumeFileStructure (
 {\r
   EFI_STATUS                            Status;\r
   UDF_ANCHOR_VOLUME_DESCRIPTOR_POINTER  AnchorPoint;\r
+  UDF_EXTENT_AD                         *ExtentAd;\r
 \r
   //\r
-  // Find an AVDP.\r
+  // Find Anchor Volume Descriptor Pointer\r
   //\r
   Status = FindAnchorVolumeDescriptorPointer (\r
     BlockIo,\r
@@ -440,7 +410,14 @@ ReadVolumeFileStructure (
   }\r
 \r
   //\r
-  // AVDP has been found. Start MVDS.\r
+  // Save Main VDS start block number\r
+  //\r
+  ExtentAd = &AnchorPoint.MainVolumeDescriptorSequenceExtent;\r
+\r
+  Volume->MainVdsStartLocation = (UINT64)ExtentAd->ExtentLocation;\r
+\r
+  //\r
+  // Start Main Volume Descriptor Sequence.\r
   //\r
   Status = StartMainVolumeDescriptorSequence (\r
     BlockIo,\r
@@ -455,9 +432,14 @@ ReadVolumeFileStructure (
   return Status;\r
 }\r
 \r
-//\r
-// Calculate length of a given File Identifier Descriptor.\r
-//\r
+/**\r
+  Calculate length of a given File Identifier Descriptor.\r
+\r
+  @param[in]  FileIdentifierDesc  File Identifier Descriptor pointer.\r
+\r
+  @return The length of a given File Identifier Descriptor.\r
+\r
+**/\r
 UINT64\r
 GetFidDescriptorLength (\r
   IN UDF_FILE_IDENTIFIER_DESCRIPTOR  *FileIdentifierDesc\r
@@ -470,9 +452,13 @@ GetFidDescriptorLength (
              );\r
 }\r
 \r
-//\r
-// Duplicate a given File Identifier Descriptor.\r
-//\r
+/**\r
+  Duplicate a given File Identifier Descriptor.\r
+\r
+  @param[in]  FileIdentifierDesc     File Identifier Descriptor pointer.\r
+  @param[out] NewFileIdentifierDesc  The duplicated File Identifier Descriptor.\r
+\r
+**/\r
 VOID\r
 DuplicateFid (\r
   IN   UDF_FILE_IDENTIFIER_DESCRIPTOR  *FileIdentifierDesc,\r
@@ -486,9 +472,15 @@ DuplicateFid (
   ASSERT (*NewFileIdentifierDesc != NULL);\r
 }\r
 \r
-//\r
-// Duplicate either a given File Entry or a given Extended File Entry.\r
-//\r
+/**\r
+  Duplicate either a given File Entry or a given Extended File Entry.\r
+\r
+  @param[in]  BlockIo             BlockIo interface.\r
+  @param[in]  Volume              Volume information pointer.\r
+  @param[in]  FileEntry           (Extended) File Entry pointer.\r
+  @param[out] NewFileEntry        The duplicated (Extended) File Entry.\r
+\r
+**/\r
 VOID\r
 DuplicateFe (\r
   IN   EFI_BLOCK_IO_PROTOCOL  *BlockIo,\r
@@ -502,15 +494,21 @@ DuplicateFe (
   ASSERT (*NewFileEntry != NULL);\r
 }\r
 \r
-//\r
-// Get raw data + length of a given File Entry or Extended File Entry.\r
-//\r
-// The file's recorded data can contain either real file content (inline) or\r
-// a sequence of extents (or Allocation Descriptors) which tells where file's\r
-// content is stored in.\r
-//\r
-// NOTE: The FE/EFE can be thought it was an inode.\r
-//\r
+/**\r
+  Get raw data + length of a given File Entry or Extended File Entry.\r
+\r
+  The file's recorded data can contain either real file content (inline) or\r
+  a sequence of extents (or Allocation Descriptors) which tells where file's\r
+  content is stored in.\r
+\r
+  NOTE: The FE/EFE can be thought it was an inode.\r
+\r
+  @param[in]  FileEntryData       (Extended) File Entry pointer.\r
+  @param[out] Data                Buffer contains the raw data of a given\r
+                                  (Extended) File Entry.\r
+  @param[out] Length              Length of the data in Buffer.\r
+\r
+**/\r
 VOID\r
 GetFileEntryData (\r
   IN   VOID    *FileEntryData,\r
@@ -518,16 +516,19 @@ GetFileEntryData (
   OUT  UINT64  *Length\r
   )\r
 {\r
+  UDF_DESCRIPTOR_TAG       *DescriptorTag;\r
   UDF_EXTENDED_FILE_ENTRY  *ExtendedFileEntry;\r
   UDF_FILE_ENTRY           *FileEntry;\r
 \r
-  if (IS_EFE (FileEntryData)) {\r
+  DescriptorTag = FileEntryData;\r
+\r
+  if (DescriptorTag->TagIdentifier == UdfExtendedFileEntry) {\r
     ExtendedFileEntry = (UDF_EXTENDED_FILE_ENTRY *)FileEntryData;\r
 \r
     *Length  = ExtendedFileEntry->InformationLength;\r
     *Data    = (VOID *)((UINT8 *)ExtendedFileEntry->Data +\r
                         ExtendedFileEntry->LengthOfExtendedAttributes);\r
-  } else if (IS_FE (FileEntryData)) {\r
+  } else if (DescriptorTag->TagIdentifier == UdfFileEntry) {\r
     FileEntry = (UDF_FILE_ENTRY *)FileEntryData;\r
 \r
     *Length  = FileEntry->InformationLength;\r
@@ -536,9 +537,15 @@ GetFileEntryData (
   }\r
 }\r
 \r
-//\r
-// Get Allocation Descriptors' data information from a given FE/EFE.\r
-//\r
+/**\r
+  Get Allocation Descriptors' data information from a given FE/EFE.\r
+\r
+  @param[in]  FileEntryData       (Extended) File Entry pointer.\r
+  @param[out] AdsData             Buffer contains the Allocation Descriptors'\r
+                                  data from a given FE/EFE.\r
+  @param[out] Length              Length of the data in AdsData.\r
+\r
+**/\r
 VOID\r
 GetAdsInformation (\r
   IN   VOID    *FileEntryData,\r
@@ -546,16 +553,19 @@ GetAdsInformation (
   OUT  UINT64  *Length\r
   )\r
 {\r
+  UDF_DESCRIPTOR_TAG       *DescriptorTag;\r
   UDF_EXTENDED_FILE_ENTRY  *ExtendedFileEntry;\r
   UDF_FILE_ENTRY           *FileEntry;\r
 \r
-  if (IS_EFE (FileEntryData)) {\r
+  DescriptorTag = FileEntryData;\r
+\r
+  if (DescriptorTag->TagIdentifier == UdfExtendedFileEntry) {\r
     ExtendedFileEntry = (UDF_EXTENDED_FILE_ENTRY *)FileEntryData;\r
 \r
     *Length = ExtendedFileEntry->LengthOfAllocationDescriptors;\r
     *AdsData = (VOID *)((UINT8 *)ExtendedFileEntry->Data +\r
                         ExtendedFileEntry->LengthOfExtendedAttributes);\r
-  } else if (IS_FE (FileEntryData)) {\r
+  } else if (DescriptorTag->TagIdentifier == UdfFileEntry) {\r
     FileEntry = (UDF_FILE_ENTRY *)FileEntryData;\r
 \r
     *Length = FileEntry->LengthOfAllocationDescriptors;\r
@@ -564,9 +574,18 @@ GetAdsInformation (
   }\r
 }\r
 \r
-//\r
-// Read next Long Allocation Descriptor from a given file's data.\r
-//\r
+/**\r
+  Read next Long Allocation Descriptor from a given file's data.\r
+\r
+  @param[in]     Data             File's data pointer.\r
+  @param[in,out] Offset           Starting offset of the File's data to read.\r
+  @param[in]     Length           Length of the data to read.\r
+  @param[out]    FoundLongAd      Long Allocation Descriptor pointer.\r
+\r
+  @retval EFI_SUCCESS             A Long Allocation Descriptor was found.\r
+  @retval EFI_DEVICE_ERROR        No more Long Allocation Descriptors.\r
+\r
+**/\r
 EFI_STATUS\r
 GetLongAdFromAds (\r
   IN      VOID                            *Data,\r
@@ -593,9 +612,9 @@ GetLongAdFromAds (
     // If it's either an indirect AD (Extended Alllocation Descriptor) or an\r
     // allocated AD, then return it.\r
     //\r
-    ExtentFlags = GET_EXTENT_FLAGS (LONG_ADS_SEQUENCE, LongAd);\r
-    if (ExtentFlags == EXTENT_IS_NEXT_EXTENT ||\r
-        ExtentFlags == EXTENT_RECORDED_AND_ALLOCATED) {\r
+    ExtentFlags = GET_EXTENT_FLAGS (LongAdsSequence, LongAd);\r
+    if (ExtentFlags == ExtentIsNextExtent ||\r
+        ExtentFlags == ExtentRecordedAndAllocated) {\r
       break;\r
     }\r
 \r
@@ -603,7 +622,7 @@ GetLongAdFromAds (
     // This AD is either not recorded but allocated, or not recorded and not\r
     // allocated. Skip it.\r
     //\r
-    *Offset += AD_LENGTH (LONG_ADS_SEQUENCE);\r
+    *Offset += AD_LENGTH (LongAdsSequence);\r
   }\r
 \r
   *FoundLongAd = LongAd;\r
@@ -611,9 +630,18 @@ GetLongAdFromAds (
   return EFI_SUCCESS;\r
 }\r
 \r
-//\r
-// Read next Short Allocation Descriptor from a given file's data.\r
-//\r
+/**\r
+  Read next Short Allocation Descriptor from a given file's data.\r
+\r
+  @param[in]     Data             File's data pointer.\r
+  @param[in,out] Offset           Starting offset of the File's data to read.\r
+  @param[in]     Length           Length of the data to read.\r
+  @param[out]    FoundShortAd     Short Allocation Descriptor pointer.\r
+\r
+  @retval EFI_SUCCESS             A Short Allocation Descriptor was found.\r
+  @retval EFI_DEVICE_ERROR        No more Short Allocation Descriptors.\r
+\r
+**/\r
 EFI_STATUS\r
 GetShortAdFromAds (\r
   IN      VOID                             *Data,\r
@@ -640,9 +668,9 @@ GetShortAdFromAds (
     // If it's either an indirect AD (Extended Alllocation Descriptor) or an\r
     // allocated AD, then return it.\r
     //\r
-    ExtentFlags = GET_EXTENT_FLAGS (SHORT_ADS_SEQUENCE, ShortAd);\r
-    if (ExtentFlags == EXTENT_IS_NEXT_EXTENT ||\r
-        ExtentFlags == EXTENT_RECORDED_AND_ALLOCATED) {\r
+    ExtentFlags = GET_EXTENT_FLAGS (ShortAdsSequence, ShortAd);\r
+    if (ExtentFlags == ExtentIsNextExtent ||\r
+        ExtentFlags == ExtentRecordedAndAllocated) {\r
       break;\r
     }\r
 \r
@@ -650,7 +678,7 @@ GetShortAdFromAds (
     // This AD is either not recorded but allocated, or not recorded and not\r
     // allocated. Skip it.\r
     //\r
-    *Offset += AD_LENGTH (SHORT_ADS_SEQUENCE);\r
+    *Offset += AD_LENGTH (ShortAdsSequence);\r
   }\r
 \r
   *FoundShortAd = ShortAd;\r
@@ -658,10 +686,21 @@ GetShortAdFromAds (
   return EFI_SUCCESS;\r
 }\r
 \r
-//\r
-// Get either a Short Allocation Descriptor or a Long Allocation Descriptor from\r
-// file's data.\r
-//\r
+/**\r
+  Get either a Short Allocation Descriptor or a Long Allocation Descriptor from\r
+  file's data.\r
+\r
+  @param[in]     RecordingFlags   Flag to indicate the type of descriptor.\r
+  @param[in]     Data             File's data pointer.\r
+  @param[in,out] Offset           Starting offset of the File's data to read.\r
+  @param[in]     Length           Length of the data to read.\r
+  @param[out]    FoundAd          Allocation Descriptor pointer.\r
+\r
+  @retval EFI_SUCCESS             A Short Allocation Descriptor was found.\r
+  @retval EFI_DEVICE_ERROR        No more Allocation Descriptors.\r
+                                  Invalid type of descriptor was given.\r
+\r
+**/\r
 EFI_STATUS\r
 GetAllocationDescriptor (\r
   IN      UDF_FE_RECORDING_FLAGS  RecordingFlags,\r
@@ -671,14 +710,14 @@ GetAllocationDescriptor (
   OUT     VOID                    **FoundAd\r
   )\r
 {\r
-  if (RecordingFlags == LONG_ADS_SEQUENCE) {\r
+  if (RecordingFlags == LongAdsSequence) {\r
     return GetLongAdFromAds (\r
       Data,\r
       Offset,\r
       Length,\r
       (UDF_LONG_ALLOCATION_DESCRIPTOR **)FoundAd\r
       );\r
-  } else if (RecordingFlags == SHORT_ADS_SEQUENCE) {\r
+  } else if (RecordingFlags == ShortAdsSequence) {\r
     return GetShortAdFromAds (\r
       Data,\r
       Offset,\r
@@ -690,9 +729,17 @@ GetAllocationDescriptor (
   return EFI_DEVICE_ERROR;\r
 }\r
 \r
-//\r
-// Return logical sector number of either Short or Long Allocation Descriptor.\r
-//\r
+/**\r
+  Return logical sector number of either Short or Long Allocation Descriptor.\r
+\r
+  @param[in]  RecordingFlags      Flag to indicate the type of descriptor.\r
+  @param[in]  Volume              Volume information pointer.\r
+  @param[in]  ParentIcb           Long Allocation Descriptor pointer.\r
+  @param[in]  Ad                  Allocation Descriptor pointer.\r
+\r
+  @return The logical sector number of the given Allocation Descriptor.\r
+\r
+**/\r
 UINT64\r
 GetAllocationDescriptorLsn (\r
   IN UDF_FE_RECORDING_FLAGS          RecordingFlags,\r
@@ -701,10 +748,11 @@ GetAllocationDescriptorLsn (
   IN VOID                            *Ad\r
   )\r
 {\r
-  if (RecordingFlags == LONG_ADS_SEQUENCE) {\r
+  if (RecordingFlags == LongAdsSequence) {\r
     return GetLongAdLsn (Volume, (UDF_LONG_ALLOCATION_DESCRIPTOR *)Ad);\r
-  } else if (RecordingFlags == SHORT_ADS_SEQUENCE) {\r
+  } else if (RecordingFlags == ShortAdsSequence) {\r
     return GetShortAdLsn (\r
+      Volume,\r
       GetPdFromLongAd (Volume, ParentIcb),\r
       (UDF_SHORT_ALLOCATION_DESCRIPTOR *)Ad\r
       );\r
@@ -713,9 +761,27 @@ GetAllocationDescriptorLsn (
   return 0;\r
 }\r
 \r
-//\r
-// Return offset + length of a given indirect Allocation Descriptor (AED).\r
-//\r
+/**\r
+  Return offset + length of a given indirect Allocation Descriptor (AED).\r
+\r
+  @param[in]  BlockIo             BlockIo interface.\r
+  @param[in]  DiskIo              DiskIo interface.\r
+  @param[in]  Volume              Volume information pointer.\r
+  @param[in]  ParentIcb           Long Allocation Descriptor pointer.\r
+  @param[in]  RecordingFlags      Flag to indicate the type of descriptor.\r
+  @param[in]  Ad                  Allocation Descriptor pointer.\r
+  @param[out] Offset              Offset of a given indirect Allocation\r
+                                  Descriptor.\r
+  @param[out] Length              Length of a given indirect Allocation\r
+                                  Descriptor.\r
+\r
+  @retval EFI_SUCCESS             The offset and length were returned.\r
+  @retval EFI_OUT_OF_RESOURCES    The offset and length were not returned due\r
+                                  to lack of resources.\r
+  @retval EFI_VOLUME_CORRUPTED    The file system structures are corrupted.\r
+  @retval other                   The offset and length were not returned.\r
+\r
+**/\r
 EFI_STATUS\r
 GetAedAdsOffset (\r
   IN   EFI_BLOCK_IO_PROTOCOL           *BlockIo,\r
@@ -734,6 +800,7 @@ GetAedAdsOffset (
   VOID                              *Data;\r
   UINT32                            LogicalBlockSize;\r
   UDF_ALLOCATION_EXTENT_DESCRIPTOR  *AllocExtDesc;\r
+  UDF_DESCRIPTOR_TAG                *DescriptorTag;\r
 \r
   ExtentLength  = GET_EXTENT_LENGTH (RecordingFlags, Ad);\r
   Lsn           = GetAllocationDescriptorLsn (RecordingFlags,\r
@@ -746,7 +813,7 @@ GetAedAdsOffset (
     return EFI_OUT_OF_RESOURCES;\r
   }\r
 \r
-  LogicalBlockSize = LV_BLOCK_SIZE (Volume, UDF_DEFAULT_LV_NUM);\r
+  LogicalBlockSize = Volume->LogicalVolDesc.LogicalBlockSize;\r
 \r
   //\r
   // Read extent.\r
@@ -762,11 +829,14 @@ GetAedAdsOffset (
     goto Exit;\r
   }\r
 \r
+  AllocExtDesc = (UDF_ALLOCATION_EXTENT_DESCRIPTOR *)Data;\r
+\r
+  DescriptorTag = &AllocExtDesc->DescriptorTag;\r
+\r
   //\r
   // Check if read extent contains a valid tag identifier for AED.\r
   //\r
-  AllocExtDesc = (UDF_ALLOCATION_EXTENT_DESCRIPTOR *)Data;\r
-  if (!IS_AED (AllocExtDesc)) {\r
+  if (DescriptorTag->TagIdentifier != UdfAllocationExtentDescriptor) {\r
     Status = EFI_VOLUME_CORRUPTED;\r
     goto Exit;\r
   }\r
@@ -784,9 +854,25 @@ Exit:
   return Status;\r
 }\r
 \r
-//\r
-// Read Allocation Extent Descriptor into memory.\r
-//\r
+/**\r
+  Read Allocation Extent Descriptor into memory.\r
+\r
+  @param[in]  BlockIo             BlockIo interface.\r
+  @param[in]  DiskIo              DiskIo interface.\r
+  @param[in]  Volume              Volume information pointer.\r
+  @param[in]  ParentIcb           Long Allocation Descriptor pointer.\r
+  @param[in]  RecordingFlags      Flag to indicate the type of descriptor.\r
+  @param[in]  Ad                  Allocation Descriptor pointer.\r
+  @param[out] Data                Buffer that contains the Allocation Extent\r
+                                  Descriptor.\r
+  @param[out] Length              Length of Data.\r
+\r
+  @retval EFI_SUCCESS             The Allocation Extent Descriptor was read.\r
+  @retval EFI_OUT_OF_RESOURCES    The Allocation Extent Descriptor was not read\r
+                                  due to lack of resources.\r
+  @retval other                   Fail to read the disk.\r
+\r
+**/\r
 EFI_STATUS\r
 GetAedAdsData (\r
   IN   EFI_BLOCK_IO_PROTOCOL           *BlockIo,\r
@@ -836,9 +922,19 @@ GetAedAdsData (
     );\r
 }\r
 \r
-//\r
-// Function used to serialise reads of Allocation Descriptors.\r
-//\r
+/**\r
+  Function used to serialise reads of Allocation Descriptors.\r
+\r
+  @param[in]      RecordingFlags  Flag to indicate the type of descriptor.\r
+  @param[in]      Ad              Allocation Descriptor pointer.\r
+  @param[in, out] Buffer          Buffer to hold the next Allocation Descriptor.\r
+  @param[in]      Length          Length of Buffer.\r
+\r
+  @retval EFI_SUCCESS             Buffer was grown to hold the next Allocation\r
+                                  Descriptor.\r
+  @retval EFI_OUT_OF_RESOURCES    Buffer was not grown due to lack of resources.\r
+\r
+**/\r
 EFI_STATUS\r
 GrowUpBufferToNextAd (\r
   IN      UDF_FE_RECORDING_FLAGS  RecordingFlags,\r
@@ -866,9 +962,26 @@ GrowUpBufferToNextAd (
   return EFI_SUCCESS;\r
 }\r
 \r
-//\r
-// Read data or size of either a File Entry or an Extended File Entry.\r
-//\r
+/**\r
+  Read data or size of either a File Entry or an Extended File Entry.\r
+\r
+  @param[in]      BlockIo         BlockIo interface.\r
+  @param[in]      DiskIo          DiskIo interface.\r
+  @param[in]      Volume          Volume information pointer.\r
+  @param[in]      ParentIcb       Long Allocation Descriptor pointer.\r
+  @param[in]      FileEntryData   FE/EFE structure pointer.\r
+  @param[in, out] ReadFileInfo    Read file information pointer.\r
+\r
+  @retval EFI_SUCCESS             Data or size of a FE/EFE was read.\r
+  @retval EFI_OUT_OF_RESOURCES    Data or size of a FE/EFE was not read due to\r
+                                  lack of resources.\r
+  @retval EFI_INVALID_PARAMETER   The read file flag given in ReadFileInfo is\r
+                                  invalid.\r
+  @retval EFI_UNSUPPORTED         The FE recording flag given in FileEntryData\r
+                                  is not supported.\r
+  @retval other                   Data or size of a FE/EFE was not read.\r
+\r
+**/\r
 EFI_STATUS\r
 ReadFile (\r
   IN      EFI_BLOCK_IO_PROTOCOL           *BlockIo,\r
@@ -896,7 +1009,7 @@ ReadFile (
   UINT32                  ExtentLength;\r
   UDF_FE_RECORDING_FLAGS  RecordingFlags;\r
 \r
-  LogicalBlockSize  = LV_BLOCK_SIZE (Volume, UDF_DEFAULT_LV_NUM);\r
+  LogicalBlockSize  = Volume->LogicalVolDesc.LogicalBlockSize;\r
   DoFreeAed         = FALSE;\r
 \r
   //\r
@@ -909,8 +1022,8 @@ ReadFile (
   Data = NULL;\r
 \r
   switch (ReadFileInfo->Flags) {\r
-  case READ_FILE_GET_FILESIZE:\r
-  case READ_FILE_ALLOCATE_AND_READ:\r
+  case ReadFileGetFileSize:\r
+  case ReadFileAllocateAndRead:\r
     //\r
     // Initialise ReadFileInfo structure for either getting file size, or\r
     // reading file's recorded data.\r
@@ -918,7 +1031,7 @@ ReadFile (
     ReadFileInfo->ReadLength = 0;\r
     ReadFileInfo->FileData = NULL;\r
     break;\r
-  case READ_FILE_SEEK_AND_READ:\r
+  case ReadFileSeekAndRead:\r
     //\r
     // About to seek a file and/or read its data.\r
     //\r
@@ -943,15 +1056,15 @@ ReadFile (
 \r
   RecordingFlags = GET_FE_RECORDING_FLAGS (FileEntryData);\r
   switch (RecordingFlags) {\r
-  case INLINE_DATA:\r
+  case InlineData:\r
     //\r
     // There are no extents for this FE/EFE. All data is inline.\r
     //\r
     GetFileEntryData (FileEntryData, &Data, &Length);\r
 \r
-    if (ReadFileInfo->Flags == READ_FILE_GET_FILESIZE) {\r
+    if (ReadFileInfo->Flags == ReadFileGetFileSize) {\r
       ReadFileInfo->ReadLength = Length;\r
-    } else if (ReadFileInfo->Flags == READ_FILE_ALLOCATE_AND_READ) {\r
+    } else if (ReadFileInfo->Flags == ReadFileAllocateAndRead) {\r
       //\r
       // Allocate buffer for starting read data.\r
       //\r
@@ -965,7 +1078,7 @@ ReadFile (
       //\r
       CopyMem (ReadFileInfo->FileData, Data, (UINTN) Length);\r
       ReadFileInfo->ReadLength = Length;\r
-    } else if (ReadFileInfo->Flags == READ_FILE_SEEK_AND_READ) {\r
+    } else if (ReadFileInfo->Flags == ReadFileSeekAndRead) {\r
       //\r
       // If FilePosition is non-zero, seek file to FilePosition, read\r
       // FileDataSize bytes and then updates FilePosition.\r
@@ -985,8 +1098,8 @@ ReadFile (
     Status = EFI_SUCCESS;\r
     break;\r
 \r
-  case LONG_ADS_SEQUENCE:\r
-  case SHORT_ADS_SEQUENCE:\r
+  case LongAdsSequence:\r
+  case ShortAdsSequence:\r
     //\r
     // This FE/EFE contains a run of Allocation Descriptors. Get data + size\r
     // for start reading them out.\r
@@ -1014,7 +1127,7 @@ ReadFile (
       // Check if AD is an indirect AD. If so, read Allocation Extent\r
       // Descriptor and its extents (ADs).\r
       //\r
-      if (GET_EXTENT_FLAGS (RecordingFlags, Ad) == EXTENT_IS_NEXT_EXTENT) {\r
+      if (GET_EXTENT_FLAGS (RecordingFlags, Ad) == ExtentIsNextExtent) {\r
         if (!DoFreeAed) {\r
           DoFreeAed = TRUE;\r
         } else {\r
@@ -1048,10 +1161,10 @@ ReadFile (
                                         Ad);\r
 \r
       switch (ReadFileInfo->Flags) {\r
-      case READ_FILE_GET_FILESIZE:\r
+      case ReadFileGetFileSize:\r
         ReadFileInfo->ReadLength += ExtentLength;\r
         break;\r
-      case READ_FILE_ALLOCATE_AND_READ:\r
+      case ReadFileAllocateAndRead:\r
         //\r
         // Increase FileData (if necessary) to read next extent.\r
         //\r
@@ -1082,7 +1195,7 @@ ReadFile (
 \r
         ReadFileInfo->ReadLength += ExtentLength;\r
         break;\r
-      case READ_FILE_SEEK_AND_READ:\r
+      case ReadFileSeekAndRead:\r
         //\r
         // Seek file first before reading in its data.\r
         //\r
@@ -1158,7 +1271,7 @@ ReadFile (
     }\r
 \r
     break;\r
-  case EXTENDED_ADS_SEQUENCE:\r
+  case ExtendedAdsSequence:\r
      // FIXME: Not supported. Got no volume with it, yet.\r
     ASSERT (FALSE);\r
     Status = EFI_UNSUPPORTED;\r
@@ -1182,7 +1295,7 @@ Done:
 \r
 Error_Read_Disk_Blk:\r
 Error_Alloc_Buffer_To_Next_Ad:\r
-  if (ReadFileInfo->Flags != READ_FILE_SEEK_AND_READ) {\r
+  if (ReadFileInfo->Flags != ReadFileSeekAndRead) {\r
     FreePool (ReadFileInfo->FileData);\r
   }\r
 \r
@@ -1194,9 +1307,22 @@ Error_Get_Aed:
   return Status;\r
 }\r
 \r
-//\r
-// Find a file by its filename from a given Parent file.\r
-//\r
+/**\r
+  Find a file by its filename from a given Parent file.\r
+\r
+  @param[in]  BlockIo             BlockIo interface.\r
+  @param[in]  DiskIo              DiskIo interface.\r
+  @param[in]  Volume              Volume information pointer.\r
+  @param[in]  FileName            File name string.\r
+  @param[in]  Parent              Parent directory file.\r
+  @param[in]  Icb                 Long Allocation Descriptor pointer.\r
+  @param[out] File                Found file.\r
+\r
+  @retval EFI_SUCCESS             The file was found.\r
+  @retval EFI_INVALID_PARAMETER   One or more input parameters are invalid.\r
+  @retval EFI_NOT_FOUND           The file was not found.\r
+\r
+**/\r
 EFI_STATUS\r
 InternalFindFile (\r
   IN   EFI_BLOCK_IO_PROTOCOL           *BlockIo,\r
@@ -1225,7 +1351,7 @@ InternalFindFile (
   //\r
   // Check if parent file is really directory.\r
   //\r
-  if (!IS_FE_DIRECTORY (Parent->FileEntry)) {\r
+  if (FE_ICB_FILE_TYPE (Parent->FileEntry) != UdfFileEntryDirectory) {\r
     return EFI_NOT_FOUND;\r
   }\r
 \r
@@ -1270,7 +1396,7 @@ InternalFindFile (
       break;\r
     }\r
 \r
-    if (IS_FID_PARENT_FILE (FileIdentifierDesc)) {\r
+    if (FileIdentifierDesc->FileCharacteristics & PARENT_FILE) {\r
       //\r
       // This FID contains the location (FE/EFE) of the parent directory of this\r
       // directory (Parent), and if FileName is either ".." or "\\", then it's\r
@@ -1373,6 +1499,9 @@ ReadUdfVolumeInformation (
 {\r
   EFI_STATUS Status;\r
 \r
+  //\r
+  // Read all necessary UDF volume information and keep it private to the driver\r
+  //\r
   Status = ReadVolumeFileStructure (\r
     BlockIo,\r
     DiskIo,\r
@@ -1382,13 +1511,12 @@ ReadUdfVolumeInformation (
     return Status;\r
   }\r
 \r
-  Status = GetFileSetDescriptors (\r
-    BlockIo,\r
-    DiskIo,\r
-    Volume\r
-    );\r
+  //\r
+  // Find File Set Descriptor\r
+  //\r
+  Status = FindFileSetDescriptor (BlockIo, DiskIo, Volume);\r
   if (EFI_ERROR (Status)) {\r
-    CleanupVolumeInformation (Volume);\r
+    return Status;\r
   }\r
 \r
   return Status;\r
@@ -1425,7 +1553,7 @@ FindRootDirectory (
     BlockIo,\r
     DiskIo,\r
     Volume,\r
-    &Volume->FileSetDescs[0]->RootDirectoryIcb,\r
+    &Volume->FileSetDesc.RootDirectoryIcb,\r
     &File->FileEntry\r
     );\r
   if (EFI_ERROR (Status)) {\r
@@ -1442,7 +1570,7 @@ FindRootDirectory (
     L"\\",\r
     NULL,\r
     &Parent,\r
-    &Volume->FileSetDescs[0]->RootDirectoryIcb,\r
+    &Volume->FileSetDesc.RootDirectoryIcb,\r
     File\r
     );\r
   if (EFI_ERROR (Status)) {\r
@@ -1478,12 +1606,13 @@ FindFileEntry (
   OUT  VOID                            **FileEntry\r
   )\r
 {\r
-  EFI_STATUS  Status;\r
-  UINT64      Lsn;\r
-  UINT32      LogicalBlockSize;\r
+  EFI_STATUS          Status;\r
+  UINT64              Lsn;\r
+  UINT32              LogicalBlockSize;\r
+  UDF_DESCRIPTOR_TAG  *DescriptorTag;\r
 \r
   Lsn               = GetLongAdLsn (Volume, Icb);\r
-  LogicalBlockSize  = LV_BLOCK_SIZE (Volume, UDF_DEFAULT_LV_NUM);\r
+  LogicalBlockSize  = Volume->LogicalVolDesc.LogicalBlockSize;\r
 \r
   *FileEntry = AllocateZeroPool (Volume->FileEntrySize);\r
   if (*FileEntry == NULL) {\r
@@ -1504,11 +1633,14 @@ FindFileEntry (
     goto Error_Read_Disk_Blk;\r
   }\r
 \r
+  DescriptorTag = *FileEntry;\r
+\r
   //\r
   // Check if the read extent contains a valid Tag Identifier for the expected\r
   // FE/EFE.\r
   //\r
-  if (!IS_FE (*FileEntry) && !IS_EFE (*FileEntry)) {\r
+  if (DescriptorTag->TagIdentifier != UdfFileEntry &&\r
+      DescriptorTag->TagIdentifier != UdfExtendedFileEntry) {\r
     Status = EFI_VOLUME_CORRUPTED;\r
     goto Error_Invalid_Fe;\r
   }\r
@@ -1531,13 +1663,14 @@ Error_Read_Disk_Blk:
   @param[in]   FilePath  File's absolute path.\r
   @param[in]   Root      Root directory file.\r
   @param[in]   Parent    Parent directory file.\r
+  @param[in]   Icb       ICB of Parent.\r
   @param[out]  File      Found file.\r
 \r
-  @retval EFI_SUCCESS          @p FilePath was found.\r
+  @retval EFI_SUCCESS          FilePath was found.\r
   @retval EFI_NO_MEDIA         The device has no media.\r
   @retval EFI_DEVICE_ERROR     The device reported an error.\r
   @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.\r
-  @retval EFI_OUT_OF_RESOURCES The @p FilePath file was not found due to lack of\r
+  @retval EFI_OUT_OF_RESOURCES The FilePath file was not found due to lack of\r
                                resources.\r
 \r
 **/\r
@@ -1617,7 +1750,7 @@ FindFile (
     // If the found file is a symlink, then find its respective FE/EFE and\r
     // FID descriptors.\r
     //\r
-    if (IS_FE_SYMLINK (File->FileEntry)) {\r
+    if (FE_ICB_FILE_TYPE (File->FileEntry) == UdfFileEntrySymlink) {\r
       FreePool ((VOID *)File->FileIdentifierDesc);\r
 \r
       FileEntry = File->FileEntry;\r
@@ -1658,7 +1791,7 @@ FindFile (
   @param[in]      Volume         UDF volume information structure.\r
   @param[in]      ParentIcb      ICB of the parent file.\r
   @param[in]      FileEntryData  FE/EFE of the parent file.\r
-  @param[in out]  ReadDirInfo    Next read directory listing structure\r
+  @param[in, out] ReadDirInfo    Next read directory listing structure\r
                                  information.\r
   @param[out]     FoundFid       File Identifier Descriptor pointer.\r
 \r
@@ -1691,7 +1824,7 @@ ReadDirectoryEntry (
     // The directory's recorded data has not been read yet. So let's cache it\r
     // into memory and the next calls won't need to read it again.\r
     //\r
-    ReadFileInfo.Flags = READ_FILE_ALLOCATE_AND_READ;\r
+    ReadFileInfo.Flags = ReadFileAllocateAndRead;\r
 \r
     Status = ReadFile (\r
       BlockIo,\r
@@ -1731,7 +1864,7 @@ ReadDirectoryEntry (
     // Update FidOffset to point to next FID.\r
     //\r
     ReadDirInfo->FidOffset += GetFidDescriptorLength (FileIdentifierDesc);\r
-  } while (IS_FID_DELETED_FILE (FileIdentifierDesc));\r
+  } while (FileIdentifierDesc->FileCharacteristics & DELETED_FILE);\r
 \r
   DuplicateFid (FileIdentifierDesc, FoundFid);\r
 \r
@@ -1830,7 +1963,7 @@ ResolveSymlink (
   UDF_PATH_COMPONENT  *PathComp;\r
   UINT8               PathCompLength;\r
   CHAR16              FileName[UDF_FILENAME_LENGTH];\r
-  CHAR16              *C;\r
+  CHAR16              *Char;\r
   UINTN               Index;\r
   UINT8               CompressionId;\r
   UDF_FILE_INFO       PreviousFile;\r
@@ -1841,7 +1974,7 @@ ResolveSymlink (
   // all its data here -- usually the data will be inline with the FE/EFE for\r
   // lower filenames.\r
   //\r
-  ReadFileInfo.Flags = READ_FILE_ALLOCATE_AND_READ;\r
+  ReadFileInfo.Flags = ReadFileAllocateAndRead;\r
 \r
   Status = ReadFile (\r
     BlockIo,\r
@@ -1907,24 +2040,24 @@ ResolveSymlink (
         return EFI_VOLUME_CORRUPTED;\r
       }\r
 \r
-      C = FileName;\r
+      Char = FileName;\r
       for (Index = 1; Index < PathCompLength; Index++) {\r
         if (CompressionId == 16) {\r
-          *C = *(UINT8 *)((UINT8 *)PathComp->ComponentIdentifier +\r
+          *Char = *(UINT8 *)((UINT8 *)PathComp->ComponentIdentifier +\r
                           Index) << 8;\r
           Index++;\r
         } else {\r
-          *C = 0;\r
+          *Char = 0;\r
         }\r
 \r
         if (Index < Length) {\r
-          *C |= (CHAR16)(*(UINT8 *)((UINT8 *)PathComp->ComponentIdentifier + Index));\r
+          *Char |= (CHAR16)(*(UINT8 *)((UINT8 *)PathComp->ComponentIdentifier + Index));\r
         }\r
 \r
-        C++;\r
+        Char++;\r
       }\r
 \r
-      *C = L'\0';\r
+      *Char = L'\0';\r
       break;\r
     }\r
 \r
@@ -1976,43 +2109,6 @@ Error_Find_File:
   return Status;\r
 }\r
 \r
-/**\r
-  Clean up in-memory UDF volume information.\r
-\r
-  @param[in] Volume Volume information pointer.\r
-\r
-**/\r
-VOID\r
-CleanupVolumeInformation (\r
-  IN UDF_VOLUME_INFO *Volume\r
-  )\r
-{\r
-  UINTN Index;\r
-\r
-  if (Volume->LogicalVolDescs != NULL) {\r
-    for (Index = 0; Index < Volume->LogicalVolDescsNo; Index++) {\r
-      FreePool ((VOID *)Volume->LogicalVolDescs[Index]);\r
-    }\r
-    FreePool ((VOID *)Volume->LogicalVolDescs);\r
-  }\r
-\r
-  if (Volume->PartitionDescs != NULL) {\r
-    for (Index = 0; Index < Volume->PartitionDescsNo; Index++) {\r
-      FreePool ((VOID *)Volume->PartitionDescs[Index]);\r
-    }\r
-    FreePool ((VOID *)Volume->PartitionDescs);\r
-  }\r
-\r
-  if (Volume->FileSetDescs != NULL) {\r
-    for (Index = 0; Index < Volume->FileSetDescsNo; Index++) {\r
-      FreePool ((VOID *)Volume->FileSetDescs[Index]);\r
-    }\r
-    FreePool ((VOID *)Volume->FileSetDescs);\r
-  }\r
-\r
-  ZeroMem ((VOID *)Volume, sizeof (UDF_VOLUME_INFO));\r
-}\r
-\r
 /**\r
   Clean up in-memory UDF file information.\r
 \r
@@ -2043,7 +2139,7 @@ CleanupFileInformation (
   @param[in]   File     File information structure.\r
   @param[out]  Size     Size of the file.\r
 \r
-  @retval EFI_SUCCESS          File size calculated and set in @p Size.\r
+  @retval EFI_SUCCESS          File size calculated and set in Size.\r
   @retval EFI_UNSUPPORTED      Extended Allocation Descriptors not supported.\r
   @retval EFI_NO_MEDIA         The device has no media.\r
   @retval EFI_DEVICE_ERROR     The device reported an error.\r
@@ -2064,7 +2160,7 @@ GetFileSize (
   EFI_STATUS          Status;\r
   UDF_READ_FILE_INFO  ReadFileInfo;\r
 \r
-  ReadFileInfo.Flags = READ_FILE_GET_FILESIZE;\r
+  ReadFileInfo.Flags = ReadFileGetFileSize;\r
 \r
   Status = ReadFile (\r
     BlockIo,\r
@@ -2089,7 +2185,7 @@ GetFileSize (
   @param[in]      File        File pointer.\r
   @param[in]      FileSize    Size of the file.\r
   @param[in]      FileName    Filename of the file.\r
-  @param[in out]  BufferSize  Size of the returned file infomation.\r
+  @param[in, out] BufferSize  Size of the returned file infomation.\r
   @param[out]     Buffer      Data of the returned file information.\r
 \r
   @retval EFI_SUCCESS          File information set.\r
@@ -2113,6 +2209,7 @@ SetFileInfo (
   EFI_FILE_INFO            *FileInfo;\r
   UDF_FILE_ENTRY           *FileEntry;\r
   UDF_EXTENDED_FILE_ENTRY  *ExtendedFileEntry;\r
+  UDF_DESCRIPTOR_TAG       *DescriptorTag;\r
 \r
   //\r
   // Calculate the needed size for the EFI_FILE_INFO structure.\r
@@ -2147,7 +2244,9 @@ SetFileInfo (
     FileInfo->Attribute |= EFI_FILE_HIDDEN;\r
   }\r
 \r
-  if (IS_FE (File->FileEntry)) {\r
+  DescriptorTag = File->FileEntry;\r
+\r
+  if (DescriptorTag->TagIdentifier == UdfFileEntry) {\r
     FileEntry = (UDF_FILE_ENTRY *)File->FileEntry;\r
 \r
     //\r
@@ -2183,7 +2282,7 @@ SetFileInfo (
                                    FileEntry->AccessTime.Second;\r
     FileInfo->LastAccessTime.Nanosecond  =\r
                                    FileEntry->AccessTime.HundredsOfMicroseconds;\r
-  } else if (IS_EFE (File->FileEntry)) {\r
+  } else if (DescriptorTag->TagIdentifier == UdfExtendedFileEntry) {\r
     ExtendedFileEntry = (UDF_EXTENDED_FILE_ENTRY *)File->FileEntry;\r
 \r
     //\r
@@ -2267,91 +2366,103 @@ GetVolumeSize (
   OUT  UINT64                 *FreeSpaceSize\r
   )\r
 {\r
-  UDF_EXTENT_AD                 ExtentAd;\r
-  UINT32                        LogicalBlockSize;\r
-  UINT64                        Lsn;\r
-  EFI_STATUS                    Status;\r
-  UDF_LOGICAL_VOLUME_INTEGRITY  *LogicalVolInt;\r
-  UINTN                         Index;\r
-  UINTN                         Length;\r
-  UINT32                        LsnsNo;\r
-\r
-  *VolumeSize     = 0;\r
-  *FreeSpaceSize  = 0;\r
-\r
-  for (Index = 0; Index < Volume->LogicalVolDescsNo; Index++) {\r
-    CopyMem ((VOID *)&ExtentAd,\r
-             (VOID *)&Volume->LogicalVolDescs[Index]->IntegritySequenceExtent,\r
-             sizeof (UDF_EXTENT_AD));\r
-    if (ExtentAd.ExtentLength == 0) {\r
-      continue;\r
-    }\r
+  EFI_STATUS                     Status;\r
+  UDF_LOGICAL_VOLUME_DESCRIPTOR  *LogicalVolDesc;\r
+  UDF_EXTENT_AD                  *ExtentAd;\r
+  UINT64                         Lsn;\r
+  UINT32                         LogicalBlockSize;\r
+  UDF_LOGICAL_VOLUME_INTEGRITY   *LogicalVolInt;\r
+  UDF_DESCRIPTOR_TAG             *DescriptorTag;\r
+  UINTN                          Index;\r
+  UINTN                          Length;\r
+  UINT32                         LsnsNo;\r
 \r
-    LogicalBlockSize = LV_BLOCK_SIZE (Volume, Index);\r
+  LogicalVolDesc = &Volume->LogicalVolDesc;\r
 \r
-  Read_Next_Sequence:\r
-    LogicalVolInt = (UDF_LOGICAL_VOLUME_INTEGRITY *)\r
-      AllocatePool (ExtentAd.ExtentLength);\r
-    if (LogicalVolInt == NULL) {\r
-      return EFI_OUT_OF_RESOURCES;\r
-    }\r
+  ExtentAd = &LogicalVolDesc->IntegritySequenceExtent;\r
 \r
-    Lsn = (UINT64)ExtentAd.ExtentLocation;\r
+  if (ExtentAd->ExtentLength == 0) {\r
+    return EFI_VOLUME_CORRUPTED;\r
+  }\r
 \r
-    Status = DiskIo->ReadDisk (\r
-      DiskIo,\r
-      BlockIo->Media->MediaId,\r
-      MultU64x32 (Lsn, LogicalBlockSize),\r
-      ExtentAd.ExtentLength,\r
-      (VOID *)LogicalVolInt\r
-      );\r
-    if (EFI_ERROR (Status)) {\r
-      FreePool ((VOID *)LogicalVolInt);\r
-      return Status;\r
-    }\r
+  LogicalVolInt = AllocatePool (ExtentAd->ExtentLength);\r
+  if (LogicalVolInt == NULL) {\r
+    return EFI_OUT_OF_RESOURCES;\r
+  }\r
 \r
-    if (!IS_LVID (LogicalVolInt)) {\r
-      FreePool ((VOID *)LogicalVolInt);\r
-      return EFI_VOLUME_CORRUPTED;\r
-    }\r
+  //\r
+  // Get location of Logical Volume Integrity Descriptor\r
+  //\r
+  Lsn = (UINT64)ExtentAd->ExtentLocation - Volume->MainVdsStartLocation;\r
 \r
-    Length = LogicalVolInt->NumberOfPartitions;\r
-    for (Index = 0; Index < Length; Index += sizeof (UINT32)) {\r
-      LsnsNo = *(UINT32 *)((UINT8 *)LogicalVolInt->Data + Index);\r
-      if (LsnsNo == 0xFFFFFFFFUL) {\r
-        //\r
-        // Size not specified.\r
-        //\r
-        continue;\r
-      }\r
+  LogicalBlockSize = LogicalVolDesc->LogicalBlockSize;\r
 \r
-      *FreeSpaceSize += MultU64x32 ((UINT64)LsnsNo, LogicalBlockSize);\r
-    }\r
+  //\r
+  // Read disk block\r
+  //\r
+  Status = DiskIo->ReadDisk (\r
+    DiskIo,\r
+    BlockIo->Media->MediaId,\r
+    MultU64x32 (Lsn, LogicalBlockSize),\r
+    ExtentAd->ExtentLength,\r
+    LogicalVolInt\r
+    );\r
+  if (EFI_ERROR (Status)) {\r
+    goto Out_Free;\r
+  }\r
 \r
-    Length = (LogicalVolInt->NumberOfPartitions * sizeof (UINT32)) << 1;\r
-    for (; Index < Length; Index += sizeof (UINT32)) {\r
-      LsnsNo = *(UINT32 *)((UINT8 *)LogicalVolInt->Data + Index);\r
-      if (LsnsNo == 0xFFFFFFFFUL) {\r
-        //\r
-        // Size not specified.\r
-        //\r
-        continue;\r
-      }\r
+  DescriptorTag = &LogicalVolInt->DescriptorTag;\r
 \r
-      *VolumeSize += MultU64x32 ((UINT64)LsnsNo, LogicalBlockSize);\r
-    }\r
+  //\r
+  // Check if read block is a Logical Volume Integrity Descriptor\r
+  //\r
+  if (DescriptorTag->TagIdentifier != UdfLogicalVolumeIntegrityDescriptor) {\r
+    Status = EFI_VOLUME_CORRUPTED;\r
+    goto Out_Free;\r
+  }\r
+\r
+  *VolumeSize = 0;\r
+  *FreeSpaceSize = 0;\r
 \r
-    CopyMem ((VOID *)&ExtentAd,(VOID *)&LogicalVolInt->NextIntegrityExtent,\r
-             sizeof (UDF_EXTENT_AD));\r
-    if (ExtentAd.ExtentLength > 0) {\r
-      FreePool ((VOID *)LogicalVolInt);\r
-      goto Read_Next_Sequence;\r
+  Length = LogicalVolInt->NumberOfPartitions;\r
+  for (Index = 0; Index < Length; Index += sizeof (UINT32)) {\r
+    LsnsNo = *(UINT32 *)((UINT8 *)LogicalVolInt->Data + Index);\r
+    //\r
+    // Check if size is not specified\r
+    //\r
+    if (LsnsNo == 0xFFFFFFFFUL) {\r
+      continue;\r
     }\r
+    //\r
+    // Accumulate free space size\r
+    //\r
+    *FreeSpaceSize += MultU64x32 ((UINT64)LsnsNo, LogicalBlockSize);\r
+  }\r
 \r
-    FreePool ((VOID *)LogicalVolInt);\r
+  Length = LogicalVolInt->NumberOfPartitions * sizeof (UINT32) * 2;\r
+  for (; Index < Length; Index += sizeof (UINT32)) {\r
+    LsnsNo = *(UINT32 *)((UINT8 *)LogicalVolInt->Data + Index);\r
+    //\r
+    // Check if size is not specified\r
+    //\r
+    if (LsnsNo == 0xFFFFFFFFUL) {\r
+      continue;\r
+    }\r
+    //\r
+    // Accumulate used volume space\r
+    //\r
+    *VolumeSize += MultU64x32 ((UINT64)LsnsNo, LogicalBlockSize);\r
   }\r
 \r
-  return EFI_SUCCESS;\r
+  Status = EFI_SUCCESS;\r
+\r
+Out_Free:\r
+  //\r
+  // Free Logical Volume Integrity Descriptor\r
+  //\r
+  FreePool (LogicalVolInt);\r
+\r
+  return Status;\r
 }\r
 \r
 /**\r
@@ -2362,9 +2473,9 @@ GetVolumeSize (
   @param[in]      Volume        UDF volume information structure.\r
   @param[in]      File          File information structure.\r
   @param[in]      FileSize      Size of the file.\r
-  @param[in out]  FilePosition  File position.\r
-  @param[in out]  Buffer        File data.\r
-  @param[in out]  BufferSize    Read size.\r
+  @param[in, out] FilePosition  File position.\r
+  @param[in, out] Buffer        File data.\r
+  @param[in, out] BufferSize    Read size.\r
 \r
   @retval EFI_SUCCESS          File seeked and read.\r
   @retval EFI_UNSUPPORTED      Extended Allocation Descriptors not supported.\r
@@ -2390,7 +2501,7 @@ ReadFileData (
   EFI_STATUS          Status;\r
   UDF_READ_FILE_INFO  ReadFileInfo;\r
 \r
-  ReadFileInfo.Flags         = READ_FILE_SEEK_AND_READ;\r
+  ReadFileInfo.Flags         = ReadFileSeekAndRead;\r
   ReadFileInfo.FilePosition  = *FilePosition;\r
   ReadFileInfo.FileData      = Buffer;\r
   ReadFileInfo.FileDataSize  = *BufferSize;\r
@@ -2435,7 +2546,6 @@ SupportUdfFileSystem (
   EFI_DEVICE_PATH_PROTOCOL  *DevicePathNode;\r
   EFI_DEVICE_PATH_PROTOCOL  *LastDevicePathNode;\r
   EFI_GUID                  *VendorDefinedGuid;\r
-  EFI_GUID                  UdfDevPathGuid = EFI_UDF_DEVICE_PATH_GUID;\r
 \r
   //\r
   // Open Device Path protocol on ControllerHandle\r
@@ -2472,7 +2582,7 @@ SupportUdfFileSystem (
       DevicePathSubType (LastDevicePathNode) == MEDIA_VENDOR_DP) {\r
     VendorDefinedGuid = (EFI_GUID *)((UINTN)LastDevicePathNode +\r
                                      OFFSET_OF (VENDOR_DEVICE_PATH, Guid));\r
-    if (CompareGuid (VendorDefinedGuid, &UdfDevPathGuid)) {\r
+    if (CompareGuid (VendorDefinedGuid, &gUdfDevPathGuid)) {\r
       Status = EFI_SUCCESS;\r
     }\r
   }\r