From 59518849d81a71284b90513f6ba76770b42ce32b Mon Sep 17 00:00:00 2001 From: rsc Date: Fri, 11 Feb 2005 17:00:46 +0000 Subject: add _fsunmount; do version in fsinit; add nsinit; add chatty9pclient --- src/lib9pclient/fs.c | 39 ++++++++++++++++++++++++++------------- src/lib9pclient/ns.c | 21 +++++++++++++++------ 2 files changed, 41 insertions(+), 19 deletions(-) (limited to 'src') diff --git a/src/lib9pclient/fs.c b/src/lib9pclient/fs.c index a7bf1b9e..1a641d12 100644 --- a/src/lib9pclient/fs.c +++ b/src/lib9pclient/fs.c @@ -13,6 +13,8 @@ static void *_fsrecv(Mux*); static int _fsgettag(Mux*, void*); static int _fssettag(Mux*, void*, uint); +int chatty9pclient; + enum { CFidchunk = 32 @@ -22,7 +24,8 @@ CFsys* fsinit(int fd) { CFsys *fs; - + int n; + fmtinstall('F', fcallfmt); fmtinstall('D', dirfmt); fmtinstall('M', dirmodefmt); @@ -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; } @@ -55,28 +65,28 @@ 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) { @@ -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); @@ -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 index 428f7fbb..c71defd6 100644 --- a/src/lib9pclient/ns.c +++ b/src/lib9pclient/ns.c @@ -5,11 +5,10 @@ #include CFsys* -nsmount(char *name, char *aname) +nsinit(char *name) { char *addr, *ns; int fd; - CFsys *fs; ns = getns(); if(ns == nil) @@ -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; } -- cgit v1.2.3