简体   繁体   English

如何创建具有777权限的目录?

[英]How to create a directory with 777 permissions?

I want to create directory with permission 777. 我想创建权限为777的目录。

The code below is creating the directory, but not with permissions I asked for. 下面的代码创建目录,但没有我要求的权限。

section .text
global _start:
_start:
             mov rax,83 ;syscall number for directory
             mov rdi,chaos ; dir name
             mov esi,00777Q ;permissions for directory
             syscall
             mov rax,60
             mov rdi,0
             syscall
section .data
           chaos:db 'somename'

Here's man 2 mkdir : 这是man 2 mkdir

The argument mode specifies the mode for the new directory (see inode(7)). 参数mode指定新目录的模式(请参见inode(7))。 It is modified by the process's umask in the usual way: in the absence of a default ACL, the mode of the created directory is (mode & ~umask & 0777) . 它由进程的umask以通常的方式修改:在没有默认ACL的情况下,创建目录的模式为(mode & ~umask & 0777)

Basically, both your program and your user can veto each permission bit: 基本上,您的程序和用户都可以否决每个权限位:

  • You can say which bits you are comfortable with by passing them to mkdir 您可以通过将它们传递给mkdir自己喜欢的位
  • The user can say which bits they are comfortable with by setting the umask 用户可以通过设置umask自己喜欢的位
  • Only bits that you both agree on will be set on the final directory. 你们都同意的位只会在最终目录中设置。

Therefore: 因此:

  • If you run umask 0000 before running your program, your directory will be 0777 . 如果在运行程序之前运行umask 0000 ,则目录将为0777

  • If you run umask 0027 your directory will be 0750 . 如果运行umask 0027目录将为0750

  • If you want to force your directory to be 777 against the user's wishes, you have to chmod("somename", 0777) in a separate step. 如果要违反用户的意愿将目录设置为777 ,则必须在单独的步骤中chmod("somename", 0777)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM