]> git.saurik.com Git - apple/xnu.git/blame_incremental - bsd/man/man2/chmod.2
xnu-1228.7.58.tar.gz
[apple/xnu.git] / bsd / man / man2 / chmod.2
... / ...
CommitLineData
1.\" $NetBSD: chmod.2,v 1.7 1995/02/27 12:32:06 cgd Exp $
2.\"
3.\" Copyright (c) 1980, 1991, 1993
4.\" The Regents of the University of California. All rights reserved.
5.\"
6.\" Redistribution and use in source and binary forms, with or without
7.\" modification, are permitted provided that the following conditions
8.\" are met:
9.\" 1. Redistributions of source code must retain the above copyright
10.\" notice, this list of conditions and the following disclaimer.
11.\" 2. Redistributions in binary form must reproduce the above copyright
12.\" notice, this list of conditions and the following disclaimer in the
13.\" documentation and/or other materials provided with the distribution.
14.\" 3. All advertising materials mentioning features or use of this software
15.\" must display the following acknowledgement:
16.\" This product includes software developed by the University of
17.\" California, Berkeley and its contributors.
18.\" 4. Neither the name of the University nor the names of its contributors
19.\" may be used to endorse or promote products derived from this software
20.\" without specific prior written permission.
21.\"
22.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32.\" SUCH DAMAGE.
33.\"
34.\" @(#)chmod.2 8.1 (Berkeley) 6/4/93
35.\"
36.Dd June 4, 1993
37.Dt CHMOD 2
38.Os BSD 4
39.Sh NAME
40.Nm chmod ,
41.Nm fchmod
42.Nd change mode of file
43.Sh SYNOPSIS
44.Fd #include <sys/types.h>
45.Fd #include <sys/stat.h>
46.Ft int
47.Fo chmod
48.Fa "const char *path"
49.Fa "mode_t mode"
50.Fc
51.Ft int
52.Fo fchmod
53.Fa "int fildes"
54.Fa "mode_t mode"
55.Fc
56.Sh DESCRIPTION
57The function
58.Fn chmod
59sets the file permission bits
60of the file
61specified by the pathname
62.Fa path
63to
64.Fa mode .
65.Fn Fchmod
66sets the permission bits of the specified
67file descriptor
68.Fa fildes .
69.Fn Chmod
70verifies that the process owner (user) either owns
71the file specified by
72.Fa path
73(or
74.Fa fildes ) ,
75or
76is the super-user.
77A mode is created from
78.Em or'd
79permission bit masks
80defined in
81.Aq Pa sys/stat.h :
82.Bd -literal -offset indent -compact
83#define S_IRWXU 0000700 /* RWX mask for owner */
84#define S_IRUSR 0000400 /* R for owner */
85#define S_IWUSR 0000200 /* W for owner */
86#define S_IXUSR 0000100 /* X for owner */
87
88#define S_IRWXG 0000070 /* RWX mask for group */
89#define S_IRGRP 0000040 /* R for group */
90#define S_IWGRP 0000020 /* W for group */
91#define S_IXGRP 0000010 /* X for group */
92
93#define S_IRWXO 0000007 /* RWX mask for other */
94#define S_IROTH 0000004 /* R for other */
95#define S_IWOTH 0000002 /* W for other */
96#define S_IXOTH 0000001 /* X for other */
97
98#define S_ISUID 0004000 /* set user id on execution */
99#define S_ISGID 0002000 /* set group id on execution */
100#define S_ISVTX 0001000 /* save swapped text even after use */
101.Ed
102.Pp
103The
104.Dv ISVTX
105(the
106.Em sticky bit )
107indicates to the system which executable files are shareable (the
108default) and the system maintains the program text of the files
109in the swap area. The sticky bit may only be set by the super user
110on shareable executable files.
111.Pp
112If mode
113.Dv ISVTX
114(the `sticky bit') is set on a directory,
115an unprivileged user may not delete or rename
116files of other users in that directory. The sticky bit may be
117set by any user on a directory which the user owns or has appropriate
118permissions.
119For more details of the properties of the sticky bit, see
120.Xr sticky 8 .
121.Pp
122Writing or changing the owner of a file
123turns off the set-user-id and set-group-id bits
124unless the user is the super-user.
125This makes the system somewhat more secure
126by protecting set-user-id (set-group-id) files
127from remaining set-user-id (set-group-id) if they are modified,
128at the expense of a degree of compatibility.
129.Sh RETURN VALUES
130Upon successful completion, a value of 0 is returned.
131Otherwise, a value of -1 is returned and
132.Va errno
133is set to indicate the error.
134.Sh ERRORS
135The
136.Fn chmod
137system call will fail and the file mode will be unchanged if:
138.Bl -tag -width Er
139.\" ==========
140.It Bq Er EACCES
141Search permission is denied for a component of the path prefix.
142.\" ==========
143.It Bq Er EFAULT
144.Fa Path
145points outside the process's allocated address space.
146.\" ==========
147.It Bq Er EINTR
148Its execution was interrupted by a signal.
149.\" ==========
150.It Bq Er EIO
151An I/O error occurred while reading from or writing to the file system.
152.\" ==========
153.It Bq Er ELOOP
154Too many symbolic links were encountered in translating the pathname.
155This is taken to be indicative of a looping symbolic link.
156.\" ==========
157.It Bq Er ENAMETOOLONG
158A component of a pathname exceeded
159.Dv {NAME_MAX}
160characters, or an entire path name exceeded
161.Dv {PATH_MAX}
162characters.
163.\" ==========
164.It Bq Er ENOENT
165The named file does not exist.
166.\" ==========
167.It Bq Er ENOTDIR
168A component of the path prefix is not a directory.
169.\" ==========
170.It Bq Er EPERM
171The effective user ID does not match the owner of the file and
172the effective user ID is not the super-user.
173.\" ==========
174.It Bq Er EROFS
175The named file resides on a read-only file system.
176.El
177.Pp
178.Fn fchmod
179will fail if:
180.Bl -tag -width Er
181.\" ==========
182.It Bq Er EBADF
183.Fa fildes
184is not a valid file descriptor.
185.\" ==========
186.It Bq Er EINVAL
187.Fa fildes
188refers to a socket, not to a file.
189.\" ==========
190.It Bq Er EINVAL
191.Fa mode
192is not a valid file mode.
193.\" ==========
194.It Bq Er EINTR
195Its execution was interrupted by a signal.
196.\" ==========
197.It Bq Er EIO
198An I/O error occurred while reading from or writing to the file system.
199.\" ==========
200.It Bq Er EPERM
201The effective user ID does not match the owner of the file and
202the effective user ID is not the super-user.
203.\" ==========
204.It Bq Er EROFS
205The file resides on a read-only file system.
206.El
207.Sh LEGACY SYNOPSIS
208.Fd #include <sys/types.h>
209.Fd #include <sys/stat.h>
210.Pp
211The include file
212.In sys/types.h
213is necessary.
214.Sh SEE ALSO
215.Xr chmod 1 ,
216.Xr chown 2 ,
217.Xr open 2 ,
218.Xr stat 2 ,
219.Xr compat 5 ,
220.Xr sticky 8
221.Sh STANDARDS
222The
223.Fn chmod
224function is expected to conform to
225.St -p1003.1-88 .
226.Sh HISTORY
227The
228.Fn fchmod
229function call
230appeared in
231.Bx 4.2 .