namespaces.7: ffix
[man-pages.git] / man2 / statx.2
blob62e86fb1b5d266c563492ca19f65e6089c4b6a9a
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 .\"
8 .\" %%%LICENSE_START(VERBATIM)
9 .\" Permission is granted to make and distribute verbatim copies of this
10 .\" manual provided the copyright notice and this permission notice are
11 .\" preserved on all copies.
12 .\"
13 .\" Permission is granted to copy and distribute modified versions of this
14 .\" manual under the conditions for verbatim copying, provided that the
15 .\" entire resulting derived work is distributed under the terms of a
16 .\" permission notice identical to this one.
17 .\"
18 .\" Since the Linux kernel and libraries are constantly changing, this
19 .\" manual page may be incorrect or out-of-date.  The author(s) assume no
20 .\" responsibility for errors or omissions, or for damages resulting from
21 .\" the use of the information contained herein.  The author(s) may not
22 .\" have taken the same level of care in the production of this manual,
23 .\" which is licensed free of charge, as they might when working
24 .\" professionally.
25 .\"
26 .\" Formatted or processed versions of this manual, if unaccompanied by
27 .\" the source, must acknowledge the copyright and authors of this work.
28 .\" %%%LICENSE_END
29 .\"
30 .TH STATX 2 2021-03-22 "Linux" "Linux Programmer's Manual"
31 .SH NAME
32 statx \- get file status (extended)
33 .SH SYNOPSIS
34 .nf
35 .BR "#include <fcntl.h>           " "/* Definition of " AT_* " constants */"
36 .B #include <sys/stat.h>
37 .PP
38 .BI "int statx(int " dirfd ", const char *restrict " pathname ", int " flags ,
39 .BI "          unsigned int " mask ", struct statx *restrict " statxbuf );
40 .fi
41 .SH DESCRIPTION
42 This function returns information about a file, storing it in the buffer
43 pointed to by
44 .IR statxbuf .
45 The returned buffer is a structure of the following type:
46 .PP
47 .in +4n
48 .EX
49 struct statx {
50     __u32 stx_mask;        /* Mask of bits indicating
51                               filled fields */
52     __u32 stx_blksize;     /* Block size for filesystem I/O */
53     __u64 stx_attributes;  /* Extra file attribute indicators */
54     __u32 stx_nlink;       /* Number of hard links */
55     __u32 stx_uid;         /* User ID of owner */
56     __u32 stx_gid;         /* Group ID of owner */
57     __u16 stx_mode;        /* File type and mode */
58     __u64 stx_ino;         /* Inode number */
59     __u64 stx_size;        /* Total size in bytes */
60     __u64 stx_blocks;      /* Number of 512B blocks allocated */
61     __u64 stx_attributes_mask;
62                            /* Mask to show what\(aqs supported
63                               in stx_attributes */
65     /* The following fields are file timestamps */
66     struct statx_timestamp stx_atime;  /* Last access */
67     struct statx_timestamp stx_btime;  /* Creation */
68     struct statx_timestamp stx_ctime;  /* Last status change */
69     struct statx_timestamp stx_mtime;  /* Last modification */
71     /* If this file represents a device, then the next two
72        fields contain the ID of the device */
73     __u32 stx_rdev_major;  /* Major ID */
74     __u32 stx_rdev_minor;  /* Minor ID */
76     /* The next two fields contain the ID of the device
77        containing the filesystem where the file resides */
78     __u32 stx_dev_major;   /* Major ID */
79     __u32 stx_dev_minor;   /* Minor ID */
81 .EE
82 .in
83 .PP
84 The file timestamps are structures of the following type:
85 .PP
86 .in +4n
87 .EX
88 struct statx_timestamp {
89     __s64 tv_sec;    /* Seconds since the Epoch (UNIX time) */
90     __u32 tv_nsec;   /* Nanoseconds since tv_sec */
92 .EE
93 .in
94 .PP
95 (Note that reserved space and padding is omitted.)
96 .SS
97 Invoking \fBstatx\fR():
98 To access a file's status, no permissions are required on the file itself,
99 but in the case of
100 .BR statx ()
101 with a pathname,
102 execute (search) permission is required on all of the directories in
103 .I pathname
104 that lead to the file.
106 .BR statx ()
107 uses
108 .IR pathname ,
109 .IR dirfd ,
111 .IR flags
112 to identify the target file in one of the following ways:
114 An absolute pathname
116 .I pathname
117 begins with a slash,
118 then it is an absolute pathname that identifies the target file.
119 In this case,
120 .I dirfd
121 is ignored.
123 A relative pathname
125 .I pathname
126 is a string that begins with a character other than a slash and
127 .IR dirfd
129 .BR AT_FDCWD ,
130 then
131 .I pathname
132 is a relative pathname that is interpreted relative to the process's
133 current working directory.
135 A directory-relative pathname
137 .I pathname
138 is a string that begins with a character other than a slash and
139 .I dirfd
140 is a file descriptor that refers to a directory, then
141 .I pathname
142 is a relative pathname that is interpreted relative to the directory
143 referred to by
144 .IR dirfd .
146 By file descriptor
148 .IR pathname
149 is an empty string and the
150 .B AT_EMPTY_PATH
151 flag is specified in
152 .IR flags
153 (see below),
154 then the target file is the one referred to by the file descriptor
155 .IR dirfd .
157 .I flags
158 can be used to influence a pathname-based lookup.
159 A value for
160 .I flags
161 is constructed by ORing together zero or more of the following constants:
163 .BR AT_EMPTY_PATH
164 .\" commit 65cfc6722361570bfe255698d9cd4dccaf47570d
166 .I pathname
167 is an empty string, operate on the file referred to by
168 .IR dirfd
169 (which may have been obtained using the
170 .BR open (2)
171 .B O_PATH
172 flag).
173 In this case,
174 .I dirfd
175 can refer to any type of file, not just a directory.
178 .I dirfd
180 .BR AT_FDCWD ,
181 the call operates on the current working directory.
183 This flag is Linux-specific; define
184 .B _GNU_SOURCE
185 .\" Before glibc 2.16, defining _ATFILE_SOURCE sufficed
186 to obtain its definition.
188 .BR AT_NO_AUTOMOUNT
189 Don't automount the terminal ("basename") component of
190 .I pathname
191 if it is a directory that is an automount point.
192 This allows the caller to gather attributes of an automount point
193 (rather than the location it would mount).
194 This flag can be used in tools that scan directories
195 to prevent mass-automounting of a directory of automount points.
197 .B AT_NO_AUTOMOUNT
198 flag has no effect if the mount point has already been mounted over.
199 This flag is Linux-specific; define
200 .B _GNU_SOURCE
201 .\" Before glibc 2.16, defining _ATFILE_SOURCE sufficed
202 to obtain its definition.
204 .B AT_SYMLINK_NOFOLLOW
206 .I pathname
207 is a symbolic link, do not dereference it:
208 instead return information about the link itself, like
209 .BR lstat (2).
211 .I flags
212 can also be used to control what sort of synchronization the kernel will do
213 when querying a file on a remote filesystem.
214 This is done by ORing in one of the following values:
216 .B AT_STATX_SYNC_AS_STAT
217 Do whatever
218 .BR stat (2)
219 does.
220 This is the default and is very much filesystem-specific.
222 .B AT_STATX_FORCE_SYNC
223 Force the attributes to be synchronized with the server.
224 This may require that
225 a network filesystem perform a data writeback to get the timestamps correct.
227 .B AT_STATX_DONT_SYNC
228 Don't synchronize anything, but rather just take whatever
229 the system has cached if possible.
230 This may mean that the information returned is approximate, but,
231 on a network filesystem, it may not involve a round trip to the server - even
232 if no lease is held.
235 .I mask
236 argument to
237 .BR statx ()
238 is used to tell the kernel which fields the caller is interested in.
239 .I mask
240 is an ORed combination of the following constants:
242 .in +4n
244 lB l.
245 STATX_TYPE      Want stx_mode & S_IFMT
246 STATX_MODE      Want stx_mode & \(tiS_IFMT
247 STATX_NLINK     Want stx_nlink
248 STATX_UID       Want stx_uid
249 STATX_GID       Want stx_gid
250 STATX_ATIME     Want stx_atime
251 STATX_MTIME     Want stx_mtime
252 STATX_CTIME     Want stx_ctime
253 STATX_INO       Want stx_ino
254 STATX_SIZE      Want stx_size
255 STATX_BLOCKS    Want stx_blocks
256 STATX_BASIC_STATS       [All of the above]
257 STATX_BTIME     Want stx_btime
258 STATX_ALL       [All currently available fields]
262 Note that, in general, the kernel does
263 .I not
264 reject values in
265 .I mask
266 other than the above.
267 (For an exception, see
268 .B EINVAL
269 in errors.)
270 Instead, it simply informs the caller which values are supported
271 by this kernel and filesystem via the
272 .I statx.stx_mask
273 field.
274 Therefore,
275 .I "do not"
276 simply set
277 .I mask
279 .B UINT_MAX
280 (all bits set),
281 as one or more bits may, in the future, be used to specify an
282 extension to the buffer.
284 The returned information
285 The status information for the target file is returned in the
286 .I statx
287 structure pointed to by
288 .IR statxbuf .
289 Included in this is
290 .I stx_mask
291 which indicates what other information has been returned.
292 .I stx_mask
293 has the same format as the
294 .I mask
295 argument and bits are set in it to indicate
296 which fields have been filled in.
298 It should be noted that the kernel may return fields that weren't
299 requested and may fail to return fields that were requested,
300 depending on what the backing filesystem supports.
301 (Fields that are given values despite being unrequested can just be ignored.)
302 In either case,
303 .I stx_mask
304 will not be equal
305 .IR mask .
307 If a filesystem does not support a field or if it has
308 an unrepresentable value (for instance, a file with an exotic type),
309 then the mask bit corresponding to that field will be cleared in
310 .I stx_mask
311 even if the user asked for it and a dummy value will be filled in for
312 compatibility purposes if one is available (e.g., a dummy UID and GID may be
313 specified to mount under some circumstances).
315 A filesystem may also fill in fields that the caller didn't ask for if it has
316 values for them available and the information is available at no extra cost.
317 If this happens, the corresponding bits will be set in
318 .IR stx_mask .
320 .\" Background: inode attributes are modified with i_mutex held, but
321 .\" read by stat() without taking the mutex.
322 .IR Note :
323 for performance and simplicity reasons, different fields in the
324 .I statx
325 structure may contain state information from different moments
326 during the execution of the system call.
327 For example, if
328 .IR stx_mode
330 .IR stx_uid
331 is changed by another process by calling
332 .BR chmod (2)
334 .BR chown (2),
335 .BR stat ()
336 might return the old
337 .I stx_mode
338 together with the new
339 .IR stx_uid ,
340 or the old
341 .I stx_uid
342 together with the new
343 .IR stx_mode .
345 Apart from
346 .I stx_mask
347 (which is described above), the fields in the
348 .I statx
349 structure are:
351 .I stx_blksize
352 The "preferred" block size for efficient filesystem I/O.
353 (Writing to a file in
354 smaller chunks may cause an inefficient read-modify-rewrite.)
356 .I stx_attributes
357 Further status information about the file (see below for more information).
359 .I stx_nlink
360 The number of hard links on a file.
362 .I stx_uid
363 This field contains the user ID of the owner of the file.
365 .I stx_gid
366 This field contains the ID of the group owner of the file.
368 .I stx_mode
369 The file type and mode.
371 .BR inode (7)
372 for details.
374 .I stx_ino
375 The inode number of the file.
377 .I stx_size
378 The size of the file (if it is a regular file or a symbolic link) in bytes.
379 The size of a symbolic link is the length of the pathname it contains,
380 without a terminating null byte.
382 .I stx_blocks
383 The number of blocks allocated to the file on the medium, in 512-byte units.
384 (This may be smaller than
385 .IR stx_size /512
386 when the file has holes.)
388 .I stx_attributes_mask
389 A mask indicating which bits in
390 .IR stx_attributes
391 are supported by the VFS and the filesystem.
393 .I stx_atime
394 The file's last access timestamp.
396 .I stx_btime
397 The file's creation timestamp.
399 .I stx_ctime
400 The file's last status change timestamp.
402 .I stx_mtime
403 The file's last modification timestamp.
405 .IR stx_dev_major " and "  stx_dev_minor
406 The device on which this file (inode) resides.
408 .IR stx_rdev_major " and "  stx_rdev_minor
409 The device that this file (inode) represents if the file is of block or
410 character device type.
412 For further information on the above fields, see
413 .BR inode (7).
415 .SS File attributes
417 .I stx_attributes
418 field contains a set of ORed flags that indicate additional attributes
419 of the file.
420 Note that any attribute that is not indicated as supported by
421 .I stx_attributes_mask
422 has no usable value here.
423 The bits in
424 .I stx_attributes_mask
425 correspond bit-by-bit to
426 .IR stx_attributes .
428 The flags are as follows:
430 .B STATX_ATTR_COMPRESSED
431 The file is compressed by the filesystem and may take extra resources
432 to access.
434 .B STATX_ATTR_IMMUTABLE
435 The file cannot be modified: it cannot be deleted or renamed,
436 no hard links can be created to this file and no data can be written to it.
438 .BR chattr (1).
440 .B STATX_ATTR_APPEND
441 The file can only be opened in append mode for writing.
442 Random access writing
443 is not permitted.
445 .BR chattr (1).
447 .B STATX_ATTR_NODUMP
448 File is not a candidate for backup when a backup program such as
449 .BR dump (8)
450 is run.
452 .BR chattr (1).
454 .B STATX_ATTR_ENCRYPTED
455 A key is required for the file to be encrypted by the filesystem.
457 .BR STATX_ATTR_VERITY " (since Linux 5.5)"
458 .\" commit 3ad2522c64cff1f5aebb987b00683268f0cc7c29
459 The file has fs-verity enabled.
460 It cannot be written to, and all reads from it will be verified
461 against a cryptographic hash that covers the
462 entire file (e.g., via a Merkle tree).
464 .BR STATX_ATTR_DAX " (since Linux 5.8)"
465 The file is in the DAX (cpu direct access) state.
466 DAX state attempts to
467 minimize software cache effects for both I/O and memory mappings of this file.
468 It requires a file system which has been configured to support DAX.
470 DAX generally assumes all accesses are via CPU load / store instructions
471 which can minimize overhead for small accesses,
472 but may adversely affect CPU utilization for large transfers.
474 File I/O is done directly to/from user-space buffers and memory mapped I/O may
475 be performed with direct memory mappings that bypass the kernel page cache.
477 While the DAX property tends to result in data being transferred synchronously,
478 it does not give the same guarantees as the
479 .B O_SYNC
480 flag (see
481 .BR open (2)),
482 where data and the necessary metadata are transferred together.
484 A DAX file may support being mapped with the
485 .B MAP_SYNC
486 flag, which enables a
487 program to use CPU cache flush instructions to persist CPU store operations
488 without an explicit
489 .BR fsync (2).
491 .BR mmap (2)
492 for more information.
493 .SH RETURN VALUE
494 On success, zero is returned.
495 On error, \-1 is returned, and
496 .I errno
497 is set to indicate the error.
498 .SH ERRORS
500 .B EACCES
501 Search permission is denied for one of the directories
502 in the path prefix of
503 .IR pathname .
504 (See also
505 .BR path_resolution (7).)
507 .B EBADF
508 .I dirfd
509 is not a valid open file descriptor.
511 .B EFAULT
512 .I pathname
514 .I statxbuf
515 is NULL or points to a location outside the process's
516 accessible address space.
518 .B EINVAL
519 Invalid flag specified in
520 .IR flags .
522 .B EINVAL
523 Reserved flag specified in
524 .IR mask .
525 (Currently, there is one such flag, designated by the constant
526 .BR STATX__RESERVED ,
527 with the value 0x80000000U.)
529 .B ELOOP
530 Too many symbolic links encountered while traversing the pathname.
532 .B ENAMETOOLONG
533 .I pathname
534 is too long.
536 .B ENOENT
537 A component of
538 .I pathname
539 does not exist, or
540 .I pathname
541 is an empty string and
542 .B AT_EMPTY_PATH
543 was not specified in
544 .IR flags .
546 .B ENOMEM
547 Out of memory (i.e., kernel memory).
549 .B ENOTDIR
550 A component of the path prefix of
551 .I pathname
552 is not a directory or
553 .I pathname
554 is relative and
555 .I dirfd
556 is a file descriptor referring to a file other than a directory.
557 .SH VERSIONS
558 .BR statx ()
559 was added to Linux in kernel 4.11; library support was added in glibc 2.28.
560 .SH CONFORMING TO
561 .BR statx ()
562 is Linux-specific.
563 .SH SEE ALSO
564 .BR ls (1),
565 .BR stat (1),
566 .BR access (2),
567 .BR chmod (2),
568 .BR chown (2),
569 .BR readlink (2),
570 .BR stat (2),
571 .BR utime (2),
572 .BR capabilities (7),
573 .BR inode (7),
574 .BR symlink (7)