Does fcntl () or something else support 'File Descriptor' specific (& not process specific) byte-range advisory lock with support for shared/exclusive locking in macOS (& also iOS)?

Hello friends,

For our application development on macOS (& also IOS), we need advisory locks which are 'File Descriptor' specific locks and not process specific. It is also important that they should support byte-range locking & shared/exclusive locking. Additionally, the same process can take multiple byte-range locks at the same time to support various combinations. Basically, we want to coordinate between multiple processes reading/writing to the same file simultaneously using advisory locks (byte-range & shared/exclusive). And we want to give flexibility to users to give file paths with all combinations like using ‘soft/hard links’, network shared file paths, etc.

We see that 'fcntl ()' system call comes closest to our
requirement. However, locks taken using standard commands FSETLK/ FGETLK, are process-specific locks & not file descriptor specific lock. That means, assuming one file descriptor has taken a byte lock, on a given file path & is in the middle of doing some operations. Now if we open the same file once again for some reason, do some read/write operation & close it, then the first file descriptor also loses all its locks, even though the second file descriptor has not done anything with the locks.

This is a big problem for us if any file-handle can lose a
file lock in the middle of doing some operation as all our coordination will go
for a toss!

In Linux, thankfully, there is an additional option of using
‘Open File Description Locks’ (non-POSIX) with ‘fcntl ()’. This is done using commands ‘FOFDSETLK/FOFDGETLK’ with ‘fcntl ()’ system call. However, we couldn’t find similar support in macOS/IOS. We also explored other lock types as well: flock () & lockf (). But both do not serve our entire purpose as stated above.

Could you please guide me, if there is any way, we can achieve byte-range advisory locking which supports shared/exclusive locking as well as which is file descriptor specific locks & not process-specific lock?

macOS has OFD locks with fcntl, which perform the same as in Linux.

Does fcntl () or something else support 'File Descriptor' specific (& not process specific) byte-range advisory lock with support for shared/exclusive locking in macOS (& also iOS)?
 
 
Q