Files
plan9port/src/lib9pclient/ns.c

69 lines
967 B
C
Raw Normal View History

2005-01-04 21:22:40 +00:00
#include <u.h>
#include <libc.h>
#include <fcall.h>
#include <9pclient.h>
#include <ctype.h>
CFsys*
nsinit(char *name)
2005-01-04 21:22:40 +00:00
{
char *addr, *ns;
int fd;
ns = getns();
2005-07-13 10:50:44 +00:00
if(ns == nil){
werrstr("no name space");
2005-01-04 21:22:40 +00:00
return nil;
2005-07-13 10:50:44 +00:00
}
2005-01-04 21:22:40 +00:00
addr = smprint("unix!%s/%s", ns, name);
free(ns);
2005-07-13 10:50:44 +00:00
if(addr == nil){
werrstr("smprint: %r");
2005-01-04 21:22:40 +00:00
return nil;
2005-07-13 10:50:44 +00:00
}
2005-01-04 21:22:40 +00:00
fd = dial(addr, 0, 0, 0);
if(fd < 0){
werrstr("dial %s: %r", addr);
free(addr);
return nil;
}
free(addr);
2005-07-13 10:50:44 +00:00
fcntl(fd, F_SETFD, FD_CLOEXEC);
return fsinit(fd);
}
CFsys*
nsmount(char *name, char *aname)
{
CFsys *fs;
CFid *fid;
2005-01-04 21:22:40 +00:00
fs = nsinit(name);
if(fs == nil)
return nil;
if((fid = fsattach(fs, nil, getuser(), aname)) == nil){
_fsunmount(fs);
2005-01-04 21:22:40 +00:00
return nil;
}
fssetroot(fs, fid);
2005-01-04 21:22:40 +00:00
return fs;
}
2005-02-08 21:03:12 +00:00
CFid*
nsopen(char *name, char *aname, char *fname, int mode)
{
CFsys *fs;
CFid *fid;
fs = nsmount(name, aname);
if(fs == nil)
return nil;
fid = fsopen(fs, fname, mode);
fsunmount(fs);
return fid;
}