File system stuff.
This commit is contained in:
parent
e97ceade5e
commit
d3df308747
29 changed files with 3316 additions and 0 deletions
46
src/libfs/write.c
Normal file
46
src/libfs/write.c
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
/* 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 *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);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue