]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - include/darwin.h
build: Add includes required for OS X
[thirdparty/xfsprogs-dev.git] / include / darwin.h
1 /*
2 * Copyright (c) 2004-2006 Silicon Graphics, Inc.
3 * All Rights Reserved.
4 *
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.
8 *
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.
13 *
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
17 */
18 #ifndef __XFS_DARWIN_H__
19 #define __XFS_DARWIN_H__
20
21 #include <unistd.h>
22 #include <sys/types.h>
23 #include <string.h>
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>
30 #include <sys/types.h>
31 #include <ftw.h>
32 #include <mach/mach_time.h>
33 #include <inttypes.h>
34 #include <stdio.h>
35
36 #include <machine/endian.h>
37 #define __BYTE_ORDER BYTE_ORDER
38 #define __BIG_ENDIAN BIG_ENDIAN
39 #define __LITTLE_ENDIAN LITTLE_ENDIAN
40
41 #include <sys/syscall.h>
42 # ifndef SYS_fsctl
43 # define SYS_fsctl 242
44 # endif
45
46 #ifndef XATTR_LIST_MAX
47 #define XATTR_LIST_MAX 65536
48 #endif
49
50 static __inline__ int xfsctl(const char *path, int fd, int cmd, void *p)
51 {
52 return syscall(SYS_fsctl, path, cmd, p, 0);
53 }
54
55 static __inline__ int platform_test_xfs_fd(int fd)
56 {
57 struct statfs buf;
58 if (fstatfs(fd, &buf) < 0)
59 return 0;
60 return strncmp(buf.f_fstypename, "xfs", 4) == 0;
61 }
62
63 static __inline__ int platform_test_xfs_path(const char *path)
64 {
65 struct statfs buf;
66 if (statfs(path, &buf) < 0)
67 return 0;
68 return strncmp(buf.f_fstypename, "xfs", 4) == 0;
69 }
70
71 static __inline__ int platform_fstatfs(int fd, struct statfs *buf)
72 {
73 return fstatfs(fd, buf);
74 }
75
76 static __inline__ void platform_getoptreset(void)
77 {
78 extern int optreset;
79 optreset = 0;
80 }
81
82 static __inline__ int platform_uuid_compare(uuid_t *uu1, uuid_t *uu2)
83 {
84 return uuid_compare(uu1, uu2, NULL);
85 }
86
87 static __inline__ void platform_uuid_unparse(uuid_t *uu, char *buffer)
88 {
89 uint32_t status;
90 char *s;
91 uuid_to_string(uu, &s, &status);
92 if (status == uuid_s_ok)
93 strcpy(buffer, s);
94 else buffer[0] = '\0';
95 free(s);
96 }
97
98 static __inline__ int platform_uuid_parse(char *buffer, uuid_t *uu)
99 {
100 uint32_t status;
101 uuid_from_string(buffer, uu, &status);
102 return (status == uuid_s_ok);
103 }
104
105 static __inline__ int platform_uuid_is_null(uuid_t *uu)
106 {
107 return uuid_is_nil(uu, NULL);
108 }
109
110 static __inline__ void platform_uuid_generate(uuid_t *uu)
111 {
112 uuid_create(uu, NULL);
113 }
114
115 static __inline__ void platform_uuid_clear(uuid_t *uu)
116 {
117 uuid_create_nil(uu, NULL);
118 }
119
120 static __inline__ void platform_uuid_copy(uuid_t *dst, uuid_t *src)
121 {
122 memcpy(dst, src, sizeof(uuid_t));
123 }
124
125 typedef unsigned char __u8;
126 typedef signed char __s8;
127 typedef unsigned short __u16;
128 typedef signed short __s16;
129 typedef unsigned int __u32;
130 typedef signed int __s32;
131 typedef unsigned long long int __u64;
132 typedef signed long long int __s64;
133
134 #define __int8_t int8_t
135 #define __int16_t int16_t
136 #define __int32_t int32_t
137 #define __int32_t int32_t
138 #define __int64_t int64_t
139 #define __uint8_t u_int8_t
140 #define __uint16_t u_int16_t
141 #define __uint32_t u_int32_t
142 #define __uint64_t u_int64_t
143 #define off64_t off_t
144
145 typedef off_t xfs_off_t;
146 typedef u_int64_t xfs_ino_t;
147 typedef u_int32_t xfs_dev_t;
148 typedef int64_t xfs_daddr_t;
149
150 #define stat64 stat
151 #define fstat64 fstat
152 #define lseek64 lseek
153 #define pread64 pread
154 #define pwrite64 pwrite
155 #define ftruncate64 ftruncate
156 #define fdatasync fsync
157 #define memalign(a,sz) valloc(sz)
158
159 #define O_LARGEFILE 0
160 #ifndef O_DIRECT
161 #define O_DIRECT 0
162 #endif
163 #ifndef O_SYNC
164 #define O_SYNC 0
165 #endif
166
167 #define ENOATTR 989 /* Attribute not found */
168 #define EFSCORRUPTED 990 /* Filesystem is corrupted */
169 #define EFSBADCRC 991 /* Bad CRC detected */
170 #define constpp char * const *
171
172 #define HAVE_FID 1
173
174 static __inline__ int
175 platform_discard_blocks(int fd, uint64_t start, uint64_t len)
176 {
177 return 0;
178 }
179
180 #endif /* __XFS_DARWIN_H__ */