X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=Nt32Pkg%2FWinNtBlockIoDxe%2FWinNtBlockIo.c;h=12924e659fbab77db9475d748767c5e8aebd792f;hp=291f7a08e2ec582160192cfe7ee1012246075651;hb=04492de53f40bb756b521d2a35744b38e08bc2a5;hpb=a00ec39b52224a40bf9a0a813b69cb43e14407a8 diff --git a/Nt32Pkg/WinNtBlockIoDxe/WinNtBlockIo.c b/Nt32Pkg/WinNtBlockIoDxe/WinNtBlockIo.c index 291f7a08e2..12924e659f 100644 --- a/Nt32Pkg/WinNtBlockIoDxe/WinNtBlockIo.c +++ b/Nt32Pkg/WinNtBlockIoDxe/WinNtBlockIo.c @@ -1,7 +1,7 @@ /**@file -Copyright (c) 2006 - 2007, Intel Corporation -All rights reserved. This program and the accompanying materials +Copyright (c) 2006 - 2013, 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 http://opensource.org/licenses/bsd-license.php @@ -972,8 +972,10 @@ WinNtBlockIoWriteBlocks ( WIN_NT_BLOCK_IO_PRIVATE *Private; UINTN BytesWritten; BOOL Flag; + BOOL Locked; EFI_STATUS Status; EFI_TPL OldTpl; + UINTN BytesReturned; OldTpl = gBS->RaiseTPL (TPL_CALLBACK); @@ -984,7 +986,24 @@ WinNtBlockIoWriteBlocks ( goto Done; } + // + // According the Windows requirement, first need to lock the volume before + // write to it. + // + if (Private->DeviceType == EfiWinNtPhysicalDisks) { + Locked = Private->WinNtThunk->DeviceIoControl (Private->NtHandle, FSCTL_LOCK_VOLUME, NULL, 0, NULL, 0, &BytesReturned, NULL); + if (Locked == 0) { + DEBUG ((EFI_D_INIT, "ReadBlocks: Lock volume failed. (%d)\n", Private->WinNtThunk->GetLastError ())); + Status = WinNtBlockIoError (Private); + goto Done; + } + } else { + Locked = 0; + } Flag = Private->WinNtThunk->WriteFile (Private->NtHandle, Buffer, (DWORD) BufferSize, (LPDWORD) &BytesWritten, NULL); + if (Locked != 0) { + Private->WinNtThunk->DeviceIoControl (Private->NtHandle, FSCTL_UNLOCK_VOLUME, NULL, 0, NULL, 0, &BytesReturned, NULL); + } if (!Flag || (BytesWritten != BufferSize)) { DEBUG ((EFI_D_INIT, "ReadBlocks: WriteFile failed. (%d)\n", Private->WinNtThunk->GetLastError ())); Status = WinNtBlockIoError (Private);