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