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 #if defined(__linux__)
40 # define O_LARGEFILE 0100000
44 # if defined(__linux__)
45 # define O_CLOEXEC 02000000 /* Sigh */
54 void fusedispatch(void*);
63 * The number of seconds that the kernel can cache
64 * returned file attributes. FUSE's default is 1.0.
65 * I haven't experimented with using 0.
67 double attrtimeout = 1.0;
70 * The number of seconds that the kernel can cache
71 * the returned entry nodeids returned by lookup.
72 * I haven't experimented with other values.
74 double entrytimeout = 1.0;
78 void init9p(char*, char*);
83 fprint(2, "usage: 9pfuse [-D] [-A attrtimeout] [-a aname] address mtpt\n");
87 void fusereader(void*);
91 threadmain(int argc, char **argv)
99 attrtimeout = atof(EARGF(usage()));
102 aname = EARGF(usage());
112 fmtinstall('F', fcallfmt);
113 fmtinstall('M', dirmodefmt);
114 fmtinstall('G', fusefmt);
116 setsid(); /* won't be able to use console, but can't be interrupted */
118 init9p(argv[0], aname);
121 fusechan = chancreate(sizeof(void*), 0);
122 proccreate(fusedispatch, nil, STACK);
123 sendp(fusechan, nil); /* sync */
125 proccreate(fusereader, nil, STACK);
127 * Now that we're serving FUSE, we can wait
128 * for the mount to finish and exit back to the user.
139 while((m = readfusemsg()) != nil)
142 fusemtpt = nil; /* no need to unmount */
147 init9p(char *addr, char *spec)
151 if(strcmp(addr, "-") == 0)
154 if((fd = dial(netmkaddr(addr, "tcp", "564"), nil, nil, nil)) < 0)
155 sysfatal("dial %s: %r", addr);
156 proccreate(watchfd, (void*)(uintptr)fd, STACK);
157 if((fsys = fsmount(fd, spec)) == nil)
158 sysfatal("fsmount: %r");
159 fsysroot = fsroot(fsys);
163 * FUSE uses nodeids to refer to active "struct inodes"
164 * (9P's unopened fids). FUSE uses fhs to refer to active
165 * "struct fuse_files" (9P's opened fids). The choice of
166 * numbers is up to us except that nodeid 1 is the root directory.
167 * We use the same number space for both and call the
168 * bookkeeping structure a FuseFid.
170 * FUSE requires nodeids to have associated generation
171 * numbers. If we reuse a nodeid, we have to bump the
172 * generation number to guarantee that the nodeid,gen
173 * combination is never reused.
175 * There are also inode numbers returned in directory reads
176 * and file attributes, but these do NOT need to match the nodeids.
177 * We use a combination of qid.path and qid.type as the inode
181 * TO DO: reference count the fids.
183 typedef struct Fusefid Fusefid;
193 /* directory read state */
202 Fusefid *freefusefidlist;
209 if((f = freefusefidlist) == nil){
210 f = emalloc(sizeof *f);
211 fusefid = erealloc(fusefid, (nfusefid+1)*sizeof *fusefid);
216 freefusefidlist = f->next;
224 freefusefid(Fusefid *f)
238 f->next = freefusefidlist;
244 _alloc(CFid *fid, int isnodeid)
250 ff->isnodeid = isnodeid;
252 return ff->id+2; /* skip 0 and 1 */
258 return _alloc(fid, 0);
261 allocnodeid(CFid *fid)
263 return _alloc(fid, 1);
267 lookupfusefid(uvlong id, int isnodeid)
270 if(id < 2 || id >= nfusefid+2)
272 ff = fusefid[(int)id-2];
273 if(ff->isnodeid != isnodeid)
279 _lookupcfid(uvlong id, int isnodeid)
283 if((ff = lookupfusefid(id, isnodeid)) == nil)
291 return _lookupcfid(fh, 0);
295 nodeid2fid(uvlong nodeid)
299 return _lookupcfid(nodeid, 1);
305 return q.path | ((uvlong)q.type<<56);
309 dir2attr(Dir *d, struct fuse_attr *attr)
311 attr->ino = qid2inode(d->qid);
312 attr->size = d->length;
313 attr->blocks = (d->length+8191)/8192;
314 attr->atime = d->atime;
315 attr->mtime = d->mtime;
316 attr->ctime = d->mtime; /* not right */
320 attr->mode = d->mode&0777;
322 attr->mode |= S_IFDIR;
323 else if(d->mode&DMSYMLINK)
324 attr->mode |= S_IFLNK;
326 attr->mode |= S_IFREG;
327 attr->nlink = 1; /* works for directories! - see FUSE FAQ */
328 attr->uid = getuid();
329 attr->gid = getgid();
334 f2timeout(double f, __u64 *s, __u32 *ns)
337 *ns = (f - (int)f)*1e9;
341 dir2attrout(Dir *d, struct fuse_attr_out *out)
343 f2timeout(attrtimeout, &out->attr_valid, &out->attr_valid_nsec);
344 dir2attr(d, &out->attr);
348 * Lookup. Walk to the name given as the argument.
349 * The response is a fuse_entry_out giving full stat info.
352 fuselookup(FuseMsg *m)
358 struct fuse_entry_out out;
361 if((fid = nodeid2fid(m->hdr->nodeid)) == nil){
362 replyfuseerrno(m, ESTALE);
365 if(strchr(name, '/')){
366 replyfuseerrno(m, ENOENT);
369 if((newfid = fswalk(fid, name)) == nil){
373 if((d = fsdirfstat(newfid)) == nil){
378 out.nodeid = allocnodeid(newfid);
379 ff = lookupfusefid(out.nodeid, 1);
380 out.generation = ff->gen;
381 f2timeout(attrtimeout, &out.attr_valid, &out.attr_valid_nsec);
382 f2timeout(entrytimeout, &out.entry_valid, &out.entry_valid_nsec);
383 dir2attr(d, &out.attr);
385 replyfuse(m, &out, sizeof out);
389 * Forget. Reference-counted clunk for nodeids.
390 * Does not send a reply.
391 * Each lookup response gives the kernel an additional reference
392 * to the returned nodeid. Forget says "drop this many references
393 * to this nodeid". Our fuselookup, when presented with the same query,
394 * does not return the same results (it allocates a new nodeid for each
395 * call), but if that ever changes, fuseforget already handles the ref
399 fuseforget(FuseMsg *m)
401 struct fuse_forget_in *in;
405 if((ff = lookupfusefid(m->hdr->nodeid, 1)) == nil)
407 if(ff->ref > in->nlookup){
408 ff->ref -= in->nlookup;
411 if(ff->ref < in->nlookup)
412 fprint(2, "bad count in forget\n");
419 * Replies with a fuse_attr_out structure giving the
420 * attr for the requested nodeid in out.attr.
421 * Out.attr_valid and out.attr_valid_nsec give
422 * the amount of time that the attributes can
425 * Empirically, though, if I run ls -ld on the root
426 * twice back to back, I still get two getattrs,
427 * even with a one second attribute timeout!
430 fusegetattr(FuseMsg *m)
433 struct fuse_attr_out out;
436 if((fid = nodeid2fid(m->hdr->nodeid)) == nil){
437 replyfuseerrno(m, ESTALE);
440 if((d = fsdirfstat(fid)) == nil){
444 memset(&out, 0, sizeof out);
445 dir2attrout(d, &out);
447 replyfuse(m, &out, sizeof out);
452 * FUSE treats the many Unix attribute setting routines
453 * more or less like 9P does, with a single message.
456 fusesetattr(FuseMsg *m)
460 struct fuse_setattr_in *in;
461 struct fuse_attr_out out;
464 if(in->valid&FATTR_FH){
465 if((fid = fh2fid(in->fh)) == nil){
466 replyfuseerrno(m, ESTALE);
470 if((fid = nodeid2fid(m->hdr->nodeid)) == nil){
471 replyfuseerrno(m, ESTALE);
475 * Special case: Linux issues a size change to
476 * truncate a file before opening it OTRUNC.
477 * Synthetic file servers (e.g., plumber) honor
478 * open(OTRUNC) but not wstat.
480 if(in->valid == FATTR_SIZE && in->size == 0){
481 if((nfid = fswalk(fid, nil)) == nil){
485 if(fsfopen(nfid, OWRITE|OTRUNC) < 0){
496 if(in->valid&FATTR_SIZE)
498 if(in->valid&FATTR_ATIME)
500 if(in->valid&FATTR_MTIME)
502 if(in->valid&FATTR_MODE)
504 if((in->valid&FATTR_UID) || (in->valid&FATTR_GID)){
506 * I can't be bothered with these yet.
508 replyfuseerrno(m, EPERM);
511 if(fsdirfwstat(fid, &d) < 0){
516 if((dd = fsdirfstat(fid)) == nil){
520 memset(&out, 0, sizeof out);
521 dir2attrout(dd, &out);
523 replyfuse(m, &out, sizeof out);
527 _fuseopenfid(uvlong nodeid, int isdir, int openmode, int *err)
531 if((fid = nodeid2fid(nodeid)) == nil){
535 if(isdir && !(fsqid(fid).type&QTDIR)){
539 if(openmode != OREAD && fsqid(fid).type&QTDIR){
544 /* Clone fid to get one we can open. */
545 newfid = fswalk(fid, nil);
547 *err = errstr2errno();
551 if(fsfopen(newfid, openmode) < 0){
552 *err = errstr2errno();
562 * Argument is a struct fuse_open_in.
563 * The mode field is ignored (presumably permission bits)
564 * and flags is the open mode.
565 * Replies with a struct fuse_open_out.
568 _fuseopen(FuseMsg *m, int isdir)
570 struct fuse_open_in *in;
571 struct fuse_open_out out;
573 int openmode, flags, err;
579 flags &= ~(O_DIRECTORY|O_NONBLOCK|O_LARGEFILE|O_CLOEXEC);
581 flags &= ~O_NOFOLLOW;
584 flags &= ~O_LARGEFILE;
588 * Discarding O_APPEND here is not completely wrong,
589 * because the host kernel will rewrite the offsets
590 * of write system calls for us. That's the best we
591 * can do on Unix anyway.
599 * Could translate but not standard 9P:
600 * O_DIRECT -> ODIRECT
601 * O_NONBLOCK -> ONONBLOCK
604 fprint(2, "unexpected open flags %#uo\n", (uint)in->flags);
605 replyfuseerrno(m, EACCES);
608 if((fid = _fuseopenfid(m->hdr->nodeid, isdir, openmode, &err)) == nil){
609 replyfuseerrno(m, err);
612 out.fh = allocfh(fid);
613 out.open_flags = FOPEN_DIRECT_IO; /* no page cache */
614 replyfuse(m, &out, sizeof out);
624 fuseopendir(FuseMsg *m)
633 _fusecreate(uvlong nodeid, char *name, int perm, int ismkdir, int omode, struct fuse_entry_out *out, int *err)
635 CFid *fid, *newfid, *newfid2;
639 if((fid = nodeid2fid(nodeid)) == nil){
646 if(ismkdir && omode != OREAD){
650 if((newfid = fswalk(fid, nil)) == nil){
651 *err = errstr2errno();
654 if(fsfcreate(newfid, name, omode, perm) < 0){
655 *err = errstr2errno();
659 if((d = fsdirfstat(newfid)) == nil){
660 *err = errstr2errno();
665 * This fid is no good, because it's open.
666 * We need an unopened fid. Sigh.
668 if((newfid2 = fswalk(fid, name)) == nil){
669 *err = errstr2errno();
674 out->nodeid = allocnodeid(newfid2);
675 ff = lookupfusefid(out->nodeid, 1);
676 out->generation = ff->gen;
677 f2timeout(attrtimeout, &out->attr_valid, &out->attr_valid_nsec);
678 f2timeout(entrytimeout, &out->entry_valid, &out->entry_valid_nsec);
679 dir2attr(d, &out->attr);
685 fusemkdir(FuseMsg *m)
687 struct fuse_mkdir_in *in;
688 struct fuse_entry_out out;
694 name = (char*)(in+1);
695 if((fid = _fusecreate(m->hdr->nodeid, name, in->mode, 1, OREAD, &out, &err)) == nil){
696 replyfuseerrno(m, err);
699 /* Toss the open fid. */
701 replyfuse(m, &out, sizeof out);
705 fusecreate(FuseMsg *m)
707 struct fuse_open_in *in;
708 struct fuse_create_out out;
710 int err, openmode, flags;
715 openmode = in->flags&3;
717 flags &= ~(O_DIRECTORY|O_NONBLOCK|O_LARGEFILE|O_EXCL);
718 flags &= ~O_APPEND; /* see comment in _fuseopen */
719 flags &= ~(O_CREAT|O_TRUNC); /* huh? */
721 fprint(2, "bad mode %#uo\n", in->flags);
722 replyfuseerrno(m, EACCES);
725 name = (char*)(in+1);
726 if((fid = _fusecreate(m->hdr->nodeid, name, in->mode, 0, openmode, &out.e, &err)) == nil){
727 replyfuseerrno(m, err);
730 out.o.fh = allocfh(fid);
731 out.o.open_flags = FOPEN_DIRECT_IO; /* no page cache */
732 replyfuse(m, &out, sizeof out);
737 * Lib9pclient implements this just as Plan 9 does,
738 * by opening the file (or not) and then closing it.
741 fuseaccess(FuseMsg *m)
743 struct fuse_access_in *in;
758 if(in->mask >= nelem(a2o)){
759 replyfuseerrno(m, EINVAL);
762 omode = a2o[in->mask];
763 if((fid = nodeid2fid(m->hdr->nodeid)) == nil){
764 replyfuseerrno(m, ESTALE);
767 if(fsqid(fid).type&QTDIR)
769 if((fid = _fuseopenfid(m->hdr->nodeid, 0, omode, &err)) == nil){
770 replyfuseerrno(m, err);
774 replyfuse(m, nil, 0);
779 * Equivalent of clunk for file handles.
780 * in->flags is the open mode used in Open or Opendir.
783 fuserelease(FuseMsg *m)
785 struct fuse_release_in *in;
789 if((ff = lookupfusefid(in->fh, 0)) != nil)
792 fprint(2, "fuserelease: fh not found\n");
793 replyfuse(m, nil, 0);
797 fusereleasedir(FuseMsg *m)
804 * Read from file handle in->fh at offset in->offset for size in->size.
805 * We truncate size to maxwrite just to keep the buffer reasonable.
813 struct fuse_read_in *in;
816 if((fid = fh2fid(in->fh)) == nil){
817 replyfuseerrno(m, ESTALE);
824 n = fspread(fid, buf, n, in->offset);
830 replyfuse(m, buf, n);
838 fusereadlink(FuseMsg *m)
843 if((fid = nodeid2fid(m->hdr->nodeid)) == nil){
844 replyfuseerrno(m, ESTALE);
847 if((d = fsdirfstat(fid)) == nil){
851 if(!(d->mode&DMSYMLINK)){
852 replyfuseerrno(m, EINVAL);
855 replyfuse(m, d->ext, strlen(d->ext));
862 * Read from file handle in->fh at offset in->offset for size in->size.
863 * We truncate size to maxwrite just to keep the buffer reasonable.
864 * We assume 9P directory read semantics: a read at offset 0 rewinds
865 * and a read at any other offset starts where we left off.
866 * If it became necessary, we could implement a crude seek
867 * or cache the entire list of directory entries.
868 * Directory entries read from 9P but not yet handed to FUSE
869 * are stored in m->d,nd,d0.
871 int canpack(Dir*, uvlong, uchar**, uchar*);
874 fusereaddir(FuseMsg *m)
876 struct fuse_read_in *in;
882 if((ff = lookupfusefid(in->fh, 0)) == nil){
883 replyfuseerrno(m, ESTALE);
887 fsseek(ff->fid, 0, 0);
889 ff->d0 = ff->d = dotdirs(ff->fid);
900 if(!canpack(ff->d, ff->off, &p, ep))
909 if((ff->nd = fsdirread(ff->fid, &ff->d0)) < 0){
919 replyfuse(m, buf, p - buf);
924 * Fuse assumes that it can always read two directory entries.
925 * If it gets just one, it will double it in the dirread results.
926 * Thus if a directory contains just "a", you see "a" twice.
927 * Adding . as the first directory entry works around this.
928 * We could add .. too, but it isn't necessary.
936 d = emalloc(2*sizeof *d);
940 f1 = fswalk(f, "..");
942 d[1].qid = fsqid(f1);
949 canpack(Dir *d, uvlong off, uchar **pp, uchar *ep)
952 struct fuse_dirent *de;
956 size = FUSE_NAME_OFFSET + strlen(d->name);
960 if(size+pad > ep - p)
962 de = (struct fuse_dirent*)p;
963 de->ino = qid2inode(d->qid);
965 de->namelen = strlen(d->name);
966 memmove(de->name, d->name, de->namelen);
968 memset(de->name+de->namelen, 0, pad);
975 * Write from file handle in->fh at offset in->offset for size in->size.
976 * Don't know what in->write_flags means.
978 * Apparently implementations are allowed to buffer these writes
979 * and wait until Flush is sent, but FUSE docs say flush may be
980 * called zero, one, or even more times per close. So better do the
981 * actual writing here. Also, errors that happen during Flush just
982 * show up in the close() return status, which no one checks anyway.
985 fusewrite(FuseMsg *m)
987 struct fuse_write_in *in;
988 struct fuse_write_out out;
995 if((fid = fh2fid(in->fh)) == nil){
996 replyfuseerrno(m, ESTALE);
999 if(in->size > fusemaxwrite){
1000 replyfuseerrno(m, EINVAL);
1003 n = fspwrite(fid, a, in->size, in->offset);
1009 replyfuse(m, &out, sizeof out);
1013 * Flush. Supposed to flush any buffered writes. Don't use this.
1015 * Flush is a total crock. It gets called on close() of a file descriptor
1016 * associated with this open file. Some open files have multiple file
1017 * descriptors and thus multiple closes of those file descriptors.
1018 * In those cases, Flush is called multiple times. Some open files
1019 * have file descriptors that are closed on process exit instead of
1020 * closed explicitly. For those files, Flush is never called.
1021 * Even more amusing, Flush gets called before close() of read-only
1022 * file descriptors too!
1024 * This is just a bad idea.
1027 fuseflush(FuseMsg *m)
1029 replyfuse(m, nil, 0);
1036 _fuseremove(FuseMsg *m, int isdir)
1042 if((fid = nodeid2fid(m->hdr->nodeid)) == nil){
1043 replyfuseerrno(m, ESTALE);
1046 if(strchr(name, '/')){
1047 replyfuseerrno(m, ENOENT);
1050 if((newfid = fswalk(fid, name)) == nil){
1054 if(isdir && !(fsqid(newfid).type&QTDIR)){
1055 replyfuseerrno(m, ENOTDIR);
1059 if(!isdir && (fsqid(newfid).type&QTDIR)){
1060 replyfuseerrno(m, EISDIR);
1064 if(fsfremove(newfid) < 0){
1068 replyfuse(m, nil, 0);
1072 fuseunlink(FuseMsg *m)
1078 fusermdir(FuseMsg *m)
1086 * FUSE sends the nodeid for the source and destination
1087 * directory and then the before and after names as strings.
1088 * 9P can only do the rename if the source and destination
1089 * are the same. If the same nodeid is used for source and
1090 * destination, we're fine, but if FUSE gives us different nodeids
1091 * that happen to correspond to the same directory, we have
1092 * no way of figuring that out. Let's hope it doesn't happen too often.
1095 fuserename(FuseMsg *m)
1097 struct fuse_rename_in *in;
1098 char *before, *after;
1103 if(in->newdir != m->hdr->nodeid){
1104 replyfuseerrno(m, EXDEV);
1107 before = (char*)(in+1);
1108 after = before + strlen(before) + 1;
1109 if((fid = nodeid2fid(m->hdr->nodeid)) == nil){
1110 replyfuseerrno(m, ESTALE);
1113 if(strchr(before, '/') || strchr(after, '/')){
1114 replyfuseerrno(m, ENOENT);
1117 if((newfid = fswalk(fid, before)) == nil){
1123 if(fsdirfwstat(newfid, &d) < 0){
1129 replyfuse(m, nil, 0);
1133 * Fsync. Commit file info to stable storage.
1134 * Not sure what in->fsync_flags are.
1137 fusefsync(FuseMsg *m)
1139 struct fuse_fsync_in *in;
1144 if((fid = fh2fid(in->fh)) == nil){
1145 replyfuseerrno(m, ESTALE);
1149 if(fsdirfwstat(fid, &d) < 0){
1153 replyfuse(m, nil, 0);
1157 * Fsyncdir. Commit dir info to stable storage?
1160 fusefsyncdir(FuseMsg *m)
1166 * Statfs. Send back information about file system.
1167 * Not really worth implementing, except that if we
1168 * reply with ENOSYS, programs like df print messages like
1169 * df: `/tmp/z': Function not implemented
1170 * and that gets annoying. Returning all zeros excludes
1171 * us from df without appearing to cause any problems.
1174 fusestatfs(FuseMsg *m)
1176 struct fuse_statfs_out out;
1178 memset(&out, 0, sizeof out);
1179 replyfuse(m, &out, sizeof out);
1182 void (*fusehandlers[100])(FuseMsg*);
1186 void (*fn)(FuseMsg*);
1188 { FUSE_LOOKUP, fuselookup },
1189 { FUSE_FORGET, fuseforget },
1190 { FUSE_GETATTR, fusegetattr },
1191 { FUSE_SETATTR, fusesetattr },
1193 * FUSE_SYMLINK, FUSE_MKNOD are unimplemented.
1195 { FUSE_READLINK, fusereadlink },
1196 { FUSE_MKDIR, fusemkdir },
1197 { FUSE_UNLINK, fuseunlink },
1198 { FUSE_RMDIR, fusermdir },
1199 { FUSE_RENAME, fuserename },
1201 * FUSE_LINK is unimplemented.
1203 { FUSE_OPEN, fuseopen },
1204 { FUSE_READ, fuseread },
1205 { FUSE_WRITE, fusewrite },
1206 { FUSE_STATFS, fusestatfs },
1207 { FUSE_RELEASE, fuserelease },
1208 { FUSE_FSYNC, fusefsync },
1210 * FUSE_SETXATTR, FUSE_GETXATTR, FUSE_LISTXATTR, and
1211 * FUSE_REMOVEXATTR are unimplemented.
1212 * FUSE will stop sending these requests after getting
1213 * an -ENOSYS reply (see dispatch below).
1215 { FUSE_FLUSH, fuseflush },
1217 * FUSE_INIT is handled in initfuse and should not be seen again.
1219 { FUSE_OPENDIR, fuseopendir },
1220 { FUSE_READDIR, fusereaddir },
1221 { FUSE_RELEASEDIR, fusereleasedir },
1222 { FUSE_FSYNCDIR, fusefsyncdir },
1223 { FUSE_ACCESS, fuseaccess },
1224 { FUSE_CREATE, fusecreate },
1233 if((uint)m->hdr->opcode >= nelem(fusehandlers)
1234 || !fusehandlers[m->hdr->opcode]){
1235 replyfuseerrno(m, ENOSYS);
1238 fusehandlers[m->hdr->opcode](m);
1242 fusedispatch(void *v)
1247 eofkill9pclient = 1; /* threadexitsall on 9P eof */
1248 atexit(unmountatexit);
1250 recvp(fusechan); /* sync */
1252 for(i=0; i<nelem(fuselist); i++){
1253 if(fuselist[i].op >= nelem(fusehandlers))
1254 sysfatal("make fusehandlers bigger op=%d", fuselist[i].op);
1255 fusehandlers[fuselist[i].op] = fuselist[i].fn;
1258 while((m = recvp(fusechan)) != nil)
1259 threadcreate(fusethread, m, STACK);
1269 sysfatal("malloc(%d): %r", n);
1275 erealloc(void *p, uint n)
1279 sysfatal("realloc(..., %d): %r", n);
1289 sysfatal("strdup(%.20s): %r", p);
1296 int fd = (int)(uintptr)v;
1298 /* wait for exception (file closed) */
1302 if(select(fd+1, NULL, NULL, &set, NULL) >= 0)
1303 threadexitsall(nil);