]> git.proxmox.com Git - mirror_edk2.git/blobdiff - FatPkg/FatPei/FatLiteAccess.c
FatPkg: Clean up source files
[mirror_edk2.git] / FatPkg / FatPei / FatLiteAccess.c
index 0a688a3185e6971779cd9b5dfd2269ea84978f90..12a3be33c5a6be1520c4bafb8d8e5763c3157810 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   FAT file system access routines for FAT recovery PEIM\r
 \r
-Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>\r
 \r
 This program and the accompanying materials are licensed and made available\r
 under the terms and conditions of the BSD License which accompanies this\r
@@ -22,16 +22,16 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
   volume structure. Note there should be a valid Block device number\r
   already set.\r
 \r
-  @param  PrivateData            Global memory map for accessing global \r
-                                 variables. \r
-  @param  Volume                 On input, the BlockDeviceNumber field of the \r
-                                 Volume  should be a valid value. On successful \r
-                                 output, all  fields except the VolumeNumber \r
-                                 field is initialized. \r
+  @param  PrivateData            Global memory map for accessing global\r
+                                 variables.\r
+  @param  Volume                 On input, the BlockDeviceNumber field of the\r
+                                 Volume  should be a valid value. On successful\r
+                                 output, all  fields except the VolumeNumber\r
+                                 field is initialized.\r
 \r
-  @retval EFI_SUCCESS            A FAT is found and the volume structure is \r
-                                 initialized. \r
-  @retval EFI_NOT_FOUND          There is no FAT on the corresponding device. \r
+  @retval EFI_SUCCESS            A FAT is found and the volume structure is\r
+                                 initialized.\r
+  @retval EFI_NOT_FOUND          There is no FAT on the corresponding device.\r
   @retval EFI_DEVICE_ERROR       There is something error while accessing device.\r
 \r
 **/\r
@@ -177,13 +177,13 @@ FatGetBpbInfo (
 /**\r
   Gets the next cluster in the cluster chain\r
 \r
-  @param  PrivateData            Global memory map for accessing global variables \r
-  @param  Volume                 The volume \r
-  @param  Cluster                The cluster \r
-  @param  NextCluster            The cluster number of the next cluster \r
+  @param  PrivateData            Global memory map for accessing global variables\r
+  @param  Volume                 The volume\r
+  @param  Cluster                The cluster\r
+  @param  NextCluster            The cluster number of the next cluster\r
 \r
-  @retval EFI_SUCCESS            The address is got \r
-  @retval EFI_INVALID_PARAMETER  ClusterNo exceeds the MaxCluster of the volume. \r
+  @retval EFI_SUCCESS            The address is got\r
+  @retval EFI_INVALID_PARAMETER  ClusterNo exceeds the MaxCluster of the volume.\r
   @retval EFI_DEVICE_ERROR       Read disk error\r
 \r
 **/\r
@@ -256,13 +256,13 @@ FatGetNextCluster (
 /**\r
   Set a file's CurrentPos and CurrentCluster, then compute StraightReadAmount.\r
 \r
-  @param  PrivateData            the global memory map \r
-  @param  File                   the file \r
-  @param  Pos                    the Position which is offset from the file's \r
-                                 CurrentPos \r
+  @param  PrivateData            the global memory map\r
+  @param  File                   the file\r
+  @param  Pos                    the Position which is offset from the file's\r
+                                 CurrentPos\r
 \r
-  @retval EFI_SUCCESS            Success. \r
-  @retval EFI_INVALID_PARAMETER  Pos is beyond file's size. \r
+  @retval EFI_SUCCESS            Success.\r
+  @retval EFI_INVALID_PARAMETER  Pos is beyond file's size.\r
   @retval EFI_DEVICE_ERROR       Something error while accessing media.\r
 \r
 **/\r
@@ -315,7 +315,10 @@ FatSetFilePos (
     }\r
 \r
     File->CurrentPos += Pos;\r
-\r
+    //\r
+    // Calculate the amount of consecutive cluster occupied by the file.\r
+    // FatReadFile() will use it to read these blocks once.\r
+    //\r
     File->StraightReadAmount  = 0;\r
     Cluster                   = File->CurrentCluster;\r
     while (!FAT_CLUSTER_FUNCTIONAL (Cluster)) {\r
@@ -343,13 +346,13 @@ FatSetFilePos (
 /**\r
   Reads file data. Updates the file's CurrentPos.\r
 \r
-  @param  PrivateData            Global memory map for accessing global variables \r
-  @param  File                   The file. \r
-  @param  Size                   The amount of data to read. \r
-  @param  Buffer                 The buffer storing the data. \r
+  @param  PrivateData            Global memory map for accessing global variables\r
+  @param  File                   The file.\r
+  @param  Size                   The amount of data to read.\r
+  @param  Buffer                 The buffer storing the data.\r
 \r
-  @retval EFI_SUCCESS            The data is read. \r
-  @retval EFI_INVALID_PARAMETER  File is invalid. \r
+  @retval EFI_SUCCESS            The data is read.\r
+  @retval EFI_INVALID_PARAMETER  File is invalid.\r
   @retval EFI_DEVICE_ERROR       Something error while accessing media.\r
 \r
 **/\r
@@ -390,7 +393,7 @@ FatReadFile (
   } else {\r
 \r
     if ((File->Attributes & FAT_ATTR_DIRECTORY) == 0) {\r
-      Size = Size < (File->FileSize - File->CurrentPos) ? Size : (UINTN) (File->FileSize - File->CurrentPos);\r
+      Size = Size < (File->FileSize - File->CurrentPos) ? Size : (File->FileSize - File->CurrentPos);\r
     }\r
     //\r
     // This is a normal cluster based file\r
@@ -431,14 +434,14 @@ FatReadFile (
   The function updates the CurrentPos of the parent dir to after the item read.\r
   If no more items were found, the function returns EFI_NOT_FOUND.\r
 \r
-  @param  PrivateData            Global memory map for accessing global variables \r
-  @param  ParentDir              The parent directory. \r
-  @param  SubFile                The File structure containing the sub file that \r
-                                 is caught. \r
+  @param  PrivateData            Global memory map for accessing global variables\r
+  @param  ParentDir              The parent directory.\r
+  @param  SubFile                The File structure containing the sub file that\r
+                                 is caught.\r
 \r
-  @retval EFI_SUCCESS            The next sub file is obtained. \r
-  @retval EFI_INVALID_PARAMETER  The ParentDir is not a directory. \r
-  @retval EFI_NOT_FOUND          No more sub file exists. \r
+  @retval EFI_SUCCESS            The next sub file is obtained.\r
+  @retval EFI_INVALID_PARAMETER  The ParentDir is not a directory.\r
+  @retval EFI_NOT_FOUND          No more sub file exists.\r
   @retval EFI_DEVICE_ERROR       Something error while accessing media.\r
 \r
 **/\r
@@ -472,7 +475,7 @@ FatReadNextDirectoryEntry (
     // We only search for *FILE* in root directory\r
     // Long file name entry is *NOT* supported\r
     //\r
-    if ((DirEntry.Attributes == FAT_ATTR_DIRECTORY) || (DirEntry.Attributes == FAT_ATTR_LFN)) {\r
+    if (((DirEntry.Attributes & FAT_ATTR_DIRECTORY) == FAT_ATTR_DIRECTORY) || (DirEntry.Attributes == FAT_ATTR_LFN)) {\r
       continue;\r
     }\r
     //\r
@@ -517,9 +520,6 @@ FatReadNextDirectoryEntry (
   SubFile->StartingCluster  = SubFile->CurrentCluster;\r
   SubFile->Volume           = ParentDir->Volume;\r
 \r
-  if (SubFile->StartingCluster != 0) {\r
-    Status = FatSetFilePos (PrivateData, SubFile, 0);\r
-  }\r
   //\r
   // in Pei phase, time parameters do not need to be filled for minimum use.\r
   //\r