*nix Documentation Project
·  Home
 +   man pages
·  Linux HOWTOs
·  FreeBSD Tips
·  *niX Forums

  man pages->HP-UX 11i man pages -> chmod (2)              
Title
Content
Arch
Section
 

l(2)

Contents


 chmod(2)                                                           chmod(2)




 NAME    [Toc]    [Back]
      chmod(), fchmod() - change file mode access permissions

 SYNOPSIS    [Toc]    [Back]
      #include <sys/stat.h>

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

      int fchmod(int fildes, mode_t mode);

 DESCRIPTION    [Toc]    [Back]
      The chmod() and fchmod() system calls set the access permission
      portion of the file's mode according to the bit pattern contained in
      mode.  path points to a path name naming a file.  fildes is a file
      descriptor.

      The following symbolic constants representing the access permission
      bits are defined with the indicated values in <sys/stat.h> and are
      used to construct the mode argument.  The value of mode is the bitwise
 inclusive OR of the values for the desired permissions.

           S_ISUID 04000 Set user ID on execution.
           S_ISGID 02000 Set group ID on execution.
           S_ENFMT 02000 Record locking enforced.
           S_ISVTX 01000 Save text image after execution.
           S_IRUSR 00400 Read by owner.
           S_IWUSR 00200 Write by owner.
           S_IXUSR 00100 Execute (search) by owner.
           S_IRGRP 00040 Read by group.
           S_IWGRP 00020 Write by group.
           S_IXGRP 00010 Execute (search) by group.
           S_IROTH 00004 Read by others (that is, anybody else).
           S_IWOTH 00002 Write by others.
           S_IXOTH 00001 Execute (search) by others.

      To change the mode of a file, the effective user ID of the process
      must match that of the owner of the file or a user with appropriate
      privileges.

      If the effective user ID of the process is not that of a user with
      appropriate privileges, mode bit S_ISVTX is cleared.

      If the effective user ID of the process is not that of a user with
      appropriate privileges, and the effective group ID of the process does
      not match the group ID of the file and none of the group IDs in the
      supplementary groups list match the group ID of the file, mode bit
      S_ISGID is cleared.

      The mode bit S_ENFMT (same as S_ISGID) is used to enforce file-locking
      mode (see lockf(2) and fcntl(2)) on files that are not group
      executable.  This might affect future calls to open(), creat(),



 Hewlett-Packard Company            - 1 -   HP-UX 11i Version 2: August 2003






 chmod(2)                                                           chmod(2)




      read(), and write() on such files (see open(2), creat(2), read(2), and
      write(2)).

      If an executable file is prepared for sharing, mode bit S_ISVTX
      prevents the system from abandoning the swap-space image of the
      program-text portion of the file when its last user terminates.  Then,
      when the next user of the file executes it, the text need not be read
      from the file system but can simply be swapped in, thus saving time.

      If the mode bit S_ISVTX (sticky bit) is set on a directory, files
      inside the directory may be renamed or removed only by the owner of
      the file, the owner of the directory, or the superuser (even if the
      modes of the directory would otherwise allow such an operation).

      If the path given to chmod() contains a symbolic link as the last
      element, this link is traversed and path name resolution continues.
      chmod() changes the access mode of the symbolic link's target, rather
      than the access mode of the link.

    Access Control Lists - HFS File Systems Only    [Toc]    [Back]
      All optional entries in a file's access control list are deleted when
      chmod() is executed.  (This behavior conforms to the IEEE Standard
      POSIX 1003.1-1988.) To preserve optional entries in a file's access
      control list, it is necessary to save and restore them using getacl()
      and setacl() (see getac
).

      To set the permission bits of access control list entries, use
      setacl() instead of chmod().

    Access Control Lists - JFS File Systems Only    [Toc]    [Back]
      The effective permissions granted by optional entries in a file's
      access control list may be changed when chmod() is executed.  In
      particular, using chmod() to remove read, write and execute
      permissions from a file's owner, owning group, and all others works as
      expected, because chmod() affects the class entry in the ACL, limiting
      any access that can be granted to additional users or groups via
      optional ACL entries.  The effect can be verified by doing a getacl(1)
      on the file after the chmod(), and noting that all optional (nondefault)
 ACL entries with nonzero permissions also have the comment #
      effective:---.

      To set the permission bits of access control list entries, use
      setacl() instead of chmod().

      For more information on access control list entries, see acl(5) and
      aclv(5).

 RETURN VALUE    [Toc]    [Back]
      chmod() returns the following values:





 Hewlett-Packard Company            - 2 -   HP-UX 11i Version 2: August 2003






 chmod(2)                                                           chmod(2)




            0   Successful completion.
           -1   Failure.  errno is set to indicate the error.

 ERRORS    [Toc]    [Back]
      If chmod() fails, the file mode is unchanged.  errno is set to one of
      the following values:

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

           [EFAULT]            path points outside the allocated address
                               space of the process.  The reliable detection
                               of this error is implementation dependent.

           [EINVAL]            path or fildes descriptor does not refer to
                               an appropriate file.

           [ELOOP]             Too many symbolic links were encountered in
                               translating path.

           [ENAMETOOLONG]      A component of path exceeds NAME_MAX bytes
                               while _POSIX_NO_TRUNC is in effect or path
                               exceeds PATH_MAX bytes.

           [ENOENT]            A component of path or the file named by path
                               does not exist.

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

           [EPERM]             The effective user ID does not match that of
                               the owner of the file, and the effective user
                               ID is not that of a user with appropriate
                               privileges.

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

      If fchmod() fails, the file mode is unchanged.  errno is set to one of
      the following values:

           [EBADF]             fildes is not a valid file descriptor.

           [EPERM]             The effective user ID does not match that of
                               the owner of the file, and the effective user
                               ID is not that of a user with appropriate
                               privileges.

           [EINVAL]            path or fildes descriptor does not refer to
                               an appropriate file.




 Hewlett-Packard Company            - 3 -   HP-UX 11i Version 2: August 2003






 chmod(2)                                                           chmod(2)




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

 AUTHOR    [Toc]    [Back]
      chmod() was developed by AT&T, the University of California, Berkeley,
      and HP.

      fchmod() was developed by the University of California, Berkeley.

 SEE ALSO    [Toc]    [Back]
      chmod(1), getacl(1), chown(2), creat(2), fcntl(2), getacl(2), read(2),
      lockf(2), mknod(2), open(2), setacl(2), write(2), acl(5), aclv(5).

 STANDARDS CONFORMANCE    [Toc]    [Back]
      chmod(): AES, SVID2, SVID3, XPG2, XPG3, XPG4, FIPS 151-2, POSIX.1

      fchmod(): AES, SVID3


 Hewlett-Packard Company            - 4 -   HP-UX 11i Version 2: August 2003
[ Back ]
      
      
 Similar pages
Name OS Title
chmod IRIX change the permissions mode of a file or directory
chmod Tru64 Change file access permissions
fchmod Tru64 Change file access permissions
chmod Linux change file access permissions
chmod Linux change permissions of a file
permissions IRIX Change Permissions - Modify Permissions and Ownership of Files
access NetBSD check access permissions of a file or pathname
access OpenBSD check access permissions of a file or pathname
chmod IRIX change mode of a file
chmod OpenBSD change mode of file
Copyright © 2004-2005 DeniX Solutions SRL
newsletter delivery service