PageRenderTime 17ms CodeModel.GetById 8ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/filesystems/sshfs/sshfs-fuse-1.9-macosx.patch

http://macfuse.googlecode.com/
Patch | 399 lines | 374 code | 25 blank | 0 comment | 0 complexity | 195a7c8268b8deb3151c8b1015f3b602 MD5 | raw file
  1diff -Naur old/Makefile.in new/Makefile.in
  2--- old/Makefile.in	2007-12-17 06:45:48.000000000 -0800
  3+++ new/Makefile.in	2008-01-10 04:04:28.000000000 -0800
  4@@ -608,7 +608,11 @@
  5 @SSH_NODELAY_SO_TRUE@	rm -f "$(DESTDIR)$(libdir)/sshnodelay.so"
  6 
  7 @SSH_NODELAY_SO_TRUE@sshnodelay.so:
  8+ifeq "$(shell uname)" "Darwin"
  9+@SSH_NODELAY_SO_TRUE@	$(CC) -Wall -dynamiclib $(CFLAGS) $(sshnodelay_libs) -install_name "$(DESTDIR)$(libdir)/sshnodelay.so" sshnodelay.c -o sshnodelay.so
 10+else
 11 @SSH_NODELAY_SO_TRUE@	$(CC) -Wall -W -s --shared -fPIC $(sshnodelay_libs) sshnodelay.c -o sshnodelay.so
 12+endif
 13 # Tell versions [3.59,3.63) of GNU make to not export all variables.
 14 # Otherwise a system limit (for SysV at least) may be exceeded.
 15 .NOEXPORT:
 16diff -Naur old/README.MacFUSE new/README.MacFUSE
 17--- old/README.MacFUSE	1969-12-31 16:00:00.000000000 -0800
 18+++ new/README.MacFUSE	2008-01-10 04:01:39.000000000 -0800
 19@@ -0,0 +1,9 @@
 20+MacFUSE Project Page:
 21+
 22+http://code.google.com/p/macfuse/
 23+
 24+Making a Universal build of sshfs:
 25+
 26+0. Make sure dependencies (glib, MacFUSE) are installed
 27+1. Run ./configure_for_macfuse.sh
 28+2. Run make
 29diff -Naur old/cache.c new/cache.c
 30--- old/cache.c	2007-12-11 14:23:24.000000000 -0800
 31+++ new/cache.c	2008-01-10 04:01:39.000000000 -0800
 32@@ -527,6 +527,9 @@
 33 	cache.next_oper = oper;
 34 
 35 	cache_unity_fill(oper, &cache_oper);
 36+#if (__FreeBSD__ >= 10)
 37+	cache_enabled = cache.on;
 38+#endif
 39 	if (cache.on) {
 40 		cache_fill(oper, &cache_oper);
 41 		pthread_mutex_init(&cache.lock, NULL);
 42@@ -561,3 +564,7 @@
 43 
 44 	return fuse_opt_parse(args, &cache, cache_opts, NULL);
 45 }
 46+
 47+#if (__FreeBSD__ >= 10)
 48+int cache_enabled;
 49+#endif
 50diff -Naur old/cache.h new/cache.h
 51--- old/cache.h	2006-02-20 03:43:23.000000000 -0800
 52+++ new/cache.h	2008-01-10 04:01:39.000000000 -0800
 53@@ -26,3 +26,7 @@
 54 int cache_parse_options(struct fuse_args *args);
 55 void cache_add_attr(const char *path, const struct stat *stbuf);
 56 void cache_invalidate(const char *path);
 57+
 58+#if (__FreeBSD__ >= 10)
 59+extern int cache_enabled;
 60+#endif
 61diff -Naur old/sshfs.c new/sshfs.c
 62--- old/sshfs.c	2007-12-11 14:23:29.000000000 -0800
 63+++ new/sshfs.c	2008-01-10 04:01:39.000000000 -0800
 64@@ -18,7 +18,12 @@
 65 #include <string.h>
 66 #include <stdint.h>
 67 #include <errno.h>
 68+#if !(__FreeBSD__ >= 10)
 69 #include <semaphore.h>
 70+#else
 71+#define MACFUSE_SSHFS_VERSION "1.3.0"
 72+#include "fuse_darwin.h"
 73+#endif
 74 #include <pthread.h>
 75 #include <netdb.h>
 76 #include <signal.h>
 77@@ -30,6 +35,10 @@
 78 #include <netinet/in.h>
 79 #include <netinet/tcp.h>
 80 #include <glib.h>
 81+#if (__FreeBSD__ >= 10)
 82+#include <libgen.h>
 83+#include <strings.h>
 84+#endif
 85 
 86 #include "cache.h"
 87 
 88@@ -100,6 +109,16 @@
 89 
 90 #define SSHNODELAY_SO "sshnodelay.so"
 91 
 92+#if (__FreeBSD__ >= 10)
 93+
 94+#ifndef LIBDIR
 95+#define LIBDIR "/usr/local/lib"
 96+#endif
 97+
 98+static char sshfs_program_path[PATH_MAX] = { 0 };
 99+
100+#endif
101+
102 struct buffer {
103 	uint8_t *p;
104 	size_t len;
105@@ -149,6 +168,9 @@
106 	int connver;
107 	int modifver;
108 	int refs;
109+#if (__FreeBSD__ >= 10)
110+	pthread_mutex_t file_lock;
111+#endif
112 };
113 
114 struct sshfs {
115@@ -184,6 +206,10 @@
116 	int server_version;
117 	unsigned remote_uid;
118 	unsigned local_uid;
119+#if (__FreeBSD__ >= 10)
120+	unsigned remote_gid;
121+	unsigned local_gid;
122+#endif
123 	int remote_uid_detected;
124 	unsigned blksize;
125 	char *progname;
126@@ -589,8 +615,17 @@
127 		}
128 	}
129 
130+#if (__FreeBSD__ >= 10)
131+	if (sshfs.remote_uid_detected) {
132+		if (uid == sshfs.remote_uid)
133+			uid = sshfs.local_uid;
134+		if (gid == sshfs.remote_gid)
135+			gid = sshfs.local_gid;
136+	}
137+#else
138 	if (sshfs.remote_uid_detected && uid == sshfs.remote_uid)
139 		uid = sshfs.local_uid;
140+#endif
141 
142 	memset(stbuf, 0, sizeof(struct stat));
143 	stbuf->st_mode = mode;
144@@ -651,11 +686,33 @@
145 #ifdef SSH_NODELAY_WORKAROUND
146 static int do_ssh_nodelay_workaround(void)
147 {
148+#if (__FreeBSD__ >= 10)
149+	char *oldpreload = getenv("DYLD_INSERT_LIBRARIES");
150+#else
151 	char *oldpreload = getenv("LD_PRELOAD");
152+#endif
153 	char *newpreload;
154 	char sopath[PATH_MAX];
155 	int res;
156 
157+#if (__FreeBSD__ >= 10)
158+	char *sshfs_program_path_base = NULL;
159+	if (!sshfs_program_path[0]) {
160+		goto nobundle;
161+	}
162+	sshfs_program_path_base = dirname(sshfs_program_path);
163+	if (!sshfs_program_path_base) {
164+		goto nobundle;
165+	}
166+	snprintf(sopath, sizeof(sopath), "%s/%s", sshfs_program_path_base,
167+		SSHNODELAY_SO);
168+	res = access(sopath, R_OK);
169+	if (res == -1) {
170+		goto nobundle;
171+	}
172+	goto pathok;
173+nobundle:
174+#endif
175 	snprintf(sopath, sizeof(sopath), "%s/%s", LIBDIR, SSHNODELAY_SO);
176 	res = access(sopath, R_OK);
177 	if (res == -1) {
178@@ -680,16 +737,24 @@
179 			return -1;
180 		}
181 	}
182+#if (__FreeBSD__ >= 10)
183+pathok:
184+#endif
185 
186 	newpreload = g_strdup_printf("%s%s%s",
187 				     oldpreload ? oldpreload : "",
188 				     oldpreload ? " " : "",
189 				     sopath);
190 
191+#if (__FreeBSD__ >= 10)
192+	if (!newpreload || setenv("DYLD_INSERT_LIBRARIES", newpreload, 1) == -1)
193+		fprintf(stderr, "warning: failed set DYLD_INSERT_LIBRARIES for ssh nodelay workaround\n");
194+#else
195 	if (!newpreload || setenv("LD_PRELOAD", newpreload, 1) == -1) {
196 		fprintf(stderr, "warning: failed set LD_PRELOAD "
197 			"for ssh nodelay workaround\n");
198 	}
199+#endif
200 	g_free(newpreload);
201 	return 0;
202 }
203@@ -1188,6 +1253,10 @@
204 
205 	sshfs.remote_uid = stbuf.st_uid;
206 	sshfs.local_uid = getuid();
207+#if (__FreeBSD__ >= 10)
208+	sshfs.remote_gid = stbuf.st_gid;
209+	sshfs.local_gid = getgid();
210+#endif
211 	sshfs.remote_uid_detected = 1;
212 	DEBUG("remote_uid = %i\n", sshfs.remote_uid);
213 
214@@ -1758,6 +1827,14 @@
215 	buf_init(&buf, 0);
216 	buf_add_path(&buf, path);
217 	buf_add_uint32(&buf, SSH_FILEXFER_ATTR_UIDGID);
218+#if (__FreeBSD__ >= 10)
219+	if (sshfs.remote_uid_detected) {
220+		if (uid == sshfs.local_uid)
221+			uid = sshfs.remote_uid;
222+		if (gid == sshfs.local_gid)
223+			gid = sshfs.remote_gid;
224+	}
225+#endif
226 	buf_add_uint32(&buf, uid);
227 	buf_add_uint32(&buf, gid);
228 	err = sftp_request(SSH_FXP_SETSTAT, &buf, SSH_FXP_STATUS, NULL);
229@@ -1840,6 +1917,9 @@
230 	sf = g_new0(struct sshfs_file, 1);
231 	list_init(&sf->write_reqs);
232 	pthread_cond_init(&sf->write_finished, NULL);
233+#if (__FreeBSD__ >= 10)
234+	pthread_mutex_init(&sf->file_lock, NULL);
235+#endif
236 	/* Assume random read after open */
237 	sf->is_seq = 0;
238 	sf->refs = 1;
239@@ -1873,11 +1953,21 @@
240 	}
241 
242 	if (!err) {
243+#if (__FreeBSD__ >= 10)
244+		if (cache_enabled)
245+			cache_add_attr(path, &stbuf);
246+#else
247 		cache_add_attr(path, &stbuf);
248+#endif
249 		buf_finish(&sf->handle);
250 		fi->fh = (unsigned long) sf;
251 	} else {
252+#if (__FreeBSD__ >= 10)
253+		if (cache_enabled)
254+			cache_invalidate(path);
255+#else
256 		cache_invalidate(path);
257+#endif
258 		g_free(sf);
259 	}
260 	buf_free(&buf);
261@@ -1932,14 +2022,32 @@
262 
263 static void sshfs_file_put(struct sshfs_file *sf)
264 {
265+#if (__FreeBSD__ >= 10)
266+	pthread_mutex_lock(&sf->file_lock);
267+#endif
268 	sf->refs--;
269+#if (__FreeBSD__ >= 10)
270+	if (!sf->refs) {
271+		pthread_mutex_unlock(&sf->file_lock);
272+		g_free(sf);
273+	} else {
274+		pthread_mutex_unlock(&sf->file_lock);
275+	}
276+#else
277 	if (!sf->refs)
278 		g_free(sf);
279+#endif
280 }
281 
282 static void sshfs_file_get(struct sshfs_file *sf)
283 {
284+#if (__FreeBSD__ >= 10)
285+	pthread_mutex_lock(&sf->file_lock);
286+#endif
287 	sf->refs++;
288+#if (__FreeBSD__ >= 10)
289+	pthread_mutex_unlock(&sf->file_lock);
290+#endif
291 }
292 
293 static int sshfs_release(const char *path, struct fuse_file_info *fi)
294@@ -2583,7 +2691,12 @@
295 		exit(1);
296 
297 	case KEY_VERSION:
298+#if (__FreeBSD__ >= 10)
299+		fprintf(stderr, "SSHFS version %s (MacFUSE SSHFS %s)\n",
300+			PACKAGE_VERSION, MACFUSE_SSHFS_VERSION);
301+#else
302 		fprintf(stderr, "SSHFS version %s\n", PACKAGE_VERSION);
303+#endif
304 #if FUSE_VERSION >= 25
305 		fuse_opt_add_arg(outargs, "--version");
306 		sshfs_fuse_main(outargs);
307@@ -2650,8 +2763,17 @@
308 		fuse_opt_insert_arg(args, 1, "-olarge_read");
309 }
310 
311+#if (__FreeBSD__ >= 10)
312+int main(int argc, char *argv[], __unused char *envp[], char **exec_path)
313+#else
314 int main(int argc, char *argv[])
315+#endif
316 {
317+#if (__FreeBSD__ >= 10)
318+	if (!realpath(*exec_path, sshfs_program_path)) {
319+		memset(sshfs_program_path, 0, PATH_MAX);
320+	}
321+#endif
322 	int res;
323 	struct fuse_args args = FUSE_ARGS_INIT(argc, argv);
324 	char *tmp;
325@@ -2660,13 +2782,21 @@
326 	const char *sftp_server;
327 	int libver;
328 
329+#if (__FreeBSD__ >= 10)
330+	/* Until this gets fixed somewhere else. */
331+	g_slice_set_config(G_SLICE_CONFIG_ALWAYS_MALLOC, TRUE);
332+#endif
333 	g_thread_init(NULL);
334 
335 	sshfs.blksize = 4096;
336 	sshfs.max_read = 65536;
337 	sshfs.nodelay_workaround = 1;
338 	sshfs.nodelaysrv_workaround = 0;
339+#if (__FreeBSD__ >= 10)
340+	sshfs.rename_workaround = 1;
341+#else
342 	sshfs.rename_workaround = 0;
343+#endif
344 	sshfs.truncate_workaround = 0;
345 	sshfs.buflimit_workaround = 1;
346 	sshfs.ssh_ver = 2;
347@@ -2676,6 +2806,10 @@
348 	ssh_add_arg("-a");
349 	ssh_add_arg("-oClearAllForwardings=yes");
350 
351+#if (__FreeBSD__ >= 10)
352+	sshfs.detect_uid = 1;
353+#endif
354+
355 	if (fuse_opt_parse(&args, &sshfs, sshfs_opts, sshfs_opt_proc) == -1 ||
356 	    parse_workarounds() == -1)
357 		exit(1);
358diff -Naur old/sshnodelay.c new/sshnodelay.c
359--- old/sshnodelay.c	2007-12-11 14:23:29.000000000 -0800
360+++ new/sshnodelay.c	2008-01-10 04:01:39.000000000 -0800
361@@ -5,6 +5,32 @@
362 #include <netinet/in.h>
363 #include <netinet/tcp.h>
364 
365+#if (__FreeBSD__ >= 10)
366+
367+int custom_connect(int sock, const struct sockaddr *addr, socklen_t addrlen);
368+
369+typedef struct interpose_s {
370+	void *new_func;
371+	void *orig_func;
372+} interpose_t;
373+
374+static const interpose_t interposers[] \
375+	__attribute__ ((section("__DATA, __interpose"))) = {
376+	{ (void *)custom_connect,  (void *)connect  },
377+};
378+
379+int custom_connect(int sock, const struct sockaddr *addr, socklen_t addrlen)
380+{
381+	int res = connect(sock, addr, addrlen);
382+	if (!res && addr->sa_family == AF_INET) {
383+		int opt = 1;
384+		setsockopt(sock, IPPROTO_TCP, TCP_NODELAY, &opt, sizeof(opt));
385+	}
386+	return res;
387+}
388+
389+#else
390+
391 int connect(int sock, const struct sockaddr *addr, socklen_t addrlen)
392 {
393 	int (*next_connect)(int, const struct sockaddr *, socklen_t) =
394@@ -16,3 +42,5 @@
395 	}
396 	return res;
397 }
398+
399+#endif