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/read.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/read.c')
-rw-r--r-- | src/lib9pclient/read.c | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/src/lib9pclient/read.c b/src/lib9pclient/read.c new file mode 100644 index 00000000..60537288 --- /dev/null +++ b/src/lib9pclient/read.c @@ -0,0 +1,72 @@ +/* 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" + +long +fspread(CFid *fid, void *buf, long n, vlong offset) +{ + Fcall tx, rx; + void *freep; + uint msize; + + msize = fid->fs->msize - IOHDRSZ; + if(n > msize) + n = msize; + tx.type = Tread; + tx.fid = fid->fid; + if(offset == -1){ + qlock(&fid->lk); + tx.offset = fid->offset; + qunlock(&fid->lk); + }else + tx.offset = offset; + tx.count = n; + + if(_fsrpc(fid->fs, &tx, &rx, &freep) < 0) + return -1; + if(rx.type == Rerror){ + werrstr("%s", rx.ename); + free(freep); + return -1; + } + if(rx.count){ + memmove(buf, rx.data, rx.count); + if(offset == -1){ + qlock(&fid->lk); + fid->offset += rx.count; + qunlock(&fid->lk); + } + } + free(freep); + + return rx.count; +} + +long +fsread(CFid *fid, void *buf, long n) +{ + return fspread(fid, buf, n, -1); +} + +long +fsreadn(CFid *fid, void *buf, long n) +{ + long tot, nn; + + for(tot=0; tot<n; tot+=nn){ + nn = fsread(fid, (char*)buf+tot, n-tot); + if(nn <= 0){ + if(tot == 0) + return nn; + break; + } + } + return tot; +} + + |