Museum

Home

Lab Overview

Retrotechnology Articles

⇒ Online Manual

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

open(2V)

chown(2)

stat(2)

sticky(8)

CHMOD(2)  —  SYSTEM CALLS

NAME

chmod, fchmod − change mode of file

SYNOPSIS

#include /usr/include/sys/stat.h

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

fchmod(fd, mode)
int fd, mode;

DESCRIPTION

The file whose name is given by path or referenced by the descriptor fd has its mode changed to mode. Modes are constructed by or’ing together some combination of the following:

S_ISUID04000 set user ID on execution
S_ISGID02000 set group ID on execution
S_ISVTX01000 save text image after execution (sticky bit)
S_IREAD00400 read by owner
S_IWRITE00200 write by owner
S_IEXEC00100 execute (search on directory) by owner
00070 read, write, execute (search) by group
00007 read, write, execute (search) by others

These bit patterns are defined in /usr/include/sys/stat.h. 

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

If the effective user ID of the process is not super-user and the process attempts to set the set group ID bit on a file owned by a group which is not in its group access list, mode bit 02000 (set group ID on execution) is cleared. 

If an executable file is set up for sharing (this is the default) then mode 01000 (save text image after execution) prevents the system from abandoning the swap-space image of the program-text portion of the file when its last user terminates.  If the effective user ID of the process is not super-user, this bit is cleared. 

If a user other than the super-user writes to a file, the set user ID and set group ID bits are turned off.  This makes the system somewhat more secure by protecting set-user-ID (set-group-ID) files from remaining set-user-ID (set-group-ID) if they are modified, at the expense of a degree of compatibility. 

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 will fail and the file mode will be unchanged if:

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

EINVAL path contains a byte with the high-order bit set. 

ENAMETOOLONG
The length of a component of path exceeds 255 characters, or the length of path exceeds 1023 characters. 

ENOENT The file referred to by path does not exist. 

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

ELOOP Too many symbolic links were encountered in translating path.

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

EINVAL fd refers to a socket, not to a file. 

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

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. 

fchmod will fail if:

EBADF The descriptor is not valid. 

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

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

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

FILES

/usr/include/sys/stat.h

SEE ALSO

open(2V), chown(2), stat(2), sticky(8)

Sun Release 3.2  —  Last change: 16 July 1986

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