statx(2) System Calls Manual statx(2) statx - ( ) LIBRARY Standard C library (libc, -lc) #define _GNU_SOURCE /* feature_test_macros(7) */ #include /* AT_* */ #include int statx(int dirfd, const char *restrict pathname, int flags, unsigned int mask, struct statx *restrict statxbuf); , , statxbuf. : 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; }; : struct statx_timestamp { __s64 tv_sec; /* ( UNIX) */ __u32 tv_nsec; /* , tv_sec */ }; ( ) statx(): , statx() , () , pathname. statx() pathname, dirfd flags : pathname , . dirfd . pathname dirfd AT_FDCWD, pathname . , If pathname is a string that begins with a character other than a slash and dirfd is a file descriptor that refers to a directory, then pathname 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.) pathname flags ( ) AT_EMPTY_PATH, , dirfd. flags . : AT_EMPTY_PATH pathname , , dirfd ( open(2) O_PATH). dirfd , . dirfd AT_FDCWD, . AT_NO_AUTOMOUNT Don't automount the terminal ("basename") component of pathname if 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 pathname , , , lstat(2). flags , . : AT_STATX_SYNC_AS_STAT stat(2). . AT_STATX_FORCE_SYNC . . AT_STATX_DONT_SYNC , ( ). , , . mask statx() . mask ( OR) : STATX_TYPE stx_mode & S_IFMT STATX_MODE Want stx_mode & ~S_IFMT STATX_NLINK stx_nlink STATX_UID stx_uid STATX_GID stx_gid STATX_ATIME stx_atime STATX_MTIME stx_mtime STATX_CTIME stx_ctime STATX_INO stx_ino STATX_SIZE stx_size STATX_BLOCKS stx_blocks STATX_BASIC_STATS [ ] STATX_BTIME stx_btime STATX_ALL The same as STATX_BASIC_STATS | STATX_BTIME. It is deprecated and should not be used. STATX_MNT_ID Want stx_mnt_id (since Linux 5.8) STATX_DIOALIGN Want stx_dio_mem_align and stx_dio_offset_align (since Linux 6.1; support varies by filesystem) , mask, ( EINVAL). , statx.stx_mask. mask UINT_MAX ( ), . statx, statxbuf. stx_mask, . stx_mask , mask, . , , , (, , , ). stx_mask mask. (, ), stx_mask, , , , , (, UID GID ). , , , . , stx_mask. : statx . , stx_mode stx_uid chmod(2) chown(2), stat() stx_mode stx_uid, stx_uid stx_mode. stx_mask ( ) statx : stx_blksize <<>> / ( // ). stx_attributes ( ). stx_nlink . stx_uid . stx_gid . stx_mode . inode(7). stx_ino . stx_size ( ) . , , . stx_blocks ( 512 ), ( , stx_size/512, (holes)). stx_attributes_mask , stx_attributes VFS . stx_atime . stx_btime . stx_ctime . stx_mtime . stx_dev_major stx_dev_minor , (). stx_rdev_major stx_rdev_minor , () , . stx_mnt_id The mount ID of the mount containing the file. This is the same number reported by name_to_handle_at(2) and corresponds to the number in the first field in one of the records in /proc/self/mountinfo. stx_dio_mem_align The alignment (in bytes) required for user memory buffers for direct I/O (O_DIRECT) on this file, or 0 if direct I/O is not supported on this file. STATX_DIOALIGN (stx_dio_mem_align and stx_dio_offset_align) is supported on block devices since Linux 6.1. The support on regular files varies by filesystem; it is 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, or 0 if direct I/O is not supported on this file. This will only be nonzero if stx_dio_mem_align is nonzero, and vice versa. inode(7). stx_attributes ( ), . , , stx_attributes_mask, . stx_attributes_mask stx_attributes. : STATX_ATTR_COMPRESSED . STATX_ATTR_IMMUTABLE : , . chattr(1). STATX_ATTR_APPEND . . chattr(1). STATX_ATTR_NODUMP , dump(8). chattr(1). STATX_ATTR_ENCRYPTED . STATX_ATTR_VERITY ( 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_DAX ( 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. 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 information. STATX_ATTR_MOUNT_ROOT (since Linux 5.8) The file is the root of a mount. On success, zero is returned. On error, -1 is returned, and errno is set to indicate the error. EACCES pathname ( path_resolution(7)). EBADF pathname , dirfd AT_FDCWD . EFAULT pathname statxbuf NULL . EINVAL flags. EINVAL mask ( , STATX__RESERVED 0x80000000U). ELOOP . ENAMETOOLONG pathname. ENOENT pathname pathname flags AT_EMPTY_PATH. ENOMEM (, ). ENOTDIR pathname dirfd , , . Linux. Linux 4.11, glibc 2.28. . 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) Alexander Golubev , Azamat Hackimov , Hotellook, Nikita , Spiros Georgaras , Vladislav , Yuri Kozlov ; GNU 3 , . . , , . Linux man-pages 6.06 31 2023 . statx(2)