1
0
Files
irix-657m-src/eoe/man/man2/chmod.2
2022-09-29 17:59:04 +03:00

259 lines
7.6 KiB
Groff

'\"! tbl | mmdoc
'\"macro stdmacro
.if n .pH g2.chmod @(#)chmod 41.11 of 5/26/91
.\" Copyright 1991 UNIX System Laboratories, Inc.
.\" Copyright 1989, 1990 AT&T
.nr X
.if \nX=0 .ds x} chmod 2 "" "\&"
.if \nX=1 .ds x} chmod 2 ""
.if \nX=2 .ds x} chmod 2 "" "\&"
.if \nX=3 .ds x} chmod "" "" "\&"
.TH \*(x}
.SH NAME
\f4chmod\f1, \f4fchmod\f1 \- change mode of file
.SH SYNOPSIS
.PP
\f4#include <sys/types.h>\f1
.br
\f4#include <sys/stat.h>\f1
.PP
\f4int chmod(const char \(**path, mode_t mode);\f1
.PP
\f4int fchmod(int fildes, mode_t mode);\f1
.SH DESCRIPTION
\f4chmod\fP and \f4fchmod\fP set the
access permission portion of the mode of
the file whose name is given by
\f2path \fP
or referenced by the descriptor
\f2fildes\fP
to the bit pattern contained in
\f2mode\fP.
If
\f2path\fP
or
\f2fildes\fP
are symbolic links, the access permissions of the
target of the symbolic links are set.
Access permission bits are interpreted as follows:
.PP
.TS
center, tab(:);
lf4 l l.
S_ISUID:04000:Set user ID on execution.
S_ISGID:020#0:Set group ID on execution if # is \f47\f1, \f45\f1, \f43\f1, or \f41\f1
::Enable mandatory file/record locking if # is \f46\f1, \f44\f1, \f42\f1, or \f40\f1
S_ISVTX:01000:Save text image after execution (a.k.a. Sticky bit).
S_IRWXU:00700:Read, write, execute by owner.
S_IRUSR:00400:Read by owner.
S_IWUSR:00200:Write by owner.
S_IXUSR:00100:Execute (search if a directory) by owner.
S_IRWXG:00070:Read, write, execute by group.
S_IRGRP:00040:Read by group.
S_IWGRP:00020:Write by group.
S_IXGRP:00010:Execute by group.
S_IRWXO:00007:Read, write, execute (search) by others.
S_IROTH:00004:Read by others.
S_IWOTH:00002:Write by others
S_IXOTH:00001:Execute by others.
.TE
.PP
Modes are constructed by
\f4OR'ing\fP the access permission bits.
.PP
The effective user
ID
of the process must match the owner of the file or the
process must be super-user to change the mode of a file.
.PP
If the effective user ID of the process is not super-user, the sticky bit
is cleared for any non-directory argument.
.PP
If the effective group
ID
of the process does not match the
group
ID
of the file,
and the process is not super-user the
mode bit 02000 (set group
ID
on execution)
is cleared.
.PP
If a directory is writable and the sticky bit, \f4S_ISVTX\fP, is
set on the directory, a process may remove or rename files within that
directory only if one or more of the following is true
[see \f4unlink\fP(2) and \f4rename\fP(2)]:
.IP
the effective user ID of the process is the same as that of the owner ID
of the file
.IP
the effective user ID of the process is the same as that of the owner ID
of the directory
.IP
the process is a super-user.
.PP
Note that the group id of the process and file are not taken
into account by the rules above. A process will only be able to remove a
file in a sticky directory based upon its effective user ID, not its
group ID.
.PP
In releases of IRIX before 6.2, a process could also remove or rename files
within a directory with the sticky bit set if the process had write permission
for the file. This has been changed in accordance with the X/Open XPG4.2
standard,
but the old behavior can be enabled via the xpg4_sticky_bit kernel tunable
variable.
.PP
If the sticky bit, \f4S_ISVTX\fP, is set on a file that is a dynamic
loader for an \f2ELF\fP executable, then when the executable is \f2exec\fPed
the old process's read only address spaces will be made available to
the dynamic loader in the new process.
This can improve program start up time considerably.
.PP
The setting of the sticky bit on any other file has no effect.
.PP
If the mode bit 02000 (set group ID on execution) is set, the
mode bit 00010 (execute or search by group) is not set, and the file is
a regular file, file and record locks will be mandatory. Future calls to
\f4open\fP(2), \f4creat\fP(2), \f4read\fP(2), and \f4write\fP(2) will
carry implicit locks, and may fail or block depending on the presence of
other locks on the file. Mapped file access is not affected by
mandatory locks.
.PP
If the mode bit 02000 is set on a directory, then any files created in
that directory will take on the group ID of the directory rather than the
group ID of the calling process. \f4mount\fP(1M) may be used to enable this
feature regardless of the mode of the directory. [See \f4fstab\fP(4)].
.PP
Mandatory locking is not supported on NFS or CacheFS.
.PP
Upon successful completion, \f4chmod\fP and \f4fchmod\fP mark for update
the \f4st_ctime\fP field of the file.
.PP
\f4chmod\fP
will fail and the file mode will be unchanged
if one or more of the following are true:
.TP 15
\f4EACCES\fP
Search permission is denied on a component of the path prefix of
\f2path\fP.
.TP 15
\f4EACCES\fP
Write permission on the named file is denied.
.TP 15
\f4EFAULT\fP
\f2path\fP
points outside the allocated address space of the process.
.TP 15
\f4EINTR\fP
A signal was caught during execution of the system call.
.TP 15
\f4EIO\fP
An I/O error occurred while reading from or writing to the file system.
.TP 15
\f4ELOOP\fP
Too many symbolic links were encountered in translating
\f2path\fP.
.TP 15
\f4EMULTIHOP\fP
Components of
\f2path\fP
require hopping to multiple remote machines
and file system type does not allow it.
.TP 15
\f4ENAMETOOLONG\fP
The length of the \f2path\f1 argument exceeds {\f4PATH_MAX\fP}, or the
length of a \f2path\f1 component exceeds {\f4NAME_MAX\fP} while
\f4_POSIX_NO_TRUNC\fP is in effect.
.TP 15
\f4ENOTDIR\fP
A component of the prefix of
\f2path\fP
is not a directory.
.TP 15
\f4ENOENT\fP
Either a component of the path prefix, or the file referred to by
\f2path\fP
does not exist or is a null pathname.
.TP 15
\f4ENOLINK\fP
\f2path\fP
points to a remote machine and the link to that machine is no longer
active.
.TP 15
\f4ETIMEDOUT\fP
The named file
is located on a remote file system which is not available [see \f4intro\fP(2)].
.TP 15
\f4EPERM\fP
The effective user ID does not match the owner of the file and the
process is not super-user.
.TP 15
\f4EROFS\fP
The file referred to by
\f2path\fP
resides on a read-only file system.
.LP
\f4fchmod\fP
will fail and the file mode will be unchanged if:
.TP 15
\f4EBADF\fP
\f2fildes\fP
is not an open file descriptor
.TP 15
\f4EIO\fP
An I/O error occurred while reading from or writing to the file system.
.TP 15
\f4EINTR\fP
A signal was caught during execution of the \f4fchmod\fP system call.
.TP 15
\f4ENOLINK\fP
\f2fildes\fP
refers to a remote machine and the link to that machine is no longer
active.
.TP 15
\f4ETIMEDOUT\fP
\f2fildes\fP
refers to a file
on a remote file system which is not available [see \f4intro\fP(2)].
.TP 15
\f4EPERM\fP
The effective user ID does not match the owner of the file and the
process is not super-user.
.TP 15
\f4EROFS\fP
The file referred to by
\f2fildes\fP
resides on a read-only file system.
.TP 15
\f4EINVAL\fP
The file referred to by
\f2fildes\fP
resides on NFS or CacheFS and mandatory locking is being enabled.
.SH "SEE ALSO"
\f4chmod\fP(1),
\f4access\fP(2),
\f4chown\fP(2), \f4creat\fP(2), \f4exec\fP(2),
\f4fcntl\fP(2), \f4mknod\fP(2), \f4open\fP(2),
\f4read\fP(2), \f4stat\fP(2), \f4write\fP(2),
\f4mkfifo\fP(3C), \f4stat\fP(5)
.\".br
.\"The "File and Record Locking" chapter in the
.\"\f2Programmer's Guide: System Services and Application Packaging Tools\f1.
.SH DIAGNOSTICS
Upon successful completion, a value of 0 is returned.
Otherwise, a value of \-1 is returned and
\f4errno\fP
is set to indicate the error.
.SH BUGS
Due to the overloading of various permission bits, the silent turning
off of the set group ID on execution bit under the above mentioned circumstances
may in fact have disabled mandatory file/record locking (for files)
or group inheritance (for directories).
The only way to determine if
\f4chmod\fP really worked in these cases is to
\f4stat\fP(2)
the file.