OCaml, default value for Unix.umask -
consider code :
#load "unix.cma" ;; print_int (unix.umask 0) ;; print_newline () ;;
when run it, 2 (binary : 000.000.010). when run 'sudo', 18 (binary : 000.010.010) expected 0o640 (binary : 110.010.000), standard library says : http://caml.inria.fr/pub/docs/manual-ocaml/libref/unix.html#typefile_perm purpose make directory. if make
(unix.umask 0) lor (0o640)
it created inaccessible. accurate @ binary numbers gives me idea default mask reverted. so, make directory using :
let revert_mask m = let user = (m land 0b000000111) in let group = (m land 0b000111000) lsr 3 in let other = (m land 0b111000000) lsr 6 in (user lsl 6) lor (group lsl 3) lor other ;;
then, create directory :
let mask = (revert_mask (unix.umask 0)) lor 0o640 ;; print_int mask ;; print_newline () ;; unix.mkdir "foo" mask ;;
i 416 (0o640), corresponds
ls -l | grep foo
:
drw-r----- 2 (me) (me) 4096 june 2 19:23 foo
however, a
cd foo
won't work.
so, i'm stuck ubuntu 14.04 , ocaml 4.01.0 toplevel.
the documentation linked says:
type file_perm = int
type of file access rights, e.g.0o640
read , write user, read group, none others
the 0o640
example, not expected default value -- , it's example file_perm
value, not example umask
value.
i'm not familiar ocaml, in unix in general umask attribute of each process, typically set default value modifiable calling umask
system call.
the bits of umask turned off when creating file or directory. example, current umask 0022
(or, in ocaml syntax, 0o022
) -- means when create file or directory, corresponding bits (write access group , others) turned off. directories need execute permission, , files don't, if create directory default permissions 755
(rwxr-xr-x
), , if create file default permissions 644
(rw-r--r--
).
0o640
not sensible umask
value.
Comments
Post a Comment