X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=FatPkg%2FEnhancedFatDxe%2FMisc.c;h=244b9dd921afb21cb7e1291cd06e3523bc42d492;hp=f91759c775c4d7119c7b7b59a268137d6ab10fe5;hb=e38f26a2f7f62b69fec2d84e83bcc4b45ddefdc1;hpb=bd10d0712fe2c644c00af6e3d2d968587ea0c400 diff --git a/FatPkg/EnhancedFatDxe/Misc.c b/FatPkg/EnhancedFatDxe/Misc.c index f91759c775..244b9dd921 100644 --- a/FatPkg/EnhancedFatDxe/Misc.c +++ b/FatPkg/EnhancedFatDxe/Misc.c @@ -1,6 +1,7 @@ -/*++ +/** @file + Miscellaneous functions. -Copyright (c) 2005 - 2013, Intel Corporation. All rights reserved.
+Copyright (c) 2005 - 2018, Intel Corporation. All rights reserved.
This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this distribution. The full text of the license may be found at @@ -10,39 +11,26 @@ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. -Module Name: - - Misc.c +**/ -Abstract: +#include "Fat.h" +UINT8 mMonthDays[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; - Miscellaneous functions +/** -Revision History + Create the task ---*/ + @param IFile - The instance of the open file. + @param Token - A pointer to the token associated with the transaction. -#include "Fat.h" + @return FAT_TASK * - Return the task instance. +**/ FAT_TASK * FatCreateTask ( FAT_IFILE *IFile, EFI_FILE_IO_TOKEN *Token ) -/*++ - -Routine Description: - - Create the task - -Arguments: - - IFile - The instance of the open file. - Token - A pointer to the token associated with the transaction. - -Return: - FAT_TASK * - Return the task instance. -**/ { FAT_TASK *Task; @@ -57,20 +45,17 @@ Return: return Task; } -VOID -FatDestroyTask ( - FAT_TASK *Task - ) -/*++ - -Routine Description: +/** - Destroy the task + Destroy the task. -Arguments: + @param Task - The task to be destroyed. - Task - The task to be destroyed. **/ +VOID +FatDestroyTask ( + FAT_TASK *Task + ) { LIST_ENTRY *Link; FAT_SUBTASK *Subtask; @@ -83,20 +68,17 @@ Arguments: FreePool (Task); } -VOID -FatWaitNonblockingTask ( - FAT_IFILE *IFile - ) -/*++ - -Routine Description: +/** Wait all non-blocking requests complete. -Arguments: + @param IFile - The instance of the open file. - IFile - The instance of the open file. **/ +VOID +FatWaitNonblockingTask ( + FAT_IFILE *IFile + ) { BOOLEAN TaskQueueEmpty; @@ -107,25 +89,19 @@ Arguments: } while (!TaskQueueEmpty); } -LIST_ENTRY * -FatDestroySubtask ( - FAT_SUBTASK *Subtask - ) -/*++ - -Routine Description: +/** Remove the subtask from subtask list. -Arguments: - - Subtask - The subtask to be removed. - -Returns: + @param Subtask - The subtask to be removed. - LIST_ENTRY * - The next node in the list. + @return LIST_ENTRY * - The next node in the list. ---*/ +**/ +LIST_ENTRY * +FatDestroySubtask ( + FAT_SUBTASK *Subtask + ) { LIST_ENTRY *Link; @@ -137,31 +113,26 @@ Returns: return Link; } +/** + + Execute the task. + + @param IFile - The instance of the open file. + @param Task - The task to be executed. + + @retval EFI_SUCCESS - The task was executed sucessfully. + @return other - An error occurred when executing the task. + +**/ EFI_STATUS FatQueueTask ( IN FAT_IFILE *IFile, IN FAT_TASK *Task ) -/*++ - -Routine Description: - - Execute the task - -Arguments: - - IFile - The instance of the open file. - Task - The task to be executed. - -Returns: - - EFI_SUCCESS - The task was executed sucessfully. - other - An error occurred when executing the task. - ---*/ { EFI_STATUS Status; LIST_ENTRY *Link; + LIST_ENTRY *NextLink; FAT_SUBTASK *Subtask; // @@ -179,13 +150,21 @@ Returns: EfiReleaseLock (&FatTaskLock); Status = EFI_SUCCESS; - for ( Link = GetFirstNode (&Task->Subtasks) - ; !IsNull (&Task->Subtasks, Link) - ; Link = GetNextNode (&Task->Subtasks, Link) + // + // Use NextLink to store the next link of the list, because Link might be remove from the + // doubly-linked list and get freed in the end of current loop. + // + // Also, list operation APIs like IsNull() and GetNextNode() are avoided during the loop, since + // they may check the validity of doubly-linked lists by traversing them. These APIs cannot + // handle list elements being removed during the traverse. + // + for ( Link = GetFirstNode (&Task->Subtasks), NextLink = GetNextNode (&Task->Subtasks, Link) + ; Link != &Task->Subtasks + ; Link = NextLink, NextLink = Link->ForwardLink ) { Subtask = CR (Link, FAT_SUBTASK, Link, FAT_SUBTASK_SIGNATURE); if (Subtask->Write) { - + Status = IFile->OFile->Volume->DiskIo2->WriteDiskEx ( IFile->OFile->Volume->DiskIo2, IFile->OFile->Volume->MediaId, @@ -238,30 +217,24 @@ Returns: return Status; } +/** + + Set the volume as dirty or not. + + @param Volume - FAT file system volume. + @param IoMode - The access mode. + @param DirtyValue - Set the volume as dirty or not. + + @retval EFI_SUCCESS - Set the new FAT entry value sucessfully. + @return other - An error occurred when operation the FAT entries. + +**/ EFI_STATUS FatAccessVolumeDirty ( IN FAT_VOLUME *Volume, IN IO_MODE IoMode, IN VOID *DirtyValue ) -/*++ - -Routine Description: - - Set the volume as dirty or not - -Arguments: - - Volume - FAT file system volume. - IoMode - The access mode. - DirtyValue - Set the volume as dirty or not. - -Returns: - - EFI_SUCCESS - Set the new FAT entry value sucessfully. - other - An error occurred when operation the FAT entries. - ---*/ { UINTN WriteCount; @@ -270,7 +243,7 @@ Returns: } /** - Invoke a notification event + Invoke a notification event. @param Event Event whose notification function is being invoked. @param Context The pointer to the notification function's context, @@ -283,22 +256,6 @@ FatOnAccessComplete ( IN EFI_EVENT Event, IN VOID *Context ) -/*++ - -Routine Description: - - Invoke a notification event - case #1. some subtasks are not completed when the FatOpenEx checks the Task->Subtasks - - sets Task->SubtaskCollected so callback to signal the event and free the task. - case #2. all subtasks are completed when the FatOpenEx checks the Task->Subtasks - - FatOpenEx signal the event and free the task. -Arguments: - - Event - Event whose notification function is being invoked. - Context - The pointer to the notification function's context, - which is implementation-dependent. - ---*/ { EFI_STATUS Status; FAT_SUBTASK *Subtask; @@ -341,6 +298,22 @@ Arguments: } } +/** + + General disk access function. + + @param Volume - FAT file system volume. + @param IoMode - The access mode (disk read/write or cache access). + @param Offset - The starting byte offset to read from. + @param BufferSize - Size of Buffer. + @param Buffer - Buffer containing read data. + @param Task point to task instance. + + @retval EFI_SUCCESS - The operation is performed successfully. + @retval EFI_VOLUME_CORRUPTED - The accesss is + @return Others - The status of read/write the disk + +**/ EFI_STATUS FatDiskIo ( IN FAT_VOLUME *Volume, @@ -350,27 +323,6 @@ FatDiskIo ( IN OUT VOID *Buffer, IN FAT_TASK *Task ) -/*++ - -Routine Description: - - General disk access function - -Arguments: - - Volume - FAT file system volume. - IoMode - The access mode (disk read/write or cache access). - Offset - The starting byte offset to read from. - BufferSize - Size of Buffer. - Buffer - Buffer containing read data. - -Returns: - - EFI_SUCCESS - The operation is performed successfully. - EFI_VOLUME_CORRUPTED - The accesss is - Others - The status of read/write the disk - ---*/ { EFI_STATUS Status; EFI_DISK_IO_PROTOCOL *DiskIo; @@ -396,7 +348,7 @@ Returns: // Blocking access // DiskIo = Volume->DiskIo; - IoFunction = (IoMode == READ_DISK) ? DiskIo->ReadDisk : DiskIo->WriteDisk; + IoFunction = (IoMode == ReadDisk) ? DiskIo->ReadDisk : DiskIo->WriteDisk; Status = IoFunction (DiskIo, Volume->MediaId, Offset, BufferSize, Buffer); } else { // @@ -408,7 +360,7 @@ Returns: } else { Subtask->Signature = FAT_SUBTASK_SIGNATURE; Subtask->Task = Task; - Subtask->Write = (BOOLEAN) (IoMode == WRITE_DISK); + Subtask->Write = (BOOLEAN) (IoMode == WriteDisk); Subtask->Offset = Offset; Subtask->Buffer = Buffer; Subtask->BufferSize = BufferSize; @@ -437,97 +389,61 @@ Returns: return Status; } +/** + + Lock the volume. + +**/ VOID FatAcquireLock ( VOID ) -/*++ - -Routine Description: - - Lock the volume. - -Arguments: - - None. - -Returns: - - None. - ---*/ { EfiAcquireLock (&FatFsLock); } -EFI_STATUS -FatAcquireLockOrFail ( - VOID - ) -/*++ - -Routine Description: +/** Lock the volume. If the lock is already in the acquired state, then EFI_ACCESS_DENIED is returned. Otherwise, EFI_SUCCESS is returned. -Arguments: - - None. - -Returns: - - EFI_SUCCESS - The volume is locked. - EFI_ACCESS_DENIED - The volume could not be locked because it is already locked. + @retval EFI_SUCCESS - The volume is locked. + @retval EFI_ACCESS_DENIED - The volume could not be locked because it is already locked. ---*/ +**/ +EFI_STATUS +FatAcquireLockOrFail ( + VOID + ) { return EfiAcquireLockOrFail (&FatFsLock); } +/** + + Unlock the volume. + +**/ VOID FatReleaseLock ( VOID ) -/*++ - -Routine Description: - - Unlock the volume. - -Arguments: - - Null. - -Returns: - - None. - ---*/ { EfiReleaseLock (&FatFsLock); } -VOID -FatFreeDirEnt ( - IN FAT_DIRENT *DirEnt - ) -/*++ - -Routine Description: +/** Free directory entry. -Arguments: - - DirEnt - The directory entry to be freed. - -Returns: - - None. + @param DirEnt - The directory entry to be freed. ---*/ +**/ +VOID +FatFreeDirEnt ( + IN FAT_DIRENT *DirEnt + ) { if (DirEnt->FileString != NULL) { FreePool (DirEnt->FileString); @@ -536,25 +452,17 @@ Returns: FreePool (DirEnt); } -VOID -FatFreeVolume ( - IN FAT_VOLUME *Volume - ) -/*++ - -Routine Description: +/** Free volume structure (including the contents of directory cache and disk cache). -Arguments: - - Volume - The volume structure to be freed. - -Returns: - - None. + @param Volume - The volume structure to be freed. ---*/ +**/ +VOID +FatFreeVolume ( + IN FAT_VOLUME *Volume + ) { // // Free disk cache @@ -569,27 +477,19 @@ Returns: FreePool (Volume); } +/** + + Translate EFI time to FAT time. + + @param ETime - The time of EFI_TIME. + @param FTime - The time of FAT_DATE_TIME. + +**/ VOID FatEfiTimeToFatTime ( IN EFI_TIME *ETime, OUT FAT_DATE_TIME *FTime ) -/*++ - -Routine Description: - - Translate EFI time to FAT time. - -Arguments: - - ETime - The time of EFI_TIME. - FTime - The time of FAT_DATE_TIME. - -Returns: - - None. - ---*/ { // // ignores timezone info in source ETime @@ -609,27 +509,19 @@ Returns: FTime->Time.DoubleSecond = (UINT16) (ETime->Second / 2); } +/** + + Translate Fat time to EFI time. + + @param FTime - The time of FAT_DATE_TIME. + @param ETime - The time of EFI_TIME.. + +**/ VOID FatFatTimeToEfiTime ( IN FAT_DATE_TIME *FTime, OUT EFI_TIME *ETime ) -/*++ - -Routine Description: - - Translate Fat time to EFI time. - -Arguments: - - FTime - The time of FAT_DATE_TIME. - ETime - The time of EFI_TIME. - -Returns: - - None. - ---*/ { ETime->Year = (UINT16) (FTime->Date.Year + 1980); ETime->Month = (UINT8) FTime->Date.Month; @@ -642,25 +534,17 @@ Returns: ETime->Daylight = 0; } -VOID -FatGetCurrentFatTime ( - OUT FAT_DATE_TIME *FatNow - ) -/*++ - -Routine Description: +/** Get Current FAT time. -Arguments: - - FatNow - Current FAT time. + @param FatNow - Current FAT time. -Returns: - - None. - ---*/ +**/ +VOID +FatGetCurrentFatTime ( + OUT FAT_DATE_TIME *FatNow + ) { EFI_STATUS Status; EFI_TIME Now; @@ -677,28 +561,21 @@ Returns: } } -BOOLEAN -FatIsValidTime ( - IN EFI_TIME *Time - ) -/*++ - -Routine Description: +/** Check whether a time is valid. -Arguments: - - Time - The time of EFI_TIME. + @param Time - The time of EFI_TIME. -Returns: + @retval TRUE - The time is valid. + @retval FALSE - The time is not valid. - TRUE - The time is valid. - FALSE - The time is not valid. - ---*/ +**/ +BOOLEAN +FatIsValidTime ( + IN EFI_TIME *Time + ) { - static UINT8 MonthDays[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; UINTN Day; BOOLEAN ValidTime; @@ -725,7 +602,7 @@ Returns: // // Perform a more specific check of the day of the month // - Day = MonthDays[Time->Month - 1]; + Day = mMonthDays[Time->Month - 1]; if (Time->Month == 2 && IS_LEAP_YEAR (Time->Year)) { Day += 1; //