diff options
Diffstat (limited to 'firmware')
-rw-r--r-- | firmware/common/dir.c | 40 |
1 files changed, 20 insertions, 20 deletions
diff --git a/firmware/common/dir.c b/firmware/common/dir.c index 9f5f082b56..21c5f0100e 100644 --- a/firmware/common/dir.c +++ b/firmware/common/dir.c | |||
@@ -74,13 +74,19 @@ DIR* opendir(const char* name) | |||
74 | char* end; | 74 | char* end; |
75 | struct fat_direntry entry; | 75 | struct fat_direntry entry; |
76 | int dd; | 76 | int dd; |
77 | DIR* pdir = opendirs; | ||
77 | #ifdef HAVE_MULTIVOLUME | 78 | #ifdef HAVE_MULTIVOLUME |
78 | int volume; | 79 | int volume; |
79 | #endif | 80 | #endif |
80 | 81 | ||
82 | if ( name[0] != '/' ) { | ||
83 | DEBUGF("Only absolute paths supported right now\n"); | ||
84 | return NULL; | ||
85 | } | ||
86 | |||
81 | /* find a free dir descriptor */ | 87 | /* find a free dir descriptor */ |
82 | for ( dd=0; dd<MAX_OPEN_DIRS; dd++ ) | 88 | for ( dd=0; dd<MAX_OPEN_DIRS; dd++, pdir++) |
83 | if ( !opendirs[dd].busy ) | 89 | if ( !pdir->busy ) |
84 | break; | 90 | break; |
85 | 91 | ||
86 | if ( dd == MAX_OPEN_DIRS ) { | 92 | if ( dd == MAX_OPEN_DIRS ) { |
@@ -89,26 +95,20 @@ DIR* opendir(const char* name) | |||
89 | return NULL; | 95 | return NULL; |
90 | } | 96 | } |
91 | 97 | ||
92 | opendirs[dd].busy = true; | 98 | pdir->busy = true; |
93 | |||
94 | if ( name[0] != '/' ) { | ||
95 | DEBUGF("Only absolute paths supported right now\n"); | ||
96 | opendirs[dd].busy = false; | ||
97 | return NULL; | ||
98 | } | ||
99 | 99 | ||
100 | #ifdef HAVE_MULTIVOLUME | 100 | #ifdef HAVE_MULTIVOLUME |
101 | /* try to extract a heading volume name, if present */ | 101 | /* try to extract a heading volume name, if present */ |
102 | volume = strip_volume(name, namecopy); | 102 | volume = strip_volume(name, namecopy); |
103 | opendirs[dd].volumecounter = 0; | 103 | pdir->volumecounter = 0; |
104 | #else | 104 | #else |
105 | strncpy(namecopy,name,sizeof(namecopy)); /* just copy */ | 105 | strncpy(namecopy,name,sizeof(namecopy)); /* just copy */ |
106 | namecopy[sizeof(namecopy)-1] = '\0'; | 106 | namecopy[sizeof(namecopy)-1] = '\0'; |
107 | #endif | 107 | #endif |
108 | 108 | ||
109 | if ( fat_opendir(IF_MV2(volume,) &(opendirs[dd].fatdir), 0, NULL) < 0 ) { | 109 | if ( fat_opendir(IF_MV2(volume,) &pdir->fatdir, 0, NULL) < 0 ) { |
110 | DEBUGF("Failed opening root dir\n"); | 110 | DEBUGF("Failed opening root dir\n"); |
111 | opendirs[dd].busy = false; | 111 | pdir->busy = false; |
112 | return NULL; | 112 | return NULL; |
113 | } | 113 | } |
114 | 114 | ||
@@ -116,32 +116,32 @@ DIR* opendir(const char* name) | |||
116 | part = strtok_r(NULL, "/", &end)) { | 116 | part = strtok_r(NULL, "/", &end)) { |
117 | /* scan dir for name */ | 117 | /* scan dir for name */ |
118 | while (1) { | 118 | while (1) { |
119 | if ((fat_getnext(&(opendirs[dd].fatdir),&entry) < 0) || | 119 | if ((fat_getnext(&pdir->fatdir,&entry) < 0) || |
120 | (!entry.name[0])) { | 120 | (!entry.name[0])) { |
121 | opendirs[dd].busy = false; | 121 | pdir->busy = false; |
122 | return NULL; | 122 | return NULL; |
123 | } | 123 | } |
124 | if ( (entry.attr & FAT_ATTR_DIRECTORY) && | 124 | if ( (entry.attr & FAT_ATTR_DIRECTORY) && |
125 | (!strcasecmp(part, entry.name)) ) { | 125 | (!strcasecmp(part, entry.name)) ) { |
126 | opendirs[dd].parent_dir = opendirs[dd].fatdir; | 126 | pdir->parent_dir = pdir->fatdir; |
127 | if ( fat_opendir(IF_MV2(volume,) | 127 | if ( fat_opendir(IF_MV2(volume,) |
128 | &(opendirs[dd].fatdir), | 128 | &pdir->fatdir, |
129 | entry.firstcluster, | 129 | entry.firstcluster, |
130 | &(opendirs[dd].parent_dir)) < 0 ) { | 130 | &pdir->parent_dir) < 0 ) { |
131 | DEBUGF("Failed opening dir '%s' (%d)\n", | 131 | DEBUGF("Failed opening dir '%s' (%d)\n", |
132 | part, entry.firstcluster); | 132 | part, entry.firstcluster); |
133 | opendirs[dd].busy = false; | 133 | pdir->busy = false; |
134 | return NULL; | 134 | return NULL; |
135 | } | 135 | } |
136 | #ifdef HAVE_MULTIVOLUME | 136 | #ifdef HAVE_MULTIVOLUME |
137 | opendirs[dd].volumecounter = -1; /* n.a. to subdirs */ | 137 | pdir->volumecounter = -1; /* n.a. to subdirs */ |
138 | #endif | 138 | #endif |
139 | break; | 139 | break; |
140 | } | 140 | } |
141 | } | 141 | } |
142 | } | 142 | } |
143 | 143 | ||
144 | return &opendirs[dd]; | 144 | return pdir; |
145 | } | 145 | } |
146 | 146 | ||
147 | int closedir(DIR* dir) | 147 | int closedir(DIR* dir) |