STAT(2) — HP-UX
NAME
stat, lstat, fstat − get file status
SYNOPSIS
#include <sys/types.h>
#include <sys/stat.h>
int stat (path, buf)
char ∗path;
struct stat ∗buf;
int lstat (path, buf)
char *path;
struct stat *buf;
int fstat (fildes, buf)
int fildes;
struct stat ∗buf;
DESCRIPTION
Stat obtains information about the named file.
Path points to a path name naming a file. Read, write, or execute permission of the named file is not required, but all directories listed in the path name leading to the file must be searchable.
Similarly, fstat obtains information about an open file known by the file descriptor fildes, obtained from a successful open, creat, dup, fcntl, or pipe system call.
Lstat is similar to stat except when the named file is a symbolic link, in which case lstat returns the information about the link, while stat returns information about the file to which the link points.
Buf is a pointer to a stat structure into which information is placed concerning the file.
The contents of the structure stat pointed to by buf include the following members:
dev_tst_dev; /* ID of device containing a */
/* directory entry for this file */
ino_tst_ino; /* Inode number */
ushortst_mode; /* File mode; see mknod(2) */
ushortst_nlink; /* Number of links */
ushortst_uid; /* User ID of file owner */
ushortst_gid; /* Group ID of file group */
dev_tst_rdev; /* Device ID; this entry defined */
/* only for char or blk spec files */
off_tst_size; /* File size (bytes) */
time_tst_atime; /* Time of last access */
time_tst_mtime; /* Last modification time */
time_tst_ctime; /* Last file status change time */
/* Measured in secs since */
/* 00:00:00 GMT, Jan 1, 1970 */
st_atime Field indicating when file data was last accessed. Changed by the following system calls: creat(2), mknod(2), pipe(2), read(2), readv (on read(2)), and utime(2).
st_mtime Field indicating when data was last modified. Changed by the following system calls: creat(2), truncate(2), ftruncate (on truncate(2)), mknod(2), pipe(2), prealloc(2), utime(2), write(2), and writev (on write(2)). Also changed by close(2) when the file is a named pipe (FIFO special) and the reference counts are zero.
st_ctime Field indicating when file status was last changed. Changed by the following system calls: chmod(2), chown(2), creat(2), fchmod(2), fchown(2), truncate(2), ftruncate (on truncate(2)), link(2), mknod(2), pipe(2), prealloc(2), rename(2), unlink(2), utime(2), write(2), and writev (on write(2)).
The touch(1) command can be used to explicitly control the times of a file.
NETWORKING FEATURES
RFA
The contents of the structure stat pointed to by buf also include the following members:
uintst_remote:1; /* Set if file is remote */
dev_tst_netdev; /* ID of device containing */
/* network special file */
ino_tst_netino; /* Inode number of network special file */
st_remote Field indicating whether the file is on a remote node. A zero value indicates that the file is on the local node; non-zero indicates that the file is on a remote node, and accessed through remote file access (RFA). Not all HP-UX systems support RFA; st_remote is always zero on non-RFA supported systems.
st_netdev, st_netino All remote file access takes place through a special file in the local file system known as a network special file. Each network special file identifies a particular remote node. When st_remote is non-zero, st_netdev and st_netino identify the appropriate network special file; otherwise these fields are zero.
RETURN VALUE
Upon successful completion, 0 is returned. Otherwise, −1 is returned and errno is set to indicate the error.
ERRORS
Stat or lstat will fail if any of the following is true:
[ENOTDIR] A component of the path prefix is not a directory.
[ENOENT] The named file does not exist (for example, path is null or a component of path does not exist).
[EACCES] Search permission is denied for a component of the path prefix.
[EFAULT] Buf or path points to an invalid address. The reliable detection of this error will be implementation dependent.
[ELOOP] Too many symbolic links were encountered in translating the path name.
Fstat will fail if any of the following are true:
[EBADF] Fildes is not a valid open file descriptor.
[EFAULT] Buf points to an invalid address. The reliable detection of this error will be implementation dependent.
DEPENDENCIES
Series 300 Diskless
The contents of the stat structure include the following additional members:
cnode_tst_cnode;/* Cnode ID of machine */
/* where the inode lives */
dev_tst_realdev;/* Real device number of device */
/* containing the inode for this file */
st_dev The ID number for the volume on which the inode exists. This number may or may not be the device number for the device containing the volume. Device numbers are not unique throughout a cluster, but the value of st_dev is guaranteed to be unique among all volumes currently mounted in the file system. The device number for the volume can always be found in the field st_realdev, which together with st_cnode fully specifies the device containing the volume.
Series 500
Besides the definition given above, st_size is significant for special files that refer to disks. In that case, st_size returns either the total physical size (in bytes) of the mass storage volume, when appropriate, or −1. This is a property of the physical device, not any directory structure imposed by it.
The fields st_netdev and st_netino are not supported.
The lstat call is not currently supported.
Series 800
Symbolic links are not supported.
AUTHOR
Stat and fstat were developed by AT&T. Lstat was developed by The University of California, Berkeley.
SEE ALSO
touch(1), chmod(2), chown(2), creat(2), link(2), mknod(2), pipe(2), read(2), rename(2), time(2), truncate(2), unlink(2), utime(2), write(2), stat(5).
Hewlett-Packard Company — Version B.1, May 11, 2021