chmod(2) DG/UX 5.4.2 chmod(2)
NAME
chmod - change mode of file
SYNOPSIS
#include <sys/types.h>
#include <sys/stat.h>
int chmod (path, mode)
char * path;
int mode;
where:
path Address of a pathname
mode File's new mode
DESCRIPTION
The chmod system call changes the mode (including permissions)
associated with a file. path points to a pathname naming a file of
type ordinary, directory, FIFO, block special, character special, or
symbolic link. If path refers to a symbolic link, the target of the
symbolic link is handled, not the symbolic link. The file must
reside on a file system device mounted read-write. Chmod sets the
protection rights, sticky bit, set-user-id bit, and set-group-id bit
of the file's mode according to mode.
Values of mode are constructed by joining one or more of the
following flags with a logical OR:
S_ISUID (04000) Set user id on execution.
S_ISGID (02000) Set group id on execution. If the (S_IEXEC
>> 3) bit is not set and the file is an
ordinary file, this bit enables mandatory
record locking for the file. If the file is
a directory, this bit causes files created in
the directory to be created with the group id
of the directory itself, rather than the
group id of the process creating the file.
S_ISVTX (01000) Sticky bit. Some versions of the UNIX®
system attempt to optimize access to
executable files (that have this bit set) by
maintaining a copy of the program image in a
memory- or disk-based file system cache. The
DG/UX system attempts this optimization for
all executable images. For files of type
`directory' and `control point directory',
the sticky bit has a further meaning. If the
sticky bit is set, then the directory is
considered append only. Processes without
appropriate permissions cannot delete or
rename files owned by other users in such a
directory.
Licensed material--property of copyright holder(s) 1
chmod(2) DG/UX 5.4.2 chmod(2)
S_IREAD (00400) Read by owner.
S_IWRITE (00200) Write by owner.
S_IEXEC (00100) Execute (search, if a directory) by owner.
(S_IREAD >> 3) (00040) Read by group.
(S_IWRITE >> 3) (00020) Write by group.
(S_IEXEC >> 3) (00010) Execute (search) by group.
(S_IREAD >> 6) (00004) Read by others.
(S_IWRITE >> 6) (00002) Write by others.
(S_IEXEC >> 6) (00001) Execute (search) by others.
For each flag set in mode, the corresponding attribute bit or
protection right is set. The other attribute bits and protection
rights are cleared. If the calling process attempts to set the
sticky bit or the set-group-id bit but does not meet the requirements
for doing so (see access control), that bit is cleared, but the
process is not notified of the failed attempt. One of the access
requirements to perform this call (the effective user id of the
process must be superuser or match the file's user id) coincides with
the access needed to set the set-user-id bit, hence the process may
always set that bit if it chooses.
The time of last change to the file's attributes is set to the
current time.
If chmod fails, the file's attributes remain unchanged.
ACCESS CONTROL
The effective user id of the calling process must be superuser or
match the user id of the file.
The process's effective user id must be superuser to set the sticky
bit.
To set the set-group-id bit, either
⊕ the process's effective user id must be superuser,
⊕ the process's effective user id must match the user id of the
file and the process's effective group id must match the
file's group id.
Failure to meet the requirements for setting one of these bits does
not produce an error. Note that meeting the first access requirement
is sufficient to allow a process to set the set-user-id bit.
The process must have permission to resolve path.
Licensed material--property of copyright holder(s) 2
chmod(2) DG/UX 5.4.2 chmod(2)
RETURN VALUE
0 The file's mode was successfully changed.
-1 An error occurred. errno is set to indicate the error.
DIAGNOSTICS
Errno may be set to one of the following error codes:
EROFS The named file resides on a file system device mounted
read-only.
EPERM The file's user id does not match yours, and you are
not the superuser.
ENOENT The file the pathname resolved to does not exist.
ENOENT A non-terminal component of the pathname does not
exist.
ENOTDIR A non-terminal component of the pathname was not a
directory or symbolic link.
ENAMETOOLONG The pathname exceeds the length limit for pathnames.
ENAMETOOLONG A component of the pathname exceeds the length limit
for filenames.
ENOMEM There are not enough system resources to resolve the
pathname or to expand a symbolic link.
ELOOP The number of symbolic links encountered during
pathname resolution exceeded MAXSYMLINKS. A symbolic
link cycle is suspected.
EPERM The pathname contains a character not in the allowed
character set.
EFAULT The pathname does not completely reside in the
process's address space, or the pathname does not
terminate in the process's address space.
SEE ALSO
chmod(1), chown(2), creat(2), fchmod(2), fchown(2), fcntl(2),
fstat(2), mknod(2), open(2), read(2), stat(2), write(2).
Licensed material--property of copyright holder(s) 3