diff options
author | rsc <devnull@localhost> | 2005-01-04 21:22:40 +0000 |
---|---|---|
committer | rsc <devnull@localhost> | 2005-01-04 21:22:40 +0000 |
commit | 46f79934b79ef526ed42bbe5a565e6b5d884d24a (patch) | |
tree | d1e663f7d3b2b328f03aeb34fdb3f4006aa97ec0 /src/lib9pclient/walk.c | |
parent | 5ba841dffa1f6cda712ebcff27c55c9d0a672c67 (diff) | |
download | plan9port-46f79934b79ef526ed42bbe5a565e6b5d884d24a.tar.gz plan9port-46f79934b79ef526ed42bbe5a565e6b5d884d24a.tar.bz2 plan9port-46f79934b79ef526ed42bbe5a565e6b5d884d24a.zip |
lib9pclient is the new libfs
Diffstat (limited to 'src/lib9pclient/walk.c')
-rw-r--r-- | src/lib9pclient/walk.c | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/src/lib9pclient/walk.c b/src/lib9pclient/walk.c new file mode 100644 index 00000000..32a2fd7b --- /dev/null +++ b/src/lib9pclient/walk.c @@ -0,0 +1,73 @@ +/* Copyright (C) 2003 Russ Cox, Massachusetts Institute of Technology */ +/* See COPYRIGHT */ + +#include <u.h> +#include <libc.h> +#include <fcall.h> +#include <9pclient.h> +#include "fsimpl.h" + +CFid* +_fswalk(CFid *fid, char *oname) +{ + char *freep, *name; + int i, nwalk; + char *p; + CFid *wfid; + Fcall tx, rx; + + freep = nil; + name = oname; + if(name){ + freep = malloc(strlen(name)+1); + if(freep == nil) + return nil; + strcpy(freep, name); + name = freep; + } + + if((wfid = _fsgetfid(fid->fs)) == nil){ + free(freep); + return nil; + } + + nwalk = 0; + do{ + /* collect names */ + for(i=0; name && *name && i < MAXWELEM; ){ + p = name; + name = strchr(name, '/'); + if(name) + *name++ = 0; + if(*p == 0 || (*p == '.' && *(p+1) == 0)) + continue; + tx.wname[i++] = p; + } + + /* do a walk */ + tx.type = Twalk; + tx.fid = nwalk ? wfid->fid : fid->fid; + tx.newfid = wfid->fid; + tx.nwname = i; + if(_fsrpc(fid->fs, &tx, &rx, 0) < 0){ + Error: + free(freep); + if(nwalk) + fsclose(wfid); + else + _fsputfid(wfid); + return nil; + } + if(rx.nwqid != tx.nwname){ + /* XXX lame error */ + werrstr("file '%s' not found", oname); + goto Error; + } + if(rx.nwqid == 0) + wfid->qid = fid->qid; + else + wfid->qid = rx.wqid[rx.nwqid-1]; + nwalk++; + }while(name && *name); + return wfid; +} |