OSDN Git Service

(split) LDP man-pages の original/ を v3.29 に更新。
[linuxjm/LDP_man-pages.git] / original / 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-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 .PD
56 .ad
57 .SH DESCRIPTION
58 These system calls change the permissions of a file.
59 They differ only in how the file is specified:
60 .IP * 2
61 .BR chmod ()
62 changes the permissions of the file specified whose pathname is given in
63 .IR path ,
64 which is dereferenced if it is a symbolic link.
65 .IP *
66 .BR fchmod ()
67 changes the permissions of the file referred to by the open file descriptor
68 .IR fd .
69 .PP
70 The new file permissions are specified in
71 .IR mode ,
72 which is a bit mask created by ORing together zero or
73 more of the following:
74 .TP 18
75 .BR S_ISUID "  (04000)"
76 set-user-ID (set process effective user ID on
77 .BR execve (2))
78 .TP
79 .BR S_ISGID "  (02000)"
80 set-group-ID (set process effective group ID on
81 .BR execve (2);
82 mandatory locking, as described in
83 .BR fcntl (2);
84 take a new file's group from parent directory, as described in
85 .BR chown (2)
86 and
87 .BR mkdir (2))
88 .TP
89 .BR S_ISVTX "  (01000)"
90 sticky bit (restricted deletion flag, as described in
91 .BR unlink (2))
92 .TP
93 .BR S_IRUSR "  (00400)"
94 read by owner
95 .TP
96 .BR S_IWUSR "  (00200)"
97 write by owner
98 .TP
99 .BR S_IXUSR "  (00100)"
100 execute/search by owner ("search" applies for directories,
101 and means that entries within the directory can be accessed)
102 .TP
103 .BR S_IRGRP "  (00040)"
104 read by group
105 .TP
106 .BR S_IWGRP "  (00020)"
107 write by group
108 .TP
109 .BR S_IXGRP "  (00010)"
110 execute/search by group
111 .TP
112 .BR S_IROTH "  (00004)"
113 read by others
114 .TP
115 .BR S_IWOTH "  (00002)"
116 write by others
117 .TP
118 .BR S_IXOTH "  (00001)"
119 execute/search by others
120 .PP
121 The effective UID of the calling process must match the owner of the file,
122 or the process must be privileged (Linux: it must have the
123 .B CAP_FOWNER
124 capability).
125
126 If the calling process is not privileged (Linux: does not have the
127 .B CAP_FSETID
128 capability), and the group of the file does not match
129 the effective group ID of the process or one of its
130 supplementary group IDs, the
131 .B S_ISGID
132 bit will be turned off,
133 but this will not cause an error to be returned.
134
135 As a security measure, depending on the file system,
136 the set-user-ID and set-group-ID execution bits
137 may be turned off if a file is written.
138 (On Linux this occurs if the writing process does not have the
139 .B CAP_FSETID
140 capability.)
141 On some file systems, only the superuser can set the sticky bit,
142 which may have a special meaning.
143 For the sticky bit, and for set-user-ID and set-group-ID bits on
144 directories, see
145 .BR stat (2).
146
147 On NFS file systems, restricting the permissions will immediately influence
148 already open files, because the access control is done on the server, but
149 open files are maintained by the client.
150 Widening the permissions may be
151 delayed for other clients if attribute caching is enabled on them.
152 .SH "RETURN VALUE"
153 On success, zero is returned.
154 On error, \-1 is returned, and
155 .I errno
156 is set appropriately.
157 .SH ERRORS
158 Depending on the file system, other errors can be returned.
159 The more general errors for
160 .BR chmod ()
161 are listed below:
162 .TP
163 .B EACCES
164 Search permission is denied on a component of the path prefix.
165 (See also
166 .BR path_resolution (7).)
167 .TP
168 .B EFAULT
169 .I path
170 points outside your accessible address space.
171 .TP
172 .B EIO
173 An I/O error occurred.
174 .TP
175 .B ELOOP
176 Too many symbolic links were encountered in resolving
177 .IR path .
178 .TP
179 .B ENAMETOOLONG
180 .I path
181 is too long.
182 .TP
183 .B ENOENT
184 The file does not exist.
185 .TP
186 .B ENOMEM
187 Insufficient kernel memory was available.
188 .TP
189 .B ENOTDIR
190 A component of the path prefix is not a directory.
191 .TP
192 .B EPERM
193 The effective UID does not match the owner of the file,
194 and the process is not privileged (Linux: it does not have the
195 .B CAP_FOWNER
196 capability).
197 .TP
198 .B EROFS
199 The named file resides on a read-only file system.
200 .PP
201 The general errors for
202 .BR fchmod ()
203 are listed below:
204 .TP
205 .B EBADF
206 The file descriptor
207 .I fd
208 is not valid.
209 .TP
210 .B EIO
211 See above.
212 .TP
213 .B EPERM
214 See above.
215 .TP
216 .B EROFS
217 See above.
218 .SH "CONFORMING TO"
219 4.4BSD, SVr4, POSIX.1-2001.
220 .SH "SEE ALSO"
221 .BR chown (2),
222 .BR execve (2),
223 .BR fchmodat (2),
224 .BR open (2),
225 .BR stat (2),
226 .BR path_resolution (7)