aboutsummaryrefslogtreecommitdiff
path: root/src/libfs/read.c
diff options
context:
space:
mode:
authorrsc <devnull@localhost>2003-12-06 18:08:52 +0000
committerrsc <devnull@localhost>2003-12-06 18:08:52 +0000
commitd3df308747ee4d1fcc063a348dcf1146b390bda7 (patch)
treea204b027256ec29b110caaa86100cbd701808b5b /src/libfs/read.c
parente97ceade5e1bba5787e39429384336fa37797906 (diff)
downloadplan9port-d3df308747ee4d1fcc063a348dcf1146b390bda7.tar.gz
plan9port-d3df308747ee4d1fcc063a348dcf1146b390bda7.tar.bz2
plan9port-d3df308747ee4d1fcc063a348dcf1146b390bda7.zip
File system stuff.
Diffstat (limited to 'src/libfs/read.c')
-rw-r--r--src/libfs/read.c48
1 files changed, 48 insertions, 0 deletions
diff --git a/src/libfs/read.c b/src/libfs/read.c
new file mode 100644
index 00000000..ca6c628c
--- /dev/null
+++ b/src/libfs/read.c
@@ -0,0 +1,48 @@
+/* Copyright (C) 2003 Russ Cox, Massachusetts Institute of Technology */
+/* See COPYRIGHT */
+
+#include <u.h>
+#include <libc.h>
+#include <fcall.h>
+#include <fs.h>
+#include "fsimpl.h"
+
+long
+fspread(Fid *fid, void *buf, long n, vlong offset)
+{
+ Fcall tx, rx;
+ void *freep;
+
+ tx.type = Tread;
+ if(offset == -1){
+ qlock(&fid->lk);
+ tx.offset = fid->offset;
+ qunlock(&fid->lk);
+ }else
+ tx.offset = offset;
+ tx.count = n;
+
+ fsrpc(fid->fs, &tx, &rx, &freep);
+ 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);
+ tx.offset += n;
+ qunlock(&fid->lk);
+ }
+ }
+ free(freep);
+
+ return rx.count;
+}
+
+long
+fsread(Fid *fid, void *buf, long n)
+{
+ return fspread(fid, buf, n, -1);
+}