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