+++ /dev/null
-/**@file\r
-Copyright (c) 2007 - 2009, Intel Corporation. All rights reserved.<BR>\r
-This program and the accompanying materials\r
-are licensed and made available under the terms and conditions of the BSD License\r
-which accompanies this distribution. The full text of the license may be found at\r
-http://opensource.org/licenses/bsd-license.php\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
-Module Name:\r
-\r
- FileIo.c\r
-\r
-Abstract:\r
-\r
- File operation for Firmware volume block driver\r
-\r
-**/\r
-#include "FileIo.h"\r
-\r
-//\r
-// Variable storage hot plug is supported but there are still some restrictions:\r
-// After plugging the storage back,\r
-// 1. Still use memory as NV if newly plugged storage is not same as the original one\r
-// 2. Still use memory as NV if there are some update operation during storage is unplugged.\r
-//\r
-\r
-\r
-EFI_STATUS\r
-FileWrite (\r
- IN EFI_FILE_PROTOCOL *File,\r
- IN UINTN Offset,\r
- IN UINTN Buffer,\r
- IN UINTN Size\r
- )\r
-{\r
- EFI_STATUS Status;\r
-\r
- Status = File->SetPosition (File, Offset);\r
- ASSERT_EFI_ERROR (Status);\r
- if (!EFI_ERROR (Status)) {\r
- Status = File->Write (File, &Size, (VOID *) Buffer);\r
- ASSERT_EFI_ERROR (Status);\r
- }\r
- return Status;\r
-}\r
-\r
-EFI_STATUS\r
-CheckStore (\r
- IN EFI_HANDLE SimpleFileSystemHandle,\r
- IN UINT32 VolumeId,\r
- OUT EFI_DEVICE_PATH_PROTOCOL **Device\r
- )\r
-{\r
-#define BLOCK_SIZE 0x200\r
-#define FAT16_VOLUME_ID_OFFSET 39\r
-#define FAT32_VOLUME_ID_OFFSET 67\r
- EFI_STATUS Status;\r
- EFI_BLOCK_IO_PROTOCOL *BlkIo;\r
- UINT8 BootSector[BLOCK_SIZE];\r
-\r
- *Device = NULL;\r
- Status = gBS->HandleProtocol (\r
- SimpleFileSystemHandle,\r
- &gEfiBlockIoProtocolGuid, // BlockIo should be supported if it supports SimpleFileSystem\r
- (VOID*)&BlkIo\r
- );\r
-\r
- if (EFI_ERROR (Status)) {\r
- goto ErrHandle;\r
- }\r
- if (!BlkIo->Media->MediaPresent) {\r
- DEBUG ((EFI_D_ERROR, "FwhMappedFile: Media not present!\n"));\r
- Status = EFI_NO_MEDIA;\r
- goto ErrHandle;\r
- }\r
- if (BlkIo->Media->ReadOnly) {\r
- DEBUG ((EFI_D_ERROR, "FwhMappedFile: Media is read-only!\n"));\r
- Status = EFI_ACCESS_DENIED;\r
- goto ErrHandle;\r
- }\r
-\r
- Status = BlkIo->ReadBlocks(\r
- BlkIo,\r
- BlkIo->Media->MediaId,\r
- 0,\r
- BLOCK_SIZE,\r
- BootSector\r
- );\r
- ASSERT_EFI_ERROR (Status);\r
- if ((*(UINT32 *) &BootSector[FAT16_VOLUME_ID_OFFSET] != VolumeId) &&\r
- (*(UINT32 *) &BootSector[FAT32_VOLUME_ID_OFFSET] != VolumeId)\r
- ) {\r
- Status = EFI_NOT_FOUND;\r
- goto ErrHandle;\r
- }\r
-\r
- *Device = DuplicateDevicePath (DevicePathFromHandle (SimpleFileSystemHandle));\r
- ASSERT (*Device != NULL);\r
-\r
-ErrHandle:\r
- return Status;\r
-}\r
-\r
-EFI_STATUS\r
-CheckStoreExists (\r
- IN EFI_DEVICE_PATH_PROTOCOL *Device\r
- )\r
-{\r
- EFI_HANDLE Handle;\r
- EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *Volume;\r
- EFI_STATUS Status;\r
-\r
- Status = gBS->LocateDevicePath (\r
- &gEfiSimpleFileSystemProtocolGuid,\r
- &Device, \r
- &Handle\r
- );\r
-\r
- if (EFI_ERROR (Status)) {\r
- return Status;\r
- }\r
-\r
- Status = gBS->HandleProtocol (\r
- Handle,\r
- &gEfiSimpleFileSystemProtocolGuid,\r
- &Volume\r
- );\r
- if (EFI_ERROR (Status)) {\r
- return Status;\r
- }\r
-\r
- return EFI_SUCCESS;\r
-}\r
-\r
-VOID\r
-FileClose (\r
- IN EFI_FILE_PROTOCOL *File\r
- )\r
-{\r
- File->Flush (File);\r
- File->Close (File);\r
-}\r
-EFI_STATUS\r
-FileOpen (\r
- IN EFI_DEVICE_PATH_PROTOCOL *Device,\r
- IN CHAR16 *MappedFile,\r
- OUT EFI_FILE_PROTOCOL **File,\r
- IN UINT64 OpenMode\r
- )\r
-{ \r
- EFI_HANDLE Handle;\r
- EFI_FILE_HANDLE Root;\r
- EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *Volume;\r
- EFI_STATUS Status;\r
-\r
- *File = NULL;\r
-\r
- Status = gBS->LocateDevicePath (\r
- &gEfiSimpleFileSystemProtocolGuid,\r
- &Device, \r
- &Handle\r
- );\r
-\r
- if (EFI_ERROR (Status)) {\r
- return Status;\r
- }\r
-\r
- Status = gBS->HandleProtocol (\r
- Handle,\r
- &gEfiSimpleFileSystemProtocolGuid,\r
- &Volume\r
- );\r
- ASSERT_EFI_ERROR (Status);\r
- if (EFI_ERROR (Status)) {\r
- return Status;\r
- }\r
- \r
- //\r
- // Open the root directory of the volume\r
- //\r
- Root = NULL;\r
- Status = Volume->OpenVolume (\r
- Volume,\r
- &Root\r
- );\r
- ASSERT_EFI_ERROR (Status);\r
- ASSERT (Root != NULL);\r
-\r
- //\r
- // Open file\r
- //\r
- Status = Root->Open (\r
- Root,\r
- File,\r
- MappedFile,\r
- OpenMode,\r
- 0\r
- );\r
- if (EFI_ERROR (Status)) {\r
- *File = NULL;\r
- }\r
-\r
- //\r
- // Close the Root directory\r
- //\r
- Root->Close (Root);\r
- return Status;\r
-}\r