1UMASK(2)                   Linux Programmer's Manual                  UMASK(2)
2
3
4

NAME

6       umask - set file mode creation mask
7

SYNOPSIS

9       #include <sys/stat.h>
10
11       mode_t umask(mode_t mask);
12

DESCRIPTION

14       umask()  sets  the calling process's file mode creation mask (umask) to
15       mask & 0777 (i.e., only the file permission bits of mask are used), and
16       returns the previous value of the mask.
17
18       The  umask  is  used  by open(2), mkdir(2), and other system calls that
19       create files to modify the permissions placed on newly created files or
20       directories.   Specifically,  permissions  in  the umask are turned off
21       from the mode argument to open(2) and mkdir(2).
22
23       Alternatively, if the parent directory has a default ACL (see  acl(5)),
24       the umask is ignored, the default ACL is inherited, the permission bits
25       are set based on the inherited ACL, and permission bits absent  in  the
26       mode  argument  are turned off.  For example, the following default ACL
27       is equivalent to a umask of 022:
28
29           u::rwx,g::r-x,o::r-x
30
31       Combining the effect of this default ACL with a mode argument  of  0666
32       (rw-rw-rw-), the resulting file permissions would be 0644 (rw-r--r--).
33
34       The  constants that should be used to specify mask are described in in‐
35       ode(7).
36
37       The typical default value for the process  umask  is  S_IWGRP | S_IWOTH
38       (octal  022).   In the usual case where the mode argument to open(2) is
39       specified as:
40
41           S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH
42
43       (octal 0666) when creating a new file, the permissions on the resulting
44       file will be:
45
46           S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH
47
48       (because 0666 & ~022 = 0644; i.e., rw-r--r--).
49

RETURN VALUE

51       This  system call always succeeds and the previous value of the mask is
52       returned.
53

CONFORMING TO

55       POSIX.1-2001, POSIX.1-2008, SVr4, 4.3BSD.
56

NOTES

58       A child process created via fork(2) inherits its parent's  umask.   The
59       umask is left unchanged by execve(2).
60
61       It  is  impossible to use umask() to fetch a process's umask without at
62       the same time changing it.  A second call  to  umask()  would  then  be
63       needed  to restore the umask.  The nonatomicity of these two steps pro‐
64       vides the potential for races in multithreaded programs.
65
66       Since Linux 4.7, the umask of any process can be viewed via  the  Umask
67       field  of /proc/[pid]/status.  Inspecting this field in /proc/self/sta‐
68       tus allows a process to retrieve its umask without  at  the  same  time
69       changing it.
70
71       The  umask  setting  also affects the permissions assigned to POSIX IPC
72       objects (mq_open(3), sem_open(3), shm_open(3)), FIFOs (mkfifo(3)),  and
73       UNIX  domain  sockets (unix(7)) created by the process.  The umask does
74       not affect the permissions assigned to System V IPC objects created  by
75       the process (using msgget(2), semget(2), shmget(2)).
76

SEE ALSO

78       chmod(2), mkdir(2), open(2), stat(2), acl(5)
79

COLOPHON

81       This  page  is  part of release 5.13 of the Linux man-pages project.  A
82       description of the project, information about reporting bugs,  and  the
83       latest     version     of     this    page,    can    be    found    at
84       https://www.kernel.org/doc/man-pages/.
85
86
87
88Linux                             2021-03-22                          UMASK(2)
Impressum