]> git.saurik.com Git - apple/xnu.git/blame_incremental - bsd/man/man2/chown.2
xnu-1228.7.58.tar.gz
[apple/xnu.git] / bsd / man / man2 / chown.2
... / ...
CommitLineData
1.\" Copyright (c) 1980, 1991, 1993, 1994
2.\" The Regents of the University of California. All rights reserved.
3.\"
4.\" Redistribution and use in source and binary forms, with or without
5.\" modification, are permitted provided that the following conditions
6.\" are met:
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. All advertising materials mentioning features or use of this software
13.\" must display the following acknowledgement:
14.\" This product includes software developed by the University of
15.\" California, Berkeley and its contributors.
16.\" 4. Neither the name of the University nor the names of its contributors
17.\" may be used to endorse or promote products derived from this software
18.\" without specific prior written permission.
19.\"
20.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30.\" SUCH DAMAGE.
31.\"
32.\" @(#)chown.2 8.4 (Berkeley) 4/19/94
33.\"
34.Dd April 19, 1994
35.Dt CHOWN 2
36.Os
37.Sh NAME
38.Nm chown ,
39.Nm fchown ,
40.Nm lchown
41.Nd change owner and group of a file
42.Sh SYNOPSIS
43.In unistd.h
44.Ft int
45.Fo chown
46.Fa "const char *path"
47.Fa "uid_t owner"
48.Fa "gid_t group"
49.Fc
50.Ft int
51.Fo fchown
52.Fa "int fildes"
53.Fa "uid_t owner"
54.Fa "gid_t group"
55.Fc
56.Ft int
57.Fo lchown
58.Fa "const char *path"
59.Fa "uid_t owner"
60.Fa "gid_t group"
61.Fc
62.Sh DESCRIPTION
63The owner ID and group ID of the file
64named by
65.Fa path
66or referenced by
67.Fa fildes
68is changed as specified by the arguments
69.Fa owner
70and
71.Fa group .
72The owner of a file may change the
73.Fa group
74to a group of which
75he or she is a member,
76but the change
77.Fa owner
78capability is restricted to the super-user.
79.Pp
80The
81.Fn chown
82system call
83clears the set-user-id and set-group-id bits
84on the file
85to prevent accidental or mischievous creation of
86set-user-id and set-group-id programs if not executed
87by the super-user.
88The
89.Fn chown
90system call
91follows symbolic links to operate on the target of the link
92rather than the link itself.
93.Pp
94The
95.Fn fchown
96system call
97is particularly useful when used in conjunction
98with the file locking primitives (see
99.Xr flock 2 ) .
100.Pp
101The
102.Fn lchown
103system call is similar to
104.Fn chown
105but does not follow symbolic links.
106.Pp
107One of the owner or group id's
108may be left unchanged by specifying it as -1.
109.Sh RETURN VALUES
110.Rv -std
111.Sh ERRORS
112.Pp
113The
114.Fn chown
115and
116.Fn lchown
117system calls will fail if:
118.Bl -tag -width Er
119.\" ==========
120.It Bq Er EACCES
121Search permission is denied for a component of the path prefix.
122.It Bq Er EFAULT
123The
124.Fa path
125argument
126points outside the process's allocated address space.
127.\" ==========
128.It Bq Er ELOOP
129Too many symbolic links are encountered in translating the pathname.
130This is taken to be indicative of a looping symbolic link.
131.\" ==========
132.It Bq Er ENAMETOOLONG
133A component of a pathname exceeded 255 characters,
134or an entire path name exceeded 1023 characters.
135.\" ==========
136.It Bq Er ENOENT
137A component of
138.Fa path
139does not exist.
140.\" ==========
141.It Bq Er ENOTDIR
142A component of the path prefix is not a directory.
143.El
144.Pp
145The
146.Fn fchown
147system call will fail if:
148.Bl -tag -width Er
149.\" ==========
150.It Bq Er EBADF
151The
152.Fa fildes
153argument
154does not refer to a valid descriptor.
155.\" ==========
156.It Bq Er EINVAL
157The
158.Fa fildes
159argument
160refers to a socket, not a file.
161.El
162.Pp
163Any of these calls will fail if:
164.Bl -tag -width Er
165.\" ==========
166.It Bq Er EINTR
167Its execution is interrupted by a signal.
168.\" ==========
169.It Bq Er EIO
170An I/O error occurs while reading from or writing to the file system.
171.\" ==========
172.It Bq Er EPERM
173The effective user ID does not match the owner of the file
174and the calling process does not have appropriate (i.e., root) privileges.
175.\" ==========
176.It Bq Er EROFS
177The named file resides on a read-only file system.
178.El
179.Sh SEE ALSO
180.Xr chgrp 1 ,
181.Xr chmod 2 ,
182.Xr flock 2 ,
183.Xr chown 8
184.Sh STANDARDS
185The
186.Fn chown
187system call is expected to conform to
188.St -p1003.1-90 .
189.Sh HISTORY
190The
191.Fn chown
192function appeared in
193.At v7 .
194The
195.Fn fchown
196system call appeared in
197.Bx 4.2 .
198.Pp
199The
200.Fn chown
201and
202.Fn fchown
203system calls were changed to follow symbolic links in
204.Bx 4.4 .
205The
206.Fn lchown
207system call was added in
208.Fx 3.0
209to compensate for the loss of functionality.