What are the final 3 bits in the UNIX permission mode bits

filesfilesystemsinodepermissions

I understand there are 12 permission bits of which there are 3 groups of 3 bits for each of user, group, and others, which are RWX respectively. RW are read and write, but for X is search for directories and execute for files.

Here is what I don't get:

  1. What are the 3 remaining mode bits and are they all stored in the inode?

  2. I know the file directory itself is considered a file as well, since all things in UNIX are files (is this true?), but since UNIX systems use ACL to represent the file system, then the file system is a list of filename-inode_number pairs. Where does a file directory store it's own inode number and filename?

Best Answer

stat /bin/su shows on one system:

Access: (4755/-rwsr-xr-x)  Uid: (    0/    root)   Gid: (    0/    root)

There's the octal representation 4755 of all 12 mode bits. The number corresponds to the bits:

octal    4   7   5   5
bits   100 111 101 101
       sst uuu ggg ooo
       ug  rwx rwx rwx

Where uuu, ggg and ooo are the permission bits for the user, group and others. The remaining group (the first one in order) contains the setuid (su), setgid (sg) and sticky (t) bits.

The setuid and sticky bits are often not mentioned, since they're zero for most files. They're still there for every file, saved along with the others.


If we really get down to it, some filesystems and interfaces store the file type along the mode bits, in the still-higher bits. The above only accounts for 12 bits, so with a 16-bit field, there's 4 left over. See, for example, the description of st_mode in stat(2).

Related Question