]> git.saurik.com Git - apple/xnu.git/blame - bsd/man/man2/chown.2
xnu-1228.7.58.tar.gz
[apple/xnu.git] / bsd / man / man2 / chown.2
CommitLineData
9bccf70c
A
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.\"
91447636 34.Dd April 19, 1994
9bccf70c
A
35.Dt CHOWN 2
36.Os
37.Sh NAME
38.Nm chown ,
91447636
A
39.Nm fchown ,
40.Nm lchown
41.Nd change owner and group of a file
9bccf70c 42.Sh SYNOPSIS
91447636 43.In unistd.h
9bccf70c 44.Ft int
2d21ac55
A
45.Fo chown
46.Fa "const char *path"
47.Fa "uid_t owner"
48.Fa "gid_t group"
49.Fc
9bccf70c 50.Ft int
2d21ac55
A
51.Fo fchown
52.Fa "int fildes"
53.Fa "uid_t owner"
54.Fa "gid_t group"
55.Fc
91447636 56.Ft int
2d21ac55
A
57.Fo lchown
58.Fa "const char *path"
59.Fa "uid_t owner"
60.Fa "gid_t group"
61.Fc
9bccf70c 62.Sh DESCRIPTION
91447636 63The owner ID and group ID of the file
9bccf70c
A
64named by
65.Fa path
66or referenced by
2d21ac55 67.Fa fildes
9bccf70c
A
68is changed as specified by the arguments
69.Fa owner
91447636 70and
9bccf70c
A
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
91447636
A
80The
81.Fn chown
82system call
9bccf70c
A
83clears the set-user-id and set-group-id bits
84on the file
85to prevent accidental or mischievous creation of
91447636
A
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.
9bccf70c 93.Pp
91447636
A
94The
95.Fn fchown
96system call
9bccf70c
A
97is particularly useful when used in conjunction
98with the file locking primitives (see
99.Xr flock 2 ) .
100.Pp
91447636
A
101The
102.Fn lchown
103system call is similar to
104.Fn chown
105but does not follow symbolic links.
106.Pp
9bccf70c
A
107One of the owner or group id's
108may be left unchanged by specifying it as -1.
109.Sh RETURN VALUES
91447636 110.Rv -std
9bccf70c 111.Sh ERRORS
2d21ac55 112.Pp
91447636
A
113The
114.Fn chown
115and
116.Fn lchown
2d21ac55 117system calls will fail if:
9bccf70c 118.Bl -tag -width Er
2d21ac55 119.\" ==========
9bccf70c
A
120.It Bq Er EACCES
121Search permission is denied for a component of the path prefix.
9bccf70c 122.It Bq Er EFAULT
91447636
A
123The
124.Fa path
125argument
9bccf70c 126points outside the process's allocated address space.
2d21ac55
A
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.
9bccf70c
A
143.El
144.Pp
91447636
A
145The
146.Fn fchown
147system call will fail if:
9bccf70c 148.Bl -tag -width Er
2d21ac55 149.\" ==========
9bccf70c 150.It Bq Er EBADF
91447636 151The
2d21ac55 152.Fa fildes
91447636 153argument
9bccf70c 154does not refer to a valid descriptor.
2d21ac55 155.\" ==========
9bccf70c 156.It Bq Er EINVAL
91447636 157The
2d21ac55 158.Fa fildes
91447636 159argument
9bccf70c 160refers to a socket, not a file.
2d21ac55
A
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.\" ==========
9bccf70c 172.It Bq Er EPERM
2d21ac55
A
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.\" ==========
9bccf70c
A
176.It Bq Er EROFS
177The named file resides on a read-only file system.
9bccf70c
A
178.El
179.Sh SEE ALSO
9bccf70c
A
180.Xr chgrp 1 ,
181.Xr chmod 2 ,
91447636
A
182.Xr flock 2 ,
183.Xr chown 8
9bccf70c
A
184.Sh STANDARDS
185The
186.Fn chown
91447636
A
187system call is expected to conform to
188.St -p1003.1-90 .
9bccf70c
A
189.Sh HISTORY
190The
91447636
A
191.Fn chown
192function appeared in
193.At v7 .
194The
9bccf70c 195.Fn fchown
91447636 196system call appeared in
9bccf70c
A
197.Bx 4.2 .
198.Pp
199The
200.Fn chown
201and
202.Fn fchown
91447636 203system calls were changed to follow symbolic links in
9bccf70c 204.Bx 4.4 .
91447636
A
205The
206.Fn lchown
207system call was added in
208.Fx 3.0
209to compensate for the loss of functionality.