lib9p: allow rewinding in 9pfile directories

front
cinap_lenrek 2017-04-30 01:49:21 +02:00
parent 56611ced39
commit f8478eb4c4
4 changed files with 10 additions and 6 deletions

View File

@ -162,7 +162,7 @@ int removefile(File*);
void closefile(File*); void closefile(File*);
File* walkfile(File*, char*); File* walkfile(File*, char*);
Readdir* opendirfile(File*); Readdir* opendirfile(File*);
long readdirfile(Readdir*, uchar*, long); long readdirfile(Readdir*, uchar*, long, long);
void closedirfile(Readdir*); void closedirfile(Readdir*);
/* /*

View File

@ -47,7 +47,7 @@ int removefile(File *file)
void closefile(File *file) void closefile(File *file)
File* walkfile(File *dir, char *path) File* walkfile(File *dir, char *path)
Readdir* opendirfile(File *dir) Readdir* opendirfile(File *dir)
long readdirfile(Readdir *rdir, uchar *buf, long n) long readdirfile(Readdir *rdir, uchar *buf, long n, long o)
void closedirfile(Readdir *rdir) void closedirfile(Readdir *rdir)
int hasperm(File *file, char *uid, int p) int hasperm(File *file, char *uid, int p)
.fi .fi

View File

@ -394,12 +394,16 @@ opendirfile(File *dir)
} }
long long
readdirfile(Readdir *r, uchar *buf, long n) readdirfile(Readdir *r, uchar *buf, long n, long o)
{ {
long x, m; long x, m;
Filelist *fl; Filelist *fl;
for(fl=r->fl, m=0; fl && m+2<=n; fl=fl->link, m+=x){ if(o == 0)
fl = r->dir->filelist;
else
fl = r->fl;
for(m=0; fl && m+2<=n; fl=fl->link, m+=x){
if(fl->f == nil) if(fl->f == nil)
x = 0; x = 0;
else if((x=convD2M(fl->f, buf+m, n-m)) <= BIT16SZ) else if((x=convD2M(fl->f, buf+m, n-m)) <= BIT16SZ)

View File

@ -512,7 +512,7 @@ sread(Srv *srv, Req *r)
return; return;
} }
if((r->fid->qid.type&QTDIR) && r->fid->file){ if((r->fid->qid.type&QTDIR) && r->fid->file){
r->ofcall.count = readdirfile(r->fid->rdir, r->rbuf, r->ifcall.count); r->ofcall.count = readdirfile(r->fid->rdir, r->rbuf, r->ifcall.count, r->ifcall.offset);
respond(r, nil); respond(r, nil);
return; return;
} }
@ -525,7 +525,7 @@ static void
rread(Req *r, char *error) rread(Req *r, char *error)
{ {
if(error==nil && (r->fid->qid.type&QTDIR)) if(error==nil && (r->fid->qid.type&QTDIR))
r->fid->diroffset += r->ofcall.count; r->fid->diroffset = r->ifcall.offset + r->ofcall.count;
} }
static void static void