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