]> git.proxmox.com Git - mirror_edk2.git/commitdiff
Enable write file to USB from Shell in Win7 OS
authorydong10 <ydong10@6f19259b-4bc3-4df7-8a09-765794883524>
Wed, 15 Feb 2012 02:40:18 +0000 (02:40 +0000)
committerydong10 <ydong10@6f19259b-4bc3-4df7-8a09-765794883524>
Wed, 15 Feb 2012 02:40:18 +0000 (02:40 +0000)
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

index e43e6cfef5e522809e8d3f357747f7f1fd25cbd6..1e12dd5204e46ce9c124d669da2e26aee6c30543 100644 (file)
@@ -1,6 +1,6 @@
 /**@file\r
 \r
-Copyright (c) 2006 - 2007, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2006 - 2012, 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
@@ -972,8 +972,10 @@ WinNtBlockIoWriteBlocks (
   WIN_NT_BLOCK_IO_PRIVATE *Private;\r
   UINTN                   BytesWritten;\r
   BOOL                    Flag;\r
+  BOOL                    Locked;\r
   EFI_STATUS              Status;\r
   EFI_TPL                 OldTpl;\r
+  UINTN                   BytesReturned;\r
 \r
   OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
 \r
@@ -984,7 +986,20 @@ WinNtBlockIoWriteBlocks (
     goto Done;\r
   }\r
 \r
+  //\r
+  // According the Windows requirement, first need to lock the volume before \r
+  // write to it.\r
+  //\r
+  Locked = Private->WinNtThunk->DeviceIoControl (Private->NtHandle, FSCTL_LOCK_VOLUME, NULL, 0, NULL, 0, &BytesReturned, NULL);\r
+  if (Locked == 0) {\r
+    DEBUG ((EFI_D_INIT, "ReadBlocks: Lock volume failed. (%d)\n", Private->WinNtThunk->GetLastError ()));\r
+    Status = WinNtBlockIoError (Private);\r
+    goto Done;\r
+  }\r
   Flag = Private->WinNtThunk->WriteFile (Private->NtHandle, Buffer, (DWORD) BufferSize, (LPDWORD) &BytesWritten, NULL);\r
+  if (Locked != 0) {\r
+    Private->WinNtThunk->DeviceIoControl (Private->NtHandle, FSCTL_UNLOCK_VOLUME, NULL, 0, NULL, 0, &BytesReturned, NULL);\r
+  }\r
   if (!Flag || (BytesWritten != BufferSize)) {\r
     DEBUG ((EFI_D_INIT, "ReadBlocks: WriteFile failed. (%d)\n", Private->WinNtThunk->GetLastError ()));\r
     Status = WinNtBlockIoError (Private);\r