]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blame - include/darwin.h
xfs_io: Add support for pwritev2()
[thirdparty/xfsprogs-dev.git] / include / darwin.h
CommitLineData
c0211f67 1/*
714bd9e5 2 * Copyright (c) 2004-2006 Silicon Graphics, Inc.
f302e9e4 3 * All Rights Reserved.
c0211f67 4 *
f302e9e4
NS
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public License
7 * as published by the Free Software Foundation.
c0211f67 8 *
f302e9e4
NS
9 * This program is distributed in the hope that it would be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Lesser General Public License for more details.
c0211f67 13 *
f302e9e4
NS
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with this program; if not, write the Free Software Foundation,
16 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
c0211f67
NS
17 */
18#ifndef __XFS_DARWIN_H__
19#define __XFS_DARWIN_H__
20
7f7fd8ac
JT
21#include <unistd.h>
22#include <sys/types.h>
23#include <string.h>
c0211f67
NS
24#include <uuid/uuid.h>
25#include <libgen.h>
26#include <sys/vm.h>
27#include <sys/stat.h>
28#include <sys/ioctl.h>
29#include <sys/mount.h>
3f257322 30#include <sys/types.h>
07b010a0 31#include <sys/time.h>
3f257322
JT
32#include <ftw.h>
33#include <mach/mach_time.h>
34#include <inttypes.h>
35#include <stdio.h>
a49984b3 36#include <sys/mman.h>
c0211f67 37
714bd9e5
NS
38#include <machine/endian.h>
39#define __BYTE_ORDER BYTE_ORDER
40#define __BIG_ENDIAN BIG_ENDIAN
41#define __LITTLE_ENDIAN LITTLE_ENDIAN
714bd9e5 42
c0211f67
NS
43#include <sys/syscall.h>
44# ifndef SYS_fsctl
45# define SYS_fsctl 242
46# endif
c6e8a131
JT
47
48#ifndef XATTR_LIST_MAX
49#define XATTR_LIST_MAX 65536
50#endif
51
c0211f67
NS
52static __inline__ int xfsctl(const char *path, int fd, int cmd, void *p)
53{
54 return syscall(SYS_fsctl, path, cmd, p, 0);
55}
56
57static __inline__ int platform_test_xfs_fd(int fd)
58{
59 struct statfs buf;
60 if (fstatfs(fd, &buf) < 0)
61 return 0;
714bd9e5 62 return strncmp(buf.f_fstypename, "xfs", 4) == 0;
c0211f67
NS
63}
64
65static __inline__ int platform_test_xfs_path(const char *path)
66{
67 struct statfs buf;
68 if (statfs(path, &buf) < 0)
69 return 0;
714bd9e5 70 return strncmp(buf.f_fstypename, "xfs", 4) == 0;
c0211f67
NS
71}
72
73static __inline__ int platform_fstatfs(int fd, struct statfs *buf)
74{
75 return fstatfs(fd, buf);
76}
77
78static __inline__ void platform_getoptreset(void)
79{
80 extern int optreset;
81 optreset = 0;
82}
83
1552a820
NS
84static __inline__ int platform_uuid_compare(uuid_t *uu1, uuid_t *uu2)
85{
dccb965d 86 return uuid_compare(*uu1, *uu2);
1552a820
NS
87}
88
4d32d744 89static __inline__ void platform_uuid_unparse(uuid_t *uu, char *buffer)
1552a820 90{
dccb965d 91 uuid_unparse(*uu, buffer);
1552a820
NS
92}
93
94static __inline__ int platform_uuid_parse(char *buffer, uuid_t *uu)
95{
dccb965d 96 return uuid_parse(buffer, *uu);
1552a820
NS
97}
98
99static __inline__ int platform_uuid_is_null(uuid_t *uu)
100{
dccb965d 101 return uuid_is_null(*uu);
1552a820
NS
102}
103
104static __inline__ void platform_uuid_generate(uuid_t *uu)
105{
dccb965d 106 uuid_generate(*uu);
1552a820
NS
107}
108
109static __inline__ void platform_uuid_clear(uuid_t *uu)
110{
dccb965d 111 uuid_clear(*uu);
1552a820
NS
112}
113
114static __inline__ void platform_uuid_copy(uuid_t *dst, uuid_t *src)
115{
dccb965d 116 uuid_copy(*dst, *src);
1552a820
NS
117}
118
24842c5c
CH
119typedef unsigned char __u8;
120typedef signed char __s8;
121typedef unsigned short __u16;
122typedef signed short __s16;
123typedef unsigned int __u32;
124typedef signed int __s32;
125typedef unsigned long long int __u64;
126typedef signed long long int __s64;
127
14f8b681
DW
128#define int8_t int8_t
129#define int16_t int16_t
130#define int32_t int32_t
131#define int32_t int32_t
132#define int64_t int64_t
c0211f67
NS
133
134typedef off_t xfs_off_t;
81043eae
FJ
135typedef uint64_t xfs_ino_t;
136typedef uint32_t xfs_dev_t;
c0211f67 137typedef int64_t xfs_daddr_t;
d8079fe0 138typedef __u32 xfs_nlink_t;
c0211f67 139
c0211f67
NS
140#define fdatasync fsync
141#define memalign(a,sz) valloc(sz)
142
c0211f67
NS
143#define O_LARGEFILE 0
144#ifndef O_DIRECT
145#define O_DIRECT 0
146#endif
147#ifndef O_SYNC
148#define O_SYNC 0
149#endif
150
c0211f67 151#define EFSCORRUPTED 990 /* Filesystem is corrupted */
99c1ec96 152#define EFSBADCRC 991 /* Bad CRC detected */
c0211f67
NS
153
154#define HAVE_FID 1
155
ad136b33 156static __inline__ int
f96aff0c 157platform_discard_blocks(int fd, uint64_t start, uint64_t len)
ad136b33
CH
158{
159 return 0;
160}
161
07b010a0
JT
162/*
163 * POSIX timer replacement.
164 * It really just do the minimum we need for xfs_repair.
165 * Also, as setitimer can't create multiple timers,
166 * the timerid things are useless - we have only one ITIMER_REAL
167 * timer.
168 */
169#define CLOCK_REALTIME ITIMER_REAL
170#define itimerspec itimerval
171typedef uint64_t timer_t;
172typedef double timer_c;
173typedef clock_id_t clockid_t;
174
175
176static inline int timer_create (clockid_t __clock_id,
177 struct sigevent *__restrict __evp,
178 timer_t *__restrict timer)
179{
180 // set something, to initialize the variable, just in case
181 *timer = 0;
182 return 0;
183}
184
185static inline int timer_settime (timer_t timerid, int flags,
186 const struct itimerspec *__restrict timerspec,
187 struct itimerspec *__restrict ovalue)
188{
189 return setitimer(ITIMER_REAL, timerspec, ovalue);
190}
191
192static inline int timer_delete (timer_t timerid)
193{
194 struct itimerspec timespec;
195
196 timespec.it_interval.tv_sec=0;
197 timespec.it_interval.tv_usec=0;
198 timespec.it_value.tv_sec=0;
199 timespec.it_value.tv_usec=0;
200
201 return setitimer(ITIMER_REAL, &timespec, NULL);
202}
203
204static inline int timer_gettime (timer_t timerid, struct itimerspec *value)
205{
206 return getitimer(ITIMER_REAL, value);
207}
208
b35b4eb8
JT
209/* FSR */
210
7141fc5b
JT
211# include <sys/mount.h>
212# include <sys/param.h>
213#include <sys/ucred.h>
214#include <errno.h>
b35b4eb8
JT
215#define _PATH_MOUNTED "/etc/mtab"
216
7141fc5b
JT
217struct mntent
218{
219 char *mnt_fsname;
220 char *mnt_dir;
221 char *mnt_type;
222 char *mnt_opts;
223 int mnt_freq;
224 int mnt_passno;
225};
226
227static inline void mntinfo2mntent (struct statfs * stats, struct mntent * mnt) {
228 mnt->mnt_fsname = stats->f_mntfromname;
229 mnt->mnt_dir = stats->f_mntonname;
230 mnt->mnt_type = stats->f_fstypename;
231}
232
233
234
235/**
236 * Abstraction of mountpoints.
237 */
238struct mntent_cursor {
239 FILE *mtabp;
240 struct statfs *stats;
241 int count;
242 int i;
243};
244
245/**
246 * OS X uses getmntinfo, which doesn't use a mtab file. So we just ignore it.
247 */
248static inline int platform_mntent_open(struct mntent_cursor * cursor, char *mtab)
249{
250 if ((cursor->count = getmntinfo(&cursor->stats, 0)) < 0) {
251 fprintf(stderr, "Error: getmntinfo() failed: %s\n", strerror(errno));
252 return 1;
253 }
254 cursor->i = 0;
255 return 0;
256}
257
258static inline struct mntent * platform_mntent_next(struct mntent_cursor * cursor)
259{
260 struct mntent * t = NULL;
261 if (cursor->i >= cursor->count){
262 return NULL;
263 }
264 mntinfo2mntent(&cursor->stats[cursor->i], t);
265 cursor->i++;
266 return t;
267}
268
269static inline void platform_mntent_close(struct mntent_cursor * cursor)
270{
271 cursor->count = 0;
272 cursor->i = 0;
273}
274
83f4b5ac
DC
275/* check whether we have to define FS_IOC_FS[GS]ETXATTR ourselves */
276#ifndef HAVE_FSXATTR
277struct fsxattr {
278 __u32 fsx_xflags; /* xflags field value (get/set) */
279 __u32 fsx_extsize; /* extsize field value (get/set)*/
280 __u32 fsx_nextents; /* nextents field value (get) */
281 __u32 fsx_projid; /* project identifier (get/set) */
1bc58d93
DW
282 __u32 fsx_cowextsize; /* cow extsize field value (get/set) */
283 unsigned char fsx_pad[8];
83f4b5ac
DC
284};
285
286/*
287 * Flags for the fsx_xflags field
288 */
289#define FS_XFLAG_REALTIME 0x00000001 /* data in realtime volume */
290#define FS_XFLAG_PREALLOC 0x00000002 /* preallocated file extents */
291#define FS_XFLAG_IMMUTABLE 0x00000008 /* file cannot be modified */
292#define FS_XFLAG_APPEND 0x00000010 /* all writes append */
293#define FS_XFLAG_SYNC 0x00000020 /* all writes synchronous */
294#define FS_XFLAG_NOATIME 0x00000040 /* do not update access time */
295#define FS_XFLAG_NODUMP 0x00000080 /* do not include in backups */
296#define FS_XFLAG_RTINHERIT 0x00000100 /* create with rt bit set */
297#define FS_XFLAG_PROJINHERIT 0x00000200 /* create with parents projid */
298#define FS_XFLAG_NOSYMLINKS 0x00000400 /* disallow symlink creation */
299#define FS_XFLAG_EXTSIZE 0x00000800 /* extent size allocator hint */
300#define FS_XFLAG_EXTSZINHERIT 0x00001000 /* inherit inode extent size */
301#define FS_XFLAG_NODEFRAG 0x00002000 /* do not defragment */
302#define FS_XFLAG_FILESTREAM 0x00004000 /* use filestream allocator */
7093f633 303#define FS_XFLAG_DAX 0x00008000 /* use DAX for IO */
83f4b5ac
DC
304#define FS_XFLAG_HASATTR 0x80000000 /* no DIFLAG for this */
305
306#define FS_IOC_FSGETXATTR _IOR ('X', 31, struct fsxattr)
307#define FS_IOC_FSSETXATTR _IOW ('X', 32, struct fsxattr)
308
309#endif
310
1bc58d93
DW
311#ifndef FS_XFLAG_COWEXTSIZE
312#define FS_XFLAG_COWEXTSIZE 0x00010000 /* CoW extent size allocator hint */
313#endif
314
c0211f67 315#endif /* __XFS_DARWIN_H__ */