STRMODE(3)
π
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 filebβ block specialcβ character specialdβ directorylβ symbolic linkpβ fifosβ socketwβ whiteout?β unknown inode type (mystery era π΅οΈ)
the next nine characters π₯
the next nine characters encode three sets of permissions, three characters each:
- the first three = permissions for the owner of the file
- the second three = for the group the file belongs to
- 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 uppercaseS/Tmeans the bit is set but there's no exec/search, and lowercases/tmeans 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
- Copyright (c) 1990, 1991, 1993 The Regents of the University of California. All rights reserved
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms