1

I want to create directory with permission 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'
Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
  • Works fine here although you should put a zero terminator after the directory name. You might also be confused by the `umask` setting being applied on top of what you specify. – Jester Dec 07 '18 at 00:41

1 Answers1

4

Here's man 2 mkdir:

The argument mode specifies the mode for the new directory (see 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).

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
  • The user can say which bits they are comfortable with by setting the 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.

  • If you run umask 0027 your directory will be 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.

that other guy
  • 116,971
  • 11
  • 170
  • 194
  • 2
    You could also first set the umask to 0 by invoking `umask(0)` from inside the program. – fuz Dec 07 '18 at 14:11