1 #ifndef _INCLUDE_DDK_IOFUNCS_H
2 #define _INCLUDE_DDK_IOFUNCS_H
3 /* $Id: iofuncs.h,v 1.26 2001/09/16 13:19:31 chorns Exp $ */
5 /* --- EXPORTED BY NTOSKRNL --- */
7 /**********************************************************************
9 * IoAcquireCancelSpinLock@4
12 * Synchronizes cancelable-state transistions for IRPs in a
13 * multiprocessor-safe way.
17 * Variable to store the current IRQ level.
27 IoAcquireCancelSpinLock (
32 IoAcquireVpbSpinLock (
35 /**********************************************************************
37 * IoAllocateAdapterChannel@
40 * Allocates an adaptor object for a DMA operation on the target
45 * Adapter channel or busmaster adapter to be allocated;
48 * Target device for DMA;
50 * NumberOfMapRegisters
51 * Number of map registers;
54 * Routine to be called when the adaptor is available;
57 * Driver defined contex that will be passed to the
61 * Success or failure code.
68 IoAllocateAdapterChannel (
69 PADAPTER_OBJECT AdaperObject
,
70 PDEVICE_OBJECT DeviceObject
,
71 ULONG NumberOfMapRegisters
,
72 PDRIVER_CONTROL ExecutionRoutine
,
75 /**********************************************************************
77 * IoAllocateController@16
80 * Sets up a call to a driver supplied controller object as
81 * soon as it is available.
85 * Driver created controller object;
91 * Routine to be called;
94 * Driver determined context to be based to the
105 IoAllocateController (
106 PCONTROLLER_OBJECT ControllerObject
,
107 PDEVICE_OBJECT DeviceObject
,
108 PDRIVER_CONTROL ExecutionRoutine
,
111 /**********************************************************************
113 * IoAllocateErrorLogEntry@8
116 * Allocates an error log packet.
120 * Object which found the error;
123 * Size in bytes of the packet to be allocated.
126 * On success, a pointer to the allocated packet.
127 * On failure, it returns NULL.
131 IoAllocateErrorLogEntry (
135 /**********************************************************************
144 * Number of stack locations to allocate;
150 * On success, the allocated IRP. On failure, NULL.
158 /**********************************************************************
163 * Allocates an MDL large enough to map the supplied buffer.
167 * Base virtual address of the buffer to be mapped;
170 * Length of the buffer to be mapped;
173 * Whether the buffer is primary or secondary;
176 * Charge non-paged pool quota to current thread;
179 * Optional irp to be associated with the MDL.
182 * On success, the allocated MDL; on failure, NULL.
187 PVOID VirtualAddress
,
189 BOOLEAN SecondaryBuffer
,
194 /**********************************************************************
199 * Creates a symbolic link between the ARC name of a physical
200 * device and the name of the corresponding device object
204 * ARC name of the device
207 * Name of the device object
212 * PUNICODE_STRING ArcName,
213 * PUNICODE_STRING DeviceName
216 #define IoAssignArcName(ArcName,DeviceName) \
217 (IoCreateSymbolicLink((ArcName),(DeviceName)))
219 /**********************************************************************
221 * IoAssignResources@24
224 * Takes a list of requested hardware resources and allocates
235 * Driver object passed to the DriverEntry routine;
248 PUNICODE_STRING RegistryPath
,
249 PUNICODE_STRING DriverClassName
,
250 PDRIVER_OBJECT DriverObject
,
251 PDEVICE_OBJECT DeviceObject
,
252 PIO_RESOURCE_REQUIREMENTS_LIST RequestedResources
,
253 PCM_RESOURCE_LIST
* AllocatedResources
256 * FUNCTION: Attaches the callers device object to a named target device
258 * SourceDevice = caller's device
259 * TargetDevice = Name of the target device
260 * AttachedDevice = Caller allocated storage. On return contains
261 * a pointer to the target device
262 * RETURNS: Success or failure code
267 PDEVICE_OBJECT SourceDevice
,
268 PUNICODE_STRING TargetDevice
,
269 PDEVICE_OBJECT
* AttachedDevice
274 * SourceDevice = device to attach
275 * TargetDevice = device to be attached to
276 * RETURNS: Success or failure code
280 IoAttachDeviceByPointer (
281 PDEVICE_OBJECT SourceDevice
,
282 PDEVICE_OBJECT TargetDevice
285 * FUNCTION: Attaches the callers device to the highest device in the chain
287 * SourceDevice = caller's device
288 * TargetDevice = Device to attach
289 * RETURNS: On success the previously highest device
294 IoAttachDeviceToDeviceStack (
295 PDEVICE_OBJECT SourceDevice
,
296 PDEVICE_OBJECT TargetDevice
299 * FUNCTION: Builds a irp to be sent to lower level drivers
301 * MajorFunction = Major function code to be set in the IRP
302 * DeviceObject = Next lower device object
303 * Buffer = Buffer (only required for some major function codes)
304 * Length = Length in bytes of the buffer
305 * StartingOffset = Starting offset on the target device
306 * IoStatusBlock = Storage for status about the operation (optional)
307 * RETURNS: On success the IRP allocated
312 IoBuildAsynchronousFsdRequest (
314 PDEVICE_OBJECT DeviceObject
,
317 PLARGE_INTEGER StartingOffset
,
318 PIO_STATUS_BLOCK IoStatusBlock
321 * FUNCTION: Allocates and sets up an IRP for a device control request
323 * IoControlCode = Type of request
324 * DeviceObject = Target device
325 * InputBuffer = Optional input buffer to the driver
326 * InputBufferLength = Length of the input buffer
327 * OutputBuffer = Optional output buffer
328 * OutputBufferLength = Length of the output buffer
329 * InternalDeviceIoControl = TRUE if the request is internal
330 * Event = Initialized event for the caller to wait for the request
332 * IoStatusBlock = I/O status block to be set when the request is
334 * RETURNS: Returns the IRP created
338 IoBuildDeviceIoControlRequest (
340 PDEVICE_OBJECT DeviceObject
,
342 ULONG InputBufferLength
,
344 ULONG OutputBufferLength
,
345 BOOLEAN InternalDeviceIoControl
,
347 PIO_STATUS_BLOCK IoStatusBlock
354 PVOID VirtualAddress
,
359 IoBuildSynchronousFsdRequest (
361 PDEVICE_OBJECT DeviceObject
,
364 PLARGE_INTEGER StartingOffset
,
366 PIO_STATUS_BLOCK IoStatusBlock
371 PDEVICE_OBJECT DeviceObject
,
381 IoCheckDesiredAccess (
387 IoCheckEaBufferValidity (
394 IoCheckFunctionAccess (
405 ACCESS_MASK DesiredAccess
,
406 ULONG DesiredShareAccess
,
407 PFILE_OBJECT FileObject
,
408 PSHARE_ACCESS ShareAccess
,
420 PKINTERRUPT
* InterruptObject
,
421 PKSERVICE_ROUTINE ServiceRoutine
,
422 PVOID ServiceContext
,
423 PKSPIN_LOCK SpinLock
,
426 KIRQL SynchronizeIrql
,
427 KINTERRUPT_MODE InterruptMode
,
429 KAFFINITY ProcessorEnableMask
,
439 * FUNCTION: Allocates memory for and intializes a device object for use for
442 * DriverObject : Driver object passed by iomgr when the driver was
444 * DeviceExtensionSize : Number of bytes for the device extension
445 * DeviceName : Unicode name of device
446 * DeviceType : Device type
447 * DeviceCharacteristics : Bit mask of device characteristics
448 * Exclusive : True if only one thread can access the device at a
452 * DeviceObject : Contains a pointer to allocated device object
453 * if the call succeeded
454 * NOTES: See the DDK documentation for more information
459 PDRIVER_OBJECT DriverObject
,
460 ULONG DeviceExtensionSize
,
461 PUNICODE_STRING DeviceName
,
462 DEVICE_TYPE DeviceType
,
463 ULONG DeviceCharacteristics
,
465 PDEVICE_OBJECT
* DeviceObject
470 OUT PHANDLE FileHandle
,
471 IN ACCESS_MASK DesiredAccess
,
472 IN POBJECT_ATTRIBUTES ObjectAttributes
,
473 OUT PIO_STATUS_BLOCK IoStatusBlock
,
474 IN PLARGE_INTEGER AllocationSize OPTIONAL
,
475 IN ULONG FileAttributes
,
476 IN ULONG ShareAccess
,
477 IN ULONG CreateDisposition
,
478 IN ULONG CreateOptions
,
479 IN PVOID EaBuffer OPTIONAL
,
481 IN CREATE_FILE_TYPE CreateFileType
,
482 IN PVOID ExtraCreateParameters OPTIONAL
,
487 IoCreateNotificationEvent (
488 PUNICODE_STRING EventName
,
493 IoCreateStreamFileObject (
494 PFILE_OBJECT FileObject
,
495 PDEVICE_OBJECT DeviceObject
499 IoCreateSymbolicLink (
500 PUNICODE_STRING SymbolicLinkName
,
501 PUNICODE_STRING DeviceName
505 IoCreateSynchronizationEvent (
506 PUNICODE_STRING EventName
,
511 IoCreateUnprotectedSymbolicLink (
512 PUNICODE_STRING SymbolicLinkName
,
513 PUNICODE_STRING DeviceName
518 * Deletes a symbolic link between the ARC name of a physical
519 * device and the name of the corresponding device object
522 * ArcName = ARC name of the device
526 * IoDeassignArcName (
527 * PUNICODE_STRING ArcName
530 #define IoDeassignArcName(ArcName) \
531 (IoDeleteSymbolicLink((ArcName)))
536 PCONTROLLER_OBJECT ControllerObject
541 PDEVICE_OBJECT DeviceObject
545 IoDeleteSymbolicLink (
546 PUNICODE_STRING SymbolicLinkName
551 PDEVICE_OBJECT TargetDevice
555 IoDisconnectInterrupt (
556 PKINTERRUPT InterruptObject
565 IoFastQueryNetworkAttributes (
575 PCONTROLLER_OBJECT ControllerObject
589 IoGetAttachedDevice (
590 PDEVICE_OBJECT DeviceObject
594 IoGetAttachedDeviceReference (
595 PDEVICE_OBJECT DeviceObject
599 IoGetBaseFileSystemDeviceObject (
600 IN PFILE_OBJECT FileObject
602 PCONFIGURATION_INFORMATION
604 IoGetConfigurationInformation (
609 * FUNCTION: Gets a pointer to the callers location in the I/O stack in
612 * Irp = Points to the IRP
613 * RETURNS: A pointer to the stack location
617 * IoGetCurrentIrpStackLocation (PIRP Irp)
619 #define IoGetCurrentIrpStackLocation(Irp) \
620 (&(Irp)->Stack[(ULONG)((Irp)->CurrentLocation)])
624 #define IoGetCurrentIrpStackLocation(Irp) \
625 ((Irp)->Tail.Overlay.CurrentStackLocation)
628 #define IoSetNextIrpStackLocation(Irp) { \
629 (Irp)->CurrentLocation--; \
630 (Irp)->Tail.Overlay.CurrentStackLocation--; }
632 #define IoCopyCurrentIrpStackLocationToNext(Irp) { \
633 PIO_STACK_LOCATION IrpSp; \
634 PIO_STACK_LOCATION NextIrpSp; \
635 IrpSp = IoGetCurrentIrpStackLocation((Irp)); \
636 NextIrpSp = IoGetNextIrpStackLocation((Irp)); \
637 RtlCopyMemory(NextIrpSp, IrpSp, \
638 FIELD_OFFSET(IO_STACK_LOCATION, CompletionRoutine)); \
639 NextIrpSp->Control = 0; }
641 #define IoSkipCurrentIrpStackLocation(Irp) \
642 (Irp)->CurrentLocation++; \
643 (Irp)->Tail.Overlay.CurrentStackLocation++;
647 IoGetCurrentProcess (
652 IoGetDeviceObjectPointer (
653 PUNICODE_STRING ObjectName
,
654 ACCESS_MASK DesiredAccess
,
655 PFILE_OBJECT
* FileObject
,
656 PDEVICE_OBJECT
* DeviceObject
660 IoGetDeviceToVerify (
661 struct _ETHREAD
* Thread
665 IoGetFileObjectGenericMapping (
669 #define IoGetFunctionCodeFromCtlCode(ControlCode) \
670 ((ControlCode >> 2) & 0x00000FFF)
679 * FUNCTION: Gives a higher level driver access to the next lower driver's
682 * Irp = points to the irp
683 * RETURNS: A pointer to the stack location
687 * IoGetNextIrpStackLocation (PIRP Irp)
689 #define IoGetNextIrpStackLocation(Irp) \
690 (&(Irp)->Stack[(Irp)->CurrentLocation-1])
694 #define IoGetNextIrpStackLocation(Irp) \
695 ((Irp)->Tail.Overlay.CurrentStackLocation-1)
700 IoGetRelatedDeviceObject (
701 PFILE_OBJECT FileObject
705 IoGetRequestorProcess (
722 #define IoInitializeDpcRequest(DeviceObject,DpcRoutine) \
723 (KeInitializeDpc(&(DeviceObject)->Dpc, \
724 (PKDEFERRED_ROUTINE)(DpcRoutine), \
728 * FUNCTION: Initalizes an irp allocated by the caller
730 * Irp = IRP to initalize
731 * PacketSize = Size in bytes of the IRP
732 * StackSize = Number of stack locations in the IRP
744 PDEVICE_OBJECT DeviceObject
,
745 PIO_TIMER_ROUTINE TimerRoutine
,
752 * IsErrorUserInduced (NTSTATUS Status)
754 #define IoIsErrorUserInduced(Status) \
755 ((BOOLEAN)(((Status) == STATUS_DEVICE_NOT_READY) || \
756 ((Status) == STATUS_IO_TIMEOUT) || \
757 ((Status) == STATUS_MEDIA_WRITE_PROTECTED) || \
758 ((Status) == STATUS_NO_MEDIA_IN_DRIVE) || \
759 ((Status) == STATUS_VERIFY_REQUIRED) || \
760 ((Status) == STATUS_UNRECOGNIZED_MEDIA) || \
761 ((Status) == STATUS_WRONG_VOLUME)))
765 IoIsOperationSynchronous (
775 IoMakeAssociatedIrp (
781 * FUNCTION: Marks the specified irp, indicating further processing will
782 * be required by other driver routines
787 * IoMarkIrpPending (PIRP Irp)
789 #define IoMarkIrpPending(Irp) \
790 (IoGetCurrentIrpStackLocation(Irp)->Control |= SL_PENDING_RETURNED)
795 IoOpenDeviceInstanceKey (
804 IoQueryDeviceDescription (
805 PINTERFACE_TYPE BusType
,
807 PCONFIGURATION_TYPE ControllerType
,
808 PULONG ControllerNumber
,
809 PCONFIGURATION_TYPE PeripheralType
,
810 PULONG PeripheralNumber
,
811 PIO_QUERY_DEVICE_ROUTINE CalloutRoutine
,
816 IoQueryDeviceEnumInfo (
820 // IoQueryFileInformation: confirmed - Undocumented because it does not require a valid file handle
823 IoQueryFileInformation (
824 IN PFILE_OBJECT FileObject
,
825 IN FILE_INFORMATION_CLASS FileInformationClass
,
827 OUT PVOID FileInformation
,
828 OUT PULONG ReturnedLength
832 IoQueryVolumeInformation (
833 IN PFILE_OBJECT FileObject
,
834 IN FS_INFORMATION_CLASS FsInformationClass
,
836 OUT PVOID FsInformation
,
837 OUT PULONG ReturnedLength
849 PDEVICE_OBJECT RealDeviceObject
853 IoRaiseInformationalHardError (
854 NTSTATUS ErrorStatus
,
855 PUNICODE_STRING String
,
856 struct _KTHREAD
* Thread
860 IoRegisterDriverReinitialization (
861 PDRIVER_OBJECT DriverObject
,
862 PDRIVER_REINITIALIZE ReinitRoutine
,
867 IoRegisterFileSystem (
868 PDEVICE_OBJECT DeviceObject
870 #if (_WIN32_WINNT >= 0x0400)
873 IoRegisterFsRegistrationChange (
874 IN PDRIVER_OBJECT DriverObject
,
875 IN PFSDNOTIFICATIONPROC FSDNotificationProc
877 #endif // (_WIN32_WINNT >= 0x0400)
880 IoRegisterShutdownNotification (
881 PDEVICE_OBJECT DeviceObject
885 IoReleaseCancelSpinLock (
890 IoReleaseVpbSpinLock (
895 IoRemoveShareAccess (
896 PFILE_OBJECT FileObject
,
897 PSHARE_ACCESS ShareAccess
901 IoReportHalResourceUsage (
902 IN PUNICODE_STRING HalDescription
,
903 IN PCM_RESOURCE_LIST RawList
,
904 IN PCM_RESOURCE_LIST TranslatedList
,
909 IoReportResourceUsage (
910 PUNICODE_STRING DriverClassName
,
911 PDRIVER_OBJECT DriverObject
,
912 PCM_RESOURCE_LIST DriverList
,
913 ULONG DriverListSize
,
914 PDEVICE_OBJECT DeviceObject
,
915 PCM_RESOURCE_LIST DeviceList
,
916 ULONG DeviceListSize
,
917 BOOLEAN OverrideConflict
,
918 PBOOLEAN ConflictDetected
921 #define IoRequestDpc(DeviceObject,Irp,Context) \
922 (KeInsertQueueDpc(&(DeviceObject)->Dpc,(Irp),(Context)))
924 #define IoSetCancelRoutine(Irp,NewCancelRoutine) \
925 ((PDRIVER_CANCEL)InterlockedExchange((PULONG)&(Irp)->CancelRoutine, \
926 (ULONG)(NewCancelRoutine)));
928 #define IoSetCompletionRoutine(Irp,Routine,Context,Success,Error,Cancel) \
930 PIO_STACK_LOCATION param; \
931 assert((Success)||(Error)||(Cancel)?(Routine)!=NULL:TRUE); \
932 param = IoGetNextIrpStackLocation((Irp)); \
933 param->CompletionRoutine=(Routine); \
934 param->CompletionContext=(Context); \
935 param->Control = 0; \
937 param->Control = SL_INVOKE_ON_SUCCESS; \
939 param->Control |= SL_INVOKE_ON_ERROR; \
941 param->Control |= SL_INVOKE_ON_CANCEL; \
945 IoSetDeviceToVerify (IN
struct _ETHREAD
* Thread
,
946 IN PDEVICE_OBJECT DeviceObject
);
949 IoSetHardErrorOrVerifyDevice (
951 IN PDEVICE_OBJECT DeviceObject
956 IN PFILE_OBJECT FileObject
,
957 IN FILE_INFORMATION_CLASS FileInformationClass
,
959 OUT PVOID FileInformation
962 #define IoSetNextIrpStackLocation(Irp) \
964 (Irp)->CurrentLocation--; \
965 (Irp)->Tail.Overlay.CurrentStackLocation--; \
971 ACCESS_MASK DesiredAccess
,
972 ULONG DesiredShareAccess
,
973 PFILE_OBJECT FileObject
,
974 PSHARE_ACCESS ShareAccess
978 IoSetThreadHardErrorMode (
979 IN BOOLEAN HardErrorEnabled
988 * FUNCTION: Determines the size of an IRP
990 * StackSize = number of stack locations in the IRP
991 * RETURNS: The size of the IRP in bytes
993 IoSizeOfIrp (CCHAR StackSize)
995 #define IoSizeOfIrp(StackSize) \
996 ((USHORT)(sizeof(IRP)+(((StackSize)-1)*sizeof(IO_STACK_LOCATION))))
1000 #define IoSizeOfIrp(StackSize) \
1001 ((USHORT)(sizeof(IRP)+((StackSize)*sizeof(IO_STACK_LOCATION))))
1005 * FUNCTION: Dequeues the next IRP from the device's associated queue and
1006 * calls its StartIo routine
1008 * DeviceObject = Device object
1009 * Cancelable = True if IRPs in the queue can be cancelled
1014 PDEVICE_OBJECT DeviceObject
,
1019 IoStartNextPacketByKey (
1020 PDEVICE_OBJECT DeviceObject
,
1025 * FUNCTION: Calls the drivers StartIO routine with the IRP or queues it if
1026 * the device is busy
1028 * DeviceObject = Device to pass the IRP to
1029 * Irp = Irp to be processed
1030 * Key = Optional value for where to insert the IRP
1031 * CancelFunction = Entry point for a driver supplied cancel function
1036 PDEVICE_OBJECT DeviceObject
,
1039 PDRIVER_CANCEL CancelFunction
1044 PDEVICE_OBJECT DeviceObject
1049 PDEVICE_OBJECT DeviceObject
1053 IoSynchronousPageWrite (
1060 struct _EPROCESS
* STDCALL
IoThreadToProcess (struct _ETHREAD
* Thread
);
1063 IoUnregisterFileSystem (
1064 IN PDEVICE_OBJECT DeviceObject
1066 #if (_WIN32_WINNT >= 0x0400)
1069 IoUnregisterFsRegistrationChange (
1073 #endif // (_WIN32_WINNT >= 0x0400)
1076 IoUnregisterShutdownNotification (
1077 PDEVICE_OBJECT DeviceObject
1081 IoUpdateShareAccess (
1082 IN PFILE_OBJECT FileObject
,
1083 IN PSHARE_ACCESS ShareAccess
1088 IN PDEVICE_OBJECT DeviceObject
,
1089 IN BOOLEAN AllowRawMount
1093 IoWriteErrorLogEntry (
1097 * FUNCTION: Sends an irp to the next lower driver
1102 PDEVICE_OBJECT DeviceObject
,
1106 * FUNCTION: Indicates the caller has finished all processing for a given
1107 * I/O request and is returning the given IRP to the I/O manager
1109 * Irp = Irp to be cancelled
1110 * PriorityBoost = Increment by which to boost the priority of the
1111 * thread making the request
1115 IofCompleteRequest (
1120 /* --- EXPORTED BY HAL --- */
1124 IoAssignDriveLetters (
1125 IN PLOADER_PARAMETER_BLOCK LoaderBlock
,
1126 IN PSTRING NtDeviceName
,
1127 OUT PUCHAR NtSystemPath
,
1128 OUT PSTRING NtSystemPathString
1133 IoFlushAdapterBuffers (
1134 PADAPTER_OBJECT AdapterObject
,
1136 PVOID MapRegisterBase
,
1139 BOOLEAN WriteToDevice
1144 IoFreeAdapterChannel (
1145 PADAPTER_OBJECT AdapterObject
1150 IoFreeMapRegisters (
1151 PADAPTER_OBJECT AdapterObject
,
1152 PVOID MapRegisterBase
,
1153 ULONG NumberOfMapRegisters
1159 PADAPTER_OBJECT AdapterObject
,
1161 PVOID MapRegisterBase
,
1164 BOOLEAN WriteToDevice
1169 IoReadPartitionTable (
1170 PDEVICE_OBJECT DeviceObject
,
1172 BOOLEAN ReturnedRecognizedPartitions
,
1173 PDRIVE_LAYOUT_INFORMATION
* PartitionBuffer
1178 IoSetPartitionInformation (
1179 PDEVICE_OBJECT DeviceObject
,
1181 ULONG PartitionNumber
,
1187 IoWritePartitionTable (
1188 PDEVICE_OBJECT DeviceObject
,
1190 ULONG SectorsPerTrack
,
1191 ULONG NumberOfHeads
,
1192 PDRIVE_LAYOUT_INFORMATION PartitionBuffer
1196 /* --- --- --- INTERNAL or REACTOS ONLY --- --- --- */
1199 * FUNCTION: Registers the driver with WMI
1201 * DeviceObject = Device to register
1202 * Action = Action to take
1203 * RETURNS: Status (?)
1207 IoWMIRegistrationControl (
1208 PDEVICE_OBJECT DeviceObject,
1209 WMIREGACTION Action);
1213 IoIsTotalDeviceFailure (
1218 #endif /* ndef _INCLUDE_DDK_IOFUNCS_H */