236 lines
5.5 KiB
HTML
236 lines
5.5 KiB
HTML
|
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
|
<HTML><HEAD><TITLE>Man page of UMASK</TITLE>
|
|
</HEAD><BODY>
|
|
<H1>UMASK</H1>
|
|
Section: Linux Programmer's Manual (2)<BR>Updated: 2017-09-15<BR><A HREF="#index">Index</A>
|
|
<A HREF="/cgi-bin/man/man2html">Return to Main Contents</A><HR>
|
|
|
|
<A NAME="lbAB"> </A>
|
|
<H2>NAME</H2>
|
|
|
|
umask - set file mode creation mask
|
|
<A NAME="lbAC"> </A>
|
|
<H2>SYNOPSIS</H2>
|
|
|
|
<B>#include <<A HREF="file:///usr/include/sys/types.h">sys/types.h</A>></B>
|
|
|
|
<BR>
|
|
|
|
<B>#include <<A HREF="file:///usr/include/sys/stat.h">sys/stat.h</A>></B>
|
|
|
|
<P>
|
|
|
|
<B>mode_t umask(mode_t </B><I>mask</I><B>);</B>
|
|
|
|
<A NAME="lbAD"> </A>
|
|
<H2>DESCRIPTION</H2>
|
|
|
|
<B>umask</B>()
|
|
|
|
sets the calling process's file mode creation mask (umask) to
|
|
<I>mask</I>
|
|
|
|
& 0777 (i.e., only the file permission bits of
|
|
<I>mask</I>
|
|
|
|
are used), and returns the previous value of the mask.
|
|
<P>
|
|
|
|
The umask is used by
|
|
<B><A HREF="/cgi-bin/man/man2html?2+open">open</A></B>(2),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?2+mkdir">mkdir</A></B>(2),
|
|
|
|
and other system calls that create files
|
|
|
|
|
|
to modify the permissions placed on newly created files or directories.
|
|
Specifically, permissions in the umask are turned off from
|
|
the
|
|
<I>mode</I>
|
|
|
|
argument to
|
|
<B><A HREF="/cgi-bin/man/man2html?2+open">open</A></B>(2)
|
|
|
|
and
|
|
<B><A HREF="/cgi-bin/man/man2html?2+mkdir">mkdir</A></B>(2).
|
|
|
|
<P>
|
|
|
|
Alternatively, if the parent directory has a default ACL (see
|
|
<B><A HREF="/cgi-bin/man/man2html?5+acl">acl</A></B>(5)),
|
|
|
|
the umask is ignored, the default ACL is inherited,
|
|
the permission bits are set based on the inherited ACL,
|
|
and permission bits absent in the
|
|
<I>mode</I>
|
|
|
|
argument are turned off.
|
|
For example, the following default ACL is equivalent to a umask of 022:
|
|
<P>
|
|
|
|
<BR> u::rwx,g::r-x,o::r-x
|
|
<P>
|
|
|
|
Combining the effect of this default ACL with a
|
|
<I>mode</I>
|
|
|
|
argument of 0666 (rw-rw-rw-), the resulting file permissions would be 0644
|
|
(rw-r--r--).
|
|
<P>
|
|
|
|
The constants that should be used to specify
|
|
<I>mask</I>
|
|
|
|
are described in
|
|
<B><A HREF="/cgi-bin/man/man2html?7+inode">inode</A></B>(7).
|
|
|
|
<P>
|
|
|
|
The typical default value for the process umask is
|
|
<I>S_IWGRP | S_IWOTH</I>
|
|
|
|
(octal 022).
|
|
In the usual case where the
|
|
<I>mode</I>
|
|
|
|
argument to
|
|
<B><A HREF="/cgi-bin/man/man2html?2+open">open</A></B>(2)
|
|
|
|
is specified as:
|
|
<P>
|
|
|
|
|
|
|
|
S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH
|
|
|
|
|
|
<P>
|
|
|
|
(octal 0666) when creating a new file, the permissions on the
|
|
resulting file will be:
|
|
<P>
|
|
|
|
|
|
|
|
S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH
|
|
|
|
|
|
<P>
|
|
|
|
(because 0666 & ~022 = 0644; i.e., rw-r--r--).
|
|
<A NAME="lbAE"> </A>
|
|
<H2>RETURN VALUE</H2>
|
|
|
|
This system call always succeeds and the previous value of the mask
|
|
is returned.
|
|
<A NAME="lbAF"> </A>
|
|
<H2>CONFORMING TO</H2>
|
|
|
|
POSIX.1-2001, POSIX.1-2008, SVr4, 4.3BSD.
|
|
<A NAME="lbAG"> </A>
|
|
<H2>NOTES</H2>
|
|
|
|
A child process created via
|
|
<B><A HREF="/cgi-bin/man/man2html?2+fork">fork</A></B>(2)
|
|
|
|
inherits its parent's umask.
|
|
The umask is left unchanged by
|
|
<B><A HREF="/cgi-bin/man/man2html?2+execve">execve</A></B>(2).
|
|
|
|
<P>
|
|
|
|
It is impossible to use
|
|
<B>umask</B>()
|
|
|
|
to fetch a process's umask without at the same time changing it.
|
|
A second call to
|
|
<B>umask</B>()
|
|
|
|
would then be needed to restore the umask.
|
|
The nonatomicity of these two steps provides the potential
|
|
for races in multithreaded programs.
|
|
<P>
|
|
|
|
Since Linux 4.7, the umask of any process can be viewed via the
|
|
<I>Umask</I>
|
|
|
|
field of
|
|
<I>/proc/[pid]/status</I>.
|
|
|
|
Inspecting this field in
|
|
<I>/proc/self/status</I>
|
|
|
|
allows a process to retrieve its umask without at the same time changing it.
|
|
<P>
|
|
|
|
The umask setting also affects the permissions assigned to POSIX IPC objects
|
|
(<B><A HREF="/cgi-bin/man/man2html?3+mq_open">mq_open</A></B>(3),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?3+sem_open">sem_open</A></B>(3),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?3+shm_open">shm_open</A></B>(3)),
|
|
|
|
FIFOs
|
|
(<B><A HREF="/cgi-bin/man/man2html?3+mkfifo">mkfifo</A></B>(3)),
|
|
|
|
and UNIX domain sockets
|
|
(<B><A HREF="/cgi-bin/man/man2html?7+unix">unix</A></B>(7))
|
|
|
|
created by the process.
|
|
The umask does not affect the permissions assigned
|
|
to System V IPC objects created by the process (using
|
|
<B><A HREF="/cgi-bin/man/man2html?2+msgget">msgget</A></B>(2),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?2+semget">semget</A></B>(2),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?2+shmget">shmget</A></B>(2)).
|
|
|
|
<A NAME="lbAH"> </A>
|
|
<H2>SEE ALSO</H2>
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?2+chmod">chmod</A></B>(2),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?2+mkdir">mkdir</A></B>(2),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?2+open">open</A></B>(2),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?2+stat">stat</A></B>(2),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?5+acl">acl</A></B>(5)
|
|
|
|
<A NAME="lbAI"> </A>
|
|
<H2>COLOPHON</H2>
|
|
|
|
This page is part of release 5.05 of the Linux
|
|
<I>man-pages</I>
|
|
|
|
project.
|
|
A description of the project,
|
|
information about reporting bugs,
|
|
and the latest version of this page,
|
|
can be found at
|
|
<A HREF="https://www.kernel.org/doc/man-pages/.">https://www.kernel.org/doc/man-pages/.</A>
|
|
<P>
|
|
|
|
<HR>
|
|
<A NAME="index"> </A><H2>Index</H2>
|
|
<DL>
|
|
<DT id="1"><A HREF="#lbAB">NAME</A><DD>
|
|
<DT id="2"><A HREF="#lbAC">SYNOPSIS</A><DD>
|
|
<DT id="3"><A HREF="#lbAD">DESCRIPTION</A><DD>
|
|
<DT id="4"><A HREF="#lbAE">RETURN VALUE</A><DD>
|
|
<DT id="5"><A HREF="#lbAF">CONFORMING TO</A><DD>
|
|
<DT id="6"><A HREF="#lbAG">NOTES</A><DD>
|
|
<DT id="7"><A HREF="#lbAH">SEE ALSO</A><DD>
|
|
<DT id="8"><A HREF="#lbAI">COLOPHON</A><DD>
|
|
</DL>
|
|
<HR>
|
|
This document was created by
|
|
<A HREF="/cgi-bin/man/man2html">man2html</A>,
|
|
using the manual pages.<BR>
|
|
Time: 00:05:35 GMT, March 31, 2021
|
|
</BODY>
|
|
</HTML>
|