LOCKDEV(8)

πŸ’– LOCKDEV(8) β€” the manual, but make it make sense πŸ’–

okay bestie, sit down, we're learning lockdev and it's actually gonna be fun.

So lockdev is a setgid binary β€” yes, setgid, we love a permission moment β€” and what it gives you is a reliable way to put an exclusive lock in /var/lock on your devices (think ttyS0 and its little friends) using both the FSSTND and the SVr4 methods. And because of that, regular users don't need write access in /var/lock. no cap, that's the whole point. πŸŽ€

And how does it pull this off? Through calls to the liblockdev(3) API. she's built different, fr fr.


✨ SYNOPSIS ✨

/usr/sbin/lockdev [<operation>] <device>

🌸 DESCRIPTION 🌸

So the lockdev command can do one of the following operations (and all of them are calls to the liblockdev(3) API, iykyk):

  • -l β€” lock the device, using the dev_lock() function πŸ”’
  • -u β€” unlock the device, using the dev_unlock() function πŸ”“
  • no operation β€” just test the lock, using the dev_testlock() function πŸ‘€

πŸ‘‘ RETURN VALUES πŸ‘‘

exit codes!! and bestie they MATTER, so here's the full vibe check:

  • 0 β€” dev_lock: OK ✨ β€” dev_unlock: OK ✨ β€” dev_testlock: not locked
  • 1 β€” dev_lock: locked other β€” dev_unlock: locked other β€” dev_testlock: locked
  • 2 β€” EACCES
  • 3 β€” EROFS
  • 4 β€” EFAULT
  • 5 β€” EINVAL
  • 6 β€” ENAMETOOLONG
  • 7 β€” ENOENT
  • 8 β€” ENOTDIR
  • 9 β€” ENOMEM
  • 10 β€” ELOOP
  • 11 β€” EIO
  • 12 β€” EPERM
  • 255 β€” dev_lock: error β€” dev_unlock: error β€” dev_testlock: error πŸ’€
not me reading 255 three times like it's gonna change. it doesn't. error is error, bestie. 😭

πŸ¦‹ SEE ALSO πŸ¦‹


okay that's the page!! this one is dated SEPTEMBER 2009 and it lives in the LOCKDEV(8) manual β€” iconic of her honestly. go forth and lock your devices responsibly. mwah πŸ’…πŸ«Ά