unixdev.net


Switch to SpeakEasy.net DSL

The Modular Manual Browser

Home Page
Manual: (SunOS-4.1.3)
Page:
Section:
Apropos / Subsearch:
optional field

CHOWN(2V)                                                            CHOWN(2V)



NAME
       chown, fchown - change owner and group of a file

SYNOPSIS
       int chown(path, owner, group)
       char *path;
       int owner;
       int group;
       int fchown(fd, owner, group)
       int fd;
       int owner;
       int group;

SYSTEM V SYNOPSIS
       #include <&lt;sys/types.h>&gt;
       int chown(path, owner, group)
       char *path;
       uid_t owner;
       gid_t 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 (see NOTES).  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, S_ISUID and S_ISGID respectively (see stat(2V)), 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 VALUES
       chown() and fchown() return:

       0      on success.

       -1     on failure and set errno to indicate the error.

ERRORS
       chown() will fail and the file will be unchanged if:

       EACCES              Search  permission is denied for a component of the
                           path prefix of path.

       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.

       ELOOP               Too many symbolic links were encountered in  trans-
                           lating path.

       ENAMETOOLONG        The length of the path argument exceeds {PATH_MAX}.

                           A pathname component is longer than {NAME_MAX} (see
                           sysconf(2V)) while {_POSIX_NO_TRUNC} is  in  effect
                           (see pathconf(2V)).

       ENOENT              The file referred to by path does not exist.

       ENOTDIR             A  component  of  the  path prefix of path is not a
                           directory.

       EPERM               The user ID specified by owner is not  the  current
                           owner ID of the file

                           The  group ID specified by group is not the current
                           group ID of the file and is  not  in  the  process'
                           supplementary  group IDs, and the effective user ID
                           is not the super-user.

       EROFS               The file referred to by path resides on a read-only
                           file system.

       fchown() will fail if:

       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 user ID specified by owner is not  the  current
                           owner ID of the file.

                           The  group ID specified by group is not the current
                           group ID of the file and is not in  the  supplemen-
                           tary  group  IDs,  and the effective user ID is not
                           the super-user.

       EROFS               The file referred to by fd resides on  a  read-only
                           file system.

SYSTEM V ERRORS
       In addition to the above, the following may also occur:

       ENOENT              path points to an empty string.

SEE ALSO
       chmod(2V), flock(2)

NOTES
       For  chown()  to  behave  as described above, {_POSIX_CHOWN_RESTRICTED}
       must be in effect  (see  pathconf(2V)).   {_POSIX_CHOWN_RESTRICTED}  is
       always  in  effect  on SunOS systems, but for portability, applications
       should call pathconf() to determine  whether  {_POSIX_CHOWN_RESTRICTED}
       is in effect for path.

       If  {_POSIX_CHOWN_RESTRICTED} is in effect for the file system on which
       the file referred to by path or fd resides,  only  the  super-user  may
       change the owner of the file.  Otherwise, processes with effective user
       ID equal to the file owner or super-user may change the  owner  of  the
       file.



                                21 January 1990                      CHOWN(2V)