|
Packit |
7cfc04 |
.\" Copyright (c) 2006, 2008, Michael Kerrisk <mtk.manpages@gmail.com>
|
|
Packit |
7cfc04 |
.\" (A few fragments remain from an earlier (1992) version written in
|
|
Packit |
7cfc04 |
.\" 1992 by Drew Eckhardt <drew@cs.colorado.edu>.)
|
|
Packit |
7cfc04 |
.\"
|
|
Packit |
7cfc04 |
.\" %%%LICENSE_START(VERBATIM)
|
|
Packit |
7cfc04 |
.\" Permission is granted to make and distribute verbatim copies of this
|
|
Packit |
7cfc04 |
.\" manual provided the copyright notice and this permission notice are
|
|
Packit |
7cfc04 |
.\" preserved on all copies.
|
|
Packit |
7cfc04 |
.\"
|
|
Packit |
7cfc04 |
.\" Permission is granted to copy and distribute modified versions of this
|
|
Packit |
7cfc04 |
.\" manual under the conditions for verbatim copying, provided that the
|
|
Packit |
7cfc04 |
.\" entire resulting derived work is distributed under the terms of a
|
|
Packit |
7cfc04 |
.\" permission notice identical to this one.
|
|
Packit |
7cfc04 |
.\"
|
|
Packit |
7cfc04 |
.\" Since the Linux kernel and libraries are constantly changing, this
|
|
Packit |
7cfc04 |
.\" manual page may be incorrect or out-of-date. The author(s) assume no
|
|
Packit |
7cfc04 |
.\" responsibility for errors or omissions, or for damages resulting from
|
|
Packit |
7cfc04 |
.\" the use of the information contained herein. The author(s) may not
|
|
Packit |
7cfc04 |
.\" have taken the same level of care in the production of this manual,
|
|
Packit |
7cfc04 |
.\" which is licensed free of charge, as they might when working
|
|
Packit |
7cfc04 |
.\" professionally.
|
|
Packit |
7cfc04 |
.\"
|
|
Packit |
7cfc04 |
.\" Formatted or processed versions of this manual, if unaccompanied by
|
|
Packit |
7cfc04 |
.\" the source, must acknowledge the copyright and authors of this work.
|
|
Packit |
7cfc04 |
.\" %%%LICENSE_END
|
|
Packit |
7cfc04 |
.\"
|
|
Packit |
7cfc04 |
.\" Modified by Michael Haardt <michael@moria.de>
|
|
Packit |
7cfc04 |
.\" Modified Sat Jul 24 12:51:53 1993 by Rik Faith <faith@cs.unc.edu>
|
|
Packit |
7cfc04 |
.\" Modified Tue Oct 22 22:39:04 1996 by Eric S. Raymond <esr@thyrsus.com>
|
|
Packit |
7cfc04 |
.\" Modified Thu May 1 06:05:54 UTC 1997 by Nicolás Lichtmaier
|
|
Packit |
7cfc04 |
.\" <nick@debian.com> with Lars Wirzenius <liw@iki.fi> suggestion
|
|
Packit |
7cfc04 |
.\" 2006-05-13, mtk, substantial rewrite of description of 'mask'
|
|
Packit |
7cfc04 |
.\" 2008-01-09, mtk, a few rewrites and additions.
|
|
Packit |
7cfc04 |
.TH UMASK 2 2017-09-15 "Linux" "Linux Programmer's Manual"
|
|
Packit |
7cfc04 |
.SH NAME
|
|
Packit |
7cfc04 |
umask \- set file mode creation mask
|
|
Packit |
7cfc04 |
.SH SYNOPSIS
|
|
Packit |
7cfc04 |
.B #include <sys/types.h>
|
|
Packit |
7cfc04 |
.br
|
|
Packit |
7cfc04 |
.B #include <sys/stat.h>
|
|
Packit |
7cfc04 |
.PP
|
|
Packit |
7cfc04 |
.BI "mode_t umask(mode_t " mask );
|
|
Packit |
7cfc04 |
.SH DESCRIPTION
|
|
Packit |
7cfc04 |
.BR umask ()
|
|
Packit |
7cfc04 |
sets the calling process's file mode creation mask (umask) to
|
|
Packit |
7cfc04 |
.I mask
|
|
Packit |
7cfc04 |
& 0777 (i.e., only the file permission bits of
|
|
Packit |
7cfc04 |
.I mask
|
|
Packit |
7cfc04 |
are used), and returns the previous value of the mask.
|
|
Packit |
7cfc04 |
.PP
|
|
Packit |
7cfc04 |
The umask is used by
|
|
Packit |
7cfc04 |
.BR open (2),
|
|
Packit |
7cfc04 |
.BR mkdir (2),
|
|
Packit |
7cfc04 |
and other system calls that create files
|
|
Packit |
7cfc04 |
.\" e.g., mkfifo(), creat(), mknod(), sem_open(), mq_open(), shm_open()
|
|
Packit |
7cfc04 |
.\" but NOT the System V IPC *get() calls
|
|
Packit |
7cfc04 |
to modify the permissions placed on newly created files or directories.
|
|
Packit |
7cfc04 |
Specifically, permissions in the umask are turned off from
|
|
Packit |
7cfc04 |
the
|
|
Packit |
7cfc04 |
.I mode
|
|
Packit |
7cfc04 |
argument to
|
|
Packit |
7cfc04 |
.BR open (2)
|
|
Packit |
7cfc04 |
and
|
|
Packit |
7cfc04 |
.BR mkdir (2).
|
|
Packit |
7cfc04 |
.PP
|
|
Packit |
7cfc04 |
Alternatively, if the parent directory has a default ACL (see
|
|
Packit |
7cfc04 |
.BR acl (5)),
|
|
Packit |
7cfc04 |
the umask is ignored, the default ACL is inherited,
|
|
Packit |
7cfc04 |
the permission bits are set based on the inherited ACL,
|
|
Packit |
7cfc04 |
and permission bits absent in the
|
|
Packit |
7cfc04 |
.I mode
|
|
Packit |
7cfc04 |
argument are turned off.
|
|
Packit |
7cfc04 |
For example, the following default ACL is equivalent to a umask of 022:
|
|
Packit |
7cfc04 |
.PP
|
|
Packit |
7cfc04 |
u::rwx,g::r-x,o::r-x
|
|
Packit |
7cfc04 |
.PP
|
|
Packit |
7cfc04 |
Combining the effect of this default ACL with a
|
|
Packit |
7cfc04 |
.I mode
|
|
Packit |
7cfc04 |
argument of 0666 (rw-rw-rw-), the resulting file permissions would be 0644
|
|
Packit |
7cfc04 |
(rw-r--r--).
|
|
Packit |
7cfc04 |
.PP
|
|
Packit |
7cfc04 |
The constants that should be used to specify
|
|
Packit |
7cfc04 |
.I mask
|
|
Packit |
7cfc04 |
are described in
|
|
Packit |
7cfc04 |
.BR inode (7).
|
|
Packit |
7cfc04 |
.PP
|
|
Packit |
7cfc04 |
The typical default value for the process umask is
|
|
Packit |
7cfc04 |
.I S_IWGRP\ |\ S_IWOTH
|
|
Packit |
7cfc04 |
(octal 022).
|
|
Packit |
7cfc04 |
In the usual case where the
|
|
Packit |
7cfc04 |
.I mode
|
|
Packit |
7cfc04 |
argument to
|
|
Packit |
7cfc04 |
.BR open (2)
|
|
Packit |
7cfc04 |
is specified as:
|
|
Packit |
7cfc04 |
.PP
|
|
Packit |
7cfc04 |
.in +4n
|
|
Packit |
7cfc04 |
.EX
|
|
Packit |
7cfc04 |
S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH
|
|
Packit |
7cfc04 |
.EE
|
|
Packit |
7cfc04 |
.in
|
|
Packit |
7cfc04 |
.PP
|
|
Packit |
7cfc04 |
(octal 0666) when creating a new file, the permissions on the
|
|
Packit |
7cfc04 |
resulting file will be:
|
|
Packit |
7cfc04 |
.PP
|
|
Packit |
7cfc04 |
.in +4n
|
|
Packit |
7cfc04 |
.EX
|
|
Packit |
7cfc04 |
S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH
|
|
Packit |
7cfc04 |
.EE
|
|
Packit |
7cfc04 |
.in
|
|
Packit |
7cfc04 |
.PP
|
|
Packit |
7cfc04 |
(because 0666 & ~022 = 0644; i.e., rw\-r\-\-r\-\-).
|
|
Packit |
7cfc04 |
.SH RETURN VALUE
|
|
Packit |
7cfc04 |
This system call always succeeds and the previous value of the mask
|
|
Packit |
7cfc04 |
is returned.
|
|
Packit |
7cfc04 |
.SH CONFORMING TO
|
|
Packit |
7cfc04 |
POSIX.1-2001, POSIX.1-2008, SVr4, 4.3BSD.
|
|
Packit |
7cfc04 |
.SH NOTES
|
|
Packit |
7cfc04 |
A child process created via
|
|
Packit |
7cfc04 |
.BR fork (2)
|
|
Packit |
7cfc04 |
inherits its parent's umask.
|
|
Packit |
7cfc04 |
The umask is left unchanged by
|
|
Packit |
7cfc04 |
.BR execve (2).
|
|
Packit |
7cfc04 |
.PP
|
|
Packit |
7cfc04 |
It is impossible to use
|
|
Packit |
7cfc04 |
.BR umask ()
|
|
Packit |
7cfc04 |
to fetch a process's umask without at the same time changing it.
|
|
Packit |
7cfc04 |
A second call to
|
|
Packit |
7cfc04 |
.BR umask ()
|
|
Packit |
7cfc04 |
would then be needed to restore the umask.
|
|
Packit |
7cfc04 |
The nonatomicity of these two steps provides the potential
|
|
Packit |
7cfc04 |
for races in multithreaded programs.
|
|
Packit |
7cfc04 |
.PP
|
|
Packit |
7cfc04 |
Since Linux 4.7, the umask of any process can be viewed via the
|
|
Packit |
7cfc04 |
.I Umask
|
|
Packit |
7cfc04 |
field of
|
|
Packit |
7cfc04 |
.IR /proc/[pid]/status .
|
|
Packit |
7cfc04 |
Inspecting this field in
|
|
Packit |
7cfc04 |
.IR /proc/self/status
|
|
Packit |
7cfc04 |
allows a process to retrieve its umask without at the same time changing it.
|
|
Packit |
7cfc04 |
.PP
|
|
Packit |
7cfc04 |
The umask setting also affects the permissions assigned to POSIX IPC objects
|
|
Packit |
7cfc04 |
.RB ( mq_open (3),
|
|
Packit |
7cfc04 |
.BR sem_open (3),
|
|
Packit |
7cfc04 |
.BR shm_open (3)),
|
|
Packit |
7cfc04 |
FIFOs
|
|
Packit |
7cfc04 |
.RB ( mkfifo (3)),
|
|
Packit |
7cfc04 |
and UNIX domain sockets
|
|
Packit |
7cfc04 |
.RB ( unix (7))
|
|
Packit |
7cfc04 |
created by the process.
|
|
Packit |
7cfc04 |
The umask does not affect the permissions assigned
|
|
Packit |
7cfc04 |
to System\ V IPC objects created by the process (using
|
|
Packit |
7cfc04 |
.BR msgget (2),
|
|
Packit |
7cfc04 |
.BR semget (2),
|
|
Packit |
7cfc04 |
.BR shmget (2)).
|
|
Packit |
7cfc04 |
.SH SEE ALSO
|
|
Packit |
7cfc04 |
.BR chmod (2),
|
|
Packit |
7cfc04 |
.BR mkdir (2),
|
|
Packit |
7cfc04 |
.BR open (2),
|
|
Packit |
7cfc04 |
.BR stat (2),
|
|
Packit |
7cfc04 |
.BR acl (5)
|
|
Packit |
7cfc04 |
.SH COLOPHON
|
|
Packit |
7cfc04 |
This page is part of release 4.15 of the Linux
|
|
Packit |
7cfc04 |
.I man-pages
|
|
Packit |
7cfc04 |
project.
|
|
Packit |
7cfc04 |
A description of the project,
|
|
Packit |
7cfc04 |
information about reporting bugs,
|
|
Packit |
7cfc04 |
and the latest version of this page,
|
|
Packit |
7cfc04 |
can be found at
|
|
Packit |
7cfc04 |
\%https://www.kernel.org/doc/man\-pages/.
|