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