Requests an opportunistic lock (oplock) on a file and acknowledges that an oplock break has occurred.

To perform this operation, call the DeviceIoControl function using the following parameters.

BOOL DeviceIoControl( (HANDLE) hDevice,              // handle to file
                     FSCTL_REQUEST_OPLOCK,          // dwIoControlCode
                     (LPVOID) lpInBuffer,           // input buffer
                     (DWORD) nInBufferSize,         // size of input buffer
                     (LPVOID) lpOutBuffer,          // output buffer
                     (DWORD) nOutBufferSize,        // size of output buffer
                     (LPDWORD) lpBytesReturned,     // number of bytes returned
                     (LPOVERLAPPED) lpOverlapped ); // OVERLAPPED structure



A handle to the file or alternate stream for which the opportunistic lock is requested. To retrieve a handle, call the CreateFile function. The file or alternate stream must have been opened with the flag FILE_FLAG_OVERLAPPED.


The control code for the operation. Use FSCTL_REQUEST_OPLOCK for this operation.


A pointer to a buffer that contains a REQUEST_OPLOCK_INPUT_BUFFER structure.


The size of the input buffer, in bytes.


A pointer to a buffer that receives a REQUEST_OPLOCK_OUTPUT_BUFFER structure.


The size of the output buffer, in bytes.


A pointer to a variable that receives the size of the data stored in the output buffer, in bytes.

This parameter is meaningless until the overlapped operation has completed. To retrieve the number of bytes returned, call GetOverlappedResult. If hDevice is associated with an I/O completion port, you can retrieve the number of bytes returned by calling GetQueuedCompletionStatus.


A pointer to an OVERLAPPED structure.

Because hDevice was opened with the FILE_FLAG_OVERLAPPED flag, the operation is performed as an overlapped (asynchronous) operation. Therefore, lpOverlapped must point to a valid OVERLAPPED structure that contains a handle to an event object. Otherwise, the function fails in unpredictable ways.

DeviceIoControl returns immediately, and the event object is signaled when the operation has been completed.

Return value

If the operation completes successfully, DeviceIoControl returns a nonzero value. To determine if the opportunistic lock is granted, call GetLastError. The code ERROR_IO_PENDING indicates that the opportunistic lock was granted. Any other code indicates that the request was denied.

If the operation fails or is pending, DeviceIoControl returns zero. To get extended error information, call GetLastError.


This operation is used only by client applications requesting an opportunistic lock (oplock) from a local server. Client applications requesting opportunistic locks from remote servers must not request them directly—the network redirector transparently requests opportunistic locks for the application. An attempt to use this operation to request opportunistic locks from remote servers will result in the request being denied.

The FSCTL_REQUEST_OPLOCK control code provides more efficient functionality than the following related control codes: FSCTL_REQUEST_OPLOCK_LEVEL_1, FSCTL_REQUEST_OPLOCK_LEVEL_2, FSCTL_REQUEST_FILTER_OPLOCK, and FSCTL_REQUEST_BATCH_OPLOCK. Requesting different oplock levels can be performed repeatedly on the same handle without closing and reopening the handle when using FSCTL_REQUEST_OPLOCK; the other control codes require that the handle be closed and then reopened with CreateFile to make such a change. This is accomplished by manipulating the RequestedOplockLevel member of the REQUEST_OPLOCK_INPUT_BUFFER structure when re-issuing the FSCTL_REQUEST_OPLOCK control code.

The following table summarizes how the caching ability of oplock types available from FSCTL_REQUEST_OPLOCK correspond to the level 2, level 1, and batch oplocks.

Alternative control codeEquivalent RequestedOplockLevel flags valueOplock type


Using the FSCTL_REQUEST_OPLOCK control code with the RequestedOplockLevel member set to OPLOCK_LEVEL_CACHE_READ | OPLOCK_LEVEL_CACHE_HANDLE grants an oplock of type RH. An RH oplock is similar to the filter oplock granted by the FSCTL_REQUEST_FILTER_OPLOCK control code. However, note that the filter oplock allows only one client to hold an oplock on a file at a time; FSCTL_REQUEST_OPLOCK allows multiple clients at a time to have the RH lock on a file. Another difference is that FSCTL_REQUEST_FILTER_OPLOCK requires an oplock break acknowledgment before writes can occur, where FSCTL_REQUEST_OPLOCK does not because the oplock break notification is advisory-only and writes are allowed to go ahead without acknowledgment. For more information, see Breaking Oplocks.

An FSCTL_REQUEST_OPLOCK control code fails if the file is opened in non-overlapped (synchronous) mode.

For the implications of overlapped I/O on this operation, see the Remarks section of the DeviceIoControl topic.

In Windows 8 and Windows Server 2012, this code is supported by the following technologies.


Server Message Block (SMB) 3.0 protocol


SMB 3.0 Transparent Failover (TFO)


SMB 3.0 with Scale-out File Shares (SO)


Cluster Shared Volume File System (CsvFS)


Resilient File System (ReFS)



Also, beginning in Windows 8 and Windows Server 2012, the FSCTL_REQUEST_OPLOCK control code can be used to request an oplock on a directory as well as a file. An oplock request on a directory may specify either OPLOCK_LEVEL_CACHE_READ or OPLOCK_LEVEL_CACHE_READ | OPLOCK_LEVEL_CACHE_HANDLE in the RequestedOplockLevel member.

An R or RH oplock on a directory breaks to None when the contents of an enumeration of the directory would change. For example, adding/deleting a file in the directory, changing the size of a file in the directory, modifying the timestamp of a file in the directory, etc., would all break the oplock on the directory. This oplock break does not require an acknowledgment before the changes in the directory may occur; it is advisory-only.

An RH oplock on a directory breaks to R when the directory itself is renamed or deleted. This oplock break does require an acknowledgment before the change to the directory can occur.


Minimum supported client

Windows 7 [desktop apps only]

Minimum supported server

Windows Server 2008 R2 [desktop apps only]


WinIoCtl.h (include Windows.h)

See also

Oplock Semantics
Opportunistic Locks