Add WinNtBlockIoDxe module into Nt32Pkg.
authorklu2 <klu2@6f19259b-4bc3-4df7-8a09-765794883524>
Wed, 27 Jun 2007 05:06:50 +0000 (05:06 +0000)
committerklu2 <klu2@6f19259b-4bc3-4df7-8a09-765794883524>
Wed, 27 Jun 2007 05:06:50 +0000 (05:06 +0000)
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@2770 6f19259b-4bc3-4df7-8a09-765794883524

Nt32Pkg/Nt32.dsc
Nt32Pkg/WinNtBlockIoDxe/ComponentName.c [new file with mode: 0644]
Nt32Pkg/WinNtBlockIoDxe/DriverConfiguration.c [new file with mode: 0644]
Nt32Pkg/WinNtBlockIoDxe/DriverDiagnostics.c [new file with mode: 0644]
Nt32Pkg/WinNtBlockIoDxe/WinNtBlockIo.c [new file with mode: 0644]
Nt32Pkg/WinNtBlockIoDxe/WinNtBlockIo.h [new file with mode: 0644]
Nt32Pkg/WinNtBlockIoDxe/WinNtBlockIo.inf [new file with mode: 0644]
Nt32Pkg/WinNtBlockIoDxe/WinNtBlockIo.msa [new file with mode: 0644]

index 896d38d..5137f63 100644 (file)
   UefiDriverEntryPoint|$(WORKSPACE)\MdePkg\Library/UefiDriverEntryPoint/UefiDriverEntryPoint.inf\r
   EdkGraphicsLib|$(WORKSPACE)\MdeModulePkg\Library/EdkGraphicsLib/EdkGraphicsLib.inf\r
   ReportStatusCodeLib|$(WORKSPACE)\MdePkg\Library/DxeReportStatusCodeLib/DxeReportStatusCodeLib.inf\r
-  PrintLib|$(WORKSPACE)\MdeModulePkg\Library/EdkDxePrintLib/EdkDxePrintLib.inf\r
+  PrintLib|$(WORKSPACE)\MdePkg\Library/BasePrintLib/BasePrintLib.inf\r
   DxeServicesTableLib|$(WORKSPACE)\MdePkg\Library/DxeServicesTableLib/DxeServicesTableLib.inf\r
   UefiDecompressLib|$(WORKSPACE)\MdeModulePkg\Library/DxeCoreUefiDecompressLibFromHob/DxeCoreUefiDecompressLibFromHob.inf\r
   HiiLib|$(WORKSPACE)\MdePkg\Library/HiiLib/HiiLib.inf\r
   UefiBootServicesTableLib|$(WORKSPACE)\MdePkg\Library/UefiBootServicesTableLib/UefiBootServicesTableLib.inf\r
   DevicePathLib|$(WORKSPACE)\MdePkg\Library/UefiDevicePathLib/UefiDevicePathLib.inf\r
-  BaseMemoryLib|$(WORKSPACE)\MdePkg\Library/DxeMemoryLib/DxeMemoryLib.inf\r
+  BaseMemoryLib|$(WORKSPACE)\MdePkg\Library/BaseMemoryLib/BaseMemoryLib.inf\r
   UefiRuntimeLib|$(WORKSPACE)\MdeModulePkg\Library/EdkUefiRuntimeLib/EdkUefiRuntimeLib.inf\r
   TianoDecompressLib|$(WORKSPACE)\MdeModulePkg\Library/DxeCoreTianoDecompressLibFromHob/DxeCoreTianoDecompressLibFromHob.inf\r
   EdkUsbLib|$(WORKSPACE)\MdeModulePkg\Library/EdkUsbLib/EdkUsbLib.inf\r
   EdkUsbLib|$(WORKSPACE)\MdeModulePkg\Library/EdkUsbLib/EdkUsbLib.inf\r
   DebugLib|$(WORKSPACE)\MdePkg\Library/BaseDebugLibNull/BaseDebugLibNull.inf\r
   DxeServicesTableLib|$(WORKSPACE)\MdePkg\Library/DxeServicesTableLib/DxeServicesTableLib.inf\r
-  PrintLib|$(WORKSPACE)\MdeModulePkg\Library/EdkDxePrintLib/EdkDxePrintLib.inf\r
+  PrintLib|$(WORKSPACE)\MdePkg\Library/BasePrintLib/BasePrintLib.inf\r
   EdkScsiLib|$(WORKSPACE)\MdeModulePkg\Library/EdkScsiLib/EdkScsiLib.inf\r
   UefiDecompressLib|$(WORKSPACE)\MdeModulePkg\Library/DxeCoreUefiDecompressLibFromHob/DxeCoreUefiDecompressLibFromHob.inf\r
   HiiLib|$(WORKSPACE)\MdePkg\Library/HiiLib/HiiLib.inf\r
   HobLib|$(WORKSPACE)\MdePkg\Library/DxeHobLib/DxeHobLib.inf\r
   DevicePathLib|$(WORKSPACE)\MdePkg\Library/UefiDevicePathLib/UefiDevicePathLib.inf\r
   EdkIfrSupportLib|$(WORKSPACE)\MdeModulePkg\Library/EdkIfrSupportLib/EdkIfrSupportLib.inf\r
-  BaseMemoryLib|$(WORKSPACE)\MdePkg\Library/DxeMemoryLib/DxeMemoryLib.inf\r
+  BaseMemoryLib|$(WORKSPACE)\MdePkg\Library/BaseMemoryLib/BaseMemoryLib.inf\r
   EdkPeCoffLoaderLib|$(WORKSPACE)\MdeModulePkg\Library/EdkDxePeCoffLoaderFromHobLib/EdkDxePeCoffLoaderFromHobLib.inf\r
   PcdLib|$(WORKSPACE)\MdePkg\Library/DxePcdLib/DxePcdLib.inf\r
   MemoryAllocationLib|$(WORKSPACE)\MdePkg\Library/DxeMemoryAllocationLib/DxeMemoryAllocationLib.inf\r
   UefiDriverEntryPoint|$(WORKSPACE)\MdePkg\Library/UefiDriverEntryPoint/UefiDriverEntryPoint.inf\r
   EdkGraphicsLib|$(WORKSPACE)\MdeModulePkg\Library/EdkGraphicsLib/EdkGraphicsLib.inf\r
   ReportStatusCodeLib|$(WORKSPACE)\MdePkg\Library/DxeReportStatusCodeLib/DxeReportStatusCodeLib.inf\r
-  PrintLib|$(WORKSPACE)\MdeModulePkg\Library/EdkDxePrintLib/EdkDxePrintLib.inf\r
+  PrintLib|$(WORKSPACE)\MdePkg\Library/BasePrintLib/BasePrintLib.inf\r
   DxeServicesTableLib|$(WORKSPACE)\MdePkg\Library/DxeServicesTableLib/DxeServicesTableLib.inf\r
   UefiDecompressLib|$(WORKSPACE)\MdeModulePkg\Library/DxeCoreUefiDecompressLibFromHob/DxeCoreUefiDecompressLibFromHob.inf\r
   HiiLib|$(WORKSPACE)\MdePkg\Library/HiiLib/HiiLib.inf\r
   UefiBootServicesTableLib|$(WORKSPACE)\MdePkg\Library/UefiBootServicesTableLib/UefiBootServicesTableLib.inf\r
   DevicePathLib|$(WORKSPACE)\MdePkg\Library/UefiDevicePathLib/UefiDevicePathLib.inf\r
-  BaseMemoryLib|$(WORKSPACE)\MdePkg\Library/DxeMemoryLib/DxeMemoryLib.inf\r
+  BaseMemoryLib|$(WORKSPACE)\MdePkg\Library/BaseMemoryLib/BaseMemoryLib.inf\r
   UefiRuntimeLib|$(WORKSPACE)\MdeModulePkg\Library/EdkUefiRuntimeLib/EdkUefiRuntimeLib.inf\r
   TianoDecompressLib|$(WORKSPACE)\MdeModulePkg\Library/DxeCoreTianoDecompressLibFromHob/DxeCoreTianoDecompressLibFromHob.inf\r
   EdkUsbLib|$(WORKSPACE)\MdeModulePkg\Library/EdkUsbLib/EdkUsbLib.inf\r
   UefiDriverEntryPoint|$(WORKSPACE)\MdePkg\Library/UefiDriverEntryPoint/UefiDriverEntryPoint.inf\r
   EdkGraphicsLib|$(WORKSPACE)\MdeModulePkg\Library/EdkGraphicsLib/EdkGraphicsLib.inf\r
   ReportStatusCodeLib|$(WORKSPACE)\MdePkg\Library/DxeReportStatusCodeLib/DxeReportStatusCodeLib.inf\r
-  PrintLib|$(WORKSPACE)\MdeModulePkg\Library/EdkDxePrintLib/EdkDxePrintLib.inf\r
+  PrintLib|$(WORKSPACE)\MdePkg\Library/BasePrintLib/BasePrintLib.inf\r
   DxeServicesTableLib|$(WORKSPACE)\MdePkg\Library/DxeServicesTableLib/DxeServicesTableLib.inf\r
   UefiDecompressLib|$(WORKSPACE)\MdeModulePkg\Library/DxeCoreUefiDecompressLibFromHob/DxeCoreUefiDecompressLibFromHob.inf\r
   HiiLib|$(WORKSPACE)\MdePkg\Library/HiiLib/HiiLib.inf\r
   UefiBootServicesTableLib|$(WORKSPACE)\MdePkg\Library/UefiBootServicesTableLib/UefiBootServicesTableLib.inf\r
   DevicePathLib|$(WORKSPACE)\MdePkg\Library/UefiDevicePathLib/UefiDevicePathLib.inf\r
-  BaseMemoryLib|$(WORKSPACE)\MdePkg\Library/DxeMemoryLib/DxeMemoryLib.inf\r
+  BaseMemoryLib|$(WORKSPACE)\MdePkg\Library/BaseMemoryLib/BaseMemoryLib.inf\r
   TianoDecompressLib|$(WORKSPACE)\MdeModulePkg\Library/DxeCoreTianoDecompressLibFromHob/DxeCoreTianoDecompressLibFromHob.inf\r
   EdkUsbLib|$(WORKSPACE)\MdeModulePkg\Library/EdkUsbLib/EdkUsbLib.inf\r
   EdkScsiLib|$(WORKSPACE)\MdeModulePkg\Library/EdkScsiLib/EdkScsiLib.inf\r
   EdkUsbLib|$(WORKSPACE)\MdeModulePkg\Library/EdkUsbLib/EdkUsbLib.inf\r
   DebugLib|$(WORKSPACE)\MdePkg\Library/BaseDebugLibNull/BaseDebugLibNull.inf\r
   DxeServicesTableLib|$(WORKSPACE)\MdePkg\Library/DxeServicesTableLib/DxeServicesTableLib.inf\r
-  PrintLib|$(WORKSPACE)\MdeModulePkg\Library/EdkDxePrintLib/EdkDxePrintLib.inf\r
+  PrintLib|$(WORKSPACE)\MdePkg\Library/BasePrintLib/BasePrintLib.inf\r
   EdkScsiLib|$(WORKSPACE)\MdeModulePkg\Library/EdkScsiLib/EdkScsiLib.inf\r
   UefiDecompressLib|$(WORKSPACE)\MdeModulePkg\Library/DxeCoreUefiDecompressLibFromHob/DxeCoreUefiDecompressLibFromHob.inf\r
   HiiLib|$(WORKSPACE)\MdePkg\Library/HiiLib/HiiLib.inf\r
   HobLib|$(WORKSPACE)\MdePkg\Library/DxeHobLib/DxeHobLib.inf\r
   DevicePathLib|$(WORKSPACE)\MdePkg\Library/UefiDevicePathLib/UefiDevicePathLib.inf\r
   EdkIfrSupportLib|$(WORKSPACE)\MdeModulePkg\Library/EdkIfrSupportLib/EdkIfrSupportLib.inf\r
-  BaseMemoryLib|$(WORKSPACE)\MdePkg\Library/DxeMemoryLib/DxeMemoryLib.inf\r
+  BaseMemoryLib|$(WORKSPACE)\MdePkg\Library/BaseMemoryLib/BaseMemoryLib.inf\r
   EdkPeCoffLoaderLib|$(WORKSPACE)\MdeModulePkg\Library/EdkDxePeCoffLoaderFromHobLib/EdkDxePeCoffLoaderFromHobLib.inf\r
   PcdLib|$(WORKSPACE)\MdePkg\Library/DxePcdLib/DxePcdLib.inf\r
   MemoryAllocationLib|$(WORKSPACE)\MdePkg\Library/DxeMemoryAllocationLib/DxeMemoryAllocationLib.inf\r
 [Components.IA32]\r
   $(WORKSPACE)\Nt32Pkg\WinNtThunkDxe\WinNtThunk.inf\r
   $(WORKSPACE)\Nt32Pkg\WinNtThunkPPIToProtocolPeim\WinNtThunkPPIToProtocolPeim.inf\r
-  $(WORKSPACE)\Nt32Pkg\WinNtAutoScanPeim\WinNtAutoScan.inf
\ No newline at end of file
+  $(WORKSPACE)\Nt32Pkg\WinNtAutoScanPeim\WinNtAutoScan.inf\r
+  $(WORKSPACE)\Nt32Pkg\WinNtBlockIoDxe\WinNtBlockIo.inf
\ No newline at end of file
diff --git a/Nt32Pkg/WinNtBlockIoDxe/ComponentName.c b/Nt32Pkg/WinNtBlockIoDxe/ComponentName.c
new file mode 100644 (file)
index 0000000..d18b0e2
--- /dev/null
@@ -0,0 +1,201 @@
+/*++\r
+\r
+Copyright (c) 2006, Intel Corporation                                                         \r
+All rights reserved. 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
+                                                                                          \r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     \r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             \r
+\r
+Module Name:\r
+\r
+  ComponentName.c\r
+\r
+Abstract:\r
+\r
+--*/\r
+#include <Uefi.h>\r
+#include <WinNtDxe.h>\r
+#include <Protocol/ComponentName.h>\r
+#include <Protocol/DriverBinding.h>\r
+\r
+#include "WinNtBlockIo.h"\r
+\r
+//\r
+// EFI Component Name Functions\r
+//\r
+EFI_STATUS\r
+EFIAPI\r
+WinNtBlockIoComponentNameGetDriverName (\r
+  IN  EFI_COMPONENT_NAME_PROTOCOL  *This,\r
+  IN  CHAR8                        *Language,\r
+  OUT CHAR16                       **DriverName\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+WinNtBlockIoComponentNameGetControllerName (\r
+  IN  EFI_COMPONENT_NAME_PROTOCOL                     *This,\r
+  IN  EFI_HANDLE                                      ControllerHandle,\r
+  IN  EFI_HANDLE                                      ChildHandle        OPTIONAL,\r
+  IN  CHAR8                                           *Language,\r
+  OUT CHAR16                                          **ControllerName\r
+  );\r
+\r
+//\r
+// EFI Component Name Protocol\r
+//\r
+EFI_COMPONENT_NAME_PROTOCOL     gWinNtBlockIoComponentName = {\r
+  WinNtBlockIoComponentNameGetDriverName,\r
+  WinNtBlockIoComponentNameGetControllerName,\r
+  "eng"\r
+};\r
+\r
+static EFI_UNICODE_STRING_TABLE mWinNtBlockIoDriverNameTable[] = {\r
+  { "eng", L"Windows Block I/O Driver" },\r
+  { NULL , NULL }\r
+};\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+WinNtBlockIoComponentNameGetDriverName (\r
+  IN  EFI_COMPONENT_NAME_PROTOCOL  *This,\r
+  IN  CHAR8                        *Language,\r
+  OUT CHAR16                       **DriverName\r
+  )\r
+/*++\r
+\r
+  Routine Description:\r
+    Retrieves a Unicode string that is the user readable name of the EFI Driver.\r
+\r
+  Arguments:\r
+    This       - A pointer to the EFI_COMPONENT_NAME_PROTOCOL instance.\r
+    Language   - A pointer to a three character ISO 639-2 language identifier.\r
+                 This is the language of the driver name that that the caller \r
+                 is requesting, and it must match one of the languages specified\r
+                 in SupportedLanguages.  The number of languages supported by a \r
+                 driver is up to the driver writer.\r
+    DriverName - A pointer to the Unicode string to return.  This Unicode string\r
+                 is the name of the driver specified by This in the language \r
+                 specified by Language.\r
+\r
+  Returns:\r
+    EFI_SUCCESS           - The Unicode string for the Driver specified by This\r
+                            and the language specified by Language was returned \r
+                            in DriverName.\r
+    EFI_INVALID_PARAMETER - Language is NULL.\r
+    EFI_INVALID_PARAMETER - DriverName is NULL.\r
+    EFI_UNSUPPORTED       - The driver specified by This does not support the \r
+                            language specified by Language.\r
+\r
+--*/\r
+{\r
+  return LookupUnicodeString (\r
+          Language,\r
+          gWinNtBlockIoComponentName.SupportedLanguages,\r
+          mWinNtBlockIoDriverNameTable,\r
+          DriverName\r
+          );\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+WinNtBlockIoComponentNameGetControllerName (\r
+  IN  EFI_COMPONENT_NAME_PROTOCOL                     *This,\r
+  IN  EFI_HANDLE                                      ControllerHandle,\r
+  IN  EFI_HANDLE                                      ChildHandle        OPTIONAL,\r
+  IN  CHAR8                                           *Language,\r
+  OUT CHAR16                                          **ControllerName\r
+  )\r
+/*++\r
+\r
+  Routine Description:\r
+    Retrieves a Unicode string that is the user readable name of the controller\r
+    that is being managed by an EFI Driver.\r
+\r
+  Arguments:\r
+    This             - A pointer to the EFI_COMPONENT_NAME_PROTOCOL instance.\r
+    ControllerHandle - The handle of a controller that the driver specified by \r
+                       This is managing.  This handle specifies the controller \r
+                       whose name is to be returned.\r
+    ChildHandle      - The handle of the child controller to retrieve the name \r
+                       of.  This is an optional parameter that may be NULL.  It \r
+                       will be NULL for device drivers.  It will also be NULL \r
+                       for a bus drivers that wish to retrieve the name of the \r
+                       bus controller.  It will not be NULL for a bus driver \r
+                       that wishes to retrieve the name of a child controller.\r
+    Language         - A pointer to a three character ISO 639-2 language \r
+                       identifier.  This is the language of the controller name \r
+                       that that the caller is requesting, and it must match one\r
+                       of the languages specified in SupportedLanguages.  The \r
+                       number of languages supported by a driver is up to the \r
+                       driver writer.\r
+    ControllerName   - A pointer to the Unicode string to return.  This Unicode\r
+                       string is the name of the controller specified by \r
+                       ControllerHandle and ChildHandle in the language specified\r
+                       by Language from the point of view of the driver specified\r
+                       by This. \r
+\r
+  Returns:\r
+    EFI_SUCCESS           - The Unicode string for the user readable name in the \r
+                            language specified by Language for the driver \r
+                            specified by This was returned in DriverName.\r
+    EFI_INVALID_PARAMETER - ControllerHandle is not a valid EFI_HANDLE.\r
+    EFI_INVALID_PARAMETER - ChildHandle is not NULL and it is not a valid EFI_HANDLE.\r
+    EFI_INVALID_PARAMETER - Language is NULL.\r
+    EFI_INVALID_PARAMETER - ControllerName is NULL.\r
+    EFI_UNSUPPORTED       - The driver specified by This is not currently managing \r
+                            the controller specified by ControllerHandle and \r
+                            ChildHandle.\r
+    EFI_UNSUPPORTED       - The driver specified by This does not support the \r
+                            language specified by Language.\r
+\r
+--*/\r
+{\r
+  EFI_STATUS              Status;\r
+  EFI_BLOCK_IO_PROTOCOL   *BlockIo;\r
+  WIN_NT_BLOCK_IO_PRIVATE *Private;\r
+\r
+  //\r
+  // This is a device driver, so ChildHandle must be NULL.\r
+  //\r
+  if (ChildHandle != NULL) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+  //\r
+  // Make sure this driver is currently managing ControllerHandle\r
+  //\r
+  Status = EfiTestManagedDevice (\r
+             ControllerHandle,\r
+             gWinNtBlockIoDriverBinding.DriverBindingHandle,\r
+             &gEfiWinNtIoProtocolGuid\r
+             );\r
+  if (EFI_ERROR (Status)) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+  //\r
+  // Get our context back\r
+  //\r
+  Status = gBS->OpenProtocol (\r
+                  ControllerHandle,\r
+                  &gEfiBlockIoProtocolGuid,\r
+                  &BlockIo,\r
+                  gWinNtBlockIoDriverBinding.DriverBindingHandle,\r
+                  ControllerHandle,\r
+                  EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  Private = WIN_NT_BLOCK_IO_PRIVATE_DATA_FROM_THIS (BlockIo);\r
+\r
+  return LookupUnicodeString (\r
+          Language,\r
+          gWinNtBlockIoComponentName.SupportedLanguages,\r
+          Private->ControllerNameTable,\r
+          ControllerName\r
+          );\r
+}\r
diff --git a/Nt32Pkg/WinNtBlockIoDxe/DriverConfiguration.c b/Nt32Pkg/WinNtBlockIoDxe/DriverConfiguration.c
new file mode 100644 (file)
index 0000000..1461de8
--- /dev/null
@@ -0,0 +1,343 @@
+/*++\r
+\r
+Copyright (c) 2006, Intel Corporation\r
+All rights reserved. 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
+\r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+Module Name:\r
+\r
+  DriverConfiguration.c\r
+\r
+Abstract:\r
+\r
+--*/\r
+#include <Uefi.h>\r
+#include <WinNtDxe.h>\r
+#include <Protocol/BlockIo.h>\r
+#include <Protocol/ComponentName.h>\r
+#include <Protocol/DriverBinding.h>\r
+\r
+#include "WinNtBlockIo.h"\r
+\r
+//\r
+// EFI Driver Configuration Functions\r
+//\r
+EFI_STATUS\r
+EFIAPI\r
+WinNtBlockIoDriverConfigurationSetOptions (\r
+  IN  EFI_DRIVER_CONFIGURATION_PROTOCOL                      *This,\r
+  IN  EFI_HANDLE                                             ControllerHandle,\r
+  IN  EFI_HANDLE                                             ChildHandle  OPTIONAL,\r
+  IN  CHAR8                                                  *Language,\r
+  OUT EFI_DRIVER_CONFIGURATION_ACTION_REQUIRED               *ActionRequired\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+WinNtBlockIoDriverConfigurationOptionsValid (\r
+  IN  EFI_DRIVER_CONFIGURATION_PROTOCOL               *This,\r
+  IN  EFI_HANDLE                                      ControllerHandle,\r
+  IN  EFI_HANDLE                                      ChildHandle  OPTIONAL\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+WinNtBlockIoDriverConfigurationForceDefaults (\r
+  IN  EFI_DRIVER_CONFIGURATION_PROTOCOL                      *This,\r
+  IN  EFI_HANDLE                                             ControllerHandle,\r
+  IN  EFI_HANDLE                                             ChildHandle  OPTIONAL,\r
+  IN  UINT32                                                 DefaultType,\r
+  OUT EFI_DRIVER_CONFIGURATION_ACTION_REQUIRED               *ActionRequired\r
+  );\r
+\r
+//\r
+// EFI Driver Configuration Protocol\r
+//\r
+EFI_DRIVER_CONFIGURATION_PROTOCOL gWinNtBlockIoDriverConfiguration = {\r
+  WinNtBlockIoDriverConfigurationSetOptions,\r
+  WinNtBlockIoDriverConfigurationOptionsValid,\r
+  WinNtBlockIoDriverConfigurationForceDefaults,\r
+  LANGUAGESUPPORTED\r
+};\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+WinNtBlockIoDriverConfigurationSetOptions (\r
+  IN  EFI_DRIVER_CONFIGURATION_PROTOCOL                      *This,\r
+  IN  EFI_HANDLE                                             ControllerHandle,\r
+  IN  EFI_HANDLE                                             ChildHandle  OPTIONAL,\r
+  IN  CHAR8                                                  *Language,\r
+  OUT EFI_DRIVER_CONFIGURATION_ACTION_REQUIRED               *ActionRequired\r
+  )\r
+/*++\r
+\r
+  Routine Description:\r
+    Allows the user to set controller specific options for a controller that a\r
+    driver is currently managing.\r
+\r
+  Arguments:\r
+    This             - A pointer to the EFI_DRIVER_CONFIGURATION_ PROTOCOL instance.\r
+    ControllerHandle - The handle of the controller to set options on.\r
+    ChildHandle      - The handle of the child controller to set options on.  This\r
+                       is an optional parameter that may be NULL.  It will be NULL\r
+                       for device drivers, and for a bus drivers that wish to set\r
+                       options for the bus controller.  It will not be NULL for a\r
+                       bus driver that wishes to set options for one of its child\r
+                       controllers.\r
+    Language         - A pointer to a three character ISO 639-2 language identifier.\r
+                       This is the language of the user interface that should be\r
+                       presented to the user, and it must match one of the languages\r
+                       specified in SupportedLanguages.  The number of languages\r
+                       supported by a driver is up to the driver writer.\r
+    ActionRequired   - A pointer to the action that the calling agent is required\r
+                       to perform when this function returns.  See "Related\r
+                       Definitions" for a list of the actions that the calling\r
+                       agent is required to perform prior to accessing\r
+                       ControllerHandle again.\r
+\r
+  Returns:\r
+    EFI_SUCCESS           - The driver specified by This successfully set the\r
+                            configuration options for the controller specified\r
+                            by ControllerHandle..\r
+    EFI_INVALID_PARAMETER - ControllerHandle is not a valid EFI_HANDLE.\r
+    EFI_INVALID_PARAMETER - ChildHandle is not NULL and it is not a valid EFI_HANDLE.\r
+    EFI_INVALID_PARAMETER - ActionRequired is NULL.\r
+    EFI_UNSUPPORTED       - The driver specified by This does not support setting\r
+                            configuration options for the controller specified by\r
+                            ControllerHandle and ChildHandle.\r
+    EFI_UNSUPPORTED       - The driver specified by This does not support the\r
+                            language specified by Language.\r
+    EFI_DEVICE_ERROR      - A device error occurred while attempt to set the\r
+                            configuration options for the controller specified\r
+                            by ControllerHandle and ChildHandle.\r
+    EFI_OUT_RESOURCES     - There are not enough resources available to set the\r
+                            configuration options for the controller specified\r
+                            by ControllerHandle and ChildHandle.\r
+\r
+--*/\r
+{\r
+  EFI_STATUS            Status;\r
+  EFI_BLOCK_IO_PROTOCOL *BlockIo;\r
+  CHAR8                 *SupportedLanguage;\r
+\r
+  SupportedLanguage = This->SupportedLanguages;\r
+\r
+  Status            = EFI_UNSUPPORTED;\r
+  while (*SupportedLanguage != 0) {\r
+    if (AsciiStrnCmp (Language, SupportedLanguage, 3) == 0) {\r
+      Status = EFI_SUCCESS;\r
+    }\r
+\r
+    SupportedLanguage += 3;\r
+  }\r
+\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  if (ActionRequired == NULL || ControllerHandle == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  if (ChildHandle != NULL) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  //\r
+  // Validate controller handle\r
+  //\r
+  Status = gBS->OpenProtocol (\r
+                  ControllerHandle,\r
+                  &gEfiWinNtIoProtocolGuid,\r
+                  &BlockIo,\r
+                  gWinNtBlockIoDriverBinding.DriverBindingHandle,\r
+                  ControllerHandle,\r
+                  EFI_OPEN_PROTOCOL_BY_DRIVER\r
+                  );\r
+\r
+  if (!EFI_ERROR (Status)) {\r
+    gBS->CloseProtocol (\r
+          ControllerHandle,\r
+          &gEfiWinNtIoProtocolGuid,\r
+          gWinNtBlockIoDriverBinding.DriverBindingHandle,\r
+          ControllerHandle\r
+          );\r
+\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  if (Status == EFI_UNSUPPORTED) {\r
+    return Status;\r
+  } else if (Status != EFI_ALREADY_STARTED) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  *ActionRequired = EfiDriverConfigurationActionNone;\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+WinNtBlockIoDriverConfigurationOptionsValid (\r
+  IN  EFI_DRIVER_CONFIGURATION_PROTOCOL               *This,\r
+  IN  EFI_HANDLE                                      ControllerHandle,\r
+  IN  EFI_HANDLE                                      ChildHandle  OPTIONAL\r
+  )\r
+/*++\r
+\r
+  Routine Description:\r
+    Tests to see if a controller's current configuration options are valid.\r
+\r
+  Arguments:\r
+    This             - A pointer to the EFI_DRIVER_CONFIGURATION_PROTOCOL instance.\r
+    ControllerHandle - The handle of the controller to test if it's current\r
+                       configuration options are valid.\r
+    ChildHandle      - The handle of the child controller to test if it's current\r
+                       configuration options are valid.  This is an optional\r
+                       parameter that may be NULL.  It will be NULL for device\r
+                       drivers.  It will also be NULL for a bus drivers that wish\r
+                       to test the configuration options for the bus controller.\r
+                       It will not be NULL for a bus driver that wishes to test\r
+                       configuration options for one of its child controllers.\r
+\r
+  Returns:\r
+    EFI_SUCCESS           - The controller specified by ControllerHandle and\r
+                            ChildHandle that is being managed by the driver\r
+                            specified by This has a valid set of  configuration\r
+                            options.\r
+    EFI_INVALID_PARAMETER - ControllerHandle is not a valid EFI_HANDLE.\r
+    EFI_INVALID_PARAMETER - ChildHandle is not NULL and it is not a valid EFI_HANDLE.\r
+    EFI_UNSUPPORTED       - The driver specified by This is not currently\r
+                            managing the controller specified by ControllerHandle\r
+                            and ChildHandle.\r
+    EFI_DEVICE_ERROR      - The controller specified by ControllerHandle and\r
+                            ChildHandle that is being managed by the driver\r
+                            specified by This has an invalid set of configuration\r
+                            options.\r
+\r
+--*/\r
+{\r
+  EFI_STATUS            Status;\r
+  EFI_BLOCK_IO_PROTOCOL *BlockIo;\r
+\r
+  if (ChildHandle != NULL) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  if (ControllerHandle == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  //\r
+  // Validate controller handle\r
+  //\r
+  Status = gBS->OpenProtocol (\r
+                  ControllerHandle,\r
+                  &gEfiWinNtIoProtocolGuid,\r
+                  &BlockIo,\r
+                  gWinNtBlockIoDriverBinding.DriverBindingHandle,\r
+                  ControllerHandle,\r
+                  EFI_OPEN_PROTOCOL_BY_DRIVER\r
+                  );\r
+\r
+  if (!EFI_ERROR (Status)) {\r
+    gBS->CloseProtocol (\r
+          ControllerHandle,\r
+          &gEfiWinNtIoProtocolGuid,\r
+          gWinNtBlockIoDriverBinding.DriverBindingHandle,\r
+          ControllerHandle\r
+          );\r
+\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  if (Status == EFI_UNSUPPORTED) {\r
+    return Status;\r
+  } else if (Status != EFI_ALREADY_STARTED) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+WinNtBlockIoDriverConfigurationForceDefaults (\r
+  IN  EFI_DRIVER_CONFIGURATION_PROTOCOL                      *This,\r
+  IN  EFI_HANDLE                                             ControllerHandle,\r
+  IN  EFI_HANDLE                                             ChildHandle  OPTIONAL,\r
+  IN  UINT32                                                 DefaultType,\r
+  OUT EFI_DRIVER_CONFIGURATION_ACTION_REQUIRED               *ActionRequired\r
+  )\r
+/*++\r
+\r
+  Routine Description:\r
+    Forces a driver to set the default configuration options for a controller.\r
+\r
+  Arguments:\r
+    This             - A pointer to the EFI_DRIVER_CONFIGURATION_ PROTOCOL instance.\r
+    ControllerHandle - The handle of the controller to force default configuration options on.\r
+    ChildHandle      - The handle of the child controller to force default configuration options on  This is an optional parameter that may be NULL.  It will be NULL for device drivers.  It will also be NULL for a bus drivers that wish to force default configuration options for the bus controller.  It will not be NULL for a bus driver that wishes to force default configuration options for one of its child controllers.\r
+    DefaultType      - The type of default configuration options to force on the controller specified by ControllerHandle and ChildHandle.  See Table 9-1 for legal values.  A DefaultType of 0x00000000 must be supported by this protocol.\r
+    ActionRequired   - A pointer to the action that the calling agent is required to perform when this function returns.  See "Related Definitions" in Section 9.1for a list of the actions that the calling agent is required to perform prior to accessing ControllerHandle again.\r
+\r
+  Returns:\r
+    EFI_SUCCESS           - The driver specified by This successfully forced the default configuration options on the controller specified by ControllerHandle and ChildHandle.\r
+    EFI_INVALID_PARAMETER - ControllerHandle is not a valid EFI_HANDLE.\r
+    EFI_INVALID_PARAMETER - ChildHandle is not NULL and it is not a valid EFI_HANDLE.\r
+    EFI_INVALID_PARAMETER - ActionRequired is NULL.\r
+    EFI_UNSUPPORTED       - The driver specified by This does not support forcing the default configuration options on the controller specified by ControllerHandle and ChildHandle.\r
+    EFI_UNSUPPORTED       - The driver specified by This does not support the configuration type specified by DefaultType.\r
+    EFI_DEVICE_ERROR      - A device error occurred while attempt to force the default configuration options on the controller specified by  ControllerHandle and ChildHandle.\r
+    EFI_OUT_RESOURCES     - There are not enough resources available to force the default configuration options on the controller specified by ControllerHandle and ChildHandle.\r
+\r
+--*/\r
+{\r
+  EFI_STATUS            Status;\r
+  EFI_BLOCK_IO_PROTOCOL *BlockIo;\r
+\r
+  if (ChildHandle != NULL) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  if (ActionRequired == NULL || ControllerHandle == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  //\r
+  // Validate controller handle\r
+  //\r
+  Status = gBS->OpenProtocol (\r
+                  ControllerHandle,\r
+                  &gEfiWinNtIoProtocolGuid,\r
+                  &BlockIo,\r
+                  gWinNtBlockIoDriverBinding.DriverBindingHandle,\r
+                  ControllerHandle,\r
+                  EFI_OPEN_PROTOCOL_BY_DRIVER\r
+                  );\r
+\r
+  if (!EFI_ERROR (Status)) {\r
+    gBS->CloseProtocol (\r
+          ControllerHandle,\r
+          &gEfiWinNtIoProtocolGuid,\r
+          gWinNtBlockIoDriverBinding.DriverBindingHandle,\r
+          ControllerHandle\r
+          );\r
+\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  if (Status == EFI_UNSUPPORTED) {\r
+    return Status;\r
+  } else if (Status != EFI_ALREADY_STARTED) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  *ActionRequired = EfiDriverConfigurationActionNone;\r
+  return EFI_SUCCESS;\r
+}\r
diff --git a/Nt32Pkg/WinNtBlockIoDxe/DriverDiagnostics.c b/Nt32Pkg/WinNtBlockIoDxe/DriverDiagnostics.c
new file mode 100644 (file)
index 0000000..b20bdb5
--- /dev/null
@@ -0,0 +1,191 @@
+/*++\r
+\r
+Copyright (c) 2006 - 2007, Intel Corporation\r
+All rights reserved. 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
+\r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+Module Name:\r
+\r
+  DriverDiagnostics.c\r
+\r
+Abstract:\r
+\r
+--*/\r
+#include <Uefi.h>\r
+#include <WinNtDxe.h>\r
+#include <Protocol/BlockIo.h>\r
+#include <Protocol/ComponentName.h>\r
+#include <Protocol/DriverBinding.h>\r
+\r
+#include "WinNtBlockIo.h"\r
+\r
+//\r
+// EFI Driver Diagnostics Functions\r
+//\r
+EFI_STATUS\r
+EFIAPI\r
+WinNtBlockIoDriverDiagnosticsRunDiagnostics (\r
+  IN  EFI_DRIVER_DIAGNOSTICS_PROTOCOL               *This,\r
+  IN  EFI_HANDLE                                    ControllerHandle,\r
+  IN  EFI_HANDLE                                    ChildHandle  OPTIONAL,\r
+  IN  EFI_DRIVER_DIAGNOSTIC_TYPE                    DiagnosticType,\r
+  IN  CHAR8                                         *Language,\r
+  OUT EFI_GUID                                      **ErrorType,\r
+  OUT UINTN                                         *BufferSize,\r
+  OUT CHAR16                                        **Buffer\r
+  );\r
+\r
+//\r
+// EFI Driver Diagnostics Protocol\r
+//\r
+EFI_DRIVER_DIAGNOSTICS_PROTOCOL gWinNtBlockIoDriverDiagnostics = {\r
+  WinNtBlockIoDriverDiagnosticsRunDiagnostics,\r
+  LANGUAGESUPPORTED\r
+};\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+WinNtBlockIoDriverDiagnosticsRunDiagnostics (\r
+  IN  EFI_DRIVER_DIAGNOSTICS_PROTOCOL               *This,\r
+  IN  EFI_HANDLE                                    ControllerHandle,\r
+  IN  EFI_HANDLE                                    ChildHandle  OPTIONAL,\r
+  IN  EFI_DRIVER_DIAGNOSTIC_TYPE                    DiagnosticType,\r
+  IN  CHAR8                                         *Language,\r
+  OUT EFI_GUID                                      **ErrorType,\r
+  OUT UINTN                                         *BufferSize,\r
+  OUT CHAR16                                        **Buffer\r
+  )\r
+/*++\r
+\r
+  Routine Description:\r
+    Runs diagnostics on a controller.\r
+\r
+  Arguments:\r
+    This             - A pointer to the EFI_DRIVER_DIAGNOSTICS_PROTOCOL instance.\r
+    ControllerHandle - The handle of the controller to run diagnostics on.\r
+    ChildHandle      - The handle of the child controller to run diagnostics on\r
+                       This is an optional parameter that may be NULL.  It will\r
+                       be NULL for device drivers.  It will also be NULL for a\r
+                       bus drivers that wish to run diagnostics on the bus\r
+                       controller.  It will not be NULL for a bus driver that\r
+                       wishes to run diagnostics on one of its child controllers.\r
+    DiagnosticType   - Indicates type of diagnostics to perform on the controller\r
+                       specified by ControllerHandle and ChildHandle.   See\r
+                       "Related Definitions" for the list of supported types.\r
+    Language         - A pointer to a three character ISO 639-2 language\r
+                       identifier.  This is the language in which the optional\r
+                       error message should be returned in Buffer, and it must\r
+                       match one of the languages specified in SupportedLanguages.\r
+                       The number of languages supported by a driver is up to\r
+                       the driver writer.\r
+    ErrorType        - A GUID that defines the format of the data returned in\r
+                       Buffer.\r
+    BufferSize       - The size, in bytes, of the data returned in Buffer.\r
+    Buffer           - A buffer that contains a Null-terminated Unicode string\r
+                       plus some additional data whose format is defined by\r
+                       ErrorType.  Buffer is allocated by this function with\r
+                       AllocatePool(), and it is the caller's responsibility\r
+                       to free it with a call to FreePool().\r
+\r
+  Returns:\r
+    EFI_SUCCESS           - The controller specified by ControllerHandle and\r
+                            ChildHandle passed the diagnostic.\r
+    EFI_INVALID_PARAMETER - ControllerHandle is not a valid EFI_HANDLE.\r
+    EFI_INVALID_PARAMETER - ChildHandle is not NULL and it is not a valid\r
+                            EFI_HANDLE.\r
+    EFI_INVALID_PARAMETER - Language is NULL.\r
+    EFI_INVALID_PARAMETER - ErrorType is NULL.\r
+    EFI_INVALID_PARAMETER - BufferType is NULL.\r
+    EFI_INVALID_PARAMETER - Buffer is NULL.\r
+    EFI_UNSUPPORTED       - The driver specified by This does not support\r
+                            running diagnostics for the controller specified\r
+                            by ControllerHandle and ChildHandle.\r
+    EFI_UNSUPPORTED       - The driver specified by This does not support the\r
+                            type of diagnostic specified by DiagnosticType.\r
+    EFI_UNSUPPORTED       - The driver specified by This does not support the\r
+                            language specified by Language.\r
+    EFI_OUT_OF_RESOURCES  - There are not enough resources available to complete\r
+                            the diagnostics.\r
+    EFI_OUT_OF_RESOURCES  - There are not enough resources available to return\r
+                            the status information in ErrorType, BufferSize,\r
+                            and Buffer.\r
+    EFI_DEVICE_ERROR      - The controller specified by ControllerHandle and\r
+                            ChildHandle did not pass the diagnostic.\r
+\r
+--*/\r
+{\r
+  EFI_STATUS            Status;\r
+  EFI_BLOCK_IO_PROTOCOL *BlockIo;\r
+  CHAR8                 *SupportedLanguage;\r
+\r
+  if (Language         == NULL ||\r
+      ErrorType        == NULL ||\r
+      Buffer           == NULL ||\r
+      ControllerHandle == NULL ||\r
+      BufferSize       == NULL) {\r
+\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  SupportedLanguage = This->SupportedLanguages;\r
+\r
+  Status            = EFI_UNSUPPORTED;\r
+  while (*SupportedLanguage != 0) {\r
+    if (AsciiStrnCmp (Language, SupportedLanguage, 3) == 0) {\r
+      Status = EFI_SUCCESS;\r
+      break;\r
+    }\r
+\r
+    SupportedLanguage += 3;\r
+  }\r
+\r
+  if (EFI_ERROR (Status)) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  *ErrorType  = NULL;\r
+  *BufferSize = 0;\r
+  if (DiagnosticType != EfiDriverDiagnosticTypeStandard) {\r
+    *ErrorType  = &gEfiBlockIoProtocolGuid;\r
+    *BufferSize = 0x60;\r
+    Buffer = AllocatePool ((UINTN) (*BufferSize));\r
+    CopyMem (*Buffer, L"Windows Block I/O Driver Diagnostics Failed\n", *BufferSize);\r
+    return EFI_DEVICE_ERROR;\r
+  }\r
+\r
+  //\r
+  // Validate controller handle\r
+  //\r
+  Status = gBS->OpenProtocol (\r
+                  ControllerHandle,\r
+                  &gEfiWinNtIoProtocolGuid,\r
+                  &BlockIo,\r
+                  gWinNtBlockIoDriverBinding.DriverBindingHandle,\r
+                  ControllerHandle,\r
+                  EFI_OPEN_PROTOCOL_BY_DRIVER\r
+                  );\r
+\r
+  if (!EFI_ERROR (Status)) {\r
+    gBS->CloseProtocol (\r
+          ControllerHandle,\r
+          &gEfiWinNtIoProtocolGuid,\r
+          gWinNtBlockIoDriverBinding.DriverBindingHandle,\r
+          ControllerHandle\r
+          );\r
+\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  if (Status == EFI_UNSUPPORTED) {\r
+    return Status;\r
+  } else if (Status != EFI_ALREADY_STARTED) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
diff --git a/Nt32Pkg/WinNtBlockIoDxe/WinNtBlockIo.c b/Nt32Pkg/WinNtBlockIoDxe/WinNtBlockIo.c
new file mode 100644 (file)
index 0000000..3f32d20
--- /dev/null
@@ -0,0 +1,1157 @@
+/*++\r
+\r
+Copyright (c) 2006 - 2007, Intel Corporation\r
+All rights reserved. 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
+\r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+Module Name:\r
+\r
+  WinNtBlockIo.c\r
+\r
+Abstract:\r
+\r
+  Produce block IO abstractions for real devices on your PC using Win32 APIs.\r
+  The configuration of what devices to mount or emulate comes from NT\r
+  environment variables. The variables must be visible to the Microsoft*\r
+  Developer Studio for them to work.\r
+\r
+  <F>ixed       - Fixed disk like a hard drive.\r
+  <R>emovable   - Removable media like a floppy or CD-ROM.\r
+  Read <O>nly   - Write protected device.\r
+  Read <W>rite  - Read write device.\r
+  <block count> - Decimal number of blocks a device supports.\r
+  <block size>  - Decimal number of bytes per block.\r
+\r
+  NT envirnonment variable contents. '<' and '>' are not part of the variable,\r
+  they are just used to make this help more readable. There should be no\r
+  spaces between the ';'. Extra spaces will break the variable. A '!' is\r
+  used to seperate multiple devices in a variable.\r
+\r
+  EFI_WIN_NT_VIRTUAL_DISKS =\r
+    <F | R><O | W>;<block count>;<block size>[!...]\r
+\r
+  EFI_WIN_NT_PHYSICAL_DISKS =\r
+    <drive letter>:<F | R><O | W>;<block count>;<block size>[!...]\r
+\r
+  Virtual Disks: These devices use a file to emulate a hard disk or removable\r
+                 media device.\r
+\r
+    Thus a 20 MB emulated hard drive would look like:\r
+    EFI_WIN_NT_VIRTUAL_DISKS=FW;40960;512\r
+\r
+    A 1.44MB emulated floppy with a block size of 1024 would look like:\r
+    EFI_WIN_NT_VIRTUAL_DISKS=RW;1440;1024\r
+\r
+  Physical Disks: These devices use NT to open a real device in your system\r
+\r
+    Thus a 120 MB floppy would look like:\r
+    EFI_WIN_NT_PHYSICAL_DISKS=B:RW;245760;512\r
+\r
+    Thus a standard CD-ROM floppy would look like:\r
+    EFI_WIN_NT_PHYSICAL_DISKS=Z:RO;307200;2048\r
+\r
+\r
+  * Other names and brands may be claimed as the property of others.\r
+\r
+--*/\r
+#include <Uefi.h>\r
+#include <WinNtDxe.h>\r
+#include <Protocol/WinNtThunk.h>\r
+#include <Protocol/WinNtIo.h>\r
+#include <Protocol/BlockIo.h>\r
+#include <Protocol/ComponentName.h>\r
+#include <Protocol/DriverBinding.h>\r
+//\r
+// The Library classes this module consumes\r
+//\r
+#include <Library/DebugLib.h>\r
+#include <Library/BaseLib.h>\r
+#include <Library/UefiDriverEntryPoint.h>\r
+#include <Library/UefiLib.h>\r
+#include <Library/BaseMemoryLib.h>\r
+#include <Library/UefiBootServicesTableLib.h>\r
+#include <Library/MemoryAllocationLib.h>\r
+\r
+#include "WinNtBlockIo.h"\r
+\r
+EFI_DRIVER_BINDING_PROTOCOL gWinNtBlockIoDriverBinding = {\r
+  WinNtBlockIoDriverBindingSupported,\r
+  WinNtBlockIoDriverBindingStart,\r
+  WinNtBlockIoDriverBindingStop,\r
+  0xa,\r
+  NULL,\r
+  NULL\r
+};\r
+\r
+/**\r
+  The user Entry Point for module WinNtBlockIo. The user code starts with this function.\r
+\r
+  @param[in] ImageHandle    The firmware allocated handle for the EFI image.  \r
+  @param[in] SystemTable    A pointer to the EFI System Table.\r
+  \r
+  @retval EFI_SUCCESS       The entry point is executed successfully.\r
+  @retval other             Some error occurs when executing this entry point.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+InitializeWinNtBlockIo(\r
+  IN EFI_HANDLE           ImageHandle,\r
+  IN EFI_SYSTEM_TABLE     *SystemTable\r
+  )\r
+{\r
+  EFI_STATUS              Status;\r
+\r
+  //\r
+  // Install driver model protocol(s).\r
+  //\r
+  Status = EfiLibInstallAllDriverProtocols (\r
+             ImageHandle,\r
+             SystemTable,\r
+             &gWinNtBlockIoDriverBinding,\r
+             ImageHandle,\r
+             &gWinNtBlockIoComponentName,\r
+             NULL,\r
+             &gWinNtBlockIoDriverDiagnostics\r
+             );\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+\r
+  return Status;\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+WinNtBlockIoDriverBindingSupported (\r
+  IN  EFI_DRIVER_BINDING_PROTOCOL  *This,\r
+  IN  EFI_HANDLE                   Handle,\r
+  IN  EFI_DEVICE_PATH_PROTOCOL     *RemainingDevicePath\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+Arguments:\r
+\r
+Returns:\r
+\r
+  None\r
+\r
+--*/\r
+// TODO:    This - add argument and description to function comment\r
+// TODO:    Handle - add argument and description to function comment\r
+// TODO:    RemainingDevicePath - add argument and description to function comment\r
+{\r
+  EFI_STATUS              Status;\r
+  EFI_WIN_NT_IO_PROTOCOL  *WinNtIo;\r
+\r
+  //\r
+  // Open the IO Abstraction(s) needed to perform the supported test\r
+  //\r
+  Status = gBS->OpenProtocol (\r
+                  Handle,\r
+                  &gEfiWinNtIoProtocolGuid,\r
+                  &WinNtIo,\r
+                  This->DriverBindingHandle,\r
+                  Handle,\r
+                  EFI_OPEN_PROTOCOL_BY_DRIVER\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  //\r
+  // Make sure the WinNtThunkProtocol is valid\r
+  //\r
+  Status = EFI_UNSUPPORTED;\r
+  if (WinNtIo->WinNtThunk->Signature == EFI_WIN_NT_THUNK_PROTOCOL_SIGNATURE) {\r
+\r
+    //\r
+    // Check the GUID to see if this is a handle type the driver supports\r
+    //\r
+    if (CompareGuid (WinNtIo->TypeGuid, &gEfiWinNtVirtualDisksGuid) ||\r
+        CompareGuid (WinNtIo->TypeGuid, &gEfiWinNtPhysicalDisksGuid) ) {\r
+      Status = EFI_SUCCESS;\r
+    }\r
+  }\r
+\r
+  //\r
+  // Close the I/O Abstraction(s) used to perform the supported test\r
+  //\r
+  gBS->CloseProtocol (\r
+        Handle,\r
+        &gEfiWinNtIoProtocolGuid,\r
+        This->DriverBindingHandle,\r
+        Handle\r
+        );\r
+\r
+  return Status;\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+WinNtBlockIoDriverBindingStart (\r
+  IN  EFI_DRIVER_BINDING_PROTOCOL   *This,\r
+  IN  EFI_HANDLE                    Handle,\r
+  IN  EFI_DEVICE_PATH_PROTOCOL      *RemainingDevicePath\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+Arguments:\r
+\r
+Returns:\r
+\r
+  None\r
+\r
+--*/\r
+// TODO:    This - add argument and description to function comment\r
+// TODO:    Handle - add argument and description to function comment\r
+// TODO:    RemainingDevicePath - add argument and description to function comment\r
+{\r
+  EFI_STATUS                  Status;\r
+  EFI_WIN_NT_IO_PROTOCOL      *WinNtIo;\r
+  WIN_NT_RAW_DISK_DEVICE_TYPE DiskType;\r
+  UINT16                      Buffer[FILENAME_BUFFER_SIZE];\r
+  CHAR16                      *Str;\r
+  BOOLEAN                     RemovableMedia;\r
+  BOOLEAN                     WriteProtected;\r
+  UINTN                       NumberOfBlocks;\r
+  UINTN                       BlockSize;\r
+\r
+  //\r
+  // Grab the protocols we need\r
+  //\r
+  Status = gBS->OpenProtocol (\r
+                  Handle,\r
+                  &gEfiWinNtIoProtocolGuid,\r
+                  &WinNtIo,\r
+                  This->DriverBindingHandle,\r
+                  Handle,\r
+                  EFI_OPEN_PROTOCOL_BY_DRIVER\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  //\r
+  // Set DiskType\r
+  //\r
+  if (CompareGuid (WinNtIo->TypeGuid, &gEfiWinNtVirtualDisksGuid)) {\r
+    DiskType = EfiWinNtVirtualDisks;\r
+  } else if (CompareGuid (WinNtIo->TypeGuid, &gEfiWinNtPhysicalDisksGuid)) {\r
+    DiskType = EfiWinNtPhysicalDisks;\r
+  } else {\r
+    Status = EFI_UNSUPPORTED;\r
+    goto Done;\r
+  }\r
+\r
+  Status  = EFI_NOT_FOUND;\r
+  Str     = WinNtIo->EnvString;\r
+  if (DiskType == EfiWinNtVirtualDisks) {\r
+    WinNtIo->WinNtThunk->SPrintf (\r
+                          Buffer,\r
+                          sizeof (Buffer),\r
+                          L"Diskfile%d",\r
+                          WinNtIo->InstanceNumber\r
+                          );\r
+  } else {\r
+    if (*Str >= 'A' && *Str <= 'Z' || *Str >= 'a' && *Str <= 'z') {\r
+      WinNtIo->WinNtThunk->SPrintf (Buffer, sizeof (Buffer), L"\\\\.\\%c:", *Str);\r
+    } else {\r
+      WinNtIo->WinNtThunk->SPrintf (Buffer, sizeof (Buffer), L"\\\\.\\PHYSICALDRIVE%c", *Str);\r
+    }\r
+\r
+    Str++;\r
+    if (*Str != ':') {\r
+      Status = EFI_NOT_FOUND;\r
+      goto Done;\r
+    }\r
+\r
+    Str++;\r
+  }\r
+\r
+  if (*Str == 'R' || *Str == 'F') {\r
+    RemovableMedia = (BOOLEAN) (*Str == 'R');\r
+    Str++;\r
+    if (*Str == 'O' || *Str == 'W') {\r
+      WriteProtected  = (BOOLEAN) (*Str == 'O');\r
+      Str             = GetNextElementPastTerminator (Str, ';');\r
+\r
+      NumberOfBlocks  = Atoi (Str);\r
+      if (NumberOfBlocks != 0) {\r
+        Str       = GetNextElementPastTerminator (Str, ';');\r
+        BlockSize = Atoi (Str);\r
+        if (BlockSize != 0) {\r
+          //\r
+          // If we get here the variable is valid so do the work.\r
+          //\r
+          Status = WinNtBlockIoCreateMapping (\r
+                    WinNtIo,\r
+                    Handle,\r
+                    Buffer,\r
+                    WriteProtected,\r
+                    RemovableMedia,\r
+                    NumberOfBlocks,\r
+                    BlockSize,\r
+                    DiskType\r
+                    );\r
+\r
+        }\r
+      }\r
+    }\r
+  }\r
+\r
+Done:\r
+  if (EFI_ERROR (Status)) {\r
+    gBS->CloseProtocol (\r
+          Handle,\r
+          &gEfiWinNtIoProtocolGuid,\r
+          This->DriverBindingHandle,\r
+          Handle\r
+          );\r
+  }\r
+\r
+  return Status;\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+WinNtBlockIoDriverBindingStop (\r
+  IN  EFI_DRIVER_BINDING_PROTOCOL  *This,\r
+  IN  EFI_HANDLE                   Handle,\r
+  IN  UINTN                        NumberOfChildren,\r
+  IN  EFI_HANDLE                   *ChildHandleBuffer\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  This              - TODO: add argument description\r
+  Handle            - TODO: add argument description\r
+  NumberOfChildren  - TODO: add argument description\r
+  ChildHandleBuffer - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  EFI_UNSUPPORTED - TODO: Add description for return value\r
+\r
+--*/\r
+{\r
+  EFI_BLOCK_IO_PROTOCOL   *BlockIo;\r
+  EFI_STATUS              Status;\r
+  WIN_NT_BLOCK_IO_PRIVATE *Private;\r
+\r
+  //\r
+  // Get our context back\r
+  //\r
+  Status = gBS->OpenProtocol (\r
+                  Handle,\r
+                  &gEfiBlockIoProtocolGuid,\r
+                  &BlockIo,\r
+                  This->DriverBindingHandle,\r
+                  Handle,\r
+                  EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  Private = WIN_NT_BLOCK_IO_PRIVATE_DATA_FROM_THIS (BlockIo);\r
+\r
+  //\r
+  // BugBug: If we need to kick people off, we need to make Uninstall Close the handles.\r
+  //         We could pass in our image handle or FLAG our open to be closed via\r
+  //         Unistall (== to saying any CloseProtocol will close our open)\r
+  //\r
+  Status = gBS->UninstallMultipleProtocolInterfaces (\r
+                  Private->EfiHandle,\r
+                  &gEfiBlockIoProtocolGuid,\r
+                  &Private->BlockIo,\r
+                  NULL\r
+                  );\r
+  if (!EFI_ERROR (Status)) {\r
+\r
+    Status = gBS->CloseProtocol (\r
+                    Handle,\r
+                    &gEfiWinNtIoProtocolGuid,\r
+                    This->DriverBindingHandle,\r
+                    Handle\r
+                    );\r
+\r
+    //\r
+    // Shut down our device\r
+    //\r
+    Private->WinNtThunk->CloseHandle (Private->NtHandle);\r
+\r
+    //\r
+    // Free our instance data\r
+    //\r
+    FreeUnicodeStringTable (Private->ControllerNameTable);\r
+\r
+    FreePool (Private);\r
+  }\r
+\r
+  return Status;\r
+}\r
+\r
+STATIC\r
+CHAR16 *\r
+GetNextElementPastTerminator (\r
+  IN  CHAR16  *EnvironmentVariable,\r
+  IN  CHAR16  Terminator\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Worker function to parse environment variables.\r
+\r
+Arguments:\r
+  EnvironmentVariable - Envirnment variable to parse.\r
+\r
+  Terminator          - Terminator to parse for.\r
+\r
+Returns:\r
+\r
+  Pointer to next eliment past the first occurence of Terminator or the '\0'\r
+  at the end of the string.\r
+\r
+--*/\r
+{\r
+  CHAR16  *Ptr;\r
+\r
+  for (Ptr = EnvironmentVariable; *Ptr != '\0'; Ptr++) {\r
+    if (*Ptr == Terminator) {\r
+      Ptr++;\r
+      break;\r
+    }\r
+  }\r
+\r
+  return Ptr;\r
+}\r
+\r
+STATIC\r
+EFI_STATUS\r
+WinNtBlockIoCreateMapping (\r
+  IN EFI_WIN_NT_IO_PROTOCOL             *WinNtIo,\r
+  IN EFI_HANDLE                         EfiDeviceHandle,\r
+  IN CHAR16                             *Filename,\r
+  IN BOOLEAN                            ReadOnly,\r
+  IN BOOLEAN                            RemovableMedia,\r
+  IN UINTN                              NumberOfBlocks,\r
+  IN UINTN                              BlockSize,\r
+  IN WIN_NT_RAW_DISK_DEVICE_TYPE        DeviceType\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  WinNtIo         - TODO: add argument description\r
+  EfiDeviceHandle - TODO: add argument description\r
+  Filename        - TODO: add argument description\r
+  ReadOnly        - TODO: add argument description\r
+  RemovableMedia  - TODO: add argument description\r
+  NumberOfBlocks  - TODO: add argument description\r
+  BlockSize       - TODO: add argument description\r
+  DeviceType      - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  TODO: add return values\r
+\r
+--*/\r
+{\r
+  EFI_STATUS              Status;\r
+  EFI_BLOCK_IO_PROTOCOL   *BlockIo;\r
+  WIN_NT_BLOCK_IO_PRIVATE *Private;\r
+  UINTN                   Index;\r
+\r
+  WinNtIo->WinNtThunk->SetErrorMode (SEM_FAILCRITICALERRORS);\r
+\r
+  Private = AllocatePool (sizeof (WIN_NT_BLOCK_IO_PRIVATE));\r
+  ASSERT (Private != NULL);\r
+\r
+  EfiInitializeLock (&Private->Lock, TPL_NOTIFY);\r
+\r
+  Private->WinNtThunk = WinNtIo->WinNtThunk;\r
+\r
+  Private->Signature  = WIN_NT_BLOCK_IO_PRIVATE_SIGNATURE;\r
+  Private->LastBlock  = NumberOfBlocks - 1;\r
+  Private->BlockSize  = BlockSize;\r
+\r
+  for (Index = 0; Filename[Index] != 0; Index++) {\r
+    Private->Filename[Index] = Filename[Index];\r
+  }\r
+\r
+  Private->Filename[Index]      = 0;\r
+\r
+  Private->ReadMode             = GENERIC_READ | (ReadOnly ? 0 : GENERIC_WRITE);\r
+  Private->ShareMode            = FILE_SHARE_READ | FILE_SHARE_WRITE;\r
+\r
+  Private->NumberOfBlocks       = NumberOfBlocks;\r
+  Private->DeviceType           = DeviceType;\r
+  Private->NtHandle             = INVALID_HANDLE_VALUE;\r
+\r
+  Private->ControllerNameTable  = NULL;\r
+\r
+  AddUnicodeString (\r
+    "eng",\r
+    gWinNtBlockIoComponentName.SupportedLanguages,\r
+    &Private->ControllerNameTable,\r
+    Private->Filename\r
+    );\r
+\r
+  BlockIo = &Private->BlockIo;\r
+  BlockIo->Revision = EFI_BLOCK_IO_PROTOCOL_REVISION;\r
+  BlockIo->Media = &Private->Media;\r
+  BlockIo->Media->BlockSize = Private->BlockSize;\r
+  BlockIo->Media->LastBlock = Private->NumberOfBlocks - 1;\r
+  BlockIo->Media->MediaId = 0;;\r
+\r
+  BlockIo->Reset = WinNtBlockIoResetBlock;\r
+  BlockIo->ReadBlocks = WinNtBlockIoReadBlocks;\r
+  BlockIo->WriteBlocks = WinNtBlockIoWriteBlocks;\r
+  BlockIo->FlushBlocks = WinNtBlockIoFlushBlocks;\r
+\r
+  BlockIo->Media->ReadOnly = ReadOnly;\r
+  BlockIo->Media->RemovableMedia = RemovableMedia;\r
+  BlockIo->Media->LogicalPartition = FALSE;\r
+  BlockIo->Media->MediaPresent = TRUE;\r
+  BlockIo->Media->WriteCaching = FALSE;\r
+\r
+  if (DeviceType == EfiWinNtVirtualDisks) {\r
+    BlockIo->Media->IoAlign = 1;\r
+\r
+    //\r
+    // Create a file to use for a virtual disk even if it does not exist.\r
+    //\r
+    Private->OpenMode = OPEN_ALWAYS;\r
+  } else if (DeviceType == EfiWinNtPhysicalDisks) {\r
+    //\r
+    // Physical disk and floppy devices require 4 byte alignment.\r
+    //\r
+    BlockIo->Media->IoAlign = 4;\r
+\r
+    //\r
+    // You can only open a physical device if it exists.\r
+    //\r
+    Private->OpenMode = OPEN_EXISTING;\r
+  } else {\r
+    ASSERT (FALSE);\r
+  }\r
+\r
+  Private->EfiHandle  = EfiDeviceHandle;\r
+  Status              = WinNtBlockIoOpenDevice (Private);\r
+  if (!EFI_ERROR (Status)) {\r
+\r
+    Status = gBS->InstallMultipleProtocolInterfaces (\r
+                    &Private->EfiHandle,\r
+                    &gEfiBlockIoProtocolGuid,\r
+                    &Private->BlockIo,\r
+                    NULL\r
+                    );\r
+    if (EFI_ERROR (Status)) {\r
+      FreeUnicodeStringTable (Private->ControllerNameTable);\r
+      FreePool (Private);\r
+    }\r
+\r
+    DEBUG ((EFI_D_INIT, "BlockDevice added: %s\n", Filename));\r
+  }\r
+\r
+  return Status;\r
+}\r
+\r
+STATIC\r
+EFI_STATUS\r
+WinNtBlockIoOpenDevice (\r
+  WIN_NT_BLOCK_IO_PRIVATE                 *Private\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  Private - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  TODO: add return values\r
+\r
+--*/\r
+{\r
+  EFI_STATUS            Status;\r
+  UINT64                FileSize;\r
+  UINT64                EndOfFile;\r
+  EFI_BLOCK_IO_PROTOCOL *BlockIo;\r
+\r
+  BlockIo = &Private->BlockIo;\r
+  EfiAcquireLock (&Private->Lock);\r
+\r
+  //\r
+  // If the device is already opened, close it\r
+  //\r
+  if (Private->NtHandle != INVALID_HANDLE_VALUE) {\r
+    BlockIo->Reset (BlockIo, FALSE);\r
+  }\r
+\r
+  //\r
+  // Open the device\r
+  //\r
+  Private->NtHandle = Private->WinNtThunk->CreateFile (\r
+                                            Private->Filename,\r
+                                            Private->ReadMode,\r
+                                            Private->ShareMode,\r
+                                            NULL,\r
+                                            Private->OpenMode,\r
+                                            0,\r
+                                            NULL\r
+                                            );\r
+\r
+  Status = Private->WinNtThunk->GetLastError ();\r
+\r
+  if (Private->NtHandle == INVALID_HANDLE_VALUE) {\r
+    DEBUG ((EFI_D_INFO, "PlOpenBlock: Could not open %s, %x\n", Private->Filename, Private->WinNtThunk->GetLastError ()));\r
+    BlockIo->Media->MediaPresent  = FALSE;\r
+    Status                        = EFI_NO_MEDIA;\r
+    goto Done;\r
+  }\r
+\r
+  if (!BlockIo->Media->MediaPresent) {\r
+    //\r
+    // BugBug: try to emulate if a CD appears - notify drivers to check it out\r
+    //\r
+    BlockIo->Media->MediaPresent = TRUE;\r
+    EfiReleaseLock (&Private->Lock);\r
+    EfiAcquireLock (&Private->Lock);\r
+  }\r
+\r
+  //\r
+  // get the size of the file\r
+  //\r
+  Status = SetFilePointer64 (Private, 0, &FileSize, FILE_END);\r
+\r
+  if (EFI_ERROR (Status)) {\r
+    FileSize = MultU64x32 (Private->NumberOfBlocks, Private->BlockSize);\r
+    if (Private->DeviceType == EfiWinNtVirtualDisks) {\r
+      DEBUG ((EFI_D_ERROR, "PlOpenBlock: Could not get filesize of %s\n", Private->Filename));\r
+      Status = EFI_UNSUPPORTED;\r
+      goto Done;\r
+    }\r
+  }\r
+\r
+  if (Private->NumberOfBlocks == 0) {\r
+    Private->NumberOfBlocks = DivU64x32 (FileSize, Private->BlockSize);\r
+  }\r
+\r
+  EndOfFile = MultU64x32 (Private->NumberOfBlocks, Private->BlockSize);\r
+\r
+  if (FileSize != EndOfFile) {\r
+    //\r
+    // file is not the proper size, change it\r
+    //\r
+    DEBUG ((EFI_D_INIT, "PlOpenBlock: Initializing block device: %hs\n", Private->Filename));\r
+\r
+    //\r
+    // first set it to 0\r
+    //\r
+    SetFilePointer64 (Private, 0, NULL, FILE_BEGIN);\r
+    Private->WinNtThunk->SetEndOfFile (Private->NtHandle);\r
+\r
+    //\r
+    // then set it to the needed file size (OS will zero fill it)\r
+    //\r
+    SetFilePointer64 (Private, EndOfFile, NULL, FILE_BEGIN);\r
+    Private->WinNtThunk->SetEndOfFile (Private->NtHandle);\r
+  }\r
+\r
+  DEBUG ((EFI_D_INIT, "%HPlOpenBlock: opened %s%N\n", Private->Filename));\r
+  Status = EFI_SUCCESS;\r
+\r
+Done:\r
+  if (EFI_ERROR (Status)) {\r
+    if (Private->NtHandle != INVALID_HANDLE_VALUE) {\r
+      BlockIo->Reset (BlockIo, FALSE);\r
+    }\r
+  }\r
+\r
+  EfiReleaseLock (&Private->Lock);\r
+  return Status;\r
+}\r
+\r
+STATIC\r
+EFI_STATUS\r
+WinNtBlockIoError (\r
+  IN WIN_NT_BLOCK_IO_PRIVATE      *Private\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  Private - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  TODO: add return values\r
+\r
+--*/\r
+{\r
+  EFI_BLOCK_IO_PROTOCOL *BlockIo;\r
+  EFI_STATUS            Status;\r
+  BOOLEAN               ReinstallBlockIoFlag;\r
+\r
+  BlockIo = &Private->BlockIo;\r
+\r
+  switch (Private->WinNtThunk->GetLastError ()) {\r
+\r
+  case ERROR_NOT_READY:\r
+    Status                        = EFI_NO_MEDIA;\r
+    BlockIo->Media->ReadOnly      = FALSE;\r
+    BlockIo->Media->MediaPresent  = FALSE;\r
+    ReinstallBlockIoFlag          = FALSE;\r
+    break;\r
+\r
+  case ERROR_WRONG_DISK:\r
+    BlockIo->Media->ReadOnly      = FALSE;\r
+    BlockIo->Media->MediaPresent  = TRUE;\r
+    BlockIo->Media->MediaId += 1;\r
+    ReinstallBlockIoFlag  = TRUE;\r
+    Status                = EFI_MEDIA_CHANGED;\r
+    break;\r
+\r
+  case ERROR_WRITE_PROTECT:\r
+    BlockIo->Media->ReadOnly  = TRUE;\r
+    ReinstallBlockIoFlag      = FALSE;\r
+    Status                    = EFI_WRITE_PROTECTED;\r
+    break;\r
+\r
+  default:\r
+    ReinstallBlockIoFlag  = FALSE;\r
+    Status                = EFI_DEVICE_ERROR;\r
+    break;\r
+  }\r
+\r
+  if (ReinstallBlockIoFlag) {\r
+    BlockIo->Reset (BlockIo, FALSE);\r
+\r
+    gBS->ReinstallProtocolInterface (\r
+          Private->EfiHandle,\r
+          &gEfiBlockIoProtocolGuid,\r
+          BlockIo,\r
+          BlockIo\r
+          );\r
+  }\r
+\r
+  return Status;\r
+}\r
+\r
+STATIC\r
+EFI_STATUS\r
+WinNtBlockIoReadWriteCommon (\r
+  IN  WIN_NT_BLOCK_IO_PRIVATE     *Private,\r
+  IN UINT32                       MediaId,\r
+  IN EFI_LBA                      Lba,\r
+  IN UINTN                        BufferSize,\r
+  IN VOID                         *Buffer,\r
+  IN CHAR8                        *CallerName\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  Private     - TODO: add argument description\r
+  MediaId     - TODO: add argument description\r
+  Lba         - TODO: add argument description\r
+  BufferSize  - TODO: add argument description\r
+  Buffer      - TODO: add argument description\r
+  CallerName  - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  EFI_NO_MEDIA - TODO: Add description for return value\r
+  EFI_MEDIA_CHANGED - TODO: Add description for return value\r
+  EFI_INVALID_PARAMETER - TODO: Add description for return value\r
+  EFI_SUCCESS - TODO: Add description for return value\r
+  EFI_BAD_BUFFER_SIZE - TODO: Add description for return value\r
+  EFI_INVALID_PARAMETER - TODO: Add description for return value\r
+  EFI_SUCCESS - TODO: Add description for return value\r
+\r
+--*/\r
+{\r
+  EFI_STATUS  Status;\r
+  UINTN       BlockSize;\r
+  UINT64      LastBlock;\r
+  INT64       DistanceToMove;\r
+  UINT64      DistanceMoved;\r
+\r
+  if (Private->NtHandle == INVALID_HANDLE_VALUE) {\r
+    Status = WinNtBlockIoOpenDevice (Private);\r
+    if (EFI_ERROR (Status)) {\r
+      return Status;\r
+    }\r
+  }\r
+\r
+  if (!Private->Media.MediaPresent) {\r
+    DEBUG ((EFI_D_INIT, "%s: No Media\n", CallerName));\r
+    return EFI_NO_MEDIA;\r
+  }\r
+\r
+  if (Private->Media.MediaId != MediaId) {\r
+    return EFI_MEDIA_CHANGED;\r
+  }\r
+\r
+  if ((UINT32) Buffer % Private->Media.IoAlign != 0) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  //\r
+  // Verify buffer size\r
+  //\r
+  BlockSize = Private->BlockSize;\r
+  if (BufferSize == 0) {\r
+    DEBUG ((EFI_D_INIT, "%s: Zero length read\n", CallerName));\r
+    return EFI_SUCCESS;\r
+  }\r
+\r
+  if ((BufferSize % BlockSize) != 0) {\r
+    DEBUG ((EFI_D_INIT, "%s: Invalid read size\n", CallerName));\r
+    return EFI_BAD_BUFFER_SIZE;\r
+  }\r
+\r
+  LastBlock = Lba + (BufferSize / BlockSize) - 1;\r
+  if (LastBlock > Private->LastBlock) {\r
+    DEBUG ((EFI_D_INIT, "ReadBlocks: Attempted to read off end of device\n"));\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+  //\r
+  // Seek to End of File\r
+  //\r
+  DistanceToMove = MultU64x32 (Lba, BlockSize);\r
+  Status = SetFilePointer64 (Private, DistanceToMove, &DistanceMoved, FILE_BEGIN);\r
+\r
+  if (EFI_ERROR (Status)) {\r
+    DEBUG ((EFI_D_INIT, "WriteBlocks: SetFilePointer failed\n"));\r
+    return WinNtBlockIoError (Private);\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+STATIC\r
+EFI_STATUS\r
+EFIAPI\r
+WinNtBlockIoReadBlocks (\r
+  IN EFI_BLOCK_IO_PROTOCOL  *This,\r
+  IN UINT32                 MediaId,\r
+  IN EFI_LBA                Lba,\r
+  IN UINTN                  BufferSize,\r
+  OUT VOID                  *Buffer\r
+  )\r
+/*++\r
+\r
+  Routine Description:\r
+    Read BufferSize bytes from Lba into Buffer.\r
+\r
+  Arguments:\r
+    This       - Protocol instance pointer.\r
+    MediaId    - Id of the media, changes every time the media is replaced.\r
+    Lba        - The starting Logical Block Address to read from\r
+    BufferSize - Size of Buffer, must be a multiple of device block size.\r
+    Buffer     - Buffer containing read data\r
+\r
+  Returns:\r
+    EFI_SUCCESS           - The data was read correctly from the device.\r
+    EFI_DEVICE_ERROR      - The device reported an error while performing the read.\r
+    EFI_NO_MEDIA          - There is no media in the device.\r
+    EFI_MEDIA_CHANGED     - The MediaId does not matched the current device.\r
+    EFI_BAD_BUFFER_SIZE   - The Buffer was not a multiple of the block size of the\r
+                            device.\r
+    EFI_INVALID_PARAMETER - The read request contains device addresses that are not\r
+                            valid for the device.\r
+\r
+--*/\r
+{\r
+  WIN_NT_BLOCK_IO_PRIVATE *Private;\r
+  BOOL                    Flag;\r
+  EFI_STATUS              Status;\r
+  DWORD                   BytesRead;\r
+  EFI_TPL                 OldTpl;\r
+\r
+  OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
+\r
+  Private = WIN_NT_BLOCK_IO_PRIVATE_DATA_FROM_THIS (This);\r
+\r
+  Status  = WinNtBlockIoReadWriteCommon (Private, MediaId, Lba, BufferSize, Buffer, "WinNtReadBlocks");\r
+  if (EFI_ERROR (Status)) {\r
+    goto Done;\r
+  }\r
+\r
+  Flag = Private->WinNtThunk->ReadFile (Private->NtHandle, Buffer, (DWORD) BufferSize, (LPDWORD) &BytesRead, NULL);\r
+  if (!Flag || (BytesRead != BufferSize)) {\r
+    DEBUG ((EFI_D_INIT, "ReadBlocks: ReadFile failed. (%d)\n", Private->WinNtThunk->GetLastError ()));\r
+    Status = WinNtBlockIoError (Private);\r
+    goto Done;\r
+  }\r
+\r
+  //\r
+  // If we wrote then media is present.\r
+  //\r
+  This->Media->MediaPresent = TRUE;\r
+  Status = EFI_SUCCESS;\r
+\r
+Done:\r
+  gBS->RestoreTPL (OldTpl);\r
+  return Status;\r
+}\r
+\r
+STATIC\r
+EFI_STATUS\r
+EFIAPI\r
+WinNtBlockIoWriteBlocks (\r
+  IN EFI_BLOCK_IO_PROTOCOL  *This,\r
+  IN UINT32                 MediaId,\r
+  IN EFI_LBA                Lba,\r
+  IN UINTN                  BufferSize,\r
+  IN VOID                   *Buffer\r
+  )\r
+/*++\r
+\r
+  Routine Description:\r
+    Write BufferSize bytes from Lba into Buffer.\r
+\r
+  Arguments:\r
+    This       - Protocol instance pointer.\r
+    MediaId    - Id of the media, changes every time the media is replaced.\r
+    Lba        - The starting Logical Block Address to read from\r
+    BufferSize - Size of Buffer, must be a multiple of device block size.\r
+    Buffer     - Buffer containing read data\r
+\r
+  Returns:\r
+    EFI_SUCCESS           - The data was written correctly to the device.\r
+    EFI_WRITE_PROTECTED   - The device can not be written to.\r
+    EFI_DEVICE_ERROR      - The device reported an error while performing the write.\r
+    EFI_NO_MEDIA          - There is no media in the device.\r
+    EFI_MEDIA_CHNAGED     - The MediaId does not matched the current device.\r
+    EFI_BAD_BUFFER_SIZE   - The Buffer was not a multiple of the block size of the\r
+                            device.\r
+    EFI_INVALID_PARAMETER - The write request contains a LBA that is not\r
+                            valid for the device.\r
+\r
+--*/\r
+{\r
+  WIN_NT_BLOCK_IO_PRIVATE *Private;\r
+  UINTN                   BytesWritten;\r
+  BOOL                    Flag;\r
+  EFI_STATUS              Status;\r
+  EFI_TPL                 OldTpl;\r
+\r
+  OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
+\r
+  Private = WIN_NT_BLOCK_IO_PRIVATE_DATA_FROM_THIS (This);\r
+\r
+  Status  = WinNtBlockIoReadWriteCommon (Private, MediaId, Lba, BufferSize, Buffer, "WinNtWriteBlocks");\r
+  if (EFI_ERROR (Status)) {\r
+    goto Done;\r
+  }\r
+\r
+  Flag = Private->WinNtThunk->WriteFile (Private->NtHandle, Buffer, (DWORD) BufferSize, (LPDWORD) &BytesWritten, NULL);\r
+  if (!Flag || (BytesWritten != BufferSize)) {\r
+    DEBUG ((EFI_D_INIT, "ReadBlocks: WriteFile failed. (%d)\n", Private->WinNtThunk->GetLastError ()));\r
+    Status = WinNtBlockIoError (Private);\r
+    goto Done;\r
+  }\r
+\r
+  //\r
+  // If the write succeeded, we are not write protected and media is present.\r
+  //\r
+  This->Media->MediaPresent = TRUE;\r
+  This->Media->ReadOnly     = FALSE;\r
+  Status = EFI_SUCCESS;\r
+\r
+Done:\r
+  gBS->RestoreTPL (OldTpl);\r
+  return Status;\r
+\r
+}\r
+\r
+STATIC\r
+EFI_STATUS\r
+EFIAPI\r
+WinNtBlockIoFlushBlocks (\r
+  IN EFI_BLOCK_IO_PROTOCOL  *This\r
+  )\r
+/*++\r
+\r
+  Routine Description:\r
+    Flush the Block Device.\r
+\r
+  Arguments:\r
+    This             - Protocol instance pointer.\r
+\r
+  Returns:\r
+    EFI_SUCCESS      - All outstanding data was written to the device\r
+    EFI_DEVICE_ERROR - The device reported an error while writting back the data\r
+    EFI_NO_MEDIA     - There is no media in the device.\r
+\r
+--*/\r
+{\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+STATIC\r
+EFI_STATUS\r
+EFIAPI\r
+WinNtBlockIoResetBlock (\r
+  IN EFI_BLOCK_IO_PROTOCOL  *This,\r
+  IN BOOLEAN                ExtendedVerification\r
+  )\r
+/*++\r
+\r
+  Routine Description:\r
+    Reset the Block Device.\r
+\r
+  Arguments:\r
+    This                 - Protocol instance pointer.\r
+    ExtendedVerification - Driver may perform diagnostics on reset.\r
+\r
+  Returns:\r
+    EFI_SUCCESS           - The device was reset.\r
+    EFI_DEVICE_ERROR      - The device is not functioning properly and could\r
+                            not be reset.\r
+\r
+--*/\r
+{\r
+  WIN_NT_BLOCK_IO_PRIVATE *Private;\r
+  EFI_TPL                 OldTpl;\r
+\r
+  OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
+\r
+  Private = WIN_NT_BLOCK_IO_PRIVATE_DATA_FROM_THIS (This);\r
+\r
+  if (Private->NtHandle != INVALID_HANDLE_VALUE) {\r
+    Private->WinNtThunk->CloseHandle (Private->NtHandle);\r
+    Private->NtHandle = INVALID_HANDLE_VALUE;\r
+  }\r
+\r
+  gBS->RestoreTPL (OldTpl);\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+UINTN\r
+Atoi (\r
+  CHAR16  *String\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Convert a unicode string to a UINTN\r
+\r
+Arguments:\r
+\r
+  String - Unicode string.\r
+\r
+Returns:\r
+\r
+  UINTN of the number represented by String.\r
+\r
+--*/\r
+{\r
+  UINTN   Number;\r
+  CHAR16  *Str;\r
+\r
+  //\r
+  // skip preceeding white space\r
+  //\r
+  Str = String;\r
+  while ((*Str) && (*Str == ' ')) {\r
+    Str++;\r
+  }\r
+  //\r
+  // Convert ot a Number\r
+  //\r
+  Number = 0;\r
+  while (*Str != '\0') {\r
+    if ((*Str >= '0') && (*Str <= '9')) {\r
+      Number = (Number * 10) +*Str - '0';\r
+    } else {\r
+      break;\r
+    }\r
+\r
+    Str++;\r
+  }\r
+\r
+  return Number;\r
+}\r
+\r
+EFI_STATUS\r
+SetFilePointer64 (\r
+  IN  WIN_NT_BLOCK_IO_PRIVATE    *Private,\r
+  IN  INT64                      DistanceToMove,\r
+  OUT UINT64                     *NewFilePointer,\r
+  IN  DWORD                      MoveMethod\r
+  )\r
+/*++\r
+\r
+This function extends the capability of SetFilePointer to accept 64 bit parameters\r
+\r
+--*/\r
+// TODO: function comment is missing 'Routine Description:'\r
+// TODO: function comment is missing 'Arguments:'\r
+// TODO: function comment is missing 'Returns:'\r
+// TODO:    Private - add argument and description to function comment\r
+// TODO:    DistanceToMove - add argument and description to function comment\r
+// TODO:    NewFilePointer - add argument and description to function comment\r
+// TODO:    MoveMethod - add argument and description to function comment\r
+{\r
+  EFI_STATUS    Status;\r
+  LARGE_INTEGER LargeInt;\r
+  UINT32        ErrorCode;\r
+\r
+  LargeInt.QuadPart = DistanceToMove;\r
+  Status            = EFI_SUCCESS;\r
+\r
+  LargeInt.LowPart = Private->WinNtThunk->SetFilePointer (\r
+                                            Private->NtHandle,\r
+                                            LargeInt.LowPart,\r
+                                            &LargeInt.HighPart,\r
+                                            MoveMethod\r
+                                            );\r
+\r
+  if (LargeInt.LowPart == -1 &&\r
+      (ErrorCode = Private->WinNtThunk->GetLastError ()) != NO_ERROR) {\r
+    Status = EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  if (NewFilePointer != NULL) {\r
+    *NewFilePointer = LargeInt.QuadPart;\r
+  }\r
+\r
+  return Status;\r
+}\r
diff --git a/Nt32Pkg/WinNtBlockIoDxe/WinNtBlockIo.h b/Nt32Pkg/WinNtBlockIoDxe/WinNtBlockIo.h
new file mode 100644 (file)
index 0000000..f4ec37c
--- /dev/null
@@ -0,0 +1,487 @@
+/*++\r
+\r
+Copyright (c) 2006, Intel Corporation                                                         \r
+All rights reserved. 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
+                                                                                          \r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     \r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             \r
+\r
+Module Name:\r
+\r
+  WinNtBlockIo.h\r
+\r
+Abstract:\r
+\r
+  Produce block IO abstractions for real devices on your PC using Win32 APIs.\r
+  The configuration of what devices to mount or emulate comes from NT \r
+  environment variables. The variables must be visible to the Microsoft* \r
+  Developer Studio for them to work.\r
+\r
+  * Other names and brands may be claimed as the property of others.\r
+\r
+--*/\r
+\r
+#ifndef _WIN_NT_BLOCK_IO_H_\r
+#define _WIN_NT_BLOCK_IO_H_\r
+\r
+#include <Uefi.h>\r
+#include <WinNtDxe.h>\r
+#include <Protocol/WinNtThunk.h>\r
+#include <Protocol/WinNtIo.h>\r
+#include <Protocol/BlockIo.h>\r
+#include <Protocol/ComponentName.h>\r
+#include <Protocol/DriverBinding.h>\r
+//\r
+// The Library classes this module consumes\r
+//\r
+#include <Library/DebugLib.h>\r
+#include <Library/BaseLib.h>\r
+#include <Library/UefiDriverEntryPoint.h>\r
+#include <Library/UefiLib.h>\r
+#include <Library/BaseMemoryLib.h>\r
+#include <Library/UefiBootServicesTableLib.h>\r
+#include <Library/MemoryAllocationLib.h>\r
+\r
+#define FILENAME_BUFFER_SIZE  80\r
+\r
+//\r
+// Language supported for driverconfiguration protocol\r
+//\r
+#define LANGUAGESUPPORTED "eng"\r
+\r
+typedef enum {\r
+  EfiWinNtVirtualDisks,\r
+  EfiWinNtPhysicalDisks,\r
+  EifWinNtMaxTypeDisks\r
+} WIN_NT_RAW_DISK_DEVICE_TYPE;\r
+\r
+#define WIN_NT_BLOCK_IO_PRIVATE_SIGNATURE EFI_SIGNATURE_32 ('N', 'T', 'b', 'k')\r
+typedef struct {\r
+  UINTN                       Signature;\r
+\r
+  EFI_LOCK                    Lock;\r
+\r
+  CHAR16                      Filename[FILENAME_BUFFER_SIZE];\r
+  UINTN                       ReadMode;\r
+  UINTN                       ShareMode;\r
+  UINTN                       OpenMode;\r
+\r
+  HANDLE                      NtHandle;\r
+  WIN_NT_RAW_DISK_DEVICE_TYPE DeviceType;\r
+\r
+  UINT64                      LastBlock;\r
+  UINTN                       BlockSize;\r
+  UINT64                      NumberOfBlocks;\r
+\r
+  EFI_HANDLE                  EfiHandle;\r
+  EFI_BLOCK_IO_PROTOCOL       BlockIo;\r
+  EFI_BLOCK_IO_MEDIA          Media;\r
+\r
+  EFI_UNICODE_STRING_TABLE    *ControllerNameTable;\r
+\r
+  EFI_WIN_NT_THUNK_PROTOCOL   *WinNtThunk;\r
+\r
+} WIN_NT_BLOCK_IO_PRIVATE;\r
+\r
+#define WIN_NT_BLOCK_IO_PRIVATE_DATA_FROM_THIS(a) \\r
+         CR(a, WIN_NT_BLOCK_IO_PRIVATE, BlockIo, WIN_NT_BLOCK_IO_PRIVATE_SIGNATURE)\r
+\r
+#define LIST_BUFFER_SIZE  512\r
+\r
+//\r
+// Block I/O Global Variables\r
+//\r
+extern EFI_DRIVER_BINDING_PROTOCOL        gWinNtBlockIoDriverBinding;\r
+extern EFI_COMPONENT_NAME_PROTOCOL        gWinNtBlockIoComponentName;\r
+extern EFI_DRIVER_CONFIGURATION_PROTOCOL  gWinNtBlockIoDriverConfiguration;\r
+extern EFI_DRIVER_DIAGNOSTICS_PROTOCOL    gWinNtBlockIoDriverDiagnostics;\r
+\r
+//\r
+// EFI Driver Binding Functions\r
+//\r
+EFI_STATUS\r
+EFIAPI\r
+WinNtBlockIoDriverBindingSupported (\r
+  IN EFI_DRIVER_BINDING_PROTOCOL    *This,\r
+  IN  EFI_HANDLE                    Handle,\r
+  IN  EFI_DEVICE_PATH_PROTOCOL      *RemainingDevicePath\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  This                - TODO: add argument description\r
+  Handle              - TODO: add argument description\r
+  RemainingDevicePath - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+WinNtBlockIoDriverBindingStart (\r
+  IN EFI_DRIVER_BINDING_PROTOCOL    *This,\r
+  IN  EFI_HANDLE                    Handle,\r
+  IN  EFI_DEVICE_PATH_PROTOCOL      *RemainingDevicePath\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  This                - TODO: add argument description\r
+  Handle              - TODO: add argument description\r
+  RemainingDevicePath - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+WinNtBlockIoDriverBindingStop (\r
+  IN  EFI_DRIVER_BINDING_PROTOCOL   *This,\r
+  IN  EFI_HANDLE                    Handle,\r
+  IN  UINTN                         NumberOfChildren,\r
+  IN  EFI_HANDLE                    *ChildHandleBuffer\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  This              - TODO: add argument description\r
+  Handle            - TODO: add argument description\r
+  NumberOfChildren  - TODO: add argument description\r
+  ChildHandleBuffer - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+//\r
+// Block IO protocol member functions\r
+//\r
+STATIC\r
+EFI_STATUS\r
+EFIAPI\r
+WinNtBlockIoReadBlocks (\r
+  IN EFI_BLOCK_IO_PROTOCOL  *This,\r
+  IN UINT32                 MediaId,\r
+  IN EFI_LBA                Lba,\r
+  IN UINTN                  BufferSize,\r
+  OUT VOID                  *Buffer\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  This        - TODO: add argument description\r
+  MediaId     - TODO: add argument description\r
+  Lba         - TODO: add argument description\r
+  BufferSize  - TODO: add argument description\r
+  Buffer      - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+STATIC\r
+EFI_STATUS\r
+EFIAPI\r
+WinNtBlockIoWriteBlocks (\r
+  IN EFI_BLOCK_IO_PROTOCOL  *This,\r
+  IN UINT32                 MediaId,\r
+  IN EFI_LBA                Lba,\r
+  IN UINTN                  BufferSize,\r
+  IN VOID                   *Buffer\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  This        - TODO: add argument description\r
+  MediaId     - TODO: add argument description\r
+  Lba         - TODO: add argument description\r
+  BufferSize  - TODO: add argument description\r
+  Buffer      - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+STATIC\r
+EFI_STATUS\r
+EFIAPI\r
+WinNtBlockIoFlushBlocks (\r
+  IN EFI_BLOCK_IO_PROTOCOL  *This\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  This  - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+STATIC\r
+EFI_STATUS\r
+EFIAPI\r
+WinNtBlockIoResetBlock (\r
+  IN EFI_BLOCK_IO_PROTOCOL  *This,\r
+  IN BOOLEAN                ExtendedVerification\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  This                  - TODO: add argument description\r
+  ExtendedVerification  - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+//\r
+// Private Worker functions\r
+//\r
+STATIC\r
+EFI_STATUS\r
+WinNtBlockIoCreateMapping (\r
+  IN EFI_WIN_NT_IO_PROTOCOL             *WinNtIo,\r
+  IN EFI_HANDLE                         EfiDeviceHandle,\r
+  IN CHAR16                             *Filename,\r
+  IN BOOLEAN                            ReadOnly,\r
+  IN BOOLEAN                            RemovableMedia,\r
+  IN UINTN                              NumberOfBlocks,\r
+  IN UINTN                              BlockSize,\r
+  IN WIN_NT_RAW_DISK_DEVICE_TYPE        DeviceType\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  WinNtIo         - TODO: add argument description\r
+  EfiDeviceHandle - TODO: add argument description\r
+  Filename        - TODO: add argument description\r
+  ReadOnly        - TODO: add argument description\r
+  RemovableMedia  - TODO: add argument description\r
+  NumberOfBlocks  - TODO: add argument description\r
+  BlockSize       - TODO: add argument description\r
+  DeviceType      - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+STATIC\r
+EFI_STATUS\r
+WinNtBlockIoReadWriteCommon (\r
+  IN  WIN_NT_BLOCK_IO_PRIVATE *Private,\r
+  IN UINT32                   MediaId,\r
+  IN EFI_LBA                  Lba,\r
+  IN UINTN                    BufferSize,\r
+  IN VOID                     *Buffer,\r
+  IN CHAR8                    *CallerName\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  Private     - TODO: add argument description\r
+  MediaId     - TODO: add argument description\r
+  Lba         - TODO: add argument description\r
+  BufferSize  - TODO: add argument description\r
+  Buffer      - TODO: add argument description\r
+  CallerName  - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+STATIC\r
+EFI_STATUS\r
+WinNtBlockIoError (\r
+  IN WIN_NT_BLOCK_IO_PRIVATE      *Private\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  Private - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+STATIC\r
+EFI_STATUS\r
+WinNtBlockIoOpenDevice (\r
+  WIN_NT_BLOCK_IO_PRIVATE         *Private\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  Private - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+STATIC\r
+CHAR16                                    *\r
+GetNextElementPastTerminator (\r
+  IN  CHAR16  *EnvironmentVariable,\r
+  IN  CHAR16  Terminator\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  EnvironmentVariable - TODO: add argument description\r
+  Terminator          - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+\r
+\r
+EFI_STATUS\r
+SetFilePointer64 (\r
+  IN  WIN_NT_BLOCK_IO_PRIVATE    *Private,\r
+  IN  INT64                      DistanceToMove,\r
+  OUT UINT64                     *NewFilePointer,\r
+  IN  DWORD                      MoveMethod\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  Private         - TODO: add argument description\r
+  DistanceToMove  - TODO: add argument description\r
+  NewFilePointer  - TODO: add argument description\r
+  MoveMethod      - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+UINTN\r
+Atoi (\r
+  CHAR16  *String\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  String  - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+#endif\r
diff --git a/Nt32Pkg/WinNtBlockIoDxe/WinNtBlockIo.inf b/Nt32Pkg/WinNtBlockIoDxe/WinNtBlockIo.inf
new file mode 100644 (file)
index 0000000..436a22a
--- /dev/null
@@ -0,0 +1,120 @@
+#/** @file\r
+# Block Io driver\r
+#\r
+# Produce block IO abstractions for real devices on your PC using Win32 APIs.\r
+#  The configuration of what devices to mount or emulate comes from NT\r
+#  environment variables. The variables must be visible to the Microsoft*\r
+#  Developer Studio for them to work.\r
+# Copyright (c) 2006 - 2007, Intel Corporation\r
+#\r
+#  All rights reserved. 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
+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#\r
+#\r
+#**/\r
+\r
+################################################################################\r
+#\r
+# Defines Section - statements that will be processed to create a Makefile.\r
+#\r
+################################################################################\r
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = WinNtBlockIo\r
+  FILE_GUID                      = F479E147-A125-11d4-BCFC-0080C73C8881\r
+  MODULE_TYPE                    = UEFI_DRIVER\r
+  VERSION_STRING                 = 1.0\r
+  EDK_RELEASE_VERSION            = 0x00020000\r
+  EFI_SPECIFICATION_VERSION      = 0x00020000\r
+\r
+  ENTRY_POINT                    = InitializeWinNtBlockIo\r
+\r
+#\r
+# The following information is for reference only and not required by the build tools.\r
+#\r
+#  VALID_ARCHITECTURES           = IA32\r
+#\r
+#  DRIVER_BINDING                =  gWinNtBlockIoDriverBinding                   \r
+#  COMPONENT_NAME                =  gWinNtBlockIoComponentName                   \r
+#  DRIVER_DIAG                   =  gWinNtBlockIoDriverDiagnostics               \r
+#\r
+\r
+################################################################################\r
+#\r
+# Sources Section - list of files that are required for the build to succeed.\r
+#\r
+################################################################################\r
+\r
+[Sources.common]\r
+  DriverDiagnostics.c\r
+  DriverConfiguration.c\r
+  ComponentName.c\r
+  WinNtBlockIo.c\r
+  WinNtBlockIo.h\r
+\r
+\r
+################################################################################\r
+#\r
+# Includes Section - list of Include locations that are required for\r
+#                    this module.\r
+#\r
+################################################################################\r
+\r
+[Includes]\r
+  $(WORKSPACE)/MdePkgPkg/Include/Library\r
+\r
+################################################################################\r
+#\r
+# Package Dependency Section - list of Package files that are required for\r
+#                              this module.\r
+#\r
+################################################################################\r
+\r
+[Packages]\r
+  Nt32Pkg/Nt32Pkg.dec\r
+  MdePkg/MdePkg.dec\r
+\r
+\r
+################################################################################\r
+#\r
+# Library Class Section - list of Library Classes that are required for\r
+#                         this module.\r
+#\r
+################################################################################\r
+\r
+[LibraryClasses]\r
+  MemoryAllocationLib\r
+  UefiBootServicesTableLib\r
+  BaseMemoryLib\r
+  UefiLib\r
+  UefiDriverEntryPoint\r
+  BaseLib\r
+  DebugLib\r
+\r
+\r
+################################################################################\r
+#\r
+# Guid C Name Section - list of Guids that this module uses or produces.\r
+#\r
+################################################################################\r
+\r
+[Guids]\r
+  gEfiWinNtPhysicalDisksGuid                    # SOMETIMES_CONSUMED\r
+  gEfiWinNtVirtualDisksGuid                     # ALWAYS_CONSUMED\r
+\r
+\r
+################################################################################\r
+#\r
+# Protocol C Name Section - list of Protocol and Protocol Notify C Names\r
+#                           that this module uses or produces.\r
+#\r
+################################################################################\r
+\r
+[Protocols]\r
+  gEfiBlockIoProtocolGuid                       # PROTOCOL BY_START\r
+  gEfiWinNtIoProtocolGuid                       # PROTOCOL TO_START\r
+\r
diff --git a/Nt32Pkg/WinNtBlockIoDxe/WinNtBlockIo.msa b/Nt32Pkg/WinNtBlockIoDxe/WinNtBlockIo.msa
new file mode 100644 (file)
index 0000000..afbf8de
--- /dev/null
@@ -0,0 +1,89 @@
+<?xml version="1.0" encoding="UTF-8"?>\r
+<ModuleSurfaceArea xmlns="http://www.TianoCore.org/2006/Edk2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">\r
+  <MsaHeader>\r
+    <ModuleName>WinNtBlockIo</ModuleName>\r
+    <ModuleType>UEFI_DRIVER</ModuleType>\r
+    <GuidValue>F479E147-A125-11d4-BCFC-0080C73C8881</GuidValue>\r
+    <Version>1.0</Version>\r
+    <Abstract>Block Io driver</Abstract>\r
+    <Description>Produce block IO abstractions for real devices on your PC using Win32 APIs.\r
+      The configuration of what devices to mount or emulate comes from NT\r
+      environment variables. The variables must be visible to the Microsoft*\r
+      Developer Studio for them to work.</Description>\r
+    <Copyright>Copyright (c) 2006 - 2007, Intel Corporation</Copyright>\r
+    <License>All rights reserved. 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
+      THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+      WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.</License>\r
+    <Specification>FRAMEWORK_BUILD_PACKAGING_SPECIFICATION   0x00000052</Specification>\r
+  </MsaHeader>\r
+  <ModuleDefinitions>\r
+    <SupportedArchitectures>IA32</SupportedArchitectures>\r
+    <BinaryModule>false</BinaryModule>\r
+    <OutputFileBasename>WinNtBlockIo</OutputFileBasename>\r
+  </ModuleDefinitions>\r
+  <LibraryClassDefinitions>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>DebugLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>BaseLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>UefiDriverModelLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>UefiDriverEntryPoint</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>UefiLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>BaseMemoryLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>UefiBootServicesTableLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>MemoryAllocationLib</Keyword>\r
+    </LibraryClass>\r
+  </LibraryClassDefinitions>\r
+  <SourceFiles>\r
+    <Filename>WinNtBlockIo.h</Filename>\r
+    <Filename>WinNtBlockIo.c</Filename>\r
+    <Filename>ComponentName.c</Filename>\r
+    <Filename>DriverConfiguration.c</Filename>\r
+    <Filename>DriverDiagnostics.c</Filename>\r
+  </SourceFiles>\r
+  <PackageDependencies>\r
+    <Package PackageGuid="5e0e9358-46b6-4ae2-8218-4ab8b9bbdcec"/>\r
+    <Package PackageGuid="0fb2aa2d-10d5-40a5-a9dc-060c12a4a3f3"/>\r
+  </PackageDependencies>\r
+  <Protocols>\r
+    <Protocol Usage="TO_START">\r
+      <ProtocolCName>gEfiWinNtIoProtocolGuid</ProtocolCName>\r
+    </Protocol>\r
+    <Protocol Usage="BY_START">\r
+      <ProtocolCName>gEfiBlockIoProtocolGuid</ProtocolCName>\r
+    </Protocol>\r
+  </Protocols>\r
+  <Guids>\r
+    <GuidCNames Usage="ALWAYS_CONSUMED">\r
+      <GuidCName>gEfiWinNtVirtualDisksGuid</GuidCName>\r
+    </GuidCNames>\r
+    <GuidCNames Usage="SOMETIMES_CONSUMED">\r
+      <GuidCName>gEfiWinNtPhysicalDisksGuid</GuidCName>\r
+    </GuidCNames>\r
+  </Guids>\r
+  <Externs>\r
+    <Specification>EFI_SPECIFICATION_VERSION 0x00020000</Specification>\r
+    <Specification>EDK_RELEASE_VERSION 0x00020000</Specification>\r
+    <Extern>\r
+      <DriverBinding>gWinNtBlockIoDriverBinding</DriverBinding>\r
+      <ComponentName>gWinNtBlockIoComponentName</ComponentName>\r
+      <DriverDiag>gWinNtBlockIoDriverDiagnostics</DriverDiag>\r
+    </Extern>\r
+  </Externs>\r
+</ModuleSurfaceArea>
\ No newline at end of file