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 <sys/stat.h> 14#include "lapi/syscalls.h" 15 16/* 17 * Timestamp structure for the timestamps in struct statx. 18 * 19 * tv_sec holds the number of seconds before (negative) or after (positive) 20 * 00:00:00 1st January 1970 UTC. 21 * 22 * tv_nsec holds a number of nanoseconds (0..999,999,999) after the tv_sec time. 23 * 24 * __reserved is held in case we need a yet finer resolution. 25 */ 26#ifndef HAVE_STRUCT_STATX_TIMESTAMP 27struct 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#ifndef HAVE_STRUCT_STATX 71struct statx { 72 /* 0x00 */ 73 uint32_t stx_mask; 74 uint32_t stx_blksize; 75 uint64_t stx_attributes; 76 /* 0x10 */ 77 uint32_t stx_nlink; 78 uint32_t stx_uid; 79 uint32_t stx_gid; 80 uint16_t stx_mode; 81 uint16_t __spare0[1]; 82 /* 0x20 */ 83 uint64_t stx_ino; 84 uint64_t stx_size; 85 uint64_t stx_blocks; 86 uint64_t stx_attributes_mask; 87 /* 0x40 */ 88 const struct statx_timestamp stx_atime; 89 const struct statx_timestamp stx_btime; 90 const struct statx_timestamp stx_ctime; 91 const struct statx_timestamp stx_mtime; 92 /* 0x80 */ 93 uint32_t stx_rdev_major; 94 uint32_t stx_rdev_minor; 95 uint32_t stx_dev_major; 96 uint32_t stx_dev_minor; 97 /* 0x90 */ 98 uint64_t __spare2[14]; 99 /* 0x100 */ 100}; 101#endif 102 103#ifndef HAVE_STATX 104 105/* 106 * statx: wrapper function of statx 107 * 108 * Returns: It returns status of statx syscall 109 */ 110static inline int statx(int dirfd, const char *pathname, unsigned int flags, 111 unsigned int mask, struct statx *statxbuf) 112{ 113 return tst_syscall(__NR_statx, dirfd, pathname, flags, mask, statxbuf); 114} 115#endif 116 117/* 118 * Flags to be stx_mask 119 * 120 * Query request/result mask for statx() and struct statx::stx_mask. 121 * 122 * These bits should be set in the mask argument of statx() to request 123 * particular items when calling statx(). 124 */ 125#ifndef STATX_TYPE 126# define STATX_TYPE 0x00000001U 127#endif 128 129#ifndef STATX_MODE 130# define STATX_MODE 0x00000002U 131#endif 132 133#ifndef STATX_NLINK 134# define STATX_NLINK 0x00000004U 135#endif 136 137#ifndef STATX_UID 138# define STATX_UID 0x00000008U 139#endif 140 141#ifndef STATX_GID 142# define STATX_GID 0x00000010U 143#endif 144 145#ifndef STATX_ATIME 146# define STATX_ATIME 0x00000020U 147#endif 148 149#ifndef STATX_MTIME 150# define STATX_MTIME 0x00000040U 151#endif 152 153#ifndef STATX_CTIME 154# define STATX_CTIME 0x00000080U 155#endif 156 157#ifndef STATX_INO 158# define STATX_INO 0x00000100U 159#endif 160 161#ifndef STATX_SIZE 162# define STATX_SIZE 0x00000200U 163#endif 164 165#ifndef STATX_BLOCKS 166# define STATX_BLOCKS 0x00000400U 167#endif 168 169#ifndef STATX_BASIC_STATS 170# define STATX_BASIC_STATS 0x000007ffU 171#endif 172 173#ifndef STATX_BTIME 174# define STATX_BTIME 0x00000800U 175#endif 176 177#ifndef STATX_MNT_ID 178# define STATX_MNT_ID 0x00001000U 179#endif 180 181#ifndef STATX_DIOALIGN 182# define STATX_DIOALIGN 0x00002000U 183#endif 184 185#ifndef STATX__RESERVED 186# define STATX__RESERVED 0x80000000U 187#endif 188 189/* 190 * Attributes to be found in stx_attributes and masked in stx_attributes_mask. 191 * 192 * These give information about the features or the state of a file that might 193 * be of use to ordinary userspace programs such as GUIs or ls rather than 194 * specialised tools. 195 * 196 * Note that the flags marked [I] correspond to generic FS_IOC_FLAGS 197 * semantically. Where possible, the numerical value is picked to correspond 198 * also. 199 */ 200#ifndef STATX_ATTR_COMPRESSED 201# define STATX_ATTR_COMPRESSED 0x00000004 202#endif 203 204#ifndef STATX_ATTR_IMMUTABLE 205# define STATX_ATTR_IMMUTABLE 0x00000010 206#endif 207 208#ifndef STATX_ATTR_APPEND 209# define STATX_ATTR_APPEND 0x00000020 210#endif 211 212#ifndef STATX_ATTR_NODUMP 213# define STATX_ATTR_NODUMP 0x00000040 214#endif 215 216#ifndef STATX_ATTR_ENCRYPTED 217# define STATX_ATTR_ENCRYPTED 0x00000800 218#endif 219 220#ifndef STATX_ATTR_AUTOMOUNT 221# define STATX_ATTR_AUTOMOUNT 0x00001000 222#endif 223 224#ifndef STATX_ATTR_MOUNT_ROOT 225# define STATX_ATTR_MOUNT_ROOT 0x00002000 226#endif 227 228#ifndef STATX_ATTR_VERITY 229# define STATX_ATTR_VERITY 0x00100000 230#endif 231 232#endif /* LAPI_STAT_H__ */ 233