xref: /reactos/drivers/base/condrv/control.c (revision 84344399)
1 /*
2  * COPYRIGHT:       See COPYING in the top level directory
3  * PROJECT:         ReactOS Console Driver
4  * FILE:            drivers/base/condrv/control.c
5  * PURPOSE:         Console Driver - Controller Device
6  * PROGRAMMERS:     Hermes Belusca-Maito (hermes.belusca@sfr.fr)
7  */
8 
9 /* INCLUDES *******************************************************************/
10 
11 #include "condrv.h"
12 
13 #include <condrv/ntddcon.h>
14 
15 #define NDEBUG
16 #include <debug.h>
17 
18 /* FUNCTIONS ******************************************************************/
19 
20 NTSTATUS NTAPI
21 ConDrvCreateController(IN PDRIVER_OBJECT DriverObject,
22                        IN PUNICODE_STRING RegistryPath)
23 {
24     NTSTATUS Status = STATUS_SUCCESS;
25     UNICODE_STRING DeviceName, SymlinkName;
26     PCONDRV_DRIVER DriverExtension;
27     PDEVICE_OBJECT Controller = NULL;
28 
29     DPRINT1("Create the Controller device...\n");
30 
31     RtlInitUnicodeString(&DeviceName , DD_CONDRV_CTRL_DEVICE_NAME_U);
32     RtlInitUnicodeString(&SymlinkName, DD_CONDRV_CTRL_SYMLNK_NAME_U);
33 
34     /* Get the driver extension */
35     DriverExtension = (PCONDRV_DRIVER)IoGetDriverObjectExtension(DriverObject,
36                                                                  DriverObject);
37 
38     /* Create the Controller device, if it doesn't exist */
39     Status = IoCreateDevice(DriverObject,
40                             0,
41                             (PUNICODE_STRING)&DeviceName,
42                             FILE_DEVICE_UNKNOWN,
43                             FILE_DEVICE_SECURE_OPEN,
44                             FALSE,
45                             &Controller);
46     if (!NT_SUCCESS(Status)) goto Done;
47 
48     Status = IoCreateSymbolicLink(&SymlinkName, &DeviceName);
49     if (!NT_SUCCESS(Status))
50     {
51         IoDeleteDevice(Controller);
52         goto Done;
53     }
54 
55     Controller->Flags &= ~DO_DEVICE_INITIALIZING;
56 
57     /* Save the Controller device */
58     DriverExtension->Controller = Controller;
59 
60 Done:
61     DPRINT1("Done, Status = 0x%08lx\n", Status);
62     return Status;
63 }
64 
65 NTSTATUS NTAPI
66 ConDrvDeleteController(IN PDRIVER_OBJECT DriverObject)
67 {
68     NTSTATUS Status = STATUS_SUCCESS;
69     PDEVICE_OBJECT Controller;
70     UNICODE_STRING SymlinkName;
71 
72     DPRINT1("Delete the Controller device...\n");
73 
74     /* Retrieve the Controller device */
75     Controller = ((PCONDRV_DRIVER)IoGetDriverObjectExtension(DriverObject, DriverObject))->Controller;
76     if (!Controller) return STATUS_OBJECT_TYPE_MISMATCH;
77 
78     RtlInitUnicodeString(&SymlinkName, DD_CONDRV_CTRL_SYMLNK_NAME_U);
79     IoDeleteSymbolicLink(&SymlinkName);
80 
81     /* Delete the controller device itself */
82     IoDeleteDevice(Controller);
83 
84     DPRINT1("Done, Status = 0x%08lx\n", Status);
85     return Status;
86 }
87 
88 /* EOF */
89