From d3df308747ee4d1fcc063a348dcf1146b390bda7 Mon Sep 17 00:00:00 2001 From: rsc Date: Sat, 6 Dec 2003 18:08:52 +0000 Subject: File system stuff. --- src/libfs/write.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 src/libfs/write.c (limited to 'src/libfs/write.c') diff --git a/src/libfs/write.c b/src/libfs/write.c new file mode 100644 index 00000000..96ecfa86 --- /dev/null +++ b/src/libfs/write.c @@ -0,0 +1,46 @@ +/* Copyright (C) 2003 Russ Cox, Massachusetts Institute of Technology */ +/* See COPYRIGHT */ + +#include +#include +#include +#include +#include "fsimpl.h" + +long +fspwrite(Fid *fd, void *buf, long n, vlong offset) +{ + Fcall tx, rx; + void *freep; + + tx.type = Tread; + if(offset == -1){ + qlock(&fd->lk); + tx.offset = fd->offset; + fd->offset += n; + qunlock(&fd->lk); + }else + tx.offset = offset; + tx.count = n; + tx.data = buf; + + fsrpc(fd->fs, &tx, &rx, &freep); + if(rx.type == Rerror){ + if(offset == -1){ + qlock(&fd->lk); + fd->offset -= n; + qunlock(&fd->lk); + } + werrstr("%s", rx.ename); + free(freep); + return -1; + } + free(freep); + return rx.count; +} + +long +fswrite(Fid *fd, void *buf, long n) +{ + return fspwrite(fd, buf, n, -1); +} -- cgit v1.2.3