Stat (system call)
is a Unix system call that queries the file system for metadata about a file (including special files such as directories).[src] The metadata contains many fields including type, size, ownership, permissions and timestamps.[src] For example, the command uses this system call to retrieve timestamps: * mtime: when last modified ( ) * atime: when last accessed ( ) * ctime: when last status changed ( ) appeared in Version 1 Unix.[src] It is among the few original Unix system calls to change, with Version 4's addition of group permissions and larger file size.[src] 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.[src]
is a Unix system call that queries the file system for metadata about a file (including special files such as directories).[src] The metadata contains many fields including type, size, ownership, permissions and timestamps.[src] For example, the command uses this system call to retrieve timestamps: mtime: when last modified ( ) atime: when last accessed ( ) ctime: when last status changed ( ) appeared in Version 1 Unix.[src] It is among the few original Unix system calls to change, with Version 4's addition of group permissions and larger file size.[src] 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.[src] ==Functions== The C POSIX library header , found on POSIX and other Unix-like operating systems, declares stat() and related functions.[src] int stat(const char* path, struct stat* buf); int lstat(const char* path, struct stat* buf); int fstat(int filedesc, struct stat* buf); Each function accepts a pointer to a struct stat buffer which the function loads with information about the specified file.[src] As typical for system calls, each function returns 0 on success, or on failure, sets errno to indicate the failure condition and returns −1.[src] The stat() and lstat() functions accept a path argument that specifies a file.[src] If the path identifies a symbolic link, stat() returns attributes of the link target, whereas lstat() returns attributes of the link itself.[src] The fstat() function accepts a file descriptor argument instead of a path, and returns attributes of the file that it identifies.[src] The library has been extended to support large files.[src] 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).[src] When the _FILE_OFFSET_BITS macro is defined as 64, the 64-bit functions are available as the original names.[src] ==Data structure== The metadata structure is defined in the header.[src] The following shows the base fields, but an implementation is free to include additional fields: struct stat { mode_t st_mode; ino_t st_ino; dev_t st_dev; dev_t st_rdev; nlink_t st_nlink; uid_t st_uid; gid_t st_gid; off_t st_size; struct timespec st_atim; struct timespec st_mtim; struct timespec st_ctim; blksize_t st_blksize; blkcnt_t st_blocks; }; POSIX.1 does not require st_rdev , st_blocks and st_blksize members; these fields are defined as part of XSI option in the Single Unix Specification.[src] In older versions of POSIX.1 standard, the time-related fields were defined as st_atime , st_mtime and st_ctime , and were of type time_t .[src] Since the 2008 version of the standard, these fields were renamed to st_atim , st_mtim and st_ctim , respectively, of type struct timespec , since this structure provides a higher resolution time unit.[src] For the sake of compatibility, implementations can define the old names in terms of the tv_sec member of struct timespec .[src] For example, st_atime can be defined as st_atim.tv_sec .[src] Fields include: st_dev identifier of device containing file st_ino inode number st_mode a bit field containing file access modes and special file type; see Unix permissions st_nlink reference count of hard links st_uid user identifier of owner st_gid group identifier of owner st_rdev device identifier (if special file) st_size total file size, in bytes st_atime time of last access st_mtime time of last modification st_ctime time of last status change st_blksize preferred block size for file system I/O, which can depend upon both the system and the type of file system st_blocks number of blocks allocated in multiples of DEV_BSIZE (usually 512 bytes).[src] include include include include include int main(int argc, char* argv[]) { struct stat sb; for (int i = 1; i ==References==[src]
27 sentences · 27 cited inline · 0 references stored
References
No reference rows published for this article.
Cite this article
MLA
"Stat (system call)." encyclopegia.org, 2026, https://encyclopegia.org/wiki/stat-system-call. Accessed 29 November 2026.
Chicago
"Stat (system call)." encyclopegia.org. Accessed November 29, 2026. https://encyclopegia.org/wiki/stat-system-call.
APA
encyclopegia.org. (2026). Stat (system call). Retrieved November 29, 2026, from https://encyclopegia.org/wiki/stat-system-call
Accessed November 29, 2026 · CC BY-SA 4.0 · citation page · JSON