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