]> git.proxmox.com Git - mirror_edk2.git/blobdiff - FatPkg/FatPei/FatLiteAccess.c
FatPkg: Apply uncrustify changes
[mirror_edk2.git] / FatPkg / FatPei / FatLiteAccess.c
index a3f846dda1d9a0932b577b92ed9c56e20a192825..10df4516b24114a9e00787f636deb3da27bc468a 100644 (file)
@@ -9,7 +9,6 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
 \r
 #include "FatLitePeim.h"\r
 \r
-\r
 /**\r
   Check if there is a valid FAT in the corresponding Block device\r
   of the volume and if yes, fill in the relevant fields for the\r
@@ -49,25 +48,25 @@ FatGetBpbInfo (
   // Read in the BPB\r
   //\r
   Status = FatReadDisk (\r
-            PrivateData,\r
-            Volume->BlockDeviceNo,\r
-            0,\r
-            sizeof (PEI_FAT_BOOT_SECTOR_EX),\r
-            &BpbEx\r
-            );\r
+             PrivateData,\r
+             Volume->BlockDeviceNo,\r
+             0,\r
+             sizeof (PEI_FAT_BOOT_SECTOR_EX),\r
+             &BpbEx\r
+             );\r
   if (EFI_ERROR (Status)) {\r
     return Status;\r
   }\r
 \r
   CopyMem (\r
-    (UINT8 *) (&Bpb),\r
-    (UINT8 *) (&BpbEx),\r
+    (UINT8 *)(&Bpb),\r
+    (UINT8 *)(&BpbEx),\r
     sizeof (PEI_FAT_BOOT_SECTOR)\r
     );\r
 \r
   Volume->FatType = FatUnknown;\r
 \r
-  Sectors         = Bpb.Sectors;\r
+  Sectors = Bpb.Sectors;\r
   if (Sectors == 0) {\r
     Sectors = Bpb.LargeSectors;\r
   }\r
@@ -77,60 +76,65 @@ FatGetBpbInfo (
     SectorsPerFat   = BpbEx.LargeSectorsPerFat;\r
     Volume->FatType = Fat32;\r
   }\r
+\r
   //\r
   // Filter out those not a FAT\r
   //\r
-  if (Bpb.Ia32Jump[0] != 0xe9 && Bpb.Ia32Jump[0] != 0xeb && Bpb.Ia32Jump[0] != 0x49) {\r
+  if ((Bpb.Ia32Jump[0] != 0xe9) && (Bpb.Ia32Jump[0] != 0xeb) && (Bpb.Ia32Jump[0] != 0x49)) {\r
     return EFI_NOT_FOUND;\r
   }\r
 \r
-  if (Bpb.ReservedSectors == 0 || Bpb.NoFats == 0 || Sectors == 0) {\r
+  if ((Bpb.ReservedSectors == 0) || (Bpb.NoFats == 0) || (Sectors == 0)) {\r
     return EFI_NOT_FOUND;\r
   }\r
 \r
-  if (Bpb.SectorsPerCluster != 1 &&\r
-      Bpb.SectorsPerCluster != 2 &&\r
-      Bpb.SectorsPerCluster != 4 &&\r
-      Bpb.SectorsPerCluster != 8 &&\r
-      Bpb.SectorsPerCluster != 16 &&\r
-      Bpb.SectorsPerCluster != 32 &&\r
-      Bpb.SectorsPerCluster != 64 &&\r
-      Bpb.SectorsPerCluster != 128\r
-      ) {\r
+  if ((Bpb.SectorsPerCluster != 1) &&\r
+      (Bpb.SectorsPerCluster != 2) &&\r
+      (Bpb.SectorsPerCluster != 4) &&\r
+      (Bpb.SectorsPerCluster != 8) &&\r
+      (Bpb.SectorsPerCluster != 16) &&\r
+      (Bpb.SectorsPerCluster != 32) &&\r
+      (Bpb.SectorsPerCluster != 64) &&\r
+      (Bpb.SectorsPerCluster != 128)\r
+      )\r
+  {\r
     return EFI_NOT_FOUND;\r
   }\r
 \r
-  if (Volume->FatType == Fat32 && (SectorsPerFat == 0 || BpbEx.FsVersion != 0)) {\r
+  if ((Volume->FatType == Fat32) && ((SectorsPerFat == 0) || (BpbEx.FsVersion != 0))) {\r
     return EFI_NOT_FOUND;\r
   }\r
 \r
-  if (Bpb.Media != 0xf0 &&\r
-      Bpb.Media != 0xf8 &&\r
-      Bpb.Media != 0xf9 &&\r
-      Bpb.Media != 0xfb &&\r
-      Bpb.Media != 0xfc &&\r
-      Bpb.Media != 0xfd &&\r
-      Bpb.Media != 0xfe &&\r
-      Bpb.Media != 0xff &&\r
+  if ((Bpb.Media != 0xf0) &&\r
+      (Bpb.Media != 0xf8) &&\r
+      (Bpb.Media != 0xf9) &&\r
+      (Bpb.Media != 0xfb) &&\r
+      (Bpb.Media != 0xfc) &&\r
+      (Bpb.Media != 0xfd) &&\r
+      (Bpb.Media != 0xfe) &&\r
+      (Bpb.Media != 0xff) &&\r
       //\r
       // FujitsuFMR\r
       //\r
-      Bpb.Media != 0x00 &&\r
-      Bpb.Media != 0x01 &&\r
-      Bpb.Media != 0xfa\r
-      ) {\r
+      (Bpb.Media != 0x00) &&\r
+      (Bpb.Media != 0x01) &&\r
+      (Bpb.Media != 0xfa)\r
+      )\r
+  {\r
     return EFI_NOT_FOUND;\r
   }\r
 \r
-  if (Volume->FatType != Fat32 && Bpb.RootEntries == 0) {\r
+  if ((Volume->FatType != Fat32) && (Bpb.RootEntries == 0)) {\r
     return EFI_NOT_FOUND;\r
   }\r
+\r
   //\r
   // If this is fat32, refuse to mount mirror-disabled volumes\r
   //\r
-  if (Volume->FatType == Fat32 && ((BpbEx.ExtendedFlags & 0x80) != 0)) {\r
+  if ((Volume->FatType == Fat32) && ((BpbEx.ExtendedFlags & 0x80) != 0)) {\r
     return EFI_NOT_FOUND;\r
   }\r
+\r
   //\r
   // Fill in the volume structure fields\r
   // (Sectors & SectorsPerFat is computed earlier already)\r
@@ -141,22 +145,21 @@ FatGetBpbInfo (
 \r
   RootDirSectors = ((Volume->RootEntries * sizeof (FAT_DIRECTORY_ENTRY)) + (Volume->SectorSize - 1)) / Volume->SectorSize;\r
 \r
-  FatLba                  = Bpb.ReservedSectors;\r
-  RootLba                 = Bpb.NoFats * SectorsPerFat + FatLba;\r
-  FirstClusterLba         = RootLba + RootDirSectors;\r
+  FatLba          = Bpb.ReservedSectors;\r
+  RootLba         = Bpb.NoFats * SectorsPerFat + FatLba;\r
+  FirstClusterLba = RootLba + RootDirSectors;\r
 \r
   Volume->VolumeSize      = MultU64x32 (Sectors, Volume->SectorSize);\r
   Volume->FatPos          = MultU64x32 (FatLba, Volume->SectorSize);\r
   Volume->RootDirPos      = MultU64x32 (RootLba, Volume->SectorSize);\r
   Volume->FirstClusterPos = MultU64x32 (FirstClusterLba, Volume->SectorSize);\r
-  Volume->MaxCluster      = (UINT32) (Sectors - FirstClusterLba) / Bpb.SectorsPerCluster;\r
+  Volume->MaxCluster      = (UINT32)(Sectors - FirstClusterLba) / Bpb.SectorsPerCluster;\r
   Volume->RootDirCluster  = BpbEx.RootDirFirstCluster;\r
 \r
   //\r
   // If this is not a fat32, determine if it's a fat16 or fat12\r
   //\r
   if (Volume->FatType != Fat32) {\r
-\r
     if (Volume->MaxCluster >= 65525) {\r
       return EFI_NOT_FOUND;\r
     }\r
@@ -167,7 +170,6 @@ FatGetBpbInfo (
   return EFI_SUCCESS;\r
 }\r
 \r
-\r
 /**\r
   Gets the next cluster in the cluster chain\r
 \r
@@ -198,7 +200,7 @@ FatGetNextCluster (
   if (Volume->FatType == Fat32) {\r
     FatEntryPos = Volume->FatPos + MultU64x32 (4, Cluster);\r
 \r
-    Status      = FatReadDisk (PrivateData, Volume->BlockDeviceNo, FatEntryPos, 4, NextCluster);\r
+    Status        = FatReadDisk (PrivateData, Volume->BlockDeviceNo, FatEntryPos, 4, NextCluster);\r
     *NextCluster &= 0x0fffffff;\r
 \r
     //\r
@@ -207,11 +209,10 @@ FatGetNextCluster (
     if ((*NextCluster) >= 0x0ffffff7) {\r
       *NextCluster |= (-1 &~0xf);\r
     }\r
-\r
   } else if (Volume->FatType == Fat16) {\r
     FatEntryPos = Volume->FatPos + MultU64x32 (2, Cluster);\r
 \r
-    Status      = FatReadDisk (PrivateData, Volume->BlockDeviceNo, FatEntryPos, 2, NextCluster);\r
+    Status = FatReadDisk (PrivateData, Volume->BlockDeviceNo, FatEntryPos, 2, NextCluster);\r
 \r
     //\r
     // Pad high bits for our FAT_CLUSTER_... macro definitions to work\r
@@ -219,17 +220,17 @@ FatGetNextCluster (
     if ((*NextCluster) >= 0xfff7) {\r
       *NextCluster |= (-1 &~0xf);\r
     }\r
-\r
   } else {\r
     FatEntryPos = Volume->FatPos + DivU64x32Remainder (MultU64x32 (3, Cluster), 2, &Dummy);\r
 \r
-    Status      = FatReadDisk (PrivateData, Volume->BlockDeviceNo, FatEntryPos, 2, NextCluster);\r
+    Status = FatReadDisk (PrivateData, Volume->BlockDeviceNo, FatEntryPos, 2, NextCluster);\r
 \r
     if ((Cluster & 0x01) != 0) {\r
       *NextCluster = (*NextCluster) >> 4;\r
     } else {\r
       *NextCluster = (*NextCluster) & 0x0fff;\r
     }\r
+\r
     //\r
     // Pad high bits for our FAT_CLUSTER_... macro definitions to work\r
     //\r
@@ -243,10 +244,8 @@ FatGetNextCluster (
   }\r
 \r
   return EFI_SUCCESS;\r
-\r
 }\r
 \r
-\r
 /**\r
   Set a file's CurrentPos and CurrentCluster, then compute StraightReadAmount.\r
 \r
@@ -274,31 +273,29 @@ FatSetFilePos (
   UINT32      PrevCluster;\r
 \r
   if (File->IsFixedRootDir) {\r
-\r
     if (Pos >= MultU64x32 (File->Volume->RootEntries, 32) - File->CurrentPos) {\r
       return EFI_INVALID_PARAMETER;\r
     }\r
 \r
-    File->CurrentPos += Pos;\r
-    File->StraightReadAmount = (UINT32) (MultU64x32 (File->Volume->RootEntries, 32) - File->CurrentPos);\r
-\r
+    File->CurrentPos        += Pos;\r
+    File->StraightReadAmount = (UINT32)(MultU64x32 (File->Volume->RootEntries, 32) - File->CurrentPos);\r
   } else {\r
-\r
     DivU64x32Remainder (File->CurrentPos, File->Volume->ClusterSize, &Offset);\r
-    AlignedPos = (UINT32) File->CurrentPos - (UINT32) Offset;\r
+    AlignedPos = (UINT32)File->CurrentPos - (UINT32)Offset;\r
 \r
     while\r
     (\r
-      !FAT_CLUSTER_FUNCTIONAL (File->CurrentCluster) &&\r
-      AlignedPos + File->Volume->ClusterSize <= File->CurrentPos + Pos\r
-    ) {\r
+     !FAT_CLUSTER_FUNCTIONAL (File->CurrentCluster) &&\r
+     AlignedPos + File->Volume->ClusterSize <= File->CurrentPos + Pos\r
+    )\r
+    {\r
       AlignedPos += File->Volume->ClusterSize;\r
-      Status = FatGetNextCluster (\r
-                PrivateData,\r
-                File->Volume,\r
-                File->CurrentCluster,\r
-                &File->CurrentCluster\r
-                );\r
+      Status      = FatGetNextCluster (\r
+                      PrivateData,\r
+                      File->Volume,\r
+                      File->CurrentCluster,\r
+                      &File->CurrentCluster\r
+                      );\r
       if (EFI_ERROR (Status)) {\r
         return EFI_DEVICE_ERROR;\r
       }\r
@@ -313,12 +310,12 @@ FatSetFilePos (
     // 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
+    File->StraightReadAmount = 0;\r
+    Cluster                  = File->CurrentCluster;\r
     while (!FAT_CLUSTER_FUNCTIONAL (Cluster)) {\r
       File->StraightReadAmount += File->Volume->ClusterSize;\r
-      PrevCluster = Cluster;\r
-      Status      = FatGetNextCluster (PrivateData, File->Volume, Cluster, &Cluster);\r
+      PrevCluster               = Cluster;\r
+      Status                    = FatGetNextCluster (PrivateData, File->Volume, Cluster, &Cluster);\r
       if (EFI_ERROR (Status)) {\r
         return EFI_DEVICE_ERROR;\r
       }\r
@@ -329,14 +326,12 @@ FatSetFilePos (
     }\r
 \r
     DivU64x32Remainder (File->CurrentPos, File->Volume->ClusterSize, &Offset);\r
-    File->StraightReadAmount -= (UINT32) Offset;\r
-\r
+    File->StraightReadAmount -= (UINT32)Offset;\r
   }\r
 \r
   return EFI_SUCCESS;\r
 }\r
 \r
-\r
 /**\r
   Reads file data. Updates the file's CurrentPos.\r
 \r
@@ -375,53 +370,52 @@ FatReadFile (
     }\r
 \r
     Status = FatReadDisk (\r
-              PrivateData,\r
-              File->Volume->BlockDeviceNo,\r
-              File->Volume->RootDirPos + File->CurrentPos,\r
-              Size,\r
-              Buffer\r
-              );\r
-    File->CurrentPos += (UINT32) Size;\r
+               PrivateData,\r
+               File->Volume->BlockDeviceNo,\r
+               File->Volume->RootDirPos + File->CurrentPos,\r
+               Size,\r
+               Buffer\r
+               );\r
+    File->CurrentPos += (UINT32)Size;\r
     return Status;\r
-\r
   } else {\r
-\r
     if ((File->Attributes & FAT_ATTR_DIRECTORY) == 0) {\r
       Size = Size < (File->FileSize - File->CurrentPos) ? Size : (File->FileSize - File->CurrentPos);\r
     }\r
+\r
     //\r
     // This is a normal cluster based file\r
     //\r
     while (Size != 0) {\r
       DivU64x32Remainder (File->CurrentPos, File->Volume->ClusterSize, &Offset);\r
-      PhysicalAddr  = File->Volume->FirstClusterPos + MultU64x32 (File->Volume->ClusterSize, File->CurrentCluster - 2);\r
+      PhysicalAddr = File->Volume->FirstClusterPos + MultU64x32 (File->Volume->ClusterSize, File->CurrentCluster - 2);\r
 \r
-      Amount        = File->StraightReadAmount;\r
-      Amount        = Size > Amount ? Amount : Size;\r
+      Amount = File->StraightReadAmount;\r
+      Amount = Size > Amount ? Amount : Size;\r
       Status = FatReadDisk (\r
-                PrivateData,\r
-                File->Volume->BlockDeviceNo,\r
-                PhysicalAddr + Offset,\r
-                Amount,\r
-                BufferPtr\r
-                );\r
+                 PrivateData,\r
+                 File->Volume->BlockDeviceNo,\r
+                 PhysicalAddr + Offset,\r
+                 Amount,\r
+                 BufferPtr\r
+                 );\r
       if (EFI_ERROR (Status)) {\r
         return EFI_DEVICE_ERROR;\r
       }\r
+\r
       //\r
       // Advance the file's current pos and current cluster\r
       //\r
-      FatSetFilePos (PrivateData, File, (UINT32) Amount);\r
+      FatSetFilePos (PrivateData, File, (UINT32)Amount);\r
 \r
       BufferPtr += Amount;\r
-      Size -= Amount;\r
+      Size      -= Amount;\r
     }\r
 \r
     return EFI_SUCCESS;\r
   }\r
 }\r
 \r
-\r
 /**\r
   This function reads the next item in the parent directory and\r
   initializes the output parameter SubFile (CurrentPos is initialized to 0).\r
@@ -446,13 +440,13 @@ FatReadNextDirectoryEntry (
   OUT PEI_FAT_FILE          *SubFile\r
   )\r
 {\r
-  EFI_STATUS          Status;\r
-  FAT_DIRECTORY_ENTRY DirEntry;\r
-  CHAR16              *Pos;\r
-  CHAR16              BaseName[9];\r
-  CHAR16              Ext[4];\r
+  EFI_STATUS           Status;\r
+  FAT_DIRECTORY_ENTRY  DirEntry;\r
+  CHAR16               *Pos;\r
+  CHAR16               BaseName[9];\r
+  CHAR16               Ext[4];\r
 \r
-  ZeroMem ((UINT8 *) SubFile, sizeof (PEI_FAT_FILE));\r
+  ZeroMem ((UINT8 *)SubFile, sizeof (PEI_FAT_FILE));\r
 \r
   //\r
   // Pick a valid directory entry\r
@@ -465,6 +459,7 @@ FatReadNextDirectoryEntry (
     if (EFI_ERROR (Status)) {\r
       return EFI_DEVICE_ERROR;\r
     }\r
+\r
     //\r
     // We only search for *FILE* in root directory\r
     // Long file name entry is *NOT* supported\r
@@ -472,35 +467,38 @@ FatReadNextDirectoryEntry (
     if (((DirEntry.Attributes & FAT_ATTR_DIRECTORY) == FAT_ATTR_DIRECTORY) || (DirEntry.Attributes == FAT_ATTR_LFN)) {\r
       continue;\r
     }\r
+\r
     //\r
     // if this is a terminator dir entry, just return EFI_NOT_FOUND\r
     //\r
     if (DirEntry.FileName[0] == EMPTY_ENTRY_MARK) {\r
       return EFI_NOT_FOUND;\r
     }\r
+\r
     //\r
     // If this not an invalid entry neither an empty entry, this is what we want.\r
     // otherwise we will start a new loop to continue to find something meaningful\r
     //\r
-    if ((UINT8) DirEntry.FileName[0] != DELETE_ENTRY_MARK) {\r
+    if ((UINT8)DirEntry.FileName[0] != DELETE_ENTRY_MARK) {\r
       break;\r
     }\r
   }\r
+\r
   //\r
   // fill in the output parameter\r
   //\r
   EngFatToStr (8, DirEntry.FileName, BaseName);\r
   EngFatToStr (3, DirEntry.FileName + 8, Ext);\r
 \r
-  Pos = (UINT16 *) SubFile->FileName;\r
-  SetMem ((UINT8 *) Pos, FAT_MAX_FILE_NAME_LENGTH, 0);\r
-  CopyMem ((UINT8 *) Pos, (UINT8 *) BaseName, 2 * (StrLen (BaseName) + 1));\r
+  Pos = (UINT16 *)SubFile->FileName;\r
+  SetMem ((UINT8 *)Pos, FAT_MAX_FILE_NAME_LENGTH, 0);\r
+  CopyMem ((UINT8 *)Pos, (UINT8 *)BaseName, 2 * (StrLen (BaseName) + 1));\r
 \r
   if (Ext[0] != 0) {\r
     Pos += StrLen (BaseName);\r
     *Pos = '.';\r
     Pos++;\r
-    CopyMem ((UINT8 *) Pos, (UINT8 *) Ext, 2 * (StrLen (Ext) + 1));\r
+    CopyMem ((UINT8 *)Pos, (UINT8 *)Ext, 2 * (StrLen (Ext) + 1));\r
   }\r
 \r
   SubFile->Attributes     = DirEntry.Attributes;\r
@@ -509,10 +507,10 @@ FatReadNextDirectoryEntry (
     SubFile->CurrentCluster |= DirEntry.FileClusterHigh << 16;\r
   }\r
 \r
-  SubFile->CurrentPos       = 0;\r
-  SubFile->FileSize         = DirEntry.FileSize;\r
-  SubFile->StartingCluster  = SubFile->CurrentCluster;\r
-  SubFile->Volume           = ParentDir->Volume;\r
+  SubFile->CurrentPos      = 0;\r
+  SubFile->FileSize        = DirEntry.FileSize;\r
+  SubFile->StartingCluster = SubFile->CurrentCluster;\r
+  SubFile->Volume          = ParentDir->Volume;\r
 \r
   //\r
   // in Pei phase, time parameters do not need to be filled for minimum use.\r