1 #include <u.h>
2 #include <libc.h>
3 #include <fcall.h>
4 #include <9pclient.h>
5 #include <ctype.h>
6
7 CFsys*
nsinit(char * name)8 nsinit(char *name)
9 {
10 char *addr, *ns;
11 int fd;
12
13 ns = getns();
14 if(ns == nil){
15 werrstr("no name space");
16 return nil;
17 }
18
19 addr = smprint("unix!%s/%s", ns, name);
20 free(ns);
21 if(addr == nil){
22 werrstr("smprint: %r");
23 return nil;
24 }
25
26 fd = dial(addr, 0, 0, 0);
27 if(fd < 0){
28 werrstr("dial %s: %r", addr);
29 free(addr);
30 return nil;
31 }
32 free(addr);
33
34 fcntl(fd, F_SETFD, FD_CLOEXEC);
35 return fsinit(fd);
36 }
37
38 CFsys*
nsmount(char * name,char * aname)39 nsmount(char *name, char *aname)
40 {
41 CFsys *fs;
42 CFid *fid;
43
44 fs = nsinit(name);
45 if(fs == nil)
46 return nil;
47 if((fid = fsattach(fs, nil, getuser(), aname)) == nil){
48 _fsunmount(fs);
49 return nil;
50 }
51 fssetroot(fs, fid);
52 return fs;
53 }
54
55 CFid*
nsopen(char * name,char * aname,char * fname,int mode)56 nsopen(char *name, char *aname, char *fname, int mode)
57 {
58 CFsys *fs;
59 CFid *fid;
60
61 fs = nsmount(name, aname);
62 if(fs == nil)
63 return nil;
64 fid = fsopen(fs, fname, mode);
65 fsunmount(fs);
66 return fid;
67 }
68