xref: /aosp_15_r20/external/ltp/include/lapi/stat.h (revision 49cdfc7efb34551c7342be41a7384b9c40d7cab7)
1*49cdfc7eSAndroid Build Coastguard Worker //SPDX-License-Identifier: GPL-2.0-or-later
2*49cdfc7eSAndroid Build Coastguard Worker /*
3*49cdfc7eSAndroid Build Coastguard Worker  * Referred from linux kernel -github/torvalds/linux/include/uapi/linux/fcntl.h
4*49cdfc7eSAndroid Build Coastguard Worker  * Copyright (c) Zilogic Systems Pvt. Ltd., 2018
5*49cdfc7eSAndroid Build Coastguard Worker  * Email: [email protected]
6*49cdfc7eSAndroid Build Coastguard Worker  */
7*49cdfc7eSAndroid Build Coastguard Worker 
8*49cdfc7eSAndroid Build Coastguard Worker #ifndef LAPI_STAT_H__
9*49cdfc7eSAndroid Build Coastguard Worker #define LAPI_STAT_H__
10*49cdfc7eSAndroid Build Coastguard Worker 
11*49cdfc7eSAndroid Build Coastguard Worker #include <stdint.h>
12*49cdfc7eSAndroid Build Coastguard Worker #include <unistd.h>
13*49cdfc7eSAndroid Build Coastguard Worker #include <sys/stat.h>
14*49cdfc7eSAndroid Build Coastguard Worker #include "lapi/syscalls.h"
15*49cdfc7eSAndroid Build Coastguard Worker 
16*49cdfc7eSAndroid Build Coastguard Worker /*
17*49cdfc7eSAndroid Build Coastguard Worker  * Timestamp structure for the timestamps in struct statx.
18*49cdfc7eSAndroid Build Coastguard Worker  *
19*49cdfc7eSAndroid Build Coastguard Worker  * tv_sec holds the number of seconds before (negative) or after (positive)
20*49cdfc7eSAndroid Build Coastguard Worker  * 00:00:00 1st January 1970 UTC.
21*49cdfc7eSAndroid Build Coastguard Worker  *
22*49cdfc7eSAndroid Build Coastguard Worker  * tv_nsec holds a number of nanoseconds (0..999,999,999) after the tv_sec time.
23*49cdfc7eSAndroid Build Coastguard Worker  *
24*49cdfc7eSAndroid Build Coastguard Worker  * __reserved is held in case we need a yet finer resolution.
25*49cdfc7eSAndroid Build Coastguard Worker  */
26*49cdfc7eSAndroid Build Coastguard Worker #ifndef HAVE_STRUCT_STATX_TIMESTAMP
27*49cdfc7eSAndroid Build Coastguard Worker struct statx_timestamp {
28*49cdfc7eSAndroid Build Coastguard Worker 	int64_t tv_sec;
29*49cdfc7eSAndroid Build Coastguard Worker 	uint32_t tv_nsec;
30*49cdfc7eSAndroid Build Coastguard Worker 	int32_t __reserved;
31*49cdfc7eSAndroid Build Coastguard Worker };
32*49cdfc7eSAndroid Build Coastguard Worker #endif
33*49cdfc7eSAndroid Build Coastguard Worker /*
34*49cdfc7eSAndroid Build Coastguard Worker  * Structures for the extended file attribute retrieval system call
35*49cdfc7eSAndroid Build Coastguard Worker  * (statx()).
36*49cdfc7eSAndroid Build Coastguard Worker  *
37*49cdfc7eSAndroid Build Coastguard Worker  * The caller passes a mask of what they're specifically interested in as a
38*49cdfc7eSAndroid Build Coastguard Worker  * parameter to statx().  What statx() actually got will be indicated in
39*49cdfc7eSAndroid Build Coastguard Worker  * st_mask upon return.
40*49cdfc7eSAndroid Build Coastguard Worker  *
41*49cdfc7eSAndroid Build Coastguard Worker  * For each bit in the mask argument:
42*49cdfc7eSAndroid Build Coastguard Worker  *
43*49cdfc7eSAndroid Build Coastguard Worker  * - if the datum is not supported:
44*49cdfc7eSAndroid Build Coastguard Worker  *
45*49cdfc7eSAndroid Build Coastguard Worker  *   - the bit will be cleared, and
46*49cdfc7eSAndroid Build Coastguard Worker  *
47*49cdfc7eSAndroid Build Coastguard Worker  *   - the datum will be set to an appropriate fabricated value if one is
48*49cdfc7eSAndroid Build Coastguard Worker  *     available (eg. CIFS can take a default uid and gid), otherwise
49*49cdfc7eSAndroid Build Coastguard Worker  *
50*49cdfc7eSAndroid Build Coastguard Worker  *   - the field will be cleared;
51*49cdfc7eSAndroid Build Coastguard Worker  *
52*49cdfc7eSAndroid Build Coastguard Worker  * - otherwise, if explicitly requested:
53*49cdfc7eSAndroid Build Coastguard Worker  *
54*49cdfc7eSAndroid Build Coastguard Worker  *   - the datum will be synchronised to the server if AT_STATX_FORCE_SYNC is
55*49cdfc7eSAndroid Build Coastguard Worker  *     set or if the datum is considered out of date, and
56*49cdfc7eSAndroid Build Coastguard Worker  *
57*49cdfc7eSAndroid Build Coastguard Worker  *   - the field will be filled in and the bit will be set;
58*49cdfc7eSAndroid Build Coastguard Worker  *
59*49cdfc7eSAndroid Build Coastguard Worker  * - otherwise, if not requested, but available in approximate form without any
60*49cdfc7eSAndroid Build Coastguard Worker  *   effort, it will be filled in anyway, and the bit will be set upon return
61*49cdfc7eSAndroid Build Coastguard Worker  *   (it might not be up to date, however, and no attempt will be made to
62*49cdfc7eSAndroid Build Coastguard Worker  *   synchronise the internal state first);
63*49cdfc7eSAndroid Build Coastguard Worker  *
64*49cdfc7eSAndroid Build Coastguard Worker  * - otherwise the field and the bit will be cleared before returning.
65*49cdfc7eSAndroid Build Coastguard Worker  *
66*49cdfc7eSAndroid Build Coastguard Worker  * Items in STATX_BASIC_STATS may be marked unavailable on return, but they
67*49cdfc7eSAndroid Build Coastguard Worker  * will have values installed for compatibility purposes so that stat() and
68*49cdfc7eSAndroid Build Coastguard Worker  * co. can be emulated in userspace.
69*49cdfc7eSAndroid Build Coastguard Worker  */
70*49cdfc7eSAndroid Build Coastguard Worker #ifndef HAVE_STRUCT_STATX
71*49cdfc7eSAndroid Build Coastguard Worker struct statx {
72*49cdfc7eSAndroid Build Coastguard Worker 	/* 0x00 */
73*49cdfc7eSAndroid Build Coastguard Worker 	uint32_t	stx_mask;
74*49cdfc7eSAndroid Build Coastguard Worker 	uint32_t	stx_blksize;
75*49cdfc7eSAndroid Build Coastguard Worker 	uint64_t	stx_attributes;
76*49cdfc7eSAndroid Build Coastguard Worker 	/* 0x10 */
77*49cdfc7eSAndroid Build Coastguard Worker 	uint32_t	stx_nlink;
78*49cdfc7eSAndroid Build Coastguard Worker 	uint32_t	stx_uid;
79*49cdfc7eSAndroid Build Coastguard Worker 	uint32_t	stx_gid;
80*49cdfc7eSAndroid Build Coastguard Worker 	uint16_t	stx_mode;
81*49cdfc7eSAndroid Build Coastguard Worker 	uint16_t	__spare0[1];
82*49cdfc7eSAndroid Build Coastguard Worker 	/* 0x20 */
83*49cdfc7eSAndroid Build Coastguard Worker 	uint64_t	stx_ino;
84*49cdfc7eSAndroid Build Coastguard Worker 	uint64_t	stx_size;
85*49cdfc7eSAndroid Build Coastguard Worker 	uint64_t	stx_blocks;
86*49cdfc7eSAndroid Build Coastguard Worker 	uint64_t	stx_attributes_mask;
87*49cdfc7eSAndroid Build Coastguard Worker 	/* 0x40 */
88*49cdfc7eSAndroid Build Coastguard Worker 	const struct statx_timestamp	stx_atime;
89*49cdfc7eSAndroid Build Coastguard Worker 	const struct statx_timestamp	stx_btime;
90*49cdfc7eSAndroid Build Coastguard Worker 	const struct statx_timestamp	stx_ctime;
91*49cdfc7eSAndroid Build Coastguard Worker 	const struct statx_timestamp	stx_mtime;
92*49cdfc7eSAndroid Build Coastguard Worker 	/* 0x80 */
93*49cdfc7eSAndroid Build Coastguard Worker 	uint32_t	stx_rdev_major;
94*49cdfc7eSAndroid Build Coastguard Worker 	uint32_t	stx_rdev_minor;
95*49cdfc7eSAndroid Build Coastguard Worker 	uint32_t	stx_dev_major;
96*49cdfc7eSAndroid Build Coastguard Worker 	uint32_t	stx_dev_minor;
97*49cdfc7eSAndroid Build Coastguard Worker 	/* 0x90 */
98*49cdfc7eSAndroid Build Coastguard Worker 	uint64_t	__spare2[14];
99*49cdfc7eSAndroid Build Coastguard Worker 	/* 0x100 */
100*49cdfc7eSAndroid Build Coastguard Worker };
101*49cdfc7eSAndroid Build Coastguard Worker #endif
102*49cdfc7eSAndroid Build Coastguard Worker 
103*49cdfc7eSAndroid Build Coastguard Worker #ifndef HAVE_STATX
104*49cdfc7eSAndroid Build Coastguard Worker 
105*49cdfc7eSAndroid Build Coastguard Worker /*
106*49cdfc7eSAndroid Build Coastguard Worker  * statx: wrapper function of statx
107*49cdfc7eSAndroid Build Coastguard Worker  *
108*49cdfc7eSAndroid Build Coastguard Worker  * Returns: It returns status of statx syscall
109*49cdfc7eSAndroid Build Coastguard Worker  */
statx(int dirfd,const char * pathname,unsigned int flags,unsigned int mask,struct statx * statxbuf)110*49cdfc7eSAndroid Build Coastguard Worker static inline int statx(int dirfd, const char *pathname, unsigned int flags,
111*49cdfc7eSAndroid Build Coastguard Worker 			unsigned int mask, struct statx *statxbuf)
112*49cdfc7eSAndroid Build Coastguard Worker {
113*49cdfc7eSAndroid Build Coastguard Worker 	return tst_syscall(__NR_statx, dirfd, pathname, flags, mask, statxbuf);
114*49cdfc7eSAndroid Build Coastguard Worker }
115*49cdfc7eSAndroid Build Coastguard Worker #endif
116*49cdfc7eSAndroid Build Coastguard Worker 
117*49cdfc7eSAndroid Build Coastguard Worker /*
118*49cdfc7eSAndroid Build Coastguard Worker  * Flags to be stx_mask
119*49cdfc7eSAndroid Build Coastguard Worker  *
120*49cdfc7eSAndroid Build Coastguard Worker  * Query request/result mask for statx() and struct statx::stx_mask.
121*49cdfc7eSAndroid Build Coastguard Worker  *
122*49cdfc7eSAndroid Build Coastguard Worker  * These bits should be set in the mask argument of statx() to request
123*49cdfc7eSAndroid Build Coastguard Worker  * particular items when calling statx().
124*49cdfc7eSAndroid Build Coastguard Worker  */
125*49cdfc7eSAndroid Build Coastguard Worker #ifndef STATX_TYPE
126*49cdfc7eSAndroid Build Coastguard Worker # define STATX_TYPE		0x00000001U
127*49cdfc7eSAndroid Build Coastguard Worker #endif
128*49cdfc7eSAndroid Build Coastguard Worker 
129*49cdfc7eSAndroid Build Coastguard Worker #ifndef STATX_MODE
130*49cdfc7eSAndroid Build Coastguard Worker # define STATX_MODE		0x00000002U
131*49cdfc7eSAndroid Build Coastguard Worker #endif
132*49cdfc7eSAndroid Build Coastguard Worker 
133*49cdfc7eSAndroid Build Coastguard Worker #ifndef STATX_NLINK
134*49cdfc7eSAndroid Build Coastguard Worker # define STATX_NLINK		0x00000004U
135*49cdfc7eSAndroid Build Coastguard Worker #endif
136*49cdfc7eSAndroid Build Coastguard Worker 
137*49cdfc7eSAndroid Build Coastguard Worker #ifndef STATX_UID
138*49cdfc7eSAndroid Build Coastguard Worker # define STATX_UID		0x00000008U
139*49cdfc7eSAndroid Build Coastguard Worker #endif
140*49cdfc7eSAndroid Build Coastguard Worker 
141*49cdfc7eSAndroid Build Coastguard Worker #ifndef STATX_GID
142*49cdfc7eSAndroid Build Coastguard Worker # define STATX_GID		0x00000010U
143*49cdfc7eSAndroid Build Coastguard Worker #endif
144*49cdfc7eSAndroid Build Coastguard Worker 
145*49cdfc7eSAndroid Build Coastguard Worker #ifndef STATX_ATIME
146*49cdfc7eSAndroid Build Coastguard Worker # define STATX_ATIME		0x00000020U
147*49cdfc7eSAndroid Build Coastguard Worker #endif
148*49cdfc7eSAndroid Build Coastguard Worker 
149*49cdfc7eSAndroid Build Coastguard Worker #ifndef STATX_MTIME
150*49cdfc7eSAndroid Build Coastguard Worker # define STATX_MTIME		0x00000040U
151*49cdfc7eSAndroid Build Coastguard Worker #endif
152*49cdfc7eSAndroid Build Coastguard Worker 
153*49cdfc7eSAndroid Build Coastguard Worker #ifndef STATX_CTIME
154*49cdfc7eSAndroid Build Coastguard Worker # define STATX_CTIME		0x00000080U
155*49cdfc7eSAndroid Build Coastguard Worker #endif
156*49cdfc7eSAndroid Build Coastguard Worker 
157*49cdfc7eSAndroid Build Coastguard Worker #ifndef STATX_INO
158*49cdfc7eSAndroid Build Coastguard Worker # define STATX_INO		0x00000100U
159*49cdfc7eSAndroid Build Coastguard Worker #endif
160*49cdfc7eSAndroid Build Coastguard Worker 
161*49cdfc7eSAndroid Build Coastguard Worker #ifndef STATX_SIZE
162*49cdfc7eSAndroid Build Coastguard Worker # define STATX_SIZE		0x00000200U
163*49cdfc7eSAndroid Build Coastguard Worker #endif
164*49cdfc7eSAndroid Build Coastguard Worker 
165*49cdfc7eSAndroid Build Coastguard Worker #ifndef STATX_BLOCKS
166*49cdfc7eSAndroid Build Coastguard Worker # define STATX_BLOCKS		0x00000400U
167*49cdfc7eSAndroid Build Coastguard Worker #endif
168*49cdfc7eSAndroid Build Coastguard Worker 
169*49cdfc7eSAndroid Build Coastguard Worker #ifndef STATX_BASIC_STATS
170*49cdfc7eSAndroid Build Coastguard Worker # define STATX_BASIC_STATS	0x000007ffU
171*49cdfc7eSAndroid Build Coastguard Worker #endif
172*49cdfc7eSAndroid Build Coastguard Worker 
173*49cdfc7eSAndroid Build Coastguard Worker #ifndef STATX_BTIME
174*49cdfc7eSAndroid Build Coastguard Worker # define STATX_BTIME		0x00000800U
175*49cdfc7eSAndroid Build Coastguard Worker #endif
176*49cdfc7eSAndroid Build Coastguard Worker 
177*49cdfc7eSAndroid Build Coastguard Worker #ifndef STATX_MNT_ID
178*49cdfc7eSAndroid Build Coastguard Worker # define STATX_MNT_ID		0x00001000U
179*49cdfc7eSAndroid Build Coastguard Worker #endif
180*49cdfc7eSAndroid Build Coastguard Worker 
181*49cdfc7eSAndroid Build Coastguard Worker #ifndef STATX_DIOALIGN
182*49cdfc7eSAndroid Build Coastguard Worker # define STATX_DIOALIGN		0x00002000U
183*49cdfc7eSAndroid Build Coastguard Worker #endif
184*49cdfc7eSAndroid Build Coastguard Worker 
185*49cdfc7eSAndroid Build Coastguard Worker #ifndef STATX__RESERVED
186*49cdfc7eSAndroid Build Coastguard Worker # define STATX__RESERVED	0x80000000U
187*49cdfc7eSAndroid Build Coastguard Worker #endif
188*49cdfc7eSAndroid Build Coastguard Worker 
189*49cdfc7eSAndroid Build Coastguard Worker /*
190*49cdfc7eSAndroid Build Coastguard Worker  * Attributes to be found in stx_attributes and masked in stx_attributes_mask.
191*49cdfc7eSAndroid Build Coastguard Worker  *
192*49cdfc7eSAndroid Build Coastguard Worker  * These give information about the features or the state of a file that might
193*49cdfc7eSAndroid Build Coastguard Worker  * be of use to ordinary userspace programs such as GUIs or ls rather than
194*49cdfc7eSAndroid Build Coastguard Worker  * specialised tools.
195*49cdfc7eSAndroid Build Coastguard Worker  *
196*49cdfc7eSAndroid Build Coastguard Worker  * Note that the flags marked [I] correspond to generic FS_IOC_FLAGS
197*49cdfc7eSAndroid Build Coastguard Worker  * semantically.  Where possible, the numerical value is picked to correspond
198*49cdfc7eSAndroid Build Coastguard Worker  * also.
199*49cdfc7eSAndroid Build Coastguard Worker  */
200*49cdfc7eSAndroid Build Coastguard Worker #ifndef STATX_ATTR_COMPRESSED
201*49cdfc7eSAndroid Build Coastguard Worker # define STATX_ATTR_COMPRESSED	0x00000004
202*49cdfc7eSAndroid Build Coastguard Worker #endif
203*49cdfc7eSAndroid Build Coastguard Worker 
204*49cdfc7eSAndroid Build Coastguard Worker #ifndef STATX_ATTR_IMMUTABLE
205*49cdfc7eSAndroid Build Coastguard Worker # define STATX_ATTR_IMMUTABLE	0x00000010
206*49cdfc7eSAndroid Build Coastguard Worker #endif
207*49cdfc7eSAndroid Build Coastguard Worker 
208*49cdfc7eSAndroid Build Coastguard Worker #ifndef STATX_ATTR_APPEND
209*49cdfc7eSAndroid Build Coastguard Worker # define STATX_ATTR_APPEND	0x00000020
210*49cdfc7eSAndroid Build Coastguard Worker #endif
211*49cdfc7eSAndroid Build Coastguard Worker 
212*49cdfc7eSAndroid Build Coastguard Worker #ifndef STATX_ATTR_NODUMP
213*49cdfc7eSAndroid Build Coastguard Worker # define STATX_ATTR_NODUMP	0x00000040
214*49cdfc7eSAndroid Build Coastguard Worker #endif
215*49cdfc7eSAndroid Build Coastguard Worker 
216*49cdfc7eSAndroid Build Coastguard Worker #ifndef STATX_ATTR_ENCRYPTED
217*49cdfc7eSAndroid Build Coastguard Worker # define STATX_ATTR_ENCRYPTED	0x00000800
218*49cdfc7eSAndroid Build Coastguard Worker #endif
219*49cdfc7eSAndroid Build Coastguard Worker 
220*49cdfc7eSAndroid Build Coastguard Worker #ifndef STATX_ATTR_AUTOMOUNT
221*49cdfc7eSAndroid Build Coastguard Worker # define STATX_ATTR_AUTOMOUNT	0x00001000
222*49cdfc7eSAndroid Build Coastguard Worker #endif
223*49cdfc7eSAndroid Build Coastguard Worker 
224*49cdfc7eSAndroid Build Coastguard Worker #ifndef STATX_ATTR_MOUNT_ROOT
225*49cdfc7eSAndroid Build Coastguard Worker # define STATX_ATTR_MOUNT_ROOT	0x00002000
226*49cdfc7eSAndroid Build Coastguard Worker #endif
227*49cdfc7eSAndroid Build Coastguard Worker 
228*49cdfc7eSAndroid Build Coastguard Worker #ifndef STATX_ATTR_VERITY
229*49cdfc7eSAndroid Build Coastguard Worker # define STATX_ATTR_VERITY	0x00100000
230*49cdfc7eSAndroid Build Coastguard Worker #endif
231*49cdfc7eSAndroid Build Coastguard Worker 
232*49cdfc7eSAndroid Build Coastguard Worker #endif /* LAPI_STAT_H__ */
233