Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ chmod(2) — HP-UX 7.01

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

chmod(1)

chown(2)

creat(2)

fcntl(2)

getacl(2)

lockf(2)

mknod(2)

open(2)

read(2)

setacl(2)

write(2)

cdf(4)

acl(5)

CHMOD(2)

NAME

chmod, fchmod − change access mode of file

SYNOPSIS

#include <sys/types.h>
#include <sys/stat.h>

int chmod (path, mode)
char ∗path;
mode_t mode;

int fchmod (fildes, mode)
int fildes;
mode_t mode;

DESCRIPTION

The path argument points to a path name naming a file.  The fildes argument is a file descriptor.  Chmod and fchmod set the access permission portion of the file’s mode according to the bit pattern contained in mode.

The following symbolic constants representing the access permission bits are defined with the indicated values in <sys/stat.h> and are used to construct the argument mode.  The value of the argument mode is the bitwise inclusive OR of the values for the desired permissions. 

S_ISUID 04000 Set user ID on execution.
S_ISGID 02000 Set group ID on execution.
S_ENFMT 02000 Record locking enforced.
S_ISVTX 01000 Save text image after execution.
S_IRUSR 00400 Read by owner.
S_IWUSR 00200 Write by owner.
S_IXUSR 00100 Execute (search) by owner.
S_IRGRP 00040 Read by group.
S_IWGRP 00020 Write by group.
S_IXGRP 00010 Execute (search) by group.
S_IROTH 00004 Read by others (that is, anybody else).
S_IWOTH 00002 Write by others.
S_IXOTH 00001 Execute (search) by others.

The effective-user-ID of the process must match that of the owner of the file or the superuser to change the mode of a file. 

If the effective-user-ID of the process is not that of the superuser, S_ISVTX (mode bit 01000, save text image on execution) is cleared. 

If the effective-user-ID of the process is not that of the superuser, and the effective-group-ID of the process does not match the group ID of the file and none of the group IDs in the supplementary groups list match the group ID of the file, S_ISGID, S_ENFMT (mode bit 02000, set group ID on execution and enforced file locking mode) is cleared. 

The set-group-ID on execution bit is also used to enforce file-locking mode (see lockf(2) and fcntl(2)) on files that are not group executable. This might affect future calls to open(2), creat(2), read(2), and write(2) on such files. 

If an executable file is prepared for sharing, S_ISVTX (mode bit 01000) prevents the system from abandoning the swap-space image of the program-text portion of the file when its last user terminates.  Then, when the next user of the file executes it, the text need not be read from the file system but can simply be swapped in, thus saving time. 

Access Control Lists

All optional entries in a file’s access control list are deleted when chmod is executed.  (This behavior conforms to the IEEE Standard POSIX 1003.1-1988.)  To preserve optional entries in a file’s access control list, it is necessary to save and restore them using getacl(2) and setacl(2).

To set the permission bits of access control list entries, use setacl(2) instead of chmod.

For more information on access control list entries, see acl(5).

RETURN VALUE

Upon successful completion, a value of 0 is returned.  Otherwise, a value of −1 is returned and errno is set to indicate the error. 

ERRORS

Chmod and fchmod fail and the file mode is unchanged if one or more of the following is true:

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

[EFAULT] Path points outside the allocated address space of the process.  The reliable detection of this error is implementation dependent. 

[ELOOP] Too many symbolic links are encountered in translating path.

[ENAMETOOLONG]
A component of path exceeds NAME_MAX bytes while _POSIX_NO_TRUNC is in effect or path exceeds PATH_MAX bytes. 

[ENOENT] A component of path does not exist. 

[ENOENT] The file named by path does not exist. 

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

[EPERM] The effective-user-ID does not match that of the owner of the file and the effective-user-ID is not that of the super-user. 

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

DEPENDENCIES

HP Clustered Environment:
If the file is a directory, the access permission bit S_CDF (04000) indicates a hidden directory (see cdf(4)).

RFA and NFS
Fchmod is not supported on remote files. 

AUTHOR

Chmod was developed by AT&T, the University of California, Berkeley, and HP. 

Fchmod was developed by the University of California, Berkeley. 

SEE ALSO

chmod(1), chown(2), creat(2), fcntl(2), getacl(2), lockf(2), mknod(2), open(2), read(2), setacl(2), write(2), cdf(4), acl(5). 

STANDARDS CONFORMANCE

chmod: SVID2, XPG2, XPG3, POSIX.1, FIPS 151-1

Hewlett-Packard Company  —  HP-UX Release 7.0: Sept 1989

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