OSDN Git Service

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