FreeBSD fixes (Lou Kamenov)

This commit is contained in:
rsc 2006-07-26 15:54:41 +00:00
parent 8f8ef0c6a9
commit 143cdf5758
2 changed files with 97 additions and 51 deletions

View file

@ -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();
}

View file

@ -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;
}