diff options
Diffstat (limited to 'firmware/common/dircache.c')
-rw-r--r-- | firmware/common/dircache.c | 79 |
1 files changed, 34 insertions, 45 deletions
diff --git a/firmware/common/dircache.c b/firmware/common/dircache.c index 4ae8d805dd..509743bdbb 100644 --- a/firmware/common/dircache.c +++ b/firmware/common/dircache.c | |||
@@ -237,19 +237,19 @@ static int sab_process_dir(unsigned long startcluster, struct dircache_entry *ce | |||
237 | !strcmp("..", sab.direntry->name)) | 237 | !strcmp("..", sab.direntry->name)) |
238 | continue; | 238 | continue; |
239 | 239 | ||
240 | ce->attribute = sab.direntry->attr; | ||
241 | ce->name_len = strlen(sab.direntry->name) + 1; | 240 | ce->name_len = strlen(sab.direntry->name) + 1; |
242 | ce->d_name = ((char *)dircache_root + dircache_size); | 241 | ce->d_name = ((char *)dircache_root + dircache_size); |
243 | ce->startcluster = sab.direntry->firstcluster; | 242 | ce->startcluster = sab.direntry->firstcluster; |
244 | ce->size = sab.direntry->filesize; | 243 | ce->info.size = sab.direntry->filesize; |
245 | ce->wrtdate = sab.direntry->wrtdate; | 244 | ce->info.attribute = sab.direntry->attr; |
246 | ce->wrttime = sab.direntry->wrttime; | 245 | ce->info.wrtdate = sab.direntry->wrtdate; |
246 | ce->info.wrttime = sab.direntry->wrttime; | ||
247 | memcpy(ce->d_name, sab.direntry->name, ce->name_len); | 247 | memcpy(ce->d_name, sab.direntry->name, ce->name_len); |
248 | 248 | ||
249 | dircache_size += ce->name_len; | 249 | dircache_size += ce->name_len; |
250 | entry_count++; | 250 | entry_count++; |
251 | 251 | ||
252 | if(ce->attribute & FAT_ATTR_DIRECTORY) | 252 | if(ce->info.attribute & FAT_ATTR_DIRECTORY) |
253 | dircache_gen_down(ce); | 253 | dircache_gen_down(ce); |
254 | 254 | ||
255 | ce = dircache_gen_next(ce); | 255 | ce = dircache_gen_next(ce); |
@@ -269,18 +269,18 @@ static int sab_process_dir(unsigned long startcluster, struct dircache_entry *ce | |||
269 | /* add "." and ".." */ | 269 | /* add "." and ".." */ |
270 | ce->d_name = "."; | 270 | ce->d_name = "."; |
271 | ce->name_len = 2; | 271 | ce->name_len = 2; |
272 | ce->attribute = FAT_ATTR_DIRECTORY; | 272 | ce->info.attribute = FAT_ATTR_DIRECTORY; |
273 | ce->startcluster = startcluster; | 273 | ce->startcluster = startcluster; |
274 | ce->size = 0; | 274 | ce->info.size = 0; |
275 | ce->down = first_ce; | 275 | ce->down = first_ce; |
276 | 276 | ||
277 | ce = dircache_gen_next(ce); | 277 | ce = dircache_gen_next(ce); |
278 | 278 | ||
279 | ce->d_name = ".."; | 279 | ce->d_name = ".."; |
280 | ce->name_len = 3; | 280 | ce->name_len = 3; |
281 | ce->attribute = FAT_ATTR_DIRECTORY; | 281 | ce->info.attribute = FAT_ATTR_DIRECTORY; |
282 | ce->startcluster = (first_ce->up ? first_ce->up->startcluster : 0); | 282 | ce->startcluster = (first_ce->up ? first_ce->up->startcluster : 0); |
283 | ce->size = 0; | 283 | ce->info.size = 0; |
284 | ce->down = first_ce->up; | 284 | ce->down = first_ce->up; |
285 | 285 | ||
286 | /* second pass: recurse ! */ | 286 | /* second pass: recurse ! */ |
@@ -311,8 +311,8 @@ static int dircache_scan_and_build(IF_MV2(int volume,) struct dircache_entry *ce | |||
311 | snprintf(ce->d_name, VOL_ENUM_POS + 3, VOL_NAMES, volume); | 311 | snprintf(ce->d_name, VOL_ENUM_POS + 3, VOL_NAMES, volume); |
312 | ce->name_len = VOL_ENUM_POS + 3; | 312 | ce->name_len = VOL_ENUM_POS + 3; |
313 | dircache_size += ce->name_len; | 313 | dircache_size += ce->name_len; |
314 | ce->attribute = FAT_ATTR_DIRECTORY | FAT_ATTR_VOLUME; | 314 | ce->info.attribute = FAT_ATTR_DIRECTORY | FAT_ATTR_VOLUME; |
315 | ce->size = 0; | 315 | ce->info.size = 0; |
316 | append_position = dircache_gen_next(ce); | 316 | append_position = dircache_gen_next(ce); |
317 | ce = dircache_gen_down(ce); | 317 | ce = dircache_gen_down(ce); |
318 | } | 318 | } |
@@ -347,18 +347,15 @@ static int sab_process_dir(struct dircache_entry *ce) | |||
347 | !strcmp("..", entry->d_name)) | 347 | !strcmp("..", entry->d_name)) |
348 | continue; | 348 | continue; |
349 | 349 | ||
350 | ce->attribute = entry->attribute; | ||
351 | ce->name_len = strlen(entry->d_name) + 1; | 350 | ce->name_len = strlen(entry->d_name) + 1; |
352 | ce->d_name = ((char *)dircache_root + dircache_size); | 351 | ce->d_name = ((char *)dircache_root + dircache_size); |
353 | ce->size = entry->size; | 352 | ce->info = entry->info; |
354 | ce->wrtdate = entry->wrtdate; | ||
355 | ce->wrttime = entry->wrttime; | ||
356 | memcpy(ce->d_name, entry->d_name, ce->name_len); | 353 | memcpy(ce->d_name, entry->d_name, ce->name_len); |
357 | 354 | ||
358 | dircache_size += ce->name_len; | 355 | dircache_size += ce->name_len; |
359 | entry_count++; | 356 | entry_count++; |
360 | 357 | ||
361 | if(entry->attribute & ATTR_DIRECTORY) | 358 | if(entry->info.attribute & ATTR_DIRECTORY) |
362 | { | 359 | { |
363 | dircache_gen_down(ce); | 360 | dircache_gen_down(ce); |
364 | if(ce->down == NULL) | 361 | if(ce->down == NULL) |
@@ -400,16 +397,16 @@ static int sab_process_dir(struct dircache_entry *ce) | |||
400 | /* add "." and ".." */ | 397 | /* add "." and ".." */ |
401 | ce->d_name = "."; | 398 | ce->d_name = "."; |
402 | ce->name_len = 2; | 399 | ce->name_len = 2; |
403 | ce->attribute = ATTR_DIRECTORY; | 400 | ce->info.attribute = ATTR_DIRECTORY; |
404 | ce->size = 0; | 401 | ce->info.size = 0; |
405 | ce->down = first_ce; | 402 | ce->down = first_ce; |
406 | 403 | ||
407 | ce = dircache_gen_next(ce); | 404 | ce = dircache_gen_next(ce); |
408 | 405 | ||
409 | ce->d_name = ".."; | 406 | ce->d_name = ".."; |
410 | ce->name_len = 3; | 407 | ce->name_len = 3; |
411 | ce->attribute = ATTR_DIRECTORY; | 408 | ce->info.attribute = ATTR_DIRECTORY; |
412 | ce->size = 0; | 409 | ce->info.size = 0; |
413 | ce->down = first_ce->up; | 410 | ce->down = first_ce->up; |
414 | 411 | ||
415 | closedir_uncached(dir); | 412 | closedir_uncached(dir); |
@@ -1022,13 +1019,11 @@ static struct dircache_entry* dircache_new_entry(const char *path, int attribute | |||
1022 | return NULL; | 1019 | return NULL; |
1023 | } | 1020 | } |
1024 | 1021 | ||
1025 | entry->attribute = attribute; | ||
1026 | entry->name_len = MIN(254, strlen(new)) + 1; | 1022 | entry->name_len = MIN(254, strlen(new)) + 1; |
1027 | entry->d_name = ((char *)dircache_root+dircache_size); | 1023 | entry->d_name = ((char *)dircache_root+dircache_size); |
1028 | entry->startcluster = 0; | 1024 | entry->startcluster = 0; |
1029 | entry->wrtdate = 0; | 1025 | memset(&entry->info, 0, sizeof(entry->info)); |
1030 | entry->wrttime = 0; | 1026 | entry->info.attribute = attribute; |
1031 | entry->size = 0; | ||
1032 | memcpy(entry->d_name, new, entry->name_len); | 1027 | memcpy(entry->d_name, new, entry->name_len); |
1033 | dircache_size += entry->name_len; | 1028 | dircache_size += entry->name_len; |
1034 | 1029 | ||
@@ -1086,7 +1081,7 @@ void dircache_update_filesize(int fd, long newsize, long startcluster) | |||
1086 | return ; | 1081 | return ; |
1087 | } | 1082 | } |
1088 | 1083 | ||
1089 | fd_bindings[fd]->size = newsize; | 1084 | fd_bindings[fd]->info.size = newsize; |
1090 | fd_bindings[fd]->startcluster = startcluster; | 1085 | fd_bindings[fd]->startcluster = startcluster; |
1091 | } | 1086 | } |
1092 | void dircache_update_filetime(int fd) | 1087 | void dircache_update_filetime(int fd) |
@@ -1106,12 +1101,12 @@ void dircache_update_filetime(int fd) | |||
1106 | return ; | 1101 | return ; |
1107 | } | 1102 | } |
1108 | year = now->tm_year+1900-1980; | 1103 | year = now->tm_year+1900-1980; |
1109 | fd_bindings[fd]->wrtdate = (((year)&0x7f)<<9) | | 1104 | fd_bindings[fd]->info.wrtdate = (((year)&0x7f)<<9) | |
1110 | (((now->tm_mon+1)&0xf)<<5) | | 1105 | (((now->tm_mon+1)&0xf)<<5) | |
1111 | (((now->tm_mday)&0x1f)); | 1106 | (((now->tm_mday)&0x1f)); |
1112 | fd_bindings[fd]->wrttime = (((now->tm_hour)&0x1f)<<11) | | 1107 | fd_bindings[fd]->info.wrttime = (((now->tm_hour)&0x1f)<<11) | |
1113 | (((now->tm_min)&0x3f)<<5) | | 1108 | (((now->tm_min)&0x3f)<<5) | |
1114 | (((now->tm_sec/2)&0x1f)); | 1109 | (((now->tm_sec/2)&0x1f)); |
1115 | #endif | 1110 | #endif |
1116 | } | 1111 | } |
1117 | 1112 | ||
@@ -1211,7 +1206,7 @@ void dircache_rename(const char *oldpath, const char *newpath) | |||
1211 | newpath = absolute_path; | 1206 | newpath = absolute_path; |
1212 | } | 1207 | } |
1213 | 1208 | ||
1214 | newentry = dircache_new_entry(newpath, entry->attribute); | 1209 | newentry = dircache_new_entry(newpath, entry->info.attribute); |
1215 | if (newentry == NULL) | 1210 | if (newentry == NULL) |
1216 | { | 1211 | { |
1217 | dircache_initialized = false; | 1212 | dircache_initialized = false; |
@@ -1219,10 +1214,10 @@ void dircache_rename(const char *oldpath, const char *newpath) | |||
1219 | } | 1214 | } |
1220 | 1215 | ||
1221 | newentry->down = oldentry.down; | 1216 | newentry->down = oldentry.down; |
1222 | newentry->size = oldentry.size; | ||
1223 | newentry->startcluster = oldentry.startcluster; | 1217 | newentry->startcluster = oldentry.startcluster; |
1224 | newentry->wrttime = oldentry.wrttime; | 1218 | newentry->info.size = oldentry.info.size; |
1225 | newentry->wrtdate = oldentry.wrtdate; | 1219 | newentry->info.wrtdate = oldentry.info.wrtdate; |
1220 | newentry->info.wrttime = oldentry.info.wrttime; | ||
1226 | } | 1221 | } |
1227 | 1222 | ||
1228 | void dircache_add_file(const char *path, long startcluster) | 1223 | void dircache_add_file(const char *path, long startcluster) |
@@ -1279,7 +1274,7 @@ DIR_CACHED* opendir_cached(const char* name) | |||
1279 | { | 1274 | { |
1280 | pdir->regulardir = NULL; | 1275 | pdir->regulardir = NULL; |
1281 | pdir->internal_entry = dircache_get_entry(name, true); | 1276 | pdir->internal_entry = dircache_get_entry(name, true); |
1282 | pdir->theent.attribute = -1; /* used to make readdir_cached aware of the first call */ | 1277 | pdir->theent.info.attribute = -1; /* used to make readdir_cached aware of the first call */ |
1283 | } | 1278 | } |
1284 | 1279 | ||
1285 | if (pdir->internal_entry == NULL && pdir->regulardir == NULL) | 1280 | if (pdir->internal_entry == NULL && pdir->regulardir == NULL) |
@@ -1306,11 +1301,8 @@ struct dirent_cached* readdir_cached(DIR_CACHED* dir) | |||
1306 | return NULL; | 1301 | return NULL; |
1307 | 1302 | ||
1308 | strlcpy(dir->theent.d_name, regentry->d_name, MAX_PATH); | 1303 | strlcpy(dir->theent.d_name, regentry->d_name, MAX_PATH); |
1309 | dir->theent.size = regentry->size; | ||
1310 | dir->theent.startcluster = regentry->startcluster; | 1304 | dir->theent.startcluster = regentry->startcluster; |
1311 | dir->theent.attribute = regentry->attribute; | 1305 | dir->theent.info = regentry->info; |
1312 | dir->theent.wrttime = regentry->wrttime; | ||
1313 | dir->theent.wrtdate = regentry->wrtdate; | ||
1314 | 1306 | ||
1315 | return &dir->theent; | 1307 | return &dir->theent; |
1316 | } | 1308 | } |
@@ -1318,7 +1310,7 @@ struct dirent_cached* readdir_cached(DIR_CACHED* dir) | |||
1318 | /* if theent.attribute=-1 then this is the first call */ | 1310 | /* if theent.attribute=-1 then this is the first call */ |
1319 | /* otherwise, this is is not so we first take the entry's ->next */ | 1311 | /* otherwise, this is is not so we first take the entry's ->next */ |
1320 | /* NOTE: normal file can't have attribute=-1 */ | 1312 | /* NOTE: normal file can't have attribute=-1 */ |
1321 | if(dir->theent.attribute != -1) | 1313 | if(dir->theent.info.attribute != -1) |
1322 | ce = ce->next; | 1314 | ce = ce->next; |
1323 | /* skip unused entries */ | 1315 | /* skip unused entries */ |
1324 | while(ce != NULL && ce->name_len == 0) | 1316 | while(ce != NULL && ce->name_len == 0) |
@@ -1330,11 +1322,8 @@ struct dirent_cached* readdir_cached(DIR_CACHED* dir) | |||
1330 | strlcpy(dir->theent.d_name, ce->d_name, MAX_PATH); | 1322 | strlcpy(dir->theent.d_name, ce->d_name, MAX_PATH); |
1331 | /* Can't do `dir->theent = *ce` | 1323 | /* Can't do `dir->theent = *ce` |
1332 | because that modifies the d_name pointer. */ | 1324 | because that modifies the d_name pointer. */ |
1333 | dir->theent.size = ce->size; | ||
1334 | dir->theent.startcluster = ce->startcluster; | 1325 | dir->theent.startcluster = ce->startcluster; |
1335 | dir->theent.attribute = ce->attribute; | 1326 | dir->theent.info = ce->info; |
1336 | dir->theent.wrttime = ce->wrttime; | ||
1337 | dir->theent.wrtdate = ce->wrtdate; | ||
1338 | dir->internal_entry = ce; | 1327 | dir->internal_entry = ce; |
1339 | 1328 | ||
1340 | //logf("-> %s", ce->name); | 1329 | //logf("-> %s", ce->name); |