common: kill _supported_os
[xfstests-dev.git] / src / statx.h
1 #ifndef STATX_H
2 #define STATX_H
3
4 #include <unistd.h>
5 #include <sys/syscall.h>
6 #include <linux/types.h>
7
8 #ifndef AT_STATX_SYNC_TYPE
9 #define AT_STATX_SYNC_TYPE      0x6000  /* Type of synchronisation required from statx() */
10 #define AT_STATX_SYNC_AS_STAT   0x0000  /* - Do whatever stat() does */
11 #define AT_STATX_FORCE_SYNC     0x2000  /* - Force the attributes to be sync'd with the server */
12 #define AT_STATX_DONT_SYNC      0x4000  /* - Don't sync attributes with the server */
13 #endif
14
15 #ifndef AT_NO_AUTOMOUNT
16 #define AT_NO_AUTOMOUNT         0x800   /* Suppress terminal automount traversal */
17 #endif
18
19 #ifndef __NR_statx
20 # ifdef __i386__
21 #  define __NR_statx 383
22 # elif defined(__x86_64__)
23 #  if defined (__ILP32__)
24 #   define __NR_statx (__X32_SYSCALL_BIT + 332)
25 #  else
26 #   define __NR_statx 332
27 #  endif
28 # endif
29 #endif
30
31 #ifndef STATX_TYPE
32
33 /*
34  * Timestamp structure for the timestamps in struct statx.
35  *
36  * tv_sec holds the number of seconds before (negative) or after (positive)
37  * 00:00:00 1st January 1970 UTC.
38  *
39  * tv_nsec holds a number of nanoseconds before (0..-999,999,999 if tv_sec is
40  * negative) or after (0..999,999,999 if tv_sec is positive) the tv_sec time.
41  *
42  * Note that if both tv_sec and tv_nsec are non-zero, then the two values must
43  * either be both positive or both negative.
44  *
45  * __reserved is held in case we need a yet finer resolution.
46  */
47 struct statx_timestamp {
48         __s64   tv_sec;
49         __s32   tv_nsec;
50         __s32   __reserved;
51 };
52
53 /*
54  * Structures for the extended file attribute retrieval system call
55  * (statx()).
56  *
57  * The caller passes a mask of what they're specifically interested in as a
58  * parameter to statx().  What statx() actually got will be indicated in
59  * st_mask upon return.
60  *
61  * For each bit in the mask argument:
62  *
63  * - if the datum is not supported:
64  *
65  *   - the bit will be cleared, and
66  *
67  *   - the datum will be set to an appropriate fabricated value if one is
68  *     available (eg. CIFS can take a default uid and gid), otherwise
69  *
70  *   - the field will be cleared;
71  *
72  * - otherwise, if explicitly requested:
73  *
74  *   - the datum will be synchronised to the server if AT_STATX_FORCE_SYNC is
75  *     set or if the datum is considered out of date, and
76  *
77  *   - the field will be filled in and the bit will be set;
78  *
79  * - otherwise, if not requested, but available in approximate form without any
80  *   effort, it will be filled in anyway, and the bit will be set upon return
81  *   (it might not be up to date, however, and no attempt will be made to
82  *   synchronise the internal state first);
83  *
84  * - otherwise the field and the bit will be cleared before returning.
85  *
86  * Items in STATX_BASIC_STATS may be marked unavailable on return, but they
87  * will have values installed for compatibility purposes so that stat() and
88  * co. can be emulated in userspace.
89  */
90 struct statx {
91         /* 0x00 */
92         __u32   stx_mask;       /* What results were written [uncond] */
93         __u32   stx_blksize;    /* Preferred general I/O size [uncond] */
94         __u64   stx_attributes; /* Flags conveying information about the file [uncond] */
95         /* 0x10 */
96         __u32   stx_nlink;      /* Number of hard links */
97         __u32   stx_uid;        /* User ID of owner */
98         __u32   stx_gid;        /* Group ID of owner */
99         __u16   stx_mode;       /* File mode */
100         __u16   __spare0[1];
101         /* 0x20 */
102         __u64   stx_ino;        /* Inode number */
103         __u64   stx_size;       /* File size */
104         __u64   stx_blocks;     /* Number of 512-byte blocks allocated */
105         __u64   __spare1[1];
106         /* 0x40 */
107         struct statx_timestamp  stx_atime;      /* Last access time */
108         struct statx_timestamp  stx_btime;      /* File creation time */
109         struct statx_timestamp  stx_ctime;      /* Last attribute change time */
110         struct statx_timestamp  stx_mtime;      /* Last data modification time */
111         /* 0x80 */
112         __u32   stx_rdev_major; /* Device ID of special file [if bdev/cdev] */
113         __u32   stx_rdev_minor;
114         __u32   stx_dev_major;  /* ID of device containing file [uncond] */
115         __u32   stx_dev_minor;
116         /* 0x90 */
117         __u64   __spare2[14];   /* Spare space for future expansion */
118         /* 0x100 */
119 };
120
121 /*
122  * Flags to be stx_mask
123  *
124  * Query request/result mask for statx() and struct statx::stx_mask.
125  *
126  * These bits should be set in the mask argument of statx() to request
127  * particular items when calling statx().
128  */
129 #define STATX_TYPE              0x00000001U     /* Want/got stx_mode & S_IFMT */
130 #define STATX_MODE              0x00000002U     /* Want/got stx_mode & ~S_IFMT */
131 #define STATX_NLINK             0x00000004U     /* Want/got stx_nlink */
132 #define STATX_UID               0x00000008U     /* Want/got stx_uid */
133 #define STATX_GID               0x00000010U     /* Want/got stx_gid */
134 #define STATX_ATIME             0x00000020U     /* Want/got stx_atime */
135 #define STATX_MTIME             0x00000040U     /* Want/got stx_mtime */
136 #define STATX_CTIME             0x00000080U     /* Want/got stx_ctime */
137 #define STATX_INO               0x00000100U     /* Want/got stx_ino */
138 #define STATX_SIZE              0x00000200U     /* Want/got stx_size */
139 #define STATX_BLOCKS            0x00000400U     /* Want/got stx_blocks */
140 #define STATX_BASIC_STATS       0x000007ffU     /* The stuff in the normal stat struct */
141 #define STATX_BTIME             0x00000800U     /* Want/got stx_btime */
142 #define STATX_ALL               0x00000fffU     /* All currently supported flags */
143
144 /*
145  * Attributes to be found in stx_attributes
146  *
147  * These give information about the features or the state of a file that might
148  * be of use to ordinary userspace programs such as GUIs or ls rather than
149  * specialised tools.
150  *
151  * Note that the flags marked [I] correspond to generic FS_IOC_FLAGS
152  * semantically.  Where possible, the numerical value is picked to correspond
153  * also.
154  */
155 #define STATX_ATTR_COMPRESSED           0x00000004 /* [I] File is compressed by the fs */
156 #define STATX_ATTR_IMMUTABLE            0x00000010 /* [I] File is marked immutable */
157 #define STATX_ATTR_APPEND               0x00000020 /* [I] File is append-only */
158 #define STATX_ATTR_NODUMP               0x00000040 /* [I] File is not to be dumped */
159 #define STATX_ATTR_ENCRYPTED            0x00000800 /* [I] File requires key to decrypt in fs */
160
161 #define STATX_ATTR_AUTOMOUNT            0x00001000 /* Dir: Automount trigger */
162 #endif /* STATX_TYPE */
163
164 static inline
165 int xfstests_statx(int dfd, const char *filename, unsigned flags,
166                    unsigned int mask, struct statx *buffer)
167 {
168 #ifdef __NR_statx
169         return syscall(__NR_statx, dfd, filename, flags, mask, buffer);
170 #else
171         errno = ENOSYS;
172         return -1;
173 #endif
174 }
175
176 #endif /* STATX_H */