summaryrefslogtreecommitdiff
path: root/firmware/common
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/common')
-rw-r--r--firmware/common/dir.c97
-rw-r--r--firmware/common/dir.h9
2 files changed, 104 insertions, 2 deletions
diff --git a/firmware/common/dir.c b/firmware/common/dir.c
new file mode 100644
index 0000000000..9388fb243a
--- /dev/null
+++ b/firmware/common/dir.c
@@ -0,0 +1,97 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2002 by Björn Stenberg
11 *
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
14 *
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
17 *
18 ****************************************************************************/
19#include <stdio.h>
20#include <string.h>
21#include "fat.h"
22#include "dir.h"
23#include "debug.h"
24#include "types.h"
25
26static DIR thedir;
27static struct dirent theent;
28static bool busy=FALSE;
29
30DIR* opendir(char* name)
31{
32 char* part;
33 struct fat_direntry entry;
34 struct fat_dir* dir = &(thedir.fatdir);
35
36 if ( busy ) {
37 DEBUGF("Only one open dir at a time\n");
38 return NULL;
39 }
40
41 if ( name[0] != '/' ) {
42 DEBUGF("Only absolute paths supported right now\n");
43 return NULL;
44 }
45
46 if ( fat_opendir(dir, 0) < 0 ) {
47 DEBUGF("Failed opening root dir\n");
48 return NULL;
49 }
50
51 while ( (part = strtok(name, "/")) ) {
52 int partlen = strlen(part);
53 /* scan dir for name */
54 while (1) {
55 if (fat_getnext(dir,&entry) < 0)
56 return NULL;
57 if ( !entry.name[0] )
58 return NULL;
59 if ( (entry.attr & FAT_ATTR_DIRECTORY) &&
60 (!strncmp(part, entry.name, partlen)) ) {
61 if ( fat_opendir(dir, entry.firstcluster) < 0 ) {
62 DEBUGF("Failed opening dir '%s' (%d)\n",
63 part, entry.firstcluster);
64 return NULL;
65 }
66 break;
67 }
68 }
69 }
70
71 busy = TRUE;
72
73 return &thedir;
74}
75
76int closedir(DIR* dir)
77{
78 busy=FALSE;
79 return 0;
80}
81
82struct dirent* readdir(DIR* dir)
83{
84 struct fat_direntry entry;
85
86 if (fat_getnext(&(dir->fatdir),&entry) < 0)
87 return NULL;
88
89 if ( !entry.name[0] )
90 return NULL;
91
92 strncpy(theent.d_name, entry.name, sizeof( theent.d_name ) );
93 theent.attribute = entry.attr;
94 theent.size = entry.filesize;
95
96 return &theent;
97}
diff --git a/firmware/common/dir.h b/firmware/common/dir.h
index 078ede2d73..2aa248579e 100644
--- a/firmware/common/dir.h
+++ b/firmware/common/dir.h
@@ -16,7 +16,6 @@
16 * KIND, either express or implied. 16 * KIND, either express or implied.
17 * 17 *
18 ****************************************************************************/ 18 ****************************************************************************/
19
20#ifndef _DIR_H_ 19#ifndef _DIR_H_
21#define _DIR_H_ 20#define _DIR_H_
22 21
@@ -31,10 +30,16 @@ struct dirent {
31 30
32 31
33#ifndef SIMULATOR 32#ifndef SIMULATOR
33
34#include "fat.h"
35
34typedef struct { 36typedef struct {
35 int offset; 37 int startcluster;
38 struct fat_dir fatdir;
36} DIR; 39} DIR;
40
37#else // SIMULATOR 41#else // SIMULATOR
42
38#ifdef WIN32 43#ifdef WIN32
39#include <io.h> 44#include <io.h>
40typedef struct DIRtag 45typedef struct DIRtag