2 * 9P to FUSE translator. Acts as FUSE server, 9P client.
3 * Mounts 9P servers via FUSE kernel module.
5 * There are four procs in this threaded program
6 * (ignoring the one that runs main and then exits).
7 * The first proc reads FUSE requests from /dev/fuse.
8 * It sends the requests over a channel to a second proc,
9 * which serves the requests. Each request runs in a
10 * thread in that second proc. Those threads do write
11 * FUSE replies, which in theory might block, but in practice don't.
12 * The 9P interactions are handled by lib9pclient, which
13 * allocates two more procs, one for reading and one for
14 * writing the 9P connection. Thus the many threads in the
15 * request proc can do 9P interactions without blocking.
18 #define _GNU_SOURCE 1 /* for O_DIRECTORY on Linux */
27 # define O_LARGEFILE 0
31 * Work around glibc's broken <bits/fcntl.h> which defines
32 * O_LARGEFILE to 0 on 64 bit architectures. But, on those same
33 * architectures, linux _forces_ O_LARGEFILE (which is always
34 * 0100000 in the kernel) at each file open. FUSE is all too
35 * happy to pass the flag onto us, where we'd have no idea what
36 * to do with it if we trusted glibc.
38 * On ARM however, the O_LARGEFILE is set correctly.
41 #if defined(__linux__) && !defined(__arm__)
43 # define O_LARGEFILE 0100000
47 # if defined(__linux__)
48 # define O_CLOEXEC 02000000 /* Sigh */
55 # if defined(__linux__)
56 # define FMODE_EXEC 040
65 void fusedispatch(void*);
74 * The number of seconds that the kernel can cache
75 * returned file attributes. FUSE's default is 1.0.
76 * I haven't experimented with using 0.
78 double attrtimeout = 1.0;
81 * The number of seconds that the kernel can cache
82 * the returned entry nodeids returned by lookup.
83 * I haven't experimented with other values.
85 double entrytimeout = 1.0;
89 void init9p(char*, char*);
94 fprint(2, "usage: 9pfuse [-D] [-A attrtimeout] [-a aname] address mtpt\n");
98 void fusereader(void*);
102 threadmaybackground(void)
108 threadmain(int argc, char **argv)
116 attrtimeout = atof(EARGF(usage()));
119 aname = EARGF(usage());
129 fmtinstall('F', fcallfmt);
130 fmtinstall('M', dirmodefmt);
131 fmtinstall('G', fusefmt);
133 setsid(); /* won't be able to use console, but can't be interrupted */
135 init9p(argv[0], aname);
138 fusechan = chancreate(sizeof(void*), 0);
139 proccreate(fusedispatch, nil, STACK);
140 sendp(fusechan, nil); /* sync */
142 proccreate(fusereader, nil, STACK);
144 * Now that we're serving FUSE, we can wait
145 * for the mount to finish and exit back to the user.
156 while((m = readfusemsg()) != nil)
159 fusemtpt = nil; /* no need to unmount */
164 init9p(char *addr, char *spec)
168 if(strcmp(addr, "-") == 0)
171 if((fd = dial(netmkaddr(addr, "tcp", "564"), nil, nil, nil)) < 0)
172 sysfatal("dial %s: %r", addr);
173 proccreate(watchfd, (void*)(uintptr)fd, STACK);
174 if((fsys = fsmount(fd, spec)) == nil)
175 sysfatal("fsmount: %r");
176 fsysroot = fsroot(fsys);
180 * FUSE uses nodeids to refer to active "struct inodes"
181 * (9P's unopened fids). FUSE uses fhs to refer to active
182 * "struct fuse_files" (9P's opened fids). The choice of
183 * numbers is up to us except that nodeid 1 is the root directory.
184 * We use the same number space for both and call the
185 * bookkeeping structure a FuseFid.
187 * FUSE requires nodeids to have associated generation
188 * numbers. If we reuse a nodeid, we have to bump the
189 * generation number to guarantee that the nodeid,gen
190 * combination is never reused.
192 * There are also inode numbers returned in directory reads
193 * and file attributes, but these do NOT need to match the nodeids.
194 * We use a combination of qid.path and qid.type as the inode
198 * TO DO: reference count the fids.
200 typedef struct Fusefid Fusefid;
210 /* directory read state */
219 Fusefid *freefusefidlist;
226 if((f = freefusefidlist) == nil){
227 f = emalloc(sizeof *f);
228 fusefid = erealloc(fusefid, (nfusefid+1)*sizeof *fusefid);
233 freefusefidlist = f->next;
241 freefusefid(Fusefid *f)
255 f->next = freefusefidlist;
261 _alloc(CFid *fid, int isnodeid)
267 ff->isnodeid = isnodeid;
269 return ff->id+2; /* skip 0 and 1 */
275 return _alloc(fid, 0);
279 allocnodeid(CFid *fid)
281 return _alloc(fid, 1);
285 lookupfusefid(uvlong id, int isnodeid)
288 if(id < 2 || id >= nfusefid+2)
290 ff = fusefid[(int)id-2];
291 if(ff->isnodeid != isnodeid)
297 _lookupcfid(uvlong id, int isnodeid)
301 if((ff = lookupfusefid(id, isnodeid)) == nil)
309 return _lookupcfid(fh, 0);
313 nodeid2fid(uvlong nodeid)
317 return _lookupcfid(nodeid, 1);
323 return q.path | ((uvlong)q.type<<56);
327 dir2attr(Dir *d, struct fuse_attr *attr)
329 attr->ino = qid2inode(d->qid);
330 attr->size = d->length;
331 attr->blocks = (d->length+8191)/8192;
332 attr->atime = d->atime;
333 attr->mtime = d->mtime;
334 attr->ctime = d->mtime; /* not right */
338 attr->mode = d->mode&0777;
340 attr->mode |= S_IFDIR;
341 else if(d->mode&DMSYMLINK)
342 attr->mode |= S_IFLNK;
344 attr->mode |= S_IFREG;
345 attr->nlink = 1; /* works for directories! - see FUSE FAQ */
346 attr->uid = getuid();
347 attr->gid = getgid();
352 f2timeout(double f, __u64 *s, __u32 *ns)
355 *ns = (f - (int)f)*1e9;
359 dir2attrout(Dir *d, struct fuse_attr_out *out)
361 f2timeout(attrtimeout, &out->attr_valid, &out->attr_valid_nsec);
362 dir2attr(d, &out->attr);
366 * Lookup. Walk to the name given as the argument.
367 * The response is a fuse_entry_out giving full stat info.
370 fuselookup(FuseMsg *m)
376 struct fuse_entry_out out;
379 if((fid = nodeid2fid(m->hdr->nodeid)) == nil){
380 replyfuseerrno(m, ESTALE);
383 if(strchr(name, '/')){
384 replyfuseerrno(m, ENOENT);
387 if((newfid = fswalk(fid, name)) == nil){
391 if((d = fsdirfstat(newfid)) == nil){
396 out.nodeid = allocnodeid(newfid);
397 ff = lookupfusefid(out.nodeid, 1);
398 out.generation = ff->gen;
399 f2timeout(attrtimeout, &out.attr_valid, &out.attr_valid_nsec);
400 f2timeout(entrytimeout, &out.entry_valid, &out.entry_valid_nsec);
401 dir2attr(d, &out.attr);
403 replyfuse(m, &out, sizeof out);
407 * Forget. Reference-counted clunk for nodeids.
408 * Does not send a reply.
409 * Each lookup response gives the kernel an additional reference
410 * to the returned nodeid. Forget says "drop this many references
411 * to this nodeid". Our fuselookup, when presented with the same query,
412 * does not return the same results (it allocates a new nodeid for each
413 * call), but if that ever changes, fuseforget already handles the ref
417 fuseforget(FuseMsg *m)
419 struct fuse_forget_in *in;
423 if((ff = lookupfusefid(m->hdr->nodeid, 1)) == nil)
425 if(ff->ref > in->nlookup){
426 ff->ref -= in->nlookup;
429 if(ff->ref < in->nlookup)
430 fprint(2, "bad count in forget\n");
438 * Replies with a fuse_attr_out structure giving the
439 * attr for the requested nodeid in out.attr.
440 * Out.attr_valid and out.attr_valid_nsec give
441 * the amount of time that the attributes can
444 * Empirically, though, if I run ls -ld on the root
445 * twice back to back, I still get two getattrs,
446 * even with a one second attribute timeout!
449 fusegetattr(FuseMsg *m)
452 struct fuse_attr_out out;
455 if((fid = nodeid2fid(m->hdr->nodeid)) == nil){
456 replyfuseerrno(m, ESTALE);
459 if((d = fsdirfstat(fid)) == nil){
463 memset(&out, 0, sizeof out);
464 dir2attrout(d, &out);
466 replyfuse(m, &out, sizeof out);
471 * FUSE treats the many Unix attribute setting routines
472 * more or less like 9P does, with a single message.
475 fusesetattr(FuseMsg *m)
479 struct fuse_setattr_in *in;
480 struct fuse_attr_out out;
483 if(in->valid&FATTR_FH){
484 if((fid = fh2fid(in->fh)) == nil){
485 replyfuseerrno(m, ESTALE);
489 if((fid = nodeid2fid(m->hdr->nodeid)) == nil){
490 replyfuseerrno(m, ESTALE);
494 * Special case: Linux issues a size change to
495 * truncate a file before opening it OTRUNC.
496 * Synthetic file servers (e.g., plumber) honor
497 * open(OTRUNC) but not wstat.
499 if(in->valid == FATTR_SIZE && in->size == 0){
500 if((nfid = fswalk(fid, nil)) == nil){
504 if(fsfopen(nfid, OWRITE|OTRUNC) < 0){
515 if(in->valid&FATTR_SIZE)
517 if(in->valid&FATTR_ATIME)
519 if(in->valid&FATTR_MTIME)
521 if(in->valid&FATTR_MODE)
522 d.mode = in->mode & 0777;
523 if((in->mode&S_IFMT) == S_IFDIR)
525 if((in->valid&FATTR_UID) || (in->valid&FATTR_GID)){
527 * I can't be bothered with these yet.
529 replyfuseerrno(m, EPERM);
532 if(fsdirfwstat(fid, &d) < 0){
537 if((dd = fsdirfstat(fid)) == nil){
541 memset(&out, 0, sizeof out);
542 dir2attrout(dd, &out);
544 replyfuse(m, &out, sizeof out);
548 _fuseopenfid(uvlong nodeid, int isdir, int openmode, int *err)
552 if((fid = nodeid2fid(nodeid)) == nil){
556 if(isdir && !(fsqid(fid).type&QTDIR)){
560 if(openmode != OREAD && fsqid(fid).type&QTDIR){
565 /* Clone fid to get one we can open. */
566 newfid = fswalk(fid, nil);
568 *err = errstr2errno();
572 if(fsfopen(newfid, openmode) < 0){
573 *err = errstr2errno();
583 * Argument is a struct fuse_open_in.
584 * The mode field is ignored (presumably permission bits)
585 * and flags is the open mode.
586 * Replies with a struct fuse_open_out.
589 _fuseopen(FuseMsg *m, int isdir)
591 struct fuse_open_in *in;
592 struct fuse_open_out out;
594 int openmode, flags, err;
600 flags &= ~(O_DIRECTORY|O_NONBLOCK|O_LARGEFILE|O_CLOEXEC|FMODE_EXEC);
602 flags &= ~O_NOFOLLOW;
605 flags &= ~O_LARGEFILE;
609 * Discarding O_APPEND here is not completely wrong,
610 * because the host kernel will rewrite the offsets
611 * of write system calls for us. That's the best we
612 * can do on Unix anyway.
621 * Could translate but not standard 9P:
622 * O_DIRECT -> ODIRECT
623 * O_NONBLOCK -> ONONBLOCK
626 fprint(2, "unexpected open flags requested=%#uo unhandled=%#uo\n", (uint)in->flags, (uint)flags);
627 replyfuseerrno(m, EACCES);
630 if((fid = _fuseopenfid(m->hdr->nodeid, isdir, openmode, &err)) == nil){
631 replyfuseerrno(m, err);
634 out.fh = allocfh(fid);
635 out.open_flags = FOPEN_DIRECT_IO; /* no page cache */
636 replyfuse(m, &out, sizeof out);
646 fuseopendir(FuseMsg *m)
655 _fusecreate(uvlong nodeid, char *name, int perm, int ismkdir, int omode, struct fuse_entry_out *out, int *err)
657 CFid *fid, *newfid, *newfid2;
661 if((fid = nodeid2fid(nodeid)) == nil){
668 if(ismkdir && omode != OREAD){
672 if((newfid = fswalk(fid, nil)) == nil){
673 *err = errstr2errno();
676 if(fsfcreate(newfid, name, omode, perm) < 0){
677 *err = errstr2errno();
681 if((d = fsdirfstat(newfid)) == nil){
682 *err = errstr2errno();
687 * This fid is no good, because it's open.
688 * We need an unopened fid. Sigh.
690 if((newfid2 = fswalk(fid, name)) == nil){
691 *err = errstr2errno();
696 out->nodeid = allocnodeid(newfid2);
697 ff = lookupfusefid(out->nodeid, 1);
698 out->generation = ff->gen;
699 f2timeout(attrtimeout, &out->attr_valid, &out->attr_valid_nsec);
700 f2timeout(entrytimeout, &out->entry_valid, &out->entry_valid_nsec);
701 dir2attr(d, &out->attr);
707 fusemkdir(FuseMsg *m)
709 struct fuse_mkdir_in *in;
710 struct fuse_entry_out out;
716 name = (char*)(in+1);
717 if((fid = _fusecreate(m->hdr->nodeid, name, in->mode, 1, OREAD, &out, &err)) == nil){
718 replyfuseerrno(m, err);
721 /* Toss the open fid. */
723 replyfuse(m, &out, sizeof out);
727 fusecreate(FuseMsg *m)
729 struct fuse_open_in *in;
730 struct fuse_create_out out;
732 int err, openmode, flags;
737 openmode = in->flags&3;
739 flags &= ~(O_DIRECTORY|O_NONBLOCK|O_LARGEFILE|O_EXCL);
740 flags &= ~O_APPEND; /* see comment in _fuseopen */
741 flags &= ~(O_CREAT|O_TRUNC); /* huh? */
743 fprint(2, "bad mode %#uo\n", in->flags);
744 replyfuseerrno(m, EACCES);
747 name = (char*)(in+1);
748 if((fid = _fusecreate(m->hdr->nodeid, name, in->mode, 0, openmode, &out.e, &err)) == nil){
749 replyfuseerrno(m, err);
752 out.o.fh = allocfh(fid);
753 out.o.open_flags = FOPEN_DIRECT_IO; /* no page cache */
754 replyfuse(m, &out, sizeof out);
759 * Lib9pclient implements this just as Plan 9 does,
760 * by opening the file (or not) and then closing it.
763 fuseaccess(FuseMsg *m)
765 struct fuse_access_in *in;
780 if(in->mask >= nelem(a2o)){
781 replyfuseerrno(m, EINVAL);
784 omode = a2o[in->mask];
785 if((fid = nodeid2fid(m->hdr->nodeid)) == nil){
786 replyfuseerrno(m, ESTALE);
789 if(fsqid(fid).type&QTDIR)
791 if((fid = _fuseopenfid(m->hdr->nodeid, 0, omode, &err)) == nil){
792 replyfuseerrno(m, err);
796 replyfuse(m, nil, 0);
801 * Equivalent of clunk for file handles.
802 * in->flags is the open mode used in Open or Opendir.
805 fuserelease(FuseMsg *m)
807 struct fuse_release_in *in;
811 if((ff = lookupfusefid(in->fh, 0)) != nil)
814 fprint(2, "fuserelease: fh not found\n");
815 replyfuse(m, nil, 0);
819 fusereleasedir(FuseMsg *m)
826 * Read from file handle in->fh at offset in->offset for size in->size.
827 * We truncate size to maxwrite just to keep the buffer reasonable.
835 struct fuse_read_in *in;
838 if((fid = fh2fid(in->fh)) == nil){
839 replyfuseerrno(m, ESTALE);
846 n = fspread(fid, buf, n, in->offset);
852 replyfuse(m, buf, n);
860 fusereadlink(FuseMsg *m)
865 if((fid = nodeid2fid(m->hdr->nodeid)) == nil){
866 replyfuseerrno(m, ESTALE);
869 if((d = fsdirfstat(fid)) == nil){
873 if(!(d->mode&DMSYMLINK)){
874 replyfuseerrno(m, EINVAL);
877 replyfuse(m, d->ext, strlen(d->ext));
884 * Read from file handle in->fh at offset in->offset for size in->size.
885 * We truncate size to maxwrite just to keep the buffer reasonable.
886 * We assume 9P directory read semantics: a read at offset 0 rewinds
887 * and a read at any other offset starts where we left off.
888 * If it became necessary, we could implement a crude seek
889 * or cache the entire list of directory entries.
890 * Directory entries read from 9P but not yet handed to FUSE
891 * are stored in m->d,nd,d0.
893 int canpack(Dir*, uvlong, uchar**, uchar*);
896 fusereaddir(FuseMsg *m)
898 struct fuse_read_in *in;
904 if((ff = lookupfusefid(in->fh, 0)) == nil){
905 replyfuseerrno(m, ESTALE);
909 fsseek(ff->fid, 0, 0);
911 ff->d0 = ff->d = dotdir(ff->fid);
922 if(!canpack(ff->d, ff->off, &p, ep))
931 if((ff->nd = fsdirread(ff->fid, &ff->d0)) < 0){
941 replyfuse(m, buf, p - buf);
946 * Fuse assumes that it can always read two directory entries.
947 * If it gets just one, it will double it in the dirread results.
948 * Thus if a directory contains just "a", you see "a" twice.
949 * Adding . as the first directory entry works around this.
950 * We could add .. too, but it isn't necessary.
957 d = emalloc(1*sizeof *d);
964 canpack(Dir *d, uvlong off, uchar **pp, uchar *ep)
967 struct fuse_dirent *de;
971 size = FUSE_NAME_OFFSET + strlen(d->name);
975 if(size+pad > ep - p)
977 de = (struct fuse_dirent*)p;
978 de->ino = qid2inode(d->qid);
980 de->namelen = strlen(d->name);
981 memmove(de->name, d->name, de->namelen);
983 memset(de->name+de->namelen, 0, pad);
990 * Write from file handle in->fh at offset in->offset for size in->size.
991 * Don't know what in->write_flags means.
993 * Apparently implementations are allowed to buffer these writes
994 * and wait until Flush is sent, but FUSE docs say flush may be
995 * called zero, one, or even more times per close. So better do the
996 * actual writing here. Also, errors that happen during Flush just
997 * show up in the close() return status, which no one checks anyway.
1000 fusewrite(FuseMsg *m)
1002 struct fuse_write_in *in;
1003 struct fuse_write_out out;
1010 if((fid = fh2fid(in->fh)) == nil){
1011 replyfuseerrno(m, ESTALE);
1014 if(in->size > fusemaxwrite){
1015 replyfuseerrno(m, EINVAL);
1018 n = fspwrite(fid, a, in->size, in->offset);
1024 replyfuse(m, &out, sizeof out);
1028 * Flush. Supposed to flush any buffered writes. Don't use this.
1030 * Flush is a total crock. It gets called on close() of a file descriptor
1031 * associated with this open file. Some open files have multiple file
1032 * descriptors and thus multiple closes of those file descriptors.
1033 * In those cases, Flush is called multiple times. Some open files
1034 * have file descriptors that are closed on process exit instead of
1035 * closed explicitly. For those files, Flush is never called.
1036 * Even more amusing, Flush gets called before close() of read-only
1037 * file descriptors too!
1039 * This is just a bad idea.
1042 fuseflush(FuseMsg *m)
1044 replyfuse(m, nil, 0);
1051 _fuseremove(FuseMsg *m, int isdir)
1057 if((fid = nodeid2fid(m->hdr->nodeid)) == nil){
1058 replyfuseerrno(m, ESTALE);
1061 if(strchr(name, '/')){
1062 replyfuseerrno(m, ENOENT);
1065 if((newfid = fswalk(fid, name)) == nil){
1069 if(isdir && !(fsqid(newfid).type&QTDIR)){
1070 replyfuseerrno(m, ENOTDIR);
1074 if(!isdir && (fsqid(newfid).type&QTDIR)){
1075 replyfuseerrno(m, EISDIR);
1079 if(fsfremove(newfid) < 0){
1083 replyfuse(m, nil, 0);
1087 fuseunlink(FuseMsg *m)
1093 fusermdir(FuseMsg *m)
1101 * FUSE sends the nodeid for the source and destination
1102 * directory and then the before and after names as strings.
1103 * 9P can only do the rename if the source and destination
1104 * are the same. If the same nodeid is used for source and
1105 * destination, we're fine, but if FUSE gives us different nodeids
1106 * that happen to correspond to the same directory, we have
1107 * no way of figuring that out. Let's hope it doesn't happen too often.
1110 fuserename(FuseMsg *m)
1112 struct fuse_rename_in *in;
1113 char *before, *after;
1118 if(in->newdir != m->hdr->nodeid){
1119 replyfuseerrno(m, EXDEV);
1122 before = (char*)(in+1);
1123 after = before + strlen(before) + 1;
1124 if((fid = nodeid2fid(m->hdr->nodeid)) == nil){
1125 replyfuseerrno(m, ESTALE);
1128 if(strchr(before, '/') || strchr(after, '/')){
1129 replyfuseerrno(m, ENOENT);
1132 if((newfid = fswalk(fid, before)) == nil){
1138 if(fsdirfwstat(newfid, &d) < 0){
1144 replyfuse(m, nil, 0);
1148 * Fsync. Commit file info to stable storage.
1149 * Not sure what in->fsync_flags are.
1152 fusefsync(FuseMsg *m)
1154 struct fuse_fsync_in *in;
1159 if((fid = fh2fid(in->fh)) == nil){
1160 replyfuseerrno(m, ESTALE);
1164 if(fsdirfwstat(fid, &d) < 0){
1168 replyfuse(m, nil, 0);
1172 * Fsyncdir. Commit dir info to stable storage?
1175 fusefsyncdir(FuseMsg *m)
1181 * Statfs. Send back information about file system.
1182 * Not really worth implementing, except that if we
1183 * reply with ENOSYS, programs like df print messages like
1184 * df: `/tmp/z': Function not implemented
1185 * and that gets annoying. Returning all zeros excludes
1186 * us from df without appearing to cause any problems.
1189 fusestatfs(FuseMsg *m)
1191 struct fuse_statfs_out out;
1193 memset(&out, 0, sizeof out);
1194 replyfuse(m, &out, sizeof out);
1197 void (*fusehandlers[100])(FuseMsg*);
1201 void (*fn)(FuseMsg*);
1203 { FUSE_LOOKUP, fuselookup },
1204 { FUSE_FORGET, fuseforget },
1205 { FUSE_GETATTR, fusegetattr },
1206 { FUSE_SETATTR, fusesetattr },
1208 * FUSE_SYMLINK, FUSE_MKNOD are unimplemented.
1210 { FUSE_READLINK, fusereadlink },
1211 { FUSE_MKDIR, fusemkdir },
1212 { FUSE_UNLINK, fuseunlink },
1213 { FUSE_RMDIR, fusermdir },
1214 { FUSE_RENAME, fuserename },
1216 * FUSE_LINK is unimplemented.
1218 { FUSE_OPEN, fuseopen },
1219 { FUSE_READ, fuseread },
1220 { FUSE_WRITE, fusewrite },
1221 { FUSE_STATFS, fusestatfs },
1222 { FUSE_RELEASE, fuserelease },
1223 { FUSE_FSYNC, fusefsync },
1225 * FUSE_SETXATTR, FUSE_GETXATTR, FUSE_LISTXATTR, and
1226 * FUSE_REMOVEXATTR are unimplemented.
1227 * FUSE will stop sending these requests after getting
1228 * an -ENOSYS reply (see dispatch below).
1230 { FUSE_FLUSH, fuseflush },
1232 * FUSE_INIT is handled in initfuse and should not be seen again.
1234 { FUSE_OPENDIR, fuseopendir },
1235 { FUSE_READDIR, fusereaddir },
1236 { FUSE_RELEASEDIR, fusereleasedir },
1237 { FUSE_FSYNCDIR, fusefsyncdir },
1238 { FUSE_ACCESS, fuseaccess },
1239 { FUSE_CREATE, fusecreate },
1248 if((uint)m->hdr->opcode >= nelem(fusehandlers)
1249 || !fusehandlers[m->hdr->opcode]){
1250 replyfuseerrno(m, ENOSYS);
1253 fusehandlers[m->hdr->opcode](m);
1257 fusedispatch(void *v)
1262 eofkill9pclient = 1; /* threadexitsall on 9P eof */
1263 atexit(unmountatexit);
1265 recvp(fusechan); /* sync */
1267 for(i=0; i<nelem(fuselist); i++){
1268 if(fuselist[i].op >= nelem(fusehandlers))
1269 sysfatal("make fusehandlers bigger op=%d", fuselist[i].op);
1270 fusehandlers[fuselist[i].op] = fuselist[i].fn;
1273 while((m = recvp(fusechan)) != nil) {
1274 switch(m->hdr->opcode) {
1276 fusehandlers[m->hdr->opcode](m);
1279 threadcreate(fusethread, m, STACK);
1291 sysfatal("malloc(%d): %r", n);
1297 erealloc(void *p, uint n)
1301 sysfatal("realloc(..., %d): %r", n);
1311 sysfatal("strdup(%.20s): %r", p);
1318 int fd = (int)(uintptr)v;
1320 /* wait for exception (file closed) */
1324 if(select(fd+1, NULL, NULL, &set, NULL) >= 0)
1325 threadexitsall(nil);