tmore functions - plan9port - [fork] Plan 9 from user space
 (HTM) git clone git://src.adamsgaard.dk/plan9port
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
 (DIR) LICENSE
       ---
 (DIR) commit 73a5509ae929e41ca0047254a880c8efd4aa72a1
 (DIR) parent 9b3357a896417eb166cf94dd2a04aa391fef21c8
 (HTM) Author: rsc <devnull@localhost>
       Date:   Sun, 23 Jul 2006 02:55:34 +0000
       
       more functions
       
       Diffstat:
         M include/9pclient.h                  |       7 +++++++
         M man/man3/9pclient.3                 |      63 ++++++++++++++++++++++++++++++-
         M src/lib9pclient/create.c            |      33 +++++++++++++++++++------------
         M src/lib9pclient/fs.c                |      18 ++++++++++++++++--
         M src/lib9pclient/open.c              |      22 ++++++++++++++++------
         M src/lib9pclient/openfd.c            |       2 +-
         M src/lib9pclient/remove.c            |       2 +-
         M src/lib9pclient/stat.c              |       2 +-
         M src/lib9pclient/walk.c              |       2 +-
         M src/lib9pclient/wstat.c             |       2 +-
       
       10 files changed, 125 insertions(+), 28 deletions(-)
       ---
 (DIR) diff --git a/include/9pclient.h b/include/9pclient.h
       t@@ -47,8 +47,15 @@ CFid *fscreate(CFsys*, char*, int, ulong);
        int fsaccess(CFsys*, char*, int);
        int        fsvprint(CFid*, char*, va_list);
        int        fsprint(CFid*, char*, ...);
       +Qid        fsqid(CFid*);
       +
       +/* manipulate unopened fids */
       +CFid        *fswalk(CFid*, char*);
       +int fsfopen(CFid*, int);
       +int fsfcreate(CFid*, char*, int, ulong);
        
        extern int chatty9pclient;
       +extern int eofkill9pclient;
        
        #ifdef __cplusplus
        }
 (DIR) diff --git a/man/man3/9pclient.3 b/man/man3/9pclient.3
       t@@ -1,6 +1,6 @@
        .TH 9PCLIENT 3
        .SH NAME
       -CFid, CFsys, fsinit, fsmount, fsroot, fssetroot, fsunmount, nsinit, nsmount, fsversion, fsauth, fsattach, fsclose, fscreate, fsremove, fsfremove, fsaccess, fsdirread, fsdirreadall, fsdirstat, fsdirfstat, fsdirwstat, fsdirfwstat, fsopen, nsopen, fsopenfd, fspread, fspwrite, fsread, fsreadn, fsseek, fswrite, fsprint, fsvprint \- 9P client library
       +CFid, CFsys, fsinit, fsmount, fsroot, fssetroot, fsunmount, nsinit, nsmount, fsversion, fsauth, fsattach, fsclose, fscreate, fsfcreate, fsremove, fsfremove, fsaccess, fsdirread, fsdirreadall, fsdirstat, fsdirfstat, fsdirwstat, fsdirfwstat, fsopen, fsfopen, nsopen, fsopenfd, fspread, fspwrite, fsread, fsreadn, fsseek, fswrite, fsprint, fsvprint \- 9P client library
        .SH SYNOPSIS
        .B #include <u.h>
        .PP
       t@@ -50,6 +50,9 @@ void        fsclose(CFid *fid)
        CFid*        fscreate(CFsys *fs, char *path, int mode, ulong perm)
        .PP
        .B
       +int        fsfcreate(CFid *fid, char *path, int mode, ulong perm)
       +.PP
       +.B
        int        fsremove(CFSys *fs, char *path)
        .PP
        .B
       t@@ -62,6 +65,9 @@ int        fsaccess(CFsys *fs, char *path, int amode)
        CFid*        fsopen(CFsys *fs, char *path, int mode)
        .PP
        .B
       +int        fsfopen(CFid *fid, char *path, int mode)
       +.PP
       +.B
        long        fspread(CFid *fid, void *buf, long n, vlong offset)
        .PP
        .B
       t@@ -86,6 +92,9 @@ int        fsvprint(CFid *fid, char *fmt, ...)
        vlong        fsseek(CFid *Fid, vlong n, int type)
        .PP
        .B
       +Qid        fsqid(CFid *fid)
       +.PP
       +.B
        long        fsdirread(CFid *fid, Dir **d)
        .PP
        .B
       t@@ -108,6 +117,12 @@ int        fsopenfd(CFsys *fs, char *path, int mode)
        .PP
        .B
        CFsys*        nsopen(char *name, char *aname, char *path, int mode)
       +.PP
       +.B
       +extern int chatty9pclient;
       +.PP
       +.B
       +extern int eofkill9pclient;
        .SH DESCRIPTION
        The
        .I 9pclient
       t@@ -218,6 +233,9 @@ Fids are not reference counted: when
        .I fsclose
        is called, the clunk transaction and freeing of storage
        happen immediately.
       +Despite its name,
       +.I fsclose
       +can be used to clunk fids that are not open for I/O.
        .PP
        .I Fscreate
        and
       t@@ -249,7 +267,25 @@ dot
        .RB ( . )
        are ignored.
        .PP
       -Once opened, these fids can be read and written using
       +Alternately,
       +.I fswalk
       +walks from a fid to a given name
       +to create a new fid.
       +The name may be nil, corresponding to a walk with no names.
       +Otherwise the name is taken as a slash-separated sequence
       +of path elements.
       +.I Fsfcreate
       +and
       +.I fsfopen
       +issue 
       +.I create
       +and
       +.I open
       +transactions using the passed fid argument,
       +which should have been obtained by calling
       +.IR fswalk .
       +.PP
       +Once opened, fids can be read and written using
        .I fspread
        and
        .IR fspwrite ,
       t@@ -291,6 +327,17 @@ repeatedly to obtain exactly
        .I n
        bytes of data, unless it encounters end-of-file or an error.
        .PP
       +.IR Attach ,
       +.IR walk ,
       +.IR create ,
       +and
       +.I open
       +transactions include in their replies an updated qid for the
       +fid being manipulated.
       +.I Fsqid
       +returns the most recent qid returned by one of these transactions
       +for the given fid.
       +.PP
        .I Fsaccess
        behaves like Unix's
        .IR access (2).
       t@@ -386,6 +433,18 @@ opens a single file on a name space server: it runs
        .IR fsopen ,
        and then
        .IR fsunmount .
       +.PP
       +If the
       +.B chatty9pclient
       +flag is set, the library prints all 9P messages
       +to standard error.
       +If the
       +.B eofkill9pclient
       +flag is set, the library calls
       +.I threadexitsall
       +(see
       +.IR thread (3))
       +when it detects EOF on a 9P connection.
        .SH SOURCE
        .B \*9/src/lib9pclient
        .SH SEE ALSO
 (DIR) diff --git a/src/lib9pclient/create.c b/src/lib9pclient/create.c
       t@@ -4,11 +4,26 @@
        #include <9pclient.h>
        #include "fsimpl.h"
        
       +int
       +fsfcreate(CFid *fid, char *name, int mode, ulong perm)
       +{
       +        Fcall tx, rx;
       +
       +        tx.type = Tcreate;
       +        tx.name = name;
       +        tx.fid = fid->fid;
       +        tx.mode = mode;
       +        tx.perm = perm;
       +        if(_fsrpc(fid->fs, &tx, &rx, 0) < 0)
       +                return -1;
       +        fid->mode = mode;
       +        return 0;
       +}
       +
        CFid*
        fscreate(CFsys *fs, char *name, int mode, ulong perm)
        {
                CFid *fid;
       -        Fcall tx, rx;
                char *p, *dir, *elem;
                
                p = strrchr(name, '/');
       t@@ -21,24 +36,16 @@ fscreate(CFsys *fs, char *name, int mode, ulong perm)
                        elem = p+1;
                }
        
       -        if((fid = _fswalk(fs->root, dir)) == nil){
       +        if((fid = fswalk(fs->root, dir)) == nil){
                        if(p)
                                *p = '/';
                        return nil;
                }
       -        tx.type = Tcreate;
       -        tx.name = elem;
       -        tx.fid = fid->fid;
       -        tx.mode = mode;
       -        tx.perm = perm;
       -        if(_fsrpc(fs, &tx, &rx, 0) < 0){
       -                if(p)
       -                        *p = '/';
       +        if(p)
       +                *p = '/';
       +        if(fsfcreate(fid, elem, mode, perm) < 0){
                        fsclose(fid);
                        return nil;
                }
       -        if(p)
       -                *p = '/';
       -        fid->mode = mode;
                return fid;
        }
 (DIR) diff --git a/src/lib9pclient/fs.c b/src/lib9pclient/fs.c
       t@@ -14,6 +14,7 @@ static int _fsgettag(Mux*, void*);
        static int _fssettag(Mux*, void*, uint);
        
        int chatty9pclient;
       +int eofkill9pclient;
        
        enum
        {
       t@@ -318,9 +319,13 @@ static int
        _fssend(Mux *mux, void *pkt)
        {
                CFsys *fs;
       +        int n;
        
                fs = mux->aux;
       -        return iowrite(fs->iosend, fs->fd, pkt, GBIT32((uchar*)pkt));
       +        n = iowrite(fs->iosend, fs->fd, pkt, GBIT32((uchar*)pkt));
       +        if(n < 0 && eofkill9pclient)
       +                threadexitsall(nil);
       +        return n;
        }
        
        static void*
       t@@ -333,8 +338,11 @@ _fsrecv(Mux *mux)
        
                fs = mux->aux;
                n = ioreadn(fs->iorecv, fs->fd, buf, 4);
       -        if(n != 4)
       +        if(n != 4){
       +                if(eofkill9pclient)
       +                        threadexitsall(nil);
                        return nil;
       +        }
                n = GBIT32(buf);
                pkt = malloc(n+4);
                if(pkt == nil){
       t@@ -356,3 +364,9 @@ _fsrecv(Mux *mux)
                }
                return pkt;
        }
       +
       +Qid
       +fsqid(CFid *fid)
       +{
       +        return fid->qid;
       +}
 (DIR) diff --git a/src/lib9pclient/open.c b/src/lib9pclient/open.c
       t@@ -4,19 +4,29 @@
        #include <9pclient.h>
        #include "fsimpl.h"
        
       +int
       +fsfopen(CFid *fid, int mode)
       +{
       +        Fcall tx, rx;
       +
       +        tx.type = Topen;
       +        tx.fid = fid->fid;
       +        tx.mode = mode;
       +        if(_fsrpc(fid->fs, &tx, &rx, 0) < 0)
       +                return -1;
       +        fid->mode = mode;
       +        return 0;
       +}
       +
        CFid*
        fsopen(CFsys *fs, char *name, int mode)
        {
                char e[ERRMAX];
                CFid *fid;
       -        Fcall tx, rx;
        
       -        if((fid = _fswalk(fs->root, name)) == nil)
       +        if((fid = fswalk(fs->root, name)) == nil)
                        return nil;
       -        tx.type = Topen;
       -        tx.fid = fid->fid;
       -        tx.mode = mode;
       -        if(_fsrpc(fs, &tx, &rx, 0) < 0){
       +        if(fsfopen(fid, mode) < 0){
                        rerrstr(e, sizeof e);
                        fsclose(fid);
                        errstr(e, sizeof e);
 (DIR) diff --git a/src/lib9pclient/openfd.c b/src/lib9pclient/openfd.c
       t@@ -10,7 +10,7 @@ fsopenfd(CFsys *fs, char *name, int mode)
                CFid *fid;
                Fcall tx, rx;
        
       -        if((fid = _fswalk(fs->root, name)) == nil)
       +        if((fid = fswalk(fs->root, name)) == nil)
                        return -1;
                tx.type = Topenfd;
                tx.fid = fid->fid;
 (DIR) diff --git a/src/lib9pclient/remove.c b/src/lib9pclient/remove.c
       t@@ -12,7 +12,7 @@ fsremove(CFsys *fs, char *name)
        {
                CFid *fid;
        
       -        if((fid = _fswalk(fs->root, name)) == nil)
       +        if((fid = fswalk(fs->root, name)) == nil)
                        return -1;
                return fsfremove(fid);
        }
 (DIR) diff --git a/src/lib9pclient/stat.c b/src/lib9pclient/stat.c
       t@@ -13,7 +13,7 @@ fsdirstat(CFsys *fs, char *name)
                Dir *d;
                CFid *fid;
        
       -        if((fid = _fswalk(fs->root, name)) == nil)
       +        if((fid = fswalk(fs->root, name)) == nil)
                        return nil;
                
                d = fsdirfstat(fid);
 (DIR) diff --git a/src/lib9pclient/walk.c b/src/lib9pclient/walk.c
       t@@ -8,7 +8,7 @@
        #include "fsimpl.h"
        
        CFid*
       -_fswalk(CFid *fid, char *oname)
       +fswalk(CFid *fid, char *oname)
        {
                char *freep, *name;
                int i, nwalk;
 (DIR) diff --git a/src/lib9pclient/wstat.c b/src/lib9pclient/wstat.c
       t@@ -13,7 +13,7 @@ fsdirwstat(CFsys *fs, char *name, Dir *d)
                int n;
                CFid *fid;
        
       -        if((fid = _fswalk(fs->root, name)) == nil)
       +        if((fid = fswalk(fs->root, name)) == nil)
                        return -1;
                
                n = fsdirfwstat(fid, d);