forked from len0rd/rockbox
Now supports multiple concurrent opendir()
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@727 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
9e7ee96b6e
commit
3d25f7825a
2 changed files with 37 additions and 20 deletions
|
|
@ -17,15 +17,16 @@
|
||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <errno.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include "fat.h"
|
#include "fat.h"
|
||||||
#include "dir.h"
|
#include "dir.h"
|
||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
|
|
||||||
static DIR thedir;
|
#define MAX_OPEN_DIRS 8
|
||||||
static struct dirent theent;
|
|
||||||
static bool busy=false;
|
static DIR opendirs[MAX_OPEN_DIRS];
|
||||||
|
|
||||||
DIR* opendir(char* name)
|
DIR* opendir(char* name)
|
||||||
{
|
{
|
||||||
|
|
@ -33,20 +34,30 @@ DIR* opendir(char* name)
|
||||||
char* part;
|
char* part;
|
||||||
char* end;
|
char* end;
|
||||||
struct fat_direntry entry;
|
struct fat_direntry entry;
|
||||||
struct fat_dir* dir = &(thedir.fatdir);
|
int dd;
|
||||||
|
|
||||||
if ( busy ) {
|
/* find a free dir descriptor */
|
||||||
DEBUGF("Only one open dir at a time\n");
|
for ( dd=0; dd<MAX_OPEN_DIRS; dd++ )
|
||||||
|
if ( !opendirs[dd].busy )
|
||||||
|
break;
|
||||||
|
|
||||||
|
if ( dd == MAX_OPEN_DIRS ) {
|
||||||
|
DEBUGF("Too many dirs open\n");
|
||||||
|
errno = EMFILE;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
opendirs[dd].busy = true;
|
||||||
|
|
||||||
if ( name[0] != '/' ) {
|
if ( name[0] != '/' ) {
|
||||||
DEBUGF("Only absolute paths supported right now\n");
|
DEBUGF("Only absolute paths supported right now\n");
|
||||||
|
opendirs[dd].busy = false;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( fat_opendir(dir, 0) < 0 ) {
|
if ( fat_opendir(&(opendirs[dd].fatdir), 0) < 0 ) {
|
||||||
DEBUGF("Failed opening root dir\n");
|
DEBUGF("Failed opening root dir\n");
|
||||||
|
opendirs[dd].busy = false;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -58,15 +69,18 @@ DIR* opendir(char* name)
|
||||||
int partlen = strlen(part);
|
int partlen = strlen(part);
|
||||||
/* scan dir for name */
|
/* scan dir for name */
|
||||||
while (1) {
|
while (1) {
|
||||||
if (fat_getnext(dir,&entry) < 0)
|
if ((fat_getnext(&(opendirs[dd].fatdir),&entry) < 0) ||
|
||||||
return NULL;
|
(!entry.name[0])) {
|
||||||
if ( !entry.name[0] )
|
opendirs[dd].busy = false;
|
||||||
return NULL;
|
return NULL;
|
||||||
|
}
|
||||||
if ( (entry.attr & FAT_ATTR_DIRECTORY) &&
|
if ( (entry.attr & FAT_ATTR_DIRECTORY) &&
|
||||||
(!strncmp(part, entry.name, partlen)) ) {
|
(!strncmp(part, entry.name, partlen)) ) {
|
||||||
if ( fat_opendir(dir, entry.firstcluster) < 0 ) {
|
if ( fat_opendir(&(opendirs[dd].fatdir),
|
||||||
|
entry.firstcluster) < 0 ) {
|
||||||
DEBUGF("Failed opening dir '%s' (%d)\n",
|
DEBUGF("Failed opening dir '%s' (%d)\n",
|
||||||
part, entry.firstcluster);
|
part, entry.firstcluster);
|
||||||
|
opendirs[dd].busy = false;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
@ -74,20 +88,19 @@ DIR* opendir(char* name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
busy = true;
|
return &opendirs[dd];
|
||||||
|
|
||||||
return &thedir;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int closedir(DIR* dir)
|
int closedir(DIR* dir)
|
||||||
{
|
{
|
||||||
busy=false;
|
dir->busy=false;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct dirent* readdir(DIR* dir)
|
struct dirent* readdir(DIR* dir)
|
||||||
{
|
{
|
||||||
struct fat_direntry entry;
|
struct fat_direntry entry;
|
||||||
|
struct dirent* theent = &(dir->theent);
|
||||||
|
|
||||||
if (fat_getnext(&(dir->fatdir),&entry) < 0)
|
if (fat_getnext(&(dir->fatdir),&entry) < 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
@ -95,12 +108,12 @@ struct dirent* readdir(DIR* dir)
|
||||||
if ( !entry.name[0] )
|
if ( !entry.name[0] )
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
strncpy(theent.d_name, entry.name, sizeof( theent.d_name ) );
|
strncpy(theent->d_name, entry.name, sizeof( theent->d_name ) );
|
||||||
theent.attribute = entry.attr;
|
theent->attribute = entry.attr;
|
||||||
theent.size = entry.filesize;
|
theent->size = entry.filesize;
|
||||||
theent.startcluster = entry.firstcluster;
|
theent->startcluster = entry.firstcluster;
|
||||||
|
|
||||||
return &theent;
|
return theent;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,8 @@
|
||||||
#ifndef _DIR_H_
|
#ifndef _DIR_H_
|
||||||
#define _DIR_H_
|
#define _DIR_H_
|
||||||
|
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
#ifndef DIRENT_DEFINED
|
#ifndef DIRENT_DEFINED
|
||||||
|
|
||||||
#define ATTR_READ_ONLY 0x01
|
#define ATTR_READ_ONLY 0x01
|
||||||
|
|
@ -42,8 +44,10 @@ struct dirent {
|
||||||
#include "fat.h"
|
#include "fat.h"
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
bool busy;
|
||||||
int startcluster;
|
int startcluster;
|
||||||
struct fat_dir fatdir;
|
struct fat_dir fatdir;
|
||||||
|
struct dirent theent;
|
||||||
} DIR;
|
} DIR;
|
||||||
|
|
||||||
#else // SIMULATOR
|
#else // SIMULATOR
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue