strmode(3bsd)

πŸ“¦
version 0.12.2 Β· 2 versions
  • 0.12.2 Β· alpine 3.22, alpine 3.23, alpine 3.24, arch rolling, debian bookworm, debian trixie, epel 10, epel 9, fedora 43, fedora 44, nixos 26.05, opensuse-leap 16.0, ubuntu noble, ubuntu questing, ubuntu resolute, ubuntu stonking (latest)
  • 0.11.5 Β· ubuntu jammy
, in alpine 3.22, alpine 3.23, alpine 3.24, arch rolling, debian bookworm, debian trixie, epel 10, epel 9, fedora 43, fedora 44, nixos 26.05, opensuse-leap 16.0, ubuntu noble, ubuntu questing, ubuntu resolute, ubuntu stonking

✨ strmode β€” bestie we're turning inode status into a cute lil string πŸ’…

okay so this one's from the Utility functions from BSD systems collection, a.k.a. libbsd, and you link it with -lbsd. she's a libbsd girlie, not a glibc one, iykyk 🫢


🌸 SYNOPSIS 🌸

#include <string.h>
(See libbsd(7) for include usage.)

void
strmode(mode_t mode, char *bp);
heads up bestie: peep libbsd(7) for how the include actually goes, it's got lore πŸ’–

πŸŽ€ DESCRIPTION πŸŽ€

so strmode() takes a file mode β€” that's the type + permission info that lives on an inode, like what stat(2) gives you β€” and it converts it into a symbolic string, which it stores at the location bp points to. that string is eleven characters long, plus a trailing NUL. no cap, exactly eleven. 🌈

The first character is the inode type, and it's gonna be one of these iconic lil guys:

  • - β€” regular file
  • b β€” block special
  • c β€” character special
  • d β€” directory
  • l β€” symbolic link
  • p β€” fifo
  • s β€” socket
  • w β€” whiteout
  • ? β€” unknown inode type

πŸ¦‹ the next nine characters (the permission part) πŸ¦‹

the next nine characters encode three sets of permissions, three characters each:

  1. the first three = permissions for the owner of the file
  2. the second three = permissions for the group the file belongs to
  3. the third three = permissions for the other, a.k.a. the default set of users
and permission checking is done as specifically as possible, fr fr. if read permission is denied to the owner in that first set, then the owner genuinely cannot read the file. that's true even if the owner is in the file's group and the group perms allow reading, or the other perms allow reading. owner set wins. periodt. πŸ’€

here's the breakdown of each character in a set:

  • first character of the set: an r means the file is readable for that set of users; a dash - means it's not readable πŸ™ˆ
  • second character of the set: a w means the file is writable for that set of users; a dash - means it's not writable
  • third character: it's the first one of the following that applies ⬇️
  • S β€” if the character is part of the owner permissions and the file is not executable (or the directory is not searchable by the owner), and the set-user-id bit is set
  • S β€” if the character is part of the group permissions and the file is not executable (or the directory is not searchable by the group), and the set-group-id bit is set
  • T β€” if the character is part of the other permissions and the file is not executable (or the directory is not searchable by others), and the sticky (S_ISVTX) bit is set
  • s β€” if the character is part of the owner permissions and the file is executable (or the directory is searchable by the owner), and the set-user-id bit is set
  • s β€” if the character is part of the group permissions and the file is executable (or the directory is searchable by the group), and the set-group-id bit is set
  • t β€” if the character is part of the other permissions and the file is executable (or the directory is searchable by others), and the sticky (S_ISVTX) bit is set
  • x β€” the file is executable, or the directory is searchable ✨
  • - β€” none of the above apply, sorry babe

πŸ‘‘ the last character πŸ‘‘

the last character is a plus sign + if there are any alternate or additional access control methods associated with the inode β€” otherwise it's just a space. that's the whole vibe check. πŸŽ€


πŸ’œ SEE ALSO πŸ’œ


⭐ HISTORY ⭐

strmode() first appeared in 4.4BSD. a true vintage queen, she's been serving since forever πŸ‘‘


and that's the whole page bestie!! this lil icon dropped from the Debian crew on July 28, 1994 β€” yeah she's older than us and still slaying πŸ’…πŸ«Ά go format some modes, mwah πŸ’–

πŸ“¦ where this page comes from