OSDN Git Service

LDP: Update original to LDP v3.79
[linuxjm/LDP_man-pages.git] / original / 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 .\" %%%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 2008-01-09 "Linux" "Linux Programmer's Manual"
35 .SH NAME
36 umask \- set file mode creation mask
37 .SH SYNOPSIS
38 .B #include <sys/types.h>
39 .br
40 .B #include <sys/stat.h>
41 .sp
42 .BI "mode_t umask(mode_t " mask );
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
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
66 The constants that should be used to specify
67 .I mask
68 are described under
69 .BR stat (2).
70
71 The typical default value for the process umask is
72 .I S_IWGRP\ |\ S_IWOTH
73 (octal 022).
74 In the usual case where the
75 .I mode
76 argument to
77 .BR open (2)
78 is specified as:
79 .nf
80
81     S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH
82
83 .fi
84 (octal 0666) when creating a new file, the permissions on the
85 resulting file will be:
86 .nf
87
88     S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH
89
90 .fi
91 (because 0666 & ~022 = 0644; i.e., rw\-r\-\-r\-\-).
92 .SH RETURN VALUE
93 This system call always succeeds and the previous value of the mask
94 is returned.
95 .SH CONFORMING TO
96 SVr4, 4.3BSD, POSIX.1-2001.
97 .SH NOTES
98 A child process created via
99 .BR fork (2)
100 inherits its parent's umask.
101 The umask is left unchanged by
102 .BR execve (2).
103
104 The umask setting also affects the permissions assigned to POSIX IPC objects
105 .RB ( mq_open (3),
106 .BR sem_open (3),
107 .BR shm_open (3)),
108 FIFOs
109 .RB ( mkfifo (3)),
110 and UNIX domain sockets
111 .RB ( unix (7))
112 created by the process.
113 The umask does not affect the permissions assigned
114 to System\ V IPC objects created by the process (using
115 .BR msgget (2),
116 .BR semget (2),
117 .BR shmget (2)).
118 .SH SEE ALSO
119 .BR chmod (2),
120 .BR mkdir (2),
121 .BR open (2),
122 .BR stat (2),
123 .BR acl (5)
124 .SH COLOPHON
125 This page is part of release 3.79 of the Linux
126 .I man-pages
127 project.
128 A description of the project,
129 information about reporting bugs,
130 and the latest version of this page,
131 can be found at
132 \%http://www.kernel.org/doc/man\-pages/.