2dde365097f90cc66fecb1df38c883fa854af921
[reactos.git] / reactos / ntoskrnl / include / internal / io.h
1 /*
2 * ReactOS kernel
3 * Copyright (C) 2000 David Welch <welch@cwcom.net>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19 /* $Id: io.h,v 1.43 2004/05/02 19:33:29 ekohl Exp $
20 *
21 * COPYRIGHT: See COPYING in the top level directory
22 * PROJECT: ReactOS kernel
23 * FILE: include/internal/io.h
24 * PURPOSE: Internal io manager declarations
25 * PROGRAMMER: David Welch (welch@mcmail.com)
26 * UPDATE HISTORY:
27 * 28/05/97: Created
28 */
29
30 #ifndef __NTOSKRNL_INCLUDE_INTERNAL_IO_H
31 #define __NTOSKRNL_INCLUDE_INTERNAL_IO_H
32
33 #include <ddk/ntddk.h>
34 #include <internal/ob.h>
35 #include <internal/module.h>
36
37
38 #ifndef __USE_W32API
39 #define DEVICE_TYPE_FROM_CTL_CODE(ctlCode) (((ULONG)(ctlCode&0xffff0000))>>16)
40 #endif
41
42 #define IO_METHOD_FROM_CTL_CODE(ctlCode) (ctlCode&0x00000003)
43
44
45 typedef struct _IO_COMPLETION_PACKET{
46 ULONG Key;
47 ULONG Overlapped;
48 IO_STATUS_BLOCK IoStatus;
49 LIST_ENTRY ListEntry;
50 } IO_COMPLETION_PACKET, *PIO_COMPLETION_PACKET;
51
52 typedef struct _DEVOBJ_EXTENSION {
53 CSHORT Type;
54 USHORT Size;
55 PDEVICE_OBJECT DeviceObject;
56 ULONG Unknown[3];
57 struct _DEVICE_NODE *DeviceNode;
58 } DEVOBJ_EXTENSION, *PDEVOBJ_EXTENSION;
59
60 typedef struct _PRIVATE_DRIVER_EXTENSIONS {
61 struct _PRIVATE_DRIVER_EXTENSIONS *Link;
62 PVOID ClientIdentificationAddress;
63 CHAR Extension[1];
64 } PRIVATE_DRIVER_EXTENSIONS, *PPRIVATE_DRIVER_EXTENSIONS;
65
66 typedef struct _DEVICE_NODE
67 {
68 struct _DEVICE_NODE *Parent;
69 struct _DEVICE_NODE *PrevSibling;
70 struct _DEVICE_NODE *NextSibling;
71 struct _DEVICE_NODE *Child;
72 PDEVICE_OBJECT Pdo;
73 UNICODE_STRING InstancePath;
74 UNICODE_STRING ServiceName;
75 //TargetDeviceNotifyList?
76 PDEVICE_CAPABILITIES CapabilityFlags;
77 ULONG Flags;
78 ULONG UserFlags;
79 ULONG DisableableDepends;
80 ULONG Problem;
81 PCM_RESOURCE_LIST CmResourceList;
82 PCM_RESOURCE_LIST BootResourcesList;
83 PIO_RESOURCE_REQUIREMENTS_LIST ResourceRequirementsList;
84 /* Not NT's */
85 UNICODE_STRING DeviceID;
86 UNICODE_STRING InstanceID;
87 UNICODE_STRING HardwareIDs;
88 UNICODE_STRING CompatibleIDs;
89 UNICODE_STRING DeviceText;
90 UNICODE_STRING DeviceTextLocation;
91 PPNP_BUS_INFORMATION BusInformation;
92 } DEVICE_NODE, *PDEVICE_NODE;
93
94 /* For Flags field */
95 #define DNF_PROCESSED 0x00000001
96 #define DNF_STARTED 0x00000002
97 #define DNF_START_FAILED 0x00000004
98 #define DNF_ENUMERATED 0x00000008
99 #define DNF_DELETED 0x00000010
100 #define DNF_MADEUP 0x00000020
101 #define DNF_START_REQUEST_PENDING 0x00000040
102 #define DNF_NO_RESOURCE_REQUIRED 0x00000080
103 #define DNF_INSUFFICIENT_RESOURCES 0x00000100
104 #define DNF_RESOURCE_ASSIGNED 0x00000200
105 #define DNF_RESOURCE_REPORTED 0x00000400
106 #define DNF_HAL_NODE 0x00000800 // ???
107 #define DNF_ADDED 0x00001000
108 #define DNF_ADD_FAILED 0x00002000
109 #define DNF_LEGACY_DRIVER 0x00004000
110 #define DNF_STOPPED 0x00008000
111 #define DNF_WILL_BE_REMOVED 0x00010000
112 #define DNF_NEED_TO_ENUM 0x00020000
113 #define DNF_NOT_CONFIGURED 0x00040000
114 #define DNF_REINSTALL 0x00080000
115 #define DNF_RESOURCE_REQUIREMENTS_NEED_FILTERED 0x00100000 // ???
116 #define DNF_DISABLED 0x00200000
117 #define DNF_RESTART_OK 0x00400000
118 #define DNF_NEED_RESTART 0x00800000
119 #define DNF_VISITED 0x01000000
120 #define DNF_ASSIGNING_RESOURCES 0x02000000
121 #define DNF_BEEING_ENUMERATED 0x04000000
122 #define DNF_NEED_ENUMERATION_ONLY 0x08000000
123 #define DNF_LOCKED 0x10000000
124 #define DNF_HAS_BOOT_CONFIG 0x20000000
125 #define DNF_BOOT_CONFIG_RESERVED 0x40000000
126 #define DNF_HAS_PROBLEM 0x80000000 // ???
127
128 /* For UserFlags field */
129 #define DNUF_DONT_SHOW_IN_UI 0x0002
130 #define DNUF_NOT_DISABLEABLE 0x0008
131
132 /* For Problem field */
133 #define CM_PROB_NOT_CONFIGURED 1
134 #define CM_PROB_FAILED_START 10
135 #define CM_PROB_NORMAL_CONFLICT 12
136 #define CM_PROB_NEED_RESTART 14
137 #define CM_PROB_REINSTALL 18
138 #define CM_PROB_WILL_BE_REMOVED 21
139 #define CM_PROB_DISABLED 22
140 #define CM_PROB_FAILED_INSTALL 28
141 #define CM_PROB_FAILED_ADD 31
142
143 /*
144 * VOID
145 * IopDeviceNodeSetFlag(
146 * PDEVICE_NODE DeviceNode,
147 * ULONG Flag);
148 */
149 #define IopDeviceNodeSetFlag(DeviceNode, Flag)((DeviceNode)->Flags |= (Flag))
150
151 /*
152 * VOID
153 * IopDeviceNodeClearFlag(
154 * PDEVICE_NODE DeviceNode,
155 * ULONG Flag);
156 */
157 #define IopDeviceNodeClearFlag(DeviceNode, Flag)((DeviceNode)->Flags &= ~(Flag))
158
159 /*
160 * BOOLEAN
161 * IopDeviceNodeHasFlag(
162 * PDEVICE_NODE DeviceNode,
163 * ULONG Flag);
164 */
165 #define IopDeviceNodeHasFlag(DeviceNode, Flag)(((DeviceNode)->Flags & (Flag)) > 0)
166
167 /*
168 * VOID
169 * IopDeviceNodeSetUserFlag(
170 * PDEVICE_NODE DeviceNode,
171 * ULONG UserFlag);
172 */
173 #define IopDeviceNodeSetUserFlag(DeviceNode, UserFlag)((DeviceNode)->UserFlags |= (UserFlag))
174
175 /*
176 * VOID
177 * IopDeviceNodeClearUserFlag(
178 * PDEVICE_NODE DeviceNode,
179 * ULONG UserFlag);
180 */
181 #define IopDeviceNodeClearUserFlag(DeviceNode, UserFlag)((DeviceNode)->UserFlags &= ~(UserFlag))
182
183 /*
184 * BOOLEAN
185 * IopDeviceNodeHasUserFlag(
186 * PDEVICE_NODE DeviceNode,
187 * ULONG UserFlag);
188 */
189 #define IopDeviceNodeHasUserFlag(DeviceNode, UserFlag)(((DeviceNode)->UserFlags & (UserFlag)) > 0)
190
191 /*
192 * VOID
193 * IopDeviceNodeSetProblem(
194 * PDEVICE_NODE DeviceNode,
195 * ULONG Problem);
196 */
197 #define IopDeviceNodeSetProblem(DeviceNode, Problem)((DeviceNode)->Problem |= (Problem))
198
199 /*
200 * VOID
201 * IopDeviceNodeClearProblem(
202 * PDEVICE_NODE DeviceNode,
203 * ULONG Problem);
204 */
205 #define IopDeviceNodeClearProblem(DeviceNode, Problem)((DeviceNode)->Problem &= ~(Problem))
206
207 /*
208 * BOOLEAN
209 * IopDeviceNodeHasProblem(
210 * PDEVICE_NODE DeviceNode,
211 * ULONG Problem);
212 */
213 #define IopDeviceNodeHasProblem(DeviceNode, Problem)(((DeviceNode)->Problem & (Problem)) > 0)
214
215
216 /*
217 Called on every visit of a node during a preorder-traversal of the device
218 node tree.
219 If the routine returns STATUS_UNSUCCESSFUL the traversal will stop and
220 STATUS_SUCCESS is returned to the caller who initiated the tree traversal.
221 Any other returned status code will be returned to the caller. If a status
222 code that indicates an error (other than STATUS_UNSUCCESSFUL) is returned,
223 the traversal is stopped immediately and the status code is returned to
224 the caller.
225 */
226 typedef NTSTATUS (*DEVICETREE_TRAVERSE_ROUTINE)(
227 PDEVICE_NODE DeviceNode,
228 PVOID Context);
229
230 /* Context information for traversing the device tree */
231 typedef struct _DEVICETREE_TRAVERSE_CONTEXT
232 {
233 /* Current device node during a traversal */
234 PDEVICE_NODE DeviceNode;
235 /* Initial device node where we start the traversal */
236 PDEVICE_NODE FirstDeviceNode;
237 /* Action routine to be called for every device node */
238 DEVICETREE_TRAVERSE_ROUTINE Action;
239 /* Context passed to the action routine */
240 PVOID Context;
241 } DEVICETREE_TRAVERSE_CONTEXT, *PDEVICETREE_TRAVERSE_CONTEXT;
242
243 /*
244 * VOID
245 * IopInitDeviceTreeTraverseContext(
246 * PDEVICETREE_TRAVERSE_CONTEXT DeviceTreeTraverseContext,
247 * PDEVICE_NODE DeviceNode,
248 * DEVICETREE_TRAVERSE_ROUTINE Action,
249 * PVOID Context);
250 */
251 #define IopInitDeviceTreeTraverseContext( \
252 _DeviceTreeTraverseContext, _DeviceNode, _Action, _Context) { \
253 (_DeviceTreeTraverseContext)->FirstDeviceNode = (_DeviceNode); \
254 (_DeviceTreeTraverseContext)->Action = (_Action); \
255 (_DeviceTreeTraverseContext)->Context = (_Context); }
256
257
258 extern PDEVICE_NODE IopRootDeviceNode;
259 extern ULONG IoOtherOperationCount;
260 extern ULONGLONG IoOtherTransferCount;
261
262 VOID
263 PnpInit(VOID);
264
265 VOID
266 IopInitDriverImplementation(VOID);
267
268 NTSTATUS
269 IopGetSystemPowerDeviceObject(PDEVICE_OBJECT *DeviceObject);
270 NTSTATUS
271 IopCreateDeviceNode(PDEVICE_NODE ParentNode,
272 PDEVICE_OBJECT PhysicalDeviceObject,
273 PDEVICE_NODE *DeviceNode);
274 NTSTATUS
275 IopFreeDeviceNode(PDEVICE_NODE DeviceNode);
276
277 VOID
278 IoInitCancelHandling(VOID);
279 VOID
280 IoInitFileSystemImplementation(VOID);
281 VOID
282 IoInitVpbImplementation(VOID);
283
284 NTSTATUS
285 IoMountVolume(IN PDEVICE_OBJECT DeviceObject,
286 IN BOOLEAN AllowRawMount);
287 POBJECT IoOpenSymlink(POBJECT SymbolicLink);
288 POBJECT IoOpenFileOnDevice(POBJECT SymbolicLink, PWCHAR Name);
289
290 VOID STDCALL
291 IoSecondStageCompletion(
292 PKAPC Apc,
293 PKNORMAL_ROUTINE* NormalRoutine,
294 PVOID* NormalContext,
295 PVOID* SystemArgument1,
296 PVOID* SystemArgument2);
297
298 NTSTATUS STDCALL
299 IopCreateFile(PVOID ObjectBody,
300 PVOID Parent,
301 PWSTR RemainingPath,
302 POBJECT_ATTRIBUTES ObjectAttributes);
303 NTSTATUS STDCALL
304 IopCreateDevice(PVOID ObjectBody,
305 PVOID Parent,
306 PWSTR RemainingPath,
307 POBJECT_ATTRIBUTES ObjectAttributes);
308 NTSTATUS IoAttachVpb(PDEVICE_OBJECT DeviceObject);
309
310 PIRP IoBuildSynchronousFsdRequestWithMdl(ULONG MajorFunction,
311 PDEVICE_OBJECT DeviceObject,
312 PMDL Mdl,
313 PLARGE_INTEGER StartingOffset,
314 PKEVENT Event,
315 PIO_STATUS_BLOCK IoStatusBlock,
316 BOOLEAN PagingIo);
317
318 VOID IoInitShutdownNotification(VOID);
319 VOID IoShutdownRegisteredDevices(VOID);
320 VOID IoShutdownRegisteredFileSystems(VOID);
321
322 NTSTATUS STDCALL
323 IoPageWrite(PFILE_OBJECT FileObject,
324 PMDL Mdl,
325 PLARGE_INTEGER Offset,
326 PKEVENT Event,
327 PIO_STATUS_BLOCK StatusBlock);
328
329 NTSTATUS
330 IoCreateArcNames(VOID);
331
332 NTSTATUS
333 IoCreateSystemRootLink(PCHAR ParameterLine);
334
335 NTSTATUS
336 IopInitiatePnpIrp(
337 PDEVICE_OBJECT DeviceObject,
338 PIO_STATUS_BLOCK IoStatusBlock,
339 ULONG MinorFunction,
340 PIO_STACK_LOCATION Stack);
341
342 BOOLEAN
343 IopCreateUnicodeString(
344 PUNICODE_STRING Destination,
345 PWSTR Source,
346 POOL_TYPE PoolType);
347
348
349 NTSTATUS
350 IoCreateDriverList(VOID);
351
352 NTSTATUS
353 IoDestroyDriverList(VOID);
354
355
356 /* errlog.c */
357
358 NTSTATUS
359 IopInitErrorLog (VOID);
360
361
362 /* rawfs.c */
363
364 BOOLEAN
365 RawFsIsRawFileSystemDeviceObject(IN PDEVICE_OBJECT DeviceObject);
366
367 NTSTATUS STDCALL
368 RawFsDriverEntry(PDRIVER_OBJECT DriverObject,
369 PUNICODE_STRING RegistryPath);
370
371
372 /* pnproot.c */
373
374 NTSTATUS
375 STDCALL
376 PnpRootDriverEntry(
377 IN PDRIVER_OBJECT DriverObject,
378 IN PUNICODE_STRING RegistryPath);
379
380 NTSTATUS
381 PnpRootCreateDevice(
382 PDEVICE_OBJECT *PhysicalDeviceObject);
383
384 /* device.c */
385
386 NTSTATUS FASTCALL
387 IopInitializeDevice(
388 PDEVICE_NODE DeviceNode,
389 PDRIVER_OBJECT DriverObject);
390
391 /* driver.c */
392
393 VOID FASTCALL
394 IopInitializeBootDrivers(VOID);
395
396 VOID FASTCALL
397 IopInitializeSystemDrivers(VOID);
398
399 NTSTATUS FASTCALL
400 IopCreateDriverObject(
401 PDRIVER_OBJECT *DriverObject,
402 PUNICODE_STRING ServiceName,
403 BOOLEAN FileSystemDriver,
404 PVOID DriverImageStart,
405 ULONG DriverImageSize);
406
407 NTSTATUS FASTCALL
408 IopLoadServiceModule(
409 IN PUNICODE_STRING ServiceName,
410 OUT PMODULE_OBJECT *ModuleObject);
411
412 NTSTATUS FASTCALL
413 IopInitializeDriverModule(
414 IN PDEVICE_NODE DeviceNode,
415 IN PMODULE_OBJECT ModuleObject,
416 IN BOOLEAN FileSystemDriver,
417 OUT PDRIVER_OBJECT *DriverObject);
418
419 NTSTATUS FASTCALL
420 IopAttachFilterDrivers(
421 PDEVICE_NODE DeviceNode,
422 BOOLEAN Lower);
423
424 VOID FASTCALL
425 IopMarkLastReinitializeDriver(VOID);
426
427 VOID FASTCALL
428 IopReinitializeDrivers(VOID);
429
430 /* pnpmgr.c */
431
432 NTSTATUS
433 IopInitializePnpServices(
434 IN PDEVICE_NODE DeviceNode,
435 IN BOOLEAN BootDrivers);
436
437 NTSTATUS
438 IopInvalidateDeviceRelations(
439 IN PDEVICE_NODE DeviceNode,
440 IN DEVICE_RELATION_TYPE Type);
441
442 #endif