Hubbry Logo
search
logo
2131397

Stat (system call)

logo
Community Hub0 Subscribers
Write something...
Be the first to start a discussion here.
Be the first to start a discussion here.
See all
Stat (system call)

stat() is a Unix system call that queries the file system for metadata about a file (including special files such as directories). The metadata contains many fields including type, size, ownership, permissions and timestamps.

For example, the ls command uses this system call to retrieve timestamps:

stat() appeared in Version 1 Unix. It is among the few original Unix system calls to change, with Version 4's addition of group permissions and larger file size.

Since at least 2004, the same-named shell command stat has been available for Linux to expose features of the system call via a command-line interface.

The C POSIX library header sys/stat.h, found on POSIX and other Unix-like operating systems, declares stat() and related functions.

Each function accepts a pointer to a struct stat buffer which the function loads with information about the specified file. As typical for system calls, each function returns 0 on success, or on failure, sets errno to indicate the failure condition and returns −1.

The stat() and lstat() functions accept a path argument that specifies a file. If the path identifies a symbolic link, stat() returns attributes of the link target, whereas lstat() returns attributes of the link itself. The fstat() function accepts a file descriptor argument instead of a path, and returns attributes of the file that it identifies.

The library has been extended to support large files. Functions stat64(), lstat64() and fstat64() load information into a struct stat64 buffer, which supports 64-bit sizes, allowing them to work with files 2 GiB and larger (up to 8 EiB). When the _FILE_OFFSET_BITS macro is defined as 64, the 64-bit functions are available as the original names.

See all
User Avatar
No comments yet.