I am using following function to request oplock but how should I know that I acquired oplock properly??
void GetOplock()
{
HANDLE FileHandle;
REQUEST_OPLOCK_OUTPUT_BUFFER Response;
BOOL bSuccess = FALSE;
BOOL ResultValid = TRUE;
DWORD PartialCheckSum = 0;
DWORD BytesSummedCounter = 0;
HANDLE KeyEvents[2];
OVERLAPPED ReadOverLapped;
LARGE_INTEGER Offset = { 0 };
DWORD RetVal;
//
// Open the file for Asynchronous I/O
//
FileHandle = CreateFile(FilePath,
GENERIC_READ|GENERIC_WRITE,
FILE_SHARE_READ|FILE_SHARE_WRITE,
NULL,
OPEN_EXISTING,
FILE_FLAG_OVERLAPPED,
NULL);
if (INVALID_HANDLE_VALUE == FileHandle) {
_tprintf(_T("Error 0x%x Opening %s\n"), GetLastError(), FilePath);
return;
}
ResetEvent(OplockInfo->OverLapped.hEvent);
bSuccess = DeviceIoControl(FileHandle,
FSCTL_REQUEST_OPLOCK,
&OplockInfo->Request,
sizeof(OplockInfo->Request),
&Response,
sizeof(Response),
NULL,
&OplockInfo->OverLapped);
if (bSuccess == FALSE && ERROR_IO_PENDING == GetLastError())
{
_tprintf(_T("got op"));
return;
}
if (bSuccess || (ERROR_IO_PENDING != GetLastError()))
{
_tprintf(_T("We failed to acquire the oplock, the error code was 0x%x\n"), GetLastError());
CloseHandle(FileHandle);
return;
}
}
I am also using wireshark to check oplock state but not getting oplock state
It is humble request that please give me the proper suggestion to request oplock at user level.
plz provide sample code if possible.