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

NAME

6       umask - set file mode creation mask
7

SYNOPSIS

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

DESCRIPTION

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

RETURN VALUE

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

CONFORMING TO

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

NOTES

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

SEE ALSO

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

COLOPHON

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