t9pfuse: support MacFUSE >=4 - plan9port - [fork] Plan 9 from user space
 (HTM) git clone git://src.adamsgaard.dk/plan9port
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
 (DIR) LICENSE
       ---
 (DIR) commit f62d4c4143c9a21e488fca658590e1546700586f
 (DIR) parent a72478870ae66b7ac1e73b1d22b578cd31852f33
 (HTM) Author: Connor Taffe <connor.taffe@liveramp.com>
       Date:   Tue, 26 Jan 2021 15:14:18 -0600
       
       9pfuse: support MacFUSE >=4
       
       MacFUSE 4 removes support for passing device fd to the mount command. Adds
       support for the receiving the fd over a socket instead, and updates command paths
       and filesystem name.
       
       Diffstat:
         M src/cmd/9pfuse/fuse.c               |      31 ++++++++++++++++++++++++++++++-
       
       1 file changed, 30 insertions(+), 1 deletion(-)
       ---
 (DIR) diff --git a/src/cmd/9pfuse/fuse.c b/src/cmd/9pfuse/fuse.c
       t@@ -798,16 +798,19 @@ mountfuse(char *mtpt)
                }
                return fd;
        #elif defined(__APPLE__)
       -        int i, pid, fd, r;
       +        int i, pid, fd, r, p[2];
                char buf[20];
                struct vfsconf vfs;
                char *f, *v;
        
                if(getvfsbyname(v="osxfusefs", &vfs) < 0 &&
       +           getvfsbyname(v="macfuse", &vfs) < 0 &&
                   getvfsbyname(v="osxfuse", &vfs) < 0 &&
                   getvfsbyname(v="fusefs", &vfs) < 0){
                        if(access((v="osxfusefs", f="/Library/Filesystems/osxfusefs.fs"
                                "/Support/load_osxfusefs"), 0) < 0 &&
       +                   access((v="macfuse", f="/Library/Filesystems/macfuse.fs"
       +                        "/Contents/Resources/load_macfuse"), 0) < 0 &&
                           access((v="osxfuse", f="/Library/Filesystems/osxfuse.fs"
                                "/Contents/Resources/load_osxfuse"), 0) < 0 &&
                           access((v="osxfuse", f="/opt/local/Library/Filesystems/osxfuse.fs"
       t@@ -837,6 +840,32 @@ mountfuse(char *mtpt)
                        }
                }
        
       +        /* MacFUSE >=4 dropped support for passing fd */
       +        if (strcmp(v, "macfuse") == 0) {
       +                if(socketpair(AF_UNIX, SOCK_STREAM, 0, p) < 0)
       +                        return -1;
       +                pid = fork();
       +                if(pid < 0)
       +                        return -1;
       +                if(pid == 0){
       +                        close(p[1]);
       +                        snprint(buf, sizeof buf, "%d", p[0]);
       +                        putenv("_FUSE_COMMFD", buf);
       +                        putenv("_FUSE_COMMVERS", "2");
       +                        putenv("_FUSE_CALL_BY_LIB", "1");
       +                        putenv("_FUSE_DAEMON_PATH",
       +                                "/Library/Filesystems/macfuse.fs/Contents/Resources/mount_macfus");
       +                        execl("/Library/Filesystems/macfuse.fs/Contents/Resources/mount_macfuse",
       +                                "mount_macfuse", mtpt, nil);
       +                        fprint(2, "exec mount_macfuse: %r\n");
       +                        _exit(1);
       +                }
       +                close(p[0]);
       +                fd = recvfd(p[1]);
       +                close(p[1]);
       +                return fd;
       +        }
       +
                /* Look for available FUSE device. */
                /*
                 * We need to truncate `fs` from the end of the vfs name if