vfs_test_lock(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… vfs_test_lock β€” Kernel API Manual ✨

okay so bestie, today we're learning about vfs_test_lock(9). it's giving "peek at the lock without touching it" energy and honestly? iconic. πŸŽ€


🌸 NAME 🌸

vfs_test_lock β€” test file byte range lock πŸ”’βœ¨


πŸ¦‹ SYNOPSIS πŸ¦‹

int vfs_test_lock (struct file *filp , struct file_lock *fl );

πŸ’– ARGUMENTS πŸ’–

  • filp β€” the file you wanna test the lock on, periodt 🫢
  • fl β€” the byte-range in the file you're testing; it also gets used to hold the result, so it's like doing double duty (main character energy fr fr) πŸ’…

🌈 DESCRIPTION 🌈

okay so on entry, fl does not contain a lock β€” like, it's empty, it's just vibing and holding a description. it identifies a range (fl_start, fl_end) in the file (c.flc_file), plus an owner (c.flc_owner) for whom existing locks should be ignored πŸ™ˆ. also c.flc_type and c.flc_flags are ignored β€” literally not important, don't even worry about them bestie πŸ’€.

both fl_lmops and fl_ops in fl must be NULL. no cap. ⭐

it returns -ERRNO on failure 😭. and it shows there's a conflicting lock by setting fl->fl_type to something other than F_UNLCK β€” that's the little tell, iykyk πŸ‘‘

🚨 big sister warning 🚨: if vfs_test_lock does find a lock and return it, the caller must use locks_free_lock or locks_release_private on the returned lock. like, you have to, it's not optional, don't leave it hanging πŸ«₯πŸ’œ

πŸ”₯ SEE ALSO πŸ”₯

kernel file ./fs/locks.c plus this whole squad right here πŸ‘‡ (besties, all of them):


βœ¨πŸ’… and that's the whole page, bestie! it's from the ./fs source, dated October 2026, page name vfs_test_lock(9) β€” slay, go test some locks responsibly πŸŽ€πŸ¦‹πŸ’–

πŸ“¦ where this page comes from