Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ chmod(2P) — Interactive 2.2

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

chown(2P)

creat(2)

fcntl(2)

mknod(2)

open(2P)

read(2P)

chmod(1)



          chmod(2P)        INTERACTIVE UNIX System (POSIX)        chmod(2P)



          NAME
               chmod - change mode of file

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

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

          DESCRIPTION
               The path argument points to a path name naming a file.  The
               chmod system call sets the access permission portion of the
               named file's mode according to the bit pattern contained in
               mode.

               Access permission bits are interpreted as follows:

                    04000
                         Set user ID on execution.

                    020#0
                         Set group ID on execution if # is 7, 5, 3, or 1.
                         Enable mandatory file/record locking if # is 6, 4,
                         2, or 0.

                    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.

               The effective user ID of the process must match the owner of
               the file or the calling process must have the appropriate
               privileges to change the mode of a file.

               If the calling process does not have the appropriate
               privileges and the file is not a directory, mode bit 01000
               (save text image on execution) is cleared.



          Rev. 1.1                                                   Page 1





          chmod(2P)        INTERACTIVE UNIX System (POSIX)        chmod(2P)



               If the calling process does not have the appropriate
               privileges and the effective group ID of the process does
               not match the group ID of the file or one of the supplemen-
               tary group IDs, mode bit 02000 (set group ID on execution)
               is cleared.

               If a 410 executable file has the sticky bit (mode bit 01000)
               set, the operating system will not delete the program text
               from the swap area when the last user process terminates.
               If a 413 executable file has the sticky bit set, the operat-
               ing system will not delete the program text from memory when
               the last user process terminates.  In either case, if the
               sticky bit is set, the text will already be available
               (either in a swap area or in memory) when the next user of
               the file executes it, thus making execution faster.

               The file creation system calls will use the set group ID bit
               of the file mode of the directory containing the new file to
               determine the group ID of this new file.  If this bit is not
               set, the group ID of this new file will be assigned its
               parent ID of the process.  Otherwise, it will be assigned
               the group ID of the containing directory.  When creating a
               new directory, the value of the set group ID bit of the file
               mode of the new directory will be inherited from the direc-
               tory containing the new directory.

               Overall, if a directory is writable and has the sticky bit
               set, files within that directory can only be removed if one
               or more of the following is true (see unlink(2)):

                    The user owns the file.
                    The user owns the directory.
                    The file is writable to the user.
                    The user is the superuser.

               If the mode bit 02000 (set group ID on execution) is set and
               the mode bit 00010 (execute or search by group) is not set,
               mandatory file/record locking will exist on a regular file.
               This may effect future calls to open(2P), creat(2),
               read(2P), and write(2P) on this file.

               chmod will fail and the file mode will be unchanged if one
               or more of the following is true:

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

               [ENOENT]       The named file does not exist.

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

               [EPERM]        The effective user ID does not match the


          Rev. 1.1                                                   Page 2





          chmod(2P)        INTERACTIVE UNIX System (POSIX)        chmod(2P)



                              owner of the file and the effective user ID
                              is not superuser.

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

               [EFAULT]       The path variable points outside the allo-
                              cated address space of the process.

               [EINTR]        A signal was caught during the chmod system
                              call.

               [ENOLINK]      The path variable points to a remote machine
                              and the link to that machine is no longer
                              active.

               [EMULTIHOP]    Components of path require hopping to multi-
                              ple remote machines.

               [ENAMETOOLONG] The length of the path argument exceeds
                              {PATH_MAX}, or a path name component is
                              longer than {NAME_MAX} while
                              {_POSIX_NO_TRUNC} is in effect.

          SEE ALSO
               chown(2P), creat(2), fcntl(2), mknod(2), open(2P), read(2P),
               write(2P.
               chmod(1) in the INTERACTIVE UNIX System User's/System
               Administrator's Reference Manual.

          DIAGNOSTICS
               Upon successful completion, a value of 0 is returned.  Oth-
               erwise, a value of -1 is returned, and errno is set to indi-
               cate the error.





















          Rev. 1.1                                                   Page 3



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