update for HEAD-2003091401
[reactos.git] / 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$
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
36
37 #ifndef __USE_W32API
38 #define DEVICE_TYPE_FROM_CTL_CODE(ctlCode) (((ULONG)(ctlCode&0xffff0000))>>16)
39 #endif
40
41 #define IO_METHOD_FROM_CTL_CODE(ctlCode) (ctlCode&0x00000003)
42
43
44 typedef struct _IO_COMPLETION_PACKET{
45    ULONG             Key;
46    ULONG             Overlapped;
47    IO_STATUS_BLOCK   IoStatus;
48    LIST_ENTRY        ListEntry;
49 } IO_COMPLETION_PACKET, *PIO_COMPLETION_PACKET;
50
51
52 typedef struct _DEVICE_NODE
53 {
54   struct _DEVICE_NODE *Parent;
55   struct _DEVICE_NODE *PrevSibling;
56   struct _DEVICE_NODE *NextSibling;
57   struct _DEVICE_NODE *Child;
58   PDRIVER_OBJECT DriverObject;
59   PDEVICE_OBJECT Pdo;
60   UNICODE_STRING InstancePath;
61   UNICODE_STRING ServiceName;
62   //TargetDeviceNotifyList?
63   PDEVICE_CAPABILITIES CapabilityFlags;
64   ULONG Flags;
65   ULONG UserFlags;
66   ULONG DisableableDepends;
67   ULONG Problem;
68   PCM_RESOURCE_LIST CmResourceList;
69   PCM_RESOURCE_LIST BootResourcesList;
70   PIO_RESOURCE_REQUIREMENTS_LIST ResourceRequirementsList;
71   /* Not NT's */
72   UNICODE_STRING DeviceID;
73   UNICODE_STRING InstanceID;
74   UNICODE_STRING HardwareIDs;
75   UNICODE_STRING CompatibleIDs;
76   UNICODE_STRING DeviceText;
77   UNICODE_STRING DeviceTextLocation;
78   PPNP_BUS_INFORMATION BusInformation;
79 } DEVICE_NODE, *PDEVICE_NODE;
80
81 /* For Flags field */
82 #define DNF_PROCESSED                           0x00000001
83 #define DNF_STARTED                             0x00000002
84 #define DNF_START_FAILED                        0x00000004
85 #define DNF_ENUMERATED                          0x00000008
86 #define DNF_DELETED                             0x00000010
87 #define DNF_MADEUP                              0x00000020
88 #define DNF_START_REQUEST_PENDING               0x00000040
89 #define DNF_NO_RESOURCE_REQUIRED                0x00000080
90 #define DNF_INSUFFICIENT_RESOURCES              0x00000100
91 #define DNF_RESOURCE_ASSIGNED                   0x00000200
92 #define DNF_RESOURCE_REPORTED                   0x00000400
93 #define DNF_HAL_NODE                            0x00000800 // ???
94 #define DNF_ADDED                               0x00001000
95 #define DNF_ADD_FAILED                          0x00002000
96 #define DNF_LEGACY_DRIVER                       0x00004000
97 #define DNF_STOPPED                             0x00008000
98 #define DNF_WILL_BE_REMOVED                     0x00010000
99 #define DNF_NEED_TO_ENUM                        0x00020000
100 #define DNF_NOT_CONFIGURED                      0x00040000
101 #define DNF_REINSTALL                           0x00080000
102 #define DNF_RESOURCE_REQUIREMENTS_NEED_FILTERED 0x00100000 // ???
103 #define DNF_DISABLED                            0x00200000
104 #define DNF_RESTART_OK                          0x00400000
105 #define DNF_NEED_RESTART                        0x00800000
106 #define DNF_VISITED                             0x01000000
107 #define DNF_ASSIGNING_RESOURCES                 0x02000000
108 #define DNF_BEEING_ENUMERATED                   0x04000000
109 #define DNF_NEED_ENUMERATION_ONLY               0x08000000
110 #define DNF_LOCKED                              0x10000000
111 #define DNF_HAS_BOOT_CONFIG                     0x20000000
112 #define DNF_BOOT_CONFIG_RESERVED                0x40000000
113 #define DNF_HAS_PROBLEM                         0x80000000 // ???
114
115 /* For UserFlags field */
116 #define DNUF_DONT_SHOW_IN_UI    0x0002
117 #define DNUF_NOT_DISABLEABLE    0x0008
118
119 /* For Problem field */
120 #define CM_PROB_NOT_CONFIGURED  1
121 #define CM_PROB_FAILED_START    10
122 #define CM_PROB_NORMAL_CONFLICT 12
123 #define CM_PROB_NEED_RESTART    14
124 #define CM_PROB_REINSTALL       18
125 #define CM_PROB_WILL_BE_REMOVED 21
126 #define CM_PROB_DISABLED        22
127 #define CM_PROB_FAILED_INSTALL  28
128 #define CM_PROB_FAILED_ADD      31
129
130 /*
131  * VOID
132  * IopDeviceNodeSetFlag(
133  *   PDEVICE_NODE DeviceNode,
134  *   ULONG Flag);
135  */
136 #define IopDeviceNodeSetFlag(DeviceNode, Flag)((DeviceNode)->Flags |= (Flag))
137
138 /*
139  * VOID
140  * IopDeviceNodeClearFlag(
141  *   PDEVICE_NODE DeviceNode,
142  *   ULONG Flag);
143  */
144 #define IopDeviceNodeClearFlag(DeviceNode, Flag)((DeviceNode)->Flags &= ~(Flag))
145
146 /*
147  * BOOLEAN
148  * IopDeviceNodeHasFlag(
149  *   PDEVICE_NODE DeviceNode,
150  *   ULONG Flag);
151  */
152 #define IopDeviceNodeHasFlag(DeviceNode, Flag)(((DeviceNode)->Flags & (Flag)) > 0)
153
154 /*
155  * VOID
156  * IopDeviceNodeSetUserFlag(
157  *   PDEVICE_NODE DeviceNode,
158  *   ULONG UserFlag);
159  */
160 #define IopDeviceNodeSetUserFlag(DeviceNode, UserFlag)((DeviceNode)->UserFlags |= (UserFlag))
161
162 /*
163  * VOID
164  * IopDeviceNodeClearUserFlag(
165  *   PDEVICE_NODE DeviceNode,
166  *   ULONG UserFlag);
167  */
168 #define IopDeviceNodeClearUserFlag(DeviceNode, UserFlag)((DeviceNode)->UserFlags &= ~(UserFlag))
169
170 /*
171  * BOOLEAN
172  * IopDeviceNodeHasUserFlag(
173  *   PDEVICE_NODE DeviceNode,
174  *   ULONG UserFlag);
175  */
176 #define IopDeviceNodeHasUserFlag(DeviceNode, UserFlag)(((DeviceNode)->UserFlags & (UserFlag)) > 0)
177
178  /*
179  * VOID
180  * IopDeviceNodeSetProblem(
181  *   PDEVICE_NODE DeviceNode,
182  *   ULONG Problem);
183  */
184 #define IopDeviceNodeSetProblem(DeviceNode, Problem)((DeviceNode)->Problem |= (Problem))
185
186 /*
187  * VOID
188  * IopDeviceNodeClearProblem(
189  *   PDEVICE_NODE DeviceNode,
190  *   ULONG Problem);
191  */
192 #define IopDeviceNodeClearProblem(DeviceNode, Problem)((DeviceNode)->Problem &= ~(Problem))
193
194 /*
195  * BOOLEAN
196  * IopDeviceNodeHasProblem(
197  *   PDEVICE_NODE DeviceNode,
198  *   ULONG Problem);
199  */
200 #define IopDeviceNodeHasProblem(DeviceNode, Problem)(((DeviceNode)->Problem & (Problem)) > 0)
201
202
203 /*
204    Called on every visit of a node during a preorder-traversal of the device
205    node tree.
206    If the routine returns STATUS_UNSUCCESSFUL the traversal will stop and
207    STATUS_SUCCESS is returned to the caller who initiated the tree traversal.
208    Any other returned status code will be returned to the caller. If a status
209    code that indicates an error (other than STATUS_UNSUCCESSFUL) is returned,
210    the traversal is stopped immediately and the status code is returned to
211    the caller.
212  */
213 typedef NTSTATUS (*DEVICETREE_TRAVERSE_ROUTINE)(
214   PDEVICE_NODE DeviceNode,
215   PVOID Context);
216
217 /* Context information for traversing the device tree */
218 typedef struct _DEVICETREE_TRAVERSE_CONTEXT
219 {
220   /* Current device node during a traversal */
221   PDEVICE_NODE DeviceNode;
222   /* Initial device node where we start the traversal */
223   PDEVICE_NODE FirstDeviceNode;
224   /* Action routine to be called for every device node */
225   DEVICETREE_TRAVERSE_ROUTINE Action;
226   /* Context passed to the action routine */
227   PVOID Context;
228 } DEVICETREE_TRAVERSE_CONTEXT, *PDEVICETREE_TRAVERSE_CONTEXT;
229
230 /*
231  * VOID
232  * IopInitDeviceTreeTraverseContext(
233  *   PDEVICETREE_TRAVERSE_CONTEXT DeviceTreeTraverseContext,
234  *   PDEVICE_NODE DeviceNode,
235  *   DEVICETREE_TRAVERSE_ROUTINE Action,
236  *   PVOID Context);
237  */
238 #define IopInitDeviceTreeTraverseContext( \
239   _DeviceTreeTraverseContext, _DeviceNode, _Action, _Context) { \
240   (_DeviceTreeTraverseContext)->FirstDeviceNode = (_DeviceNode); \
241   (_DeviceTreeTraverseContext)->Action = (_Action); \
242   (_DeviceTreeTraverseContext)->Context = (_Context); }
243
244
245 extern PDEVICE_NODE IopRootDeviceNode;
246
247 VOID
248 PnpInit(VOID);
249
250 VOID
251 IopInitDriverImplementation(VOID);
252
253 NTSTATUS
254 IopGetSystemPowerDeviceObject(PDEVICE_OBJECT *DeviceObject);
255 NTSTATUS
256 IopCreateDeviceNode(PDEVICE_NODE ParentNode,
257                     PDEVICE_OBJECT PhysicalDeviceObject,
258                     PDEVICE_NODE *DeviceNode);
259 NTSTATUS
260 IopFreeDeviceNode(PDEVICE_NODE DeviceNode);
261 NTSTATUS
262 IopInterrogateBusExtender(PDEVICE_NODE DeviceNode,
263                           PDEVICE_OBJECT Pdo,
264                           BOOLEAN BootDriversOnly);
265 VOID
266 IopLoadBootStartDrivers(VOID);
267 NTSTATUS
268 IopCreateDriverObject(PDRIVER_OBJECT *DriverObject,
269                       PUNICODE_STRING ServiceName,
270                       BOOLEAN FileSystemDriver,
271                       PVOID DriverImageStart,
272                       ULONG DriverImageSize);
273 NTSTATUS
274 IopInitializeDeviceNodeService(PDEVICE_NODE DeviceNode);
275 NTSTATUS
276 IopInitializeDriver(PDRIVER_INITIALIZE DriverEntry,
277                     PDEVICE_NODE DeviceNode,
278                     BOOLEAN FileSystemDriver,
279                     PVOID DriverImageStart,
280                     ULONG DriverImageSize);
281 VOID
282 IoInitCancelHandling(VOID);
283 VOID
284 IoInitFileSystemImplementation(VOID);
285 VOID
286 IoInitVpbImplementation(VOID);
287
288 NTSTATUS
289 IoMountVolume(IN PDEVICE_OBJECT DeviceObject,
290               IN BOOLEAN AllowRawMount);
291 POBJECT IoOpenSymlink(POBJECT SymbolicLink);
292 POBJECT IoOpenFileOnDevice(POBJECT SymbolicLink, PWCHAR Name);
293
294 VOID STDCALL
295 IoSecondStageCompletion(
296    PKAPC Apc,
297    PKNORMAL_ROUTINE* NormalRoutine,
298    PVOID* NormalContext,
299    PVOID* SystemArgument1,
300    PVOID* SystemArgument2);
301
302 NTSTATUS STDCALL
303 IopCreateFile(PVOID ObjectBody,
304               PVOID Parent,
305               PWSTR RemainingPath,
306               POBJECT_ATTRIBUTES ObjectAttributes);
307 NTSTATUS STDCALL
308 IopCreateDevice(PVOID ObjectBody,
309                 PVOID Parent,
310                 PWSTR RemainingPath,
311                 POBJECT_ATTRIBUTES ObjectAttributes);
312 NTSTATUS IoAttachVpb(PDEVICE_OBJECT DeviceObject);
313
314 PIRP IoBuildSynchronousFsdRequestWithMdl(ULONG MajorFunction,
315                                          PDEVICE_OBJECT DeviceObject,
316                                          PMDL Mdl,
317                                          PLARGE_INTEGER StartingOffset,
318                                          PKEVENT Event,
319                                          PIO_STATUS_BLOCK IoStatusBlock,
320                                          BOOLEAN PagingIo);
321
322 VOID IoInitShutdownNotification(VOID);
323 VOID IoShutdownRegisteredDevices(VOID);
324 VOID IoShutdownRegisteredFileSystems(VOID);
325
326 NTSTATUS STDCALL
327 IoPageWrite(PFILE_OBJECT        FileObject,
328             PMDL                Mdl,
329             PLARGE_INTEGER      Offset,
330             PKEVENT             Event,
331             PIO_STATUS_BLOCK    StatusBlock);
332
333 NTSTATUS
334 IoCreateArcNames(VOID);
335
336 NTSTATUS
337 IoCreateSystemRootLink(PCHAR ParameterLine);
338
339 NTSTATUS
340 IopInitiatePnpIrp(
341   PDEVICE_OBJECT DeviceObject,
342   PIO_STATUS_BLOCK IoStatusBlock,
343   ULONG MinorFunction,
344   PIO_STACK_LOCATION Stack);
345
346 BOOLEAN
347 IopCreateUnicodeString(
348   PUNICODE_STRING       Destination,
349   PWSTR Source,
350   POOL_TYPE PoolType);
351
352
353 NTSTATUS
354 IoCreateDriverList(VOID);
355
356 NTSTATUS
357 IoDestroyDriverList(VOID);
358
359
360 /* errlog.c */
361
362 NTSTATUS
363 IopInitErrorLog (VOID);
364
365
366 /* rawfs.c */
367
368 BOOLEAN
369 RawFsIsRawFileSystemDeviceObject(IN PDEVICE_OBJECT DeviceObject);
370
371 NTSTATUS STDCALL
372 RawFsDriverEntry(PDRIVER_OBJECT DriverObject,
373   PUNICODE_STRING RegistryPath);
374
375
376 /* pnproot.c */
377
378 NTSTATUS
379 STDCALL
380 PnpRootDriverEntry(
381   IN PDRIVER_OBJECT DriverObject,
382   IN PUNICODE_STRING RegistryPath);
383
384 NTSTATUS
385 PnpRootCreateDevice(
386   PDEVICE_OBJECT *PhysicalDeviceObject);
387
388 #endif