1 #ifndef _INCLUDE_DDK_IOFUNCS_H
2 #define _INCLUDE_DDK_IOFUNCS_H
3 /* $Id: iofuncs.h,v 1.13 2000/06/12 14:51:26 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
,
438 * FUNCTION: Allocates memory for and intializes a device object for use for
441 * DriverObject : Driver object passed by iomgr when the driver was
443 * DeviceExtensionSize : Number of bytes for the device extension
444 * DeviceName : Unicode name of device
445 * DeviceType : Device type
446 * DeviceCharacteristics : Bit mask of device characteristics
447 * Exclusive : True if only one thread can access the device at a
451 * DeviceObject : Contains a pointer to allocated device object
452 * if the call succeeded
453 * NOTES: See the DDK documentation for more information
458 PDRIVER_OBJECT DriverObject
,
459 ULONG DeviceExtensionSize
,
460 PUNICODE_STRING DeviceName
,
461 DEVICE_TYPE DeviceType
,
462 ULONG DeviceCharacteristics
,
464 PDEVICE_OBJECT
* DeviceObject
469 OUT PHANDLE FileHandle
,
470 IN ACCESS_MASK DesiredAccess
,
471 IN POBJECT_ATTRIBUTES ObjectAttributes
,
472 OUT PIO_STATUS_BLOCK IoStatusBlock
,
473 IN PLARGE_INTEGER AllocationSize OPTIONAL
,
474 IN ULONG FileAttributes
,
475 IN ULONG ShareAccess
,
476 IN ULONG CreateDisposition
,
477 IN ULONG CreateOptions
,
478 IN PVOID EaBuffer OPTIONAL
,
480 IN CREATE_FILE_TYPE CreateFileType
,
481 IN PVOID ExtraCreateParameters OPTIONAL
,
486 IoCreateNotificationEvent (
487 PUNICODE_STRING EventName
,
492 IoCreateStreamFileObject (
493 PFILE_OBJECT FileObject
,
494 PDEVICE_OBJECT DeviceObject
498 IoCreateSymbolicLink (
499 PUNICODE_STRING SymbolicLinkName
,
500 PUNICODE_STRING DeviceName
504 IoCreateSynchronizationEvent (
505 PUNICODE_STRING EventName
,
510 IoCreateUnprotectedSymbolicLink (
511 PUNICODE_STRING SymbolicLinkName
,
512 PUNICODE_STRING DeviceName
517 * Deletes a symbolic link between the ARC name of a physical
518 * device and the name of the corresponding device object
521 * ArcName = ARC name of the device
525 * IoDeassignArcName (
526 * PUNICODE_STRING ArcName
529 #define IoDeassignArcName(ArcName) \
530 IoDeleteSymbolicLink((ArcName))
535 PCONTROLLER_OBJECT ControllerObject
540 PDEVICE_OBJECT DeviceObject
544 IoDeleteSymbolicLink (
545 PUNICODE_STRING SymbolicLinkName
550 PDEVICE_OBJECT TargetDevice
554 IoDisconnectInterrupt (
555 PKINTERRUPT InterruptObject
564 IoFastQueryNetworkAttributes (
574 PCONTROLLER_OBJECT ControllerObject
588 IoGetAttachedDevice (
589 PDEVICE_OBJECT DeviceObject
593 IoGetBaseFileSystemDeviceObject (
594 IN PFILE_OBJECT FileObject
596 PCONFIGURATION_INFORMATION
598 IoGetConfigurationInformation (
603 * FUNCTION: Gets a pointer to the callers location in the I/O stack in
606 * Irp = Points to the IRP
607 * RETURNS: A pointer to the stack location
611 * IoGetCurrentIrpStackLocation (PIRP Irp)
613 #define IoGetCurrentIrpStackLocation(Irp) \
614 (&(Irp)->Stack[(ULONG)((Irp)->CurrentLocation)])
618 #define IoGetCurrentIrpStackLocation(Irp) \
619 ((Irp)->Tail.Overlay.CurrentStackLocation)
623 IoGetCurrentProcess (
628 IoGetDeviceObjectPointer (
629 PUNICODE_STRING ObjectName
,
630 ACCESS_MASK DesiredAccess
,
631 PFILE_OBJECT
* FileObject
,
632 PDEVICE_OBJECT
* DeviceObject
636 IoGetDeviceToVerify (
641 IoGetFileObjectGenericMapping (
645 #define IoGetFunctionCodeFromCtlCode(ControlCode) \
646 ((ControlCode >> 2) & 0x00000FFF)
655 * FUNCTION: Gives a higher level driver access to the next lower driver's
658 * Irp = points to the irp
659 * RETURNS: A pointer to the stack location
663 * IoGetNextIrpStackLocation (PIRP Irp)
665 #define IoGetNextIrpStackLocation(Irp) \
666 (&(Irp)->Stack[(Irp)->CurrentLocation-1])
670 #define IoGetNextIrpStackLocation(Irp) \
671 ((Irp)->Tail.Overlay.CurrentStackLocation-1)
676 IoGetRelatedDeviceObject (
677 PFILE_OBJECT FileObject
681 IoGetRequestorProcess (
687 PVOID
* Minimum
, /* guess */
688 PVOID
* Maximum
/* guess */
696 #define IoInitializeDpcRequest(DeviceObject, DpcRoutine) \
697 (KeInitializeDpc(&(DeviceObject)->Dpc, \
698 (PKDEFERRED_ROUTINE)(DpcRoutine), \
702 * FUNCTION: Initalizes an irp allocated by the caller
704 * Irp = IRP to initalize
705 * PacketSize = Size in bytes of the IRP
706 * StackSize = Number of stack locations in the IRP
718 PDEVICE_OBJECT DeviceObject
,
719 PIO_TIMER_ROUTINE TimerRoutine
,
726 * IsErrorUserInduced (NTSTATUS Status)
728 #define IoIsErrorUserInduced(Status) \
729 ((BOOLEAN)(((Status) == STATUS_DEVICE_NOT_READY) || \
730 ((Status) == STATUS_IO_TIMEOUT) || \
731 ((Status) == STATUS_MEDIA_WRITE_PROTECTED) || \
732 ((Status) == STATUS_NO_MEDIA_IN_DRIVE) || \
733 ((Status) == STATUS_VERIFY_REQUIRED) || \
734 ((Status) == STATUS_UNRECOGNIZED_MEDIA) || \
735 ((Status) == STATUS_WRONG_VOLUME)))
739 IoIsOperationSynchronous (
749 IoMakeAssociatedIrp (
755 * FUNCTION: Marks the specified irp, indicating further processing will
756 * be required by other driver routines
761 * IoMarkIrpPending (PIRP Irp)
763 #define IoMarkIrpPending(Irp) \
764 (IoGetCurrentIrpStackLocation(Irp)->Control |= SL_PENDING_RETURNED)
769 IoOpenDeviceInstanceKey (
779 PFILE_OBJECT FileObject
,
781 PLARGE_INTEGER Offset
,
782 PIO_STATUS_BLOCK StatusBlock
786 IoQueryDeviceDescription (
787 PINTERFACE_TYPE BusType
,
789 PCONFIGURATION_TYPE ControllerType
,
790 PULONG ControllerNumber
,
791 PCONFIGURATION_TYPE PeripheralType
,
792 PULONG PeripheralNumber
,
793 PIO_QUERY_DEVICE_ROUTINE CalloutRoutine
,
798 IoQueryDeviceEnumInfo (
802 // IoQueryFileInformation: confirmed - Undocumented because it does not require a valid file handle
805 IoQueryFileInformation (
806 IN PFILE_OBJECT FileObject
,
807 IN FILE_INFORMATION_CLASS FileInformationClass
,
809 OUT PVOID FileInformation
,
810 OUT PULONG ReturnedLength
814 IoQueryVolumeInformation (
815 IN PFILE_OBJECT FileObject
,
816 IN FS_INFORMATION_CLASS FsInformationClass
,
818 OUT PVOID FsInformation
,
819 OUT PULONG ReturnedLength
831 PDEVICE_OBJECT RealDeviceObject
835 IoRaiseInformationalHardError (
836 NTSTATUS ErrorStatus
,
837 PUNICODE_STRING String
,
842 IoRegisterDriverReinitialization (
843 PDRIVER_OBJECT DriverObject
,
844 PDRIVER_REINITIALIZE ReinitRoutine
,
849 IoRegisterFileSystem (
850 PDEVICE_OBJECT DeviceObject
852 #if (_WIN32_WINNT >= 0x0400)
855 IoRegisterFsRegistrationChange (
856 IN PDRIVER_OBJECT DriverObject
,
857 IN PFSDNOTIFICATIONPROC FSDNotificationProc
859 #endif // (_WIN32_WINNT >= 0x0400)
862 IoRegisterShutdownNotification (
863 PDEVICE_OBJECT DeviceObject
867 IoReleaseCancelSpinLock (
872 IoReleaseVpbSpinLock (
877 IoRemoveShareAccess (
878 PFILE_OBJECT FileObject
,
879 PSHARE_ACCESS ShareAccess
883 IoReportHalResourceUsage (
884 PUNICODE_STRING HalDescription
,
891 IoReportResourceUsage (
892 PUNICODE_STRING DriverClassName
,
893 PDRIVER_OBJECT DriverObject
,
894 PCM_RESOURCE_LIST DriverList
,
895 ULONG DriverListSize
,
896 PDEVICE_OBJECT DeviceObject
,
897 PCM_RESOURCE_LIST DeviceList
,
898 ULONG DeviceListSize
,
899 BOOLEAN OverrideConflict
,
900 PBOOLEAN ConflictDetected
903 #define IoRequestDpc(DeviceObject, Irp, Context) \
904 (KeInsertQueueDpc(&(DeviceObject)->Dpc,(Irp),(Context)))
906 #define IoSetCancelRoutine(Irp, NewCancelRoutine) \
907 ((PDRIVER_CANCEL)InterlockedExchange((PULONG)&(Irp)->CancelRoutine, \
908 (ULONG)(NewCancelRoutine)));
910 #define IoSetCompletionRoutine (Irp,Routine,Context,Success,Error,Cancel) \
912 PIO_STACK_LOCATION param; \
913 assert((Success)||(Error)||(Cancel)?(Routine)!=NULL:TRUE); \
914 param = IoGetNextIrpStackLocation((Irp)); \
915 param->CompletionRoutine=(Routine); \
916 param->CompletionContext=(Context); \
917 param->Control = 0; \
919 param->Control = SL_INVOKE_ON_SUCCESS; \
921 param->Control |= SL_INVOKE_ON_ERROR; \
923 param->Control |= SL_INVOKE_ON_CANCEL; \
928 IoSetDeviceToVerify (
934 IoSetHardErrorOrVerifyDevice (
936 PDEVICE_OBJECT DeviceObject
941 IN PFILE_OBJECT FileObject
,
942 IN FILE_INFORMATION_CLASS FileInformationClass
,
944 OUT PVOID FileInformation
947 #define IoSetNextIrpStackLocation(Irp) \
949 (Irp)->CurrentLocation--; \
950 (Irp)->Tail.Overlay.CurrentStackLocation--; \
956 ACCESS_MASK DesiredAccess
,
957 ULONG DesiredShareAccess
,
958 PFILE_OBJECT FileObject
,
959 PSHARE_ACCESS ShareAccess
963 IoSetThreadHardErrorMode (
964 IN BOOLEAN HardErrorEnabled
973 * FUNCTION: Determines the size of an IRP
975 * StackSize = number of stack locations in the IRP
976 * RETURNS: The size of the IRP in bytes
978 IoSizeOfIrp (CCHAR StackSize)
980 #define IoSizeOfIrp(StackSize) \
981 ((USHORT)(sizeof(IRP)+(((StackSize)-1)*sizeof(IO_STACK_LOCATION))))
985 #define IoSizeOfIrp(StackSize) \
986 ((USHORT)(sizeof(IRP)+((StackSize)*sizeof(IO_STACK_LOCATION))))
990 * FUNCTION: Dequeues the next IRP from the device's associated queue and
991 * calls its StartIo routine
993 * DeviceObject = Device object
994 * Cancelable = True if IRPs in the queue can be cancelled
999 PDEVICE_OBJECT DeviceObject
,
1004 IoStartNextPacketByKey (
1005 PDEVICE_OBJECT DeviceObject
,
1010 * FUNCTION: Calls the drivers StartIO routine with the IRP or queues it if
1011 * the device is busy
1013 * DeviceObject = Device to pass the IRP to
1014 * Irp = Irp to be processed
1015 * Key = Optional value for where to insert the IRP
1016 * CancelFunction = Entry point for a driver supplied cancel function
1021 PDEVICE_OBJECT DeviceObject
,
1024 PDRIVER_CANCEL CancelFunction
1029 PDEVICE_OBJECT DeviceObject
1034 PDEVICE_OBJECT DeviceObject
1038 IoSynchronousPageWrite (
1052 IoUnregisterFileSystem (
1053 IN PDEVICE_OBJECT DeviceObject
1055 #if (_WIN32_WINNT >= 0x0400)
1058 IoUnregisterFsRegistrationChange (
1062 #endif // (_WIN32_WINNT >= 0x0400)
1065 IoUnregisterShutdownNotification (
1066 PDEVICE_OBJECT DeviceObject
1070 IoUpdateShareAccess (
1071 IN PFILE_OBJECT FileObject
,
1072 IN PSHARE_ACCESS ShareAccess
1077 IN PDEVICE_OBJECT DeviceObject
,
1078 IN BOOLEAN AllowRawMount
1082 IoWriteErrorLogEntry (
1086 * FUNCTION: Sends an irp to the next lower driver
1091 PDEVICE_OBJECT DeviceObject
,
1095 * FUNCTION: Indicates the caller has finished all processing for a given
1096 * I/O request and is returning the given IRP to the I/O manager
1098 * Irp = Irp to be cancelled
1099 * PriorityBoost = Increment by which to boost the priority of the
1100 * thread making the request
1104 IofCompleteRequest (
1109 /* --- EXPORTED BY HAL --- */
1113 IoAssignDriveLetters (
1121 IoFlushAdapterBuffers (
1122 PADAPTER_OBJECT AdapterObject
,
1124 PVOID MapRegisterBase
,
1127 BOOLEAN WriteToDevice
1131 IoFreeAdapterChannel (
1132 PADAPTER_OBJECT AdapterObject
1136 IoFreeMapRegisters (
1137 PADAPTER_OBJECT AdapterObject
,
1138 PVOID MapRegisterBase
,
1139 ULONG NumberOfMapRegisters
1144 PADAPTER_OBJECT AdapterObject
,
1146 PVOID MapRegisterBase
,
1149 BOOLEAN WriteToDevice
1153 IoReadPartitionTable (
1154 PDEVICE_OBJECT DeviceObject
,
1156 BOOLEAN ReturnedRecognizedPartitions
,
1157 struct _DRIVE_LAYOUT_INFORMATION
** PBuffer
1161 IoSetPartitionInformation (
1162 PDEVICE_OBJECT DeviceObject
,
1164 ULONG PartitionNumber
,
1169 IoWritePartitionTable (
1170 PDEVICE_OBJECT DeviceObject
,
1172 ULONG SectorsPerTrack
,
1173 ULONG NumberOfHeads
,
1174 struct _DRIVE_LAYOUT_INFORMATION
* PBuffer
1178 /* --- --- --- INTERNAL or REACTOS ONLY --- --- --- */
1183 * FUNCTION: Registers the driver with WMI
1185 * DeviceObject = Device to register
1186 * Action = Action to take
1187 * RETURNS: Status (?)
1189 //NTSTATUS IoWMIRegistrationControl(DeviceObject, WMIREGACTION Action);
1193 * FUNCTION: Returns a pointer to the callers
1194 * stack location in the irp
1198 IoGetCurrentIrpStackLocation (
1204 IoGetFunctionCodeFromCtlCode (
1213 IoGetNextIrpStackLocation (
1219 IoInitializeDpcRequest (
1220 PDEVICE_OBJECT DeviceObject,
1221 PIO_DPC_ROUTINE DpcRoutine
1226 IoIsErrorUserInduced (
1231 IoIsTotalDeviceFailure (
1235 * FUNCTION: Marks an IRP as pending
1238 * NOTE: If a driver doesn't complete the irp in its dispatch routine it
1239 * must mark it pending otherwise the I/O manager will complete it on
1240 * return from the dispatch routine.
1251 PDEVICE_OBJECT DeviceObject,
1258 IoSetCancelRoutine (
1260 PDRIVER_CANCEL CancelRoutine
1265 IoSetCompletionRoutine (
1267 PIO_COMPLETION_ROUTINE CompletionRoutine,
1269 BOOLEAN InvokeOnSuccess,
1270 BOOLEAN InvokeOnError,
1271 BOOLEAN InvokeOnCancel
1276 IoSetNextIrpStackLocation (
1281 * FUNCTION: Determines the size of an IRP
1283 * StackSize = number of stack locations in the IRP
1284 * RETURNS: The size of the IRP in bytes
1293 // Preliminary guess
1296 IoQueryFileVolumeInformation (
1297 IN PFILE_OBJECT FileObject
,
1298 IN FS_INFORMATION_CLASS FsInformationClass
,
1300 OUT PVOID FsInformation
,
1301 OUT PULONG ReturnedLength
1305 #endif /* ndef _INCLUDE_DDK_IOFUNCS_H */