Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

How many bits on a linux file system is taken up for the permissions of a file?

share|improve this question
    
Do you literally mean the traditional permissions bits, or do you care about other permission-like metadata? –  mattdm Apr 1 '11 at 1:36
add comment

3 Answers 3

up vote 7 down vote accepted

To add to the other answers:

Traditional Unix permissions are broken down into:

  • read (r)
  • write (w)
  • execute file/access directory (x)

Each of those is stored as a bit, where 1 means permitted and 0 means not permitted.

For example, read only access, typically written r--, is stored as binary 100, or octal 4.

There are 3 sets of those permissions, which determines the allowed access for:

  • the owner of the file
  • the group of the file
  • all other users

They are all stored together in the same variable, e.g. rw-r-----, meaning read-write for the owner, read-only for the group, and no access for others, is stored as 110100000 binary, 640 octal.

So that makes 9 bits.

Then, there are 3 other special bits:

  • setuid
  • setgid
  • sticky

See man 1 chmod for details of those.

And finally, the file's type is stored using 4 bits, e.g. whether it is a regular file, or a directory, or a pipe, or a device, or whatever.

These are all stored together in the inode, and together it makes 16 bits.

share|improve this answer
    
Thank you for a great visual explanation to the answer! –  KerxPhilo Apr 1 '11 at 3:21
    
After I was confused by this blog post about linux file permissions I almost wanted to ask about it in UL-SE but lucky I found your explanation. –  humanityANDpeace Feb 23 at 7:55
add comment

Which permissions? Basic permissions fit in 16 bits; ext2 uses 32 bits, plus another 32 bits for file flags (chattr(1)); then POSIX ACLs use variable space in addition. See /usr/include/linux/ext2_fs.h for details. (ext3 and ext4 build on ext2 and mostly use the same structure.)

share|improve this answer
add comment

Information about files are stored in a data structure called an inode. There is a field in this structure for the mode, which contains the permissions. This field on my system is an unsigned short which is 2 bytes and 16 bits.

Take a look at fs.h in the Linux source to see for yourself.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.