--- Makefile.com.old	2011-11-09 13:15:20.820359500 -0500
+++ Makefile.com	2011-11-09 14:42:19.274443000 -0500
@@ -65,6 +65,7 @@
         fuse_kernel.h \
         fuse_lowlevel.h \
         fuse_lowlevel_compat.h \
+        ulockmgr.h \
         fuse_opt.h
 
 INCHDRS = $(HDRS:%=../include/%)
@@ -105,6 +106,6 @@
 	$(INSTALL) -f $(ROOT)/usr/include/fuse ../include/fuse_lowlevel.h
 	$(INSTALL) -f $(ROOT)/usr/include/fuse ../include/fuse_lowlevel_compat.h
 	$(INSTALL) -f $(ROOT)/usr/include/fuse ../include/fuse_opt.h
-
+	$(INSTALL) -f $(ROOT)/usr/include/fuse ../include/ulockmgr.h
 clean:
 	rm -f $(OBJS) $(FUSERMOUNT_OBJS) $(FUSERMOUNT) $(FUSE_LIB) $(MOUNT_FUSE) $(MOUNT_FUSE_OBJS)
+++ fuse.c	2011-11-09 13:29:16.146778000 -0500
@@ -1306,8 +1306,11 @@
 {
     if (!err) {
         struct fuse *f = req_fuse(req);
-        if (fuse_reply_entry(req, e) == -ENOENT)
+               if (fuse_reply_entry(req, e) == -ENOENT) {
+                       /* Skip forget for negative result */
+                       if  (e->ino != 0)
             forget_node(f, e->ino, 1);
+               }
     } else
         reply_err(req, err);
 }
@@ -2071,6 +2074,7 @@
         }
     } else {
         reply_err(req, err);
+               pthread_mutex_destroy(&dh->lock);
         free(dh);
     }
     free(path);
@@ -2884,7 +2888,7 @@
 "    -o readdir_ino         try to fill in d_ino in readdir\n"
 "    -o direct_io           use direct I/O\n"
 "    -o kernel_cache        cache files in kernel\n"
-"    -o [no]auto_cache      enable caching based on modification times\n"
+"    -o [no]auto_cache      enable caching based on modification times (off)\n"
 "    -o umask=M             set file permissions (octal)\n"
 "    -o uid=N               set file owner\n"
 "    -o gid=N               set file group\n"
--- mount.c.old	2011-11-09 13:43:46.225855000 -0500
+++ mount.c	2011-11-09 13:48:00.549421000 -0500
@@ -333,10 +333,14 @@
            then the filesystem is already unmounted */
         if (res == 1 && (pfd.revents & POLLERR))
             return;
+
+               /* Need to close file descriptor, otherwise synchronous umount
+                  would recurse into filesystem, and deadlock */
+               close(fd);
     }
 
     if (geteuid() == 0) {
-        fuse_mnt_umount("fuse", mountpoint, 1);
+               fuse_mnt_umount("fuse", mountpoint,  1);
         return;
     }
 
--- mount_bsd.c.old	2011-11-09 13:49:45.181396000 -0500
+++ mount_bsd.c	2011-11-09 13:56:51.955838500 -0500
@@ -215,7 +215,7 @@
     dev = getenv("FUSE_DEV_NAME");
 
     if (! dev)
-	dev = FUSE_DEV_TRUNK;
+	dev = (char *)FUSE_DEV_TRUNK;
 
     if ((fd = open(dev, O_RDWR)) < 0) {
         perror("fuse: failed to open fuse device");
@@ -227,6 +227,7 @@
         goto out;
 
     pid = fork();
+       cpid = pid;
 
     if (pid == -1) {
         perror("fuse: fork() failed");
@@ -235,6 +236,13 @@
     }
 
     if (pid == 0) {
+               if (! init_backgrounded()) {
+                       /*
+                        * If init is not backgrounded, we have to
+                        * call the mount util backgrounded, to avoid
+                        * deadlock.
+                        */
+
         pid = fork();
 
         if (pid == -1) {
@@ -242,14 +250,17 @@
             close(fd);
             exit(1);
         }
+               }
 
         if (pid == 0) {
             const char *argv[32];
             int a = 0;
 
-            if (! fdnam)
-                asprintf(&fdnam, "%d", fd);
-
+                       if (! fdnam && asprintf(&fdnam, "%d", fd) == -1) {
+                               perror("fuse: failed to assemble mount arguments
+");
+                               exit(1);
+                       }
             argv[a++] = mountprog;
             if (opts) {
                 argv[a++] = "-o";
@@ -266,7 +277,11 @@
         exit(0);
     }
 
-    waitpid(pid, NULL, 0);
+       if (waitpid(cpid, &status, 0) == -1 || WEXITSTATUS(status) != 0) {
+               perror("fuse: failed to mount file system");
+               close(fd);
+               return -1;
+       }
 
 out:
     return fd;
--- ../../libfuse/fuse.pc	2010-06-15 15:46:54.000000000 +0100
+++ fuse.pc	2011-11-09 17:54:57.131890866 +0000
@@ -5,6 +5,6 @@
 
 Name: fuse
 Description: Filesystem in Userspace
-Version: 2.7.1
+Version: 2.7.6
 Libs: -L${libdir} -lfuse -lxnet
 Cflags: -I${includedir}/fuse -D_FILE_OFFSET_BITS=64
--- /dev/null	2011-11-09 16:44:05.000000000 +0000
+++ include/ulockmgr.h	2011-02-02 11:00:22.000000000 +0000
@@ -0,0 +1,24 @@
+/*
+  libulockmgr: Userspace Lock Manager Library
+  Copyright (C) 2006  Miklos Szeredi <miklos@szeredi.hu>
+
+  This program can be distributed under the terms of the GNU LGPLv2.
+  See the file COPYING.LIB.
+*/
+
+#include <stdint.h>
+#include <fcntl.h>
+#include <sys/types.h>
+
+/**
+ * Perform POSIX locking operation
+ *
+ * @param fd the file descriptor
+ * @param cmd the locking command (F_GETFL, F_SETLK or F_SETLKW)
+ * @param lock the lock parameters
+ * @param owner the lock owner ID cookie
+ * @param owner_len length of the lock owner ID cookie
+ * @return 0 on success -errno on error
+ */
+int ulockmgr_op(int fd, int cmd, struct flock *lock, const void *owner,
+		size_t owner_len);
--- ../../libfuse/fuse_loop_mt.c	2010-06-15 15:46:54.000000000 +0100
+++ fuse_loop_mt.c	2011-09-13 08:23:14.000000000 +0100
@@ -2,7 +2,7 @@
     FUSE: Filesystem in Userspace
     Copyright (C) 2001-2007  Miklos Szeredi <miklos@szeredi.hu>
 
-    This program can be distributed under the terms of the GNU LGPL.
+  This program can be distributed under the terms of the GNU LGPLv2.
     See the file COPYING.LIB.
 */
 
@@ -19,6 +19,9 @@
 #include <errno.h>
 #include <sys/time.h>
 
+/* Environment var controlling the thread stack size */
+#define ENVNAME_THREAD_STACK "FUSE_THREAD_STACK"
+
 struct fuse_worker {
     struct fuse_worker *prev;
     struct fuse_worker *next;
@@ -67,7 +70,11 @@
     while (!fuse_session_exited(mt->se)) {
         int isforget = 0;
         struct fuse_chan *ch = mt->prevch;
-        int res = fuse_chan_recv(&ch, w->buf, w->bufsize);
+		int res;
+
+		pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
+		res = fuse_chan_recv(&ch, w->buf, w->bufsize);
+		pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL);
         if (res == -EINTR)
             continue;
         if (res <= 0) {
@@ -121,6 +128,7 @@
     }
 
     sem_post(&mt->finish);
+	pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
     pause();
 
     return NULL;
@@ -131,6 +139,8 @@
     sigset_t oldset;
     sigset_t newset;
     int res;
+	pthread_attr_t attr;
+	char *stack_size;
     struct fuse_worker *w = malloc(sizeof(struct fuse_worker));
     if (!w) {
         fprintf(stderr, "fuse: failed to allocate worker structure\n");
@@ -146,6 +156,12 @@
         return -1;
     }
 
+	/* Override default stack size */
+	pthread_attr_init(&attr);
+	stack_size = getenv(ENVNAME_THREAD_STACK);
+	if (stack_size && pthread_attr_setstacksize(&attr, atoi(stack_size)))
+		fprintf(stderr, "fuse: invalid stack size: %s\n", stack_size);
+
     /* Disallow signal reception in worker threads */
     sigemptyset(&newset);
     sigaddset(&newset, SIGTERM);
@@ -153,10 +169,12 @@
     sigaddset(&newset, SIGHUP);
     sigaddset(&newset, SIGQUIT);
     pthread_sigmask(SIG_BLOCK, &newset, &oldset);
-    res = pthread_create(&w->thread_id, NULL, fuse_do_work, w);
+	res = pthread_create(&w->thread_id, &attr, fuse_do_work, w);
     pthread_sigmask(SIG_SETMASK, &oldset, NULL);
+	pthread_attr_destroy(&attr);
     if (res != 0) {
-        fprintf(stderr, "fuse: error creating thread: %s\n", strerror(res));
+		fprintf(stderr, "fuse: error creating thread: %s\n",
+			strerror(res));
         free(w->buf);
         free(w);
         return -1;
