summaryrefslogtreecommitdiff
blob: 8770fa9ba92b458715f379919576ddd1d9efa164 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
--- btrfs-image.c.orig	2009-02-15 14:49:17.000000000 +0100
+++ btrfs-image.c	2009-02-15 12:42:10.000000000 +0100
@@ -249,7 +249,7 @@
 static int metadump_init(struct metadump_struct *md, struct btrfs_root *root,
 			 FILE *out, int num_threads, int compress_level)
 {
-	int i, ret;
+	int i, ret = 0;
 
 	memset(md, 0, sizeof(*md));
 	pthread_cond_init(&md->cond, NULL);
@@ -608,7 +608,11 @@
 		if (async->start == BTRFS_SUPER_INFO_OFFSET)
 			update_super(outbuf);
 
+#ifdef __APPLE__
+		ret = pwrite(outfd, outbuf, size, async->start);
+#else
 		ret = pwrite64(outfd, outbuf, size, async->start);
+#endif
 		BUG_ON(ret != size);
 
 		pthread_mutex_lock(&mdres->mutex);
@@ -834,7 +838,9 @@
 	}
 
 	if (num_threads == 0 && compress_level > 0) {
+#ifdef _SC_NPROCESSORS_ONLN
 		num_threads = sysconf(_SC_NPROCESSORS_ONLN);
+#endif
 		if (num_threads <= 0)
 			num_threads = 1;
 	}
--- btrfsck.c.orig	2009-02-15 14:40:07.000000000 +0100
+++ btrfsck.c	2009-02-15 12:32:04.000000000 +0100
@@ -21,6 +21,9 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <fcntl.h>
+
+#include <sys/stat.h>
+
 #include "kerncompat.h"
 #include "ctree.h"
 #include "disk-io.h"
--- disk-io.c.orig	2009-02-15 13:35:46.000000000 +0100
+++ disk-io.c	2009-02-14 20:41:42.000000000 +0100
@@ -143,7 +143,11 @@
 	device = multi->stripes[0].dev;
 	device->total_ios++;
 	blocksize = min(blocksize, (u32)(64 * 1024));
+#ifdef __APPLE__
+	read(device->fd, &multi->stripes[0].physical, blocksize);
+#else
 	readahead(device->fd, multi->stripes[0].physical, blocksize);
+#endif
 	kfree(multi);
 	return 0;
 }
@@ -699,7 +703,11 @@
 	u64 bytenr;
 
 	if (sb_bytenr != BTRFS_SUPER_INFO_OFFSET) {
+#ifdef __APPLE__
+		ret = pread(fd, &buf, sizeof(buf), sb_bytenr);
+#else
 		ret = pread64(fd, &buf, sizeof(buf), sb_bytenr);
+#endif
 		if (ret < sizeof(buf))
 			return -1;
 
@@ -714,7 +722,11 @@
 
 	for (i = 0; i < BTRFS_SUPER_MIRROR_MAX; i++) {
 		bytenr = btrfs_sb_offset(i);
+#ifdef __APPLE__
+		ret = pread(fd, &buf, sizeof(buf), bytenr);
+#else
 		ret = pread64(fd, &buf, sizeof(buf), bytenr);
+#endif
 		if (ret < sizeof(buf))
 			break;
 
@@ -747,8 +759,13 @@
 				      BTRFS_SUPER_INFO_SIZE - BTRFS_CSUM_SIZE);
 		btrfs_csum_final(crc, (char *)&sb->csum[0]);
 
+#ifdef __APPLE__
+		ret = pwrite(device->fd, sb, BTRFS_SUPER_INFO_SIZE,
+				root->fs_info->super_bytenr);
+#else
 		ret = pwrite64(device->fd, sb, BTRFS_SUPER_INFO_SIZE,
 			       root->fs_info->super_bytenr);
+#endif
 		BUG_ON(ret != BTRFS_SUPER_INFO_SIZE);
 		return 0;
 	}
@@ -765,7 +782,11 @@
 				      BTRFS_SUPER_INFO_SIZE - BTRFS_CSUM_SIZE);
 		btrfs_csum_final(crc, (char *)&sb->csum[0]);
 
+#ifdef __APPLE__
+		ret = pwrite(device->fd, sb, BTRFS_SUPER_INFO_SIZE, bytenr);
+#else
 		ret = pwrite64(device->fd, sb, BTRFS_SUPER_INFO_SIZE, bytenr);
+#endif
 		BUG_ON(ret != BTRFS_SUPER_INFO_SIZE);
 	}
 	return 0;
--- extent-tree.c.orig	2009-02-15 13:39:33.000000000 +0100
+++ extent-tree.c	2009-02-14 20:43:40.000000000 +0100
@@ -2564,7 +2564,7 @@
 	u64 total_metadata = 0;
 	u64 chunk_objectid;
 	int ret;
-	int bit;
+	int bit = 0;
 	struct btrfs_root *extent_root;
 	struct btrfs_block_group_cache *cache;
 	struct extent_io_tree *block_group_cache;
--- file-item.c.orig	2009-02-15 13:41:47.000000000 +0100
+++ file-item.c	2009-02-14 20:44:17.000000000 +0100
@@ -193,7 +193,7 @@
 			  struct btrfs_root *root, u64 alloc_end,
 			  u64 bytenr, char *data, size_t len)
 {
-	int ret;
+	int ret = 0;
 	struct btrfs_key file_key;
 	struct btrfs_key found_key;
 	u64 next_offset = (u64)-1;
--- ioctl.h.orig	2009-02-15 13:46:49.000000000 +0100
+++ ioctl.h	2009-02-15 13:48:54.000000000 +0100
@@ -18,15 +18,23 @@
 
 #ifndef __IOCTL_
 #define __IOCTL_
+#ifndef __APPLE__
 #include <asm/types.h>
 #include <linux/ioctl.h>
+#endif
+
+#include <stdint.h>
 
 #define BTRFS_IOCTL_MAGIC 0x94
 #define BTRFS_VOL_NAME_MAX 255
 #define BTRFS_PATH_NAME_MAX 4087
 
 struct btrfs_ioctl_vol_args {
+#ifdef __APPLE__
+	int64_t fd;
+#else
 	__s64 fd;
+#endif
 	char name[BTRFS_PATH_NAME_MAX + 1];
 };
 
--- kerncompat.h.orig	2009-02-15 13:25:46.000000000 +0100
+++ kerncompat.h	2009-02-15 13:28:49.000000000 +0100
@@ -22,8 +22,13 @@
 #include <stdlib.h>
 #include <errno.h>
 #include <string.h>
+#ifdef __APPLE__
+#include <stdint.h>
+#include <libkern/OSByteOrder.h>
+#else
 #include <endian.h>
 #include <byteswap.h>
+#endif
 #include <assert.h>
 
 #ifndef READ
@@ -42,7 +47,7 @@
 #define GFP_NOFS 0
 #define __read_mostly
 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
-#define ULONG_MAX       (~0UL)
+//#define ULONG_MAX       (~0UL)
 #define BUG() abort()
 #ifdef __CHECKER__
 #define __force    __attribute__((force))
@@ -53,11 +58,18 @@
 #endif
 
 #ifndef __CHECKER__
+#ifdef __APPLE__
+typedef uint32_t u32;
+typedef uint64_t u64;
+typedef uint16_t u16;
+typedef uint8_t u8;
+#else
 #include <asm/types.h>
 typedef __u32 u32;
 typedef __u64 u64;
 typedef __u16 u16;
 typedef __u8 u8;
+#endif /* __APPLE__ */
 #else
 typedef unsigned int u32;
 typedef unsigned int __u32;
@@ -236,12 +248,21 @@
 #define __le8 u8
 
 #if __BYTE_ORDER == __BIG_ENDIAN
+#ifdef __APPLE__
+#define cpu_to_le64(x) ((__force __le64)(u64)(OSSwapHostToLittleInt64(x)))
+#define le64_to_cpu(x) ((__force u64)(__le64)(OSSwapLittleToHostInt64(x)))
+#define cpu_to_le32(x) ((__force __le32)(u32)(OSSwapHostToLittleInt32(x)))
+#define le32_to_cpu(x) ((__force u32)(__le32)(OSSwapLittleToHostInt32(x)))
+#define cpu_to_le16(x) ((__force __le16)(u16)(OSSwapHostToLittleInt16(x)))
+#define le16_to_cpu(x) ((__force u16)(__le16)(OSSwapLittleToHostInt16(x)))
+#else
 #define cpu_to_le64(x) ((__force __le64)(u64)(bswap_64(x)))
 #define le64_to_cpu(x) ((__force u64)(__le64)(bswap_64(x)))
 #define cpu_to_le32(x) ((__force __le32)(u32)(bswap_32(x)))
 #define le32_to_cpu(x) ((__force u32)(__le32)(bswap_32(x)))
 #define cpu_to_le16(x) ((__force __le16)(u16)(bswap_16(x)))
 #define le16_to_cpu(x) ((__force u16)(__le16)(bswap_16(x)))
+#endif /* __APPLE__ */
 #else
 #define cpu_to_le64(x) ((__force __le64)(u64)(x))
 #define le64_to_cpu(x) ((__force u64)(__le64)(x))
--- list.h.orig	2009-02-15 13:57:31.000000000 +0100
+++ list.h	2009-02-14 20:55:04.000000000 +0100
@@ -38,7 +38,7 @@
 
 #define LIST_HEAD_INIT(name) { &(name), &(name) }
 
-#define LIST_HEAD(name) \
+#define BTRFS_LIST_HEAD(name) \
 	struct list_head name = LIST_HEAD_INIT(name)
 
 static inline void INIT_LIST_HEAD(struct list_head *list)
--- mkfs.c.orig	2009-02-15 14:42:49.000000000 +0100
+++ mkfs.c	2009-02-15 14:47:19.000000000 +0100
@@ -18,6 +18,7 @@
 
 #define _XOPEN_SOURCE 500
 #define _GNU_SOURCE
+#define _DARWIN_C_SOURCE
 
 #ifndef __CHECKER__
 #include <sys/ioctl.h>
@@ -33,7 +34,9 @@
 #include <unistd.h>
 #include <getopt.h>
 #include <uuid/uuid.h>
+#ifndef __APPLE__
 #include <linux/fs.h>
+#endif
 #include <ctype.h>
 #include "kerncompat.h"
 #include "ctree.h"
--- utils.c.orig	2009-02-15 13:52:25.000000000 +0100
+++ utils.c	2009-02-15 13:53:35.000000000 +0100
@@ -18,6 +18,7 @@
 
 #define _XOPEN_SOURCE 600
 #define __USE_XOPEN2K
+#define _DARWIN_C_SOURCE
 #include <stdio.h>
 #include <stdlib.h>
 #ifndef __CHECKER__
@@ -30,7 +31,13 @@
 #include <dirent.h>
 #include <fcntl.h>
 #include <unistd.h>
+#ifdef __APPLE__
+#include <sys/disk.h>
+#else
 #include <mntent.h>
+#endif
+
+
 #include "kerncompat.h"
 #include "radix-tree.h"
 #include "ctree.h"
@@ -393,7 +400,11 @@
 	if (!S_ISBLK(st->st_mode)) {
 		return 0;
 	}
+#ifdef __APPLE__
+	if (ioctl(fd, DKIOCGETBLOCKCOUNT, &size) >= 0) {
+#else
 	if (ioctl(fd, BLKGETSIZE64, &size) >= 0) {
+#endif
 		return size;
 	}
 	return 0;
@@ -594,6 +605,9 @@
  */
 int check_mounted(char *file)
 {
+#ifdef __APPLE__
+	return 0;
+#else
 	struct mntent *mnt;
 	struct stat st_buf;
 	dev_t file_dev = 0;
@@ -638,6 +652,7 @@
 
 	endmntent (f);
 	return ret;
+#endif
 }
 
 struct pending_dir {
--- volumes.c.orig	2009-02-15 14:02:34.000000000 +0100
+++ volumes.c	2009-02-14 20:55:25.000000000 +0100
@@ -50,7 +50,7 @@
 #define map_lookup_size(n) (sizeof(struct map_lookup) + \
 			    (sizeof(struct btrfs_bio_stripe) * (n)))
 
-static LIST_HEAD(fs_uuids);
+static BTRFS_LIST_HEAD(fs_uuids);
 
 static struct btrfs_device *__find_device(struct list_head *head, u64 devid,
 					  u8 *uuid)