- NDK 0.98, now with versionned headers. Too many changes to list, see the TinyKRNL...
[reactos.git] / reactos / drivers / storage / diskdump / diskdump.c
index 927af75..cc17160 100644 (file)
 
 /* INCLUDES *****************************************************************/
 
-#include <ddk/ntddk.h>
-#include <ddk/scsi.h>
-#include <ddk/class2.h>
-#include <ddk/ntddscsi.h>
-#include <napi/core.h>
+#include <ntddk.h>
+#include <scsi.h>
+#include <ntdddisk.h>
+#include <ntddscsi.h>
+#include <include/class2.h>
+#include <diskdump/diskdump.h>
+#include <ndk/rtlfuncs.h>
+
 #include "../scsiport/scsiport_int.h"
 
 #define NDEBUG
@@ -41,6 +44,7 @@
 #undef VERSION
 #define VERSION  "0.0.1"
 
+#undef KeGetCurrentIrql
 /* PROTOTYPES ***************************************************************/
 
 NTSTATUS STDCALL
@@ -184,7 +188,7 @@ DiskDumpBuildRequest(LARGE_INTEGER StartingOffset, PMDL Mdl)
   RtlZeroMemory(Cdb, MAXIMUM_CDB_SIZE);
 
   Cdb->CDB10.LogicalUnitNumber = CoreDumpClass2DeviceExtension->Lun;
-  TransferBlocks = (USHORT)(PAGE_SIZE >> 
+  TransferBlocks = (USHORT)(PAGE_SIZE >>
                            CoreDumpClass2DeviceExtension->SectorShift);
 
   /* Copy little endian values into CDB in big endian format */
@@ -219,13 +223,13 @@ DiskDumpInit(VOID)
 {
   KIRQL CurrentIrql = KeGetCurrentIrql();
   IsDumping = TRUE;
-  if (CurrentIrql >= CoreDumpPortDeviceExtension->Interrupt->SynchLevel)
+  if (CurrentIrql >= CoreDumpPortDeviceExtension->Interrupt->SynchronizeIrql)
     {
       DbgPrint("DISKDUMP: Error: Crash inside high priority interrupt routine.\n");
       return(STATUS_UNSUCCESSFUL);
-    }  
+    }
   CoreDumpPortDeviceExtension->Interrupt->ServiceRoutine = DiskDumpIsr;
-  
+
   return(STATUS_SUCCESS);
 }
 
@@ -238,13 +242,13 @@ DiskDumpFinish(VOID)
 NTSTATUS STDCALL
 DiskDumpWrite(LARGE_INTEGER Address, PMDL Mdl)
 {
-  KIRQL OldIrql, OldIrql2;
+  KIRQL OldIrql = 0, OldIrql2 = 0;
   KIRQL CurrentIrql = KeGetCurrentIrql();
 
-  if (CurrentIrql < (CoreDumpPortDeviceExtension->Interrupt->SynchLevel - 1))
+  if (CurrentIrql < (CoreDumpPortDeviceExtension->Interrupt->SynchronizeIrql - 1))
     {
-      KeRaiseIrql(CoreDumpPortDeviceExtension->Interrupt->SynchLevel - 1, &OldIrql);
-    }  
+      KeRaiseIrql(CoreDumpPortDeviceExtension->Interrupt->SynchronizeIrql - 1, &OldIrql);
+    }
 
   /* Adjust the address for the start of the partition. */
   Address.QuadPart +=
@@ -257,7 +261,7 @@ DiskDumpWrite(LARGE_INTEGER Address, PMDL Mdl)
 
   /* Start i/o on the HBA. */
   IrqComplete = IrqNextRequest = FALSE;
-  KeRaiseIrql(CoreDumpPortDeviceExtension->Interrupt->SynchLevel, &OldIrql2);
+  KeRaiseIrql(CoreDumpPortDeviceExtension->Interrupt->SynchronizeIrql, &OldIrql2);
   if (!CoreDumpPortDeviceExtension->HwStartIo(&CoreDumpPortDeviceExtension->MiniPortDeviceExtension,
                                              &CoreDumpSrb))
     {
@@ -272,8 +276,8 @@ DiskDumpWrite(LARGE_INTEGER Address, PMDL Mdl)
   while (!IrqComplete || !IrqNextRequest)
     {
       __asm__ ("hlt\n\t");
-    }  
-  if (CurrentIrql < (CoreDumpPortDeviceExtension->Interrupt->SynchLevel - 1))
+    }
+  if (CurrentIrql < (CoreDumpPortDeviceExtension->Interrupt->SynchronizeIrql - 1))
     {
       KeLowerIrql(OldIrql);
     }
@@ -294,7 +298,7 @@ DiskDumpPrepare(PDEVICE_OBJECT DeviceObject, PDUMP_POINTERS DumpPointers)
   PIMAGE_NT_HEADERS NtHeader;
   PVOID ImportDirectory;
   ULONG ImportDirectorySize;
-  PIMAGE_IMPORT_MODULE_DIRECTORY ImportModuleDirectory;
+  PIMAGE_IMPORT_DESCRIPTOR ImportModuleDirectory;
   PVOID DriverBase;
   PCH Name;
   ULONG i;
@@ -322,12 +326,12 @@ DiskDumpPrepare(PDEVICE_OBJECT DeviceObject, PDUMP_POINTERS DumpPointers)
       return(STATUS_UNSUCCESSFUL);
     }
   /*  Process each import module  */
-  ImportModuleDirectory = (PIMAGE_IMPORT_MODULE_DIRECTORY)ImportDirectory;
+  ImportModuleDirectory = (PIMAGE_IMPORT_DESCRIPTOR)ImportDirectory;
   DPRINT("Processeing import directory at %p\n", ImportModuleDirectory);
-  while (ImportModuleDirectory->dwRVAModuleName)
+  while (ImportModuleDirectory->Name)
     {
       /*  Check to make sure that import lib is kernel  */
-      Name = (PCHAR) DriverBase + ImportModuleDirectory->dwRVAModuleName;
+      Name = (PCHAR) DriverBase + ImportModuleDirectory->Name;
 
       if (strcmp(Name, "scsiport.sys") != 0)
        {
@@ -337,19 +341,19 @@ DiskDumpPrepare(PDEVICE_OBJECT DeviceObject, PDUMP_POINTERS DumpPointers)
        }
 
       /*  Get the import address list  */
-      ImportAddressList = (PVOID *) ((PUCHAR)DriverBase + 
-                                    ImportModuleDirectory->dwRVAFunctionAddressList);
-      
+      ImportAddressList = (PVOID *) ((PUCHAR)DriverBase +
+                                    (ULONG_PTR)ImportModuleDirectory->FirstThunk);
+
       /*  Get the list of functions to import  */
-      if (ImportModuleDirectory->dwRVAFunctionNameList != 0)
+      if (ImportModuleDirectory->OriginalFirstThunk != 0)
        {
-         FunctionNameList = (PULONG) ((PUCHAR)DriverBase + 
-                                      ImportModuleDirectory->dwRVAFunctionNameList);
+         FunctionNameList = (PULONG) ((PUCHAR)DriverBase +
+                                      (ULONG_PTR)ImportModuleDirectory->OriginalFirstThunk);
        }
       else
        {
-         FunctionNameList = (PULONG) ((PUCHAR)DriverBase + 
-                                      ImportModuleDirectory->dwRVAFunctionAddressList);
+         FunctionNameList = (PULONG) ((PUCHAR)DriverBase +
+                                      (ULONG_PTR)ImportModuleDirectory->FirstThunk);
        }
       /*  Walk through function list and fixup addresses  */
       while (*FunctionNameList != 0L)
@@ -357,16 +361,18 @@ DiskDumpPrepare(PDEVICE_OBJECT DeviceObject, PDUMP_POINTERS DumpPointers)
          if ((*FunctionNameList) & 0x80000000) // hint
            {
              Name = NULL;
-                     
+
              Hint = (*FunctionNameList) & 0xffff;
            }
          else // hint-name
            {
-             Name = (PCHAR)((DWORD)DriverBase + 
+             Name = (PCHAR)((ULONG)DriverBase +
                              *FunctionNameList + 2);
-             Hint = *(PWORD)((DWORD)DriverBase + *FunctionNameList);
+             Hint = *(PUSHORT)((ULONG)DriverBase + *FunctionNameList);
            }
+#if 0
          DPRINT("  Hint:%04x  Name:%s\n", Hint, pName);
+#endif
 
          for (i = 0; i < (sizeof(DiskDumpExports) / sizeof(DiskDumpExports[0])); i++)
            {
@@ -387,10 +393,10 @@ DiskDumpPrepare(PDEVICE_OBJECT DeviceObject, PDUMP_POINTERS DumpPointers)
            }
          DiskDumpExports[i].OldFunction = *ImportAddressList;
          if (DiskDumpExports[i].NewFunction != NULL)
-           {         
+           {
              *ImportAddressList = DiskDumpExports[i].NewFunction;
            }
-         
+
          ImportAddressList++;
          FunctionNameList++;
        }
@@ -404,7 +410,7 @@ DiskDumpPrepare(PDEVICE_OBJECT DeviceObject, PDUMP_POINTERS DumpPointers)
  *     DriverEntry
  *
  * DESCRIPTION
- *     This function initializes the driver, locates and claims 
+ *     This function initializes the driver, locates and claims
  *     hardware resources, and creates various NT objects needed
  *     to process I/O requests.
  *