I was looking at the permission bits used in various functions like stat() and chmod(), and I wanted a description of what the macros defined actually are. For instance S_IRUSR says it’s represented by 00400 (GNU/Linux). My question is, could someone describe what the 00400 actually is? Is it a number, what? I understand how to OR the macros, I just don’t get what the macro actually is.
I was looking at the permission bits used in various functions like stat() and
Share
I am going to describe the left most three numbers in permission and that would also explain about S_IRUSR,
So each of the numbers is an octal number. Each number could be from 0 to 7. Each octal number could be converted to 3-bit binary number. Each bit represents a permission.
Lets write 0 to 7 into binary and see the permission bits:
So each number represents permissions. Now next part is for who these pemmissions are.
Let the left most three number be XYZ:
Now,
Given that, Z_ISUSR = 00400, now 4 means readable by user IRUSR = Is Readable by user.
These three are the important numbers in permissions, and these only specify the permissions given to the file.