HPlogo MPE/iX Developer's Kit Reference Manual Volume I: HP 3000 MPE/iX Computer Systems > Chapter 4  POSIX/iX Library Function Descriptions

hmod

» 

Technical documentation

Complete book in PDF
» Feedback

 » Table of Contents

 » Index

Changes file access permissions.

Syntax

   #include <sys/types.h>

   #include <sys/stat.h> 

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

Parameters

pathname

A pointer to a string containing the pathname of a file or directory whose access permissions are to be modified. The pathname must be terminated by a null character.

mode

New access permissions. Access permission bits are set by ORing any combination of the following macros:

S_IRWXU

Set file owner class read, write, and execute (if a file) or search (if a directory) permission bits.

S_IRUSR

Set file owner class read permission bit.

S_IWUSR

Set file owner class write permission bit.

S_IXUSR

Set file owner class execute (if a file) or search (if a directory) permission bit.

S_IRWXG

Set file group class read, write, and execute (if a file) or search (if a directory) permission bits.

S_IRGRP

Set file group class read permission bit.

S_IWGRP

Set file group class write permission bit.

S_IXGRP

Set file group class execute (if a file) or search (if a directory) permission bit.

S_IRWXO

Set file other class read, write, and execute (if a file) or search (if a directory) permission bits.

S_IROTH

Set file other class read permission bit.

S_IWOTH

Set file other class write permission bit.

S_IXOTH

Set file other class execute (if a file) or search (if a directory) permission bit.

Unused bits of the mode parameter not associated with access permissions must contain zeros, or an error occurs.

Return Values

0

Success.

-1

An error occurred. Access permission bits are not changed, and errno is set to indicate the error condition.

Description

The chmod() function sets the file access permission bits of the file or directory named in pathname to the bits specified in mode. Access permissions can be modified only when one of the following conditions is true:

  • The user associated with the calling process is the file owner (a user whose effective UID matches the UID of the file).

  • The user associated with the calling process has appropriate privileges, defined to be one of the following:

    • a user whose GID matches the GID of the file and who has the MPE/iX account manager (AM) user capability

    • a user who has the MPE/iX system manager (SM) user capability

Upon successful completion, chmod() marks for update the st_ctime time field of the file.

Implementation Considerations

Refer to the EIMPL, EINVAL, and EFAULT error descriptions below.

The S_ISUID and S_ISGID bits are not currently supported.

Changes to file access permission bits do not affect access to pathname through open file descriptors already associated with pathname at the time of the chmod() call.

If bits in mode other than access permission bits are set to a nonzero value, an error is returned and access permission bits are not changed.

Errors

If an error occurs, errno is set to one of the following values:

EACCESCAUSEThe calling process does not have search permission to a component of the pathname.
 ACTIONMake sure that the calling process has search permission to all component directories in the pathname.
EFAULTCAUSEThe system detected a NULL or bad address in attempting to use pathname, or the pathname was not terminated by a null character.
 ACTIONMake sure that the pointer is correctly initialized.
EIMPLCAUSE

One of the following:

  • The pathname begins with two slash characters (//).

  • The unused bits of the mode parameter do not contain zeros.

 ACTION

One of the following:

  • Do not begin pathnames with two slash characters (//).

  • Set to zero all mode bits that are not access permission bits.

EINVALCAUSEThe pathname parameter specified the root directory, an MPE/iX account, or an MPE/iX group.
 ACTIONDo not attempt to change the access permission bits of the root directory, an MPE/iX account, or an MPE/iX group.
ENAMETOOLONGCAUSE

One of the following:

  • The length of the pathname exceeds the {PATH_MAX} limit (defined in the file <limits.h>).

  • A component of the pathname is longer than {NAME_MAX} (defined in <limits.h>), and {_POSIX_NO_TRUNC} is in effect for that directory.

 ACTIONMake sure that both the component's length and the full pathname length do not exceed the {NAME_MAX} or {PATH_MAX} limits.
ENOENTCAUSEThe specified file does not exist, or pathname points to an empty string.
 ACTIONSpecify an existing filename.
ENOTDIRCAUSEA component of the pathname is not a directory.
 ACTIONSpecify a valid pathname.
EPERMCAUSE

One of the following:

  • The calling process does not have the MPE/iX process handling (PH) capability.

  • The calling process has outstanding switches to CM code, has set critical mode, has outstanding NOWAITIO, or is holding an operating system internal resource, or the calling process is in a Procedure Exit handler.

 ACTION

One of the following:

  • Link the program file with the MPE/iX PH capability.

  • Do not execute execl() when the calling process has outstanding switches to CM code, has set critical mode, has outstanding NOWAITIO, or is holding an operating system internal resource, or in a Procedure Exit handler.

See Also

chown(), mkdir(), stat(), fstat(), <sys/stat.h>, POSIX.1 (Section 5.6.4)

Feedback to webmaster