Getdents implementation in library/vfs/mfs.
Changed readdir, etc. to use getdents
This commit is contained in:
@@ -44,7 +44,6 @@ DIR *opendir(const char *name)
|
||||
}
|
||||
|
||||
dp->_fd= d;
|
||||
dp->_v7= -1;
|
||||
dp->_count= 0;
|
||||
dp->_pos= 0;
|
||||
|
||||
|
||||
+24
-38
@@ -2,58 +2,44 @@
|
||||
* 24 Apr 1989
|
||||
*/
|
||||
#define nil 0
|
||||
#include <lib.h>
|
||||
#define read _read
|
||||
#define readdir _readdir
|
||||
#define readdir _readdir
|
||||
#define getdents _getdents
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <dirent.h>
|
||||
#include <unistd.h>
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
#include <fcntl.h>
|
||||
#include <limits.h>
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
|
||||
#define v7ent(p) ((struct _v7_direct *) (p))
|
||||
#define V7_EXTENT (sizeof(struct _v7_direct) / sizeof(struct _fl_direct) - 1)
|
||||
|
||||
struct dirent *readdir(DIR *dp)
|
||||
/* Return the next entry in a directory. Handle V7 and FLEX format dirs. */
|
||||
/* Return the next entry in a directory. */
|
||||
{
|
||||
struct dirent *e;
|
||||
struct dirent *entp;
|
||||
int count, pos, reclen;
|
||||
|
||||
if (dp == nil) { errno= EBADF; return nil; }
|
||||
|
||||
do {
|
||||
if (dp->_count <= 0) {
|
||||
/* Read the next directory block. */
|
||||
dp->_count= read(dp->_fd, dp->_buf, sizeof(dp->_buf));
|
||||
if (dp->_count <= 0) return nil;
|
||||
count= dp->_count;
|
||||
pos= dp->_pos;
|
||||
if (count == 0 || pos >= count)
|
||||
{
|
||||
count= getdents(dp->_fd, (struct dirent *)dp->_buf,
|
||||
sizeof(dp->_buf));
|
||||
if (count <= 0) return nil;
|
||||
dp->_count= count;
|
||||
dp->_pos= pos= 0;
|
||||
}
|
||||
entp= (struct dirent *)&((char *)dp->_buf)[pos];
|
||||
reclen= entp->d_reclen;
|
||||
dp->_pos= pos+reclen;
|
||||
|
||||
dp->_count/= sizeof(dp->_buf[0]);
|
||||
dp->_ptr= dp->_buf;
|
||||
|
||||
/* Extent is zero of the first flex entry. */
|
||||
if (dp->_v7 == (char)-1) dp->_v7= dp->_buf[0].d_extent;
|
||||
}
|
||||
|
||||
if (!dp->_v7) {
|
||||
/* FLEX. */
|
||||
e= (struct dirent *) dp->_ptr;
|
||||
} else {
|
||||
/* V7: transform to FLEX. */
|
||||
e= (struct dirent *) dp->_v7f;
|
||||
e->d_ino= v7ent(dp->_ptr)->d_ino;
|
||||
e->d_extent= V7_EXTENT;
|
||||
memcpy(e->d_name, v7ent(dp->_ptr)->d_name, DIRSIZ);
|
||||
e->d_name[DIRSIZ]= 0;
|
||||
}
|
||||
|
||||
dp->_ptr+= 1 + e->d_extent;
|
||||
dp->_count-= 1 + e->d_extent;
|
||||
dp->_pos+= (1 + e->d_extent) * sizeof(*dp->_ptr);
|
||||
|
||||
} while (e->d_ino == 0);
|
||||
return e;
|
||||
return entp;
|
||||
}
|
||||
|
||||
/*
|
||||
* $PchId: _readdir.c,v 1.6 2005/01/27 21:46:42 philip Exp $
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user