Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does mode_t 0644 mean?

#define COPYMODE 0644
creat(argV[2],COPYMODE);

I have these two lines of code in a copy.c file. I don't know what it means. Please give some example about it

like image 498
Sycx Avatar asked Aug 24 '13 06:08

Sycx


People also ask

What does chmod 755 do?

755 means read and execute access for everyone and also write access for the owner of the file. When you perform chmod 755 filename command you allow everyone to read and execute the file, the owner is allowed to write to the file as well.

What permissions does the octal value 0640 stand for?

An octal number, up to four digits long, that specifies the file's absolute permissions in bits. The rightmost digit is special (described later) and the second, third, and fourth represent the file's owner, the file's group, and all users. See Figure 1-3 for an example, displaying the meaning of mode 0640.


1 Answers

There are 3x3 bit flags for a mode:

  • (owning) User
    • read
    • write
    • execute
  • Group
    • read
    • write
    • execute
  • Other
    • read
    • write
    • execute

So each triple encodes nicely as an octal digit.

rwx oct    meaning
--- ---    -------
001 01   = execute
010 02   = write
011 03   = write & execute
100 04   = read
101 05   = read & execute
110 06   = read & write
111 07   = read & write & execute

So 0644 is:

* (owning) User: read & write
* Group: read
* Other: read

Note that in C, an initial 0 indicates octal notation, just like 0x indicates hexadecimal notation. So every time you write plain zero in C, it's actually an octal zero (fun fact).

This might also be written:

-rw-r--r--

Whereas full permissions, 0777 can also be written:

-rwxrwxrwx

So the octal number passed to creat corresponds directly (via octal encoding of the bit-pattern) to the file permissions as displayed by ls -l.

like image 191
luser droog Avatar answered Oct 12 '22 09:10

luser droog