]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man2/chmod.2
1022cc3f21973cc116d18011c0cbc14c061e6734
[thirdparty/man-pages.git] / man2 / chmod.2
1 .\" Hey Emacs! This file is -*- nroff -*- source.
2 .\"
3 .\" Copyright (c) 1992 Drew Eckhardt (drew@cs.colorado.edu), March 28, 1992
4 .\"
5 .\" Permission is granted to make and distribute verbatim copies of this
6 .\" manual provided the copyright notice and this permission notice are
7 .\" preserved on all copies.
8 .\"
9 .\" Permission is granted to copy and distribute modified versions of this
10 .\" manual under the conditions for verbatim copying, provided that the
11 .\" entire resulting derived work is distributed under the terms of a
12 .\" permission notice identical to this one.
13 .\"
14 .\" Since the Linux kernel and libraries are constantly changing, this
15 .\" manual page may be incorrect or out-of-date. The author(s) assume no
16 .\" responsibility for errors or omissions, or for damages resulting from
17 .\" the use of the information contained herein. The author(s) may not
18 .\" have taken the same level of care in the production of this manual,
19 .\" which is licensed free of charge, as they might when working
20 .\" professionally.
21 .\"
22 .\" Formatted or processed versions of this manual, if unaccompanied by
23 .\" the source, must acknowledge the copyright and authors of this work.
24 .\"
25 .\" Modified by Michael Haardt <michael@moria.de>
26 .\" Modified 1993-07-21 by Rik Faith <faith@cs.unc.edu>
27 .\" Modified 1997-01-12 by Michael Haardt
28 .\" <michael@cantor.informatik.rwth-aachen.de>: NFS details
29 .\" Modified 2004-06-23 by Michael Kerrisk <mtk.manpages@gmail.com>
30 .\"
31 .TH CHMOD 2 2010-09-20 "Linux" "Linux Programmer's Manual"
32 .SH NAME
33 chmod, fchmod \- change permissions of a file
34 .SH SYNOPSIS
35 .B #include <sys/stat.h>
36 .sp
37 .BI "int chmod(const char *" path ", mode_t " mode );
38 .br
39 .BI "int fchmod(int " fd ", mode_t " mode );
40 .sp
41 .in -4n
42 Feature Test Macro Requirements for glibc (see
43 .BR feature_test_macros (7)):
44 .in
45 .sp
46 .ad l
47 .PD 0
48 .BR fchmod ():
49 .RS 4
50 .TP 4
51 Since glibc 2.12:
52 _POSIX_C_SOURCE\ >=\ 200809L ||
53 _BSD_SOURCE ||
54 _XOPEN_SOURCE\ >=\ 500 ||
55 _XOPEN_SOURCE\ &&\ _XOPEN_SOURCE_EXTENDED
56 .TP
57 Before glibc 2.12:
58 _BSD_SOURCE ||
59 _XOPEN_SOURCE\ >=\ 500 ||
60 _XOPEN_SOURCE\ &&\ _XOPEN_SOURCE_EXTENDED
61 .RE
62 .PD
63 .ad
64 .SH DESCRIPTION
65 These system calls change the permissions of a file.
66 They differ only in how the file is specified:
67 .IP * 2
68 .BR chmod ()
69 changes the permissions of the file specified whose pathname is given in
70 .IR path ,
71 which is dereferenced if it is a symbolic link.
72 .IP *
73 .BR fchmod ()
74 changes the permissions of the file referred to by the open file descriptor
75 .IR fd .
76 .PP
77 The new file permissions are specified in
78 .IR mode ,
79 which is a bit mask created by ORing together zero or
80 more of the following:
81 .TP 18
82 .BR S_ISUID " (04000)"
83 set-user-ID (set process effective user ID on
84 .BR execve (2))
85 .TP
86 .BR S_ISGID " (02000)"
87 set-group-ID (set process effective group ID on
88 .BR execve (2);
89 mandatory locking, as described in
90 .BR fcntl (2);
91 take a new file's group from parent directory, as described in
92 .BR chown (2)
93 and
94 .BR mkdir (2))
95 .TP
96 .BR S_ISVTX " (01000)"
97 sticky bit (restricted deletion flag, as described in
98 .BR unlink (2))
99 .TP
100 .BR S_IRUSR " (00400)"
101 read by owner
102 .TP
103 .BR S_IWUSR " (00200)"
104 write by owner
105 .TP
106 .BR S_IXUSR " (00100)"
107 execute/search by owner ("search" applies for directories,
108 and means that entries within the directory can be accessed)
109 .TP
110 .BR S_IRGRP " (00040)"
111 read by group
112 .TP
113 .BR S_IWGRP " (00020)"
114 write by group
115 .TP
116 .BR S_IXGRP " (00010)"
117 execute/search by group
118 .TP
119 .BR S_IROTH " (00004)"
120 read by others
121 .TP
122 .BR S_IWOTH " (00002)"
123 write by others
124 .TP
125 .BR S_IXOTH " (00001)"
126 execute/search by others
127 .PP
128 The effective UID of the calling process must match the owner of the file,
129 or the process must be privileged (Linux: it must have the
130 .B CAP_FOWNER
131 capability).
132
133 If the calling process is not privileged (Linux: does not have the
134 .B CAP_FSETID
135 capability), and the group of the file does not match
136 the effective group ID of the process or one of its
137 supplementary group IDs, the
138 .B S_ISGID
139 bit will be turned off,
140 but this will not cause an error to be returned.
141
142 As a security measure, depending on the file system,
143 the set-user-ID and set-group-ID execution bits
144 may be turned off if a file is written.
145 (On Linux this occurs if the writing process does not have the
146 .B CAP_FSETID
147 capability.)
148 On some file systems, only the superuser can set the sticky bit,
149 which may have a special meaning.
150 For the sticky bit, and for set-user-ID and set-group-ID bits on
151 directories, see
152 .BR stat (2).
153
154 On NFS file systems, restricting the permissions will immediately influence
155 already open files, because the access control is done on the server, but
156 open files are maintained by the client.
157 Widening the permissions may be
158 delayed for other clients if attribute caching is enabled on them.
159 .SH "RETURN VALUE"
160 On success, zero is returned.
161 On error, \-1 is returned, and
162 .I errno
163 is set appropriately.
164 .SH ERRORS
165 Depending on the file system, other errors can be returned.
166 The more general errors for
167 .BR chmod ()
168 are listed below:
169 .TP
170 .B EACCES
171 Search permission is denied on a component of the path prefix.
172 (See also
173 .BR path_resolution (7).)
174 .TP
175 .B EFAULT
176 .I path
177 points outside your accessible address space.
178 .TP
179 .B EIO
180 An I/O error occurred.
181 .TP
182 .B ELOOP
183 Too many symbolic links were encountered in resolving
184 .IR path .
185 .TP
186 .B ENAMETOOLONG
187 .I path
188 is too long.
189 .TP
190 .B ENOENT
191 The file does not exist.
192 .TP
193 .B ENOMEM
194 Insufficient kernel memory was available.
195 .TP
196 .B ENOTDIR
197 A component of the path prefix is not a directory.
198 .TP
199 .B EPERM
200 The effective UID does not match the owner of the file,
201 and the process is not privileged (Linux: it does not have the
202 .B CAP_FOWNER
203 capability).
204 .TP
205 .B EROFS
206 The named file resides on a read-only file system.
207 .PP
208 The general errors for
209 .BR fchmod ()
210 are listed below:
211 .TP
212 .B EBADF
213 The file descriptor
214 .I fd
215 is not valid.
216 .TP
217 .B EIO
218 See above.
219 .TP
220 .B EPERM
221 See above.
222 .TP
223 .B EROFS
224 See above.
225 .SH "CONFORMING TO"
226 4.4BSD, SVr4, POSIX.1-2001.
227 .SH "SEE ALSO"
228 .BR chown (2),
229 .BR execve (2),
230 .BR fchmodat (2),
231 .BR open (2),
232 .BR stat (2),
233 .BR path_resolution (7)