// wdm.h
typedef struct _IO_STACK_LOCATION {
UCHAR MajorFunction;
UCHAR MinorFunction;
UCHAR Flags;
UCHAR Control;
union {
struct {
PIO_SECURITY_CONTEXT SecurityContext;
ULONG Options;
USHORT POINTER_ALIGNMENT FileAttributes;
USHORT ShareAccess;
ULONG POINTER_ALIGNMENT EaLength;
} Create;
struct {
PIO_SECURITY_CONTEXT SecurityContext;
ULONG Options;
USHORT POINTER_ALIGNMENT Reserved;
USHORT ShareAccess;
PNAMED_PIPE_CREATE_PARAMETERS Parameters;
} CreatePipe;
struct {
PIO_SECURITY_CONTEXT SecurityContext;
ULONG Options;
USHORT POINTER_ALIGNMENT Reserved;
USHORT ShareAccess;
PMAILSLOT_CREATE_PARAMETERS Parameters;
} CreateMailslot;
struct {
ULONG Length;
ULONG POINTER_ALIGNMENT Key;
ULONG Flags;
LARGE_INTEGER ByteOffset;
} Read;
struct {
ULONG Length;
ULONG POINTER_ALIGNMENT Key;
ULONG Flags;
LARGE_INTEGER ByteOffset;
} Write;
struct {
ULONG Length;
PUNICODE_STRING FileName;
FILE_INFORMATION_CLASS FileInformationClass;
ULONG POINTER_ALIGNMENT FileIndex;
} QueryDirectory;
struct {
ULONG Length;
ULONG POINTER_ALIGNMENT CompletionFilter;
} NotifyDirectory;
struct {
ULONG Length;
ULONG POINTER_ALIGNMENT CompletionFilter;
DIRECTORY_NOTIFY_INFORMATION_CLASS POINTER_ALIGNMENT DirectoryNotifyInformationClass;
} NotifyDirectoryEx;
struct {
ULONG Length;
FILE_INFORMATION_CLASS POINTER_ALIGNMENT FileInformationClass;
} QueryFile;
struct {
ULONG Length;
FILE_INFORMATION_CLASS POINTER_ALIGNMENT FileInformationClass;
PFILE_OBJECT FileObject;
union {
struct {
BOOLEAN ReplaceIfExists;
BOOLEAN AdvanceOnly;
};
ULONG ClusterCount;
HANDLE DeleteHandle;
};
} SetFile;
struct {
ULONG Length;
PVOID EaList;
ULONG EaListLength;
ULONG POINTER_ALIGNMENT EaIndex;
} QueryEa;
struct {
ULONG Length;
} SetEa;
struct {
ULONG Length;
FS_INFORMATION_CLASS POINTER_ALIGNMENT FsInformationClass;
} QueryVolume;
struct {
ULONG Length;
FS_INFORMATION_CLASS POINTER_ALIGNMENT FsInformationClass;
} SetVolume;
struct {
ULONG OutputBufferLength;
ULONG POINTER_ALIGNMENT InputBufferLength;
ULONG POINTER_ALIGNMENT FsControlCode;
PVOID Type3InputBuffer;
} FileSystemControl;
struct {
PLARGE_INTEGER Length;
ULONG POINTER_ALIGNMENT Key;
LARGE_INTEGER ByteOffset;
} LockControl;
struct {
ULONG OutputBufferLength;
ULONG POINTER_ALIGNMENT InputBufferLength;
ULONG POINTER_ALIGNMENT IoControlCode;
PVOID Type3InputBuffer;
} DeviceIoControl;
struct {
SECURITY_INFORMATION SecurityInformation;
ULONG POINTER_ALIGNMENT Length;
} QuerySecurity;
struct {
SECURITY_INFORMATION SecurityInformation;
PSECURITY_DESCRIPTOR SecurityDescriptor;
} SetSecurity;
struct {
PVPB Vpb;
PDEVICE_OBJECT DeviceObject;
ULONG OutputBufferLength;
} MountVolume;
struct {
PVPB Vpb;
PDEVICE_OBJECT DeviceObject;
} VerifyVolume;
struct {
struct _SCSI_REQUEST_BLOCK *Srb;
} Scsi;
struct {
ULONG Length;
PSID StartSid;
PFILE_GET_QUOTA_INFORMATION SidList;
ULONG SidListLength;
} QueryQuota;
struct {
ULONG Length;
} SetQuota;
struct {
DEVICE_RELATION_TYPE Type;
} QueryDeviceRelations;
struct {
const GUID *InterfaceType;
USHORT Size;
USHORT Version;
PINTERFACE Interface;
PVOID InterfaceSpecificData;
} QueryInterface;
struct {
PDEVICE_CAPABILITIES Capabilities;
} DeviceCapabilities;
struct {
PIO_RESOURCE_REQUIREMENTS_LIST IoResourceRequirementList;
} FilterResourceRequirements;
struct {
ULONG WhichSpace;
PVOID Buffer;
ULONG Offset;
ULONG POINTER_ALIGNMENT Length;
} ReadWriteConfig;
struct {
BOOLEAN Lock;
} SetLock;
struct {
BUS_QUERY_ID_TYPE IdType;
} QueryId;
struct {
DEVICE_TEXT_TYPE DeviceTextType;
LCID POINTER_ALIGNMENT LocaleId;
} QueryDeviceText;
struct {
BOOLEAN InPath;
BOOLEAN Reserved[3];
DEVICE_USAGE_NOTIFICATION_TYPE POINTER_ALIGNMENT Type;
} UsageNotification;
struct {
SYSTEM_POWER_STATE PowerState;
} WaitWake;
struct {
PPOWER_SEQUENCE PowerSequence;
} PowerSequence;
#if ...
struct {
union {
ULONG SystemContext;
SYSTEM_POWER_STATE_CONTEXT SystemPowerStateContext;
};
POWER_STATE_TYPE POINTER_ALIGNMENT Type;
POWER_STATE POINTER_ALIGNMENT State;
POWER_ACTION POINTER_ALIGNMENT ShutdownType;
} Power;
#else
struct {
ULONG SystemContext;
POWER_STATE_TYPE POINTER_ALIGNMENT Type;
POWER_STATE POINTER_ALIGNMENT State;
POWER_ACTION POINTER_ALIGNMENT ShutdownType;
} Power;
#endif
struct {
PCM_RESOURCE_LIST AllocatedResources;
PCM_RESOURCE_LIST AllocatedResourcesTranslated;
} StartDevice;
struct {
ULONG_PTR ProviderId;
PVOID DataPath;
ULONG BufferSize;
PVOID Buffer;
} WMI;
struct {
PVOID Argument1;
PVOID Argument2;
PVOID Argument3;
PVOID Argument4;
} Others;
} Parameters;
PDEVICE_OBJECT DeviceObject;
PFILE_OBJECT FileObject;
PIO_COMPLETION_ROUTINE CompletionRoutine;
PVOID Context;
} IO_STACK_LOCATION, *PIO_STACK_LOCATION;
View the official Windows Driver Kit DDI referenceNo description available.
The IO_STACK_LOCATION structure defines an I/O stack location, which is an entry in the I/O stack that is associated with each IRP. Each I/O stack location in an IRP has some common members and some request-type-specific members.
MajorFunctionThe IRP major function code indicating the type of I/O operation to be performed.
MinorFunctionA subfunction code for MajorFunction. The PnP manager, the power manager, file system drivers, and SCSI class drivers set this member for some requests.
FlagsRequest-type-specific values used almost exclusively by file system drivers. Removable-media device drivers check whether this member is set with SL_OVERRIDE_VERIFY_VOLUME for read requests to determine whether to continue the read operation even if the device object's Flags is set with DO_VERIFY_VOLUME. Intermediate drivers layered over a removable-media device driver must copy this member into the I/O stack location of the next-lower driver in all incoming IRP_MJ_READ requests.
For documentation of other SL_* flags for IRP_MJ_CREATE, see IRP_MJ_CREATE (IFS).
Possible flag values include:
| Flag | Value | Description |
|---|---|---|
| SL_KEY_SPECIFIED | 0x01 |
Indicates that the IO_STACK_LOCATION.Parameters.Read(OrWrite).Key contains which copy of a given sector should be read when redundancy is enabled. Today this flag is use only with IRP_MJ_READ operations. |
| SL_OVERRIDE_VERIFY_VOLUME | 0x02 |
This flag is used to determine whether to continue the read operation even if the device object's Flags is set with DO_VERIFY_VOLUME. |
| SL_WRITE_THROUGH | 0x04 |
This flag informs the storage driver to set appropriate flags so that the disk bypasses the write cache in order to force the disk to write through to its persistent storage media. This flag is device-specific; not all disk drives support bypassing disk-cache. |
| SL_FT_SEQUENTIAL_WRITE | 0x08 |
Reserved for system use. |
| SL_FORCE_DIRECT_WRITE | 0x10 |
This flag lets kernel-mode drivers write to volume areas that they normally cannot write to because of blocking direct write in the file system and storage driver stack. Direct write blocking helps improve security. This flag is checked both at the file system layer and storage stack layer. For more information about direct write blocking, see Blocking Direct Write Operations to Volumes and Disks. |
| SL_REALTIME_STREAM | 0x20 |
This flag hints that the IO is for real-time streaming requests to a CD-ROM class driver. This hints the driver to perform READ/WRITE operations at a guaranteed speed for real-time streaming. This flag is valid only with optical media. |
| SL_PERSISTENT_MEMORY_FIXED_MAPPING | 0x20 |
The persistent memory mapping of the bytes in the write request cannot change while handling this write request. This flag is valid only with a persistent memory device and IRP_MJ_WRITE. |
For persistent memory devices, one of the reasons for remapping (modifying the physical address of a given LBA) on persistent memory devices is to provide efficient sector level atomicity. If the flag is not set, remapping is allowed especially if it results in the driver providing sector atomicity. File systems (or the requester) prefer that a persistent memory device driver provides sector atomicity. If the flag is set, a persistent memory driver shall not remap the physical addresses corresponding to the LBAs. If that means sector atomicity can't be provided, so be it. However, the driver is more than welcome to provide sector atomicity as long as there is no remapping.
ControlDrivers can check this member to determine whether it is set with SL_PENDING_RETURNED and under what conditions the CompletionRoutine is called. Drivers have read-only access to this member. Drivers call IoSetCompletionRoutine or IoSetCompletionRoutineEx to specify these conditions.
ParametersA union that depends on the major and minor IRP function code values contained in MajorFunction and MinorFunction. The following table shows which IRPs use the individual members of the Parameters union.
| Member name | IRPs that use this member |
|---|---|
| Create | IRP_MJ_CREATE |
| Read | IRP_MJ_READ |
| Write | IRP_MJ_WRITE |
| QueryFile | IRP_MJ_QUERY_INFORMATION |
| SetFile | IRP_MJ_SET_INFORMATION |
| QueryVolume | IRP_MJ_QUERY_VOLUME_INFORMATION |
| DeviceIoControl | IRP_MJ_DEVICE_CONTROL and IRP_MJ_INTERNAL_DEVICE_CONTROL |
| MountVolume | IRP_MN_MOUNT_VOLUME |
| VerifyVolume | IRP_MN_VERIFY_VOLUME |
| Scsi | IRP_MJ_INTERNAL_DEVICE_CONTROL (SCSI) |
| QueryDeviceRelations | IRP_MN_QUERY_DEVICE_RELATIONS |
| QueryInterface | IRP_MN_QUERY_INTERFACE |
| DeviceCapabilities | IRP_MN_QUERY_CAPABILITIES |
| FilterResourceRequirements | IRP_MN_FILTER_RESOURCE_REQUIREMENTS |
| ReadWriteConfig | IRP_MN_READ_CONFIG and IRP_MN_WRITE_CONFIG |
| SetLock | IRP_MN_SET_LOCK |
| QueryId | IRP_MN_QUERY_ID |
| QueryDeviceText | IRP_MN_QUERY_DEVICE_TEXT |
| UsageNotification | IRP_MN_DEVICE_USAGE_NOTIFICATION |
| WaitWake | IRP_MN_WAIT_WAKE |
| PowerSequence | IRP_MN_POWER_SEQUENCE |
| Power | IRP_MN_SET_POWER and IRP_MN_QUERY_POWER |
| StartDevice | IRP_MN_START_DEVICE |
| WMI | WMI minor IRPs |
| Others | Driver-specific IRPs |
For more information, see IRP Major Function Codes.
Parameters.CreateSystem service parameters for NtCreateFile.
Parameters.Create.SecurityContextParameters.Create.OptionsParameters.Create.FileAttributesParameters.Create.ShareAccessParameters.Create.EaLengthParameters.CreatePipeSystem service parameters fo NtCreateNamedPipeFile.
Parameters.CreatePipe.SecurityContextParameters.CreatePipe.OptionsParameters.CreatePipe.ReservedParameters.CreatePipe.ShareAccessParameters.CreatePipe.ParametersParameters.CreateMailslotSystem service parameters for NtCreateMailslotFile.
Parameters.CreateMailslot.SecurityContextParameters.CreateMailslot.OptionsParameters.CreateMailslot.ReservedParameters.CreateMailslot.ShareAccessParameters.CreateMailslot.ParametersParameters.ReadSystem service parameters for NtReadFile.
Parameters.Read.LengthParameters.Read.KeyParameters.Read.FlagsParameters.Read.ByteOffsetParameters.WriteSystem service parameters for NtWriteFile.
Parameters.Write.LengthParameters.Write.KeyParameters.Write.FlagsParameters.Write.ByteOffsetParameters.QueryDirectorySystem service parameters for NtQueryDirectoryFile.
Parameters.QueryDirectory.LengthParameters.QueryDirectory.FileNameParameters.QueryDirectory.FileInformationClassParameters.QueryDirectory.FileIndexParameters.NotifyDirectorySystem service parameters for NtNotifyChangeDirectoryFile.
Parameters.NotifyDirectory.LengthParameters.NotifyDirectory.CompletionFilterParameters.NotifyDirectoryExSystem service parameters for NtNotifyChangeDirectoryFileEx.
Parameters.NotifyDirectoryEx.LengthParameters.NotifyDirectoryEx.CompletionFilterParameters.NotifyDirectoryEx.DirectoryNotifyInformationClassParameters.QueryFileSystem service parameters for NtQueryInformationFile.
Parameters.QueryFile.LengthParameters.QueryFile.FileInformationClassParameters.SetFileSystem service parameters for NtSetInformationFile.
Parameters.SetFile.LengthParameters.SetFile.FileInformationClassParameters.SetFile.FileObjectParameters.SetFile.ReplaceIfExistsParameters.SetFile.AdvanceOnlyParameters.SetFile.ClusterCountParameters.SetFile.DeleteHandleParameters.QueryEaSystem service parameters for NtQueryEaFile.
Parameters.QueryEa.LengthParameters.QueryEa.EaListParameters.QueryEa.EaListLengthParameters.QueryEa.EaIndexParameters.SetEaSystem service parameters for NtSetEaFile.
Parameters.SetEa.LengthParameters.QueryVolumeSystem service parameters for NtQueryVolumeInformationFile.
Parameters.QueryVolume.LengthParameters.QueryVolume.FsInformationClassParameters.SetVolumeSystem service parameters for NtSetVolumeInformationFile.
Parameters.SetVolume.LengthParameters.SetVolume.FsInformationClassParameters.FileSystemControlSystem service parameters for NtFsControlFile.
Parameters.FileSystemControl.OutputBufferLengthParameters.FileSystemControl.InputBufferLengthParameters.FileSystemControl.FsControlCodeParameters.FileSystemControl.Type3InputBufferParameters.LockControlSystem service parameters for LockFile/NtUnlockFile.
Parameters.LockControl.LengthParameters.LockControl.KeyParameters.LockControl.ByteOffsetParameters.DeviceIoControlSystem service parameters for NtDeviceIoControlFile.
Parameters.DeviceIoControl.OutputBufferLengthParameters.DeviceIoControl.InputBufferLengthParameters.DeviceIoControl.IoControlCodeParameters.DeviceIoControl.Type3InputBufferParameters.QuerySecuritySystem service parameters for NtQuerySecurityObject.
Parameters.QuerySecurity.SecurityInformationParameters.QuerySecurity.LengthParameters.SetSecuritySystem service parameters for NtSetSecurityObject.
Parameters.SetSecurity.SecurityInformationParameters.SetSecurity.SecurityDescriptorParameters.MountVolumeSystem service parameters for MountVolume.
Parameters.MountVolume.VpbParameters.MountVolume.DeviceObjectParameters.MountVolume.OutputBufferLengthParameters.VerifyVolumeSystem service parameters for VerifyVolume.
Parameters.VerifyVolume.VpbParameters.VerifyVolume.DeviceObjectParameters.ScsiParameters for Scsi with internal device control.
Parameters.Scsi.SrbParameters.QueryQuotaSystem service parameters for NtQueryQuotaInformationFile.
Parameters.QueryQuota.LengthParameters.QueryQuota.StartSidParameters.QueryQuota.SidListParameters.QueryQuota.SidListLengthParameters.SetQuotaSystem service parameters for NtSetQuotaInformationFile.
Parameters.SetQuota.LengthParameters.QueryDeviceRelationsParameters for IRP_MN_QUERY_DEVICE_RELATIONS.
Parameters.QueryDeviceRelations.TypeParameters.QueryInterfaceParameters for IRP_MN_QUERY_INTERFACE.
Parameters.QueryInterface.InterfaceTypeParameters.QueryInterface.SizeParameters.QueryInterface.VersionParameters.QueryInterface.InterfaceParameters.QueryInterface.InterfaceSpecificDataParameters.DeviceCapabilitiesParameters for IRP_MN_QUERY_CAPABILITIES.
Parameters.DeviceCapabilities.CapabilitiesParameters.FilterResourceRequirementsParameters for IRP_MN_FILTER_RESOURCE_REQUIREMENTS.
Parameters.FilterResourceRequirements.IoResourceRequirementListParameters.ReadWriteConfigParameters for IRP_MN_READ_CONFIG and IRP_MN_WRITE_CONFIG.
Parameters.ReadWriteConfig.WhichSpaceParameters.ReadWriteConfig.BufferParameters.ReadWriteConfig.OffsetParameters.ReadWriteConfig.LengthParameters.SetLockParameters for IRP_MN_SET_LOCK.
Parameters.SetLock.LockParameters.QueryIdParameters for IRP_MN_QUERY_ID.
Parameters.QueryId.IdTypeParameters.QueryDeviceTextParameters for IRP_MN_QUERY_DEVICE_TEXT.
Parameters.QueryDeviceText.DeviceTextTypeParameters.QueryDeviceText.LocaleIdParameters.UsageNotificationParameters for IRP_MN_DEVICE_USAGE_NOTIFICATION.
Parameters.UsageNotification.InPathParameters.UsageNotification.Reserved[3]Parameters.UsageNotification.TypeParameters.WaitWakeParameters for IRP_MN_WAIT_WAKE.
Parameters.WaitWake.PowerStateParameters.PowerSequenceParameter for IRP_MN_POWER_SEQUENCE.
Parameters.PowerSequence.PowerSequenceParameters.Power.SystemPowerStateContextParameters.PowerParameters for IRP_MN_SET_POWER and IRP_MN_QUERY_POWER.
Parameters.Power.SystemContextParameters.Power.TypeParameters.Power.StateParameters.Power.ShutdownTypeParameters.StartDeviceParameters for StartDevice.
Parameters.StartDevice.AllocatedResourcesParameters.StartDevice.AllocatedResourcesTranslatedParameters.WMIParameters for WMI IRPs.
Parameters.WMI.ProviderIdParameters.WMI.DataPathParameters.WMI.BufferSizeParameters.WMI.BufferParameters.OthersParameters for other driver-specific operations.
Parameters.Others.Argument1Parameters.Others.Argument2Parameters.Others.Argument3Parameters.Others.Argument4DeviceObjectA pointer to the driver-created DEVICE_OBJECT structure representing the target physical, logical, or virtual device for which this driver is to handle the IRP.
FileObjectA pointer to a FILE_OBJECT structure that represents the file object, if any, that is associated with DeviceObject pointer.
CompletionRoutineThe completion routine that is invoked depending on the flags in the Control field of this structure.
ContextDriver-defined context that is used to store the address of the context parameter that is passed to the CompletionRoutine.
For each IRP, there is one IO_STACK_LOCATION structure for each driver in a driver stack. Each IRP's set of I/O stack locations is appended to the IRP, following the IRP structure.
Every higher-level driver is responsible for setting up the I/O stack location for the next-lower driver in each IRP. A driver must call IoGetCurrentIrpStackLocation to get a pointer to its own stack location for each IRP. Higher-level drivers can call IoGetNextIrpStackLocation to get a pointer to the next-lower driver's stack location.
The higher-level driver must set up the stack location contents before calling IoCallDriver to pass an IRP to the lower-level driver. If the driver will pass the input IRP on to the next lower-level driver, the dispatch routine should call IoSkipCurrentIrpStackLocation or IoCopyCurrentIrpStackLocationToNext to set up the I/O stack location of the next-lower driver.
A higher-level driver's call to IoCallDriver sets the DeviceObject member to the next-lower-level driver's target device object, in the I/O stack location of the lower driver. The I/O manager passes each higher-level driver's IoCompletion routine a pointer to its own device object when the IoCompletion routine is called on completion of the IRP.
If a higher-level driver allocates IRPs to make requests of its own, its IoCompletion routine is passed a NULL DeviceObject pointer if that driver neither allocates a stack location for itself nor sets up the DeviceObject pointer in its own stack location of the newly allocated IRP.
In some cases, a higher-level driver layered over a mass-storage device driver is responsible for splitting up large transfer requests for the underlying device driver. In particular, SCSI class drivers must check the Parameters.Read.Length and Parameters.Write.Length, determine whether the size of the requested transfer exceeds the underlying HBA's transfer capabilities, and, if so, split the Length of the original request into a sequence of partial transfers to satisfy the original IRP.
IoCopyCurrentIrpStackLocationToNext