statx(2)
โจ NAME โจ
okay so bestie, this is statx(2) from the System Calls Manual โ it's the extended file status girlie. She's giving you the whole vibe of a file: who owns it, how big it is, timestamps, device IDs, all of it. Let's go. โจ
statx โ get file status (extended)
๐ LIBRARY ๐
Standard C library (libc, -lc) โ yes, she's a libc girlie.
๐ช SYNOPSIS ๐ช
#define _GNU_SOURCE /* See feature_test_macros(7) */
#include <fcntl.h> /* Definition of AT_* constants */
#include <sys/stat.h>
int statx(int dirfd, const char *_Nullable restrict path,
int flags, unsigned int mask,
struct statx *restrict statxbuf);
๐ธ DESCRIPTION ๐ธ
This function returns info about a file, storing it in the buffer pointed to by statxbuf. The returned buffer is a structure of the following type:
struct statx {
__u32 stx_mask; /* Mask of bits indicating
filled fields */
__u32 stx_blksize; /* Block size for filesystem I/O */
__u64 stx_attributes; /* Extra file attribute indicators */
__u32 stx_nlink; /* Number of hard links */
__u32 stx_uid; /* User ID of owner */
__u32 stx_gid; /* Group ID of owner */
__u16 stx_mode; /* File type and mode */
__u64 stx_ino; /* Inode number */
__u64 stx_size; /* Total size in bytes */
__u64 stx_blocks; /* Number of 512B blocks allocated */
__u64 stx_attributes_mask;
/* Mask to show what's supported
in stx_attributes */
/* The following fields are file timestamps */
struct statx_timestamp stx_atime; /* Last access */
struct statx_timestamp stx_btime; /* Creation */
struct statx_timestamp stx_ctime; /* Last status change */
struct statx_timestamp stx_mtime; /* Last modification */
/* If this file represents a device, then the next two
fields contain the ID of the device */
__u32 stx_rdev_major; /* Major ID */
__u32 stx_rdev_minor; /* Minor ID */
/* The next two fields contain the ID of the device
containing the filesystem where the file resides */
__u32 stx_dev_major; /* Major ID */
__u32 stx_dev_minor; /* Minor ID */
__u64 stx_mnt_id; /* Mount ID */
/* Direct I/O alignment restrictions */
__u32 stx_dio_mem_align;
__u32 stx_dio_offset_align;
__u64 stx_subvol; /* Subvolume identifier */
/* Direct I/O atomic write limits */
__u32 stx_atomic_write_unit_min;
__u32 stx_atomic_write_unit_max;
__u32 stx_atomic_write_segments_max;
/* File offset alignment for direct I/O reads */
__u32 stx_dio_read_offset_align;
/* Direct I/O atomic write max opt limit */
__u32 stx_atomic_write_unit_max_opt;
};
The file timestamps are structures of the following type:
struct statx_timestamp {
__s64 tv_sec; /* Seconds since the Epoch (UNIX time) */
__u32 tv_nsec; /* Nanoseconds since tv_sec */
};
๐ซง tiny note bestie: reserved space and padding is omitted from these structs.
๐ซถ Invoking statx(): ๐ซถ
To access a file's status, no permissions are required on the file itself, but in the case of statx() with a pathname, execute (search) permission is required on all of the directories in path that lead to the file. The directory girlies matter, fr fr.
statx() uses path, dirfd, and flags to identify the target file in one of the following ways:
๐ An absolute pathname
If path begins with a slash, then it is an absolute pathname that identifies the target file. In this case, dirfd is ignored. Bye dirfd, you're not needed here.
๐ A relative pathname
If path is a string that begins with a character other than a slash and dirfd is AT_FDCWD, then path is a relative pathname that is interpreted relative to the process's current working directory.
๐ A directory-relative pathname
If path is a string that begins with a character other than a slash and dirfd is a file descriptor that refers to a directory, then path is a relative pathname that is interpreted relative to the directory referred to by dirfd. (See openat(2) for an explanation of why this is useful.)
๐ By file descriptor
If path is an empty string (or NULL since Linux 6.11) and the AT_EMPTY_PATH flag is specified in flags (see below), then the target file is the one referred to by the file descriptor dirfd.
flags can be used to influence a pathname-based lookup. A value for flags is constructed by ORing together zero or more of the following constants:
AT_EMPTY_PATHโ Ifpathis an empty string (orNULLsince Linux 6.11), operate on the file referred to bydirfd(which may have been obtained using theopen(2)O_PATHflag). In this case,dirfdcan refer to any type of file, not just a directory.
If dirfd is AT_FDCWD, the call operates on the current working directory.
AT_NO_AUTOMOUNTโ Don't automount the terminal ("basename") component ofpathif it is a directory that is an automount point. This allows the caller to gather attributes of an automount point (rather than the location it would mount). This flag has no effect if the mount point has already been mounted over.
The AT_NO_AUTOMOUNT flag can be used in tools that scan directories to prevent mass-automounting of a directory of automount points.
All of stat(2), lstat(2), and fstatat(2) act as though AT_NO_AUTOMOUNT was set.
AT_SYMLINK_NOFOLLOWโ Ifpathis a symbolic link, do not dereference it: instead return information about the link itself, likelstat(2).
flags can also be used to control what sort of synchronization the kernel will do when querying a file on a remote filesystem. This is done by ORing in one of the following values:
AT_STATX_SYNC_AS_STATโ Do whateverstat(2)does. This is the default and is very much filesystem-specific.AT_STATX_FORCE_SYNCโ Force the attributes to be synchronized with the server. This may require that a network filesystem perform a data writeback to get the timestamps correct.AT_STATX_DONT_SYNCโ Don't synchronize anything, but rather just take whatever the system has cached if possible. This may mean that the information returned is approximate, but, on a network filesystem, it may not involve a round trip to the server - even if no lease is held.
The mask argument to statx() is used to tell the kernel which fields the caller is interested in. mask is an ORed combination of the following constants:
STATX_TYPEโ Wantstx_mode & S_IFMTSTATX_MODEโ Wantstx_mode & ~S_IFMTSTATX_NLINKโ Wantstx_nlinkSTATX_UIDโ Wantstx_uidSTATX_GIDโ Wantstx_gidSTATX_ATIMEโ Wantstx_atimeSTATX_MTIMEโ Wantstx_mtimeSTATX_CTIMEโ Wantstx_ctimeSTATX_INOโ Wantstx_inoSTATX_SIZEโ Wantstx_sizeSTATX_BLOCKSโ Wantstx_blocksSTATX_BASIC_STATSโ [All of the above]STATX_BTIMEโ Wantstx_btimeSTATX_ALLโ The same asSTATX_BASIC_STATS | STATX_BTIME. It is deprecated and should not be used.STATX_MNT_IDโ Wantstx_mnt_id(since Linux 5.8)STATX_DIOALIGNโ Wantstx_dio_mem_alignandstx_dio_offset_align. (since Linux 6.1; support varies by filesystem)STATX_MNT_ID_UNIQUEโ Want uniquestx_mnt_id(since Linux 6.8)STATX_SUBVOLโ Wantstx_subvol(since Linux 6.10; support varies by filesystem)STATX_WRITE_ATOMICโ Wantstx_atomic_write_unit_min,stx_atomic_write_unit_max,stx_atomic_write_segments_max, andstx_atomic_write_unit_max_opt. (since Linux 6.11; support varies by filesystem)STATX_DIO_READ_ALIGNโ Wantstx_dio_read_offset_align. (since Linux 6.14; support varies by filesystem)
Note that, in general, the kernel does not reject values in mask other than the above. (For an exception, see EINVAL in errors.) Instead, it simply informs the caller which values are supported by this kernel and filesystem via the statx.stx_mask field. Therefore, do not simply set mask to UINT_MAX (all bits set), as one or more bits may, in the future, be used to specify an extension to the buffer.
๐ซ The returned information ๐ซ
The status information for the target file is returned in the statx structure pointed to by statxbuf. Included in this is stx_mask which indicates what other information has been returned. stx_mask has the same format as the mask argument and bits are set in it to indicate which fields have been filled in.
It should be noted that the kernel may return fields that weren't requested and may fail to return fields that were requested, depending on what the backing filesystem supports. (Fields that are given values despite being unrequested can just be ignored.) In either case, stx_mask will not be equal mask.
If a filesystem does not support a field or if it has an unrepresentable value (for instance, a file with an exotic type), then the mask bit corresponding to that field will be cleared in stx_mask even if the user asked for it and a dummy value will be filled in for compatibility purposes if one is available (e.g., a dummy UID and GID may be specified to mount under some circumstances).
A filesystem may also fill in fields that the caller didn't ask for if it has values for them available and the information is available at no extra cost. If this happens, the corresponding bits will be set in stx_mask.
Note: for performance and simplicity reasons, different fields in thestatxstructure may contain state information from different moments during the execution of the system call. For example, ifstx_modeorstx_uidis changed by another process by callingchmod(2)orchown(2),stat()might return the oldstx_modetogether with the newstx_uid, or the oldstx_uidtogether with the newstx_mode.
Apart from stx_mask (which is described above), the fields in the statx structure are:
๐ง stx_blksize
The "preferred" block size for efficient filesystem I/O. (Writing to a file in smaller chunks may cause an inefficient read-modify-rewrite.)
๐ง stx_attributes
Further status information about the file (see below for more information).
๐ง stx_nlink
The number of hard links on a file.
stx_uidโ bestie, this is just the user ID of whoever owns the file ๐stx_gidโ and this one's the ID of the group that owns it ๐ซถstx_modeโ the file type and the mode. Full deets live ininode(7), go look ๐stx_inoโ the inode number of the file, iconic as always โจstx_sizeโ the size of the file in bytes, but only if it's a regular file or a symbolic link. And for a symlink? The size is literally the length of the pathname it contains, without a terminating null byte. no cap ๐ฆstx_blocksโ how many blocks got allocated to the file on the medium, counted in 512-byte units. Heads up though: this can be smaller thanstx_size/512when the file has holes ๐stx_attributes_maskโ a mask telling you which bits instx_attributesthe VFS and the filesystem actually support. If a bit isn't in the mask, don't trust it ๐stx_atimeโ the file's last access timestamp โฐstx_btimeโ the file's creation timestamp, the baby photo of timestamps ๐ผstx_ctimeโ the file's last status change timestamp ๐ธstx_mtimeโ the file's last modification timestamp โจstx_dev_major,stx_dev_minorโ the device where this file (inode) lives ๐stx_rdev_major,stx_rdev_minorโ the device this file (inode) represents, but only if the file is a block or character device type ๐๏ธstx_mnt_idโ here's the tea โ if you're usingSTATX_MNT_ID, this is the mount ID of the mount containing the file. Same number thatname_to_handle_at(2)reports, and it corresponds to the number in the first field in one of the records in/proc/self/mountinfo.
If you're using STATX_MNT_ID_UNIQUE instead, this is the unique mount ID of the mount containing the file. That's the number reported by listmount(2), and it's the ID you use to query the mount with statmount(2). It is guaranteed to not get reused while the system is running. periodt ๐
stx_dio_mem_alignโ the alignment (in bytes) required for user memory buffers for direct I/O (O_DIRECT) on this file, or0if direct I/O isn't supported on this file.
STATX_DIOALIGN (that's stx_dio_mem_align and stx_dio_offset_align) has been supported on block devices since Linux 6.1. On regular files it varies by filesystem โ it's supported by ext4, f2fs, and xfs since Linux 6.1 ๐
stx_dio_offset_alignโ the alignment (in bytes) required for file offsets and I/O segment lengths for direct I/O (O_DIRECT) on this file, or0if direct I/O isn't supported on this file. It'll only be nonzero ifstx_dio_mem_alignis nonzero, and vice versa โ they're a matched set, fr fr ๐ซถstx_dio_read_offset_alignโ the alignment (in bytes) required for file offsets and I/O segment lengths for direct I/O reads (O_DIRECT) on this file. If it's zero, then the limit instx_dio_offset_alignapplies to reads too. If it's non-zero, this value must be smaller than or equal tostx_dio_offset_align, which must be provided by the file system if the application requests it. And no โ the memory alignment instx_dio_mem_alignis not affected by this value ๐
STATX_DIO_READ_ALIGN (that's stx_dio_offset_align) is supported by xfs on regular files since Linux 6.14 ๐ฅ
stx_subvolโ the subvolume number of the current file.
Okay so subvolumes are fancy directories โ they form a tree structure that you can walk recursively ๐ณ Support varies by filesystem; it's supported by bcachefs and btrfs since Linux 6.10 โจ
stx_atomic_write_unit_min,stx_atomic_write_unit_maxโ the minimum and maximum sizes (in bytes) supported for direct I/O (O_DIRECT) on the file to be written with torn-write protection. Each of these values is guaranteed to be a power-of-2 ๐
STATX_WRITE_ATOMIC (that's stx_atomic_write_unit_min, stx_atomic_write_unit_max, and stx_atomic_write_segments_max) has been supported on block devices since Linux 6.11. On regular files it varies by filesystem โ supported by xfs and ext4 since Linux 6.13 ๐
stx_atomic_write_unit_max_optโ the maximum size (in bytes) that's optimised for writes issued with torn-write protection. If it's non-zero, this value will not exceed the value instx_atomic_write_unit_maxand will not be less than the value instx_atomic_write_unit_min. A value of zero meansstx_atomic_write_unit_maxis the optimised limit. And btw โ slower writes may be experienced when the size of the write exceedsstx_atomic_write_unit_max_opt(when it's non-zero) ๐stx_atomic_write_segments_maxโ the maximum number of elements in an array of vectors for a write with torn-write protection enabled. See theRWF_ATOMICflag forpwritev2(2)๐- For even more info on all the fields above, go see
inode(7)๐
๐ File attributes ๐
The stx_attributes field contains a set of ORed flags that indicate extra attributes of the file โจ Big note though: any attribute that is not indicated as supported by stx_attributes_mask has no usable value here. The bits in stx_attributes_mask correspond bit-by-bit to stx_attributes โ they're in sync, bestie ๐
The flags are as follows:
STATX_ATTR_COMPRESSEDโ the file is compressed by the filesystem, so it may take extra resources to access ๐๏ธSTATX_ATTR_IMMUTABLEโ the file cannot be modified. Like, at all: it cannot be deleted or renamed, no hard links can be created to this file, and no data can be written to it. Seechattr(1)๐STATX_ATTR_APPENDโ the file can only be opened in append mode for writing. Random access writing is not permitted. Seechattr(1)๐STATX_ATTR_NODUMPโ the file is not a candidate for backup when a backup program such asdump(8)is run. Seechattr(1)๐STATX_ATTR_ENCRYPTEDโ a key is required for the file to be encrypted by the filesystem ๐STATX_ATTR_VERITY(since Linux 5.5) โ the file has fs-verity enabled. It cannot be written to, and all reads from it will be verified against a cryptographic hash that covers the entire file (e.g., via a Merkle tree) ๐งSTATX_ATTR_WRITE_ATOMIC(since Linux 6.11) โ the file supports torn-write protection ๐ฅSTATX_ATTR_DAX(since Linux 5.8) โ the file is in the DAX (cpu direct access) state. DAX state attempts to minimize software cache effects for both I/O and memory mappings of this file. It requires a file system which has been configured to support DAX โก
DAX generally assumes all accesses are via CPU load / store instructions, which can minimize overhead for small accesses, but may adversely affect CPU utilization for large transfers ๐
File I/O is done directly to/from user-space buffers, and memory mapped I/O may be performed with direct memory mappings that bypass the kernel page cache ๐
While the DAX property tends to result in data being transferred synchronously, it does not give the same guarantees as the O_SYNC flag (see open(2)), where data and the necessary metadata are transferred together. Important distinction, don't mix them up ๐
A DAX file may support being mapped with the MAP_SYNC flag, which enables a program to use CPU cache flush instructions to persist CPU store operations without an explicit fsync(2). See mmap(2) for more ๐
STATX_ATTR_MOUNT_ROOT(since Linux 5.8) โ the file is the root of a mount ๐ฑ
๐ RETURN VALUE ๐
On success, zero is returned ๐ On error, -1 is returned, and errno is set to indicate the error ๐ญ
๐ฅ ERRORS ๐ฅ
EACCESโ search permission is denied for one of the directories in the path prefix of path. (See alsopath_resolution(7).)EBADFโ path is relative but dirfd is neitherAT_FDCWDnor a valid file descriptor.EFAULTโ path or statxbuf points to a location outside the process's accessible address space, or isNULL. (Except since Linux 6.11: ifAT_EMPTY_PATHis specified in flags, path is allowed to beNULL.)EINVALโ invalid flag specified in flags.EINVALโ reserved flag specified in mask. (Currently, there is one such flag, designated by the constantSTATX__RESERVED, with the value0x80000000U.)ELOOPโ too many symbolic links encountered while traversing the pathname.ENAMETOOLONGโ path is too long.ENOENTโ a component of path does not exist, or path is an empty string andAT_EMPTY_PATHwas not specified in flags.ENOMEMโ out of memory (i.e., kernel memory).ENOTDIRโ a component of the path prefix of path is not a directory, or path is relative and dirfd is a file descriptor referring to a file other than a directory.
โญ STANDARDS โญ
Linux. ๐ง
๐ฆ HISTORY ๐ฆ
Linux 4.11, glibc 2.28. the way this is giving vintage but still serving ๐
๐ธ SEE ALSO ๐ธ
ls(1), stat(1), access(2), chmod(2), chown(2), name_to_handle_at(2), readlink(2), stat(2), utime(2), proc(5), capabilities(7), inode(7), symlink(7)
and that's a wrap on statx(2), bestie ๐ซถ this whole page is from the Linux man-pages 6.20 era, dated 2026-02-08 โ go forth and stat your little heart out, ilysm ๐โจ๐
๐ฆ where this page comes from
- arch rolling: man-pages 6.20-1 ยท BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
- nixpkgs unstable: man-pages 6.20
- ๐ the page's license: Linux-man-pages-copyleft
- Copyright 2017, David Howells <dhowells@redhat.com>
- Copyright 1992, Drew Eckhardt <drew@cs.colorado.edu>
- Copyright 1995, Nicolai Langfeldt <janl@ifi.uio.no>
- Copyright 2006-2014, Michael Kerrisk <mtk.manpages@gmail.com>
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms