CHOWN
Section: System Calls (2)
Updated: August 1, 1992
Index
Return to Main Contents
NAME
chown - change owner and group of a file
SYNOPSIS
#include <sys/types.h>
int chown(const char *path, uid_t owner, gid_t group);
fchown(int fd, int owner, int group);
DESCRIPTION
The
chown
function changes the user ID and group ID
of the file whose pathname is
given by the
path
argument to the numeric values in the
owner
and
group
arguments, respectively.
The
fchown
function changes the user ID and group ID
of the open file given by
fd.
Only the super-user
may change the user ID (owner) of the file;
if users were able to give files away,
they could defeat file-space accounting procedures.
A non super-user process can change
the group ID of the file
if and only if
its effective user ID matches the file owner,
owner
is equal to the file owner, and
group
is equal
either to the process' effective group ID or
one of its supplementary group IDs.
Unless the user id of the process is
that of the super-user,
the
chown
function 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.
The owner or group ID of the file
may be left unchanged by setting
the corresponding argument to -1.
If the final component of
path
is a symbolic link,
then the owner and group IDs
of the symbolic link are changed,
not the owner and group IDs
of the file or directory to which it points.
Upon successful completion,
chown
marks for update the
st_ctime
field of the file.
RETURN VALUE
Upon successful completion,
chown
returns a value of zero.
Otherwise, a value of -1 is returned and
errno
is set to indicate
the error.
ERRORS
If any of the following conditions occurs,
chown
returns -1 and sets
errno
to the corresponding value:
- [EACCES]
-
Search permission is denied for a component of the path prefix.
- [EFAULT]
-
The
path
argument points outside the process's allocated address space.
- [EINVAL]
-
The pathname contains a character with the high-order bit set.
- [EIO]
-
An I/O error occurred while reading from or writing to the file system.
- [ELOOP]
-
Too many symbolic links were encountered in translating the pathname.
- [ENAMETOOLONG]
-
A component of
path
exceeds 255 characters,
or the entire pathname exceeds 1023 characters.
For POSIX applications these values are given
by the constants {NAME_MAX} and {PATH_MAX}, respectively.
- [ENOTDIR]
-
A component of the path prefix is not a directory.
- [ENOENT]
-
The named file does not exist or
path
points to an empty string.
- [EPERM]
-
The effective user ID is not the super-user.
- [EROFS]
-
The named file resides on a read-only file system.
The following conditions cause
fchown
to fail and return -1:
- [EBADF]
-
Fd
does not refer to a valid descriptor.
- [EINVAL]
-
Fd
refers to a socket, not a file.
- [EIO]
-
An I/O error occurred while reading from or writing to the file system.
- [EPERM]
-
The effective user ID is not the super-user.
- [EROFS]
-
The named file resides on a read-only file system.
SEE ALSO
chgrp(1),
chmod(2),
chown(8)
Index
- NAME
-
- SYNOPSIS
-
- DESCRIPTION
-
- RETURN VALUE
-
- ERRORS
-
- SEE ALSO
-
This document was created by
man2html,
using the manual pages.
Time: 00:58:47 GMT, September 26, 2024