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

http://macfuse.googlecode.com/ · Patch · 416 lines · 390 code · 26 blank · 0 comment · 0 complexity · f7b3cb74a4d8dba031c2cb12c8c51109 MD5 · raw file

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