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