diff options
author | Björn Stenberg <bjorn@haxx.se> | 2002-05-03 15:36:52 +0000 |
---|---|---|
committer | Björn Stenberg <bjorn@haxx.se> | 2002-05-03 15:36:52 +0000 |
commit | 4d4ec3aa0b2c0bb45e7c004885accee303f1277f (patch) | |
tree | fd6432a02c7f2c0e9e0124c51f678ee5f4c1edb1 /firmware/common | |
parent | 924164e6a7b4a97d248a07928b8b9f22bf5aec0b (diff) | |
download | rockbox-4d4ec3aa0b2c0bb45e7c004885accee303f1277f.tar.gz rockbox-4d4ec3aa0b2c0bb45e7c004885accee303f1277f.zip |
Added opendir, closedir and readdir
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@412 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware/common')
-rw-r--r-- | firmware/common/dir.c | 97 | ||||
-rw-r--r-- | firmware/common/dir.h | 9 |
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 | |||
26 | static DIR thedir; | ||
27 | static struct dirent theent; | ||
28 | static bool busy=FALSE; | ||
29 | |||
30 | DIR* 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 | |||
76 | int closedir(DIR* dir) | ||
77 | { | ||
78 | busy=FALSE; | ||
79 | return 0; | ||
80 | } | ||
81 | |||
82 | struct 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 | |||
34 | typedef struct { | 36 | typedef 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> |
40 | typedef struct DIRtag | 45 | typedef struct DIRtag |