readv2: Note preadv2(..., RWF_NOWAIT) bug in BUGS section
[man-pages.git] / man2 / umask.2
blob8a11c50e9685eabfcc4be34719438d75e4644c66
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/stat.h>
40 .PP
41 .BI "mode_t umask(mode_t " mask );
42 .fi
43 .SH DESCRIPTION
44 .BR umask ()
45 sets the calling process's file mode creation mask (umask) to
46 .I mask
47 & 0777 (i.e., only the file permission bits of
48 .I mask
49 are used), and returns the previous value of the mask.
50 .PP
51 The umask is used by
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.
58 Specifically, permissions in the umask are turned off from
59 the
60 .I mode
61 argument to
62 .BR open (2)
63 and
64 .BR mkdir (2).
65 .PP
66 Alternatively, if the parent directory has a default ACL (see
67 .BR acl (5)),
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
71 .I mode
72 argument are turned off.
73 For example, the following default ACL is equivalent to a umask of 022:
74 .PP
75     u::rwx,g::r-x,o::r-x
76 .PP
77 Combining the effect of this default ACL with a
78 .I mode
79 argument of 0666 (rw-rw-rw-), the resulting file permissions would be 0644
80 (rw-r--r--).
81 .PP
82 The constants that should be used to specify
83 .I mask
84 are described in
85 .BR inode (7).
86 .PP
87 The typical default value for the process umask is
88 .I S_IWGRP\ |\ S_IWOTH
89 (octal 022).
90 In the usual case where the
91 .I mode
92 argument to
93 .BR open (2)
94 is specified as:
95 .PP
96 .in +4n
97 .EX
98 S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH
99 .EE
102 (octal 0666) when creating a new file, the permissions on the
103 resulting file will be:
105 .in +4n
107 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH
111 (because 0666 & \(ti022 = 0644; i.e., rw\-r\-\-r\-\-).
112 .SH RETURN VALUE
113 This system call always succeeds and the previous value of the mask
114 is returned.
115 .SH CONFORMING TO
116 POSIX.1-2001, POSIX.1-2008, SVr4, 4.3BSD.
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).
124 It is impossible to use
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.
133 Since Linux 4.7, the umask of any process can be viewed via the
134 .I Umask
135 field of
136 .IR /proc/[pid]/status .
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.
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)),
147 and UNIX domain sockets
148 .RB ( unix (7))
149 created by the process.
150 The umask does not affect the permissions assigned
151 to System\ V IPC objects created by the process (using
152 .BR msgget (2),
153 .BR semget (2),
154 .BR shmget (2)).
155 .SH SEE ALSO
156 .BR chmod (2),
157 .BR mkdir (2),
158 .BR open (2),
159 .BR stat (2),
160 .BR acl (5)