1STATX(2) Linux Programmer's Manual STATX(2)
2
3
4
6 statx - get file status (extended)
7
9 #include <fcntl.h> /* Definition of AT_* constants */
10 #include <sys/stat.h>
11
12 int statx(int dirfd, const char *restrict pathname, int flags,
13 unsigned int mask, struct statx *restrict statxbuf);
14
16 This function returns information about a file, storing it in the buf‐
17 fer pointed to by statxbuf. The returned buffer is a structure of the
18 following type:
19
20 struct statx {
21 __u32 stx_mask; /* Mask of bits indicating
22 filled fields */
23 __u32 stx_blksize; /* Block size for filesystem I/O */
24 __u64 stx_attributes; /* Extra file attribute indicators */
25 __u32 stx_nlink; /* Number of hard links */
26 __u32 stx_uid; /* User ID of owner */
27 __u32 stx_gid; /* Group ID of owner */
28 __u16 stx_mode; /* File type and mode */
29 __u64 stx_ino; /* Inode number */
30 __u64 stx_size; /* Total size in bytes */
31 __u64 stx_blocks; /* Number of 512B blocks allocated */
32 __u64 stx_attributes_mask;
33 /* Mask to show what's supported
34 in stx_attributes */
35
36 /* The following fields are file timestamps */
37 struct statx_timestamp stx_atime; /* Last access */
38 struct statx_timestamp stx_btime; /* Creation */
39 struct statx_timestamp stx_ctime; /* Last status change */
40 struct statx_timestamp stx_mtime; /* Last modification */
41
42 /* If this file represents a device, then the next two
43 fields contain the ID of the device */
44 __u32 stx_rdev_major; /* Major ID */
45 __u32 stx_rdev_minor; /* Minor ID */
46
47 /* The next two fields contain the ID of the device
48 containing the filesystem where the file resides */
49 __u32 stx_dev_major; /* Major ID */
50 __u32 stx_dev_minor; /* Minor ID */
51 };
52
53 The file timestamps are structures of the following type:
54
55 struct statx_timestamp {
56 __s64 tv_sec; /* Seconds since the Epoch (UNIX time) */
57 __u32 tv_nsec; /* Nanoseconds since tv_sec */
58 };
59
60 (Note that reserved space and padding is omitted.)
61
62 Invoking statx():
63 To access a file's status, no permissions are required on the file it‐
64 self, but in the case of statx() with a pathname, execute (search) per‐
65 mission is required on all of the directories in pathname that lead to
66 the file.
67
68 statx() uses pathname, dirfd, and flags to identify the target file in
69 one of the following ways:
70
71 An absolute pathname
72 If pathname begins with a slash, then it is an absolute pathname
73 that identifies the target file. In this case, dirfd is ig‐
74 nored.
75
76 A relative pathname
77 If pathname is a string that begins with a character other than
78 a slash and dirfd is AT_FDCWD, then pathname is a relative path‐
79 name that is interpreted relative to the process's current work‐
80 ing directory.
81
82 A directory-relative pathname
83 If pathname is a string that begins with a character other than
84 a slash and dirfd is a file descriptor that refers to a direc‐
85 tory, then pathname is a relative pathname that is interpreted
86 relative to the directory referred to by dirfd.
87
88 By file descriptor
89 If pathname is an empty string and the AT_EMPTY_PATH flag is
90 specified in flags (see below), then the target file is the one
91 referred to by the file descriptor dirfd.
92
93 flags can be used to influence a pathname-based lookup. A value for
94 flags is constructed by ORing together zero or more of the following
95 constants:
96
97 AT_EMPTY_PATH
98 If pathname is an empty string, operate on the file referred to
99 by dirfd (which may have been obtained using the open(2) O_PATH
100 flag). In this case, dirfd can refer to any type of file, not
101 just a directory.
102
103 If dirfd is AT_FDCWD, the call operates on the current working
104 directory.
105
106 This flag is Linux-specific; define _GNU_SOURCE to obtain its
107 definition.
108
109 AT_NO_AUTOMOUNT
110 Don't automount the terminal ("basename") component of pathname
111 if it is a directory that is an automount point. This allows
112 the caller to gather attributes of an automount point (rather
113 than the location it would mount). This flag can be used in
114 tools that scan directories to prevent mass-automounting of a
115 directory of automount points. The AT_NO_AUTOMOUNT flag has no
116 effect if the mount point has already been mounted over. This
117 flag is Linux-specific; define _GNU_SOURCE to obtain its defini‐
118 tion.
119
120 AT_SYMLINK_NOFOLLOW
121 If pathname is a symbolic link, do not dereference it: instead
122 return information about the link itself, like lstat(2).
123
124 flags can also be used to control what sort of synchronization the ker‐
125 nel will do when querying a file on a remote filesystem. This is done
126 by ORing in one of the following values:
127
128 AT_STATX_SYNC_AS_STAT
129 Do whatever stat(2) does. This is the default and is very much
130 filesystem-specific.
131
132 AT_STATX_FORCE_SYNC
133 Force the attributes to be synchronized with the server. This
134 may require that a network filesystem perform a data writeback
135 to get the timestamps correct.
136
137 AT_STATX_DONT_SYNC
138 Don't synchronize anything, but rather just take whatever the
139 system has cached if possible. This may mean that the informa‐
140 tion returned is approximate, but, on a network filesystem, it
141 may not involve a round trip to the server - even if no lease is
142 held.
143
144 The mask argument to statx() is used to tell the kernel which fields
145 the caller is interested in. mask is an ORed combination of the fol‐
146 lowing constants:
147
148 STATX_TYPE Want stx_mode & S_IFMT
149 STATX_MODE Want stx_mode & ~S_IFMT
150 STATX_NLINK Want stx_nlink
151 STATX_UID Want stx_uid
152 STATX_GID Want stx_gid
153 STATX_ATIME Want stx_atime
154 STATX_MTIME Want stx_mtime
155 STATX_CTIME Want stx_ctime
156 STATX_INO Want stx_ino
157 STATX_SIZE Want stx_size
158 STATX_BLOCKS Want stx_blocks
159 STATX_BASIC_STATS [All of the above]
160 STATX_BTIME Want stx_btime
161 STATX_ALL [All currently available fields]
162
163 Note that, in general, the kernel does not reject values in mask other
164 than the above. (For an exception, see EINVAL in errors.) Instead, it
165 simply informs the caller which values are supported by this kernel and
166 filesystem via the statx.stx_mask field. Therefore, do not simply set
167 mask to UINT_MAX (all bits set), as one or more bits may, in the fu‐
168 ture, be used to specify an extension to the buffer.
169
170 The returned information
171 The status information for the target file is returned in the statx
172 structure pointed to by statxbuf. Included in this is stx_mask which
173 indicates what other information has been returned. stx_mask has the
174 same format as the mask argument and bits are set in it to indicate
175 which fields have been filled in.
176
177 It should be noted that the kernel may return fields that weren't re‐
178 quested and may fail to return fields that were requested, depending on
179 what the backing filesystem supports. (Fields that are given values
180 despite being unrequested can just be ignored.) In either case,
181 stx_mask will not be equal mask.
182
183 If a filesystem does not support a field or if it has an unrepre‐
184 sentable value (for instance, a file with an exotic type), then the
185 mask bit corresponding to that field will be cleared in stx_mask even
186 if the user asked for it and a dummy value will be filled in for com‐
187 patibility purposes if one is available (e.g., a dummy UID and GID may
188 be specified to mount under some circumstances).
189
190 A filesystem may also fill in fields that the caller didn't ask for if
191 it has values for them available and the information is available at no
192 extra cost. If this happens, the corresponding bits will be set in
193 stx_mask.
194
195 Note: for performance and simplicity reasons, different fields in the
196 statx structure may contain state information from different moments
197 during the execution of the system call. For example, if stx_mode or
198 stx_uid is changed by another process by calling chmod(2) or chown(2),
199 stat() might return the old stx_mode together with the new stx_uid, or
200 the old stx_uid together with the new stx_mode.
201
202 Apart from stx_mask (which is described above), the fields in the statx
203 structure are:
204
205 stx_blksize
206 The "preferred" block size for efficient filesystem I/O. (Writ‐
207 ing to a file in smaller chunks may cause an inefficient read-
208 modify-rewrite.)
209
210 stx_attributes
211 Further status information about the file (see below for more
212 information).
213
214 stx_nlink
215 The number of hard links on a file.
216
217 stx_uid
218 This field contains the user ID of the owner of the file.
219
220 stx_gid
221 This field contains the ID of the group owner of the file.
222
223 stx_mode
224 The file type and mode. See inode(7) for details.
225
226 stx_ino
227 The inode number of the file.
228
229 stx_size
230 The size of the file (if it is a regular file or a symbolic
231 link) in bytes. The size of a symbolic link is the length of
232 the pathname it contains, without a terminating null byte.
233
234 stx_blocks
235 The number of blocks allocated to the file on the medium, in
236 512-byte units. (This may be smaller than stx_size/512 when the
237 file has holes.)
238
239 stx_attributes_mask
240 A mask indicating which bits in stx_attributes are supported by
241 the VFS and the filesystem.
242
243 stx_atime
244 The file's last access timestamp.
245
246 stx_btime
247 The file's creation timestamp.
248
249 stx_ctime
250 The file's last status change timestamp.
251
252 stx_mtime
253 The file's last modification timestamp.
254
255 stx_dev_major and stx_dev_minor
256 The device on which this file (inode) resides.
257
258 stx_rdev_major and stx_rdev_minor
259 The device that this file (inode) represents if the file is of
260 block or character device type.
261
262 For further information on the above fields, see inode(7).
263
264 File attributes
265 The stx_attributes field contains a set of ORed flags that indicate ad‐
266 ditional attributes of the file. Note that any attribute that is not
267 indicated as supported by stx_attributes_mask has no usable value here.
268 The bits in stx_attributes_mask correspond bit-by-bit to stx_at‐
269 tributes.
270
271 The flags are as follows:
272
273 STATX_ATTR_COMPRESSED
274 The file is compressed by the filesystem and may take extra re‐
275 sources to access.
276
277 STATX_ATTR_IMMUTABLE
278 The file cannot be modified: it cannot be deleted or renamed, no
279 hard links can be created to this file and no data can be writ‐
280 ten to it. See chattr(1).
281
282 STATX_ATTR_APPEND
283 The file can only be opened in append mode for writing. Random
284 access writing is not permitted. See chattr(1).
285
286 STATX_ATTR_NODUMP
287 File is not a candidate for backup when a backup program such as
288 dump(8) is run. See chattr(1).
289
290 STATX_ATTR_ENCRYPTED
291 A key is required for the file to be encrypted by the filesys‐
292 tem.
293
294 STATX_ATTR_VERITY (since Linux 5.5)
295 The file has fs-verity enabled. It cannot be written to, and
296 all reads from it will be verified against a cryptographic hash
297 that covers the entire file (e.g., via a Merkle tree).
298
299 STATX_ATTR_DAX (since Linux 5.8)
300 The file is in the DAX (cpu direct access) state. DAX state at‐
301 tempts to minimize software cache effects for both I/O and mem‐
302 ory mappings of this file. It requires a file system which has
303 been configured to support DAX.
304
305 DAX generally assumes all accesses are via CPU load / store in‐
306 structions which can minimize overhead for small accesses, but
307 may adversely affect CPU utilization for large transfers.
308
309 File I/O is done directly to/from user-space buffers and memory
310 mapped I/O may be performed with direct memory mappings that by‐
311 pass the kernel page cache.
312
313 While the DAX property tends to result in data being transferred
314 synchronously, it does not give the same guarantees as the
315 O_SYNC flag (see open(2)), where data and the necessary metadata
316 are transferred together.
317
318 A DAX file may support being mapped with the MAP_SYNC flag,
319 which enables a program to use CPU cache flush instructions to
320 persist CPU store operations without an explicit fsync(2). See
321 mmap(2) for more information.
322
324 On success, zero is returned. On error, -1 is returned, and errno is
325 set to indicate the error.
326
328 EACCES Search permission is denied for one of the directories in the
329 path prefix of pathname. (See also path_resolution(7).)
330
331 EBADF dirfd is not a valid open file descriptor.
332
333 EFAULT pathname or statxbuf is NULL or points to a location outside the
334 process's accessible address space.
335
336 EINVAL Invalid flag specified in flags.
337
338 EINVAL Reserved flag specified in mask. (Currently, there is one such
339 flag, designated by the constant STATX__RESERVED, with the value
340 0x80000000U.)
341
342 ELOOP Too many symbolic links encountered while traversing the path‐
343 name.
344
345 ENAMETOOLONG
346 pathname is too long.
347
348 ENOENT A component of pathname does not exist, or pathname is an empty
349 string and AT_EMPTY_PATH was not specified in flags.
350
351 ENOMEM Out of memory (i.e., kernel memory).
352
353 ENOTDIR
354 A component of the path prefix of pathname is not a directory or
355 pathname is relative and dirfd is a file descriptor referring to
356 a file other than a directory.
357
359 statx() was added to Linux in kernel 4.11; library support was added in
360 glibc 2.28.
361
363 statx() is Linux-specific.
364
366 ls(1), stat(1), access(2), chmod(2), chown(2), readlink(2), stat(2),
367 utime(2), capabilities(7), inode(7), symlink(7)
368
370 This page is part of release 5.12 of the Linux man-pages project. A
371 description of the project, information about reporting bugs, and the
372 latest version of this page, can be found at
373 https://www.kernel.org/doc/man-pages/.
374
375
376
377Linux 2021-03-22 STATX(2)