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