]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man2/statx.2
subpage_prot.2: Add LIBRARY section
[thirdparty/man-pages.git] / man2 / statx.2
CommitLineData
9905e59b
DH
1.\" Copyright (c) 2017 David Howells <dhowells@redhat.com>
2.\"
3.\" Derived from the stat.2 manual page:
4.\" Copyright (c) 1992 Drew Eckhardt (drew@cs.colorado.edu), March 28, 1992
5.\" Parts Copyright (c) 1995 Nicolai Langfeldt (janl@ifi.uio.no), 1/1/95
6.\" and Copyright (c) 2006, 2007, 2014 Michael Kerrisk <mtk.manpages@gmail.com>
7.\"
5fbde956 8.\" SPDX-License-Identifier: Linux-man-pages-copyleft
9905e59b 9.\"
6e00b7a8 10.TH STATX 2 2021-08-27 "Linux" "Linux Programmer's Manual"
9905e59b 11.SH NAME
835f4293 12statx \- get file status (extended)
9905e59b
DH
13.SH SYNOPSIS
14.nf
c9f3f849 15.BR "#include <fcntl.h> " "/* Definition of " AT_* " constants */"
9905e59b 16.B #include <sys/stat.h>
dbfe9c70 17.PP
049d7f92
AC
18.BI "int statx(int " dirfd ", const char *restrict " pathname ", int " flags ,
19.BI " unsigned int " mask ", struct statx *restrict " statxbuf );
9905e59b 20.fi
9905e59b 21.SH DESCRIPTION
9905e59b
DH
22This function returns information about a file, storing it in the buffer
23pointed to by
15d1f5ac 24.IR statxbuf .
c8701baf 25The returned buffer is a structure of the following type:
9905e59b
DH
26.PP
27.in +4n
b8302363 28.EX
9905e59b 29struct statx {
77a09ad7
MK
30 __u32 stx_mask; /* Mask of bits indicating
31 filled fields */
32 __u32 stx_blksize; /* Block size for filesystem I/O */
33 __u64 stx_attributes; /* Extra file attribute indicators */
34 __u32 stx_nlink; /* Number of hard links */
35 __u32 stx_uid; /* User ID of owner */
36 __u32 stx_gid; /* Group ID of owner */
37 __u16 stx_mode; /* File type and mode */
38 __u64 stx_ino; /* Inode number */
39 __u64 stx_size; /* Total size in bytes */
40 __u64 stx_blocks; /* Number of 512B blocks allocated */
aabbefb4 41 __u64 stx_attributes_mask;
861d36ba 42 /* Mask to show what\(aqs supported
aabbefb4 43 in stx_attributes */
6a4667aa
MK
44
45 /* The following fields are file timestamps */
46 struct statx_timestamp stx_atime; /* Last access */
47 struct statx_timestamp stx_btime; /* Creation */
48 struct statx_timestamp stx_ctime; /* Last status change */
49 struct statx_timestamp stx_mtime; /* Last modification */
50
20c8cd9a
MK
51 /* If this file represents a device, then the next two
52 fields contain the ID of the device */
77a09ad7
MK
53 __u32 stx_rdev_major; /* Major ID */
54 __u32 stx_rdev_minor; /* Minor ID */
6a4667aa
MK
55
56 /* The next two fields contain the ID of the device
790314d7 57 containing the filesystem where the file resides */
77a09ad7
MK
58 __u32 stx_dev_major; /* Major ID */
59 __u32 stx_dev_minor; /* Minor ID */
728009a4 60 __u64 stx_mnt_id; /* Mount ID */
9905e59b 61};
b8302363 62.EE
9905e59b
DH
63.in
64.PP
6a4667aa 65The file timestamps are structures of the following type:
9905e59b
DH
66.PP
67.in +4n
b8302363 68.EX
9905e59b 69struct statx_timestamp {
6a4667aa 70 __s64 tv_sec; /* Seconds since the Epoch (UNIX time) */
aabbefb4 71 __u32 tv_nsec; /* Nanoseconds since tv_sec */
9905e59b 72};
b8302363 73.EE
9905e59b
DH
74.in
75.PP
790314d7 76(Note that reserved space and padding is omitted.)
9905e59b
DH
77.SS
78Invoking \fBstatx\fR():
14b5d02a
MK
79To access a file's status, no permissions are required on the file itself,
80but in the case of
9905e59b 81.BR statx ()
835f4293 82with a pathname,
14b5d02a 83execute (search) permission is required on all of the directories in
9905e59b
DH
84.I pathname
85that lead to the file.
86.PP
87.BR statx ()
88uses
6a4667aa
MK
89.IR pathname ,
90.IR dirfd ,
91and
92.IR flags
56a05af6 93to identify the target file in one of the following ways:
9905e59b 94.TP
7e43caf4
MK
95An absolute pathname
96If
9905e59b 97.I pathname
7e43caf4
MK
98begins with a slash,
99then it is an absolute pathname that identifies the target file.
100In this case,
9905e59b 101.I dirfd
14b5d02a 102is ignored.
9905e59b 103.TP
7e43caf4
MK
104A relative pathname
105If
9905e59b 106.I pathname
7e43caf4 107is a string that begins with a character other than a slash and
6a4667aa
MK
108.IR dirfd
109is
7e43caf4
MK
110.BR AT_FDCWD ,
111then
112.I pathname
113is a relative pathname that is interpreted relative to the process's
114current working directory.
9905e59b 115.TP
aabbefb4 116A directory-relative pathname
7e43caf4 117If
9905e59b 118.I pathname
7e43caf4 119is a string that begins with a character other than a slash and
9905e59b 120.I dirfd
7e43caf4
MK
121is a file descriptor that refers to a directory, then
122.I pathname
123is a relative pathname that is interpreted relative to the directory
124referred to by
9905e59b 125.IR dirfd .
717c3a7d
MK
126(See
127.BR openat (2)
128for an explanation of why this is useful.)
9905e59b 129.TP
7e43caf4
MK
130By file descriptor
131If
77a09ad7 132.IR pathname
85dbf7cd 133is an empty string and the
7e43caf4 134.B AT_EMPTY_PATH
85dbf7cd
MK
135flag is specified in
136.IR flags
137(see below),
138then the target file is the one referred to by the file descriptor
139.IR dirfd .
9905e59b
DH
140.PP
141.I flags
835f4293 142can be used to influence a pathname-based lookup.
14b5d02a 143A value for
9905e59b 144.I flags
c8701baf 145is constructed by ORing together zero or more of the following constants:
9905e59b
DH
146.TP
147.BR AT_EMPTY_PATH
148.\" commit 65cfc6722361570bfe255698d9cd4dccaf47570d
149If
150.I pathname
151is an empty string, operate on the file referred to by
152.IR dirfd
153(which may have been obtained using the
154.BR open (2)
155.B O_PATH
156flag).
85dbf7cd
MK
157In this case,
158.I dirfd
159can refer to any type of file, not just a directory.
efeece04 160.IP
9905e59b
DH
161If
162.I dirfd
163is
164.BR AT_FDCWD ,
165the call operates on the current working directory.
efeece04 166.IP
9905e59b
DH
167This flag is Linux-specific; define
168.B _GNU_SOURCE
169.\" Before glibc 2.16, defining _ATFILE_SOURCE sufficed
170to obtain its definition.
171.TP
172.BR AT_NO_AUTOMOUNT
173Don't automount the terminal ("basename") component of
174.I pathname
175if it is a directory that is an automount point.
176This allows the caller to gather attributes of an automount point
177(rather than the location it would mount).
178This flag can be used in tools that scan directories
179to prevent mass-automounting of a directory of automount points.
180The
181.B AT_NO_AUTOMOUNT
182flag has no effect if the mount point has already been mounted over.
183This flag is Linux-specific; define
184.B _GNU_SOURCE
185.\" Before glibc 2.16, defining _ATFILE_SOURCE sufficed
186to obtain its definition.
187.TP
188.B AT_SYMLINK_NOFOLLOW
189If
190.I pathname
191is a symbolic link, do not dereference it:
192instead return information about the link itself, like
6a4667aa 193.BR lstat (2).
9905e59b
DH
194.PP
195.I flags
14b5d02a
MK
196can also be used to control what sort of synchronization the kernel will do
197when querying a file on a remote filesystem.
c8701baf 198This is done by ORing in one of the following values:
9905e59b 199.TP
709f7bb6 200.B AT_STATX_SYNC_AS_STAT
9905e59b 201Do whatever
6a4667aa 202.BR stat (2)
14b5d02a 203does.
56a05af6 204This is the default and is very much filesystem-specific.
9905e59b 205.TP
709f7bb6 206.B AT_STATX_FORCE_SYNC
46711e96 207Force the attributes to be synchronized with the server.
14b5d02a 208This may require that
9905e59b
DH
209a network filesystem perform a data writeback to get the timestamps correct.
210.TP
709f7bb6 211.B AT_STATX_DONT_SYNC
46711e96 212Don't synchronize anything, but rather just take whatever
ffe297ee 213the system has cached if possible.
14b5d02a 214This may mean that the information returned is approximate, but,
9905e59b
DH
215on a network filesystem, it may not involve a round trip to the server - even
216if no lease is held.
217.PP
218The
219.I mask
220argument to
221.BR statx ()
222is used to tell the kernel which fields the caller is interested in.
223.I mask
c8701baf 224is an ORed combination of the following constants:
9905e59b
DH
225.PP
226.in +4n
227.TS
228lB l.
229STATX_TYPE Want stx_mode & S_IFMT
af2d18b2 230STATX_MODE Want stx_mode & \(tiS_IFMT
9905e59b
DH
231STATX_NLINK Want stx_nlink
232STATX_UID Want stx_uid
233STATX_GID Want stx_gid
f4572b65
MK
234STATX_ATIME Want stx_atime
235STATX_MTIME Want stx_mtime
236STATX_CTIME Want stx_ctime
9905e59b
DH
237STATX_INO Want stx_ino
238STATX_SIZE Want stx_size
239STATX_BLOCKS Want stx_blocks
240STATX_BASIC_STATS [All of the above]
f4572b65 241STATX_BTIME Want stx_btime
728009a4 242STATX_MNT_ID Want stx_mnt_id (since Linux 5.8)
9905e59b
DH
243STATX_ALL [All currently available fields]
244.TE
245.in
246.PP
c031ffcc 247Note that, in general, the kernel does
393c5b58
MK
248.I not
249reject values in
250.I mask
251other than the above.
c031ffcc
MK
252(For an exception, see
253.B EINVAL
254in errors.)
393c5b58
MK
255Instead, it simply informs the caller which values are supported
256by this kernel and filesystem via the
257.I statx.stx_mask
258field.
259Therefore,
260.I "do not"
9905e59b
DH
261simply set
262.I mask
709f7bb6
MK
263to
264.B UINT_MAX
393c5b58 265(all bits set),
709f7bb6 266as one or more bits may, in the future, be used to specify an
9905e59b
DH
267extension to the buffer.
268.SS
269The returned information
9905e59b
DH
270The status information for the target file is returned in the
271.I statx
272structure pointed to by
15d1f5ac 273.IR statxbuf .
9905e59b
DH
274Included in this is
275.I stx_mask
276which indicates what other information has been returned.
277.I stx_mask
790314d7
MK
278has the same format as the
279.I mask
280argument and bits are set in it to indicate
9905e59b
DH
281which fields have been filled in.
282.PP
ffe297ee
MK
283It should be noted that the kernel may return fields that weren't
284requested and may fail to return fields that were requested,
285depending on what the backing filesystem supports.
c859dfb5 286(Fields that are given values despite being unrequested can just be ignored.)
14b5d02a 287In either case,
9905e59b
DH
288.I stx_mask
289will not be equal
290.IR mask .
291.PP
ffe297ee
MK
292If a filesystem does not support a field or if it has
293an unrepresentable value (for instance, a file with an exotic type),
294then the mask bit corresponding to that field will be cleared in
9905e59b
DH
295.I stx_mask
296even if the user asked for it and a dummy value will be filled in for
835f4293 297compatibility purposes if one is available (e.g., a dummy UID and GID may be
9905e59b
DH
298specified to mount under some circumstances).
299.PP
300A filesystem may also fill in fields that the caller didn't ask for if it has
835f4293 301values for them available and the information is available at no extra cost.
14b5d02a 302If this happens, the corresponding bits will be set in
9905e59b
DH
303.IR stx_mask .
304.PP
9905e59b
DH
305.\" Background: inode attributes are modified with i_mutex held, but
306.\" read by stat() without taking the mutex.
835f4293
MK
307.IR Note :
308for performance and simplicity reasons, different fields in the
9905e59b
DH
309.I statx
310structure may contain state information from different moments
311during the execution of the system call.
312For example, if
313.IR stx_mode
314or
315.IR stx_uid
316is changed by another process by calling
317.BR chmod (2)
318or
319.BR chown (2),
320.BR stat ()
321might return the old
322.I stx_mode
323together with the new
324.IR stx_uid ,
325or the old
326.I stx_uid
327together with the new
328.IR stx_mode .
329.PP
77a09ad7
MK
330Apart from
331.I stx_mask
332(which is described above), the fields in the
9905e59b
DH
333.I statx
334structure are:
335.TP
13470fd3
MK
336.I stx_blksize
337The "preferred" block size for efficient filesystem I/O.
338(Writing to a file in
339smaller chunks may cause an inefficient read-modify-rewrite.)
340.TP
341.I stx_attributes
342Further status information about the file (see below for more information).
343.TP
344.I stx_nlink
345The number of hard links on a file.
346.TP
347.I stx_uid
348This field contains the user ID of the owner of the file.
349.TP
350.I stx_gid
351This field contains the ID of the group owner of the file.
aabbefb4 352.TP
9905e59b 353.I stx_mode
14b5d02a 354The file type and mode.
19cda35d
MK
355See
356.BR inode (7)
357for details.
9905e59b 358.TP
fc31d730
MK
359.I stx_ino
360The inode number of the file.
361.TP
9905e59b
DH
362.I stx_size
363The size of the file (if it is a regular file or a symbolic link) in bytes.
ffe297ee
MK
364The size of a symbolic link is the length of the pathname it contains,
365without a terminating null byte.
9905e59b
DH
366.TP
367.I stx_blocks
368The number of blocks allocated to the file on the medium, in 512-byte units.
369(This may be smaller than
370.IR stx_size /512
371when the file has holes.)
372.TP
13470fd3
MK
373.I stx_attributes_mask
374A mask indicating which bits in
375.IR stx_attributes
376are supported by the VFS and the filesystem.
9905e59b
DH
377.TP
378.I stx_atime
379The file's last access timestamp.
9905e59b
DH
380.TP
381.I stx_btime
14b5d02a 382The file's creation timestamp.
9905e59b
DH
383.TP
384.I stx_ctime
14b5d02a 385The file's last status change timestamp.
9905e59b
DH
386.TP
387.I stx_mtime
14b5d02a 388The file's last modification timestamp.
13470fd3
MK
389.TP
390.IR stx_dev_major " and " stx_dev_minor
391The device on which this file (inode) resides.
392.TP
393.IR stx_rdev_major " and " stx_rdev_minor
394The device that this file (inode) represents if the file is of block or
395character device type.
728009a4
N
396.TP
397.I stx_mnt_id
398.\" commit fa2fcf4f1df1559a0a4ee0f46915b496cc2ebf60
053132a8
MK
399The mount ID of the mount containing the file.
400This is the same number reported by
728009a4
N
401.BR name_to_handle_at (2)
402and corresponds to the number in the first field in one of the records in
403.IR /proc/self/mountinfo .
9905e59b 404.PP
19cda35d
MK
405For further information on the above fields, see
406.BR inode (7).
14b5d02a 407.\"
9905e59b 408.SS File attributes
9905e59b
DH
409The
410.I stx_attributes
c8701baf 411field contains a set of ORed flags that indicate additional attributes
aabbefb4
MK
412of the file.
413Note that any attribute that is not indicated as supported by
414.I stx_attributes_mask
415has no usable value here.
416The bits in
417.I stx_attributes_mask
418correspond bit-by-bit to
419.IR stx_attributes .
efeece04 420.PP
aabbefb4 421The flags are as follows:
9905e59b 422.TP
77a09ad7 423.B STATX_ATTR_COMPRESSED
56a05af6
MK
424The file is compressed by the filesystem and may take extra resources
425to access.
9905e59b 426.TP
77a09ad7 427.B STATX_ATTR_IMMUTABLE
ffe297ee
MK
428The file cannot be modified: it cannot be deleted or renamed,
429no hard links can be created to this file and no data can be written to it.
709f7bb6
MK
430See
431.BR chattr (1).
9905e59b 432.TP
77a09ad7 433.B STATX_ATTR_APPEND
14b5d02a
MK
434The file can only be opened in append mode for writing.
435Random access writing
436is not permitted.
709f7bb6
MK
437See
438.BR chattr (1).
9905e59b 439.TP
77a09ad7 440.B STATX_ATTR_NODUMP
709f7bb6
MK
441File is not a candidate for backup when a backup program such as
442.BR dump (8)
443is run.
444See
445.BR chattr (1).
9905e59b 446.TP
77a09ad7 447.B STATX_ATTR_ENCRYPTED
9905e59b 448A key is required for the file to be encrypted by the filesystem.
ba2a5200 449.TP
c436f71f
MK
450.BR STATX_ATTR_VERITY " (since Linux 5.5)"
451.\" commit 3ad2522c64cff1f5aebb987b00683268f0cc7c29
452The file has fs-verity enabled.
453It cannot be written to, and all reads from it will be verified
454against a cryptographic hash that covers the
455entire file (e.g., via a Merkle tree).
38ad6a88 456.TP
2e335632 457.BR STATX_ATTR_DAX " (since Linux 5.8)"
c9e6c5ab
MK
458The file is in the DAX (cpu direct access) state.
459DAX state attempts to
38ad6a88
IW
460minimize software cache effects for both I/O and memory mappings of this file.
461It requires a file system which has been configured to support DAX.
2e335632 462.IP
c9e6c5ab
MK
463DAX generally assumes all accesses are via CPU load / store instructions
464which can minimize overhead for small accesses,
465but may adversely affect CPU utilization for large transfers.
2e335632 466.IP
38ad6a88 467File I/O is done directly to/from user-space buffers and memory mapped I/O may
c9e6c5ab 468be performed with direct memory mappings that bypass the kernel page cache.
2e335632 469.IP
38ad6a88 470While the DAX property tends to result in data being transferred synchronously,
c9e6c5ab
MK
471it does not give the same guarantees as the
472.B O_SYNC
473flag (see
474.BR open (2)),
475where data and the necessary metadata are transferred together.
2e335632 476.IP
c9e6c5ab
MK
477A DAX file may support being mapped with the
478.B MAP_SYNC
479flag, which enables a
38ad6a88
IW
480program to use CPU cache flush instructions to persist CPU store operations
481without an explicit
c9e6c5ab 482.BR fsync (2).
38ad6a88 483See
c9e6c5ab 484.BR mmap (2)
38ad6a88 485for more information.
9905e59b
DH
486.SH RETURN VALUE
487On success, zero is returned.
488On error, \-1 is returned, and
489.I errno
f6a4078b 490is set to indicate the error.
9905e59b
DH
491.SH ERRORS
492.TP
9905e59b
DH
493.B EACCES
494Search permission is denied for one of the directories
495in the path prefix of
496.IR pathname .
497(See also
498.BR path_resolution (7).)
499.TP
500.B EBADF
9f4e736a
MK
501.I pathname
502is relative but
9905e59b 503.I dirfd
9f4e736a
MK
504is neither
505.B AT_FDCWD
506nor a valid file descriptor.
9905e59b
DH
507.TP
508.B EFAULT
09ff9f4a
MK
509.I pathname
510or
15d1f5ac 511.I statxbuf
09ff9f4a
MK
512is NULL or points to a location outside the process's
513accessible address space.
9905e59b 514.TP
1b206bd8
MK
515.B EINVAL
516Invalid flag specified in
517.IR flags .
518.TP
aabbefb4
MK
519.B EINVAL
520Reserved flag specified in
521.IR mask .
c031ffcc
MK
522(Currently, there is one such flag, designated by the constant
523.BR STATX__RESERVED ,
524with the value 0x80000000U.)
aabbefb4 525.TP
9905e59b 526.B ELOOP
835f4293 527Too many symbolic links encountered while traversing the pathname.
9905e59b
DH
528.TP
529.B ENAMETOOLONG
530.I pathname
531is too long.
532.TP
533.B ENOENT
534A component of
535.I pathname
536does not exist, or
537.I pathname
c8701baf
MK
538is an empty string and
539.B AT_EMPTY_PATH
540was not specified in
541.IR flags .
9905e59b
DH
542.TP
543.B ENOMEM
544Out of memory (i.e., kernel memory).
545.TP
546.B ENOTDIR
547A component of the path prefix of
548.I pathname
549is not a directory or
550.I pathname
551is relative and
552.I dirfd
553is a file descriptor referring to a file other than a directory.
554.SH VERSIONS
555.BR statx ()
e06763fe 556was added to Linux in kernel 4.11; library support was added in glibc 2.28.
7a192d0d
MK
557.SH CONFORMING TO
558.BR statx ()
56a05af6 559is Linux-specific.
9905e59b
DH
560.SH SEE ALSO
561.BR ls (1),
562.BR stat (1),
563.BR access (2),
564.BR chmod (2),
565.BR chown (2),
728009a4 566.BR name_to_handle_at (2),
9905e59b 567.BR readlink (2),
6edadda6 568.BR stat (2),
9905e59b 569.BR utime (2),
728009a4 570.BR proc (5),
9905e59b 571.BR capabilities (7),
3b363b62 572.BR inode (7),
9905e59b 573.BR symlink (7)