]>
Commit | Line | Data |
---|---|---|
616c2730 | 1 | .\" Copyright (c) 2006, 2008, Michael Kerrisk <mtk.manpages@gmail.com> |
0d26ae94 | 2 | .\" (A few fragments remain from an earlier (1992) version written in |
8d3a62d6 | 3 | .\" 1992 by Drew Eckhardt <drew@cs.colorado.edu>.) |
fea681da | 4 | .\" |
93015253 | 5 | .\" %%%LICENSE_START(VERBATIM) |
fea681da MK |
6 | .\" Permission is granted to make and distribute verbatim copies of this |
7 | .\" manual provided the copyright notice and this permission notice are | |
8 | .\" preserved on all copies. | |
9 | .\" | |
10 | .\" Permission is granted to copy and distribute modified versions of this | |
11 | .\" manual under the conditions for verbatim copying, provided that the | |
12 | .\" entire resulting derived work is distributed under the terms of a | |
13 | .\" permission notice identical to this one. | |
c13182ef | 14 | .\" |
fea681da MK |
15 | .\" Since the Linux kernel and libraries are constantly changing, this |
16 | .\" manual page may be incorrect or out-of-date. The author(s) assume no | |
17 | .\" responsibility for errors or omissions, or for damages resulting from | |
18 | .\" the use of the information contained herein. The author(s) may not | |
19 | .\" have taken the same level of care in the production of this manual, | |
20 | .\" which is licensed free of charge, as they might when working | |
21 | .\" professionally. | |
c13182ef | 22 | .\" |
fea681da MK |
23 | .\" Formatted or processed versions of this manual, if unaccompanied by |
24 | .\" the source, must acknowledge the copyright and authors of this work. | |
4b72fb64 | 25 | .\" %%%LICENSE_END |
fea681da MK |
26 | .\" |
27 | .\" Modified by Michael Haardt <michael@moria.de> | |
28 | .\" Modified Sat Jul 24 12:51:53 1993 by Rik Faith <faith@cs.unc.edu> | |
29 | .\" Modified Tue Oct 22 22:39:04 1996 by Eric S. Raymond <esr@thyrsus.com> | |
e00c3a07 | 30 | .\" Modified Thu May 1 06:05:54 UTC 1997 by Nicolás Lichtmaier |
fea681da | 31 | .\" <nick@debian.com> with Lars Wirzenius <liw@iki.fi> suggestion |
c80909ad | 32 | .\" 2006-05-13, mtk, substantial rewrite of description of 'mask' |
8d3a62d6 | 33 | .\" 2008-01-09, mtk, a few rewrites and additions. |
4b8c67d9 | 34 | .TH UMASK 2 2017-09-15 "Linux" "Linux Programmer's Manual" |
fea681da | 35 | .SH NAME |
d1fd6d3d | 36 | umask \- set file mode creation mask |
fea681da MK |
37 | .SH SYNOPSIS |
38 | .B #include <sys/types.h> | |
39 | .br | |
40 | .B #include <sys/stat.h> | |
68e4db0a | 41 | .PP |
fea681da MK |
42 | .BI "mode_t umask(mode_t " mask ); |
43 | .SH DESCRIPTION | |
d1fd6d3d | 44 | .BR umask () |
c13182ef MK |
45 | sets the calling process's file mode creation mask (umask) to |
46 | .I mask | |
8d3a62d6 MK |
47 | & 0777 (i.e., only the file permission bits of |
48 | .I mask | |
49 | are used), and returns the previous value of the mask. | |
efeece04 | 50 | .PP |
fea681da | 51 | The umask is used by |
d1fd6d3d MK |
52 | .BR open (2), |
53 | .BR mkdir (2), | |
54 | and other system calls that create files | |
55 | .\" e.g., mkfifo(), creat(), mknod(), sem_open(), mq_open(), shm_open() | |
56 | .\" but NOT the System V IPC *get() calls | |
57 | to modify the permissions placed on newly created files or directories. | |
fea681da | 58 | Specifically, permissions in the umask are turned off from |
c6fa0841 MK |
59 | the |
60 | .I mode | |
61 | argument to | |
fea681da | 62 | .BR open (2) |
d1fd6d3d | 63 | and |
c80909ad | 64 | .BR mkdir (2). |
efeece04 | 65 | .PP |
a57c98a0 | 66 | Alternatively, if the parent directory has a default ACL (see |
5d817eb4 | 67 | .BR acl (5)), |
a57c98a0 MK |
68 | the umask is ignored, the default ACL is inherited, |
69 | the permission bits are set based on the inherited ACL, | |
70 | and permission bits absent in the | |
5d817eb4 | 71 | .I mode |
a57c98a0 MK |
72 | argument are turned off. |
73 | For example, the following default ACL is equivalent to a umask of 022: | |
efeece04 | 74 | .PP |
a57c98a0 | 75 | u::rwx,g::r-x,o::r-x |
efeece04 | 76 | .PP |
a57c98a0 | 77 | Combining the effect of this default ACL with a |
5d817eb4 | 78 | .I mode |
a57c98a0 | 79 | argument of 0666 (rw-rw-rw-), the resulting file permissions would be 0644 |
5d817eb4 | 80 | (rw-r--r--). |
efeece04 | 81 | .PP |
c13182ef | 82 | The constants that should be used to specify |
c80909ad | 83 | .I mask |
e6fc1596 MK |
84 | are described in |
85 | .BR inode (7). | |
efeece04 | 86 | .PP |
c80909ad | 87 | The typical default value for the process umask is |
2f0af33b | 88 | .I S_IWGRP\ |\ S_IWOTH |
c80909ad MK |
89 | (octal 022). |
90 | In the usual case where the | |
91 | .I mode | |
c13182ef | 92 | argument to |
d1fd6d3d | 93 | .BR open (2) |
c80909ad | 94 | is specified as: |
408731d4 MK |
95 | .PP |
96 | .in +4n | |
97 | .EX | |
98 | S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH | |
99 | .EE | |
100 | .in | |
101 | .PP | |
c80909ad MK |
102 | (octal 0666) when creating a new file, the permissions on the |
103 | resulting file will be: | |
408731d4 MK |
104 | .PP |
105 | .in +4n | |
106 | .EX | |
107 | S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH | |
108 | .EE | |
109 | .in | |
110 | .PP | |
94e9d9fe | 111 | (because 0666 & ~022 = 0644; i.e., rw\-r\-\-r\-\-). |
47297adb | 112 | .SH RETURN VALUE |
fea681da MK |
113 | This system call always succeeds and the previous value of the mask |
114 | is returned. | |
47297adb | 115 | .SH CONFORMING TO |
1500e827 | 116 | POSIX.1-2001, POSIX.1-2008, SVr4, 4.3BSD. |
ef828a01 MK |
117 | .SH NOTES |
118 | A child process created via | |
119 | .BR fork (2) | |
120 | inherits its parent's umask. | |
121 | The umask is left unchanged by | |
122 | .BR execve (2). | |
efeece04 | 123 | .PP |
cfa21a0b | 124 | It is impossible to use |
8a2de39c MK |
125 | .BR umask () |
126 | to fetch a process's umask without at the same time changing it. | |
127 | A second call to | |
128 | .BR umask () | |
129 | would then be needed to restore the umask. | |
130 | The nonatomicity of these two steps provides the potential | |
131 | for races in multithreaded programs. | |
efeece04 | 132 | .PP |
0c00a52e | 133 | Since Linux 4.7, the umask of any process can be viewed via the |
ac6c297c | 134 | .I Umask |
0c00a52e MK |
135 | field of |
136 | .IR /proc/[pid]/status . | |
8a2de39c MK |
137 | Inspecting this field in |
138 | .IR /proc/self/status | |
139 | allows a process to retrieve its umask without at the same time changing it. | |
efeece04 | 140 | .PP |
8d3a62d6 MK |
141 | The umask setting also affects the permissions assigned to POSIX IPC objects |
142 | .RB ( mq_open (3), | |
143 | .BR sem_open (3), | |
144 | .BR shm_open (3)), | |
145 | FIFOs | |
146 | .RB ( mkfifo (3)), | |
008f1ecc | 147 | and UNIX domain sockets |
8d3a62d6 MK |
148 | .RB ( unix (7)) |
149 | created by the process. | |
150 | The umask does not affect the permissions assigned | |
efbfd7ec | 151 | to System\ V IPC objects created by the process (using |
8d3a62d6 MK |
152 | .BR msgget (2), |
153 | .BR semget (2), | |
154 | .BR shmget (2)). | |
47297adb | 155 | .SH SEE ALSO |
d1fd6d3d MK |
156 | .BR chmod (2), |
157 | .BR mkdir (2), | |
c80909ad | 158 | .BR open (2), |
e2ee112d | 159 | .BR stat (2), |
b7ac18e9 | 160 | .BR acl (5) |