-
Notifications
You must be signed in to change notification settings - Fork 0
/
umask.html
182 lines (137 loc) · 5.53 KB
/
umask.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
<!-- Creator : groff version 1.22.4 -->
<!-- CreationDate: Wed Jan 29 11:25:42 2020 -->
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta name="generator" content="groff -Thtml, see www.gnu.org">
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<meta name="Content-Style" content="text/css">
<style type="text/css">
p { margin-top: 0; margin-bottom: 0; vertical-align: top }
pre { margin-top: 0; margin-bottom: 0; vertical-align: top }
table { margin-top: 0; margin-bottom: 0; vertical-align: top }
h1 { text-align: center }
</style>
<title>UMASK</title>
</head>
<body>
<h1 align="center">UMASK</h1>
<a href="#NAME">NAME</a><br>
<a href="#SYNOPSIS">SYNOPSIS</a><br>
<a href="#DESCRIPTION">DESCRIPTION</a><br>
<a href="#RETURN VALUE">RETURN VALUE</a><br>
<a href="#CONFORMING TO">CONFORMING TO</a><br>
<a href="#NOTES">NOTES</a><br>
<a href="#SEE ALSO">SEE ALSO</a><br>
<a href="#COLOPHON">COLOPHON</a><br>
<hr>
<h2>NAME
<a name="NAME"></a>
</h2>
<p style="margin-left:11%; margin-top: 1em">umask - set
file mode creation mask</p>
<h2>SYNOPSIS
<a name="SYNOPSIS"></a>
</h2>
<p style="margin-left:11%; margin-top: 1em"><b>#include
<sys/types.h> <br>
#include <sys/stat.h></b></p>
<p style="margin-left:11%; margin-top: 1em"><b>mode_t
umask(mode_t</b> <i>mask</i><b>);</b></p>
<h2>DESCRIPTION
<a name="DESCRIPTION"></a>
</h2>
<p style="margin-left:11%; margin-top: 1em"><b>umask</b>()
sets the calling process’s file mode creation mask
(umask) to <i>mask</i> & 0777 (i.e., only the file
permission bits of <i>mask</i> are used), and returns the
previous value of the mask.</p>
<p style="margin-left:11%; margin-top: 1em">The umask is
used by <b>open</b>(2), <b>mkdir</b>(2), and other system
calls that create files to modify the permissions placed on
newly created files or directories. Specifically,
permissions in the umask are turned off from the <i>mode</i>
argument to <b>open</b>(2) and <b>mkdir</b>(2).</p>
<p style="margin-left:11%; margin-top: 1em">Alternatively,
if the parent directory has a default ACL (see
<b>acl</b>(5)), the umask is ignored, the default ACL is
inherited, the permission bits are set based on the
inherited ACL, and permission bits absent in the <i>mode</i>
argument are turned off. For example, the following default
ACL is equivalent to a umask of 022:</p>
<p style="margin-left:11%; margin-top: 1em">u::rwx,g::r-x,o::r-x</p>
<p style="margin-left:11%; margin-top: 1em">Combining the
effect of this default ACL with a <i>mode</i> argument of
0666 (rw-rw-rw-), the resulting file permissions would be
0644 (rw-r--r--).</p>
<p style="margin-left:11%; margin-top: 1em">The constants
that should be used to specify <i>mask</i> are described in
<b>inode</b>(7).</p>
<p style="margin-left:11%; margin-top: 1em">The typical
default value for the process umask is
<i>S_IWGRP | S_IWOTH</i> (octal 022). In the usual
case where the <i>mode</i> argument to <b>open</b>(2) is
specified as:</p>
<p style="margin-left:17%; margin-top: 1em">S_IRUSR |
S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH</p>
<p style="margin-left:11%; margin-top: 1em">(octal 0666)
when creating a new file, the permissions on the resulting
file will be:</p>
<p style="margin-left:17%; margin-top: 1em">S_IRUSR |
S_IWUSR | S_IRGRP | S_IROTH</p>
<p style="margin-left:11%; margin-top: 1em">(because 0666
& ~022 = 0644; i.e., rw-r--r--).</p>
<h2>RETURN VALUE
<a name="RETURN VALUE"></a>
</h2>
<p style="margin-left:11%; margin-top: 1em">This system
call always succeeds and the previous value of the mask is
returned.</p>
<h2>CONFORMING TO
<a name="CONFORMING TO"></a>
</h2>
<p style="margin-left:11%; margin-top: 1em">POSIX.1-2001,
POSIX.1-2008, SVr4, 4.3BSD.</p>
<h2>NOTES
<a name="NOTES"></a>
</h2>
<p style="margin-left:11%; margin-top: 1em">A child process
created via <b>fork</b>(2) inherits its parent’s
umask. The umask is left unchanged by <b>execve</b>(2).</p>
<p style="margin-left:11%; margin-top: 1em">It is
impossible to use <b>umask</b>() to fetch a process’s
umask without at the same time changing it. A second call to
<b>umask</b>() would then be needed to restore the umask.
The nonatomicity of these two steps provides the potential
for races in multithreaded programs.</p>
<p style="margin-left:11%; margin-top: 1em">Since Linux
4.7, the umask of any process can be viewed via the
<i>Umask</i> field of <i>/proc/[pid]/status</i>. Inspecting
this field in <i>/proc/self/status</i> allows a process to
retrieve its umask without at the same time changing it.</p>
<p style="margin-left:11%; margin-top: 1em">The umask
setting also affects the permissions assigned to POSIX IPC
objects (<b>mq_open</b>(3), <b>sem_open</b>(3),
<b>shm_open</b>(3)), FIFOs (<b>mkfifo</b>(3)), and UNIX
domain sockets (<b>unix</b>(7)) created by the process. The
umask does not affect the permissions assigned to
System V IPC objects created by the process (using
<b>msgget</b>(2), <b>semget</b>(2), <b>shmget</b>(2)).</p>
<h2>SEE ALSO
<a name="SEE ALSO"></a>
</h2>
<p style="margin-left:11%; margin-top: 1em"><b>chmod</b>(2),
<b>mkdir</b>(2), <b>open</b>(2), <b>stat</b>(2),
<b>acl</b>(5)</p>
<h2>COLOPHON
<a name="COLOPHON"></a>
</h2>
<p style="margin-left:11%; margin-top: 1em">This page is
part of release 5.02 of the Linux <i>man-pages</i> project.
A description of the project, information about reporting
bugs, and the latest version of this page, can be found at
https://www.kernel.org/doc/man-pages/.</p>
<hr>
</body>
</html>