summaryrefslogtreecommitdiff
path: root/firmware
diff options
context:
space:
mode:
authorBjörn Stenberg <bjorn@haxx.se>2002-05-27 09:13:24 +0000
committerBjörn Stenberg <bjorn@haxx.se>2002-05-27 09:13:24 +0000
commit3d25f7825a7e3df85a8077aec8b7bbce5fde8dfa (patch)
tree5bdbad1bfbd2215f1e4bbaa4e31a8f95f59956dd /firmware
parent9e7ee96b6eccb1060a56375ce19f0a0bdc0471b7 (diff)
downloadrockbox-3d25f7825a7e3df85a8077aec8b7bbce5fde8dfa.tar.gz
rockbox-3d25f7825a7e3df85a8077aec8b7bbce5fde8dfa.zip
Now supports multiple concurrent opendir()
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@727 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware')
-rw-r--r--firmware/common/dir.c53
-rw-r--r--firmware/common/dir.h4
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 @@
17 * 17 *
18 ****************************************************************************/ 18 ****************************************************************************/
19#include <stdio.h> 19#include <stdio.h>
20#include <errno.h>
20#include <string.h> 21#include <string.h>
21#include <stdbool.h> 22#include <stdbool.h>
22#include "fat.h" 23#include "fat.h"
23#include "dir.h" 24#include "dir.h"
24#include "debug.h" 25#include "debug.h"
25 26
26static DIR thedir; 27#define MAX_OPEN_DIRS 8
27static struct dirent theent; 28
28static bool busy=false; 29static DIR opendirs[MAX_OPEN_DIRS];
29 30
30DIR* opendir(char* name) 31DIR* opendir(char* name)
31{ 32{
@@ -33,20 +34,30 @@ DIR* opendir(char* name)
33 char* part; 34 char* part;
34 char* end; 35 char* end;
35 struct fat_direntry entry; 36 struct fat_direntry entry;
36 struct fat_dir* dir = &(thedir.fatdir); 37 int dd;
38
39 /* find a free dir descriptor */
40 for ( dd=0; dd<MAX_OPEN_DIRS; dd++ )
41 if ( !opendirs[dd].busy )
42 break;
37 43
38 if ( busy ) { 44 if ( dd == MAX_OPEN_DIRS ) {
39 DEBUGF("Only one open dir at a time\n"); 45 DEBUGF("Too many dirs open\n");
46 errno = EMFILE;
40 return NULL; 47 return NULL;
41 } 48 }
42 49
50 opendirs[dd].busy = true;
51
43 if ( name[0] != '/' ) { 52 if ( name[0] != '/' ) {
44 DEBUGF("Only absolute paths supported right now\n"); 53 DEBUGF("Only absolute paths supported right now\n");
54 opendirs[dd].busy = false;
45 return NULL; 55 return NULL;
46 } 56 }
47 57
48 if ( fat_opendir(dir, 0) < 0 ) { 58 if ( fat_opendir(&(opendirs[dd].fatdir), 0) < 0 ) {
49 DEBUGF("Failed opening root dir\n"); 59 DEBUGF("Failed opening root dir\n");
60 opendirs[dd].busy = false;
50 return NULL; 61 return NULL;
51 } 62 }
52 63
@@ -58,15 +69,18 @@ DIR* opendir(char* name)
58 int partlen = strlen(part); 69 int partlen = strlen(part);
59 /* scan dir for name */ 70 /* scan dir for name */
60 while (1) { 71 while (1) {
61 if (fat_getnext(dir,&entry) < 0) 72 if ((fat_getnext(&(opendirs[dd].fatdir),&entry) < 0) ||
62 return NULL; 73 (!entry.name[0])) {
63 if ( !entry.name[0] ) 74 opendirs[dd].busy = false;
64 return NULL; 75 return NULL;
76 }
65 if ( (entry.attr & FAT_ATTR_DIRECTORY) && 77 if ( (entry.attr & FAT_ATTR_DIRECTORY) &&
66 (!strncmp(part, entry.name, partlen)) ) { 78 (!strncmp(part, entry.name, partlen)) ) {
67 if ( fat_opendir(dir, entry.firstcluster) < 0 ) { 79 if ( fat_opendir(&(opendirs[dd].fatdir),
80 entry.firstcluster) < 0 ) {
68 DEBUGF("Failed opening dir '%s' (%d)\n", 81 DEBUGF("Failed opening dir '%s' (%d)\n",
69 part, entry.firstcluster); 82 part, entry.firstcluster);
83 opendirs[dd].busy = false;
70 return NULL; 84 return NULL;
71 } 85 }
72 break; 86 break;
@@ -74,20 +88,19 @@ DIR* opendir(char* name)
74 } 88 }
75 } 89 }
76 90
77 busy = true; 91 return &opendirs[dd];
78
79 return &thedir;
80} 92}
81 93
82int closedir(DIR* dir) 94int closedir(DIR* dir)
83{ 95{
84 busy=false; 96 dir->busy=false;
85 return 0; 97 return 0;
86} 98}
87 99
88struct dirent* readdir(DIR* dir) 100struct dirent* readdir(DIR* dir)
89{ 101{
90 struct fat_direntry entry; 102 struct fat_direntry entry;
103 struct dirent* theent = &(dir->theent);
91 104
92 if (fat_getnext(&(dir->fatdir),&entry) < 0) 105 if (fat_getnext(&(dir->fatdir),&entry) < 0)
93 return NULL; 106 return NULL;
@@ -95,12 +108,12 @@ struct dirent* readdir(DIR* dir)
95 if ( !entry.name[0] ) 108 if ( !entry.name[0] )
96 return NULL; 109 return NULL;
97 110
98 strncpy(theent.d_name, entry.name, sizeof( theent.d_name ) ); 111 strncpy(theent->d_name, entry.name, sizeof( theent->d_name ) );
99 theent.attribute = entry.attr; 112 theent->attribute = entry.attr;
100 theent.size = entry.filesize; 113 theent->size = entry.filesize;
101 theent.startcluster = entry.firstcluster; 114 theent->startcluster = entry.firstcluster;
102 115
103 return &theent; 116 return theent;
104} 117}
105 118
106/* 119/*
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 @@
19#ifndef _DIR_H_ 19#ifndef _DIR_H_
20#define _DIR_H_ 20#define _DIR_H_
21 21
22#include <stdbool.h>
23
22#ifndef DIRENT_DEFINED 24#ifndef DIRENT_DEFINED
23 25
24#define ATTR_READ_ONLY 0x01 26#define ATTR_READ_ONLY 0x01
@@ -42,8 +44,10 @@ struct dirent {
42#include "fat.h" 44#include "fat.h"
43 45
44typedef struct { 46typedef struct {
47 bool busy;
45 int startcluster; 48 int startcluster;
46 struct fat_dir fatdir; 49 struct fat_dir fatdir;
50 struct dirent theent;
47} DIR; 51} DIR;
48 52
49#else // SIMULATOR 53#else // SIMULATOR