Museum

Home

Lab Overview

Retrotechnology Articles

⇒ Online Manual

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

chown(8)

chgrp(1)

chmod(2)

flock(2)

CHOWN(2)                             BSD                              CHOWN(2)



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
     chown changes the owner and group of the file named by path or referenced
     by fd 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 can change the
     group to a group of which he is a member.

     chown 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.

     fchown is particularly useful when used in conjunction with the file
     locking primitives (see flock(2)).

     One of the owner or group IDs may be left unchanged by specifying it as
     -1.

     Under some implementations, 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.  Links
     under Domain/OS BSD don't have owners or groups; this operation always
     returns success.

ERRORS
     chown will fail and the file will be unchanged if any of the following
     are true.

     [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.

     [ENOENT]         The named file does not exist.

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

     [ELOOP]          Too many symbolic links were encountered in translating
                      the pathname.

     [EROFS]          The named file resides on a read-only file system.

     [EFAULT]         path points outside the process' allocated address
                      space.

     [EIO]            An I/O error occurred while reading from or writing to
                      the file system.

     fchown will fail if any of the following are true:

     [EBADF]          fd does not refer to a valid descriptor.
     [EINVAL]         fd refers to a socket, not a file.

     [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.

SEE ALSO
     chown(8), chgrp(1), chmod(2), flock(2)

DIAGNOSTICS
     A successful call returns 0.  An unsuccessful call returns -1 and sets
     errno.

NOTES
     In some implementations, chown also may return the following error:

     [EINVAL]         The pathname contains a character with the high-order
                      bit set.

     chown and fchown also may return the following error:

     [EPERM]          The effective user ID is not the super-user.

Typewritten Software • bear@typewritten.org • Edmonds, WA 98026