branch update for HEAD-2003050101
[reactos.git] / ntoskrnl / io / device.c
index 6e8b696..57fde3f 100644 (file)
@@ -76,9 +76,15 @@ IoDeleteDevice(PDEVICE_OBJECT DeviceObject)
 #endif /* !LIBCAPTIVE */
        }
 
+#ifndef LIBCAPTIVE
+       /* W32 expects CreatedDeviceObject->DeviceExtension to follow *CreatedDeviceObject!
+        * Undocumented by W32!
+        * See also IoCreateDevice().
+        */
        /* free device extension */
        if (DeviceObject->DeviceObjectExtension)
                ExFreePool (DeviceObject->DeviceObjectExtension);
+#endif /* LIBCAPTIVE */
 
        /* remove device from driver device list */
        Previous = DeviceObject->DriverObject->DeviceObject;
@@ -621,11 +627,17 @@ IoCreateDevice(PDRIVER_OBJECT DriverObject,
 {
    PDEVICE_OBJECT CreatedDeviceObject;
    OBJECT_ATTRIBUTES ObjectAttributes;
-   HANDLE DeviceHandle;
    NTSTATUS Status;
    
    assert_irql(PASSIVE_LEVEL);
    
+   assert(sizeof(CreatedDeviceObject->Queue.Wcb) == 40);
+   assert(sizeof(CreatedDeviceObject->DeviceQueue) == 20);
+   assert(sizeof(CreatedDeviceObject->Dpc) == 32);
+   assert(sizeof(CreatedDeviceObject->DeviceLock) == 16);
+   assert(sizeof(DEVICE_OBJECT) == 184);
+   assert(sizeof(DEVICE_OBJECT) == 0xB8);
+
    if (DeviceName != NULL)
      {
        DPRINT("IoCreateDevice(DriverObject %x, DeviceName %S)\n",DriverObject,
@@ -636,10 +648,19 @@ IoCreateDevice(PDRIVER_OBJECT DriverObject,
        DPRINT("IoCreateDevice(DriverObject %x)\n",DriverObject);
      }
    
+#ifdef LIBCAPTIVE
+   /* W32 expects CreatedDeviceObject->DeviceExtension to follow *CreatedDeviceObject!
+    * Undocumented by W32!
+    * See also IoDeleteDevice().
+    */
+   /* TODO:thread */
+   IoDeviceObjectType->NonpagedPoolCharge = sizeof (DEVICE_OBJECT) + DeviceExtensionSize;
+#endif /* LIBCAPTIVE */
+
    if (DeviceName != NULL)
      {
        InitializeObjectAttributes(&ObjectAttributes,DeviceName,0,NULL,NULL);
-       Status = ObCreateObject(&DeviceHandle,
+       Status = ObCreateObject(NULL,
                                0,
                                &ObjectAttributes,
                                IoDeviceObjectType,
@@ -647,13 +668,22 @@ IoCreateDevice(PDRIVER_OBJECT DriverObject,
      }
    else
      {
-       Status = ObCreateObject(&DeviceHandle,
+       Status = ObCreateObject(NULL,
                                0,
                                NULL,
                                IoDeviceObjectType,
                                (PVOID*)&CreatedDeviceObject);
      }
    
+#ifdef LIBCAPTIVE
+   /* W32 expects CreatedDeviceObject->DeviceExtension to follow *CreatedDeviceObject!
+    * Undocumented by W32!
+    * See also IoDeleteDevice().
+    */
+   /* TODO:thread */
+   IoDeviceObjectType->NonpagedPoolCharge = sizeof (DEVICE_OBJECT);    /* restore */
+#endif /* LIBCAPTIVE */
+
    *DeviceObject = NULL;
    
    if (!NT_SUCCESS(Status))
@@ -674,16 +704,29 @@ IoCreateDevice(PDRIVER_OBJECT DriverObject,
      }
   
   CreatedDeviceObject->Type = DeviceType;
-  CreatedDeviceObject->Size = sizeof (*CreatedDeviceObject);
+   /* W32 (ntfs) expects CreatedDeviceObject->Size to cover even 'DeviceExtensionSize'.
+    * Undocumented by W32!
+    */
+  CreatedDeviceObject->Size = sizeof (DEVICE_OBJECT) + DeviceExtensionSize;
   CreatedDeviceObject->ReferenceCount = 0;     /* or 1? it is floating unused this way */
   CreatedDeviceObject->DriverObject = DriverObject;
   CreatedDeviceObject->CurrentIrp = NULL;
   CreatedDeviceObject->Flags = 0;
   CreatedDeviceObject->Characteristics = DeviceCharacteristics;
+  CreatedDeviceObject->Timer = NULL;
+  CreatedDeviceObject->Vpb = NULL;
 
+#ifndef LIBCAPTIVE
   CreatedDeviceObject->DeviceExtension = 
     ExAllocatePoolWithTag(NonPagedPool, DeviceExtensionSize,
                          TAG_DEVICE_EXTENSION);
+#else /* !LIBCAPTIVE */
+  /* W32 expects CreatedDeviceObject->DeviceExtension to follow *CreatedDeviceObject!
+   * Undocumented by W32!
+   * See also IoDeleteDevice().
+   */
+  CreatedDeviceObject->DeviceExtension = (void *)(CreatedDeviceObject+1);
+#endif /* LIBCAPTIVE */
   if (DeviceExtensionSize > 0 && CreatedDeviceObject->DeviceExtension == NULL)
     {
       ExFreePool(CreatedDeviceObject);
@@ -697,6 +740,13 @@ IoCreateDevice(PDRIVER_OBJECT DriverObject,
                    DeviceExtensionSize);
     }
 
+#ifdef LIBCAPTIVE
+  /* Magic value expected by ntfs.sys NT5.1sp1 _NtfsInitializeIrpContext()
+   */
+  if (DeviceExtensionSize>=0x2A)
+    *(USHORT *)(((UCHAR *)CreatedDeviceObject->DeviceExtension)+0x28)=0x0701;
+#endif /* LIBCAPTIVE */
+
   CreatedDeviceObject->AttachedDevice = NULL;
   CreatedDeviceObject->DeviceType = DeviceType;
   CreatedDeviceObject->StackSize = 1;