spelling fix, outblock to oublock
[unix-history] / usr / src / lib / libc / sys / chown.2
CommitLineData
37512f15
KM
1.\" Copyright (c) 1980 Regents of the University of California.
2.\" All rights reserved. The Berkeley software License Agreement
3.\" specifies the terms and conditions for redistribution.
4.\"
dbe80be1 5.\" @(#)chown.2 6.6 (Berkeley) %G%
37512f15 6.\"
9a68374b 7.TH CHOWN 2 ""
37512f15
KM
8.UC 4
9.SH NAME
10chown \- change owner and group of a file
11.SH SYNOPSIS
12.nf
0aa506e6
KM
13.ft B
14chown(path, owner, group)
15char *path;
16int owner, group;
17.PP
18.ft B
19fchown(fd, owner, group)
20int fd, owner, group;
37512f15
KM
21.fi
22.SH DESCRIPTION
23The file
d84f45ef 24that is named by \fIpath\fP or referenced by \fIfd\fP
37512f15
KM
25has its
26.I owner
27and
28.I group
29changed as specified.
0859885e
MK
30Only the super-user
31may change the owner of the file,
37512f15 32because if users were able to give files away,
0aa506e6 33they could defeat the file-space accounting procedures.
0859885e
MK
34The owner of the file may change the group
35to a group of which he is a member.
37512f15
KM
36.PP
37On some systems,
38.I chown
0aa506e6 39clears the set-user-id and set-group-id bits
37512f15
KM
40on the file
41to prevent accidental creation of
0859885e 42set-user-id and set-group-id programs.
0aa506e6
KM
43.PP
44.I Fchown
45is particularly useful when used in conjunction
46with the file locking primitives (see
47.IR flock (2)).
48.PP
0859885e
MK
49One of the owner or group id's
50may be left unchanged by specifying it as \-1.
dbe80be1
KM
51.PP
52If the final component of
53.I path
54is a symbolic link,
55the ownership and group of the symbolic link is changed,
56not the ownership and group of the file or directory to which it points.
0aa506e6
KM
57.SH "RETURN VALUE
58Zero is returned if the operation was successful;
59\-1 is returned if an error occurs, with a more specific
60error code being placed in the global variable \fIerrno\fP.
61.SH "ERRORS
62.I Chown
63will fail and the file will be unchanged if:
64.TP 15
0aa506e6
KM
65[ENOTDIR]
66A component of the path prefix is not a directory.
67.TP 15
b5984ffe
KM
68[EINVAL]
69The pathname contains a character with the high-order bit set.
0aa506e6 70.TP 15
b5984ffe
KM
71[ENAMETOOLONG]
72A component of a pathname exceeded 255 characters,
73or an entire path name exceeded 1023 characters.
0aa506e6
KM
74.TP 15
75[ENOENT]
76The named file does not exist.
77.TP 15
78[EACCES]
b5984ffe
KM
79Search permission is denied for a component of the path prefix.
80.TP 15
81[ELOOP]
82Too many symbolic links were encountered in translating the pathname.
0aa506e6
KM
83.TP 15
84[EPERM]
fd690c8b 85The effective user ID is not the super-user.
0aa506e6
KM
86.TP 15
87[EROFS]
88The named file resides on a read-only file system.
89.TP 15
90[EFAULT]
91.I Path
92points outside the process's allocated address space.
fd690c8b
KM
93.TP 15
94[EIO]
95An I/O error occurred while reading from or writing to the file system.
0aa506e6
KM
96.PP
97.I Fchown
98will fail if:
99.TP 15
100[EBADF]
101.I Fd
102does not refer to a valid descriptor.
103.TP 15
104[EINVAL]
105.I Fd
106refers to a socket, not a file.
b5984ffe 107.TP 15
fd690c8b
KM
108[EPERM]
109The effective user ID is not the super-user.
110.TP 15
b5984ffe
KM
111[EROFS]
112The named file resides on a read-only file system.
fd690c8b
KM
113.TP 15
114[EIO]
115An I/O error occurred while reading from or writing to the file system.
37512f15 116.SH "SEE ALSO"
0859885e 117chown(8), chgrp(1), chmod(2), flock(2)