]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man2/umask.2
getent.1, ldd.1, locale.1, localedef.1, memusage.1, memusagestat.1, mtrace.1, _exit...
[thirdparty/man-pages.git] / man2 / umask.2
1 .\" Copyright (c) 2006, 2008, Michael Kerrisk <mtk.manpages@gmail.com>
2 .\" (A few fragments remain from an earlier (1992) version written in
3 .\" 1992 by Drew Eckhardt <drew@cs.colorado.edu>.)
4 .\"
5 .\" %%%LICENSE_START(VERBATIM)
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.
14 .\"
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.
22 .\"
23 .\" Formatted or processed versions of this manual, if unaccompanied by
24 .\" the source, must acknowledge the copyright and authors of this work.
25 .\" %%%LICENSE_END
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>
30 .\" Modified Thu May 1 06:05:54 UTC 1997 by Nicolás Lichtmaier
31 .\" <nick@debian.com> with Lars Wirzenius <liw@iki.fi> suggestion
32 .\" 2006-05-13, mtk, substantial rewrite of description of 'mask'
33 .\" 2008-01-09, mtk, a few rewrites and additions.
34 .TH UMASK 2 2021-03-22 "Linux" "Linux Programmer's Manual"
35 .SH NAME
36 umask \- set file mode creation mask
37 .SH SYNOPSIS
38 .nf
39 .B #include <sys/types.h>
40 .B #include <sys/stat.h>
41 .PP
42 .BI "mode_t umask(mode_t " mask );
43 .fi
44 .SH DESCRIPTION
45 .BR umask ()
46 sets the calling process's file mode creation mask (umask) to
47 .I mask
48 & 0777 (i.e., only the file permission bits of
49 .I mask
50 are used), and returns the previous value of the mask.
51 .PP
52 The umask is used by
53 .BR open (2),
54 .BR mkdir (2),
55 and other system calls that create files
56 .\" e.g., mkfifo(), creat(), mknod(), sem_open(), mq_open(), shm_open()
57 .\" but NOT the System V IPC *get() calls
58 to modify the permissions placed on newly created files or directories.
59 Specifically, permissions in the umask are turned off from
60 the
61 .I mode
62 argument to
63 .BR open (2)
64 and
65 .BR mkdir (2).
66 .PP
67 Alternatively, if the parent directory has a default ACL (see
68 .BR acl (5)),
69 the umask is ignored, the default ACL is inherited,
70 the permission bits are set based on the inherited ACL,
71 and permission bits absent in the
72 .I mode
73 argument are turned off.
74 For example, the following default ACL is equivalent to a umask of 022:
75 .PP
76 u::rwx,g::r-x,o::r-x
77 .PP
78 Combining the effect of this default ACL with a
79 .I mode
80 argument of 0666 (rw-rw-rw-), the resulting file permissions would be 0644
81 (rw-r--r--).
82 .PP
83 The constants that should be used to specify
84 .I mask
85 are described in
86 .BR inode (7).
87 .PP
88 The typical default value for the process umask is
89 .I S_IWGRP\ |\ S_IWOTH
90 (octal 022).
91 In the usual case where the
92 .I mode
93 argument to
94 .BR open (2)
95 is specified as:
96 .PP
97 .in +4n
98 .EX
99 S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH
100 .EE
101 .in
102 .PP
103 (octal 0666) when creating a new file, the permissions on the
104 resulting file will be:
105 .PP
106 .in +4n
107 .EX
108 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH
109 .EE
110 .in
111 .PP
112 (because 0666 & \(ti022 = 0644; i.e., rw\-r\-\-r\-\-).
113 .SH RETURN VALUE
114 This system call always succeeds and the previous value of the mask
115 is returned.
116 .SH CONFORMING TO
117 POSIX.1-2001, POSIX.1-2008, SVr4, 4.3BSD.
118 .SH NOTES
119 A child process created via
120 .BR fork (2)
121 inherits its parent's umask.
122 The umask is left unchanged by
123 .BR execve (2).
124 .PP
125 It is impossible to use
126 .BR umask ()
127 to fetch a process's umask without at the same time changing it.
128 A second call to
129 .BR umask ()
130 would then be needed to restore the umask.
131 The nonatomicity of these two steps provides the potential
132 for races in multithreaded programs.
133 .PP
134 Since Linux 4.7, the umask of any process can be viewed via the
135 .I Umask
136 field of
137 .IR /proc/[pid]/status .
138 Inspecting this field in
139 .IR /proc/self/status
140 allows a process to retrieve its umask without at the same time changing it.
141 .PP
142 The umask setting also affects the permissions assigned to POSIX IPC objects
143 .RB ( mq_open (3),
144 .BR sem_open (3),
145 .BR shm_open (3)),
146 FIFOs
147 .RB ( mkfifo (3)),
148 and UNIX domain sockets
149 .RB ( unix (7))
150 created by the process.
151 The umask does not affect the permissions assigned
152 to System\ V IPC objects created by the process (using
153 .BR msgget (2),
154 .BR semget (2),
155 .BR shmget (2)).
156 .SH SEE ALSO
157 .BR chmod (2),
158 .BR mkdir (2),
159 .BR open (2),
160 .BR stat (2),
161 .BR acl (5)