STRMODE(3)

πŸ“¦
version 15.1 Β· 2 versions
, in freebsd 15.1

πŸ’… STRMODE(3) β€” the strmode glow-up, bestie

okay so real talk: this is the strmode page from the library functions manual (section 3, the libc girlies). it's the function that turns your boring numbers into that iconic -rwxr-xr-x string. let's get into it 🫢


✨ LIBRARY ✨

Standard C Library β€” aka libc, link it with -lc. it's giving foundation, it's giving everywhere, you don't gotta hunt for it πŸ’–


πŸŽ€ SYNOPSIS πŸŽ€

#include <string.h>

void
strmode(mode_t mode, char *bp);

that's it. two args, no return value. she doesn't return anything because the string itself is the whole point, periodt ✨


🌸 DESCRIPTION 🌸

so strmode() takes a file mode β€” y'know, the type + permission info that lives on an inode, see stat(2) if you're nosy β€” and converts it into a symbolic string. where does it go? into the location referenced by bp. and bestie, that stored string is eleven characters long, plus a trailing NUL at the end. don't forget the NUL, the NUL is load-bearing 😭

the first character πŸ’«

the first char is the inode type, and it's gonna be one of these:

  • - β€” regular file
  • b β€” block special
  • c β€” character special
  • d β€” directory
  • l β€” symbolic link
  • p β€” fifo
  • s β€” socket
  • w β€” whiteout
  • ? β€” unknown inode type (mystery era πŸ•΅οΈ)

the next nine characters πŸ”₯

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 = for the group the file belongs to
  3. the third three = for the "other", or default, set of users
🚨 important vibe check: permission checking is done as specifically as possible. if read permission is denied to the owner of a file in that first set of permissions, the owner will not be able to read the file. yes, even if the owner is in the file's group and the group permissions allow reading β€” even if the "other" permissions allow reading too. specificity wins, always, no cap πŸ’…

character one of each trio πŸ“

if the first character of the three-character set is r, the file is readable for that set of users. if it's a dash -, it is not readable. simple as that πŸ¦‹

character two of each trio 🌈

if the second character of the three-character set is w, the file is writable for that set of users. if it's a dash -, it is not writable. slay 🌟

character three of each trio πŸ‘‘

the third character is the first of the following that applies β€” order matters, iykyk:

  • S β€” when this 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 β€” when this 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 β€” when this 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 β€” when this 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 β€” when this 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 β€” when this 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. go off πŸƒβ€β™€οΈ
  • - β€” none of the above apply. it's giving nothing, honestly πŸ’€
πŸ’‘ notice how uppercase S / T means the bit is set but there's no exec/search, and lowercase s / t means the bit is set and there is? that's the whole trick, bestie, that's the lore 🧚

the last character ⭐

the last character will always be a space. always. she said what she said.


πŸ¦‹ SEE ALSO πŸ¦‹

go read those next, they're all icon behavior ✨


πŸ’œ HISTORY πŸ’œ

the strmode() function first appeared in 4.4BSD. a true legend, a main character from day one πŸ‘‘


and that's the page!! mwah πŸ’‹ this lil translation was brought to you by Debian, dated July 28, 1994 β€” yeah she's vintage, she's archival, she's still serving πŸŽ€πŸ’–

πŸ“¦ where this page comes from
  • freebsd 15.1: base 15.1
  • πŸ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms