xref: /reactos/drivers/base/condrv/condrv.c (revision 84ccccab)
1 /*
2  * COPYRIGHT:       See COPYING in the top level directory
3  * PROJECT:         ReactOS Console Driver
4  * FILE:            drivers/base/condrv/condrv.c
5  * PURPOSE:         Console Driver Management Functions
6  * PROGRAMMERS:     Hermes Belusca-Maito (hermes.belusca@sfr.fr)
7  */
8 
9 /* INCLUDES *******************************************************************/
10 
11 #include "condrv.h"
12 
13 #define NDEBUG
14 #include <debug.h>
15 
16 /* FUNCTIONS ******************************************************************/
17 
18 /*
19  * Callback functions prototypes
20  */
21 DRIVER_INITIALIZE DriverEntry;
22 DRIVER_UNLOAD     ConDrvUnload;
23 /*
24 DRIVER_DISPATCH ConDrvIoControl;
25 DRIVER_DISPATCH ConDrvCreate;
26 DRIVER_DISPATCH ConDrvClose;
27 DRIVER_DISPATCH ConDrvRead;
28 DRIVER_DISPATCH ConDrvWrite;
29 DRIVER_DISPATCH ConDrvCleanup;
30 */
31 DRIVER_DISPATCH ConDrvDispatch;
32 
33 NTSTATUS NTAPI
34 DriverEntry(IN PDRIVER_OBJECT DriverObject,
35             IN PUNICODE_STRING RegistryPath)
36 {
37     NTSTATUS Status;
38     USHORT i;
39     PCONDRV_DRIVER DriverExtension = NULL;
40 
41     DPRINT1("Loading ReactOS Console Driver v0.0.1...\n");
42 
43     DriverObject->DriverUnload = ConDrvUnload;
44 
45     /* Initialize the different callback function pointers */
46     for (i = 0 ; i <= IRP_MJ_MAXIMUM_FUNCTION ; ++i)
47         DriverObject->MajorFunction[i] = ConDrvDispatch;
48 
49 #if 0
50     DriverObject->MajorFunction[IRP_MJ_CREATE]  = ConDrvCreate;
51     DriverObject->MajorFunction[IRP_MJ_CLOSE]   = ConDrvClose;
52 
53     /* temporary deactivated...
54     DriverObject->MajorFunction[IRP_MJ_CLEANUP] = ConDrvCleanup;
55     */
56     DriverObject->MajorFunction[IRP_MJ_READ]    = ConDrvRead;
57     DriverObject->MajorFunction[IRP_MJ_WRITE]   = ConDrvWrite;
58 
59     DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = ConDrvIoControl;
60 #endif
61 
62     Status = IoAllocateDriverObjectExtension(DriverObject,
63                                              DriverObject, // Unique ID for the driver object extension ==> gives it its address !
64                                              sizeof(CONDRV_DRIVER),
65                                              (PVOID*)&DriverExtension);
66     if (!NT_SUCCESS(Status))
67     {
68         DPRINT1("IoAllocateDriverObjectExtension() failed with status 0x%08lx\n", Status);
69         return Status;
70     }
71     RtlZeroMemory(DriverExtension, sizeof(CONDRV_DRIVER));
72 
73     Status = ConDrvCreateController(DriverObject, RegistryPath);
74 
75     DPRINT1("Done, Status = 0x%08lx\n", Status);
76     return Status;
77 }
78 
79 VOID NTAPI
80 ConDrvUnload(IN PDRIVER_OBJECT DriverObject)
81 {
82     DPRINT1("Unloading ReactOS Console Driver v0.0.1...\n");
83 
84     /*
85      * Delete the Controller device. This has as effect
86      * to delete also all the terminals.
87      */
88     ConDrvDeleteController(DriverObject);
89 
90     /* Sanity check: No devices must exist at this point */
91     ASSERT(DriverObject->DeviceObject == NULL);
92 
93     DPRINT1("Done\n");
94     return;
95 }
96 
97 /* EOF */
98