Synchronize with trunk revision 59636 (just before Alex's CreateProcess revamp).
[reactos.git] / drivers / base / condrv / control.c
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 #define NDEBUG
14 #include <debug.h>
15
16
17 /* FUNCTIONS ******************************************************************/
18
19 NTSTATUS NTAPI
20 ConDrvCreateController(IN PDRIVER_OBJECT DriverObject,
21 IN PUNICODE_STRING RegistryPath)
22 {
23 NTSTATUS Status = STATUS_SUCCESS;
24 UNICODE_STRING DeviceName, SymlinkName;
25 PCONDRV_DRIVER DriverExtension;
26 PDEVICE_OBJECT Controller = NULL;
27
28 DPRINT1("Create the Controller device...\n");
29
30 RtlInitUnicodeString(&DeviceName , DD_CONDRV_CTRL_DEVICE_NAME_U);
31 RtlInitUnicodeString(&SymlinkName, DD_CONDRV_CTRL_SYMLNK_NAME_U);
32
33 /* Get the driver extension */
34 DriverExtension = (PCONDRV_DRIVER)IoGetDriverObjectExtension(DriverObject,
35 DriverObject);
36
37 /* Create the Controller device, if it doesn't exist */
38 Status = IoCreateDevice(DriverObject,
39 0,
40 (PUNICODE_STRING)&DeviceName,
41 FILE_DEVICE_UNKNOWN,
42 FILE_DEVICE_SECURE_OPEN,
43 FALSE,
44 &Controller);
45 if (!NT_SUCCESS(Status)) goto Done;
46
47 Status = IoCreateSymbolicLink(&SymlinkName, &DeviceName);
48 if (!NT_SUCCESS(Status))
49 {
50 IoDeleteDevice(Controller);
51 goto Done;
52 }
53
54 Controller->Flags &= ~DO_DEVICE_INITIALIZING;
55
56 /* Save the Controller device */
57 DriverExtension->Controller = Controller;
58
59 Done:
60 DPRINT1("Done, Status = 0x%08lx\n", Status);
61 return Status;
62 }
63
64 NTSTATUS NTAPI
65 ConDrvDeleteController(IN PDRIVER_OBJECT DriverObject)
66 {
67 NTSTATUS Status = STATUS_SUCCESS;
68 PDEVICE_OBJECT Controller;
69 UNICODE_STRING SymlinkName;
70
71 DPRINT1("Delete the Controller device...\n");
72
73 /* Retrieve the Controller device */
74 Controller = ((PCONDRV_DRIVER)IoGetDriverObjectExtension(DriverObject, DriverObject))->Controller;
75 if (!Controller) return STATUS_OBJECT_TYPE_MISMATCH;
76
77 RtlInitUnicodeString(&SymlinkName, DD_CONDRV_CTRL_SYMLNK_NAME_U);
78 IoDeleteSymbolicLink(&SymlinkName);
79
80 /* Delete the controller device itself */
81 IoDeleteDevice(Controller);
82
83 DPRINT1("Done, Status = 0x%08lx\n", Status);
84 return Status;
85 }
86
87 /* EOF */