Add write buffer for tar writes

update fuse to 2.9.2

catch return from unlink so that we don't print error messages when things work
Change-Id: I1115039a0fa5d9d73f78ef1abd79755d7ffd9d96
diff --git a/fuse/helper.c b/fuse/helper.c
index 7b994fd..ace19dd 100644
--- a/fuse/helper.c
+++ b/fuse/helper.c
@@ -179,13 +179,37 @@
 
 int fuse_daemonize(int foreground)
 {
-	int res;
-
 	if (!foreground) {
-		res = daemon(0, 0);
-		if (res == -1) {
-			perror("fuse: failed to daemonize program\n");
+		int nullfd;
+
+		/*
+		 * demonize current process by forking it and killing the
+		 * parent.  This makes current process as a child of 'init'.
+		 */
+		switch(fork()) {
+		case -1:
+			perror("fuse_daemonize: fork");
 			return -1;
+		case 0:
+			break;
+		default:
+			_exit(0);
+		}
+
+		if (setsid() == -1) {
+			perror("fuse_daemonize: setsid");
+			return -1;
+		}
+
+		(void) chdir("/");
+
+		nullfd = open("/dev/null", O_RDWR, 0);
+		if (nullfd != -1) {
+			(void) dup2(nullfd, 0);
+			(void) dup2(nullfd, 1);
+			(void) dup2(nullfd, 2);
+			if (nullfd > 2)
+				close(nullfd);
 		}
 	}
 	return 0;
@@ -227,7 +251,8 @@
 {
 	int fd = ch ? fuse_chan_fd(ch) : -1;
 	fuse_kern_unmount(mountpoint, fd);
-	fuse_chan_destroy(ch);
+	if (ch)
+		fuse_chan_destroy(ch);
 }
 
 void fuse_unmount(const char *mountpoint, struct fuse_chan *ch)
@@ -324,11 +349,9 @@
 	if (fuse == NULL)
 		return 1;
 
-#ifdef __MULTI_THREAD
 	if (multithreaded)
 		res = fuse_loop_mt(fuse);
 	else
-#endif
 		res = fuse_loop(fuse);
 
 	fuse_teardown_common(fuse, mountpoint);
@@ -359,7 +382,7 @@
 
 #include "fuse_compat.h"
 
-#ifndef __FreeBSD__
+#if !defined(__FreeBSD__) && !defined(__NetBSD__)
 
 struct fuse *fuse_setup_compat22(int argc, char *argv[],
 				 const struct fuse_operations_compat22 *op,
@@ -417,7 +440,7 @@
 FUSE_SYMVER(".symver fuse_main_compat2,fuse_main@");
 FUSE_SYMVER(".symver fuse_main_real_compat22,fuse_main_real@FUSE_2.2");
 
-#endif /* __FreeBSD__ */
+#endif /* __FreeBSD__ || __NetBSD__ */
 
 
 struct fuse *fuse_setup_compat25(int argc, char *argv[],