Debian Codegraph @

upstream/debian-trixie/man2/statx.2

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