10#define WIN_NT_BLOCK_IO_PRIVATE_SIGNATURE SIGNATURE_32 ('N', 'T', 'b', 'k')
27#define WIN_NT_BLOCK_IO_PRIVATE_DATA_FROM_THIS(a) \
28 CR(a, WIN_NT_BLOCK_IO_PRIVATE, EmuBlockIo, WIN_NT_BLOCK_IO_PRIVATE_SIGNATURE)
33 IN BOOLEAN ExtendedVerification
39 IN INT64 DistanceToMove,
40 OUT UINT64 *NewFilePointer,
51 LARGE_INTEGER LargeInt;
53 LargeInt.QuadPart = DistanceToMove;
56 LargeInt.LowPart = SetFilePointer (
63 if ((LargeInt.LowPart == -1) && (GetLastError () != NO_ERROR)) {
64 Status = EFI_INVALID_PARAMETER;
67 if (NewFilePointer !=
NULL) {
68 *NewFilePointer = LargeInt.QuadPart;
75WinNtBlockIoOpenDevice (
86 if (Private->NtHandle != INVALID_HANDLE_VALUE) {
93 Private->NtHandle = CreateFile (
95 GENERIC_READ | (Private->Readonly ? 0 : GENERIC_WRITE),
96 FILE_SHARE_READ | FILE_SHARE_WRITE,
103 if (Private->NtHandle == INVALID_HANDLE_VALUE) {
104 DEBUG ((DEBUG_INFO,
"OpenBlock: Could not open %S, %x\n", Private->FileName, GetLastError ()));
105 Media->MediaPresent =
FALSE;
106 Status = EFI_NO_MEDIA;
113 Status = SetFilePointer64 (Private, 0, &FileSize, FILE_END);
115 if (EFI_ERROR (Status)) {
116 DEBUG ((DEBUG_ERROR,
"OpenBlock: Could not get filesize of %s\n", Private->FileName));
117 Status = EFI_UNSUPPORTED;
121 Media->LastBlock =
DivU64x32 (FileSize, (UINT32)Private->BlockSize) - 1;
123 DEBUG ((DEBUG_INIT,
"OpenBlock: opened %S\n", Private->FileName));
127 if (EFI_ERROR (Status)) {
128 if (Private->NtHandle != INVALID_HANDLE_VALUE) {
138WinNtBlockIoCreateMapping (
145 Private = WIN_NT_BLOCK_IO_PRIVATE_DATA_FROM_THIS (This);
148 Media->RemovableMedia = Private->Removable;
149 Media->MediaPresent =
TRUE;
150 Media->LogicalPartition =
FALSE;
151 Media->ReadOnly = Private->Readonly;
152 Media->WriteCaching =
FALSE;
154 Media->LastBlock = 0;
155 Media->BlockSize = Private->BlockSize;
158 Media->LowestAlignedLba = 0;
159 Media->LogicalBlocksPerPhysicalBlock = 0;
162 Media->OptimalTransferLengthGranularity = 0;
167 Private->Media = Media;
168 return WinNtBlockIoOpenDevice (Private, Media);
195 Media = Private->Media;
197 switch (GetLastError ()) {
198 case ERROR_NOT_READY:
201 Status = EFI_NO_MEDIA;
204 case ERROR_WRONG_DISK:
208 Status = EFI_MEDIA_CHANGED;
211 case ERROR_WRITE_PROTECT:
213 Status = EFI_WRITE_PROTECTED;
217 Status = EFI_DEVICE_ERROR;
221 if ((Status == EFI_NO_MEDIA) || (Status == EFI_MEDIA_CHANGED)) {
235 if (Token->Event !=
NULL) {
237 Token->TransactionStatus = Status;
292 UINT64 DistanceToMove;
293 UINT64 DistanceMoved;
295 Private = WIN_NT_BLOCK_IO_PRIVATE_DATA_FROM_THIS (This);
300 DistanceToMove =
MultU64x32 (Lba, (UINT32)Private->BlockSize);
301 Status = SetFilePointer64 (Private, DistanceToMove, &DistanceMoved, FILE_BEGIN);
303 if (EFI_ERROR (Status) || (DistanceToMove != DistanceMoved)) {
304 DEBUG ((DEBUG_INIT,
"ReadBlocks: SetFilePointer failed\n"));
305 return WinNtBlockIoError (Private->Media);
308 Flag =
ReadFile (Private->NtHandle, Buffer, (DWORD)BufferSize, (LPDWORD)&BytesRead,
NULL);
309 if (!Flag || (BytesRead != BufferSize)) {
310 return WinNtBlockIoError (Private->Media);
362 UINT64 DistanceToMove;
363 UINT64 DistanceMoved;
365 Private = WIN_NT_BLOCK_IO_PRIVATE_DATA_FROM_THIS (This);
370 DistanceToMove =
MultU64x32 (Lba, (UINT32)Private->BlockSize);
371 Status = SetFilePointer64 (Private, DistanceToMove, &DistanceMoved, FILE_BEGIN);
373 if (EFI_ERROR (Status) || (DistanceToMove != DistanceMoved)) {
374 DEBUG ((DEBUG_INIT,
"WriteBlocks: SetFilePointer failed\n"));
375 return WinNtBlockIoError (Private->Media);
378 Success = WriteFile (Private->NtHandle, Buffer, (DWORD)BufferSize, (LPDWORD)&BytesWritten,
NULL);
379 if (!Success || (BytesWritten != BufferSize)) {
380 return WinNtBlockIoError (Private->Media);
438 IN BOOLEAN ExtendedVerification
443 Private = WIN_NT_BLOCK_IO_PRIVATE_DATA_FROM_THIS (This);
445 if (Private->NtHandle != INVALID_HANDLE_VALUE) {
446 CloseHandle (Private->NtHandle);
447 Private->NtHandle = INVALID_HANDLE_VALUE;
458 WinNtBlockIoCreateMapping
463WinNtBlockIoThunkOpen (
471 if (Private ==
NULL) {
472 return EFI_OUT_OF_RESOURCES;
475 Private->Signature = WIN_NT_BLOCK_IO_PRIVATE_SIGNATURE;
476 Private->Thunk = This;
477 CopyMem (&Private->EmuBlockIo, &gEmuBlockIoProtocol, sizeof (gEmuBlockIoProtocol));
478 Private->BlockSize = 512;
479 Private->NtHandle = INVALID_HANDLE_VALUE;
482 if (Private->FileName ==
NULL) {
483 return EFI_OUT_OF_RESOURCES;
490 Str =
StrStr (Private->FileName, L
":");
492 Private->Removable =
FALSE;
493 Private->Readonly =
FALSE;
495 for (*Str++ = L
'\0'; *Str != L
'\0'; Str++) {
496 if ((*Str ==
'R') || (*Str ==
'F')) {
497 Private->Removable = (BOOLEAN)(*Str == L
'R');
500 if ((*Str ==
'O') || (*Str ==
'W')) {
501 Private->Readonly = (BOOLEAN)(*Str == L
'O');
505 Private->BlockSize = wcstol (++Str,
NULL, 0);
511 This->Interface = &Private->EmuBlockIo;
512 This->Private = Private;
518WinNtBlockIoThunkClose (
524 Private = This->Private;
526 if (Private !=
NULL) {
527 if (Private->FileName !=
NULL) {
538 &gEmuBlockIoProtocolGuid,
542 WinNtBlockIoThunkOpen,
543 WinNtBlockIoThunkClose,
UINTN EFIAPI StrSize(IN CONST CHAR16 *String)
UINT64 EFIAPI DivU64x32(IN UINT64 Dividend, IN UINT32 Divisor)
UINT64 EFIAPI MultU64x32(IN UINT64 Multiplicand, IN UINT32 Multiplier)
CHAR16 *EFIAPI StrStr(IN CONST CHAR16 *String, IN CONST CHAR16 *SearchString)
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
VOID EFIAPI FreePool(IN VOID *Buffer)
VOID *EFIAPI AllocateCopyPool(IN UINTN AllocationSize, IN CONST VOID *Buffer)
EFI_STATUS ReadFile(IN EFI_BLOCK_IO_PROTOCOL *BlockIo, IN EFI_DISK_IO_PROTOCOL *DiskIo, IN UDF_VOLUME_INFO *Volume, IN UDF_LONG_ALLOCATION_DESCRIPTOR *ParentIcb, IN VOID *FileEntryData, IN OUT UDF_READ_FILE_INFO *ReadFileInfo)
#define DEBUG(Expression)
VOID *EFIAPI AllocatePool(IN UINTN AllocationSize)
EFI_STATUS WinNtBlockIoFlushBlocks(IN EMU_BLOCK_IO_PROTOCOL *This, IN OUT EFI_BLOCK_IO2_TOKEN *Token)
EFI_STATUS WinNtBlockIoWriteBlocks(IN EMU_BLOCK_IO_PROTOCOL *This, IN UINT32 MediaId, IN EFI_LBA Lba, IN OUT EFI_BLOCK_IO2_TOKEN *Token, IN UINTN BufferSize, IN VOID *Buffer)
EFI_STATUS WinNtBlockIoReset(IN EMU_BLOCK_IO_PROTOCOL *This, IN BOOLEAN ExtendedVerification)
EFI_STATUS WinNtBlockIoReadBlocks(IN EMU_BLOCK_IO_PROTOCOL *This, IN UINT32 MediaId, IN EFI_LBA Lba, IN OUT EFI_BLOCK_IO2_TOKEN *Token, IN UINTN BufferSize, OUT VOID *Buffer)