plan9port/src/libfs/write.c

47 lines
792 B
C
Raw Normal View History

2003-12-06 18:08:52 +00:00
/* 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
fspwrite(Fid *fid, void *buf, long n, vlong offset)
2003-12-06 18:08:52 +00:00
{
Fcall tx, rx;
void *freep;
tx.type = Twrite;
tx.fid = fid->fid;
2003-12-06 18:08:52 +00:00
if(offset == -1){
qlock(&fid->lk);
tx.offset = fid->offset;
qunlock(&fid->lk);
2003-12-06 18:08:52 +00:00
}else
tx.offset = offset;
tx.count = n;
tx.data = buf;
fsrpc(fid->fs, &tx, &rx, &freep);
2003-12-06 18:08:52 +00:00
if(rx.type == Rerror){
werrstr("%s", rx.ename);
free(freep);
return -1;
}
if(offset == -1 && rx.count){
qlock(&fid->lk);
fid->offset += rx.count;
qunlock(&fid->lk);
}
2003-12-06 18:08:52 +00:00
free(freep);
return rx.count;
}
long
fswrite(Fid *fid, void *buf, long n)
2003-12-06 18:08:52 +00:00
{
return fspwrite(fid, buf, n, -1);
2003-12-06 18:08:52 +00:00
}