linux mkdir 功能无法授权完全权限

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8719867/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 03:53:58  来源:igfitidea点击:

linux mkdir function can't authorize full permission

clinuxpermissionsmkdir

提问by manuzhang

I am testing the mkdirfunction to create a new directory:

我正在测试mkdir创建新目录的功能:

folder =  mkdir("./linux", 511);

or

或者

 folder = mkdir("./linux", 0777);

or

或者

folder = mkdir("./linux", S_IRWXU | S_IRWXG | S_IRWXO);

As you can see, I try to authorize the full permission to the directory but here's what comes up with ls -l | grep linux:

如您所见,我尝试授予对目录的完全权限,但结果ls -l | grep linux如下:

drwxr-xr-x 2 manuzhang manuzhang 4096 2012-01-04 06:53 linux

why can't I authorize write permission for group and others?

为什么我不能为组和其他人授予写权限?

Updates:
weird thing, as you guys told me I tried umask. It works with either umask(S_IWGRP)or umask(S_IWOTH)but failswith umask(S_IWGRP | S_IWOTH), any ideas?

更新
奇怪的事情,正如你们告诉我的那样,我试过了umask。它与两种umask(S_IWGRP)umask(S_IWOTH)未能umask(S_IWGRP | S_IWOTH)任何想法?

回答by sbenitezb

Check the umask function: man 2 umask

检查 umask 功能:man 2 umask

回答by duskwuff -inactive-

Permissions set by system calls like mkdirand openare always masked against the current process's umask. You can change the current umask using the umask()function; make sure to set it back when you're done.

由系统调用设置的权限,例如mkdiropen总是针对当前进程的umask. 您可以使用该umask()功能更改当前的 umask ;确保完成后将其重新设置。

回答by Kristian Glass

From man 2 mkdir:

来自man 2 mkdir

The argument mode specifies the permissions to use. It is modified by the process's umask in the usual way: the permissions of the created directory are (mode & ~umask & 0777).

参数 mode 指定要使用的权限。它以通常的方式由进程的 umask 修改:创建的目录的权限为 (mode & ~umask & 0777)。

I suggest you look at your umask - it is probably set to 0022. Try a chmodpost-mkdir.

我建议你看看你的 umask - 它可能设置为0022. 尝试chmod后 - mkdir