]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/Disk/UdfDxe/FileSystemOperations.c
MdeModulePkg/UdfDxe: Refine enum member naming style
[mirror_edk2.git] / MdeModulePkg / Universal / Disk / UdfDxe / FileSystemOperations.c
index 904262a2ba5cec52d2c840779e986fe228686de1..5df267761ff6e2c0c115a17342136b38f4834b60 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
@@ -58,6 +75,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
@@ -211,11 +244,17 @@ Error_Alloc_Pds:
   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
@@ -270,9 +309,15 @@ GetPdFromLongAd (
   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
@@ -288,25 +333,44 @@ GetLongAdLsn (
                  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]  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_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
 }\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
+  @param[in]  LogicalVolDescNum   Index of Logical Volume Descriptor\r
+  @param[out] FileSetDesc         File Set Descriptor 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
@@ -347,9 +411,20 @@ FindFileSetDescriptor (
   return EFI_SUCCESS;\r
 }\r
 \r
-//\r
-// Get all File Set Descriptors for each Logical Volume Descriptor.\r
-//\r
+/**\r
+  Get all File Set Descriptors for each Logical Volume Descriptor.\r
+\r
+  @param[in]      BlockIo         BlockIo interface.\r
+  @param[in]      DiskIo          DiskIo interface.\r
+  @param[in, out] Volume          Volume information pointer.\r
+\r
+  @retval EFI_SUCCESS             File Set Descriptors were got.\r
+  @retval EFI_OUT_OF_RESOURCES    File Set Descriptors were not got due to lack\r
+                                  of resources.\r
+  @retval other                   Error occured when finding File Set\r
+                                  Descriptor in Logical Volume Descriptor.\r
+\r
+**/\r
 EFI_STATUS\r
 GetFileSetDescriptors (\r
   IN      EFI_BLOCK_IO_PROTOCOL  *BlockIo,\r
@@ -412,9 +487,17 @@ Error_Alloc_Fsd:
   return Status;\r
 }\r
 \r
-//\r
-// Read Volume and File Structure on an UDF file system.\r
-//\r
+/**\r
+  Read Volume and File Structure on an UDF file system.\r
+\r
+  @param[in]   BlockIo            BlockIo interface.\r
+  @param[in]   DiskIo             DiskIo interface.\r
+  @param[out]  Volume             Volume information pointer.\r
+\r
+  @retval EFI_SUCCESS             Volume and File Structure were read.\r
+  @retval other                   Volume and File Structure were not read.\r
+\r
+**/\r
 EFI_STATUS\r
 ReadVolumeFileStructure (\r
   IN   EFI_BLOCK_IO_PROTOCOL  *BlockIo,\r
@@ -453,9 +536,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
@@ -468,9 +556,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
@@ -480,11 +572,19 @@ DuplicateFid (
   *NewFileIdentifierDesc =\r
     (UDF_FILE_IDENTIFIER_DESCRIPTOR *)AllocateCopyPool (\r
       (UINTN) GetFidDescriptorLength (FileIdentifierDesc), FileIdentifierDesc);\r
+\r
+  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
@@ -494,17 +594,25 @@ DuplicateFe (
   )\r
 {\r
   *NewFileEntry = AllocateCopyPool (Volume->FileEntrySize, FileEntry);\r
+\r
+  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
@@ -530,9 +638,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
@@ -558,9 +672,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
@@ -587,9 +710,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
@@ -597,7 +720,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
@@ -605,9 +728,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
@@ -634,9 +766,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
@@ -644,7 +776,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
@@ -652,10 +784,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
@@ -665,14 +808,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
@@ -684,9 +827,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
@@ -695,9 +846,9 @@ 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
       GetPdFromLongAd (Volume, ParentIcb),\r
       (UDF_SHORT_ALLOCATION_DESCRIPTOR *)Ad\r
@@ -707,9 +858,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
@@ -778,9 +947,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
@@ -830,9 +1015,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
@@ -860,9 +1055,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
@@ -893,9 +1105,18 @@ ReadFile (
   LogicalBlockSize  = LV_BLOCK_SIZE (Volume, UDF_DEFAULT_LV_NUM);\r
   DoFreeAed         = FALSE;\r
 \r
+  //\r
+  // set BytesLeft to suppress incorrect compiler/analyzer warnings\r
+  //\r
+  BytesLeft = 0;\r
+  DataOffset = 0;\r
+  FilePosition = 0;\r
+  FinishedSeeking = FALSE;\r
+  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
@@ -903,7 +1124,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
@@ -928,15 +1149,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
@@ -950,7 +1171,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
@@ -962,11 +1183,16 @@ ReadFile (
         );\r
 \r
       ReadFileInfo->FilePosition += ReadFileInfo->FileDataSize;\r
+    } else {\r
+      ASSERT (FALSE);\r
+      return EFI_INVALID_PARAMETER;\r
     }\r
 \r
+    Status = EFI_SUCCESS;\r
     break;\r
-  case LONG_ADS_SEQUENCE:\r
-  case SHORT_ADS_SEQUENCE:\r
+\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
@@ -994,7 +1220,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
@@ -1014,6 +1240,7 @@ ReadFile (
         if (EFI_ERROR (Status)) {\r
           goto Error_Get_Aed;\r
         }\r
+        ASSERT (Data != NULL);\r
 \r
         AdOffset = 0;\r
         continue;\r
@@ -1027,10 +1254,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
@@ -1061,7 +1288,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
@@ -1077,9 +1304,6 @@ ReadFile (
 \r
         if (FilePosition + ExtentLength > ReadFileInfo->FilePosition) {\r
           Offset = ReadFileInfo->FilePosition - FilePosition;\r
-          if (Offset < 0) {\r
-            Offset = -(Offset);\r
-          }\r
         } else {\r
           Offset = 0;\r
         }\r
@@ -1140,11 +1364,19 @@ 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
     break;\r
+\r
+  default:\r
+    //\r
+    // A flag value reserved by the ECMA-167 standard (3rd Edition - June\r
+    // 1997); 14.6 ICB Tag; 14.6.8 Flags (RBP 18); was found.\r
+    //\r
+    Status = EFI_UNSUPPORTED;\r
+    break;\r
   }\r
 \r
 Done:\r
@@ -1156,7 +1388,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
@@ -1168,9 +1400,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
@@ -1189,6 +1434,13 @@ InternalFindFile (
   CHAR16                          FoundFileName[UDF_FILENAME_LENGTH];\r
   VOID                            *CompareFileEntry;\r
 \r
+  //\r
+  // Check if both Parent->FileIdentifierDesc and Icb are NULL.\r
+  //\r
+  if ((Parent->FileIdentifierDesc == NULL) && (Icb == NULL)) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
   //\r
   // Check if parent file is really directory.\r
   //\r
@@ -1201,6 +1453,10 @@ InternalFindFile (
   // FE/EFE and FID descriptors.\r
   //\r
   if (StrCmp (FileName, L".") == 0) {\r
+    if (Parent->FileIdentifierDesc == NULL) {\r
+      return EFI_INVALID_PARAMETER;\r
+    }\r
+\r
     DuplicateFe (BlockIo, Volume, Parent->FileEntry, &File->FileEntry);\r
     DuplicateFid (Parent->FileIdentifierDesc, &File->FileIdentifierDesc);\r
 \r
@@ -1218,7 +1474,7 @@ InternalFindFile (
       BlockIo,\r
       DiskIo,\r
       Volume,\r
-      Parent->FileIdentifierDesc ?\r
+      (Parent->FileIdentifierDesc != NULL) ?\r
       &Parent->FileIdentifierDesc->Icb :\r
       Icb,\r
       Parent->FileEntry,\r
@@ -1494,13 +1750,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
@@ -1621,7 +1878,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
@@ -1654,7 +1911,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
@@ -1745,7 +2002,7 @@ GetFileNameFromFid (
     }\r
 \r
     if (Index < Length) {\r
-      *FileName |= OstaCompressed[Index];\r
+      *FileName |= (CHAR16)(OstaCompressed[Index]);\r
     }\r
 \r
     FileName++;\r
@@ -1793,7 +2050,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
@@ -1804,7 +2061,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
@@ -1870,24 +2127,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 |= *(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
@@ -2006,7 +2263,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
@@ -2027,7 +2284,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
@@ -2052,7 +2309,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
@@ -2080,7 +2337,7 @@ SetFileInfo (
   //\r
   // Calculate the needed size for the EFI_FILE_INFO structure.\r
   //\r
-  FileInfoLength = sizeof (EFI_FILE_INFO) + (FileName ?\r
+  FileInfoLength = sizeof (EFI_FILE_INFO) + ((FileName != NULL) ?\r
                                              StrSize (FileName) :\r
                                              sizeof (CHAR16));\r
   if (*BufferSize < FileInfoLength) {\r
@@ -2325,9 +2582,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
@@ -2353,7 +2610,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
@@ -2398,7 +2655,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
@@ -2435,7 +2691,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