C语言 mode_t 0644 是什么意思?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18415904/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What does mode_t 0644 mean?
提问by Sycx
#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
我在 copy.c 文件中有这两行代码。我不知道这是什么意思。请举例说明
回答by luser droog
There are 3x3 bit flags for a mode:
模式有 3x3 位标志:
- (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:
所以 0644 是:
* (owning) User: read & write
* Group: read
* Other: read
Note that in C, an initial 0indicates octal notation, just like 0xindicates hexadecimal notation. So every time you write plain zero in C, it's actually an octalzero (fun fact).
请注意,在 C 中,首字母0表示八进制表示法,就像0x表示十六进制表示法一样。所以每次你用 C 写纯零时,它实际上是一个八进制零(有趣的事实)。
This might also be written:
也可以这样写:
-rw-r--r--
Whereas full permissions, 0777 can also be written:
而完全权限,0777 也可以写成:
-rwxrwxrwx
So the octal number passed to creatcorresponds directly (via octal encoding of the bit-pattern) to the file permissions as displayed by ls -l.
因此,传递给的八进制数creat直接(通过位模式的八进制编码)对应于ls -l.
回答by Rafe Kettler
It means that:
这意味着:
- The file's owner can read and write (6)
- Users in the same group as the file's owner can read (first 4)
- All users can read (second 4)
- 文件的所有者可以读写 (6)
- 与文件所有者在同一组中的用户可以读取(前 4 个)
- 所有用户都可以阅读(第二个 4)

