X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=FatPkg%2FEnhancedFatDxe%2FReadWrite.c;h=ad3c2604127434f866f85af317c95f0a4bb55fca;hp=4621817c93d2562490142c6b3a7502f8d4be8cce;hb=64b25f5db17c3b16d2a898095a4a205404126b49;hpb=149d633529cc3105474f392215cc188741fb6617 diff --git a/FatPkg/EnhancedFatDxe/ReadWrite.c b/FatPkg/EnhancedFatDxe/ReadWrite.c index 4621817c93..ad3c260412 100644 --- a/FatPkg/EnhancedFatDxe/ReadWrite.c +++ b/FatPkg/EnhancedFatDxe/ReadWrite.c @@ -1,6 +1,7 @@ -/*++ +/** @file + Functions that perform file read/write. -Copyright (c) 2005 - 2013, Intel Corporation. All rights reserved.
+Copyright (c) 2005 - 2017, 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,44 +11,29 @@ 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: +**/ - ReadWrite.c +#include "Fat.h" -Abstract: +/** - Functions that perform file read/write + Get the file's position of the file. -Revision History ---*/ + @param FHand - The handle of file. + @param Position - The file's position of the file. -#include "Fat.h" + @retval EFI_SUCCESS - Get the info successfully. + @retval EFI_DEVICE_ERROR - Can not find the OFile for the file. + @retval EFI_UNSUPPORTED - The open file is not a file. +**/ EFI_STATUS EFIAPI FatGetPosition ( IN EFI_FILE_PROTOCOL *FHand, OUT UINT64 *Position ) -/*++ - -Routine Description: - - Get the file's position of the file. - -Arguments: - - FHand - The handle of file. - Position - The file's position of the file. - -Returns: - - EFI_SUCCESS - Get the info successfully. - EFI_DEVICE_ERROR - Can not find the OFile for the file. - EFI_UNSUPPORTED - The open file is not a file. - ---*/ { FAT_IFILE *IFile; FAT_OFILE *OFile; @@ -67,30 +53,24 @@ Returns: return EFI_SUCCESS; } +/** + + Set the file's position of the file. + + @param FHand - The handle of file. + @param Position - The file's position of the file. + + @retval EFI_SUCCESS - Set the info successfully. + @retval EFI_DEVICE_ERROR - Can not find the OFile for the file. + @retval EFI_UNSUPPORTED - Set a directory with a not-zero position. + +**/ EFI_STATUS EFIAPI FatSetPosition ( IN EFI_FILE_PROTOCOL *FHand, IN UINT64 Position ) -/*++ - -Routine Description: - - Set the file's position of the file. - -Arguments: - - FHand - The handle of file. - Position - The file's position of the file. - -Returns: - - EFI_SUCCESS - Set the info successfully. - EFI_DEVICE_ERROR - Can not find the OFile for the file. - EFI_UNSUPPORTED - Set a directory with a not-zero position. - ---*/ { FAT_IFILE *IFile; FAT_OFILE *OFile; @@ -130,30 +110,24 @@ Returns: return EFI_SUCCESS; } +/** + + Get the file info from the open file of the IFile into Buffer. + + @param IFile - The instance of the open file. + @param BufferSize - Size of Buffer. + @param Buffer - Buffer containing read data. + + @retval EFI_SUCCESS - Get the file info successfully. + @retval other - An error occurred when operation the disk. + +**/ EFI_STATUS FatIFileReadDir ( IN FAT_IFILE *IFile, IN OUT UINTN *BufferSize, OUT VOID *Buffer ) -/*++ - -Routine Description: - - Get the file info from the open file of the IFile into Buffer. - -Arguments: - - IFile - The instance of the open file. - BufferSize - Size of Buffer. - Buffer - Buffer containing read data. - -Returns: - - EFI_SUCCESS - Get the file info successfully. - other - An error occurred when operation the disk. - ---*/ { EFI_STATUS Status; FAT_OFILE *OFile; @@ -199,12 +173,30 @@ Done: // Update IFile->Position, if everything is all right // CurrentPos = ODir->CurrentPos; - IFile->Position = (UINT64) (CurrentPos * sizeof (FAT_DIRECTORY_ENTRY)); + IFile->Position = CurrentPos * sizeof (FAT_DIRECTORY_ENTRY); } return Status; } +/** + + Get the file info from the open file of the IFile into Buffer. + + @param FHand - The file handle to access. + @param IoMode - Indicate whether the access mode is reading or writing. + @param BufferSize - Size of Buffer. + @param Buffer - Buffer containing read data. + @param Token - A pointer to the token associated with the transaction. + + @retval EFI_SUCCESS - Get the file info successfully. + @retval EFI_DEVICE_ERROR - Can not find the OFile for the file. + @retval EFI_VOLUME_CORRUPTED - The file type of open file is error. + @retval EFI_WRITE_PROTECTED - The disk is write protect. + @retval EFI_ACCESS_DENIED - The file is read-only. + @return other - An error occurred when operating on the disk. + +**/ EFI_STATUS FatIFileAccess ( IN EFI_FILE_PROTOCOL *FHand, @@ -213,30 +205,6 @@ FatIFileAccess ( IN OUT VOID *Buffer, IN EFI_FILE_IO_TOKEN *Token ) -/*++ - -Routine Description: - - Get the file info from the open file of the IFile into Buffer. - -Arguments: - - FHand - The file handle to access. - IoMode - Indicate whether the access mode is reading or writing. - BufferSize - Size of Buffer. - Buffer - Buffer containing read data. - Token - A pointer to the token associated with the transaction. - -Returns: - - EFI_SUCCESS - Get the file info successfully. - EFI_DEVICE_ERROR - Can not find the OFile for the file. - EFI_VOLUME_CORRUPTED - The file type of open file is error. - EFI_WRITE_PROTECTED - The disk is write protect. - EFI_ACCESS_DENIED - The file is read-only. - other - An error occurred when operating on the disk. - ---*/ { EFI_STATUS Status; FAT_IFILE *IFile; @@ -250,11 +218,18 @@ Returns: Volume = OFile->Volume; Task = NULL; + // + // Write to a directory is unsupported + // + if ((OFile->ODir != NULL) && (IoMode == WriteData)) { + return EFI_UNSUPPORTED; + } + if (OFile->Error == EFI_NOT_FOUND) { return EFI_DEVICE_ERROR; } - if (IoMode == READ_DATA) { + if (IoMode == ReadData) { // // If position is at EOF, then return device error // @@ -296,16 +271,10 @@ Returns: if (!EFI_ERROR (Status)) { if (OFile->ODir != NULL) { // - // Access a directory + // Read a directory is supported // - Status = EFI_UNSUPPORTED; - if (IoMode == READ_DATA) { - // - // Read a directory is supported - // - Status = FatIFileReadDir (IFile, BufferSize, Buffer); - } - + ASSERT (IoMode == ReadData); + Status = FatIFileReadDir (IFile, BufferSize, Buffer); OFile = NULL; } else { // @@ -316,7 +285,7 @@ Returns: // // The position goes beyond the end of file // - if (IoMode == READ_DATA) { + if (IoMode == ReadData) { // // Adjust the actual size read // @@ -372,6 +341,21 @@ Done: return Status; } +/** + + Get the file info. + + @param FHand - The handle of the file. + @param BufferSize - Size of Buffer. + @param Buffer - Buffer containing read data. + + + @retval EFI_SUCCESS - Get the file info successfully. + @retval EFI_DEVICE_ERROR - Can not find the OFile for the file. + @retval EFI_VOLUME_CORRUPTED - The file type of open file is error. + @return other - An error occurred when operation the disk. + +**/ EFI_STATUS EFIAPI FatRead ( @@ -379,59 +363,50 @@ FatRead ( IN OUT UINTN *BufferSize, OUT VOID *Buffer ) -/*++ +{ + return FatIFileAccess (FHand, ReadData, BufferSize, Buffer, NULL); +} -Routine Description: +/** Get the file info. -Arguments: - - FHand - The handle of the file. - BufferSize - Size of Buffer. - Buffer - Buffer containing read data. - -Returns: + @param FHand - The handle of the file. + @param Token - A pointer to the token associated with the transaction. - EFI_SUCCESS - Get the file info successfully. - EFI_DEVICE_ERROR - Can not find the OFile for the file. - EFI_VOLUME_CORRUPTED - The file type of open file is error. - other - An error occurred when operation the disk. - ---*/ -{ - return FatIFileAccess (FHand, READ_DATA, BufferSize, Buffer, NULL); -} + @retval EFI_SUCCESS - Get the file info successfully. + @retval EFI_DEVICE_ERROR - Can not find the OFile for the file. + @retval EFI_VOLUME_CORRUPTED - The file type of open file is error. + @return other - An error occurred when operation the disk. +**/ EFI_STATUS EFIAPI FatReadEx ( IN EFI_FILE_PROTOCOL *FHand, IN OUT EFI_FILE_IO_TOKEN *Token ) -/*++ - -Routine Description: - - Get the file info. - -Arguments: +{ + return FatIFileAccess (FHand, ReadData, &Token->BufferSize, Token->Buffer, Token); +} - FHand - The handle of the file. - Token - A pointer to the token associated with the transaction. +/** -Returns: + Write the content of buffer into files. - EFI_SUCCESS - Get the file info successfully. - EFI_DEVICE_ERROR - Can not find the OFile for the file. - EFI_VOLUME_CORRUPTED - The file type of open file is error. - other - An error occurred when operation the disk. + @param FHand - The handle of the file. + @param BufferSize - Size of Buffer. + @param Buffer - Buffer containing write data. ---*/ -{ - return FatIFileAccess (FHand, READ_DATA, &Token->BufferSize, Token->Buffer, Token); -} + @retval EFI_SUCCESS - Set the file info successfully. + @retval EFI_WRITE_PROTECTED - The disk is write protect. + @retval EFI_ACCESS_DENIED - The file is read-only. + @retval EFI_DEVICE_ERROR - The OFile is not valid. + @retval EFI_UNSUPPORTED - The open file is not a file. + - The writing file size is larger than 4GB. + @return other - An error occurred when operation the disk. +**/ EFI_STATUS EFIAPI FatWrite ( @@ -439,62 +414,49 @@ FatWrite ( IN OUT UINTN *BufferSize, IN VOID *Buffer ) -/*++ - -Routine Description: - - Write the content of buffer into files. +{ + return FatIFileAccess (FHand, WriteData, BufferSize, Buffer, NULL); +} -Arguments: +/** - FHand - The handle of the file. - BufferSize - Size of Buffer. - Buffer - Buffer containing write data. + Get the file info. -Returns: + @param FHand - The handle of the file. + @param Token - A pointer to the token associated with the transaction. - EFI_SUCCESS - Set the file info successfully. - EFI_WRITE_PROTECTED - The disk is write protect. - EFI_ACCESS_DENIED - The file is read-only. - EFI_DEVICE_ERROR - The OFile is not valid. - EFI_UNSUPPORTED - The open file is not a file. - - The writing file size is larger than 4GB. - other - An error occurred when operation the disk. - ---*/ -{ - return FatIFileAccess (FHand, WRITE_DATA, BufferSize, Buffer, NULL); -} + @retval EFI_SUCCESS - Get the file info successfully. + @retval EFI_DEVICE_ERROR - Can not find the OFile for the file. + @retval EFI_VOLUME_CORRUPTED - The file type of open file is error. + @return other - An error occurred when operation the disk. +**/ EFI_STATUS EFIAPI FatWriteEx ( IN EFI_FILE_PROTOCOL *FHand, IN OUT EFI_FILE_IO_TOKEN *Token ) -/*++ - -Routine Description: - - Get the file info. - -Arguments: +{ + return FatIFileAccess (FHand, WriteData, &Token->BufferSize, Token->Buffer, Token); +} - FHand - The handle of the file. - Token - A pointer to the token associated with the transaction. +/** -Returns: + This function reads data from a file or writes data to a file. + It uses OFile->PosRem to determine how much data can be accessed in one time. - EFI_SUCCESS - Get the file info successfully. - EFI_DEVICE_ERROR - Can not find the OFile for the file. - EFI_VOLUME_CORRUPTED - The file type of open file is error. - other - An error occurred when operation the disk. + @param OFile - The open file. + @param IoMode - Indicate whether the access mode is reading or writing. + @param Position - The position where data will be accessed. + @param DataBufferSize - Size of Buffer. + @param UserBuffer - Buffer containing data. + @param Task point to task instance. ---*/ -{ - return FatIFileAccess (FHand, WRITE_DATA, &Token->BufferSize, Token->Buffer, Token); -} + @retval EFI_SUCCESS - Access the data successfully. + @return other - An error occurred when operating on the disk. +**/ EFI_STATUS FatAccessOFile ( IN FAT_OFILE *OFile, @@ -504,27 +466,6 @@ FatAccessOFile ( IN OUT UINT8 *UserBuffer, IN FAT_TASK *Task ) -/*++ - -Routine Description: - - This function reads data from a file or writes data to a file. - It uses OFile->PosRem to determine how much data can be accessed in one time. - -Arguments: - - OFile - The open file. - IoMode - Indicate whether the access mode is reading or writing. - Position - The position where data will be accessed. - DataBufferSize - Size of Buffer. - UserBuffer - Buffer containing data. - -Returns: - - EFI_SUCCESS - Access the data successfully. - other - An error occurred when operating on the disk. - ---*/ { FAT_VOLUME *Volume; UINTN Len; @@ -562,7 +503,7 @@ Returns: Position += Len; UserBuffer += Len; BufferSize -= Len; - if (IoMode == WRITE_DATA) { + if (IoMode == WriteData) { OFile->Dirty = TRUE; OFile->Archive = TRUE; } @@ -578,28 +519,22 @@ Returns: return Status; } -EFI_STATUS -FatExpandOFile ( - IN FAT_OFILE *OFile, - IN UINT64 ExpandedSize - ) -/*++ - -Routine Description: +/** Expand OFile by appending zero bytes at the end of OFile. -Arguments: - - OFile - The open file. - ExpandedSize - The number of zero bytes appended at the end of the file. + @param OFile - The open file. + @param ExpandedSize - The number of zero bytes appended at the end of the file. -Returns: + @retval EFI_SUCCESS - The file is expanded successfully. + @return other - An error occurred when expanding file. - EFI_SUCCESS - The file is expanded successfully. - other - An error occurred when expanding file. - ---*/ +**/ +EFI_STATUS +FatExpandOFile ( + IN FAT_OFILE *OFile, + IN UINT64 ExpandedSize + ) { EFI_STATUS Status; UINTN WritePos; @@ -613,29 +548,23 @@ Returns: return Status; } -EFI_STATUS -FatWriteZeroPool ( - IN FAT_OFILE *OFile, - IN UINTN WritePos - ) -/*++ - -Routine Description: +/** Write zero pool from the WritePos to the end of OFile. -Arguments: - - OFile - The open file to write zero pool. - WritePos - The number of zero bytes written. - -Returns: + @param OFile - The open file to write zero pool. + @param WritePos - The number of zero bytes written. - EFI_SUCCESS - Write the zero pool successfully. - EFI_OUT_OF_RESOURCES - Not enough memory to perform the operation. - other - An error occurred when writing disk. + @retval EFI_SUCCESS - Write the zero pool successfully. + @retval EFI_OUT_OF_RESOURCES - Not enough memory to perform the operation. + @return other - An error occurred when writing disk. ---*/ +**/ +EFI_STATUS +FatWriteZeroPool ( + IN FAT_OFILE *OFile, + IN UINTN WritePos + ) { EFI_STATUS Status; VOID *ZeroBuffer; @@ -663,7 +592,7 @@ Returns: do { WriteSize = AppendedSize > BufferSize ? BufferSize : (UINTN) AppendedSize; AppendedSize -= WriteSize; - Status = FatAccessOFile (OFile, WRITE_DATA, WritePos, &WriteSize, ZeroBuffer, NULL); + Status = FatAccessOFile (OFile, WriteData, WritePos, &WriteSize, ZeroBuffer, NULL); if (EFI_ERROR (Status)) { break; } @@ -675,28 +604,22 @@ Returns: return Status; } -EFI_STATUS -FatTruncateOFile ( - IN FAT_OFILE *OFile, - IN UINTN TruncatedSize - ) -/*++ - -Routine Description: +/** Truncate the OFile to smaller file size. -Arguments: - - OFile - The open file. - TruncatedSize - The new file size. + @param OFile - The open file. + @param TruncatedSize - The new file size. -Returns: + @retval EFI_SUCCESS - The file is truncated successfully. + @return other - An error occurred when truncating file. - EFI_SUCCESS - The file is truncated successfully. - other - An error occurred when truncating file. - ---*/ +**/ +EFI_STATUS +FatTruncateOFile ( + IN FAT_OFILE *OFile, + IN UINTN TruncatedSize + ) { OFile->FileSize = TruncatedSize; return FatShrinkEof (OFile);