]> git.proxmox.com Git - mirror_edk2.git/blobdiff - Nt32Pkg/WinNtBlockIoDxe/WinNtBlockIo.c
Do not lock the volume when the volume maps to a file instead of a physical disk.
[mirror_edk2.git] / Nt32Pkg / WinNtBlockIoDxe / WinNtBlockIo.c
index 291f7a08e2ec582160192cfe7ee1012246075651..12924e659fbab77db9475d748767c5e8aebd792f 100644 (file)
@@ -1,7 +1,7 @@
 /**@file\r
 \r
-Copyright (c) 2006 - 2007, Intel Corporation\r
-All rights reserved. This program and the accompanying materials\r
+Copyright (c) 2006 - 2013, 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
 http://opensource.org/licenses/bsd-license.php\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,24 @@ WinNtBlockIoWriteBlocks (
     goto Done;\r
   }\r
 \r
+  //\r
+  // According the Windows requirement, first need to lock the volume before \r
+  // write to it.\r
+  //\r
+  if (Private->DeviceType == EfiWinNtPhysicalDisks) {\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
+  } else {\r
+    Locked = 0;\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