Museum

Home

Lab Overview

Retrotechnology Articles

⇒ Online Manual

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

chmod(1)

chown(2)

getgroups(2)

mknod(2)

setgroups(2)



  chmod(2)                            CLIX                            chmod(2)



  NAME

    chmod - Changes file access permissions

  LIBRARY

    Standard C Library (libc.a)

  SYNOPSIS

    #include <sys/types.h>

    #include <sys/stat.h>

    int chmod(
      char *path ,
      mode_t mode );

  PARAMETERS

    path   Specifies the full pathname of the file.

    mode   Specifies the bit pattern that determines the access permissions.
           The mode parameter is constructed by a logical OR of one or more of
           the following values, which are defined in the <sys/stat.h> header
           file:

           04000   S_ISUID   Sets the process's effective user ID to
                             the file owner on execution.
           02000   S_ISGID   Sets the process's effective group ID to
                             the file group on execution if S_IXGRP
                             is also set.  Otherwise, enable
                             mandatory file/record locking if S_IXGRP
                             is not set.
           01000   S_ISVTX   Saves text image after execution.
           02000   S_ENFMT   Enables enforcement-mode record locking.
           00400   S_IRUSR   Permits the file owner to read it.
           00200   S_IWUSR   Permits the file owner to write to it.
           00100   S_IXUSR   Permits the file owner to execute it (or
                             to search the directory).
           00040   S_IRGRP   Permits the file group to read it.
           00020   S_IWGRP   Permits the file group to write to it.
           00010   S_IXGRP   Permits the file group to execute it (or
                             to search the directory).
           00004   S_IROTH   Permits others to read the file.
           00002   S_IWOTH   Permits others to write to the file.
           00001   S_IXOTH   Permits others to execute the file (or
                             to search the directory).

  DESCRIPTION




  2/94 - Intergraph Corporation                                              1






  chmod(2)                            CLIX                            chmod(2)



    The chmod() function sets the access permissions of the file specified by
    the path parameter.  The access permissions of the file are set according
    to the bit pattern specified by the mode parameter.

    To change file access permissions, the effective user ID of the calling
    process must either match the ID of the file owner or be superuser.

    Mode values (other than the ones listed in the PARAMETERS section) exist
    that can be set with the mknod() function, but not with chmod().

    Setting S_ISVTX for a shared executable file prevents the system from
    unmapping the program text segment of the file when its last user
    terminates.  Thus, when the next process executes it, the text need not be
    read from the file system.  It is simply paged in, saving time.

    If S_ISGID is set and S_IXGRP is not set, mandatory file/record locking
    will exist on a regular file.  This may effect future calls to the open(),
    creat(), read(), and write() functions on this file.

    If the effective user ID of the calling process is not superuser, chmod()
    clears the S_ISVTX bit.

    If the effective user ID of the process is not superuser, and if the
    effective group ID or one of the supplementary groups of the process does
    not match the file's existing group ID, chmod() clears the S_ISGID bit.

  EXAMPLES

    1.  To grant read-only permission for all users and write permission only
        to the owner of a file:

        if (!chmod("filename", S_IRUSR | S_IWUSR | S_IRGRP |
                    S_IROTH))
             perror("Could not chmod filename");


    2.  To use octal values for the same example as shown above:

        if (!chmod("filename", 00400 | 00200 | 00040 | 00004))
             perror("Could not chmod filename");


  RETURN VALUES

    Upon successful completion, chmod() returns a value of 0.  If chmod()
    fails, a value of -1 is returned, and the global variable errno is set to
    identify the error.

  ERRORS

    The chmod() function fails and the file permissions remain unchanged if



  2                                              Intergraph Corporation - 2/94






  chmod(2)                            CLIX                            chmod(2)



    one or more of the following are true:

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

    [ENOENT]
           The named file does not exist.

    [EACCESS]
           A component of the path parameter has search permission denied.

    [EPERM]
           The effective user ID does not match the ID of the owner of the
           file or the effective user ID is not superuser.

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

    [EFAULT]
           The path parameter points to a location outside of the allocated
           address space of the process.

    [ENAMETOOLONG]
           The length of the path parameter exceeds PATH_MAX, or a pathname
           component is longer than NAME_MAX while _POSIX_NO_TRUNC is in
           effect.

    [EINTR]
           A signal was caught during the chmod() function.

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

    [EMULTIHOP]
           Components of path require hopping to multiple remote machines.

  RELATED INFORMATION

    Commands:  chmod(1)

    Functions:  chown(2), getgroups(2), mknod(2), setgroups(2)












  2/94 - Intergraph Corporation                                              3




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