Share via

WIN API for creating a file without requesting for an oplock

Aviv Rozia 46 Reputation points
2022-06-01T07:09:57.277+00:00

Hi, I have a SMB server that has a limited resources, I am trying to create a test using Windows APIs that creates a deep file tree.
I am looking for a WIN API that creates a file without asking for an oplock upon creation since I would like to create a file and close its handle immediately.
After investigation I found 2 relevant APIs, CreateFile(), which I used until now and CreateFile2() which can get additional flags such as FILE_FLAG_OPEN_REQUIRING_OPLOCK, however when using this API it seems that windows client ignores this flag and the request is the same (batch oplock still exists in the request).
I found a trick to break the oplock by moving/renaming the file after creation, but I am curious if there is any other elegant way or any other API that I can use in order to create a file without asking for an oplock upon request?

Windows development | Windows API - Win32

Answer accepted by question author

Jeanine Zhang-MSFT 11,356 Reputation points Microsoft External Staff
2022-06-02T06:28:09.45+00:00

@Aviv Rozia

According to the Doc: Opportunistic Locks

Typically, file systems implement support for opportunistic locks. Applications generally leave opportunistic lock management to the file system drivers.

As far as I'm concerned, Windows atomaticaly managing opcloks on file system level, and there is no suitable api to create a file without asking for an oplock upon request.

Was this answer helpful?


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.