]> git.proxmox.com Git - mirror_edk2.git/blobdiff - FatPkg/EnhancedFatDxe/Init.c
FatPkg: Apply uncrustify changes
[mirror_edk2.git] / FatPkg / EnhancedFatDxe / Init.c
index fb62dc23323c1c57d94888ddc0f509bed412e912..208318c7ad6aa98143e4b51b0608121770ae10ee 100644 (file)
@@ -25,10 +25,10 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
 **/\r
 EFI_STATUS\r
 FatAllocateVolume (\r
-  IN  EFI_HANDLE                Handle,\r
-  IN  EFI_DISK_IO_PROTOCOL      *DiskIo,\r
-  IN  EFI_DISK_IO2_PROTOCOL     *DiskIo2,\r
-  IN  EFI_BLOCK_IO_PROTOCOL     *BlockIo\r
+  IN  EFI_HANDLE             Handle,\r
+  IN  EFI_DISK_IO_PROTOCOL   *DiskIo,\r
+  IN  EFI_DISK_IO2_PROTOCOL  *DiskIo2,\r
+  IN  EFI_BLOCK_IO_PROTOCOL  *BlockIo\r
   )\r
 {\r
   EFI_STATUS  Status;\r
@@ -45,15 +45,15 @@ FatAllocateVolume (
   //\r
   // Initialize the structure\r
   //\r
-  Volume->Signature                   = FAT_VOLUME_SIGNATURE;\r
-  Volume->Handle                      = Handle;\r
-  Volume->DiskIo                      = DiskIo;\r
-  Volume->DiskIo2                     = DiskIo2;\r
-  Volume->BlockIo                     = BlockIo;\r
-  Volume->MediaId                     = BlockIo->Media->MediaId;\r
-  Volume->ReadOnly                    = BlockIo->Media->ReadOnly;\r
-  Volume->VolumeInterface.Revision    = EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_REVISION;\r
-  Volume->VolumeInterface.OpenVolume  = FatOpenVolume;\r
+  Volume->Signature                  = FAT_VOLUME_SIGNATURE;\r
+  Volume->Handle                     = Handle;\r
+  Volume->DiskIo                     = DiskIo;\r
+  Volume->DiskIo2                    = DiskIo2;\r
+  Volume->BlockIo                    = BlockIo;\r
+  Volume->MediaId                    = BlockIo->Media->MediaId;\r
+  Volume->ReadOnly                   = BlockIo->Media->ReadOnly;\r
+  Volume->VolumeInterface.Revision   = EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_REVISION;\r
+  Volume->VolumeInterface.OpenVolume = FatOpenVolume;\r
   InitializeListHead (&Volume->CheckRef);\r
   InitializeListHead (&Volume->DirCacheList);\r
   //\r
@@ -68,6 +68,7 @@ FatAllocateVolume (
   if (EFI_ERROR (Status)) {\r
     goto Done;\r
   }\r
+\r
   //\r
   // Initialize cache\r
   //\r
@@ -75,6 +76,7 @@ FatAllocateVolume (
   if (EFI_ERROR (Status)) {\r
     goto Done;\r
   }\r
+\r
   //\r
   // Install our protocol interfaces on the device's handle\r
   //\r
@@ -87,6 +89,7 @@ FatAllocateVolume (
   if (EFI_ERROR (Status)) {\r
     goto Done;\r
   }\r
+\r
   //\r
   // Volume installed\r
   //\r
@@ -113,7 +116,7 @@ Done:
 **/\r
 EFI_STATUS\r
 FatAbandonVolume (\r
-  IN FAT_VOLUME *Volume\r
+  IN FAT_VOLUME  *Volume\r
   )\r
 {\r
   EFI_STATUS  Status;\r
@@ -146,6 +149,7 @@ FatAbandonVolume (
   if (!EFI_ERROR (Status)) {\r
     LockedByMe = TRUE;\r
   }\r
+\r
   //\r
   // The volume is still being used. Hence, set error flag for all OFiles still in\r
   // use. In two cases, we could get here. One is EFI_MEDIA_CHANGED, the other is\r
@@ -190,7 +194,7 @@ FatAbandonVolume (
 **/\r
 EFI_STATUS\r
 FatOpenDevice (\r
-  IN OUT FAT_VOLUME           *Volume\r
+  IN OUT FAT_VOLUME  *Volume\r
   )\r
 {\r
   EFI_STATUS            Status;\r
@@ -213,8 +217,8 @@ FatOpenDevice (
   // This is the only part of FAT code that uses parent DiskIo,\r
   // Others use FatDiskIo which utilizes a Cache.\r
   //\r
-  DiskIo  = Volume->DiskIo;\r
-  Status  = DiskIo->ReadDisk (DiskIo, Volume->MediaId, 0, sizeof (FatBs), &FatBs);\r
+  DiskIo = Volume->DiskIo;\r
+  Status = DiskIo->ReadDisk (DiskIo, Volume->MediaId, 0, sizeof (FatBs), &FatBs);\r
 \r
   if (EFI_ERROR (Status)) {\r
     DEBUG ((DEBUG_INIT, "FatOpenDevice: read of part_lba failed %r\n", Status));\r
@@ -236,13 +240,14 @@ FatOpenDevice (
     SectorsPerFat = FatBs.FatBse.Fat32Bse.LargeSectorsPerFat;\r
     FatType       = Fat32;\r
   }\r
+\r
   //\r
   // Is boot sector a fat sector?\r
   // (Note that so far we only know if the sector is FAT32 or not, we don't\r
   // know if the sector is Fat16 or Fat12 until later when we can compute\r
   // the volume size)\r
   //\r
-  if (FatBs.FatBsb.ReservedSectors == 0 || FatBs.FatBsb.NumFats == 0 || Sectors == 0) {\r
+  if ((FatBs.FatBsb.ReservedSectors == 0) || (FatBs.FatBsb.NumFats == 0) || (Sectors == 0)) {\r
     return EFI_UNSUPPORTED;\r
   }\r
 \r
@@ -250,8 +255,8 @@ FatOpenDevice (
     return EFI_UNSUPPORTED;\r
   }\r
 \r
-  BlockAlignment = (UINT8) HighBitSet32 (FatBs.FatBsb.SectorSize);\r
-  if (BlockAlignment > MAX_BLOCK_ALIGNMENT || BlockAlignment < MIN_BLOCK_ALIGNMENT) {\r
+  BlockAlignment = (UINT8)HighBitSet32 (FatBs.FatBsb.SectorSize);\r
+  if ((BlockAlignment > MAX_BLOCK_ALIGNMENT) || (BlockAlignment < MIN_BLOCK_ALIGNMENT)) {\r
     return EFI_UNSUPPORTED;\r
   }\r
 \r
@@ -259,18 +264,20 @@ FatOpenDevice (
     return EFI_UNSUPPORTED;\r
   }\r
 \r
-  SectorsPerClusterAlignment = (UINT8) HighBitSet32 (FatBs.FatBsb.SectorsPerCluster);\r
+  SectorsPerClusterAlignment = (UINT8)HighBitSet32 (FatBs.FatBsb.SectorsPerCluster);\r
   if (SectorsPerClusterAlignment > MAX_SECTORS_PER_CLUSTER_ALIGNMENT) {\r
     return EFI_UNSUPPORTED;\r
   }\r
 \r
-  if (FatBs.FatBsb.Media <= 0xf7 &&\r
-      FatBs.FatBsb.Media != 0xf0 &&\r
-      FatBs.FatBsb.Media != 0x00 &&\r
-      FatBs.FatBsb.Media != 0x01\r
-      ) {\r
+  if ((FatBs.FatBsb.Media <= 0xf7) &&\r
+      (FatBs.FatBsb.Media != 0xf0) &&\r
+      (FatBs.FatBsb.Media != 0x00) &&\r
+      (FatBs.FatBsb.Media != 0x01)\r
+      )\r
+  {\r
     return EFI_UNSUPPORTED;\r
   }\r
+\r
   //\r
   // Initialize fields the volume information for this FatType\r
   //\r
@@ -278,6 +285,7 @@ FatOpenDevice (
     if (FatBs.FatBsb.RootEntries == 0) {\r
       return EFI_UNSUPPORTED;\r
     }\r
+\r
     //\r
     // Unpack fat12, fat16 info\r
     //\r
@@ -286,35 +294,36 @@ FatOpenDevice (
     //\r
     // If this is fat32, refuse to mount mirror-disabled volumes\r
     //\r
-    if ((SectorsPerFat == 0 || FatBs.FatBse.Fat32Bse.FsVersion != 0) || (FatBs.FatBse.Fat32Bse.ExtendedFlags & 0x80)) {\r
+    if (((SectorsPerFat == 0) || (FatBs.FatBse.Fat32Bse.FsVersion != 0)) || (FatBs.FatBse.Fat32Bse.ExtendedFlags & 0x80)) {\r
       return EFI_UNSUPPORTED;\r
     }\r
+\r
     //\r
     // Unpack fat32 info\r
     //\r
     Volume->RootCluster = FatBs.FatBse.Fat32Bse.RootDirFirstCluster;\r
   }\r
 \r
-  Volume->NumFats           = FatBs.FatBsb.NumFats;\r
+  Volume->NumFats = FatBs.FatBsb.NumFats;\r
   //\r
   // Compute some fat locations\r
   //\r
-  BlockSize                 = FatBs.FatBsb.SectorSize;\r
-  RootDirSectors            = ((Volume->RootEntries * sizeof (FAT_DIRECTORY_ENTRY)) + (BlockSize - 1)) / BlockSize;\r
+  BlockSize      = FatBs.FatBsb.SectorSize;\r
+  RootDirSectors = ((Volume->RootEntries * sizeof (FAT_DIRECTORY_ENTRY)) + (BlockSize - 1)) / BlockSize;\r
 \r
-  FatLba                    = FatBs.FatBsb.ReservedSectors;\r
-  RootLba                   = FatBs.FatBsb.NumFats * SectorsPerFat + FatLba;\r
-  FirstClusterLba           = RootLba + RootDirSectors;\r
+  FatLba          = FatBs.FatBsb.ReservedSectors;\r
+  RootLba         = FatBs.FatBsb.NumFats * SectorsPerFat + FatLba;\r
+  FirstClusterLba = RootLba + RootDirSectors;\r
 \r
-  Volume->FatPos            = FatLba * BlockSize;\r
-  Volume->FatSize           = SectorsPerFat * BlockSize;\r
+  Volume->FatPos  = FatLba * BlockSize;\r
+  Volume->FatSize = SectorsPerFat * BlockSize;\r
 \r
-  Volume->VolumeSize        = LShiftU64 (Sectors, BlockAlignment);\r
-  Volume->RootPos           = LShiftU64 (RootLba, BlockAlignment);\r
-  Volume->FirstClusterPos   = LShiftU64 (FirstClusterLba, BlockAlignment);\r
-  Volume->MaxCluster        = (Sectors - FirstClusterLba) >> SectorsPerClusterAlignment;\r
-  Volume->ClusterAlignment  = (UINT8)(BlockAlignment + SectorsPerClusterAlignment);\r
-  Volume->ClusterSize       = (UINTN)1 << (Volume->ClusterAlignment);\r
+  Volume->VolumeSize       = LShiftU64 (Sectors, BlockAlignment);\r
+  Volume->RootPos          = LShiftU64 (RootLba, BlockAlignment);\r
+  Volume->FirstClusterPos  = LShiftU64 (FirstClusterLba, BlockAlignment);\r
+  Volume->MaxCluster       = (Sectors - FirstClusterLba) >> SectorsPerClusterAlignment;\r
+  Volume->ClusterAlignment = (UINT8)(BlockAlignment + SectorsPerClusterAlignment);\r
+  Volume->ClusterSize      = (UINTN)1 << (Volume->ClusterAlignment);\r
 \r
   //\r
   // If this is not a fat32, determine if it's a fat16 or fat12\r
@@ -334,12 +343,14 @@ FatOpenDevice (
     if (Volume->MaxCluster < FAT_MAX_FAT16_CLUSTER) {\r
       return EFI_VOLUME_CORRUPTED;\r
     }\r
+\r
     //\r
     // fat32 fat-entries are 4 bytes\r
     //\r
     Volume->FatEntrySize = sizeof (UINT32);\r
     DirtyMask            = FAT32_DIRTY_MASK;\r
   }\r
+\r
   //\r
   // Get the DirtyValue and NotDirtyValue\r
   // We should keep the initial value as the NotDirtyValue\r
@@ -353,6 +364,7 @@ FatOpenDevice (
 \r
     Volume->DirtyValue = Volume->NotDirtyValue & DirtyMask;\r
   }\r
+\r
   //\r
   // If present, read the fat hint info\r
   //\r
@@ -360,23 +372,27 @@ FatOpenDevice (
     Volume->FreeInfoPos = FatBs.FatBse.Fat32Bse.FsInfoSector * BlockSize;\r
     if (FatBs.FatBse.Fat32Bse.FsInfoSector != 0) {\r
       FatDiskIo (Volume, ReadDisk, Volume->FreeInfoPos, sizeof (FAT_INFO_SECTOR), &Volume->FatInfoSector, NULL);\r
-      if (Volume->FatInfoSector.Signature == FAT_INFO_SIGNATURE &&\r
-          Volume->FatInfoSector.InfoBeginSignature == FAT_INFO_BEGIN_SIGNATURE &&\r
-          Volume->FatInfoSector.InfoEndSignature == FAT_INFO_END_SIGNATURE &&\r
-          Volume->FatInfoSector.FreeInfo.ClusterCount <= Volume->MaxCluster\r
-          ) {\r
+      if ((Volume->FatInfoSector.Signature == FAT_INFO_SIGNATURE) &&\r
+          (Volume->FatInfoSector.InfoBeginSignature == FAT_INFO_BEGIN_SIGNATURE) &&\r
+          (Volume->FatInfoSector.InfoEndSignature == FAT_INFO_END_SIGNATURE) &&\r
+          (Volume->FatInfoSector.FreeInfo.ClusterCount <= Volume->MaxCluster)\r
+          )\r
+      {\r
         Volume->FreeInfoValid = TRUE;\r
       }\r
     }\r
   }\r
+\r
   //\r
   // Just make up a FreeInfo.NextCluster for use by allocate cluster\r
   //\r
-  if (FAT_MIN_CLUSTER > Volume->FatInfoSector.FreeInfo.NextCluster ||\r
-     Volume->FatInfoSector.FreeInfo.NextCluster > Volume->MaxCluster + 1\r
-     ) {\r
+  if ((FAT_MIN_CLUSTER > Volume->FatInfoSector.FreeInfo.NextCluster) ||\r
+      (Volume->FatInfoSector.FreeInfo.NextCluster > Volume->MaxCluster + 1)\r
+      )\r
+  {\r
     Volume->FatInfoSector.FreeInfo.NextCluster = FAT_MIN_CLUSTER;\r
   }\r
+\r
   //\r
   // We are now defining FAT Type\r
   //\r