IRP_MJ_LOCK_CONTROL

When Sent

The IRP_MJ_LOCK_CONTROL request is sent by the I/O Manager and other operating system components, as well as other kernel-mode drivers.

Operation: File System Drivers

The file system driver should extract and decode the file object to determine whether the target device object is the file system's control device object. If this is the case, the file system driver should complete the IRP as appropriate without processing the lock request.

Otherwise, if the request has been issued on a handle that represents a user file open, the file system driver should perform the operation indicated by the minor function code and complete the IRP. If not, the driver should fail the IRP.

The following are the valid minor function codes:

Code Description

IRP_MN_LOCK

Indicates a byte-range lock request, possibly on behalf of a user-mode application that has called the Microsoft Win32 LockFile function.

IRP_MN_UNLOCK_ALL

Indicates a request to release all byte-range locks for a file, usually because the last outstanding handle to a file object is being closed.

IRP_MN_UNLOCK_ALL_BY_KEY

Indicates a request to release all byte-range locks with a specified key value.

IRP_MN_UNLOCK_SINGLE

Indicates a request to release a single byte-range lock, possibly on behalf of a user-mode application that has called the Microsoft Win32 UnlockFile function.

Operation: File System Filter Drivers

File system filter drivers should pass the IRP down to the next-lower driver on the stack after performing any needed processing.

Parameters

A file system or filter driver calls IoGetCurrentIrpStackLocation with the given IRP to get a pointer to its own stack location in the IRP, shown in the following list as IrpSp. (The IRP is shown as Irp.) The driver can use the information that is set in the following members of the IRP and the IRP stack location in processing a lock control request:

DeviceObject
Pointer to the target device object.

Irp->IoStatus
Pointer to an IO_STATUS_BLOCK structure that receives the final completion status and information about the requested operation.

IrpSp->FileObject
Pointer to the file object that is associated with DeviceObject.

The IrpSp->FileObject parameter contains a pointer to the RelatedFileObject field, which is also a FILE_OBECT structure. The RelatedFileObject field of the FILE_OBJECT structure is not valid during the processing of IRP_MJ_LOCK_CONTROL and should not be used.

IrpSp->Flags
One or more of the following:

Flag Meaning

SL_EXCLUSIVE_LOCK

If this flag is set, an exclusive byte-range lock is requested. Otherwise, a shared lock is requested.

SL_FAIL_IMMEDIATELY

If this flag is set, the lock request should fail if it cannot be granted immediately.

IrpSp->MajorFunction
Specifies IRP_MJ_LOCK_CONTROL.

IrpSp->MinorFunction
Specifies one of the following:

  • IRP_MN_LOCK
  • IRP_MN_UNLOCK_ALL
  • IRP_MN_UNLOCK_ALL_BY_KEY
  • IRP_MN_UNLOCK_SINGLE

IrpSp->Parameters.LockControl.ByteOffset
Starting byte offset within the file of the byte range to be locked or unlocked.

IrpSp->Parameters.LockControl.Key
Key for the byte-range lock.

IrpSp->Parameters.LockControl.Length
Length, in bytes, of the byte range to be locked or unlocked.

See also

FltProcessFileLock

FsRtlProcessFileLock

IO_STACK_LOCATION

IO_STATUS_BLOCK

IoGetCurrentIrpStackLocation

IRP