#include <unistd.h> int faccessx(int fildes, int amode, int who);Service Program Name: QP0LLIB1
The faccessx() function determines whether a file can be accessed by a specified class of users in a particular manner.
Adopted authority is not used.
The following symbols, which are defined in the <unistd.h> header file, can be used in amode:
You can take the bitwise inclusive OR of any or all of the last three symbols to test several access modes at once. If you are using F_OK to test for the existence of the file, you cannot use OR with any of the other symbols. If any other bits are set in amode, faccessx() returns the [EINVAL] error.
The following symbols, which are defined in the <unistd.h> header file, can be used in who:
Note: If the real and effective user ID are the same and the real and effective group ID are the same, the request is treated as ACC_INVOKER. See the Usage Notes for more details.
The following authorities are required if the who parameter is ACC_SELF or ACC_INVOKER. If ACC_SELF is specified, the effective UID and GID of the caller are used. If ACC_INVOKER is used, the real UID and GID of the caller are used.
Authorization Required for faccessx()
Object Referred to | Authority Required | errno |
---|---|---|
Object when R_OK is specified | *R | EACCES |
Object when W_OK is specified | *W | EACCES |
Object when X_OK is specified | *X | EACCES |
Object when R_OK | W_OK is specified | *RW | EACCES |
Object when R_OK | X_OK is specified | *RX | EACCES |
Object when W_OK | X_OK is specified | *WX | EACCES |
Object when R_OK | W_OK | X_OK is specified | *RWX | EACCES |
Object when F_OK is specified | None | None |
If the current thread has *ALLOBJ special authority, faccessx() with ACC_SELF or ACC_INVOKER will indicate success for R_OK, W_OK, or X_OK even if none of the permission bits are set.
If faccessx() is not successful, errno usually indicates one of the following errors. Under some conditions, errno could indicate an error other than those listed here.
Error condition | Additional information |
---|---|
[EACCES] |
The class of users specified by the who parameter does not have the permission indicated by the amode parameter. If you are accessing a remote file through the Network File System, update operations to file permissions at the server are not reflected at the client until updates to data that is stored locally by the Network File System take place. (Several options on the Add Mounted File System (ADDMFS) command determine the time between refresh operations of local data.) Access to a remote file may also fail due to different mappings of user IDs (UID) or group IDs (GID) on the local and remote systems. |
[EAGAIN] | |
[EBADFID] | |
[EBADNAME] | |
[EBUSY] | |
[ECONVERT] | |
[EDAMAGE] | |
[EFAULT] | |
[EFILECVT] | |
[EINVAL] | |
[EIO] | |
[EINTR] | |
[ENOSPC] | |
[ENOTAVAIL] | |
[ENOTSAFE] | |
[ENOTSUP] | |
[EROOBJ] | |
[ESTALE] |
If you are accessing a remote file through the Network File System, the file may have been deleted at the server. |
[ETXTBSY] | |
[EUNKNOWN] |
If interaction with a file server is required to access the object, errno could indicate one of the following errors:
Error condition | Additional information |
---|---|
[EADDRNOTAVAIL] | |
[ECONNABORTED] | |
[ECONNREFUSED] | |
[ECONNRESET] | |
[EHOSTDOWN] | |
[EHOSTUNREACH] | |
[ENETDOWN] | |
[ENETRESET] | |
[ENETUNREACH] | |
[ESTALE] |
If you are accessing a remote file through the Network File System, the file may have been deleted at the server. |
[ETIMEDOUT] | |
[EUNATCH] |
The following messages may be sent from this function:
Message ID | Error Message Text |
---|---|
CPE3418 E | Possible APAR condition or hardware failure. |
CPFA0D4 E | File system error occurred. Error number &1. |
CPF3CF2 E | Error(s) occurred during running of &1 API. |
CPF9872 E | Program or service program &1 in library &2 ended. Reason code &3. |
Some physical file systems do not support ACC_SELF for the who parameter. However, faccessx() will change the who parameter from ACC_SELF to ACC_INVOKER if the caller's real and effective user ID are equal, and the caller's real and effective group ID are equal.
The Network File System will only support the value ACC_INVOKER for the who parameter. If faccessx() is called on a file in a mounted Network File System directory with a value for who other than ACC_INVOKER, the call will return -1 and errno ENOTSUP. Note: If the value for who has been mapped from ACC_SELF to ACC_INVOKER as previously described, then ENOTSUP will not be returned.
Local access to remote files through the Network File System may produce unexpected results due to conditions at the server. Once a file is open, subsequent requests to perform operations on the file can fail because file attributes are checked at the server on each request. If permissions on the file are made more restrictive at the server or the file is unlinked or made unavailable by the server for another client, your operation on an open file descriptor will fail when the local Network File System receives these updates. The local Network File System also impacts operations that retrieve file attributes. Recent changes at the server may not be available at your client yet, and old values may be returned from operations. (Several options on the Add Mounted File System (ADDMFS) command determine the time between refresh operations of local data.)
The QNTC File System will only support the value ACC_INVOKER for the who parameter. If faccessx() is called on a file in the QNTC File System with a value for who other than ACC_INVOKER, the call will return -1 and errno ENOTSUP.
Note: If the value for who has been mapped from ACC_SELF to ACC_INVOKER as previously described, then ENOTSUP will not be returned.
If the file descriptor refers to an object that exists on a volume formatted in Universal Disk Format (UDF), the authorization that is checked for the object follows the rules described in the previous table, Authorization Required for faccessx(). If the object exists on a volume formatted in some other media format, no authorization checks are made on the object. The volume authorization list is checked for the requested authority regardless of the volume media format.
The QFileSvr.400 File System will only support the value ACC_INVOKER for the who parameter. If faccessx() is called on a file in the QFileSvr.400 File System with a value for who other than ACC_INVOKER, the call will return -1 and errno ENOTSUP.
Note: If the value for who has been mapped from ACC_SELF to ACC_INVOKER as previously described, then ENOTSUP will not be returned.
The QNetWare File System will only support the value ACC_INVOKER for the who parameter. If faccessx() is called on a file in the QNetWare File System with a value for who other than ACC_INVOKER, the call will return -1 and errno ENOTSUP.
Note: If the value for who has been mapped from ACC_SELF to ACC_INVOKER as previously described, then ENOTSUP will not be returned.
See Code disclaimer information for information pertaining to code examples.
The following example determines how a file is accessed:
#include <stdio.h> #include <unistd.h> #include <fcntl.h> main() { char path[]="/myfile"; int fd; fd = open(path, O_RDONLY); if (fd == -1) { printf("Error opening file.\n"); return; } if (faccessx(fd, R_OK, ACC_OTHERS) == 0) printf("Someone besides the owner has read access to '%s'\n", path); if (faccessx(fd, W_OK, ACC_OTHERS) == 0) printf("Someone besides the owner has write access to '%s'\n", path); if (faccessx(fd, X_OK, ACC_OTHERS) == 0) printf("Someone besides the owner has search access to '%s'\n", path); close(fd); }
Output:
In this example faccessx() was called on a descriptor for '/myfile'. The following would be the output if someone other than the owner has *R authority, someone besides the owner has *W authority, and noone other than the owner has *X authority.
Someone besides the owner has read access to '/' Someone besides the owner has write access to '/'
Top | UNIX-Type APIs | APIs by category |