From 3d25f7825a7e3df85a8077aec8b7bbce5fde8dfa Mon Sep 17 00:00:00 2001 From: Björn Stenberg Date: Mon, 27 May 2002 09:13:24 +0000 Subject: Now supports multiple concurrent opendir() git-svn-id: svn://svn.rockbox.org/rockbox/trunk@727 a1c6a512-1295-4272-9138-f99709370657 --- firmware/common/dir.c | 53 ++++++++++++++++++++++++++++++++------------------- firmware/common/dir.h | 4 ++++ 2 files changed, 37 insertions(+), 20 deletions(-) diff --git a/firmware/common/dir.c b/firmware/common/dir.c index e1f4c064a0..5fb1415fb0 100644 --- a/firmware/common/dir.c +++ b/firmware/common/dir.c @@ -17,15 +17,16 @@ * ****************************************************************************/ #include +#include #include #include #include "fat.h" #include "dir.h" #include "debug.h" -static DIR thedir; -static struct dirent theent; -static bool busy=false; +#define MAX_OPEN_DIRS 8 + +static DIR opendirs[MAX_OPEN_DIRS]; DIR* opendir(char* name) { @@ -33,20 +34,30 @@ DIR* opendir(char* name) char* part; char* end; struct fat_direntry entry; - struct fat_dir* dir = &(thedir.fatdir); + int dd; + + /* find a free dir descriptor */ + for ( dd=0; ddbusy=false; return 0; } struct dirent* readdir(DIR* dir) { struct fat_direntry entry; + struct dirent* theent = &(dir->theent); if (fat_getnext(&(dir->fatdir),&entry) < 0) return NULL; @@ -95,12 +108,12 @@ struct dirent* readdir(DIR* dir) if ( !entry.name[0] ) return NULL; - strncpy(theent.d_name, entry.name, sizeof( theent.d_name ) ); - theent.attribute = entry.attr; - theent.size = entry.filesize; - theent.startcluster = entry.firstcluster; + strncpy(theent->d_name, entry.name, sizeof( theent->d_name ) ); + theent->attribute = entry.attr; + theent->size = entry.filesize; + theent->startcluster = entry.firstcluster; - return &theent; + return theent; } /* diff --git a/firmware/common/dir.h b/firmware/common/dir.h index 274c0b1ea4..0cd35d063b 100644 --- a/firmware/common/dir.h +++ b/firmware/common/dir.h @@ -19,6 +19,8 @@ #ifndef _DIR_H_ #define _DIR_H_ +#include + #ifndef DIRENT_DEFINED #define ATTR_READ_ONLY 0x01 @@ -42,8 +44,10 @@ struct dirent { #include "fat.h" typedef struct { + bool busy; int startcluster; struct fat_dir fatdir; + struct dirent theent; } DIR; #else // SIMULATOR -- cgit v1.2.3