2 Copyright (c) 2007 - 2009, Intel Corporation
3 All rights reserved. This program and the accompanying materials
4 are licensed and made available under the terms and conditions of the BSD License
5 which accompanies this distribution. The full text of the license may be found at
6 http://opensource.org/licenses/bsd-license.php
8 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
9 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
17 File operation for Firmware volume block driver
23 // Variable storage hot plug is supported but there are still some restrictions:
24 // After plugging the storage back,
25 // 1. Still use memory as NV if newly plugged storage is not same as the original one
26 // 2. Still use memory as NV if there are some update operation during storage is unplugged.
32 IN EFI_FILE_PROTOCOL
*File
,
40 Status
= File
->SetPosition (File
, Offset
);
41 ASSERT_EFI_ERROR (Status
);
42 if (!EFI_ERROR (Status
)) {
43 Status
= File
->Write (File
, &Size
, (VOID
*) Buffer
);
44 ASSERT_EFI_ERROR (Status
);
51 IN EFI_HANDLE SimpleFileSystemHandle
,
53 OUT EFI_DEVICE_PATH_PROTOCOL
**Device
56 #define BLOCK_SIZE 0x200
57 #define FAT16_VOLUME_ID_OFFSET 39
58 #define FAT32_VOLUME_ID_OFFSET 67
60 EFI_BLOCK_IO_PROTOCOL
*BlkIo
;
61 UINT8 BootSector
[BLOCK_SIZE
];
64 Status
= gBS
->HandleProtocol (
65 SimpleFileSystemHandle
,
66 &gEfiBlockIoProtocolGuid
, // BlockIo should be supported if it supports SimpleFileSystem
70 if (EFI_ERROR (Status
)) {
73 if (!BlkIo
->Media
->MediaPresent
) {
74 DEBUG ((EFI_D_ERROR
, "FwhMappedFile: Media not present!\n"));
75 Status
= EFI_NO_MEDIA
;
78 if (BlkIo
->Media
->ReadOnly
) {
79 DEBUG ((EFI_D_ERROR
, "FwhMappedFile: Media is read-only!\n"));
80 Status
= EFI_ACCESS_DENIED
;
84 Status
= BlkIo
->ReadBlocks(
86 BlkIo
->Media
->MediaId
,
91 ASSERT_EFI_ERROR (Status
);
92 if ((*(UINT32
*) &BootSector
[FAT16_VOLUME_ID_OFFSET
] != VolumeId
) &&
93 (*(UINT32
*) &BootSector
[FAT32_VOLUME_ID_OFFSET
] != VolumeId
)
95 Status
= EFI_NOT_FOUND
;
99 *Device
= DuplicateDevicePath (DevicePathFromHandle (SimpleFileSystemHandle
));
100 ASSERT (*Device
!= NULL
);
108 IN EFI_DEVICE_PATH_PROTOCOL
*Device
112 EFI_SIMPLE_FILE_SYSTEM_PROTOCOL
*Volume
;
115 Status
= gBS
->LocateDevicePath (
116 &gEfiSimpleFileSystemProtocolGuid
,
121 if (EFI_ERROR (Status
)) {
125 Status
= gBS
->HandleProtocol (
127 &gEfiSimpleFileSystemProtocolGuid
,
130 if (EFI_ERROR (Status
)) {
139 IN EFI_FILE_PROTOCOL
*File
147 IN EFI_DEVICE_PATH_PROTOCOL
*Device
,
148 IN CHAR16
*MappedFile
,
149 OUT EFI_FILE_PROTOCOL
**File
,
154 EFI_FILE_HANDLE Root
;
155 EFI_SIMPLE_FILE_SYSTEM_PROTOCOL
*Volume
;
160 Status
= gBS
->LocateDevicePath (
161 &gEfiSimpleFileSystemProtocolGuid
,
166 if (EFI_ERROR (Status
)) {
170 Status
= gBS
->HandleProtocol (
172 &gEfiSimpleFileSystemProtocolGuid
,
175 ASSERT_EFI_ERROR (Status
);
176 if (EFI_ERROR (Status
)) {
181 // Open the root directory of the volume
184 Status
= Volume
->OpenVolume (
188 ASSERT_EFI_ERROR (Status
);
189 ASSERT (Root
!= NULL
);
194 Status
= Root
->Open (
201 if (EFI_ERROR (Status
)) {
206 // Close the Root directory