tFreeBSD fixes (Lou Kamenov) - 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 143cdf575889feef82ed98a19df8761002d3895f
 (DIR) parent 8f8ef0c6a9752494a008d478be391ff915057c2e
 (HTM) Author: rsc <devnull@localhost>
       Date:   Wed, 26 Jul 2006 15:54:41 +0000
       
       FreeBSD fixes (Lou Kamenov)
       
       Diffstat:
         M src/cmd/9pfuse/fuse.c               |     137 ++++++++++++++++++++-----------
         M src/cmd/9pfuse/main.c               |      11 +++++++++--
       
       2 files changed, 97 insertions(+), 51 deletions(-)
       ---
 (DIR) diff --git a/src/cmd/9pfuse/fuse.c b/src/cmd/9pfuse/fuse.c
       t@@ -6,6 +6,9 @@ int fusebufsize;
        int fusemaxwrite;
        FuseMsg *fusemsglist;
        
       +int mountfuse(char *mtpt);
       +void unmountfuse(char *mtpt);
       +
        FuseMsg*
        allocfusemsg(void)
        {
       t@@ -58,10 +61,20 @@ readfusemsg(void)
                        return nil;
                }
                m->nbuf = n;
       +
       +        /*
       +         * FreeBSD FUSE sends a short length in the header
       +         * for FUSE_INIT even though the actual read length
       +         * is correct.
       +         */
       +        if(n == sizeof(*m->hdr)+sizeof(struct fuse_init_in)
       +        && m->hdr->opcode == FUSE_INIT && m->hdr->len < n)
       +                m->hdr->len = n;
       +
                if(m->hdr->len != n)
                        sysfatal("readfusemsg: got %d wanted %d",
                                n, m->hdr->len);
       -        m->hdr->len -= sizeof(m->hdr);
       +        m->hdr->len -= sizeof(*m->hdr);
                
                /*
                 * Paranoia.
       t@@ -246,54 +259,6 @@ replyfuseerrstr(FuseMsg *m)
                replyfuseerrno(m, errstr2errno());
        }
        
       -/*
       - * Mounts a fuse file system on mtpt and returns
       - * a file descriptor for the corresponding fuse 
       - * message conversation.
       - */
       -int
       -mountfuse(char *mtpt)
       -{
       -        int p[2], pid, fd;
       -        char buf[20];
       -        
       -        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);
       -                execlp("fusermount", "fusermount", "--", mtpt, nil);
       -                fprint(2, "exec fusermount: %r\n");
       -                _exit(1);
       -        }
       -        close(p[0]);
       -        fd = recvfd(p[1]);
       -        close(p[1]);
       -        waitpid();
       -        return fd;
       -}
       -
       -void
       -unmountfuse(char *mtpt)
       -{
       -        int pid;
       -        
       -        pid = fork();
       -        if(pid < 0)
       -                return;
       -        if(pid == 0){
       -                atexitdont(unmountatexit);
       -                execlp("fusermount", "fusermount", "-u", "-z", "--", mtpt, nil);
       -                fprint(2, "exec fusermount -u: %r\n");
       -                _exit(1);
       -        }
       -        waitpid();
       -}
       -
        char *fusemtpt;
        void
        unmountatexit(void)
       t@@ -770,3 +735,77 @@ fusefmt(Fmt *fmt)
                return 0;
        }
        
       +/*
       + * Mounts a fuse file system on mtpt and returns
       + * a file descriptor for the corresponding fuse 
       + * message conversation.
       + */
       +int
       +mountfuse(char *mtpt)
       +{
       +#if defined(__linux__)
       +        int p[2], pid, fd;
       +        char buf[20];
       +        
       +        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);
       +                execlp("fusermount", "fusermount", "--", mtpt, nil);
       +                fprint(2, "exec fusermount: %r\n");
       +                _exit(1);
       +        }
       +        close(p[0]);
       +        fd = recvfd(p[1]);
       +        close(p[1]);
       +        waitpid();
       +        return fd;
       +#elif defined(__FreeBSD__)
       +        int pid, fd;
       +        char buf[20];
       +        
       +        if((fd = open("/dev/fuse", ORDWR)) < 0)
       +                return -1;
       +        snprint(buf, sizeof buf, "%d", fd);
       +        
       +        pid = fork();
       +        if(pid < 0)
       +                return -1;
       +        if(pid == 0){
       +                execlp("mount_fusefs", "mount_fusefs", buf, mtpt, nil);
       +                fprint(2, "exec mount_fusefs: %r\n");
       +                _exit(1);
       +        }
       +        waitpid();
       +        return fd;
       +#else
       +        werrstr("cannot mount fuse on this system");
       +        return -1;
       +#endif
       +}
       +
       +void
       +unmountfuse(char *mtpt)
       +{
       +        int pid;
       +
       +        pid = fork();
       +        if(pid < 0)
       +                return;
       +        if(pid == 0){
       +#if defined(__linux__)
       +                execlp("fusermount", "fusermount", "-u", "-z", "--", mtpt, nil);
       +                fprint(2, "exec fusermount -u: %r\n");
       +#else
       +                execlp("umount", "umount", mtpt, nil);
       +                fprint(2, "exec umount: %r\n");
       +#endif
       +                _exit(1);
       +        }
       +        waitpid();
       +}
 (DIR) diff --git a/src/cmd/9pfuse/main.c b/src/cmd/9pfuse/main.c
       t@@ -689,7 +689,7 @@ fuseaccess(FuseMsg *m)
        {
                struct fuse_access_in *in;
                CFid *fid;
       -        int err;
       +        int err, omode;
                static int a2o[] = {
                        0,
                        OEXEC,
       t@@ -706,7 +706,14 @@ fuseaccess(FuseMsg *m)
                        replyfuseerrno(m, EINVAL);
                        return;
                }
       -        if((fid = _fuseopenfid(m->hdr->nodeid, 0, a2o[in->mask], &err)) == nil){
       +        omode = a2o[in->mask];
       +        if((fid = nodeid2fid(m->hdr->nodeid)) == nil){
       +                replyfuseerrno(m, ESTALE);
       +                return;
       +        }
       +        if(fsqid(fid).type&QTDIR)
       +                omode = OREAD;
       +        if((fid = _fuseopenfid(m->hdr->nodeid, 0, omode, &err)) == nil){
                        replyfuseerrno(m, err);
                        return;
                }