1 .\" Copyright (c) 1980, 1991, 1993
2 .\" The Regents of the University of California. All rights reserved.
4 .\" Redistribution and use in source and binary forms, with or without
5 .\" modification, are permitted provided that the following conditions
7 .\" 1. Redistributions of source code must retain the above copyright
8 .\" notice, this list of conditions and the following disclaimer.
9 .\" 2. Redistributions in binary form must reproduce the above copyright
10 .\" notice, this list of conditions and the following disclaimer in the
11 .\" documentation and/or other materials provided with the distribution.
12 .\" 3. Neither the name of the University nor the names of its contributors
13 .\" may be used to endorse or promote products derived from this software
14 .\" without specific prior written permission.
16 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
17 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
20 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 .Nd change mode of file
42 .Fn chmod "const char *path" "mode_t mode"
44 .Fn fchmod "int fd" "mode_t mode"
46 .Fn lchmod "const char *path" "mode_t mode"
48 .Fn fchmodat "int fd" "const char *path" "mode_t mode" "int flag"
50 The file permission bits of the file named specified by
52 or referenced by the file descriptor
58 system call verifies that the process owner (user) either owns
67 system call follows symbolic links to operate on the target of the link
68 rather than the link itself.
72 system call is similar to
74 but does not follow symbolic links.
78 is equivalent to either
84 except in the case where
86 specifies a relative path.
87 In this case the file to be changed is determined relative to the directory
88 associated with the file descriptor
90 instead of the current working directory.
93 are constructed by a bitwise-inclusive OR of flags from the following list, defined
96 .Bl -tag -width indent
97 .It Dv AT_SYMLINK_NOFOLLOW
100 names a symbolic link, then the mode of the symbolic link is changed.
101 .It Dv AT_RESOLVE_BENEATH
102 Only walk paths below the directory specified by the
105 See the description of the
106 .Dv O_RESOLVE_BENEATH
113 argument is an empty string, operate on the file or directory
114 referenced by the descriptor
120 operate on the current working directory.
125 is passed the special value
129 parameter, the current working directory is used.
132 is zero, the behavior is identical to a call to
135 A mode is created from
141 .Bd -literal -offset indent -compact
142 #define S_IRWXU 0000700 /* RWX mask for owner */
143 #define S_IRUSR 0000400 /* R for owner */
144 #define S_IWUSR 0000200 /* W for owner */
145 #define S_IXUSR 0000100 /* X for owner */
147 #define S_IRWXG 0000070 /* RWX mask for group */
148 #define S_IRGRP 0000040 /* R for group */
149 #define S_IWGRP 0000020 /* W for group */
150 #define S_IXGRP 0000010 /* X for group */
152 #define S_IRWXO 0000007 /* RWX mask for other */
153 #define S_IROTH 0000004 /* R for other */
154 #define S_IWOTH 0000002 /* W for other */
155 #define S_IXOTH 0000001 /* X for other */
157 #define S_ISUID 0004000 /* set user id on execution */
158 #define S_ISGID 0002000 /* set group id on execution */
159 #define S_ISVTX 0001000 /* sticky bit */
169 VM system totally ignores the sticky bit
172 On UFS-based file systems (FFS, LFS) the sticky
173 bit may only be set upon directories.
177 (the `sticky bit') is set on a directory,
178 an unprivileged user may not delete or rename
179 files of other users in that directory.
180 The sticky bit may be
181 set by any user on a directory which the user owns or has appropriate
183 For more details of the properties of the sticky bit, see
186 If mode ISUID (set UID) is set on a directory,
187 and the MNT_SUIDDIR option was used in the mount of the file system,
188 then the owner of any new files and sub-directories
189 created within this directory are set
190 to be the same as the owner of that directory.
191 If this function is enabled, new directories will inherit
192 the bit from their parents.
193 Execute bits are removed from
194 the file, and it will not be given to root.
195 This behavior does not change the
196 requirements for the user to be allowed to write the file, but only the eventual
197 owner after it has been created.
198 Group inheritance is not affected.
200 This feature is designed for use on fileservers serving PC users via
201 ftp, SAMBA, or netatalk.
202 It provides security holes for shell users and as
203 such should not be used on shell machines, especially on home directories.
204 This option requires the SUIDDIR
205 option in the kernel to work.
206 Only UFS file systems support this option.
207 For more details of the suiddir mount option, see
210 Writing or changing the owner of a file
211 turns off the set-user-id and set-group-id bits
212 unless the user is the super-user.
213 This makes the system somewhat more secure
214 by protecting set-user-id (set-group-id) files
215 from remaining set-user-id (set-group-id) if they are modified,
216 at the expense of a degree of compatibility.
223 will fail and the file mode will be unchanged if:
226 A component of the path prefix is not a directory.
227 .It Bq Er ENAMETOOLONG
228 A component of a pathname exceeded 255 characters,
229 or an entire path name exceeded 1023 characters.
231 The named file does not exist.
233 Search permission is denied for a component of the path prefix.
235 Too many symbolic links were encountered in translating the pathname.
237 The effective user ID does not match the owner of the file and
238 the effective user ID is not the super-user.
240 The effective user ID is not the super-user, the effective user ID do match the
241 owner of the file, but the group ID of the file does not match the effective
242 group ID nor one of the supplementary group IDs.
244 The named file has its immutable or append-only flag set, see the
246 manual page for more information.
248 The named file resides on a read-only file system.
253 points outside the process's allocated address space.
255 An I/O error occurred while reading from or writing to the file system.
257 Corrupted data was detected while reading from the file system.
259 The effective user ID is not the super-user, the mode includes the sticky bit
261 and path does not refer to a directory.
266 system call will fail if:
269 The descriptor is not valid.
274 refers to a socket, not to a file.
276 The file resides on a read-only file system.
278 An I/O error occurred while reading from or writing to the file system.
280 Corrupted data was detected while reading from the file system.
292 argument does not specify an absolute path and the
296 nor a valid file descriptor open for searching.
300 argument is not valid.
304 argument is not an absolute path and
308 nor a file descriptor associated with a directory.
309 .It Bq Er ENOTCAPABLE
312 or contained a ".." component leading to a
313 directory outside of the directory hierarchy specified by
315 and the process is in capability mode or the
316 .Dv AT_RESOLVE_BENEATH
329 system call is expected to conform to
331 except for the return of
335 bit on directories is expected to conform to
339 system call is expected to conform to
348 system call appeared in
352 system call appeared in
356 system call appeared in