Apparently on some versions of OS X,
once readdir returns nil once, it automatically
rewinds and starts reading from the beginning
of the directory.
U9fs has always assumed that once you hit the end
of the directory, readdir will repeatedly return nil
(at least twice). Remove this assumption.
--
/sys/src/cmd/unix/u9fs/u9fs.c
u9fs.c.orig:60,65 - /n/sources/patch/applied/u9fs-eof/u9fs.c:60,66
int diroffset;
int fd;
struct dirent *dirent;
+ int direof;
Fid *next;
Fid *prev;
int auth;
u9fs.c.orig:739,745 - /n/sources/patch/applied/u9fs-eof/u9fs.c:740,751
}
rewinddir(fid->dir);
fid->diroffset = 0;
+ fid->direof = 0;
}
+ if(fid->direof){
+ tx->count = 0;
+ return;
+ }
p = (uchar*)tx->data;
ep = (uchar*)tx->data+rx->count;
u9fs.c.orig:747,754 - /n/sources/patch/applied/u9fs-eof/u9fs.c:753,762
if(p+BIT16SZ >= ep)
break;
if(fid->dirent == nil) /* one entry cache for when convD2M fails */
- if((fid->dirent = readdir(fid->dir)) == nil)
+ if((fid->dirent = readdir(fid->dir)) == nil){
+ fid->direof = 1;
break;
+ }
if(strcmp(fid->dirent->d_name, ".") == 0
|| strcmp(fid->dirent->d_name, "..") == 0){
fid->dirent = nil;