2

fnctl (https://man7.org/linux/man-pages/man2/fcntl.2.html) supports locking a portion of a file (specified by start position and length).

Behind the scenes, what does the algorithm look like?

I'm primarily looking for information about which lock type(s) it uses, how it uses ranges (does it use a prefix tree?), etc.

1 Answer 1

1

On Linux, the default implementation is provided by posix_lock_inode (each file system can provide its own implementation, I haven’t checked how common that is). The function has a fair number of comments highlighting its various sections, I won’t repeat them here unless you have specific questions. Ranges are coalesced when they overlap, but there isn’t any particularly fancy data structure used to represent all the ranges in a given file.

The locks are stored in linked lists; see struct file_lock_context and struct file_lock_core.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.