/filesystems/sshfs/sshfs-fuse-2.1-macosx.patch
Patch | 416 lines | 390 code | 26 blank | 0 comment | 0 complexity | f7b3cb74a4d8dba031c2cb12c8c51109 MD5 | raw file
1diff -Naur old/Makefile.in new/Makefile.in 2--- old/Makefile.in 2008-07-11 04:04:11.000000000 -0700 3+++ new/Makefile.in 2008-07-14 18:14:24.000000000 -0700 4@@ -660,7 +660,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-07-14 18:14:24.000000000 -0700 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 2008-07-11 04:00:33.000000000 -0700 31+++ new/cache.c 2008-07-14 18:30:25.000000000 -0700 32@@ -553,6 +553,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@@ -587,3 +590,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 2008-07-11 04:00:33.000000000 -0700 52+++ new/cache.h 2008-07-14 18:16:57.000000000 -0700 53@@ -27,3 +27,7 @@ 54 void cache_add_attr(const char *path, const struct stat *stbuf, uint64_t wrctr); 55 void cache_invalidate(const char *path); 56 uint64_t cache_get_write_ctr(void); 57+ 58+#if (__FreeBSD__ >= 10) 59+extern int cache_enabled; 60+#endif 61diff -Naur old/sshfs.c new/sshfs.c 62--- old/sshfs.c 2008-07-11 04:00:33.000000000 -0700 63+++ new/sshfs.c 2008-07-14 18:32:07.000000000 -0700 64@@ -19,7 +19,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.7.0" 72+#include "fuse_darwin.h" 73+#endif 74 #include <pthread.h> 75 #include <netdb.h> 76 #include <signal.h> 77@@ -34,6 +39,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@@ -120,6 +129,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@@ -169,6 +188,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@@ -208,6 +230,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@@ -641,8 +667,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@@ -745,11 +780,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@@ -774,16 +831,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@@ -1476,6 +1541,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@@ -2070,6 +2139,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@@ -2153,6 +2230,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@@ -2186,11 +2266,21 @@ 240 } 241 242 if (!err) { 243+#if (__FreeBSD__ >= 10) 244+ if (cache_enabled) 245+ cache_add_attr(path, &stbuf, wrctr); 246+#else 247 cache_add_attr(path, &stbuf, wrctr); 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@@ -2245,14 +2335,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@@ -2942,7 +3050,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@@ -3026,6 +3139,15 @@ 308 perror("Failed to allocate locked page for password"); 309 return -1; 310 } 311+#if (__FreeBSD__ >= 10) 312+ if (mlock(sshfs.password, size) != 0) { 313+ memset(sshfs.password, 0, size); 314+ munmap(sshfs.password, size); 315+ sshfs.password = NULL; 316+ perror("Failed to allocate locked page for password"); 317+ return -1; 318+ } 319+#endif /* __FreeBSD__ >= 10 */ 320 321 /* Don't use fgets() because password might stay in memory */ 322 for (n = 0; n < max_password; n++) { 323@@ -3091,8 +3213,17 @@ 324 } 325 } 326 327+#if (__FreeBSD__ >= 10) 328+int main(int argc, char *argv[], __unused char *envp[], char **exec_path) 329+#else 330 int main(int argc, char *argv[]) 331+#endif 332 { 333+#if (__FreeBSD__ >= 10) 334+ if (!realpath(*exec_path, sshfs_program_path)) { 335+ memset(sshfs_program_path, 0, PATH_MAX); 336+ } 337+#endif 338 int res; 339 struct fuse_args args = FUSE_ARGS_INIT(argc, argv); 340 char *tmp; 341@@ -3101,6 +3232,10 @@ 342 const char *sftp_server; 343 int libver; 344 345+#if (__FreeBSD__ >= 10) 346+ /* Until this gets fixed somewhere else. */ 347+ g_slice_set_config(G_SLICE_CONFIG_ALWAYS_MALLOC, TRUE); 348+#endif /* __FreeBSD__ >= 10 */ 349 g_thread_init(NULL); 350 351 sshfs.blksize = 4096; 352@@ -3108,7 +3243,11 @@ 353 sshfs.max_write = 65536; 354 sshfs.nodelay_workaround = 1; 355 sshfs.nodelaysrv_workaround = 0; 356+#if (__FreeBSD__ >= 10) 357+ sshfs.rename_workaround = 1; 358+#else 359 sshfs.rename_workaround = 0; 360+#endif /* __FreeBSD__ >= 10 */ 361 sshfs.truncate_workaround = 0; 362 sshfs.buflimit_workaround = 1; 363 sshfs.ssh_ver = 2; 364@@ -3121,6 +3260,10 @@ 365 ssh_add_arg("-a"); 366 ssh_add_arg("-oClearAllForwardings=yes"); 367 368+#if (__FreeBSD__ >= 10) 369+ sshfs.detect_uid = 1; 370+#endif 371+ 372 if (fuse_opt_parse(&args, &sshfs, sshfs_opts, sshfs_opt_proc) == -1 || 373 parse_workarounds() == -1) 374 exit(1); 375diff -Naur old/sshnodelay.c new/sshnodelay.c 376--- old/sshnodelay.c 2007-12-11 14:23:29.000000000 -0800 377+++ new/sshnodelay.c 2008-07-14 18:14:32.000000000 -0700 378@@ -5,6 +5,32 @@ 379 #include <netinet/in.h> 380 #include <netinet/tcp.h> 381 382+#if (__FreeBSD__ >= 10) 383+ 384+int custom_connect(int sock, const struct sockaddr *addr, socklen_t addrlen); 385+ 386+typedef struct interpose_s { 387+ void *new_func; 388+ void *orig_func; 389+} interpose_t; 390+ 391+static const interpose_t interposers[] \ 392+ __attribute__ ((section("__DATA, __interpose"))) = { 393+ { (void *)custom_connect, (void *)connect }, 394+}; 395+ 396+int custom_connect(int sock, const struct sockaddr *addr, socklen_t addrlen) 397+{ 398+ int res = connect(sock, addr, addrlen); 399+ if (!res && addr->sa_family == AF_INET) { 400+ int opt = 1; 401+ setsockopt(sock, IPPROTO_TCP, TCP_NODELAY, &opt, sizeof(opt)); 402+ } 403+ return res; 404+} 405+ 406+#else 407+ 408 int connect(int sock, const struct sockaddr *addr, socklen_t addrlen) 409 { 410 int (*next_connect)(int, const struct sockaddr *, socklen_t) = 411@@ -16,3 +42,5 @@ 412 } 413 return res; 414 } 415+ 416+#endif