stat.2 (2010 09)

s
stat(2) stat(2)
NAME
stat() - get file status
SYNOPSIS
#include <sys/types.h>
#include <sys/stat.h>
int stat(const char *path, struct stat *buf);
DESCRIPTION
The stat() function obtains information about the named file and writes it to the area pointed to by the
buf argument. The path argument is a pointer to a path name of any file within the mounted file system.
(All directories listed in the path name must be searchable). Read, write or execute permission of the
named file is not required, but all directories listed in the pathname leading to all directories listed in the
pathname leading to the file must be searchable. An implementation that provides additional or alter-
nate file access control mechanisms may, under implementation-dependent conditions, cause
stat() to
fail. In particular, the system may deny the existence of the file specified by path .
The buf argument is a pointer to a
stat structure, as defined in the header <sys/stat.h>, into which
information is placed concerning the file. The
stat structure contains the following members:
dev_t st_dev; /* ID of device containing a */
/* directory entry for this file */
ino_t st_ino; /* Inode number */
short st_fstype; /* Type of filesystem this file */
/* is in; see sysfs(2) */
ushort st_mode; /* File type, attributes, and */
/* access control summary */
ushort st_basemode /* Permission bits (see chmod(1)) */
ushort st_nlink; /* Number of links */
uid_t st_uid; /* User ID of file owner */
gid_t st_gid; /* Group ID of file group */
dev_t st_rdev; /* Device ID; this entry defined */
/* only for char or blk spec files */
off_t st_size; /* File size (bytes) */
time_t st_atime; /* Time of last access */
int st_natime; /* Reserved, DO NOT USE; field may change. */
time_t st_mtime; /* Last modification time */
int st_nmtime; /* Reserved, DO NOT USE, field may change. */
time_t st_ctime; /* Last file status change time */
/* Measured in secs since */
/* 00:00:00 GMT, Jan 1, 1970 */
int st_nctime; /* Reserved, DO NOT USE; field may change */
long st_blksize; /* File system block size */
blkcnt_t st_blocks; /* Number of blocks of a */
/* file-system-specific size */
/* allocated for this object */
uint st_acl:1; /* Set if the file has optional */
/* access control list entries */
/* HFS File Systems only */
uint st_aclv:1; /* Set if the file has optional */
/* access control list entries */
/* JFS File Systems only */
(Note that the position of items in this list does not necessarily reflect the order of the members in the
structure.)
If the chosen path name or file descriptor refers to a Multi-Level Directory (MLD), and the process does
not have the multilevel effective privilege, the i-node number returned in st_ino is the i-node of the MLD
itself.
The
stat() function updates any time-related fields (as described in the definition of File Times Update
in the XBD specification), before writing into the stat structure.
The structure members st_mode , st_ino , st_dev , st_uid , st_gid , st_atime , st_ctime , and st_mtime will
have meaningful values for all file types defined in this document. The value of the member st_nlink will
HP-UX 11i Version 3: September 2010 1 Hewlett-Packard Company 1

Summary of content (2 pages)