]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blame - include/darwin.h
libxfs: fix xfs_trans_alloc_empty namespace
[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
c0211f67
NS
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
133#define __uint8_t u_int8_t
134#define __uint16_t u_int16_t
135#define __uint32_t u_int32_t
136#define __uint64_t u_int64_t
c0211f67
NS
137
138typedef off_t xfs_off_t;
139typedef u_int64_t xfs_ino_t;
140typedef u_int32_t xfs_dev_t;
141typedef int64_t xfs_daddr_t;
d8079fe0 142typedef __u32 xfs_nlink_t;
c0211f67 143
c0211f67
NS
144#define fdatasync fsync
145#define memalign(a,sz) valloc(sz)
146
c0211f67
NS
147#define O_LARGEFILE 0
148#ifndef O_DIRECT
149#define O_DIRECT 0
150#endif
151#ifndef O_SYNC
152#define O_SYNC 0
153#endif
154
c0211f67 155#define EFSCORRUPTED 990 /* Filesystem is corrupted */
99c1ec96 156#define EFSBADCRC 991 /* Bad CRC detected */
c0211f67
NS
157
158#define HAVE_FID 1
159
ad136b33 160static __inline__ int
f96aff0c 161platform_discard_blocks(int fd, uint64_t start, uint64_t len)
ad136b33
CH
162{
163 return 0;
164}
165
07b010a0
JT
166/*
167 * POSIX timer replacement.
168 * It really just do the minimum we need for xfs_repair.
169 * Also, as setitimer can't create multiple timers,
170 * the timerid things are useless - we have only one ITIMER_REAL
171 * timer.
172 */
173#define CLOCK_REALTIME ITIMER_REAL
174#define itimerspec itimerval
175typedef uint64_t timer_t;
176typedef double timer_c;
177typedef clock_id_t clockid_t;
178
179
180static inline int timer_create (clockid_t __clock_id,
181 struct sigevent *__restrict __evp,
182 timer_t *__restrict timer)
183{
184 // set something, to initialize the variable, just in case
185 *timer = 0;
186 return 0;
187}
188
189static inline int timer_settime (timer_t timerid, int flags,
190 const struct itimerspec *__restrict timerspec,
191 struct itimerspec *__restrict ovalue)
192{
193 return setitimer(ITIMER_REAL, timerspec, ovalue);
194}
195
196static inline int timer_delete (timer_t timerid)
197{
198 struct itimerspec timespec;
199
200 timespec.it_interval.tv_sec=0;
201 timespec.it_interval.tv_usec=0;
202 timespec.it_value.tv_sec=0;
203 timespec.it_value.tv_usec=0;
204
205 return setitimer(ITIMER_REAL, &timespec, NULL);
206}
207
208static inline int timer_gettime (timer_t timerid, struct itimerspec *value)
209{
210 return getitimer(ITIMER_REAL, value);
211}
212
b35b4eb8
JT
213/* FSR */
214
7141fc5b
JT
215# include <sys/mount.h>
216# include <sys/param.h>
217#include <sys/ucred.h>
218#include <errno.h>
b35b4eb8
JT
219#define _PATH_MOUNTED "/etc/mtab"
220
7141fc5b
JT
221struct mntent
222{
223 char *mnt_fsname;
224 char *mnt_dir;
225 char *mnt_type;
226 char *mnt_opts;
227 int mnt_freq;
228 int mnt_passno;
229};
230
231static inline void mntinfo2mntent (struct statfs * stats, struct mntent * mnt) {
232 mnt->mnt_fsname = stats->f_mntfromname;
233 mnt->mnt_dir = stats->f_mntonname;
234 mnt->mnt_type = stats->f_fstypename;
235}
236
237
238
239/**
240 * Abstraction of mountpoints.
241 */
242struct mntent_cursor {
243 FILE *mtabp;
244 struct statfs *stats;
245 int count;
246 int i;
247};
248
249/**
250 * OS X uses getmntinfo, which doesn't use a mtab file. So we just ignore it.
251 */
252static inline int platform_mntent_open(struct mntent_cursor * cursor, char *mtab)
253{
254 if ((cursor->count = getmntinfo(&cursor->stats, 0)) < 0) {
255 fprintf(stderr, "Error: getmntinfo() failed: %s\n", strerror(errno));
256 return 1;
257 }
258 cursor->i = 0;
259 return 0;
260}
261
262static inline struct mntent * platform_mntent_next(struct mntent_cursor * cursor)
263{
264 struct mntent * t = NULL;
265 if (cursor->i >= cursor->count){
266 return NULL;
267 }
268 mntinfo2mntent(&cursor->stats[cursor->i], t);
269 cursor->i++;
270 return t;
271}
272
273static inline void platform_mntent_close(struct mntent_cursor * cursor)
274{
275 cursor->count = 0;
276 cursor->i = 0;
277}
278
83f4b5ac
DC
279/* check whether we have to define FS_IOC_FS[GS]ETXATTR ourselves */
280#ifndef HAVE_FSXATTR
281struct fsxattr {
282 __u32 fsx_xflags; /* xflags field value (get/set) */
283 __u32 fsx_extsize; /* extsize field value (get/set)*/
284 __u32 fsx_nextents; /* nextents field value (get) */
285 __u32 fsx_projid; /* project identifier (get/set) */
1bc58d93
DW
286 __u32 fsx_cowextsize; /* cow extsize field value (get/set) */
287 unsigned char fsx_pad[8];
83f4b5ac
DC
288};
289
290/*
291 * Flags for the fsx_xflags field
292 */
293#define FS_XFLAG_REALTIME 0x00000001 /* data in realtime volume */
294#define FS_XFLAG_PREALLOC 0x00000002 /* preallocated file extents */
295#define FS_XFLAG_IMMUTABLE 0x00000008 /* file cannot be modified */
296#define FS_XFLAG_APPEND 0x00000010 /* all writes append */
297#define FS_XFLAG_SYNC 0x00000020 /* all writes synchronous */
298#define FS_XFLAG_NOATIME 0x00000040 /* do not update access time */
299#define FS_XFLAG_NODUMP 0x00000080 /* do not include in backups */
300#define FS_XFLAG_RTINHERIT 0x00000100 /* create with rt bit set */
301#define FS_XFLAG_PROJINHERIT 0x00000200 /* create with parents projid */
302#define FS_XFLAG_NOSYMLINKS 0x00000400 /* disallow symlink creation */
303#define FS_XFLAG_EXTSIZE 0x00000800 /* extent size allocator hint */
304#define FS_XFLAG_EXTSZINHERIT 0x00001000 /* inherit inode extent size */
305#define FS_XFLAG_NODEFRAG 0x00002000 /* do not defragment */
306#define FS_XFLAG_FILESTREAM 0x00004000 /* use filestream allocator */
7093f633 307#define FS_XFLAG_DAX 0x00008000 /* use DAX for IO */
83f4b5ac
DC
308#define FS_XFLAG_HASATTR 0x80000000 /* no DIFLAG for this */
309
310#define FS_IOC_FSGETXATTR _IOR ('X', 31, struct fsxattr)
311#define FS_IOC_FSSETXATTR _IOW ('X', 32, struct fsxattr)
312
313#endif
314
1bc58d93
DW
315#ifndef FS_XFLAG_COWEXTSIZE
316#define FS_XFLAG_COWEXTSIZE 0x00010000 /* CoW extent size allocator hint */
317#endif
318
c0211f67 319#endif /* __XFS_DARWIN_H__ */