Description

The stat() function obtains information about the file pointed to by path.
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.

The lstat() function obtains file attributes similar to stat(), except when the
named file is a symbolic link; in that case lstat() returns information
about the link, while stat() returns information about the file the link references.

The fstat() function obtains information about an open file known by the
file descriptor fildes, obtained from a successful open(2), creat(2), dup(2), fcntl(2), or
pipe(2) function. If fildes references a shared memory object, the system updates
in the stat structure pointed to by the buf argument only the
st_uid, st_gid, st_size, and st_mode fields, and only the S_IRUSR, S_IWUSR, S_IRGRP,
S_IWGRP, S_IROTH, and S_IWOTH file permission bits need be valid. The system
can update other fields and flags. The fstat() function updates any pending time-related
fields before writing to the stat structure.

The fstatat() function obtains file attributes similar to the stat(), lstat(), and
fstat() functions. If the path argument is a relative path, it
is resolved relative to the fildes argument rather than the current working directory.
If path is absolute, the fildes argument is unused. If
the fildes argument has the special value AT_FDCWD, relative paths are resolved
from the current working directory. If AT_SYMLINK_NOFOLLOW is set in the flag
argument, the function behaves like lstat() and does not automatically follow symbolic
links. See fsattr(5). If _AT_TRIGGER is set in the flag argument
and the vnode is a trigger mount point, the mount is performed
and the function returns the attributes of the root of the mounted
filesystem.

The buf argument is a pointer to a stat structure into which
information is placed concerning the file. A stat structure includes the following
members:

The mode of the file as described for the mknod() function. In addition to the modes described on the mknod(2) manual page, the mode of a file can also be S_IFSOCK if the file is a socket, S_IFDOOR if the file is a door, S_IFPORT if the file is an event port, or S_IFLNK if the file is a symbolic link. S_IFLNK can be returned either by lstat() or by fstat() when the AT_SYMLINK_NOFOLLOW flag is set.

st_ino

This field uniquely identifies the file in a given file system. The pair st_ino and st_dev uniquely identifies regular files.

st_dev

This field uniquely identifies the file system that contains the file. Its value may be used as input to the ustat() function to determine more information about this file system. No other meaning is associated with this value.

st_rdev

This field should be used only by administrative commands. It is valid only for block special or character special files and only has meaning on the system where the file was configured.

st_nlink

This field should be used only by administrative commands.

st_uid

The user ID of the file's owner.

st_gid

The group ID of the file's group.

st_size

For regular files, this is the address of the end of the file. For block special or character special, this is not defined. See also pipe(2).

st_atime

Time when file data was last accessed. Some of the functions that change this member are: creat(), mknod(), pipe(), utime(2), and read(2).

st_mtime

Time when data was last modified. Some of the functions that change this member are: creat(), mknod(), pipe(), utime(), and write(2).

The following example fragment gets status information for each entry in a
directory. The call to the stat() function stores file information in the
stat structure pointed to by statbuf. The lines that follow the stat()
call format the fields in the stat structure for presentation to the user
of the program.

The following example shows how to obtain file status information for a
file named /home/cnd/mod1. The structure variable buffer is defined for the stat
structure. The /home/cnd/mod1 file is opened with read/write privileges and is passed to the
open file descriptor fildes.

The following example shows how to obtain status information for a symbolic
link named /modules/pass1. The structure variable buffer is defined for the stat
structure. If the path argument specified the filename for the file pointed to
by the symbolic link (/home/cnd/mod1), the results of calling the function would
be the same as those returned by a call to the stat()
function.

Usage

If chmod() or fchmod() is used to change the file group owner
permissions on a file with non-trivial ACL entries, only the ACL mask
is set to the new permissions and the group owner permission bits
in the file's mode field (defined in mknod(2)) are unchanged. A
non-trivial ACL entry is one whose meaning cannot be represented in the
file's mode field alone. The new ACL mask permissions might change the
effective permissions for additional users and groups that have ACL entries on
the file.

The stat(), fstat(), and lstat() functions have transitional interfaces for 64-bit file
offsets. See lf64(5).