ref: f8478eb4c4a60d0deb9eb3276540d74f1866f878
parent: 56611ced3949dba491a6bc7d0271837b3808fb2f
author: cinap_lenrek <[email protected]>
date: Sat Apr 29 21:49:21 EDT 2017
lib9p: allow rewinding in 9pfile directories
--- a/sys/include/9p.h
+++ b/sys/include/9p.h
@@ -162,7 +162,7 @@
void closefile(File*);
File* walkfile(File*, char*);
Readdir* opendirfile(File*);
-long readdirfile(Readdir*, uchar*, long);
+long readdirfile(Readdir*, uchar*, long, long);
void closedirfile(Readdir*);
/*
--- a/sys/man/2/9pfile
+++ b/sys/man/2/9pfile
@@ -47,7 +47,7 @@
void closefile(File *file)
File* walkfile(File *dir, char *path)
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)
int hasperm(File *file, char *uid, int p)
.fi
--- a/sys/src/lib9p/file.c
+++ b/sys/src/lib9p/file.c
@@ -394,12 +394,16 @@
}
long
-readdirfile(Readdir *r, uchar *buf, long n)
+readdirfile(Readdir *r, uchar *buf, long n, long o)
{
long x, m;
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)
x = 0;
else if((x=convD2M(fl->f, buf+m, n-m)) <= BIT16SZ)
--- a/sys/src/lib9p/srv.c
+++ b/sys/src/lib9p/srv.c
@@ -512,7 +512,7 @@
return;
}
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);
return;
}
@@ -525,7 +525,7 @@
rread(Req *r, char *error)
{
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