From 21e3aefed2b24a3875a2d056164e46677089e4bb Mon Sep 17 00:00:00 2001 From: ydong10 Date: Wed, 15 Feb 2012 02:40:18 +0000 Subject: Enable write file to USB from Shell in Win7 OS Signed-off-by: ydong10 Reviewed-by: niruiyu git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@13013 6f19259b-4bc3-4df7-8a09-765794883524 --- Nt32Pkg/WinNtBlockIoDxe/WinNtBlockIo.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'Nt32Pkg') diff --git a/Nt32Pkg/WinNtBlockIoDxe/WinNtBlockIo.c b/Nt32Pkg/WinNtBlockIoDxe/WinNtBlockIo.c index e43e6cfef5..1e12dd5204 100644 --- a/Nt32Pkg/WinNtBlockIoDxe/WinNtBlockIo.c +++ b/Nt32Pkg/WinNtBlockIoDxe/WinNtBlockIo.c @@ -1,6 +1,6 @@ /**@file -Copyright (c) 2006 - 2007, Intel Corporation. All rights reserved.
+Copyright (c) 2006 - 2012, 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 @@ -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,20 @@ WinNtBlockIoWriteBlocks ( goto Done; } + // + // According the Windows requirement, first need to lock the volume before + // write to it. + // + 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; + } 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); -- cgit v1.2.3