1 #ifndef _INCLUDE_DDK_IOFUNCS_H
2 #define _INCLUDE_DDK_IOFUNCS_H
3 /* $Id: iofuncs.h,v 1.24 2001/06/08 15:06:51 ekohl 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 IoCopyCurrentIrpStackLocationToNext(Irp) { \
629 PIO_STACK_LOCATION IrpSp; \
630 PIO_STACK_LOCATION NextIrpSp; \
631 IrpSp = IoGetCurrentIrpStackLocation((Irp)); \
632 NextIrpSp = IoGetNextIrpStackLocation((Irp)); \
633 RtlCopyMemory(NextIrpSp, IrpSp, \
634 FIELD_OFFSET(IO_STACK_LOCATION, CompletionRoutine)); \
635 NextIrpSp->Control = 0; }
639 IoGetCurrentProcess (
644 IoGetDeviceObjectPointer (
645 PUNICODE_STRING ObjectName
,
646 ACCESS_MASK DesiredAccess
,
647 PFILE_OBJECT
* FileObject
,
648 PDEVICE_OBJECT
* DeviceObject
652 IoGetDeviceToVerify (
653 struct _ETHREAD
* Thread
657 IoGetFileObjectGenericMapping (
661 #define IoGetFunctionCodeFromCtlCode(ControlCode) \
662 ((ControlCode >> 2) & 0x00000FFF)
671 * FUNCTION: Gives a higher level driver access to the next lower driver's
674 * Irp = points to the irp
675 * RETURNS: A pointer to the stack location
679 * IoGetNextIrpStackLocation (PIRP Irp)
681 #define IoGetNextIrpStackLocation(Irp) \
682 (&(Irp)->Stack[(Irp)->CurrentLocation-1])
686 #define IoGetNextIrpStackLocation(Irp) \
687 ((Irp)->Tail.Overlay.CurrentStackLocation-1)
692 IoGetRelatedDeviceObject (
693 PFILE_OBJECT FileObject
697 IoGetRequestorProcess (
714 #define IoInitializeDpcRequest(DeviceObject,DpcRoutine) \
715 (KeInitializeDpc(&(DeviceObject)->Dpc, \
716 (PKDEFERRED_ROUTINE)(DpcRoutine), \
720 * FUNCTION: Initalizes an irp allocated by the caller
722 * Irp = IRP to initalize
723 * PacketSize = Size in bytes of the IRP
724 * StackSize = Number of stack locations in the IRP
736 PDEVICE_OBJECT DeviceObject
,
737 PIO_TIMER_ROUTINE TimerRoutine
,
744 * IsErrorUserInduced (NTSTATUS Status)
746 #define IoIsErrorUserInduced(Status) \
747 ((BOOLEAN)(((Status) == STATUS_DEVICE_NOT_READY) || \
748 ((Status) == STATUS_IO_TIMEOUT) || \
749 ((Status) == STATUS_MEDIA_WRITE_PROTECTED) || \
750 ((Status) == STATUS_NO_MEDIA_IN_DRIVE) || \
751 ((Status) == STATUS_VERIFY_REQUIRED) || \
752 ((Status) == STATUS_UNRECOGNIZED_MEDIA) || \
753 ((Status) == STATUS_WRONG_VOLUME)))
757 IoIsOperationSynchronous (
767 IoMakeAssociatedIrp (
773 * FUNCTION: Marks the specified irp, indicating further processing will
774 * be required by other driver routines
779 * IoMarkIrpPending (PIRP Irp)
781 #define IoMarkIrpPending(Irp) \
782 (IoGetCurrentIrpStackLocation(Irp)->Control |= SL_PENDING_RETURNED)
787 IoOpenDeviceInstanceKey (
796 IoQueryDeviceDescription (
797 PINTERFACE_TYPE BusType
,
799 PCONFIGURATION_TYPE ControllerType
,
800 PULONG ControllerNumber
,
801 PCONFIGURATION_TYPE PeripheralType
,
802 PULONG PeripheralNumber
,
803 PIO_QUERY_DEVICE_ROUTINE CalloutRoutine
,
808 IoQueryDeviceEnumInfo (
812 // IoQueryFileInformation: confirmed - Undocumented because it does not require a valid file handle
815 IoQueryFileInformation (
816 IN PFILE_OBJECT FileObject
,
817 IN FILE_INFORMATION_CLASS FileInformationClass
,
819 OUT PVOID FileInformation
,
820 OUT PULONG ReturnedLength
824 IoQueryVolumeInformation (
825 IN PFILE_OBJECT FileObject
,
826 IN FS_INFORMATION_CLASS FsInformationClass
,
828 OUT PVOID FsInformation
,
829 OUT PULONG ReturnedLength
841 PDEVICE_OBJECT RealDeviceObject
845 IoRaiseInformationalHardError (
846 NTSTATUS ErrorStatus
,
847 PUNICODE_STRING String
,
848 struct _KTHREAD
* Thread
852 IoRegisterDriverReinitialization (
853 PDRIVER_OBJECT DriverObject
,
854 PDRIVER_REINITIALIZE ReinitRoutine
,
859 IoRegisterFileSystem (
860 PDEVICE_OBJECT DeviceObject
862 #if (_WIN32_WINNT >= 0x0400)
865 IoRegisterFsRegistrationChange (
866 IN PDRIVER_OBJECT DriverObject
,
867 IN PFSDNOTIFICATIONPROC FSDNotificationProc
869 #endif // (_WIN32_WINNT >= 0x0400)
872 IoRegisterShutdownNotification (
873 PDEVICE_OBJECT DeviceObject
877 IoReleaseCancelSpinLock (
882 IoReleaseVpbSpinLock (
887 IoRemoveShareAccess (
888 PFILE_OBJECT FileObject
,
889 PSHARE_ACCESS ShareAccess
893 IoReportHalResourceUsage (
894 PUNICODE_STRING HalDescription
,
901 IoReportResourceUsage (
902 PUNICODE_STRING DriverClassName
,
903 PDRIVER_OBJECT DriverObject
,
904 PCM_RESOURCE_LIST DriverList
,
905 ULONG DriverListSize
,
906 PDEVICE_OBJECT DeviceObject
,
907 PCM_RESOURCE_LIST DeviceList
,
908 ULONG DeviceListSize
,
909 BOOLEAN OverrideConflict
,
910 PBOOLEAN ConflictDetected
913 #define IoRequestDpc(DeviceObject,Irp,Context) \
914 (KeInsertQueueDpc(&(DeviceObject)->Dpc,(Irp),(Context)))
916 #define IoSetCancelRoutine(Irp,NewCancelRoutine) \
917 ((PDRIVER_CANCEL)InterlockedExchange((PULONG)&(Irp)->CancelRoutine, \
918 (ULONG)(NewCancelRoutine)));
920 #define IoSetCompletionRoutine(Irp,Routine,Context,Success,Error,Cancel) \
922 PIO_STACK_LOCATION param; \
923 assert((Success)||(Error)||(Cancel)?(Routine)!=NULL:TRUE); \
924 param = IoGetNextIrpStackLocation((Irp)); \
925 param->CompletionRoutine=(Routine); \
926 param->CompletionContext=(Context); \
927 param->Control = 0; \
929 param->Control = SL_INVOKE_ON_SUCCESS; \
931 param->Control |= SL_INVOKE_ON_ERROR; \
933 param->Control |= SL_INVOKE_ON_CANCEL; \
937 IoSetDeviceToVerify (IN
struct _ETHREAD
* Thread
,
938 IN PDEVICE_OBJECT DeviceObject
);
941 IoSetHardErrorOrVerifyDevice (
943 IN PDEVICE_OBJECT DeviceObject
948 IN PFILE_OBJECT FileObject
,
949 IN FILE_INFORMATION_CLASS FileInformationClass
,
951 OUT PVOID FileInformation
954 #define IoSetNextIrpStackLocation(Irp) \
956 (Irp)->CurrentLocation--; \
957 (Irp)->Tail.Overlay.CurrentStackLocation--; \
963 ACCESS_MASK DesiredAccess
,
964 ULONG DesiredShareAccess
,
965 PFILE_OBJECT FileObject
,
966 PSHARE_ACCESS ShareAccess
970 IoSetThreadHardErrorMode (
971 IN BOOLEAN HardErrorEnabled
980 * FUNCTION: Determines the size of an IRP
982 * StackSize = number of stack locations in the IRP
983 * RETURNS: The size of the IRP in bytes
985 IoSizeOfIrp (CCHAR StackSize)
987 #define IoSizeOfIrp(StackSize) \
988 ((USHORT)(sizeof(IRP)+(((StackSize)-1)*sizeof(IO_STACK_LOCATION))))
992 #define IoSizeOfIrp(StackSize) \
993 ((USHORT)(sizeof(IRP)+((StackSize)*sizeof(IO_STACK_LOCATION))))
997 * FUNCTION: Dequeues the next IRP from the device's associated queue and
998 * calls its StartIo routine
1000 * DeviceObject = Device object
1001 * Cancelable = True if IRPs in the queue can be cancelled
1006 PDEVICE_OBJECT DeviceObject
,
1011 IoStartNextPacketByKey (
1012 PDEVICE_OBJECT DeviceObject
,
1017 * FUNCTION: Calls the drivers StartIO routine with the IRP or queues it if
1018 * the device is busy
1020 * DeviceObject = Device to pass the IRP to
1021 * Irp = Irp to be processed
1022 * Key = Optional value for where to insert the IRP
1023 * CancelFunction = Entry point for a driver supplied cancel function
1028 PDEVICE_OBJECT DeviceObject
,
1031 PDRIVER_CANCEL CancelFunction
1036 PDEVICE_OBJECT DeviceObject
1041 PDEVICE_OBJECT DeviceObject
1045 IoSynchronousPageWrite (
1052 struct _EPROCESS
* STDCALL
IoThreadToProcess (struct _ETHREAD
* Thread
);
1055 IoUnregisterFileSystem (
1056 IN PDEVICE_OBJECT DeviceObject
1058 #if (_WIN32_WINNT >= 0x0400)
1061 IoUnregisterFsRegistrationChange (
1065 #endif // (_WIN32_WINNT >= 0x0400)
1068 IoUnregisterShutdownNotification (
1069 PDEVICE_OBJECT DeviceObject
1073 IoUpdateShareAccess (
1074 IN PFILE_OBJECT FileObject
,
1075 IN PSHARE_ACCESS ShareAccess
1080 IN PDEVICE_OBJECT DeviceObject
,
1081 IN BOOLEAN AllowRawMount
1085 IoWriteErrorLogEntry (
1089 * FUNCTION: Sends an irp to the next lower driver
1094 PDEVICE_OBJECT DeviceObject
,
1098 * FUNCTION: Indicates the caller has finished all processing for a given
1099 * I/O request and is returning the given IRP to the I/O manager
1101 * Irp = Irp to be cancelled
1102 * PriorityBoost = Increment by which to boost the priority of the
1103 * thread making the request
1107 IofCompleteRequest (
1112 /* --- EXPORTED BY HAL --- */
1116 IoAssignDriveLetters (
1117 IN PLOADER_PARAMETER_BLOCK LoaderBlock
,
1118 IN PSTRING NtDeviceName
,
1119 OUT PUCHAR NtSystemPath
,
1120 OUT PSTRING NtSystemPathString
1125 IoFlushAdapterBuffers (
1126 PADAPTER_OBJECT AdapterObject
,
1128 PVOID MapRegisterBase
,
1131 BOOLEAN WriteToDevice
1136 IoFreeAdapterChannel (
1137 PADAPTER_OBJECT AdapterObject
1142 IoFreeMapRegisters (
1143 PADAPTER_OBJECT AdapterObject
,
1144 PVOID MapRegisterBase
,
1145 ULONG NumberOfMapRegisters
1151 PADAPTER_OBJECT AdapterObject
,
1153 PVOID MapRegisterBase
,
1156 BOOLEAN WriteToDevice
1161 IoReadPartitionTable (
1162 PDEVICE_OBJECT DeviceObject
,
1164 BOOLEAN ReturnedRecognizedPartitions
,
1165 PDRIVE_LAYOUT_INFORMATION
* PartitionBuffer
1170 IoSetPartitionInformation (
1171 PDEVICE_OBJECT DeviceObject
,
1173 ULONG PartitionNumber
,
1179 IoWritePartitionTable (
1180 PDEVICE_OBJECT DeviceObject
,
1182 ULONG SectorsPerTrack
,
1183 ULONG NumberOfHeads
,
1184 PDRIVE_LAYOUT_INFORMATION PartitionBuffer
1188 /* --- --- --- INTERNAL or REACTOS ONLY --- --- --- */
1191 * FUNCTION: Registers the driver with WMI
1193 * DeviceObject = Device to register
1194 * Action = Action to take
1195 * RETURNS: Status (?)
1199 IoWMIRegistrationControl (
1200 PDEVICE_OBJECT DeviceObject,
1201 WMIREGACTION Action);
1205 IoIsTotalDeviceFailure (
1210 #endif /* ndef _INCLUDE_DDK_IOFUNCS_H */