add fsseek
This commit is contained in:
parent
0fcd970331
commit
daefa1a92f
3 changed files with 50 additions and 0 deletions
|
|
@ -22,6 +22,9 @@ CFid *fsopen(CFsys*, char*, int);
|
||||||
int fsopenfd(CFsys*, char*, int);
|
int fsopenfd(CFsys*, char*, int);
|
||||||
long fsread(CFid*, void*, long);
|
long fsread(CFid*, void*, long);
|
||||||
long fsreadn(CFid*, void*, long);
|
long fsreadn(CFid*, void*, long);
|
||||||
|
long fspread(CFid*, void*, long, vlong);
|
||||||
|
long fspwrite(CFid*, void*, long, vlong);
|
||||||
|
vlong fsseek(CFid*, vlong, int);
|
||||||
long fswrite(CFid*, void*, long);
|
long fswrite(CFid*, void*, long);
|
||||||
void fsclose(CFid*);
|
void fsclose(CFid*);
|
||||||
void fsunmount(CFsys*);
|
void fsunmount(CFsys*);
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@ OFILES=\
|
||||||
open.$O\
|
open.$O\
|
||||||
openfd.$O\
|
openfd.$O\
|
||||||
read.$O\
|
read.$O\
|
||||||
|
seek.$O\
|
||||||
stat.$O\
|
stat.$O\
|
||||||
walk.$O\
|
walk.$O\
|
||||||
write.$O\
|
write.$O\
|
||||||
|
|
|
||||||
46
src/lib9pclient/seek.c
Normal file
46
src/lib9pclient/seek.c
Normal file
|
|
@ -0,0 +1,46 @@
|
||||||
|
#include <u.h>
|
||||||
|
#include <libc.h>
|
||||||
|
#include <fcall.h>
|
||||||
|
#include <9pclient.h>
|
||||||
|
#include "fsimpl.h"
|
||||||
|
|
||||||
|
vlong
|
||||||
|
fsseek(CFid *fid, vlong n, int whence)
|
||||||
|
{
|
||||||
|
Dir *d;
|
||||||
|
|
||||||
|
switch(whence){
|
||||||
|
case 0:
|
||||||
|
qlock(&fid->lk);
|
||||||
|
fid->offset = n;
|
||||||
|
qunlock(&fid->lk);
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
qlock(&fid->lk);
|
||||||
|
n += fid->offset;
|
||||||
|
if(n < 0){
|
||||||
|
qunlock(&fid->lk);
|
||||||
|
werrstr("negative offset");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
fid->offset = n;
|
||||||
|
qunlock(&fid->lk);
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
if((d = fsdirfstat(fid)) == nil)
|
||||||
|
return -1;
|
||||||
|
n += d->length;
|
||||||
|
if(n < 0){
|
||||||
|
werrstr("negative offset");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
qlock(&fid->lk);
|
||||||
|
fid->offset = n;
|
||||||
|
qunlock(&fid->lk);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
werrstr("bad whence in fsseek");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return n;
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue