Added registry shutdown function CmShutdownRegistry()
[reactos.git] / reactos / ntoskrnl / io / iomgr.c
1 /* $Id: iomgr.c,v 1.16 2000/10/05 19:15:50 ekohl Exp $
2 *
3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS kernel
5 * FILE: ntoskrnl/io/iomgr.c
6 * PURPOSE: Initializes the io manager
7 * PROGRAMMER: David Welch (welch@mcmail.com)
8 * REVISION HISTORY:
9 * 29/07/98: Created
10 */
11
12 /* INCLUDES ****************************************************************/
13
14 #include <limits.h>
15 #include <ddk/ntddk.h>
16 #include <internal/ob.h>
17 #include <internal/io.h>
18
19 #define NDEBUG
20 #include <internal/debug.h>
21
22 /* GLOBALS *******************************************************************/
23
24 /* DATA ********************************************************************/
25
26
27 POBJECT_TYPE EXPORTED IoDeviceObjectType = NULL;
28 POBJECT_TYPE EXPORTED IoFileObjectType = NULL;
29 ULONG EXPORTED IoReadOperationCount = 0; /* FIXME: unknown type */
30 ULONG EXPORTED IoReadTransferCount = 0; /* FIXME: unknown type */
31 ULONG EXPORTED IoWriteOperationCount = 0; /* FIXME: unknown type */
32 ULONG EXPORTED IoWriteTransferCount = 0; /* FIXME: unknown type */
33 ULONG EXPORTED IoStatisticsLock = 0; /* FIXME: unknown type */
34
35 /* FUNCTIONS ****************************************************************/
36
37 VOID IopCloseFile(PVOID ObjectBody, ULONG HandleCount)
38 {
39 PFILE_OBJECT FileObject = (PFILE_OBJECT)ObjectBody;
40 PIRP Irp;
41 PIO_STACK_LOCATION StackPtr;
42 NTSTATUS Status;
43
44 DPRINT("IopCloseFile()\n");
45
46 if (HandleCount > 0)
47 {
48 return;
49 }
50
51 ObReferenceObjectByPointer(FileObject,
52 STANDARD_RIGHTS_REQUIRED,
53 IoFileObjectType,
54 UserMode);
55
56 Irp = IoBuildSynchronousFsdRequest(IRP_MJ_CLEANUP,
57 FileObject->DeviceObject,
58 NULL,
59 0,
60 NULL,
61 NULL,
62 NULL);
63 StackPtr = IoGetNextIrpStackLocation(Irp);
64 StackPtr->FileObject = FileObject;
65
66 Status = IoCallDriver(FileObject->DeviceObject, Irp);
67 }
68
69 VOID IopDeleteFile(PVOID ObjectBody)
70 {
71 PFILE_OBJECT FileObject = (PFILE_OBJECT)ObjectBody;
72 PIRP Irp;
73 PIO_STACK_LOCATION StackPtr;
74 NTSTATUS Status;
75
76 DPRINT("IopDeleteFile()\n");
77
78 ObReferenceObjectByPointer(ObjectBody,
79 STANDARD_RIGHTS_REQUIRED,
80 IoFileObjectType,
81 UserMode);
82
83 Irp = IoBuildSynchronousFsdRequest(IRP_MJ_CLOSE,
84 FileObject->DeviceObject,
85 NULL,
86 0,
87 NULL,
88 NULL,
89 NULL);
90 StackPtr = IoGetNextIrpStackLocation(Irp);
91 StackPtr->FileObject = FileObject;
92
93 Status = IoCallDriver(FileObject->DeviceObject, Irp);
94
95 if (FileObject->FileName.Buffer != NULL)
96 {
97 ExFreePool(FileObject->FileName.Buffer);
98 FileObject->FileName.Buffer = 0;
99 }
100 }
101
102
103 VOID IoInit (VOID)
104 {
105 OBJECT_ATTRIBUTES attr;
106 HANDLE handle;
107 UNICODE_STRING UnicodeString;
108 UNICODE_STRING DeviceName;
109
110 /*
111 * Register iomgr types: DeviceObjectType
112 */
113 IoDeviceObjectType = ExAllocatePool (
114 NonPagedPool,
115 sizeof (OBJECT_TYPE)
116 );
117
118 IoDeviceObjectType->TotalObjects = 0;
119 IoDeviceObjectType->TotalHandles = 0;
120 IoDeviceObjectType->MaxObjects = ULONG_MAX;
121 IoDeviceObjectType->MaxHandles = ULONG_MAX;
122 IoDeviceObjectType->PagedPoolCharge = 0;
123 IoDeviceObjectType->NonpagedPoolCharge = sizeof (DEVICE_OBJECT);
124 IoDeviceObjectType->Dump = NULL;
125 IoDeviceObjectType->Open = NULL;
126 IoDeviceObjectType->Close = NULL;
127 IoDeviceObjectType->Delete = NULL;
128 IoDeviceObjectType->Parse = NULL;
129 IoDeviceObjectType->Security = NULL;
130 IoDeviceObjectType->QueryName = NULL;
131 IoDeviceObjectType->OkayToClose = NULL;
132 IoDeviceObjectType->Create = IopCreateDevice;
133
134 RtlInitUnicodeString (
135 & IoDeviceObjectType->TypeName,
136 L"Device"
137 );
138
139 /*
140 * Register iomgr types: FileObjectType
141 * (alias DriverObjectType)
142 */
143 IoFileObjectType = ExAllocatePool (
144 NonPagedPool,
145 sizeof (OBJECT_TYPE)
146 );
147
148 IoFileObjectType->TotalObjects = 0;
149 IoFileObjectType->TotalHandles = 0;
150 IoFileObjectType->MaxObjects = ULONG_MAX;
151 IoFileObjectType->MaxHandles = ULONG_MAX;
152 IoFileObjectType->PagedPoolCharge = 0;
153 IoFileObjectType->NonpagedPoolCharge = sizeof(FILE_OBJECT);
154 IoFileObjectType->Dump = NULL;
155 IoFileObjectType->Open = NULL;
156 IoFileObjectType->Close = IopCloseFile;
157 IoFileObjectType->Delete = IopDeleteFile;
158 IoFileObjectType->Parse = NULL;
159 IoFileObjectType->Security = NULL;
160 IoFileObjectType->QueryName = NULL;
161 IoFileObjectType->OkayToClose = NULL;
162 IoFileObjectType->Create = IopCreateFile;
163
164 RtlInitUnicodeString (
165 & IoFileObjectType->TypeName,
166 L"File"
167 );
168
169 /*
170 * Create the '\Device' directory
171 */
172 RtlInitUnicodeString (
173 & UnicodeString,
174 L"\\Device"
175 );
176 InitializeObjectAttributes (
177 & attr,
178 & UnicodeString,
179 0,
180 NULL,
181 NULL
182 );
183 ZwCreateDirectoryObject (
184 & handle,
185 0,
186 & attr
187 );
188
189 /*
190 * Create the '\??' directory
191 */
192 RtlInitUnicodeString (
193 & UnicodeString,
194 L"\\??"
195 );
196 InitializeObjectAttributes (
197 & attr,
198 & UnicodeString,
199 0,
200 NULL,
201 NULL
202 );
203 ZwCreateDirectoryObject (
204 & handle,
205 0,
206 & attr
207 );
208
209 /*
210 * Create the '\ArcName' directory
211 */
212 RtlInitUnicodeString (
213 & UnicodeString,
214 L"\\ArcName");
215 InitializeObjectAttributes (
216 & attr,
217 & UnicodeString,
218 0,
219 NULL,
220 NULL
221 );
222 ZwCreateDirectoryObject (
223 & handle,
224 0,
225 & attr
226 );
227
228 /*
229 * Initialize remaining subsubsystem
230 */
231 IoInitCancelHandling ();
232 IoInitSymbolicLinkImplementation ();
233 IoInitFileSystemImplementation ();
234 IoInitVpbImplementation ();
235 IoInitShutdownNotification ();
236
237 /*
238 * Create link from '\DosDevices' to '\??' directory
239 */
240 RtlInitUnicodeString (&UnicodeString,
241 L"\\DosDevices");
242 RtlInitUnicodeString (&DeviceName,
243 L"\\??");
244 IoCreateSymbolicLink (&UnicodeString,
245 &DeviceName);
246 }
247
248 /* EOF */