tadd _fsunmount; do version in fsinit; add nsinit; add chatty9pclient - plan9po… | |
git clone git://src.adamsgaard.dk/plan9port | |
Log | |
Files | |
Refs | |
README | |
LICENSE | |
--- | |
commit 59518849d81a71284b90513f6ba76770b42ce32b | |
parent 2aa7d3036738bc548cfe6d8d83ff45cb1cb9c8c7 | |
Author: rsc <devnull@localhost> | |
Date: Fri, 11 Feb 2005 17:00:46 +0000 | |
add _fsunmount; do version in fsinit; add nsinit; add chatty9pclient | |
Diffstat: | |
M src/lib9pclient/fs.c | 39 +++++++++++++++++++++--------… | |
M src/lib9pclient/ns.c | 21 +++++++++++++++------ | |
2 files changed, 41 insertions(+), 19 deletions(-) | |
--- | |
diff --git a/src/lib9pclient/fs.c b/src/lib9pclient/fs.c | |
t@@ -13,6 +13,8 @@ static void *_fsrecv(Mux*); | |
static int _fsgettag(Mux*, void*); | |
static int _fssettag(Mux*, void*, uint); | |
+int chatty9pclient; | |
+ | |
enum | |
{ | |
CFidchunk = 32 | |
t@@ -22,7 +24,8 @@ CFsys* | |
fsinit(int fd) | |
{ | |
CFsys *fs; | |
- | |
+ int n; | |
+ | |
fmtinstall('F', fcallfmt); | |
fmtinstall('D', dirfmt); | |
fmtinstall('M', dirmodefmt); | |
t@@ -42,6 +45,13 @@ fsinit(int fd) | |
fs->iorecv = ioproc(); | |
fs->iosend = ioproc(); | |
muxinit(&fs->mux); | |
+ | |
+ strcpy(fs->version, "9P2000"); | |
+ if((n = fsversion(fs, 8192, fs->version, sizeof fs->version)) < 0){ | |
+ _fsunmount(fs); | |
+ return nil; | |
+ } | |
+ fs->msize = n; | |
return fs; | |
} | |
t@@ -55,29 +65,29 @@ fsroot(CFsys *fs) | |
CFsys* | |
fsmount(int fd, char *aname) | |
{ | |
- int n; | |
CFsys *fs; | |
CFid *fid; | |
fs = fsinit(fd); | |
if(fs == nil) | |
return nil; | |
- strcpy(fs->version, "9P2000"); | |
- if((n = fsversion(fs, 8192, fs->version, sizeof fs->version)) < 0){ | |
- Error: | |
- fs->fd = -1; | |
- fsunmount(fs); | |
+ | |
+ if((fid = fsattach(fs, nil, getuser(), aname)) == nil){ | |
+ _fsunmount(fs); | |
return nil; | |
} | |
- fs->msize = n; | |
- | |
- if((fid = fsattach(fs, nil, getuser(), aname)) == nil) | |
- goto Error; | |
fssetroot(fs, fid); | |
return fs; | |
} | |
void | |
+_fsunmount(CFsys *fs) | |
+{ | |
+ fs->fd = -1; | |
+ fsunmount(fs); | |
+} | |
+ | |
+void | |
fsunmount(CFsys *fs) | |
{ | |
fsclose(fs->root); | |
t@@ -196,7 +206,9 @@ _fsrpc(CFsys *fs, Fcall *tx, Fcall *rx, void **freep) | |
*freep = nil; | |
if(tpkt == nil) | |
return -1; | |
- //fprint(2, "<- %F\n", tx); | |
+ tx->tag = 0; | |
+ if(chatty9pclient) | |
+ fprint(2, "<- %F\n", tx); | |
nn = convS2M(tx, tpkt, n); | |
if(nn != n){ | |
free(tpkt); | |
t@@ -216,7 +228,8 @@ _fsrpc(CFsys *fs, Fcall *tx, Fcall *rx, void **freep) | |
fprint(2, "%r\n"); | |
return -1; | |
} | |
- //fprint(2, "-> %F\n", rx); | |
+ if(chatty9pclient) | |
+ fprint(2, "-> %F\n", rx); | |
if(rx->type == Rerror){ | |
werrstr("%s", rx->ename); | |
free(rpkt); | |
diff --git a/src/lib9pclient/ns.c b/src/lib9pclient/ns.c | |
t@@ -5,11 +5,10 @@ | |
#include <ctype.h> | |
CFsys* | |
-nsmount(char *name, char *aname) | |
+nsinit(char *name) | |
{ | |
char *addr, *ns; | |
int fd; | |
- CFsys *fs; | |
ns = getns(); | |
if(ns == nil) | |
t@@ -29,13 +28,23 @@ nsmount(char *name, char *aname) | |
free(addr); | |
fcntl(fd, F_SETFL, FD_CLOEXEC); | |
+ return fsinit(fd); | |
+} | |
+ | |
+CFsys* | |
+nsmount(char *name, char *aname) | |
+{ | |
+ CFsys *fs; | |
+ CFid *fid; | |
- fs = fsmount(fd, aname); | |
- if(fs == nil){ | |
- close(fd); | |
+ fs = nsinit(name); | |
+ if(fs == nil) | |
+ return nil; | |
+ if((fid = fsattach(fs, nil, getuser(), aname)) == nil){ | |
+ _fsunmount(fs); | |
return nil; | |
} | |
- | |
+ fssetroot(fs, fid); | |
return fs; | |
} | |