1 /* 2 * PROJECT: ReactOS Kernel 3 * LICENSE: GPL - See COPYING in the top level directory 4 * FILE: ntoskrnl/include/internal/io.h 5 * PURPOSE: Internal header for the I/O Manager 6 * PROGRAMMERS: Alex Ionescu (alex.ionescu@reactos.org) 7 */ 8 9 #include "ntdddisk.h" 10 11 // 12 // Define this if you want debugging support 13 // 14 #define _IO_DEBUG_ 0x00 15 16 // 17 // These define the Debug Masks Supported 18 // 19 #define IO_IRP_DEBUG 0x01 20 #define IO_FILE_DEBUG 0x02 21 #define IO_API_DEBUG 0x04 22 #define IO_CTL_DEBUG 0x08 23 24 // 25 // Debug/Tracing support 26 // 27 #if _IO_DEBUG_ 28 #ifdef NEW_DEBUG_SYSTEM_IMPLEMENTED // enable when Debug Filters are implemented 29 #define IOTRACE(x, ...) \ 30 { \ 31 DbgPrintEx("%s [%.16s] - ", \ 32 __FUNCTION__, \ 33 PsGetCurrentProcess()->ImageFileName); \ 34 DbgPrintEx(__VA_ARGS__); \ 35 } 36 #else 37 #define IOTRACE(x, ...) \ 38 if (x & IopTraceLevel) \ 39 { \ 40 DbgPrint("%s [%.16s] - ", \ 41 __FUNCTION__, \ 42 PsGetCurrentProcess()->ImageFileName); \ 43 DbgPrint(__VA_ARGS__); \ 44 } 45 #endif 46 #else 47 #define IOTRACE(x, fmt, ...) DPRINT(fmt, ##__VA_ARGS__) 48 #endif 49 50 // 51 // Registry path to the enumeration root key 52 // 53 #define ENUM_ROOT L"\\Registry\\Machine\\System\\CurrentControlSet\\Enum" 54 55 // 56 // Returns the type of METHOD_ used in this IOCTL 57 // 58 #define IO_METHOD_FROM_CTL_CODE(c) (c & 0x00000003) 59 60 // 61 // Bugcheck codes for RAM disk booting 62 // 63 // 64 // No LoaderXIPRom descriptor was found in the loader memory list 65 // 66 #define RD_NO_XIPROM_DESCRIPTOR 1 67 // 68 // Unable to open the RAM disk driver (ramdisk.sys or \Device\Ramdisk) 69 // 70 #define RD_NO_RAMDISK_DRIVER 2 71 // 72 // FSCTL_CREATE_RAM_DISK failed 73 // 74 #define RD_FSCTL_FAILED 3 75 // 76 // Unable to create GUID string from binary GUID 77 // 78 #define RD_GUID_CONVERT_FAILED 4 79 // 80 // Unable to create symbolic link pointing to the RAM disk device 81 // 82 #define RD_SYMLINK_CREATE_FAILED 5 83 84 // 85 // Max traversal of reparse points for a single open in IoParseDevice 86 // 87 #define IOP_MAX_REPARSE_TRAVERSAL 0x20 88 89 // 90 // Private flags for IoCreateFile / IoParseDevice 91 // 92 #define IOP_USE_TOP_LEVEL_DEVICE_HINT 0x01 93 #define IOP_CREATE_FILE_OBJECT_EXTENSION 0x02 94 95 96 typedef struct _FILE_OBJECT_EXTENSION 97 { 98 PDEVICE_OBJECT TopDeviceObjectHint; 99 PVOID FilterContext; 100 101 } FILE_OBJECT_EXTENSION, *PFILE_OBJECT_EXTENSION; 102 103 104 105 // 106 // We can call the Ob Inlined API, it's the same thing 107 // 108 #define IopAllocateMdlFromLookaside \ 109 ObpAllocateObjectCreateInfoBuffer 110 #define IopFreeMdlFromLookaside \ 111 ObpFreeCapturedAttributes 112 113 // 114 // Determines if the IRP is Synchronous 115 // 116 #define IsIrpSynchronous(Irp, FileObject) \ 117 ((Irp->Flags & IRP_SYNCHRONOUS_API) || \ 118 (!(FileObject) ? \ 119 FALSE : \ 120 FileObject->Flags & FO_SYNCHRONOUS_IO)) \ 121 122 // 123 // Returns the internal Device Object Extension 124 // 125 #define IoGetDevObjExtension(DeviceObject) \ 126 ((PEXTENDED_DEVOBJ_EXTENSION) \ 127 (DeviceObject->DeviceObjectExtension)) \ 128 129 // 130 // Returns the internal Driver Object Extension 131 // 132 #define IoGetDrvObjExtension(DriverObject) \ 133 ((PEXTENDED_DRIVER_EXTENSION) \ 134 (DriverObject->DriverExtension)) \ 135 136 /* 137 * VOID 138 * IopDeviceNodeSetFlag( 139 * PDEVICE_NODE DeviceNode, 140 * ULONG Flag); 141 */ 142 #define IopDeviceNodeSetFlag(DeviceNode, Flag) \ 143 ((DeviceNode)->Flags |= (Flag)) 144 145 /* 146 * VOID 147 * IopDeviceNodeClearFlag( 148 * PDEVICE_NODE DeviceNode, 149 * ULONG Flag); 150 */ 151 #define IopDeviceNodeClearFlag(DeviceNode, Flag) \ 152 ((DeviceNode)->Flags &= ~(Flag)) 153 154 /* 155 * BOOLEAN 156 * IopDeviceNodeHasFlag( 157 * PDEVICE_NODE DeviceNode, 158 * ULONG Flag); 159 */ 160 #define IopDeviceNodeHasFlag(DeviceNode, Flag) \ 161 (((DeviceNode)->Flags & (Flag)) > 0) 162 163 /* 164 * VOID 165 * IopDeviceNodeSetUserFlag( 166 * PDEVICE_NODE DeviceNode, 167 * ULONG UserFlag); 168 */ 169 #define IopDeviceNodeSetUserFlag(DeviceNode, UserFlag) \ 170 ((DeviceNode)->UserFlags |= (UserFlag)) 171 172 /* 173 * VOID 174 * IopDeviceNodeClearUserFlag( 175 * PDEVICE_NODE DeviceNode, 176 * ULONG UserFlag); 177 */ 178 #define IopDeviceNodeClearUserFlag(DeviceNode, UserFlag)\ 179 ((DeviceNode)->UserFlags &= ~(UserFlag)) 180 181 /* 182 * BOOLEAN 183 * IopDeviceNodeHasUserFlag( 184 * PDEVICE_NODE DeviceNode, 185 * ULONG UserFlag); 186 */ 187 #define IopDeviceNodeHasUserFlag(DeviceNode, UserFlag) \ 188 (((DeviceNode)->UserFlags & (UserFlag)) > 0) 189 190 /* 191 * VOID 192 * IopDeviceNodeSetProblem( 193 * PDEVICE_NODE DeviceNode, 194 * ULONG Problem); 195 */ 196 #define IopDeviceNodeSetProblem(DeviceNode, Problem) \ 197 ((DeviceNode)->Problem |= (Problem)) 198 199 /* 200 * VOID 201 * IopDeviceNodeClearProblem( 202 * PDEVICE_NODE DeviceNode, 203 * ULONG Problem); 204 */ 205 #define IopDeviceNodeClearProblem(DeviceNode, Problem) \ 206 ((DeviceNode)->Problem &= ~(Problem)) 207 208 /* 209 * BOOLEAN 210 * IopDeviceNodeHasProblem( 211 * PDEVICE_NODE DeviceNode, 212 * ULONG Problem); 213 */ 214 #define IopDeviceNodeHasProblem(DeviceNode, Problem) \ 215 (((DeviceNode)->Problem & (Problem)) > 0) 216 217 /* 218 * VOID 219 * IopInitDeviceTreeTraverseContext( 220 * PDEVICETREE_TRAVERSE_CONTEXT DeviceTreeTraverseContext, 221 * PDEVICE_NODE DeviceNode, 222 * DEVICETREE_TRAVERSE_ROUTINE Action, 223 * PVOID Context); 224 */ 225 #define IopInitDeviceTreeTraverseContext( \ 226 _DeviceTreeTraverseContext, _DeviceNode, _Action, \ 227 _Context) { \ 228 (_DeviceTreeTraverseContext)->FirstDeviceNode = \ 229 (_DeviceNode); \ 230 (_DeviceTreeTraverseContext)->Action = (_Action); \ 231 (_DeviceTreeTraverseContext)->Context = (_Context); } 232 233 /* 234 * BOOLEAN 235 * IopIsValidPhysicalDeviceObject( 236 * IN PDEVICE_OBJECT PhysicalDeviceObject); 237 */ 238 #define IopIsValidPhysicalDeviceObject(PhysicalDeviceObject) \ 239 (((PEXTENDED_DEVOBJ_EXTENSION)PhysicalDeviceObject) && \ 240 (((PEXTENDED_DEVOBJ_EXTENSION)PhysicalDeviceObject->DeviceObjectExtension)->DeviceNode) && \ 241 (((PEXTENDED_DEVOBJ_EXTENSION)PhysicalDeviceObject->DeviceObjectExtension)->DeviceNode->Flags & DNF_ENUMERATED)) 242 243 // 244 // Device List Operations 245 // 246 typedef enum _IOP_DEVICE_LIST_OPERATION 247 { 248 IopRemove, 249 IopAdd 250 } IOP_DEVICE_LIST_OPERATION, *PIOP_DEVICE_LIST_OPERATION; 251 252 // 253 // Transfer statistics 254 // 255 typedef enum _IOP_TRANSFER_TYPE 256 { 257 IopReadTransfer, 258 IopWriteTransfer, 259 IopOtherTransfer 260 } IOP_TRANSFER_TYPE, *PIOP_TRANSFER_TYPE; 261 262 // 263 // Packet Types when piggybacking on the IRP Overlay 264 // 265 typedef enum _COMPLETION_PACKET_TYPE 266 { 267 IopCompletionPacketIrp, 268 IopCompletionPacketMini, 269 IopCompletionPacketQuota 270 } COMPLETION_PACKET_TYPE, *PCOMPLETION_PACKET_TYPE; 271 272 // 273 // Special version of the IRP Overlay used to optimize I/O completion 274 // by not using up a separate structure. 275 // 276 typedef struct _IOP_MINI_COMPLETION_PACKET 277 { 278 struct 279 { 280 LIST_ENTRY ListEntry; 281 union 282 { 283 struct _IO_STACK_LOCATION *CurrentStackLocation; 284 ULONG PacketType; 285 }; 286 }; 287 PVOID KeyContext; 288 PVOID ApcContext; 289 NTSTATUS IoStatus; 290 ULONG_PTR IoStatusInformation; 291 } IOP_MINI_COMPLETION_PACKET, *PIOP_MINI_COMPLETION_PACKET; 292 293 // 294 // I/O Completion Context for IoSetIoCompletionRoutineEx 295 // 296 typedef struct _IO_UNLOAD_SAFE_COMPLETION_CONTEXT 297 { 298 PDEVICE_OBJECT DeviceObject; 299 PVOID Context; 300 PIO_COMPLETION_ROUTINE CompletionRoutine; 301 } IO_UNLOAD_SAFE_COMPLETION_CONTEXT, *PIO_UNLOAD_SAFE_COMPLETION_CONTEXT; 302 303 // 304 // I/O Wrapper around the Executive Work Item 305 // 306 typedef struct _IO_WORKITEM 307 { 308 WORK_QUEUE_ITEM Item; 309 PDEVICE_OBJECT DeviceObject; 310 PIO_WORKITEM_ROUTINE WorkerRoutine; 311 PVOID Context; 312 } IO_WORKITEM; 313 314 // 315 // I/O Wrapper around the Kernel Interrupt 316 // 317 typedef struct _IO_INTERRUPT 318 { 319 KINTERRUPT FirstInterrupt; 320 PKINTERRUPT Interrupt[MAXIMUM_PROCESSORS]; 321 KSPIN_LOCK SpinLock; 322 } IO_INTERRUPT, *PIO_INTERRUPT; 323 324 // 325 // I/O Error Log Packet Header 326 // 327 typedef struct _ERROR_LOG_ENTRY 328 { 329 CSHORT Type; 330 CSHORT Size; 331 LIST_ENTRY ListEntry; 332 PDEVICE_OBJECT DeviceObject; 333 PDRIVER_OBJECT DriverObject; 334 LARGE_INTEGER TimeStamp; 335 } ERROR_LOG_ENTRY, *PERROR_LOG_ENTRY; 336 337 // 338 // To simplify matters, the kernel is made to support both the checked and free 339 // version of the I/O Remove Lock in the same binary. This structure includes 340 // both, since the DDK has the structure with a compile-time #ifdef. 341 // 342 typedef struct _EXTENDED_IO_REMOVE_LOCK 343 { 344 IO_REMOVE_LOCK_COMMON_BLOCK Common; 345 IO_REMOVE_LOCK_DBG_BLOCK Dbg; 346 } EXTENDED_IO_REMOVE_LOCK, *PEXTENDED_IO_REMOVE_LOCK; 347 348 // 349 // Dummy File Object used inside the Open Packet so that OB knows how to 350 // deal with the Object Pointer even though it's not a real file. 351 // 352 typedef struct _DUMMY_FILE_OBJECT 353 { 354 OBJECT_HEADER ObjectHeader; 355 CHAR FileObjectBody[sizeof(FILE_OBJECT)]; 356 } DUMMY_FILE_OBJECT, *PDUMMY_FILE_OBJECT; 357 358 // 359 // Open packet used as a context for Device/File parsing so that the parse 360 // routine can know what operation is being requested. 361 // 362 typedef struct _OPEN_PACKET 363 { 364 CSHORT Type; 365 CSHORT Size; 366 PFILE_OBJECT FileObject; 367 NTSTATUS FinalStatus; 368 ULONG_PTR Information; 369 ULONG ParseCheck; 370 PFILE_OBJECT RelatedFileObject; 371 OBJECT_ATTRIBUTES OriginalAttributes; 372 LARGE_INTEGER AllocationSize; 373 ULONG CreateOptions; 374 USHORT FileAttributes; 375 USHORT ShareAccess; 376 PVOID EaBuffer; 377 ULONG EaLength; 378 ULONG Options; 379 ULONG Disposition; 380 PFILE_BASIC_INFORMATION BasicInformation; 381 PFILE_NETWORK_OPEN_INFORMATION NetworkInformation; 382 CREATE_FILE_TYPE CreateFileType; 383 PVOID ExtraCreateParameters; 384 BOOLEAN Override; 385 BOOLEAN QueryOnly; 386 BOOLEAN DeleteOnly; 387 BOOLEAN FullAttributes; 388 PDUMMY_FILE_OBJECT LocalFileObject; 389 BOOLEAN TraversedMountPoint; 390 ULONG InternalFlags; 391 PDEVICE_OBJECT TopDeviceObjectHint; 392 } OPEN_PACKET, *POPEN_PACKET; 393 394 // 395 // Parameters packet for Load/Unload work item's context 396 // 397 typedef struct _LOAD_UNLOAD_PARAMS 398 { 399 NTSTATUS Status; 400 PCUNICODE_STRING RegistryPath; 401 WORK_QUEUE_ITEM WorkItem; 402 KEVENT Event; 403 PDRIVER_OBJECT DriverObject; 404 } LOAD_UNLOAD_PARAMS, *PLOAD_UNLOAD_PARAMS; 405 406 // 407 // Boot Driver List Entry 408 // 409 typedef struct _DRIVER_INFORMATION 410 { 411 LIST_ENTRY Link; 412 PDRIVER_OBJECT DriverObject; 413 PBOOT_DRIVER_LIST_ENTRY DataTableEntry; 414 HANDLE ServiceHandle; 415 USHORT TagPosition; 416 ULONG Failed; 417 ULONG Processed; 418 NTSTATUS Status; 419 } DRIVER_INFORMATION, *PDRIVER_INFORMATION; 420 421 // 422 // Boot Driver Node 423 // 424 typedef struct _BOOT_DRIVER_NODE 425 { 426 BOOT_DRIVER_LIST_ENTRY ListEntry; 427 UNICODE_STRING Group; 428 UNICODE_STRING Name; 429 ULONG Tag; 430 ULONG ErrorControl; 431 } BOOT_DRIVER_NODE, *PBOOT_DRIVER_NODE; 432 433 // 434 // List of Bus Type GUIDs 435 // 436 typedef struct _IO_BUS_TYPE_GUID_LIST 437 { 438 ULONG GuidCount; 439 FAST_MUTEX Lock; 440 GUID Guids[1]; 441 } IO_BUS_TYPE_GUID_LIST, *PIO_BUS_TYPE_GUID_LIST; 442 extern PIO_BUS_TYPE_GUID_LIST IopBusTypeGuidList; 443 444 // 445 // Shutdown entry for registed devices 446 // 447 typedef struct _SHUTDOWN_ENTRY 448 { 449 LIST_ENTRY ShutdownList; 450 PDEVICE_OBJECT DeviceObject; 451 } SHUTDOWN_ENTRY, *PSHUTDOWN_ENTRY; 452 453 // 454 // F/S Notification entry for registered File Systems 455 // 456 typedef struct _FS_CHANGE_NOTIFY_ENTRY 457 { 458 LIST_ENTRY FsChangeNotifyList; 459 PDRIVER_OBJECT DriverObject; 460 PDRIVER_FS_NOTIFICATION FSDNotificationProc; 461 } FS_CHANGE_NOTIFY_ENTRY, *PFS_CHANGE_NOTIFY_ENTRY; 462 463 // 464 // Driver (Boot) Re-Initialization Entry 465 // 466 typedef struct _DRIVER_REINIT_ITEM 467 { 468 LIST_ENTRY ItemEntry; 469 PDRIVER_OBJECT DriverObject; 470 PDRIVER_REINITIALIZE ReinitRoutine; 471 PVOID Context; 472 } DRIVER_REINIT_ITEM, *PDRIVER_REINIT_ITEM; 473 474 // 475 // Called on every visit of a node during a preorder-traversal of the device 476 // node tree. 477 // If the routine returns STATUS_UNSUCCESSFUL the traversal will stop and 478 // STATUS_SUCCESS is returned to the caller who initiated the tree traversal. 479 // Any other returned status code will be returned to the caller. If a status 480 // code that indicates an error (other than STATUS_UNSUCCESSFUL) is returned, 481 // the traversal is stopped immediately and the status code is returned to 482 // the caller. 483 // 484 typedef 485 NTSTATUS 486 (*DEVICETREE_TRAVERSE_ROUTINE)( 487 IN PDEVICE_NODE DeviceNode, 488 IN PVOID Context 489 ); 490 491 // 492 // Context information for traversing the device tree 493 // 494 typedef struct _DEVICETREE_TRAVERSE_CONTEXT 495 { 496 // 497 // Current device node during a traversal 498 // 499 PDEVICE_NODE DeviceNode; 500 501 // 502 // Initial device node where we start the traversal 503 // 504 PDEVICE_NODE FirstDeviceNode; 505 506 // 507 // Action routine to be called for every device node 508 // 509 DEVICETREE_TRAVERSE_ROUTINE Action; 510 511 // 512 // Context passed to the action routine 513 // 514 PVOID Context; 515 } DEVICETREE_TRAVERSE_CONTEXT, *PDEVICETREE_TRAVERSE_CONTEXT; 516 517 // 518 // Reserve IRP allocator 519 // Used for read paging IOs in low-memory situations 520 // 521 typedef struct _RESERVE_IRP_ALLOCATOR 522 { 523 PIRP ReserveIrp; 524 volatile LONG ReserveIrpInUse; 525 KEVENT WaitEvent; 526 CCHAR StackSize; 527 } RESERVE_IRP_ALLOCATOR, *PRESERVE_IRP_ALLOCATOR; 528 529 // 530 // Resource code 531 // 532 ULONG 533 NTAPI 534 PnpDetermineResourceListSize(IN PCM_RESOURCE_LIST ResourceList); 535 536 NTSTATUS 537 NTAPI 538 IopAssignDeviceResources( 539 IN PDEVICE_NODE DeviceNode 540 ); 541 542 NTSTATUS 543 NTAPI 544 IopFixupResourceListWithRequirements( 545 IN PIO_RESOURCE_REQUIREMENTS_LIST RequirementsList, 546 OUT PCM_RESOURCE_LIST *ResourceList 547 ); 548 549 NTSTATUS 550 NTAPI 551 IopDetectResourceConflict( 552 IN PCM_RESOURCE_LIST ResourceList, 553 IN BOOLEAN Silent, 554 OUT OPTIONAL PCM_PARTIAL_RESOURCE_DESCRIPTOR ConflictingDescriptor 555 ); 556 557 // 558 // PNP Routines 559 // 560 NTSTATUS 561 NTAPI 562 PipCallDriverAddDevice( 563 IN PDEVICE_NODE DeviceNode, 564 IN BOOLEAN LoadDriver, 565 IN PDRIVER_OBJECT DriverObject 566 ); 567 568 NTSTATUS 569 NTAPI 570 IopInitializePlugPlayServices( 571 VOID 572 ); 573 574 BOOLEAN 575 NTAPI 576 PpInitSystem( 577 VOID 578 ); 579 580 VOID 581 PnpInit2( 582 VOID 583 ); 584 585 VOID 586 IopInitDriverImplementation( 587 VOID 588 ); 589 590 VOID 591 IopInitPnpNotificationImplementation( 592 VOID 593 ); 594 595 VOID 596 IopNotifyPlugPlayNotification( 597 IN PDEVICE_OBJECT DeviceObject, 598 IN IO_NOTIFICATION_EVENT_CATEGORY EventCategory, 599 IN LPCGUID Event, 600 IN PVOID EventCategoryData1, 601 IN PVOID EventCategoryData2 602 ); 603 604 NTSTATUS 605 IopGetSystemPowerDeviceObject( 606 IN PDEVICE_OBJECT *DeviceObject 607 ); 608 609 PDEVICE_NODE 610 NTAPI 611 PipAllocateDeviceNode( 612 IN PDEVICE_OBJECT PhysicalDeviceObject 613 ); 614 615 NTSTATUS 616 IopCreateDeviceNode( 617 IN PDEVICE_NODE ParentNode, 618 IN PDEVICE_OBJECT PhysicalDeviceObject, 619 IN PUNICODE_STRING ServiceName, 620 OUT PDEVICE_NODE *DeviceNode 621 ); 622 623 NTSTATUS 624 IopFreeDeviceNode( 625 IN PDEVICE_NODE DeviceNode 626 ); 627 628 NTSTATUS 629 NTAPI 630 IopQueryDeviceCapabilities(PDEVICE_NODE DeviceNode, 631 PDEVICE_CAPABILITIES DeviceCaps); 632 633 NTSTATUS 634 NTAPI 635 IopSynchronousCall( 636 IN PDEVICE_OBJECT DeviceObject, 637 IN PIO_STACK_LOCATION IoStackLocation, 638 OUT PVOID *Information 639 ); 640 641 NTSTATUS 642 NTAPI 643 IopInitiatePnpIrp( 644 IN PDEVICE_OBJECT DeviceObject, 645 IN PIO_STATUS_BLOCK IoStatusBlock, 646 IN UCHAR MinorFunction, 647 IN PIO_STACK_LOCATION Stack 648 ); 649 650 PDEVICE_NODE 651 FASTCALL 652 IopGetDeviceNode( 653 IN PDEVICE_OBJECT DeviceObject 654 ); 655 656 NTSTATUS 657 IopActionConfigureChildServices( 658 IN PDEVICE_NODE DeviceNode, 659 IN PVOID Context 660 ); 661 662 NTSTATUS 663 IopActionInitChildServices( 664 IN PDEVICE_NODE DeviceNode, 665 IN PVOID Context 666 ); 667 668 NTSTATUS 669 IopEnumerateDevice( 670 IN PDEVICE_OBJECT DeviceObject 671 ); 672 673 NTSTATUS 674 IoCreateDriverList( 675 VOID 676 ); 677 678 NTSTATUS 679 IoDestroyDriverList( 680 VOID 681 ); 682 683 NTSTATUS 684 IopInitPlugPlayEvents(VOID); 685 686 NTSTATUS 687 IopQueueTargetDeviceEvent( 688 const GUID *Guid, 689 PUNICODE_STRING DeviceIds 690 ); 691 692 NTSTATUS 693 IopInitializePnpServices( 694 IN PDEVICE_NODE DeviceNode); 695 696 NTSTATUS 697 NTAPI 698 IopOpenRegistryKeyEx( 699 PHANDLE KeyHandle, 700 HANDLE ParentKey, 701 PUNICODE_STRING Name, 702 ACCESS_MASK DesiredAccess); 703 704 NTSTATUS 705 NTAPI 706 IopGetRegistryValue( 707 IN HANDLE Handle, 708 IN PWSTR ValueName, 709 OUT PKEY_VALUE_FULL_INFORMATION *Information 710 ); 711 712 NTSTATUS 713 NTAPI 714 IopCreateRegistryKeyEx( 715 OUT PHANDLE Handle, 716 IN HANDLE BaseHandle OPTIONAL, 717 IN PUNICODE_STRING KeyName, 718 IN ACCESS_MASK DesiredAccess, 719 IN ULONG CreateOptions, 720 OUT PULONG Disposition OPTIONAL 721 ); 722 723 724 NTSTATUS 725 IopTraverseDeviceTree( 726 PDEVICETREE_TRAVERSE_CONTEXT Context); 727 728 // 729 // PnP Routines 730 // 731 NTSTATUS 732 NTAPI 733 IopUpdateRootKey( 734 VOID 735 ); 736 737 NTSTATUS 738 NTAPI 739 PiInitCacheGroupInformation( 740 VOID 741 ); 742 743 USHORT 744 NTAPI 745 PpInitGetGroupOrderIndex( 746 IN HANDLE ServiceHandle 747 ); 748 749 USHORT 750 NTAPI 751 PipGetDriverTagPriority( 752 IN HANDLE ServiceHandle 753 ); 754 755 NTSTATUS 756 NTAPI 757 PnpRegMultiSzToUnicodeStrings( 758 IN PKEY_VALUE_FULL_INFORMATION KeyValueInformation, 759 OUT PUNICODE_STRING *UnicodeStringList, 760 OUT PULONG UnicodeStringCount 761 ); 762 763 BOOLEAN 764 NTAPI 765 PnpRegSzToString( 766 IN PWCHAR RegSzData, 767 IN ULONG RegSzLength, 768 OUT PUSHORT StringLength OPTIONAL 769 ); 770 771 // 772 // Initialization Routines 773 // 774 NTSTATUS 775 NTAPI 776 IopCreateArcNames( 777 IN PLOADER_PARAMETER_BLOCK LoaderBlock 778 ); 779 780 NTSTATUS 781 NTAPI 782 IopReassignSystemRoot( 783 IN PLOADER_PARAMETER_BLOCK LoaderBlock, 784 OUT PANSI_STRING NtBootPath 785 ); 786 787 BOOLEAN 788 NTAPI 789 IoInitSystem( 790 IN PLOADER_PARAMETER_BLOCK LoaderBlock 791 ); 792 793 BOOLEAN 794 NTAPI 795 IopVerifyDiskSignature( 796 IN PDRIVE_LAYOUT_INFORMATION_EX DriveLayout, 797 IN PARC_DISK_SIGNATURE ArcDiskSignature, 798 OUT PULONG Signature 799 ); 800 801 BOOLEAN 802 NTAPI 803 IoInitializeCrashDump( 804 IN HANDLE PageFileHandle 805 ); 806 807 // 808 // Device/Volume Routines 809 // 810 VOID 811 NTAPI 812 IopReadyDeviceObjects( 813 IN PDRIVER_OBJECT Driver 814 ); 815 816 NTSTATUS 817 FASTCALL 818 IopInitializeDevice( 819 IN PDEVICE_NODE DeviceNode, 820 IN PDRIVER_OBJECT DriverObject 821 ); 822 823 NTSTATUS 824 IopStartDevice( 825 IN PDEVICE_NODE DeviceNode 826 ); 827 828 NTSTATUS 829 IopStopDevice( 830 IN PDEVICE_NODE DeviceNode 831 ); 832 833 NTSTATUS 834 IopRemoveDevice( 835 IN PDEVICE_NODE DeviceNode 836 ); 837 838 PVPB 839 NTAPI 840 IopCheckVpbMounted( 841 IN POPEN_PACKET OpenPacket, 842 IN PDEVICE_OBJECT DeviceObject, 843 IN PUNICODE_STRING RemainingName, 844 OUT PNTSTATUS Status 845 ); 846 847 NTSTATUS 848 NTAPI 849 IopMountVolume( 850 IN PDEVICE_OBJECT DeviceObject, 851 IN BOOLEAN AllowRawMount, 852 IN BOOLEAN DeviceIsLocked, 853 IN BOOLEAN Alertable, 854 OUT PVPB *Vpb 855 ); 856 857 PVOID 858 IoOpenSymlink( 859 IN PVOID SymbolicLink 860 ); 861 862 PVOID 863 IoOpenFileOnDevice( 864 IN PVOID SymbolicLink, 865 IN PWCHAR Name 866 ); 867 868 NTSTATUS 869 NTAPI 870 IopCreateVpb( 871 IN PDEVICE_OBJECT DeviceObject 872 ); 873 874 VOID 875 NTAPI 876 IopDereferenceVpbAndFree( 877 IN PVPB Vpb 878 ); 879 880 VOID 881 NTAPI 882 IoInitFileSystemImplementation( 883 VOID 884 ); 885 886 VOID 887 NTAPI 888 IoInitVpbImplementation( 889 VOID 890 ); 891 892 NTSTATUS 893 NTAPI 894 IopReferenceDeviceObject( 895 IN PDEVICE_OBJECT DeviceObject 896 ); 897 898 VOID 899 NTAPI 900 IopDereferenceDeviceObject( 901 IN PDEVICE_OBJECT DeviceObject, 902 IN BOOLEAN ForceUnload 903 ); 904 905 NTSTATUS 906 NTAPI 907 IoGetRelatedTargetDevice( 908 IN PFILE_OBJECT FileObject, 909 OUT PDEVICE_OBJECT *DeviceObject 910 ); 911 912 VOID 913 NTAPI 914 IopUnloadDevice( 915 IN PDEVICE_OBJECT DeviceObject 916 ); 917 918 // 919 // IRP Routines 920 // 921 NTSTATUS 922 NTAPI 923 IopCleanupFailedIrp( 924 IN PFILE_OBJECT FileObject, 925 IN PKEVENT EventObject, 926 IN PVOID Buffer OPTIONAL 927 ); 928 929 VOID 930 NTAPI 931 IopAbortInterruptedIrp( 932 IN PKEVENT EventObject, 933 IN PIRP Irp 934 ); 935 936 PIRP 937 NTAPI 938 IopAllocateIrpMustSucceed( 939 IN CCHAR StackSize 940 ); 941 942 BOOLEAN 943 NTAPI 944 IopInitializeReserveIrp( 945 IN PRESERVE_IRP_ALLOCATOR ReserveIrpAllocator 946 ); 947 948 PIRP 949 NTAPI 950 IopAllocateReserveIrp( 951 IN CCHAR StackSize 952 ); 953 954 // 955 // Shutdown routines 956 // 957 VOID 958 IoInitShutdownNotification( 959 VOID 960 ); 961 962 VOID 963 NTAPI 964 IoShutdownSystem( 965 IN ULONG Phase 966 ); 967 968 VOID 969 NTAPI 970 IopShutdownBaseFileSystems( 971 IN PLIST_ENTRY ListHead 972 ); 973 974 // 975 // Boot logging support 976 // 977 VOID 978 IopInitBootLog( 979 IN BOOLEAN StartBootLog 980 ); 981 982 VOID 983 IopStartBootLog( 984 VOID 985 ); 986 987 VOID 988 IopStopBootLog( 989 VOID 990 ); 991 992 VOID 993 IopBootLog( 994 IN PUNICODE_STRING DriverName, 995 IN BOOLEAN Success 996 ); 997 998 VOID 999 IopSaveBootLogToFile( 1000 VOID 1001 ); 1002 1003 // 1004 // I/O Cancellation Routines 1005 // 1006 VOID 1007 NTAPI 1008 IoCancelThreadIo( 1009 IN PETHREAD Thread 1010 ); 1011 1012 VOID 1013 IoInitCancelHandling( 1014 VOID 1015 ); 1016 1017 // 1018 // I/O Completion 1019 // 1020 VOID 1021 NTAPI 1022 IopCompleteRequest( 1023 IN PKAPC Apc, 1024 IN PKNORMAL_ROUTINE* NormalRoutine, 1025 IN PVOID* NormalContext, 1026 IN PVOID* SystemArgument1, 1027 IN PVOID* SystemArgument2 1028 ); 1029 1030 // 1031 // Error Logging Routines 1032 // 1033 VOID 1034 NTAPI 1035 IopInitErrorLog( 1036 VOID 1037 ); 1038 1039 VOID 1040 NTAPI 1041 IopLogWorker( 1042 IN PVOID Parameter 1043 ); 1044 1045 // 1046 // Raw File System MiniDriver 1047 // 1048 BOOLEAN 1049 RawFsIsRawFileSystemDeviceObject( 1050 IN PDEVICE_OBJECT DeviceObject 1051 ); 1052 1053 NTSTATUS 1054 NTAPI 1055 RawFsDriverEntry( 1056 IN PDRIVER_OBJECT DriverObject, 1057 IN PUNICODE_STRING RegistryPath 1058 ); 1059 1060 // 1061 // PnP Root MiniDriver 1062 // 1063 NTSTATUS 1064 NTAPI 1065 PnpRootDriverEntry( 1066 IN PDRIVER_OBJECT DriverObject, 1067 IN PUNICODE_STRING RegistryPath 1068 ); 1069 1070 NTSTATUS 1071 PnpRootCreateDevice( 1072 IN PUNICODE_STRING ServiceName, 1073 IN OPTIONAL PDRIVER_OBJECT DriverObject, 1074 OUT PDEVICE_OBJECT *PhysicalDeviceObject, 1075 OUT OPTIONAL PUNICODE_STRING FullInstancePath 1076 ); 1077 1078 NTSTATUS 1079 PnpRootRegisterDevice( 1080 IN PDEVICE_OBJECT DeviceObject); 1081 1082 // 1083 // Driver Routines 1084 // 1085 VOID 1086 FASTCALL 1087 IopInitializeBootDrivers( 1088 VOID 1089 ); 1090 1091 VOID 1092 FASTCALL 1093 IopInitializeSystemDrivers( 1094 VOID 1095 ); 1096 1097 NTSTATUS 1098 NTAPI 1099 IopCreateDriver(IN PUNICODE_STRING DriverName OPTIONAL, 1100 IN PDRIVER_INITIALIZE InitializationFunction, 1101 IN PUNICODE_STRING RegistryPath OPTIONAL, 1102 IN PCUNICODE_STRING ServiceName, 1103 IN PLDR_DATA_TABLE_ENTRY ModuleObject OPTIONAL, 1104 OUT PDRIVER_OBJECT *pDriverObject); 1105 1106 VOID 1107 NTAPI 1108 IopDeleteDriver( 1109 IN PVOID ObjectBody 1110 ); 1111 1112 NTSTATUS 1113 FASTCALL 1114 IopGetDriverObject( 1115 OUT PDRIVER_OBJECT *DriverObject, 1116 IN PUNICODE_STRING ServiceName, 1117 IN BOOLEAN FileSystem 1118 ); 1119 1120 NTSTATUS 1121 FASTCALL 1122 IopLoadServiceModule( 1123 IN PUNICODE_STRING ServiceName, 1124 OUT PLDR_DATA_TABLE_ENTRY *ModuleObject 1125 ); 1126 1127 NTSTATUS 1128 NTAPI 1129 IopLoadUnloadDriver( 1130 _In_opt_ PCUNICODE_STRING RegistryPath, 1131 _Inout_ PDRIVER_OBJECT *DriverObject 1132 ); 1133 1134 NTSTATUS 1135 FASTCALL 1136 IopInitializeDriverModule( 1137 IN PDEVICE_NODE DeviceNode, 1138 IN PLDR_DATA_TABLE_ENTRY ModuleObject, 1139 IN PUNICODE_STRING ServiceName, 1140 IN BOOLEAN FileSystemDriver, 1141 OUT PDRIVER_OBJECT *DriverObject 1142 ); 1143 1144 NTSTATUS 1145 FASTCALL 1146 IopAttachFilterDrivers( 1147 IN PDEVICE_NODE DeviceNode, 1148 IN HANDLE EnumSubKey, 1149 IN HANDLE ClassKey, 1150 IN BOOLEAN Lower 1151 ); 1152 1153 VOID 1154 NTAPI 1155 IopReinitializeDrivers( 1156 VOID 1157 ); 1158 1159 VOID 1160 NTAPI 1161 IopReinitializeBootDrivers( 1162 VOID 1163 ); 1164 1165 // 1166 // File Routines 1167 // 1168 VOID 1169 NTAPI 1170 IopDeleteDevice(IN PVOID ObjectBody); 1171 1172 NTSTATUS 1173 NTAPI 1174 IopParseDevice( 1175 IN PVOID ParseObject, 1176 IN PVOID ObjectType, 1177 IN OUT PACCESS_STATE AccessState, 1178 IN KPROCESSOR_MODE AccessMode, 1179 IN ULONG Attributes, 1180 IN OUT PUNICODE_STRING CompleteName, 1181 IN OUT PUNICODE_STRING RemainingName, 1182 IN OUT PVOID Context, 1183 IN PSECURITY_QUALITY_OF_SERVICE SecurityQos OPTIONAL, 1184 OUT PVOID *Object 1185 ); 1186 1187 NTSTATUS 1188 NTAPI 1189 IopParseFile( 1190 IN PVOID ParseObject, 1191 IN PVOID ObjectType, 1192 IN OUT PACCESS_STATE AccessState, 1193 IN KPROCESSOR_MODE AccessMode, 1194 IN ULONG Attributes, 1195 IN OUT PUNICODE_STRING CompleteName, 1196 IN OUT PUNICODE_STRING RemainingName, 1197 IN OUT PVOID Context OPTIONAL, 1198 IN PSECURITY_QUALITY_OF_SERVICE SecurityQos OPTIONAL, 1199 OUT PVOID *Object 1200 ); 1201 1202 VOID 1203 NTAPI 1204 IopDeleteFile( 1205 IN PVOID ObjectBody 1206 ); 1207 1208 NTSTATUS 1209 NTAPI 1210 IopGetSetSecurityObject( 1211 IN PVOID ObjectBody, 1212 IN SECURITY_OPERATION_CODE OperationCode, 1213 IN PSECURITY_INFORMATION SecurityInformation, 1214 IN OUT PSECURITY_DESCRIPTOR SecurityDescriptor, 1215 IN OUT PULONG BufferLength, 1216 OUT PSECURITY_DESCRIPTOR *OldSecurityDescriptor, 1217 IN POOL_TYPE PoolType, 1218 IN OUT PGENERIC_MAPPING GenericMapping 1219 ); 1220 1221 NTSTATUS 1222 NTAPI 1223 IopQueryName( 1224 IN PVOID ObjectBody, 1225 IN BOOLEAN HasName, 1226 OUT POBJECT_NAME_INFORMATION ObjectNameInfo, 1227 IN ULONG Length, 1228 OUT PULONG ReturnLength, 1229 IN KPROCESSOR_MODE PreviousMode 1230 ); 1231 1232 NTSTATUS 1233 NTAPI 1234 IopQueryNameInternal( 1235 IN PVOID ObjectBody, 1236 IN BOOLEAN HasName, 1237 IN BOOLEAN QueryDosName, 1238 OUT POBJECT_NAME_INFORMATION ObjectNameInfo, 1239 IN ULONG Length, 1240 OUT PULONG ReturnLength, 1241 IN KPROCESSOR_MODE PreviousMode 1242 ); 1243 1244 VOID 1245 NTAPI 1246 IopCloseFile( 1247 IN PEPROCESS Process OPTIONAL, 1248 IN PVOID Object, 1249 IN ACCESS_MASK GrantedAccess, 1250 IN ULONG ProcessHandleCount, 1251 IN ULONG SystemHandleCount 1252 ); 1253 1254 NTSTATUS 1255 NTAPI 1256 IopAcquireFileObjectLock( 1257 _In_ PFILE_OBJECT FileObject, 1258 _In_ KPROCESSOR_MODE AccessMode, 1259 _In_ BOOLEAN Alertable, 1260 _Out_ PBOOLEAN LockFailed 1261 ); 1262 1263 PVOID 1264 NTAPI 1265 IoGetFileObjectFilterContext( 1266 IN PFILE_OBJECT FileObject 1267 ); 1268 1269 NTSTATUS 1270 NTAPI 1271 IoChangeFileObjectFilterContext( 1272 IN PFILE_OBJECT FileObject, 1273 IN PVOID FilterContext, 1274 IN BOOLEAN Define 1275 ); 1276 1277 VOID 1278 NTAPI 1279 IopDoNameTransmogrify( 1280 IN PIRP Irp, 1281 IN PFILE_OBJECT FileObject, 1282 IN PREPARSE_DATA_BUFFER DataBuffer 1283 ); 1284 1285 NTSTATUS 1286 NTAPI 1287 IoComputeDesiredAccessFileObject( 1288 IN PFILE_OBJECT FileObject, 1289 IN PACCESS_MASK DesiredAccess 1290 ); 1291 1292 NTSTATUS 1293 NTAPI 1294 IopGetFileInformation( 1295 IN PFILE_OBJECT FileObject, 1296 IN ULONG Length, 1297 IN FILE_INFORMATION_CLASS FileInfoClass, 1298 OUT PVOID Buffer, 1299 OUT PULONG ReturnedLength 1300 ); 1301 1302 BOOLEAN 1303 NTAPI 1304 IopVerifyDeviceObjectOnStack( 1305 IN PDEVICE_OBJECT BaseDeviceObject, 1306 IN PDEVICE_OBJECT TopDeviceObjectHint 1307 ); 1308 1309 // 1310 // I/O Timer Routines 1311 // 1312 VOID 1313 FASTCALL 1314 IopInitTimerImplementation( 1315 VOID 1316 ); 1317 1318 VOID 1319 NTAPI 1320 IopRemoveTimerFromTimerList( 1321 IN PIO_TIMER Timer 1322 ); 1323 1324 // 1325 // I/O Completion Routines 1326 // 1327 VOID 1328 NTAPI 1329 IopDeleteIoCompletion( 1330 PVOID ObjectBody 1331 ); 1332 1333 NTSTATUS 1334 NTAPI 1335 IoSetIoCompletion( 1336 IN PVOID IoCompletion, 1337 IN PVOID KeyContext, 1338 IN PVOID ApcContext, 1339 IN NTSTATUS IoStatus, 1340 IN ULONG_PTR IoStatusInformation, 1341 IN BOOLEAN Quota 1342 ); 1343 1344 // 1345 // Ramdisk Routines 1346 // 1347 NTSTATUS 1348 NTAPI 1349 IopStartRamdisk( 1350 IN PLOADER_PARAMETER_BLOCK LoaderBlock 1351 ); 1352 1353 // 1354 // Configuration Routines 1355 // 1356 NTSTATUS 1357 NTAPI 1358 IopFetchConfigurationInformation(OUT PWSTR * SymbolicLinkList, 1359 IN GUID Guid, 1360 IN ULONG ExpectedInterfaces, 1361 IN PULONG Interfaces 1362 ); 1363 1364 VOID 1365 NTAPI 1366 IopStoreSystemPartitionInformation(IN PUNICODE_STRING NtSystemPartitionDeviceName, 1367 IN PUNICODE_STRING OsLoaderPathName 1368 ); 1369 1370 // 1371 // Global I/O Data 1372 // 1373 extern POBJECT_TYPE IoCompletionType; 1374 extern PDEVICE_NODE IopRootDeviceNode; 1375 extern KSPIN_LOCK IopDeviceTreeLock; 1376 extern ULONG IopTraceLevel; 1377 extern GENERAL_LOOKASIDE IopMdlLookasideList; 1378 extern GENERIC_MAPPING IopCompletionMapping; 1379 extern GENERIC_MAPPING IopFileMapping; 1380 extern POBJECT_TYPE _IoFileObjectType; 1381 extern HAL_DISPATCH _HalDispatchTable; 1382 extern LIST_ENTRY IopErrorLogListHead; 1383 extern ULONG IopNumTriageDumpDataBlocks; 1384 extern PVOID IopTriageDumpDataBlocks[64]; 1385 extern PIO_BUS_TYPE_GUID_LIST PnpBusTypeGuidList; 1386 extern PDRIVER_OBJECT IopRootDriverObject; 1387 extern KSPIN_LOCK IopDeviceActionLock; 1388 extern LIST_ENTRY IopDeviceActionRequestList; 1389 extern RESERVE_IRP_ALLOCATOR IopReserveIrpAllocator; 1390 1391 // 1392 // Inlined Functions 1393 // 1394 #include "io_x.h" 1395