chmod(2) chmod(2)NAME chmod, fchmod - change mode of file SYNOPSIS #include <sys/types.h> #include <sys/stat.h> int chmod(path, mode) char *path; mode_t mode; int fchmod(fd, mode) int fd; mode_t mode; DESCRIPTION chmod sets the access-permission portion of the named file's mode according to the bit pattern contained in mode. The path argument points to a pathname of a file. Access-permission bits are interpreted as follows: 04000 Set effective user ID on execution. 02000 Set effective group ID on execution. 01000 Save text image after execution. 00400 Read by owner. 00200 Write by owner. 00100 Execute (search if a directory) by owner. 00070 Read, write, execute (search) by group. 00007 Read, write, execute (search) by others. To change the mode of a file, the effective user ID of the calling process must match the owner of the file or be the superuser. If the effective user ID of the process is not the superuser, mode bit 01000 (save text image after execution) is cleared. January 1992 1
chmod(2) chmod(2)If the effective user ID of the process is not the superuser and the effective group ID of the process does not match the group ID of the file, mode bit 02000 (set the effective group ID on execution) is cleared. If an executable file is prepared for sharing (refer to the -n option for the cc(1) command), then 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. Thus, 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, saving time. Changing the owner of a file turns off mode bit 04000 (set user ID), unless the superuser does it. Changing this bit makes the system somewhat more secure at the expense of a degree of compatibility. STATUS MESSAGES AND VALUES On successful completion, a value of 0 is returned. Otherwise, a value of -1 is returned and errno is set to indicate the error. The chmod command will fail and the file mode will be unchanged if one or more of the following conditions is true: EACCES Search permission is denied on a component of the path prefix. EFAULT The path points outside the allocated address space of the process. ELOOP Too many symbolic links were encountered in translating a pathname. ENAMETOOLONG A component of a pathname exceeded NAME_MAX characters, or an entire pathname exceeded PATH_MAX. ENOENT The named file does not exist. ENOTDIR A component of the path prefix is not a directory. EPERM The effective user ID does not match the owner of the file, and the effective user ID is not the superuser. 2 January 1992
chmod(2) chmod(2)EROFS The named file resides on a read-only file system. SEE ALSO chown(2), mknod(2), open(2), stat(2), umask(2) chmod(1) in A/UX Command Reference January 1992 3