OSDN Git Service

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