🎭 Linux st_mode Calculator


Enter a mask:

Result:


All Flags:

What is it for?

This calculator is for decoding the st_mode mask to a human-readable format. It will be probably be useless to 99.99999% of people. The st_mode flags are defined here: include/uapi/linux/stat.h They are used to define file type and file permissions. It is used (as far as I know) when you read the attributes of a file, and when a new file is created. When you read the attributes of a file a struct stat is returned. This struct contains st_mode.
struct stat {
    dev_t     st_dev;     /* ID of device containing file */
    ino_t     st_ino;     /* inode number */
    mode_t    st_mode;    /* protection */
....

For example we have:
fstat(3, {st_mode=S_IFREG|0644, st_size=5699248, ...}) = 0

which would have an st_mode of 010644, which means it a regular file, with permissions rw-r-r-. The other location it is used is when we open a file for creation:
int open(const char *pathname, int flags, mode_t mode);
int creat(const char *pathname, mode_t mode);
int openat(int dirfd, const char *pathname, int flags, mode_t mode);

The st_mode flag is set to define the permissions of the new file being created. (See the open docs: https://man7.org/linux/man-pages/man2/open.2.html) The st_mode flag will only appear in raw octal when probes are being used, and even then sometimes a pointer to a struct is in the that field instead of actual data (which is annoying). For example when we make this call:
int fd = open("/tmp/test.txt", O_RDWR|O_CREAT);

// it becomes this (or something similiar) in kernel space
int ret = sys_open(path, flags, mode);
  
//which becomes something like when open calls are traced:
test_me-2737    [000] ....  3556.552147: test_probe: (do_sys_open+0x0/0x290) dfd=0xffffffff986daf80 filename="supervise/status.new" flags=0x1ed mode=0xc0273f48ffffffff