CHOWN(2) — SYSTEM CALLS
NAME
chown, fchown − change owner and group of a file
SYNOPSIS
chown(path, owner, group)
char ∗path;
int owner, group;
fchown(fd, owner, group)
int fd, owner, group;
DESCRIPTION
The file that is named by path or referenced by fd has its owner and group changed as specified. Only the super-user may change the owner of the file, because if users were able to give files away, they could defeat the file-space accounting procedures. The owner of the file may change the group to a group of which he is a member; the super-user may change the group arbitrarily.
fchown is particularly useful when used in conjunction with the file locking primitives (see flock(2)).
If owner or group is specified as −1, the corresponding ID of the file is not changed.
If a process whose effective user ID is not super-user successfully changes the group ID of a file, the set-user-ID and set-group-ID bits of the file mode, 04000 and 02000 respectively, will be cleared.
If the final component of path is a symbolic link, the ownership and group of the symbolic link is changed, not the ownership and group of the file or directory to which it points.
RETURN VALUE
Zero is returned if the operation was successful; −1 is returned, and a more specific error code is placed in the global variable errno, if an error occurs.
ERRORS
chown will fail and the file will be unchanged if:
ENOTDIR A component of the path prefix of path is not a directory.
EINVAL path contains a byte with the high-order bit set.
ENAMETOOLONG
The length of a component of path exceeds 255 characters, or the length of path exceeds 1023 characters.
ENOENT The file referred to by path does not exist.
EACCES Search permission is denied for a component of the path prefix of path.
ELOOP Too many symbolic links were encountered in translating path.
EPERM The user ID specified by owner is not the current owner ID of the file, or the group ID specified by group is not the current group ID fo the file and is not in the process’ group access list, and the effective user ID is not the super-user.
EROFS The file referred to by path resides on a read-only file system.
EFAULT path points outside the process’s allocated address space.
EIO An I/O error occurred while reading from or writing to the file system.
fchown will fail if:
EBADF fd does not refer to a valid descriptor.
EINVAL fd refers to a socket, not a file.
EPERM The user ID specified by owner is not the current owner ID of the file, or the group ID specified by group is not the current group group access list, and the effective user ID is not the super-user.
EROFS The file referred to by fd resides on a read-only file system.
EIO An I/O error occurred while reading from or writing to the file system.
SEE ALSO
Sun Release 3.2 — Last change: 16 July 1986