3831a123e02395beabc593c3e970c3f55db3dec2
[reactos.git] / reactos / ntoskrnl / include / internal / io.h
1 #ifndef __NTOSKRNL_INCLUDE_INTERNAL_IO_H
2 #define __NTOSKRNL_INCLUDE_INTERNAL_IO_H
3
4 #include <ddk/ntdddisk.h>
5
6 /* STRUCTURES ***************************************************************/
7
8 typedef struct _DISKENTRY
9 {
10 LIST_ENTRY ListEntry;
11 ULONG DiskNumber;
12 ULONG Signature;
13 ULONG Checksum;
14 PDEVICE_OBJECT DeviceObject;
15 } DISKENTRY, *PDISKENTRY;
16
17 #define PARTITION_TBL_SIZE 4
18
19 #include <pshpack1.h>
20
21 typedef struct _PARTITION
22 {
23 unsigned char BootFlags; /* bootable? 0=no, 128=yes */
24 unsigned char StartingHead; /* beginning head number */
25 unsigned char StartingSector; /* beginning sector number */
26 unsigned char StartingCylinder; /* 10 bit nmbr, with high 2 bits put in begsect */
27 unsigned char PartitionType; /* Operating System type indicator code */
28 unsigned char EndingHead; /* ending head number */
29 unsigned char EndingSector; /* ending sector number */
30 unsigned char EndingCylinder; /* also a 10 bit nmbr, with same high 2 bit trick */
31 unsigned int StartingBlock; /* first sector relative to start of disk */
32 unsigned int SectorCount; /* number of sectors in partition */
33 } PARTITION, *PPARTITION;
34
35 typedef struct _PARTITION_SECTOR
36 {
37 UCHAR BootCode[440]; /* 0x000 */
38 ULONG Signature; /* 0x1B8 */
39 UCHAR Reserved[2]; /* 0x1BC */
40 PARTITION Partition[PARTITION_TBL_SIZE]; /* 0x1BE */
41 USHORT Magic; /* 0x1FE */
42 } PARTITION_SECTOR, *PPARTITION_SECTOR;
43
44 #include <poppack.h>
45
46 #define IO_METHOD_FROM_CTL_CODE(ctlCode) (ctlCode&0x00000003)
47
48 extern POBJECT_TYPE IoCompletionType;
49 extern PDEVICE_NODE IopRootDeviceNode;
50
51 /* This is like the IRP Overlay so we can optimize its insertion */
52 typedef struct _IO_COMPLETION_PACKET
53 {
54 struct
55 {
56 LIST_ENTRY ListEntry;
57 union
58 {
59 struct _IO_STACK_LOCATION *CurrentStackLocation;
60 ULONG PacketType;
61 };
62 };
63 PVOID Key;
64 PVOID Context;
65 IO_STATUS_BLOCK IoStatus;
66 } IO_COMPLETION_PACKET, *PIO_COMPLETION_PACKET;
67
68 /* List of Bus Type GUIDs */
69 typedef struct _IO_BUS_TYPE_GUID_LIST
70 {
71 ULONG GuidCount;
72 FAST_MUTEX Lock;
73 GUID Guids[1];
74 } IO_BUS_TYPE_GUID_LIST, *PIO_BUS_TYPE_GUID_LIST;
75 extern PIO_BUS_TYPE_GUID_LIST IopBusTypeGuidList;
76
77 /* Packet Types */
78 #define IrpCompletionPacket 0x1
79 #define IrpMiniCompletionPacket 0x2
80
81 /*
82 * VOID
83 * IopDeviceNodeSetFlag(
84 * PDEVICE_NODE DeviceNode,
85 * ULONG Flag);
86 */
87 #define IopDeviceNodeSetFlag(DeviceNode, Flag) \
88 ((DeviceNode)->Flags |= (Flag))
89
90 /*
91 * VOID
92 * IopDeviceNodeClearFlag(
93 * PDEVICE_NODE DeviceNode,
94 * ULONG Flag);
95 */
96 #define IopDeviceNodeClearFlag(DeviceNode, Flag) \
97 ((DeviceNode)->Flags &= ~(Flag))
98
99 /*
100 * BOOLEAN
101 * IopDeviceNodeHasFlag(
102 * PDEVICE_NODE DeviceNode,
103 * ULONG Flag);
104 */
105 #define IopDeviceNodeHasFlag(DeviceNode, Flag) \
106 (((DeviceNode)->Flags & (Flag)) > 0)
107
108 /*
109 * VOID
110 * IopDeviceNodeSetUserFlag(
111 * PDEVICE_NODE DeviceNode,
112 * ULONG UserFlag);
113 */
114 #define IopDeviceNodeSetUserFlag(DeviceNode, UserFlag) \
115 ((DeviceNode)->UserFlags |= (UserFlag))
116
117 /*
118 * VOID
119 * IopDeviceNodeClearUserFlag(
120 * PDEVICE_NODE DeviceNode,
121 * ULONG UserFlag);
122 */
123 #define IopDeviceNodeClearUserFlag(DeviceNode, UserFlag) \
124 ((DeviceNode)->UserFlags &= ~(UserFlag))
125
126 /*
127 * BOOLEAN
128 * IopDeviceNodeHasUserFlag(
129 * PDEVICE_NODE DeviceNode,
130 * ULONG UserFlag);
131 */
132 #define IopDeviceNodeHasUserFlag(DeviceNode, UserFlag) \
133 (((DeviceNode)->UserFlags & (UserFlag)) > 0)
134
135 /*
136 * VOID
137 * IopDeviceNodeSetProblem(
138 * PDEVICE_NODE DeviceNode,
139 * ULONG Problem);
140 */
141 #define IopDeviceNodeSetProblem(DeviceNode, Problem) \
142 ((DeviceNode)->Problem |= (Problem))
143
144 /*
145 * VOID
146 * IopDeviceNodeClearProblem(
147 * PDEVICE_NODE DeviceNode,
148 * ULONG Problem);
149 */
150 #define IopDeviceNodeClearProblem(DeviceNode, Problem) \
151 ((DeviceNode)->Problem &= ~(Problem))
152
153 /*
154 * BOOLEAN
155 * IopDeviceNodeHasProblem(
156 * PDEVICE_NODE DeviceNode,
157 * ULONG Problem);
158 */
159 #define IopDeviceNodeHasProblem(DeviceNode, Problem) \
160 (((DeviceNode)->Problem & (Problem)) > 0)
161
162
163 /*
164 Called on every visit of a node during a preorder-traversal of the device
165 node tree.
166 If the routine returns STATUS_UNSUCCESSFUL the traversal will stop and
167 STATUS_SUCCESS is returned to the caller who initiated the tree traversal.
168 Any other returned status code will be returned to the caller. If a status
169 code that indicates an error (other than STATUS_UNSUCCESSFUL) is returned,
170 the traversal is stopped immediately and the status code is returned to
171 the caller.
172 */
173 typedef NTSTATUS (*DEVICETREE_TRAVERSE_ROUTINE)(
174 PDEVICE_NODE DeviceNode,
175 PVOID Context
176 );
177
178 /* Context information for traversing the device tree */
179 typedef struct _DEVICETREE_TRAVERSE_CONTEXT
180 {
181 /* Current device node during a traversal */
182 PDEVICE_NODE DeviceNode;
183 /* Initial device node where we start the traversal */
184 PDEVICE_NODE FirstDeviceNode;
185 /* Action routine to be called for every device node */
186 DEVICETREE_TRAVERSE_ROUTINE Action;
187 /* Context passed to the action routine */
188 PVOID Context;
189 } DEVICETREE_TRAVERSE_CONTEXT, *PDEVICETREE_TRAVERSE_CONTEXT;
190
191 /*
192 * VOID
193 * IopInitDeviceTreeTraverseContext(
194 * PDEVICETREE_TRAVERSE_CONTEXT DeviceTreeTraverseContext,
195 * PDEVICE_NODE DeviceNode,
196 * DEVICETREE_TRAVERSE_ROUTINE Action,
197 * PVOID Context);
198 */
199 #define IopInitDeviceTreeTraverseContext( \
200 _DeviceTreeTraverseContext, _DeviceNode, _Action, _Context) { \
201 (_DeviceTreeTraverseContext)->FirstDeviceNode = (_DeviceNode); \
202 (_DeviceTreeTraverseContext)->Action = (_Action); \
203 (_DeviceTreeTraverseContext)->Context = (_Context); }
204
205 VOID
206 PnpInit(VOID);
207
208 VOID
209 PnpInit2(VOID);
210
211 VOID
212 IopInitDriverImplementation(VOID);
213
214 VOID
215 IopInitPnpNotificationImplementation(VOID);
216
217 VOID
218 IopNotifyPlugPlayNotification(
219 IN PDEVICE_OBJECT DeviceObject,
220 IN IO_NOTIFICATION_EVENT_CATEGORY EventCategory,
221 IN GUID* Event,
222 IN PVOID EventCategoryData1,
223 IN PVOID EventCategoryData2
224 );
225
226 NTSTATUS
227 IopGetSystemPowerDeviceObject(PDEVICE_OBJECT *DeviceObject);
228
229 NTSTATUS
230 IopCreateDeviceNode(
231 PDEVICE_NODE ParentNode,
232 PDEVICE_OBJECT PhysicalDeviceObject,
233 PDEVICE_NODE *DeviceNode
234 );
235
236 NTSTATUS
237 IopFreeDeviceNode(PDEVICE_NODE DeviceNode);
238
239 VOID
240 IoInitCancelHandling(VOID);
241
242 VOID
243 IoInitFileSystemImplementation(VOID);
244
245 VOID
246 IoInitVpbImplementation(VOID);
247
248 NTSTATUS
249 IoMountVolume(
250 IN PDEVICE_OBJECT DeviceObject,
251 IN BOOLEAN AllowRawMount
252 );
253
254 PVOID
255 IoOpenSymlink(PVOID SymbolicLink);
256
257 PVOID
258 IoOpenFileOnDevice(
259 PVOID SymbolicLink,
260 PWCHAR Name
261 );
262
263 NTSTATUS
264 STDCALL
265 IopCreateDevice(
266 PVOID ObjectBody,
267 PVOID Parent,
268 PWSTR RemainingPath,
269 POBJECT_ATTRIBUTES ObjectAttributes
270 );
271
272 NTSTATUS
273 STDCALL
274 IopAttachVpb(PDEVICE_OBJECT DeviceObject);
275
276 VOID
277 IoInitShutdownNotification(VOID);
278
279 VOID
280 IoShutdownRegisteredDevices(VOID);
281
282 VOID
283 IoShutdownRegisteredFileSystems(VOID);
284
285 NTSTATUS
286 IoCreateArcNames(VOID);
287
288 NTSTATUS
289 IoCreateSystemRootLink(PCHAR ParameterLine);
290
291 NTSTATUS
292 IopInitiatePnpIrp(
293 PDEVICE_OBJECT DeviceObject,
294 PIO_STATUS_BLOCK IoStatusBlock,
295 ULONG MinorFunction,
296 PIO_STACK_LOCATION Stack
297 );
298
299 NTSTATUS
300 IoCreateDriverList(VOID);
301
302 NTSTATUS
303 IoDestroyDriverList(VOID);
304
305 /* bootlog.c */
306
307 VOID
308 IopInitBootLog(BOOLEAN StartBootLog);
309
310 VOID
311 IopStartBootLog(VOID);
312
313 VOID
314 IopStopBootLog(VOID);
315
316 VOID
317 IopBootLog(
318 PUNICODE_STRING DriverName,
319 BOOLEAN Success
320 );
321
322 VOID
323 IopSaveBootLogToFile(VOID);
324
325 /* cancel.c */
326
327 VOID
328 STDCALL
329 IoCancelThreadIo(PETHREAD Thread);
330
331 /* errlog.c */
332
333 NTSTATUS
334 IopInitErrorLog(VOID);
335
336 /* rawfs.c */
337
338 BOOLEAN
339 RawFsIsRawFileSystemDeviceObject(IN PDEVICE_OBJECT DeviceObject);
340
341 NTSTATUS
342 STDCALL
343 RawFsDriverEntry(PDRIVER_OBJECT DriverObject,
344 PUNICODE_STRING RegistryPath);
345
346
347 /* pnpmgr.c */
348
349 PDEVICE_NODE
350 FASTCALL
351 IopGetDeviceNode(PDEVICE_OBJECT DeviceObject);
352
353 NTSTATUS
354 IopActionConfigureChildServices(PDEVICE_NODE DeviceNode,
355 PVOID Context);
356
357 NTSTATUS
358 IopActionInitChildServices(PDEVICE_NODE DeviceNode,
359 PVOID Context,
360 BOOLEAN BootDrivers);
361
362
363 /* pnproot.c */
364
365 NTSTATUS
366 STDCALL
367 PnpRootDriverEntry(
368 IN PDRIVER_OBJECT DriverObject,
369 IN PUNICODE_STRING RegistryPath
370 );
371
372 NTSTATUS
373 PnpRootCreateDevice(PDEVICE_OBJECT *PhysicalDeviceObject);
374
375 /* device.c */
376
377 NTSTATUS
378 FASTCALL
379 IopInitializeDevice(
380 PDEVICE_NODE DeviceNode,
381 PDRIVER_OBJECT DriverObject
382 );
383
384 NTSTATUS
385 IopStartDevice(PDEVICE_NODE DeviceNode);
386
387 /* driver.c */
388
389 VOID
390 FASTCALL
391 IopInitializeBootDrivers(VOID);
392
393 VOID
394 FASTCALL
395 IopInitializeSystemDrivers(VOID);
396
397 NTSTATUS
398 FASTCALL
399 IopCreateDriverObject(
400 PDRIVER_OBJECT *DriverObject,
401 PUNICODE_STRING ServiceName,
402 ULONG CreateAttributes,
403 BOOLEAN FileSystemDriver,
404 PVOID DriverImageStart,
405 ULONG DriverImageSize
406 );
407
408 NTSTATUS
409 FASTCALL
410 IopGetDriverObject(
411 PDRIVER_OBJECT *DriverObject,
412 PUNICODE_STRING ServiceName,
413 BOOLEAN FileSystem
414 );
415
416 NTSTATUS
417 FASTCALL
418 IopLoadServiceModule(
419 IN PUNICODE_STRING ServiceName,
420 OUT PLDR_DATA_TABLE_ENTRY *ModuleObject
421 );
422
423 NTSTATUS
424 FASTCALL
425 IopInitializeDriverModule(
426 IN PDEVICE_NODE DeviceNode,
427 IN PLDR_DATA_TABLE_ENTRY ModuleObject,
428 IN PUNICODE_STRING ServiceName,
429 IN BOOLEAN FileSystemDriver,
430 OUT PDRIVER_OBJECT *DriverObject
431 );
432
433 NTSTATUS
434 FASTCALL
435 IopAttachFilterDrivers(
436 PDEVICE_NODE DeviceNode,
437 BOOLEAN Lower
438 );
439
440 VOID
441 FASTCALL
442 IopMarkLastReinitializeDriver(VOID);
443
444 VOID
445 FASTCALL
446 IopReinitializeDrivers(VOID);
447
448 /* file.c */
449
450 NTSTATUS
451 STDCALL
452 IopCreateFile(
453 PVOID ObjectBody,
454 PVOID Parent,
455 PWSTR RemainingPath,
456 POBJECT_CREATE_INFORMATION ObjectAttributes
457 );
458
459 VOID
460 STDCALL
461 IopDeleteFile(PVOID ObjectBody);
462
463 NTSTATUS
464 STDCALL
465 IopSecurityFile(
466 PVOID ObjectBody,
467 SECURITY_OPERATION_CODE OperationCode,
468 SECURITY_INFORMATION SecurityInformation,
469 PSECURITY_DESCRIPTOR SecurityDescriptor,
470 PULONG BufferLength,
471 PSECURITY_DESCRIPTOR *OldSecurityDescriptor,
472 POOL_TYPE PoolType,
473 PGENERIC_MAPPING GenericMapping
474 );
475
476 NTSTATUS
477 STDCALL
478 IopQueryNameFile(
479 PVOID ObjectBody,
480 POBJECT_NAME_INFORMATION ObjectNameInfo,
481 ULONG Length,
482 PULONG ReturnLength
483 );
484
485 VOID
486 STDCALL
487 IopCloseFile(
488 PVOID ObjectBody,
489 ULONG HandleCount
490 );
491
492 /* plugplay.c */
493
494 NTSTATUS
495 INIT_FUNCTION
496 IopInitPlugPlayEvents(VOID);
497
498 NTSTATUS
499 IopQueueTargetDeviceEvent(
500 const GUID *Guid,
501 PUNICODE_STRING DeviceIds
502 );
503
504 /* pnpmgr.c */
505
506 NTSTATUS
507 IopInitializePnpServices(
508 IN PDEVICE_NODE DeviceNode,
509 IN BOOLEAN BootDrivers)
510 ;
511
512 NTSTATUS
513 IopInvalidateDeviceRelations(
514 IN PDEVICE_NODE DeviceNode,
515 IN DEVICE_RELATION_TYPE Type
516 );
517
518 /* timer.c */
519 VOID
520 FASTCALL
521 IopInitTimerImplementation(VOID);
522
523 VOID
524 STDCALL
525 IopRemoveTimerFromTimerList(IN PIO_TIMER Timer);
526
527 /* iocomp.c */
528 VOID
529 FASTCALL
530 IopInitIoCompletionImplementation(VOID);
531
532 #define CM_RESOURCE_LIST_SIZE(ResList) \
533 (ResList->Count == 1) ? \
534 FIELD_OFFSET(CM_RESOURCE_LIST, List[0].PartialResourceList. \
535 PartialDescriptors[(ResList)->List[0].PartialResourceList.Count]) \
536 : \
537 FIELD_OFFSET(CM_RESOURCE_LIST, List)
538
539 /* xhal.c */
540 NTSTATUS
541 FASTCALL
542 xHalQueryDriveLayout(
543 IN PUNICODE_STRING DeviceName,
544 OUT PDRIVE_LAYOUT_INFORMATION *LayoutInfo
545 );
546
547 #undef HalExamineMBR
548 VOID
549 FASTCALL
550 HalExamineMBR(
551 IN PDEVICE_OBJECT DeviceObject,
552 IN ULONG SectorSize,
553 IN ULONG MBRTypeIdentifier,
554 OUT PVOID *Buffer
555 );
556
557 VOID
558 FASTCALL
559 xHalIoAssignDriveLetters(
560 IN PLOADER_PARAMETER_BLOCK LoaderBlock,
561 IN PSTRING NtDeviceName,
562 OUT PUCHAR NtSystemPath,
563 OUT PSTRING NtSystemPathString
564 );
565
566 NTSTATUS
567 FASTCALL
568 xHalIoReadPartitionTable(
569 PDEVICE_OBJECT DeviceObject,
570 ULONG SectorSize,
571 BOOLEAN ReturnRecognizedPartitions,
572 PDRIVE_LAYOUT_INFORMATION *PartitionBuffer
573 );
574
575 NTSTATUS
576 FASTCALL
577 xHalIoSetPartitionInformation(
578 IN PDEVICE_OBJECT DeviceObject,
579 IN ULONG SectorSize,
580 IN ULONG PartitionNumber,
581 IN ULONG PartitionType
582 );
583
584 NTSTATUS
585 FASTCALL
586 xHalIoWritePartitionTable(
587 IN PDEVICE_OBJECT DeviceObject,
588 IN ULONG SectorSize,
589 IN ULONG SectorsPerTrack,
590 IN ULONG NumberOfHeads,
591 IN PDRIVE_LAYOUT_INFORMATION PartitionBuffer
592 );
593
594 #endif