chown(2)
NAME
chown, fchown − change owner and group of a file
SYNTAX
chown(path, owner, group)
char *path;
int owner, group;
fchown(fd, owner, group)
int fd, owner, group;
DESCRIPTION
The file which is named by path or referenced by fd has its owner and group changed as specified. Only the super-user may execute this call, because if users were able to give files away, they could defeat the file-space accounting procedures.
The chown system call clears the set-user-id and set-group-id bits on the file to prevent accidental creation of set-user-id and set-group-id programs owned by the super-user.
The fchown system call is particularly useful when used in conjunction with the file locking primitives. For further information, see flock(.).
Only one of the owner and group ID’s may be set by specifying the other as −1.
RETURN VALUE
Zero is returned if the operation was successful; −1 is returned if an error occurs, with a more specific error code being placed in the global variable errno.
ENVIRONMENT
Differs from the System V definition in that only the superuser may change the ownership. Also, ELOOP is a possible error condition.
DIAGNOSTICS
The chown system call will fail and the file will be unchanged if:
[ENOTDIR]
A component of the path prefix is not a directory.
[ENAMETOOLONG]
A component of a pathname exceeded 255 characters, or an entire pathname exceeded 1023 characters.
[EINVAL]
The argument contains a character with the high-order bit set.
[ENOENT]
The named file does not exist.
[EACCES]
Search permission is denied for a component of the path prefix.
[EPERM]
The effective user ID is not the super-user.
[EROFS]
The named file resides on a read-only file system.
[EFAULT]
The path points outside the process’s allocated address space.
[ELOOP]
Too many symbolic links were encountered in translating the pathname.
[EIO] An I/O error occurred while reading from or writing to the file system.
[ESTALE]
The file handle given in the argument is invalid. The file referred to by that file handle no longer exists or has been revoked.
The fchown system call will fail if:
[EBADF]
The fd does not refer to a valid descriptor.
[EINVAL]
The fd refers to a socket, not a file.
[EPERM]
The effective user ID is not the super-user.
[EROFS]
The named file resides on a read-only file system.
[EIO] An I/O error occurred while reading from or writing to the file system.
[ETIMEDOUT]
A "connect" request or remote file operation failed because the connected party did not properly respond after a period of time which is dependent on the communications protocol.