25 plumbopen(char *name, int omode)
28 fsplumb = nsmount("plumb", "");
32 * It's important that when we send something,
33 * we find out whether it was a valid plumb write.
34 * (If it isn't, the client might fall back to some
35 * other mechanism or indicate to the user what happened.)
36 * We can't use a pipe for this, so we have to use the
37 * fid interface. But we need to return a fd.
38 * Return a fd for /dev/null so that we return a unique
39 * file descriptor. In plumbsend we'll look for pfd
40 * and use the recorded fid instead.
42 if((omode&3) == OWRITE){
44 werrstr("already have plumb send open");
47 pfd = open("/dev/null", OWRITE);
50 pfid = fsopen(fsplumb, name, omode);
59 return fsopenfd(fsplumb, name, omode);
63 plumbopenfid(char *name, int mode)
66 fsplumb = nsmount("plumb", "");
68 werrstr("mount plumb: %r");
72 return fsopen(fsplumb, name, mode);
76 plumbsendtofid(CFid *fid, Plumbmsg *m)
82 werrstr("invalid fid");
85 buf = plumbpack(m, &n);
88 n = fswrite(fid, buf, n);
94 plumbsend(int fd, Plumbmsg *m)
97 werrstr("invalid fd");
101 werrstr("fd is not the plumber");
104 return plumbsendtofid(pfid, m);
117 n = read(fd, buf, 8192);
120 m = plumbunpackpartial(buf, n, &more);
121 if(m==nil && more>0){
122 /* we now know how many more bytes to read for complete message */
123 buf = realloc(buf, n+more);
126 if(readn(fd, buf+n, more) == more)
127 m = plumbunpackpartial(buf, n+more, nil);
135 plumbrecvfid(CFid *fid)
142 werrstr("invalid fid");
148 n = fsread(fid, buf, 8192);
151 m = plumbunpackpartial(buf, n, &more);
152 if(m==nil && more>0){
153 /* we now know how many more bytes to read for complete message */
154 buf = realloc(buf, n+more);
157 if(fsreadn(fid, buf+n, more) == more)
158 m = plumbunpackpartial(buf, n+more, nil);