]> git.proxmox.com Git - mirror_edk2.git/blobdiff - FatPkg/EnhancedFatDxe/Init.c
FatPkg: Refine casting expression result to bigger size
[mirror_edk2.git] / FatPkg / EnhancedFatDxe / Init.c
index b0e34d18cd005cbb16f42e102f071557dd262c0b..6febffcddd62f1a5186988d9497b83819ba2df3b 100644 (file)
@@ -1,7 +1,8 @@
-/*++\r
+/** @file\r
+  Initialization routines.\r
 \r
-Copyright (c) 2005 - 2007, Intel Corporation\r
-All rights reserved. This program and the accompanying materials are licensed and made available\r
+Copyright (c) 2005 - 2013, Intel Corporation. All rights reserved.<BR>\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
 distribution. The full text of the license may be found at\r
 http://opensource.org/licenses/bsd-license.php\r
@@ -9,50 +10,36 @@ http://opensource.org/licenses/bsd-license.php
 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
 \r
+**/\r
 \r
-Module Name:\r
+#include "Fat.h"\r
 \r
-  Init.c\r
+/**\r
 \r
-Abstract:\r
+  Allocates volume structure, detects FAT file system, installs protocol,\r
+  and initialize cache.\r
 \r
-  Initialization routines\r
+  @param  Handle                - The handle of parent device.\r
+  @param  DiskIo                - The DiskIo of parent device.\r
+  @param  DiskIo2               - The DiskIo2 of parent device.\r
+  @param  BlockIo               - The BlockIo of parent devicel\r
 \r
---*/\r
-\r
-#include "Fat.h"\r
+  @retval EFI_SUCCESS           - Allocate a new volume successfully.\r
+  @retval EFI_OUT_OF_RESOURCES  - Can not allocate the memory.\r
+  @return Others                - Allocating a new volume failed.\r
 \r
+**/\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
   )\r
-/*++\r
-\r
-Routine Description:\r
-\r
-  Allocates volume structure, detects FAT file system, installs protocol,\r
-  and initialize cache.\r
-\r
-Arguments:\r
-\r
-  Handle                - The handle of parent device.\r
-  DiskIo                - The DiskIo of parent device.\r
-  BlockIo               - The BlockIo of parent devicel\r
-\r
-Returns:\r
-\r
-  EFI_SUCCESS           - Allocate a new volume successfully.\r
-  EFI_OUT_OF_RESOURCES  - Can not allocate the memory.\r
-  Others                - Allocating a new volume failed.\r
-\r
---*/\r
 {\r
   EFI_STATUS  Status;\r
   FAT_VOLUME  *Volume;\r
-  BOOLEAN     LockedByMe;\r
-  LockedByMe = FALSE;\r
+\r
   //\r
   // Allocate a volume structure\r
   //\r
@@ -60,20 +47,14 @@ Returns:
   if (Volume == NULL) {\r
     return EFI_OUT_OF_RESOURCES;\r
   }\r
-  //\r
-  // Acquire the lock.\r
-  // If caller has already acquired the lock, cannot lock it again.\r
-  //\r
-  if (!FatIsLocked ()) {\r
-    FatAcquireLock ();\r
-    LockedByMe = TRUE;\r
-  }\r
+\r
   //\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
@@ -119,13 +100,6 @@ Returns:
   Volume->Valid = TRUE;\r
 \r
 Done:\r
-  //\r
-  // Unlock if locked by myself.\r
-  //\r
-  if (LockedByMe) {\r
-    FatReleaseLock ();\r
-  }\r
-\r
   if (EFI_ERROR (Status)) {\r
     FatFreeVolume (Volume);\r
   }\r
@@ -133,26 +107,20 @@ Done:
   return Status;\r
 }\r
 \r
-EFI_STATUS\r
-FatAbandonVolume (\r
-  IN FAT_VOLUME *Volume\r
-  )\r
-/*++\r
-\r
-Routine Description:\r
+/**\r
 \r
   Called by FatDriverBindingStop(), Abandon the volume.\r
 \r
-Arguments:\r
-\r
-  Volume                - The volume to be abandoned.\r
-\r
-Returns:\r
+  @param  Volume                - The volume to be abandoned.\r
 \r
-  EFI_SUCCESS           - Abandoned the volume successfully.\r
-  Others                - Can not uninstall the protocol interfaces.\r
+  @retval EFI_SUCCESS           - Abandoned the volume successfully.\r
+  @return Others                - Can not uninstall the protocol interfaces.\r
 \r
---*/\r
+**/\r
+EFI_STATUS\r
+FatAbandonVolume (\r
+  IN FAT_VOLUME *Volume\r
+  )\r
 {\r
   EFI_STATUS  Status;\r
   BOOLEAN     LockedByMe;\r
@@ -180,9 +148,9 @@ Returns:
   // means we are in the process of some Fat operation),\r
   // we can not acquire again.\r
   //\r
-  if (!FatIsLocked ()) {\r
+  Status = FatAcquireLockOrFail ();\r
+  if (!EFI_ERROR (Status)) {\r
     LockedByMe = TRUE;\r
-    FatAcquireLock ();\r
   }\r
   //\r
   // The volume is still being used. Hence, set error flag for all OFiles still in\r
@@ -208,34 +176,28 @@ Returns:
   // FatCleanupVolume do the task.\r
   //\r
   if (LockedByMe) {\r
-    FatCleanupVolume (Volume, NULL, EFI_SUCCESS);\r
+    FatCleanupVolume (Volume, NULL, EFI_SUCCESS, NULL);\r
     FatReleaseLock ();\r
   }\r
 \r
   return EFI_SUCCESS;\r
 }\r
 \r
-EFI_STATUS\r
-FatOpenDevice (\r
-  IN OUT FAT_VOLUME           *Volume\r
-  )\r
-/*++\r
-\r
-Routine Description:\r
+/**\r
 \r
-  Detects FAT file system on Disk and set relevant fields of Volume\r
+  Detects FAT file system on Disk and set relevant fields of Volume.\r
 \r
-Arguments:\r
+  @param Volume                - The volume structure.\r
 \r
-  Volume                - The volume structure.\r
+  @retval EFI_SUCCESS           - The Fat File System is detected successfully\r
+  @retval EFI_UNSUPPORTED       - The volume is not FAT file system.\r
+  @retval EFI_VOLUME_CORRUPTED  - The volume is corrupted.\r
 \r
-Returns:\r
-\r
-  EFI_SUCCESS           - The Fat File System is detected successfully\r
-  EFI_UNSUPPORTED       - The volume is not FAT file system.\r
-  EFI_VOLUME_CORRUPTED  - The volume is corrupted.\r
-\r
---*/\r
+**/\r
+EFI_STATUS\r
+FatOpenDevice (\r
+  IN OUT FAT_VOLUME           *Volume\r
+  )\r
 {\r
   EFI_STATUS            Status;\r
   UINT32                BlockSize;\r
@@ -278,7 +240,7 @@ Returns:
   SectorsPerFat = FatBs.FatBsb.SectorsPerFat;\r
   if (SectorsPerFat == 0) {\r
     SectorsPerFat = FatBs.FatBse.Fat32Bse.LargeSectorsPerFat;\r
-    FatType       = FAT32;\r
+    FatType       = Fat32;\r
   }\r
   //\r
   // Is boot sector a fat sector?\r
@@ -318,7 +280,7 @@ Returns:
   //\r
   // Initialize fields the volume information for this FatType\r
   //\r
-  if (FatType != FAT32) {\r
+  if (FatType != Fat32) {\r
     if (FatBs.FatBsb.RootEntries == 0) {\r
       return EFI_UNSUPPORTED;\r
     }\r
@@ -363,12 +325,12 @@ Returns:
   //\r
   // If this is not a fat32, determine if it's a fat16 or fat12\r
   //\r
-  if (FatType != FAT32) {\r
+  if (FatType != Fat32) {\r
     if (Volume->MaxCluster >= FAT_MAX_FAT16_CLUSTER) {\r
       return EFI_VOLUME_CORRUPTED;\r
     }\r
 \r
-    FatType = Volume->MaxCluster < FAT_MAX_FAT12_CLUSTER ? FAT12 : FAT16;\r
+    FatType = Volume->MaxCluster < FAT_MAX_FAT12_CLUSTER ? Fat12 : Fat16;\r
     //\r
     // fat12 & fat16 fat-entries are 2 bytes\r
     //\r
@@ -389,8 +351,8 @@ Returns:
   // We should keep the initial value as the NotDirtyValue\r
   // in case the volume is dirty already\r
   //\r
-  if (FatType != FAT12) {\r
-    Status = FatAccessVolumeDirty (Volume, READ_DISK, &Volume->NotDirtyValue);\r
+  if (FatType != Fat12) {\r
+    Status = FatAccessVolumeDirty (Volume, ReadDisk, &Volume->NotDirtyValue);\r
     if (EFI_ERROR (Status)) {\r
       return Status;\r
     }\r
@@ -400,10 +362,10 @@ Returns:
   //\r
   // If present, read the fat hint info\r
   //\r
-  if (FatType == FAT32) {\r
+  if (FatType == Fat32) {\r
     Volume->FreeInfoPos = FatBs.FatBse.Fat32Bse.FsInfoSector * BlockSize;\r
     if (FatBs.FatBse.Fat32Bse.FsInfoSector != 0) {\r
-      FatDiskIo (Volume, READ_DISK, Volume->FreeInfoPos, sizeof (FAT_INFO_SECTOR), &Volume->FatInfoSector);\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