aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/9pfuse
diff options
context:
space:
mode:
authorrsc <devnull@localhost>2006-07-26 15:54:41 +0000
committerrsc <devnull@localhost>2006-07-26 15:54:41 +0000
commit143cdf575889feef82ed98a19df8761002d3895f (patch)
tree9ad08a0def21c2f509df025b62aeec6f2043d579 /src/cmd/9pfuse
parent8f8ef0c6a9752494a008d478be391ff915057c2e (diff)
downloadplan9port-143cdf575889feef82ed98a19df8761002d3895f.tar.gz
plan9port-143cdf575889feef82ed98a19df8761002d3895f.tar.bz2
plan9port-143cdf575889feef82ed98a19df8761002d3895f.zip
FreeBSD fixes (Lou Kamenov)
Diffstat (limited to 'src/cmd/9pfuse')
-rw-r--r--src/cmd/9pfuse/fuse.c137
-rw-r--r--src/cmd/9pfuse/main.c11
2 files changed, 97 insertions, 51 deletions
diff --git a/src/cmd/9pfuse/fuse.c b/src/cmd/9pfuse/fuse.c
index 0e61f72f..5c071ab4 100644
--- a/src/cmd/9pfuse/fuse.c
+++ b/src/cmd/9pfuse/fuse.c
@@ -6,6 +6,9 @@ int fusebufsize;
int fusemaxwrite;
FuseMsg *fusemsglist;
+int mountfuse(char *mtpt);
+void unmountfuse(char *mtpt);
+
FuseMsg*
allocfusemsg(void)
{
@@ -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.
@@ -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)
@@ -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();
+}
diff --git a/src/cmd/9pfuse/main.c b/src/cmd/9pfuse/main.c
index f0a9efae..5a2ef8f6 100644
--- a/src/cmd/9pfuse/main.c
+++ b/src/cmd/9pfuse/main.c
@@ -689,7 +689,7 @@ fuseaccess(FuseMsg *m)
{
struct fuse_access_in *in;
CFid *fid;
- int err;
+ int err, omode;
static int a2o[] = {
0,
OEXEC,
@@ -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;
}