signal.7: Since Linux 3.8, read(2) on an inotify FD is restartable with SA_RESTART
[man-pages.git] / man2 / statx.2
bloba69096dd7b72855cd442d30c7af8ea1b9b6f286c
1 '\" t
2 .\" Copyright (c) 2017 David Howells <dhowells@redhat.com>
3 .\"
4 .\" Derived from the stat.2 manual page:
5 .\"   Copyright (c) 1992 Drew Eckhardt (drew@cs.colorado.edu), March 28, 1992
6 .\"   Parts Copyright (c) 1995 Nicolai Langfeldt (janl@ifi.uio.no), 1/1/95
7 .\"   and Copyright (c) 2006, 2007, 2014 Michael Kerrisk <mtk.manpages@gmail.com>
8 .\"
9 .\" %%%LICENSE_START(VERBATIM)
10 .\" Permission is granted to make and distribute verbatim copies of this
11 .\" manual provided the copyright notice and this permission notice are
12 .\" preserved on all copies.
13 .\"
14 .\" Permission is granted to copy and distribute modified versions of this
15 .\" manual under the conditions for verbatim copying, provided that the
16 .\" entire resulting derived work is distributed under the terms of a
17 .\" permission notice identical to this one.
18 .\"
19 .\" Since the Linux kernel and libraries are constantly changing, this
20 .\" manual page may be incorrect or out-of-date.  The author(s) assume no
21 .\" responsibility for errors or omissions, or for damages resulting from
22 .\" the use of the information contained herein.  The author(s) may not
23 .\" have taken the same level of care in the production of this manual,
24 .\" which is licensed free of charge, as they might when working
25 .\" professionally.
26 .\"
27 .\" Formatted or processed versions of this manual, if unaccompanied by
28 .\" the source, must acknowledge the copyright and authors of this work.
29 .\" %%%LICENSE_END
30 .\"
31 .TH STATX 2 2017-05-03 "Linux" "Linux Programmer's Manual"
32 .SH NAME
33 statx \- get file status (extended)
34 .SH SYNOPSIS
35 .nf
36 .B #include <sys/types.h>
37 .B #include <sys/stat.h>
38 .B #include <unistd.h>
39 .BR "#include <fcntl.h>           " "/* Definition of AT_* constants */"
41 .BI "int statx(int " dirfd ", const char *" pathname ", int " flags ","
42 .BI "          unsigned int " mask ", struct statx *" statxbuf );
43 .fi
45 .IR Note :
46 There is no glibc wrapper for
47 .BR statx ();
48 see NOTES.
49 .SH DESCRIPTION
50 .PP
51 This function returns information about a file, storing it in the buffer
52 pointed to by
53 .IR statxbuf .
54 The returned buffer is a structure of the following type:
55 .PP
56 .in +4n
57 .nf
58 struct statx {
59     __u32 stx_mask;        /* Mask of bits indicating
60                               filled fields */
61     __u32 stx_blksize;     /* Block size for filesystem I/O */
62     __u64 stx_attributes;  /* Extra file attribute indicators */
63     __u32 stx_nlink;       /* Number of hard links */
64     __u32 stx_uid;         /* User ID of owner */
65     __u32 stx_gid;         /* Group ID of owner */
66     __u16 stx_mode;        /* File type and mode */
67     __u64 stx_ino;         /* Inode number */
68     __u64 stx_size;        /* Total size in bytes */
69     __u64 stx_blocks;      /* Number of 512B blocks allocated */
70     __u64 stx_attributes_mask;
71                            /* Mask to show what's supported
72                               in stx_attributes */
74     /* The following fields are file timestamps */
75     struct statx_timestamp stx_atime;  /* Last access */
76     struct statx_timestamp stx_btime;  /* Creation */
77     struct statx_timestamp stx_ctime;  /* Last status change */
78     struct statx_timestamp stx_mtime;  /* Last modification */
80     /* If this file represents a device, then the next two
81        fields contain the ID of the device */
82     __u32 stx_rdev_major;  /* Major ID */
83     __u32 stx_rdev_minor;  /* Minor ID */
85     /* The next two fields contain the ID of the device
86        containing the filesystem where the file resides */
87     __u32 stx_dev_major;   /* Major ID */
88     __u32 stx_dev_minor;   /* Minor ID */
90 .fi
91 .in
92 .PP
93 The file timestamps are structures of the following type:
94 .PP
95 .in +4n
96 .nf
97 struct statx_timestamp {
98     __s64 tv_sec;    /* Seconds since the Epoch (UNIX time) */
99     __u32 tv_nsec;   /* Nanoseconds since tv_sec */
104 (Note that reserved space and padding is omitted.)
106 Invoking \fBstatx\fR():
108 To access a file's status, no permissions are required on the file itself,
109 but in the case of
110 .BR statx ()
111 with a pathname,
112 execute (search) permission is required on all of the directories in
113 .I pathname
114 that lead to the file.
116 .BR statx ()
117 uses
118 .IR pathname ,
119 .IR dirfd ,
121 .IR flags
122 to identify the target file in one of the following ways:
124 An absolute pathname
126 .I pathname
127 begins with a slash,
128 then it is an absolute pathname that identifies the target file.
129 In this case,
130 .I dirfd
131 is ignored.
133 A relative pathname
135 .I pathname
136 is a string that begins with a character other than a slash and
137 .IR dirfd
139 .BR AT_FDCWD ,
140 then
141 .I pathname
142 is a relative pathname that is interpreted relative to the process's
143 current working directory.
145 A directory-relative pathname
147 .I pathname
148 is a string that begins with a character other than a slash and
149 .I dirfd
150 is a file descriptor that refers to a directory, then
151 .I pathname
152 is a relative pathname that is interpreted relative to the directory
153 referred to by
154 .IR dirfd .
156 By file descriptor
158 .IR pathname
159 is an empty string and the
160 .B AT_EMPTY_PATH
161 flag is specified in
162 .IR flags
163 (see below),
164 then the target file is the one referred to by the file descriptor
165 .IR dirfd .
167 .I flags
168 can be used to influence a pathname-based lookup.
169 A value for
170 .I flags
171 is constructed by ORing together zero or more of the following constants:
173 .BR AT_EMPTY_PATH
174 .\" commit 65cfc6722361570bfe255698d9cd4dccaf47570d
176 .I pathname
177 is an empty string, operate on the file referred to by
178 .IR dirfd
179 (which may have been obtained using the
180 .BR open (2)
181 .B O_PATH
182 flag).
183 In this case,
184 .I dirfd
185 can refer to any type of file, not just a directory.
188 .I dirfd
190 .BR AT_FDCWD ,
191 the call operates on the current working directory.
193 This flag is Linux-specific; define
194 .B _GNU_SOURCE
195 .\" Before glibc 2.16, defining _ATFILE_SOURCE sufficed
196 to obtain its definition.
198 .BR AT_NO_AUTOMOUNT
199 Don't automount the terminal ("basename") component of
200 .I pathname
201 if it is a directory that is an automount point.
202 This allows the caller to gather attributes of an automount point
203 (rather than the location it would mount).
204 This flag can be used in tools that scan directories
205 to prevent mass-automounting of a directory of automount points.
207 .B AT_NO_AUTOMOUNT
208 flag has no effect if the mount point has already been mounted over.
209 This flag is Linux-specific; define
210 .B _GNU_SOURCE
211 .\" Before glibc 2.16, defining _ATFILE_SOURCE sufficed
212 to obtain its definition.
214 .B AT_SYMLINK_NOFOLLOW
216 .I pathname
217 is a symbolic link, do not dereference it:
218 instead return information about the link itself, like
219 .BR lstat (2).
221 .I flags
222 can also be used to control what sort of synchronization the kernel will do
223 when querying a file on a remote filesystem.
224 This is done by ORing in one of the following values:
226 .B AT_STATX_SYNC_AS_STAT
227 Do whatever
228 .BR stat (2)
229 does.
230 This is the default and is very much filesystem-specific.
232 .B AT_STATX_FORCE_SYNC
233 Force the attributes to be synchronized with the server.
234 This may require that
235 a network filesystem perform a data writeback to get the timestamps correct.
237 .B AT_STATX_DONT_SYNC
238 Don't synchronize anything, but rather just take whatever
239 the system has cached if possible.
240 This may mean that the information returned is approximate, but,
241 on a network filesystem, it may not involve a round trip to the server - even
242 if no lease is held.
245 .I mask
246 argument to
247 .BR statx ()
248 is used to tell the kernel which fields the caller is interested in.
249 .I mask
250 is an ORed combination of the following constants:
252 .in +4n
254 lB l.
255 STATX_TYPE      Want stx_mode & S_IFMT
256 STATX_MODE      Want stx_mode & ~S_IFMT
257 STATX_NLINK     Want stx_nlink
258 STATX_UID       Want stx_uid
259 STATX_GID       Want stx_gid
260 STATX_ATIME     Want stx_atime
261 STATX_MTIME     Want stx_mtime
262 STATX_CTIME     Want stx_ctime
263 STATX_INO       Want stx_ino
264 STATX_SIZE      Want stx_size
265 STATX_BLOCKS    Want stx_blocks
266 STATX_BASIC_STATS       [All of the above]
267 STATX_BTIME     Want stx_btime
268 STATX_ALL       [All currently available fields]
272 Note that the kernel does
273 .I not
274 reject values in
275 .I mask
276 other than the above.
277 Instead, it simply informs the caller which values are supported
278 by this kernel and filesystem via the
279 .I statx.stx_mask
280 field.
281 Therefore,
282 .I "do not"
283 simply set
284 .I mask
286 .B UINT_MAX
287 (all bits set),
288 as one or more bits may, in the future, be used to specify an
289 extension to the buffer.
291 The returned information
293 The status information for the target file is returned in the
294 .I statx
295 structure pointed to by
296 .IR statxbuf .
297 Included in this is
298 .I stx_mask
299 which indicates what other information has been returned.
300 .I stx_mask
301 has the same format as the
302 .I mask
303 argument and bits are set in it to indicate
304 which fields have been filled in.
306 It should be noted that the kernel may return fields that weren't
307 requested and may fail to return fields that were requested,
308 depending on what the backing filesystem supports.
309 (Fields that are given values despite being unrequested can just be ignored.)
310 In either case,
311 .I stx_mask
312 will not be equal
313 .IR mask .
315 If a filesystem does not support a field or if it has
316 an unrepresentable value (for instance, a file with an exotic type),
317 then the mask bit corresponding to that field will be cleared in
318 .I stx_mask
319 even if the user asked for it and a dummy value will be filled in for
320 compatibility purposes if one is available (e.g., a dummy UID and GID may be
321 specified to mount under some circumstances).
323 A filesystem may also fill in fields that the caller didn't ask for if it has
324 values for them available and the information is available at no extra cost.
325 If this happens, the corresponding bits will be set in
326 .IR stx_mask .
328 .\" Background: inode attributes are modified with i_mutex held, but
329 .\" read by stat() without taking the mutex.
330 .IR Note :
331 for performance and simplicity reasons, different fields in the
332 .I statx
333 structure may contain state information from different moments
334 during the execution of the system call.
335 For example, if
336 .IR stx_mode
338 .IR stx_uid
339 is changed by another process by calling
340 .BR chmod (2)
342 .BR chown (2),
343 .BR stat ()
344 might return the old
345 .I stx_mode
346 together with the new
347 .IR stx_uid ,
348 or the old
349 .I stx_uid
350 together with the new
351 .IR stx_mode .
353 Apart from
354 .I stx_mask
355 (which is described above), the fields in the
356 .I statx
357 structure are:
359 .I stx_blksize
360 The "preferred" block size for efficient filesystem I/O.
361 (Writing to a file in
362 smaller chunks may cause an inefficient read-modify-rewrite.)
364 .I stx_attributes
365 Further status information about the file (see below for more information).
367 .I stx_nlink
368 The number of hard links on a file.
370 .I stx_uid
371 This field contains the user ID of the owner of the file.
373 .I stx_gid
374 This field contains the ID of the group owner of the file.
376 .I stx_mode
377 The file type and mode.
379 .BR inode (7)
380 for details.
382 .I stx_ino
383 The inode number of the file.
385 .I stx_size
386 The size of the file (if it is a regular file or a symbolic link) in bytes.
387 The size of a symbolic link is the length of the pathname it contains,
388 without a terminating null byte.
390 .I stx_blocks
391 The number of blocks allocated to the file on the medium, in 512-byte units.
392 (This may be smaller than
393 .IR stx_size /512
394 when the file has holes.)
396 .I stx_attributes_mask
397 A mask indicating which bits in
398 .IR stx_attributes
399 are supported by the VFS and the filesystem.
401 .I stx_atime
402 The file's last access timestamp.
404 .I stx_btime
405 The file's creation timestamp.
407 .I stx_ctime
408 The file's last status change timestamp.
410 .I stx_mtime
411 The file's last modification timestamp.
413 .IR stx_dev_major " and "  stx_dev_minor
414 The device on which this file (inode) resides.
416 .IR stx_rdev_major " and "  stx_rdev_minor
417 The device that this file (inode) represents if the file is of block or
418 character device type.
420 For further information on the above fields, see
421 .BR inode (7).
423 .SS File attributes
426 .I stx_attributes
427 field contains a set of ORed flags that indicate additional attributes
428 of the file.
429 Note that any attribute that is not indicated as supported by
430 .I stx_attributes_mask
431 has no usable value here.
432 The bits in
433 .I stx_attributes_mask
434 correspond bit-by-bit to
435 .IR stx_attributes .
437 The flags are as follows:
439 .B STATX_ATTR_COMPRESSED
440 The file is compressed by the filesystem and may take extra resources
441 to access.
443 .B STATX_ATTR_IMMUTABLE
444 The file cannot be modified: it cannot be deleted or renamed,
445 no hard links can be created to this file and no data can be written to it.
447 .BR chattr (1).
449 .B STATX_ATTR_APPEND
450 The file can only be opened in append mode for writing.
451 Random access writing
452 is not permitted.
454 .BR chattr (1).
456 .B STATX_ATTR_NODUMP
457 File is not a candidate for backup when a backup program such as
458 .BR dump (8)
459 is run.
461 .BR chattr (1).
463 .B STATX_ATTR_ENCRYPTED
464 A key is required for the file to be encrypted by the filesystem.
465 .SH RETURN VALUE
466 On success, zero is returned.
467 On error, \-1 is returned, and
468 .I errno
469 is set appropriately.
470 .SH ERRORS
472 .B EACCES
473 Search permission is denied for one of the directories
474 in the path prefix of
475 .IR pathname .
476 (See also
477 .BR path_resolution (7).)
479 .B EBADF
480 .I dirfd
481 is not a valid open file descriptor.
483 .B EFAULT
484 .I pathname
486 .I statxbuf
487 is NULL or points to a location outside the process's
488 accessible address space.
490 .B EINVAL
491 Invalid flag specified in
492 .IR flags .
494 .B EINVAL
495 Reserved flag specified in
496 .IR mask .
498 .B ELOOP
499 Too many symbolic links encountered while traversing the pathname.
501 .B ENAMETOOLONG
502 .I pathname
503 is too long.
505 .B ENOENT
506 A component of
507 .I pathname
508 does not exist, or
509 .I pathname
510 is an empty string and
511 .B AT_EMPTY_PATH
512 was not specified in
513 .IR flags .
515 .B ENOMEM
516 Out of memory (i.e., kernel memory).
518 .B ENOTDIR
519 A component of the path prefix of
520 .I pathname
521 is not a directory or
522 .I pathname
523 is relative and
524 .I dirfd
525 is a file descriptor referring to a file other than a directory.
526 .SH VERSIONS
527 .BR statx ()
528 was added to Linux in kernel 4.11.
529 .SH CONFORMING TO
530 .BR statx ()
531 is Linux-specific.
532 .SH NOTES
533 Glibc does not (yet) provide a wrapper for the
534 .BR statx ()
535 system call; call it using
536 .BR syscall (2).
537 .SH SEE ALSO
538 .BR ls (1),
539 .BR stat (1),
540 .BR access (2),
541 .BR chmod (2),
542 .BR chown (2),
543 .BR stat (2),
544 .BR readlink (2),
545 .BR utime (2),
546 .BR capabilities (7),
547 .BR inode (7),
548 .BR symlink (7)