12 plumbopen(char *name, int omode)
15 fsplumb = nsmount("plumb", "");
19 * It's important that when we send something,
20 * we find out whether it was a valid plumb write.
21 * (If it isn't, the client might fall back to some
22 * other mechanism or indicate to the user what happened.)
23 * We can't use a pipe for this, so we have to use the
24 * fid interface. But we need to return a fd.
25 * Return a fd for /dev/null so that we return a unique
26 * file descriptor. In plumbsend we'll look for pfd
27 * and use the recorded fid instead.
29 if((omode&3) == OWRITE){
31 werrstr("already have plumb send open");
34 pfd = open("/dev/null", OWRITE);
37 pfid = fsopen(fsplumb, name, omode);
46 return fsopenfd(fsplumb, name, omode);
50 plumbopenfid(char *name, int mode)
53 fsplumb = nsmount("plumb", "");
56 return fsopen(fsplumb, name, mode);
60 plumbsendtofid(Fid *fid, Plumbmsg *m)
66 werrstr("invalid fid");
69 buf = plumbpack(m, &n);
72 n = fswrite(fid, buf, n);
78 plumbsend(int fd, Plumbmsg *m)
81 werrstr("invalid fd");
85 werrstr("fd is not the plumber");
88 return plumbsendtofid(pfid, m);
101 n = read(fd, buf, 8192);
104 m = plumbunpackpartial(buf, n, &more);
105 if(m==nil && more>0){
106 /* we now know how many more bytes to read for complete message */
107 buf = realloc(buf, n+more);
110 if(readn(fd, buf+n, more) == more)
111 m = plumbunpackpartial(buf, n+more, nil);
119 plumbrecvfid(Fid *fid)
128 n = fsread(fid, buf, 8192);
131 m = plumbunpackpartial(buf, n, &more);
132 if(m==nil && more>0){
133 /* we now know how many more bytes to read for complete message */
134 buf = realloc(buf, n+more);
137 if(fsreadn(fid, buf+n, more) == more)
138 m = plumbunpackpartial(buf, n+more, nil);