]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man2/chmod.2
Added/updated glibc feature test macro requirements
[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@gmx.net>
30 .\"
31 .TH CHMOD 2 2007-07-26 "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 " fildes ", 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 .BR fchmod ():
47 _BSD_SOURCE || _XOPEN_SOURCE\ >=\ 500
48 .SH DESCRIPTION
49 The mode of the file given by
50 .I path
51 or referenced by
52 .I fildes
53 is changed.
54
55 Modes are specified by
56 .IR or'ing
57 the following:
58 .RS
59 .TP 1.0i
60 .B S_ISUID
61 04000 set user ID on execution
62 .TP
63 .B S_ISGID
64 02000 set group ID on execution
65 .TP
66 .B S_ISVTX
67 01000 sticky bit
68 .TP
69 .B S_IRUSR
70 00400 read by owner
71 .TP
72 .B S_IWUSR
73 00200 write by owner
74 .TP
75 .B S_IXUSR
76 00100 execute/search by owner
77 .TP
78 .B S_IRGRP
79 00040 read by group
80 .TP
81 .B S_IWGRP
82 00020 write by group
83 .TP
84 .B S_IXGRP
85 00010 execute/search by group
86 .TP
87 .B S_IROTH
88 00004 read by others
89 .TP
90 .B S_IWOTH
91 00002 write by others
92 .TP
93 .B S_IXOTH
94 00001 execute/search by others
95 .RE
96 .PP
97 The effective UID of the calling process must match the owner of the file,
98 or the process must be privileged (Linux: it must have the
99 .B CAP_FOWNER
100 capability).
101
102 If the calling process is not privileged (Linux: does not have the
103 .B CAP_FSETID
104 capability), and the group of the file does not match
105 the effective group ID of the process or one of its
106 supplementary group IDs, the
107 .B S_ISGID
108 bit will be turned off,
109 but this will not cause an error to be returned.
110
111 As a security measure, depending on the file system,
112 the set-user-ID and set-group-ID execution bits
113 may be turned off if a file is written.
114 (On Linux this occurs if the writing process does not have the
115 .B CAP_FSETID
116 capability.)
117 On some file systems, only the superuser can set the sticky bit,
118 which may have a special meaning.
119 For the sticky bit, and for set-user-ID and set-group-ID bits on
120 directories, see
121 .BR stat (2).
122
123 On NFS file systems, restricting the permissions will immediately influence
124 already open files, because the access control is done on the server, but
125 open files are maintained by the client.
126 Widening the permissions may be
127 delayed for other clients if attribute caching is enabled on them.
128 .SH "RETURN VALUE"
129 On success, zero is returned.
130 On error, \-1 is returned, and
131 .I errno
132 is set appropriately.
133 .SH ERRORS
134 Depending on the file system, other errors can be returned.
135 The more general errors for
136 .BR chmod ()
137 are listed below:
138 .TP
139 .B EACCES
140 Search permission is denied on a component of the path prefix.
141 (See also
142 .BR path_resolution (7).)
143 .TP
144 .B EFAULT
145 .I path
146 points outside your accessible address space.
147 .TP
148 .B EIO
149 An I/O error occurred.
150 .TP
151 .B ELOOP
152 Too many symbolic links were encountered in resolving
153 .IR path .
154 .TP
155 .B ENAMETOOLONG
156 .I path
157 is too long.
158 .TP
159 .B ENOENT
160 The file does not exist.
161 .TP
162 .B ENOMEM
163 Insufficient kernel memory was available.
164 .TP
165 .B ENOTDIR
166 A component of the path prefix is not a directory.
167 .TP
168 .B EPERM
169 The effective UID does not match the owner of the file,
170 and the process is not privileged (Linux: it does not have the
171 .B CAP_FOWNER
172 capability).
173 .TP
174 .B EROFS
175 The named file resides on a read-only file system.
176 .PP
177 The general errors for
178 .BR fchmod ()
179 are listed below:
180 .TP
181 .B EBADF
182 The file descriptor
183 .I fildes
184 is not valid.
185 .TP
186 .B EIO
187 See above.
188 .TP
189 .B EPERM
190 See above.
191 .TP
192 .B EROFS
193 See above.
194 .SH "CONFORMING TO"
195 4.4BSD, SVr4, POSIX.1-2001.
196 .SH "SEE ALSO"
197 .BR chown (2),
198 .BR execve (2),
199 .BR fchmodat (2),
200 .BR open (2),
201 .BR stat (2),
202 .BR path_resolution (7)