chown, chownx
Purpose
Changes the owner and group IDs of a file.
Syntax
int chown (path, owner, group) #include <sys/chownx.h>
char *path;
int owner, group; int chownx (path, owner, group, tflag)
char *path;
int owner, group, tflag;
Description
The chown system call changes the owner ID and the group
ID of the file named by the path parameter. If Distrib-
uted Services is installed on your system, the path can
cross into another node, naming a remote file.
If the named file is a local file, the owner and group
IDs of that file are set to the numeric values contained
in the owner and group parameters, respectively. If the
named file is a remote file, then the IDs of the named
file are set to the values contained in owner and group
after both outbound and inbound translation. (See Man-
aging the AIX Operating System for a description of ID
translation.)
A process can change the ownership of a file only if its
effective user ID (translated, if the file is remote) is
either superuser or the same as the file's owner ID.
If the effective user ID of the calling process is not
the same as the superuser ID, then the chown system call
clears the set-user-ID (S_ISUID) and set-group-ID
(S_ISGID) bits of the file mode. (See "stat.h" for the
definitions of the constants S_ISUID and S_ISGID.)
The chownx system call performs the same function as the
chown system call, except that it also allows the process
to change owner and group IDs with or without ID trans-
lation by specifying the tflag parameter.
The tflag parameter determines the translation of the
owner and group parameters. This parameter is con-
structed by logically ORing two of the following values:
T_OWNER_RAW Changes the file's owner to the value of
the owner parameter without translation.
T_OWNER_TRAN Changes the file's owner to the value of
the owner parameter after translation
through the sending node's outbound
translate tables and the receiving
node's inbound translation tables. If
the file is a local file, this is the
same as T_OWNER_RAW; no translation is
done.
T_OWNER_AS_IS Ignores the value specified in the owner
parameter and leaves the owner ID of the
file unaltered.
T_GROUP_RAW Changes the file's group ID to the value
of the group parameter without trans-
lation.
T_GROUP_TRAN Changes the file's group ID to the value
of the group parameter after translation
through the sending node's outbound
translate tables and the receiving
node's inbound translation tables. If
the file is a local file, this is the
same as T_GROUP_RAW; no translation is
done.
T_GROUP_AS_IS Ignores the value specified in the group
parameter and leaves the group ID of the
file unaltered.
Only one each of the T_OWNER and the T_GROUP bits should
be specified.
Note that the following two system calls are equivalent:
chown (path, owner, group)
chownx (path, owner, group, T_OWNER_TRAN | T_GROUP_TRAN)
Return Value
Upon successful completion, a value of 0 is returned. If
the chown or chownx system call fails, a value of -1 is
returned and errno is set to indicate the error.
Diagnostics
The chown and chownx system calls fail and the owner ID
and the group ID of the named file remain unchanged if
one or more of the following are true:
ENOTDIR A component of the path prefix is not a direc-
tory.
ENOENT The named file does not exist.
EACCES Search permission is denied on a component of
the path prefix.
EPERM The effective user ID does not match the owner
of the file and the effective user ID is not
superuser.
EROFS The named file resides on a read-only file
system.
EFAULT The path parameter &pointsout..
ESTALE The process's root or current directory is
located in a virtual file system that has been
unmounted.
If Distributed Services is installed on your system,
chown or chownx can also fail if one or more of the fol-
lowing are true:
EDIST The server has blocked new inbound
requests.
EDIST Outbound requests are currently blocked.
EDIST The server has a release level of Distrib-
uted Services that cannot communicate with
this node.
EAGAIN The server is too busy to accept the
request.
ESTALE The file descriptor for a remote file has
become obsolete.
EPERM The server's translate tables do not
contain an entry for at least one of the
following IDs:
o The user ID of the caller
o The owner parameter
o The group parameter.
ENODEV The named file is a remote file located on
a device that has been unmounted at the
server.
ENOMEM Either this node or the server does not
have enough memory available to service the
request.
ENOCONNECT An attempt to establish a new network con-
nection with a remote node failed.
EBADCONNECT An attempt to use an existing network con-
nection with a remote node failed.
Related Information
In this book: "chmod," "fullstat, ffullstat," and
"stat.h."
The chown command in AIX Operating System Commands Refer-
ence.
Managing the AIX Operating System.