mirror of
https://github.com/9fans/plan9port.git
synced 2025-01-15 11:20:03 +00:00
55 lines
753 B
C
55 lines
753 B
C
#include <u.h>
|
|
#include <libc.h>
|
|
#include <fcall.h>
|
|
#include <9pclient.h>
|
|
#include <ctype.h>
|
|
|
|
CFsys*
|
|
nsmount(char *name, char *aname)
|
|
{
|
|
char *addr, *ns;
|
|
int fd;
|
|
CFsys *fs;
|
|
|
|
ns = getns();
|
|
if(ns == nil)
|
|
return nil;
|
|
|
|
addr = smprint("unix!%s/%s", ns, name);
|
|
free(ns);
|
|
if(addr == nil)
|
|
return nil;
|
|
|
|
fd = dial(addr, 0, 0, 0);
|
|
if(fd < 0){
|
|
werrstr("dial %s: %r", addr);
|
|
free(addr);
|
|
return nil;
|
|
}
|
|
free(addr);
|
|
|
|
fcntl(fd, F_SETFL, FD_CLOEXEC);
|
|
|
|
fs = fsmount(fd, aname);
|
|
if(fs == nil){
|
|
close(fd);
|
|
return nil;
|
|
}
|
|
|
|
return fs;
|
|
}
|
|
|
|
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;
|
|
}
|
|
|