Debian Codegraph @

upstream/debian-unstable/man2/umask.2

raw
1 .\" Copyright 2006-2008, Michael Kerrisk <[email protected]>
2 .\" Copyright, the authors of the Linux man-pages project
3 .\"
4 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
5 .\"
6 .TH umask 2 2026-02-08 "Linux man-pages 6.18"
7 .SH NAME
8 umask \- set file mode creation mask
9 .SH LIBRARY
10 Standard C library
11 .RI ( libc ,\~ \-lc )
12 .SH SYNOPSIS
13 .nf
14 .B #include <sys/stat.h>
15 .P
16 .BI "mode_t umask(mode_t " mask );
17 .fi
18 .SH DESCRIPTION
19 .BR umask ()
20 sets the calling process's file mode creation mask (umask) to
21 .I mask
22 & 0777 (i.e., only the file permission bits of
23 .I mask
24 are used), and returns the previous value of the mask.
25 .P
26 The umask is used by
27 .BR open (2),
28 .BR mkdir (2),
29 and other system calls that create files
30 .\" e.g., mkfifo(), creat(), mknod(), sem_open(), mq_open(), shm_open()
31 .\" but NOT the System V IPC *get() calls
32 to modify the permissions placed on newly created files or directories.
33 Specifically, permissions in the umask are turned off from
34 the
35 .I mode
36 argument to
37 .BR open (2)
38 and
39 .BR mkdir (2).
40 .P
41 Alternatively, if the parent directory has a default ACL (see
42 .BR acl (5)),
43 the umask is ignored, the default ACL is inherited,
44 the permission bits are set based on the inherited ACL,
45 and permission bits absent in the
46 .I mode
47 argument are turned off.
48 For example, the following default ACL is equivalent to a umask of 022:
49 .P
50 .in +4n
51 .EX
52 u::rwx,g::r-x,o::r-x
53 .EE
54 .in
55 .P
56 Combining the effect of this default ACL with a
57 .I mode
58 argument of 0666 (rw-rw-rw-), the resulting file permissions would be 0644
59 (rw-r--r--).
60 .P
61 The constants that should be used to specify
62 .I mask
63 are described in
64 .BR inode (7).
65 .P
66 The typical default value for the process umask is
67 .BR S_IWGRP " | " S_IWOTH
68 (octal 022).
69 In the usual case where the
70 .I mode
71 argument to
72 .BR open (2)
73 is specified as:
74 .P
75 .in +4n
76 .EX
77 .BR S_IRUSR " | " S_IWUSR " | " S_IRGRP " | " S_IWGRP " | " S_IROTH " | " S_IWOTH
78 .EE
79 .in
80 .P
81 (octal 0666) when creating a new file, the permissions on the
82 resulting file will be:
83 .P
84 .in +4n
85 .EX
86 .BR S_IRUSR " | " S_IWUSR " | " S_IRGRP " | " S_IROTH
87 .EE
88 .in
89 .P
90 (because 0666 & \[ti]022 = 0644;
91 i.e., rw\-r\-\-r\-\-).
92 .SH RETURN VALUE
93 This system call always succeeds and the previous value of the mask
94 is returned.
95 .SH STANDARDS
96 POSIX.1-2008.
97 .SH HISTORY
98 POSIX.1-2001, SVr4, 4.3BSD.
99 .SH NOTES
100 A child process created via
101 .BR fork (2)
102 inherits its parent's umask.
103 The umask is left unchanged by
104 .BR execve (2).
105 .P
106 It is impossible to use
107 .BR umask ()
108 to fetch a process's umask without at the same time changing it.
109 A second call to
110 .BR umask ()
111 would then be needed to restore the umask.
112 The nonatomicity of these two steps provides the potential
113 for races in multithreaded programs.
114 .P
115 Since Linux 4.7, the umask of any process can be viewed via the
116 .I Umask
117 field of
118 .IR /proc/ pid /status .
119 Inspecting this field in
120 .I /proc/self/status
121 allows a process to retrieve its umask without at the same time changing it.
122 .P
123 The umask setting also affects the permissions assigned to POSIX IPC objects
124 .RB ( mq_open (3),
125 .BR sem_open (3),
126 .BR shm_open (3)),
127 FIFOs
128 .RB ( mkfifo (3)),
129 and UNIX domain sockets
130 .RB ( unix (7))
131 created by the process.
132 The umask does not affect the permissions assigned
133 to System\ V IPC objects created by the process (using
134 .BR msgget (2),
135 .BR semget (2),
136 .BR shmget (2)).
137 .SH SEE ALSO
138 .BR chmod (2),
139 .BR mkdir (2),
140 .BR open (2),
141 .BR stat (2),
142 .BR acl (5)