-/*++\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
-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
+Copyright (c) 2005 - 2013, Intel Corporation. All rights reserved.<BR>\r
+SPDX-License-Identifier: BSD-2-Clause-Patent\r
\r
-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
+#include "Fat.h"\r
\r
-Module Name:\r
-\r
- Init.c\r
-\r
-Abstract:\r
+/**\r
\r
- Initialization routines\r
+ Allocates volume structure, detects FAT file system, installs protocol,\r
+ and initialize cache.\r
\r
---*/\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 device.\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
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
//\r
// Volume installed\r
//\r
- DEBUG ((EFI_D_INIT, "%HInstalled Fat filesystem on %x%N\n", Handle));\r
+ DEBUG ((EFI_D_INIT, "Installed Fat filesystem on %p\n", Handle));\r
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
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
+ @param Volume - The volume to be abandoned.\r
\r
-Returns:\r
+ @retval EFI_SUCCESS - Abandoned the volume successfully.\r
+ @return Others - Can not uninstall the protocol interfaces.\r
\r
- EFI_SUCCESS - Abandoned the volume successfully.\r
- 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
// 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
// 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
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
//\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
//\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
// 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
//\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