Consider this code :
#load "unix.cma" ;;
print_int (Unix.umask 0) ;;
print_newline () ;;
When I run it, I get 2 (binary : 000.000.010). When I run it with 'sudo', I get 18 (binary : 000.010.010) I was expected to get something like 0o640 (binary : 110.010.000), as the standard library says : http://caml.inria.fr/pub/docs/manual-ocaml/libref/Unix.html#TYPEfile_perm My purpose is to make a directory. If I make it with
(Unix.umask 0) lor (0o640)
it is created but inaccessible. An accurate look at the binary numbers gives me the idea that the default mask could be reverted. So, I make a directory using this :
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, I create my directory :
let mask = (revert_mask (Unix.umask 0)) lor 0o640 ;;
print_int mask ;;
print_newline () ;;
Unix.mkdir "foo" mask ;;
I get 416 (0o640), which corresponds to my
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 with ubuntu 14.04 and ocaml 4.01.0 toplevel.