#include <sys/stat.h> int fstat(int descriptor, struct stat *buffer)
The fstat() function gets status information about the object specified by the open descriptor descriptor and stores the information in the area of memory indicated by the buffer argument. The status information is returned in a stat structure, as defined in the <sys/stat.h> header file.
The st_mode, st_dev, and st_blksize fields are the only fields set for socket descriptors. The st_mode field is set to a value that indicates the descriptor is a socket descriptor, the st_dev field is set to -1, and the st_blksize field is set to an optimal value determined by the system.
No authorization is required.
0 | fstat() was successful. The information is returned in buffer. |
-1 | fstat() was not successful. The errno global variable is set to indicate the error. |
If fstat() 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] |
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] | |
[EBADF] | |
[EBADFID] | |
[EBADFUNC] |
A given descriptor or directory pointer is not valid for this operation. The specified descriptor is incorrect, or does not refer to an open object. |
[EBUSY] | |
[EDAMAGE] | |
[EFAULT] | |
[EINVAL] |
This error code may be returned when the underlying object represented by the descriptor is unable to fill the stat structure (for example, if the function was issued against a socket descriptor that had its connection reset). |
[EIO] | |
[ENOBUFS] | |
[ENOSYSRSC] | |
[ENOTAVAIL] | |
[ENOTSAFE] | |
[EOVERFLOW] |
The specified file exists and its size is too large to be represented in the structure pointed to by buffer (the file is larger than 2GB minus 1 byte). |
[EPERM] | |
[ESTALE] |
If you are accessing a remote file through the Network File System, the file may have been deleted at the server. |
[EUNATCH] | |
[EUNKNOWN] |
If interaction with a file server is required to access the object, errno could also indicate one of the following errors:
Error condition | Additional information |
---|---|
[EADDRNOTAVAIL] | |
[ECONNABORTED] | |
[ECONNREFUSED] | |
[ECONNRESET] | |
[EHOSTDOWN] | |
[EHOSTUNREACH] | |
[ENETDOWN] | |
[ENETRESET] | |
[ENETUNREACH] | |
[ETIMEDOUT] |
The following messages may be sent from this function:
Message ID | Error Message Text |
---|---|
CPFA0D4 E | File system error occurred. Error number &1. |
CPFA081 E | Unable to set return value or error code. |
CPF3CF2 E | Error(s) occurred during running of &1 API. |
CPE3418 E | Possible APAR condition or hardware failure. |
CPF9872 E | Program or service program &1 in library &2 ended. Reason code &3. |
Note: IBM reserves the right to change the calculation of the optimal send size.
The value for st_atime will always be zero. The value for st_ctime will always be the creation date and time of the file or directory.
The user, group, and other mode bits are always on for an object that exists on a volume not formatted in Universal Disk Format (UDF).
fstat() on /QOPT will always return 2,147,483,647 for size fields.
fstat() on optical volumes will return the volume capacity or 2,147,483,647, whichever is smaller.
The file access time is not changed.
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 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 QNetWare file system does not fully support mode bits. See the Netware on iSeries topic for more information.
The value of st_vfs will always be 0 for remote objects accessed via QFileSvr.400.
See Code disclaimer information for information pertaining to code examples.
The following example gets status information:
#include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #include <stdio.h> #include <time.h> main() { char fn[]="temp.file"; struct stat info; int file_descriptor; if ((file_descriptor = creat(fn, S_IWUSR)) < 0) perror("creat() error"); else { if (fstat(file_descriptor, &info) != 0) perror("fstat() error"); else { puts("fstat() returned:"); printf(" inode: %d\n", (int) info.st_ino); printf(" dev id: %d\n", (int) info.st_dev); printf(" mode: %08x\n", info.st_mode); printf(" links: %d\n", info.st_nlink); printf(" uid: %d\n", (int) info.st_uid); printf(" gid: %d\n", (int) info.st_gid); } close(file_descriptor); unlink(fn); } }
Output: Note that the output may vary from system to system.
fstat() returned: inode: 3057 dev id: 1 mode: 03000080 links: 1 uid: 137 gid: 500
Top | UNIX-Type APIs | APIs by category |