Better handling of errors/special cases
authorHervé Poussineau <hpoussin@reactos.org>
Sun, 28 May 2006 21:43:45 +0000 (21:43 +0000)
committerHervé Poussineau <hpoussin@reactos.org>
Sun, 28 May 2006 21:43:45 +0000 (21:43 +0000)
svn path=/trunk/; revision=22095

reactos/drivers/base/green/dispatch.c
reactos/drivers/base/green/green.h
reactos/drivers/base/green/green.inf
reactos/drivers/base/green/pnp.c

index 57f2b90..d40df5c 100644 (file)
@@ -76,7 +76,26 @@ GreenDispatch(
        {
                DPRINT1("Unknown combination: MajorFunction 0x%lx, DeviceType %d\n",
                        MajorFunction, DeviceType);
-               ASSERT(FALSE);
+               switch (DeviceType)
+               {
+                       case KeyboardFDO:
+                       case ScreenFDO:
+                       {
+                               IoSkipCurrentIrpStackLocation(Irp);
+                               return IoCallDriver(((PCOMMON_FDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension)->LowerDevice, Irp);
+                       }
+                       case GreenFDO:
+                       {
+                               PDRIVER_OBJECT DriverObject;
+                               PGREEN_DRIVER_EXTENSION DriverExtension;
+                               DriverObject = DeviceObject->DriverObject;
+                               DriverExtension = IoGetDriverObjectExtension(DriverObject, DriverObject);
+                               IoSkipCurrentIrpStackLocation(Irp);
+                               return IoCallDriver(DriverExtension->LowerDevice, Irp);
+                       }
+                       default:
+                               ASSERT(FALSE);
+               }
        }
 
        Irp->IoStatus.Information = Information;
index 1b8a27c..6b6260f 100644 (file)
@@ -105,6 +105,7 @@ typedef struct _GREEN_DRIVER_EXTENSION
        ULONG SampleRate;
 
        PDEVICE_OBJECT GreenMainDO;
+       PDEVICE_OBJECT LowerDevice;
 } GREEN_DRIVER_EXTENSION, *PGREEN_DRIVER_EXTENSION;
 
 /************************************ createclose.c */
index b7a3754..805fbda 100644 (file)
@@ -38,9 +38,9 @@ ServiceType    = 1
 StartType      = 1
 ErrorControl   = 0
 ServiceBinary  = %12%\green.sys
-LoadOrderGroup = Video Init
+LoadOrderGroup = Extended base
 Description    = %GREEN.DriverDesc%
-Dependencies   = blue
+Dependencies   = blue, serial
 
 [Green_AddReg.NT]
 HKLM,"SYSTEM\CurrentControlSet\Services\green\Parameters","AttachedDevice",0x00000000,"\Device\Serial1"
index cdec298..cec5993 100644 (file)
@@ -26,7 +26,8 @@ CreateGreenFdo(
 
        DriverExtension = IoGetDriverObjectExtension(DriverObject, DriverObject);
 
-       Status = IoCreateDevice(DriverObject,
+       Status = IoCreateDevice(
+               DriverObject,
                sizeof(GREEN_DEVICE_EXTENSION),
                NULL,
                FILE_DEVICE_TERMSRV,
@@ -43,7 +44,7 @@ CreateGreenFdo(
        RtlZeroMemory(DeviceExtension, sizeof(GREEN_DEVICE_EXTENSION));
        DeviceExtension->Common.Type = GreenFDO;
        DriverExtension->GreenMainDO->Flags |= DO_POWER_PAGABLE;
-       IoAttachDeviceToDeviceStack(DriverExtension->GreenMainDO, GreenPdo);
+       DriverExtension->LowerDevice = IoAttachDeviceToDeviceStack(DriverExtension->GreenMainDO, GreenPdo);
 
        /* Initialize serial port */
        InitializeObjectAttributes(&ObjectAttributes, &DriverExtension->AttachedDeviceName, OBJ_KERNEL_HANDLE, NULL, NULL);
@@ -119,10 +120,18 @@ cleanup:
        {
                if (DeviceExtension && DeviceExtension->Serial)
                        ObDereferenceObject(DeviceExtension->Serial);
-               if (DriverExtension && DriverExtension->GreenMainDO)
+               if (DriverExtension)
                {
-                       IoDeleteDevice(DriverExtension->GreenMainDO);
-                       DriverExtension->GreenMainDO = NULL;
+                       if (DriverExtension->LowerDevice)
+                       {
+                               IoDetachDevice(DriverExtension->LowerDevice);
+                               DriverExtension->LowerDevice = NULL;
+                       }
+                       if (DriverExtension->GreenMainDO)
+                       {
+                               IoDeleteDevice(DriverExtension->GreenMainDO);
+                               DriverExtension->GreenMainDO = NULL;
+                       }
                }
        }
        return Status;
@@ -219,39 +228,45 @@ GreenQueryBusRelations(
        DeviceExtension = (PGREEN_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
 
        /* Create PDOs for keyboard and screen */
-       Status = IoCreateDevice(
-               DeviceObject->DriverObject,
-               sizeof(COMMON_DEVICE_EXTENSION),
-               NULL,
-               FILE_DEVICE_KEYBOARD,
-               FILE_AUTOGENERATED_DEVICE_NAME | FILE_DEVICE_SECURE_OPEN,
-               FALSE,
-               &DeviceExtension->KeyboardPdo);
-       if (!NT_SUCCESS(Status))
+       if (DeviceExtension->KeyboardPdo == NULL)
        {
-               DPRINT("IoCreateDevice() failed with status 0x%lx\n", Status);
-               goto cleanup;
+               Status = IoCreateDevice(
+                       DeviceObject->DriverObject,
+                       sizeof(COMMON_DEVICE_EXTENSION),
+                       NULL,
+                       FILE_DEVICE_KEYBOARD,
+                       FILE_AUTOGENERATED_DEVICE_NAME | FILE_DEVICE_SECURE_OPEN,
+                       FALSE,
+                       &DeviceExtension->KeyboardPdo);
+               if (!NT_SUCCESS(Status))
+               {
+                       DPRINT("IoCreateDevice() failed with status 0x%lx\n", Status);
+                       goto cleanup;
+               }
+               ((PCOMMON_DEVICE_EXTENSION)DeviceExtension->KeyboardPdo->DeviceExtension)->Type = KeyboardPDO;
+               DeviceExtension->KeyboardPdo->Flags |= DO_POWER_PAGABLE | DO_BUS_ENUMERATED_DEVICE;
+               DeviceExtension->KeyboardPdo->Flags &= ~DO_DEVICE_INITIALIZING;
        }
-       ((PCOMMON_DEVICE_EXTENSION)DeviceExtension->KeyboardPdo->DeviceExtension)->Type = KeyboardPDO;
-       DeviceExtension->KeyboardPdo->Flags |= DO_POWER_PAGABLE | DO_BUS_ENUMERATED_DEVICE;
-       DeviceExtension->KeyboardPdo->Flags &= ~DO_DEVICE_INITIALIZING;
 
-       Status = IoCreateDevice(
-               DeviceObject->DriverObject,
-               sizeof(COMMON_DEVICE_EXTENSION),
-               NULL,
-               FILE_DEVICE_SCREEN,
-               FILE_AUTOGENERATED_DEVICE_NAME | FILE_DEVICE_SECURE_OPEN,
-               FALSE,
-               &DeviceExtension->ScreenPdo);
-       if (!NT_SUCCESS(Status))
+       if (DeviceExtension->ScreenPdo == NULL)
        {
-               DPRINT("IoCreateDevice() failed with status 0x%lx\n", Status);
-               goto cleanup;
+               Status = IoCreateDevice(
+                       DeviceObject->DriverObject,
+                       sizeof(COMMON_DEVICE_EXTENSION),
+                       NULL,
+                       FILE_DEVICE_SCREEN,
+                       FILE_AUTOGENERATED_DEVICE_NAME | FILE_DEVICE_SECURE_OPEN,
+                       FALSE,
+                       &DeviceExtension->ScreenPdo);
+               if (!NT_SUCCESS(Status))
+               {
+                       DPRINT("IoCreateDevice() failed with status 0x%lx\n", Status);
+                       goto cleanup;
+               }
+               ((PCOMMON_DEVICE_EXTENSION)DeviceExtension->ScreenPdo->DeviceExtension)->Type = ScreenPDO;
+               DeviceExtension->ScreenPdo->Flags |= DO_POWER_PAGABLE | DO_BUS_ENUMERATED_DEVICE;
+               DeviceExtension->ScreenPdo->Flags &= ~DO_DEVICE_INITIALIZING;
        }
-       ((PCOMMON_DEVICE_EXTENSION)DeviceExtension->ScreenPdo->DeviceExtension)->Type = ScreenPDO;
-       DeviceExtension->ScreenPdo->Flags |= DO_POWER_PAGABLE | DO_BUS_ENUMERATED_DEVICE;
-       DeviceExtension->ScreenPdo->Flags &= ~DO_DEVICE_INITIALIZING;
 
        /* Allocate return structure */
        DeviceRelations = (PDEVICE_RELATIONS)ExAllocatePool(