From 6eaab4d00446c070c655f0e6c9a872532a776b6f Mon Sep 17 00:00:00 2001 From: Thomas Martitz Date: Wed, 1 Sep 2010 21:29:34 +0000 Subject: Ged rid of uisimulator/common/io.c for android builds. Use host's functions for file i/o directly (open(), close() ,etc.), not the sim_* variants. Some dir functions need to be wrapped still because we need to cache the parents dir's path (host's dirent doesn't let us know). For the same reason (incompatibility) with host's dirent) detach some members from Rockbox' dirent struct and put it into an extra one, the values can be retrieved via the new dir_get_info(). Get rid of the sim_ prefix for sleep as well and change the signature to unix sleep(). git-svn-id: svn://svn.rockbox.org/rockbox/trunk@27968 a1c6a512-1295-4272-9138-f99709370657 --- firmware/common/dir_uncached.c | 10 +++--- firmware/common/dircache.c | 79 ++++++++++++++++++------------------------ firmware/common/file.c | 8 ++--- firmware/common/filefuncs.c | 9 +++++ 4 files changed, 52 insertions(+), 54 deletions(-) (limited to 'firmware/common') diff --git a/firmware/common/dir_uncached.c b/firmware/common/dir_uncached.c index e3e33a4c11..2ce23e8b8e 100644 --- a/firmware/common/dir_uncached.c +++ b/firmware/common/dir_uncached.c @@ -171,7 +171,7 @@ struct dirent_uncached* readdir_uncached(DIR_UNCACHED* dir) if (fat_ismounted(dir->volumecounter)) { memset(theent, 0, sizeof(*theent)); - theent->attribute = FAT_ATTR_DIRECTORY | FAT_ATTR_VOLUME; + theent->info.attribute = FAT_ATTR_DIRECTORY | FAT_ATTR_VOLUME; snprintf(theent->d_name, sizeof(theent->d_name), VOL_NAMES, dir->volumecounter); return theent; @@ -187,11 +187,11 @@ struct dirent_uncached* readdir_uncached(DIR_UNCACHED* dir) return NULL; strlcpy(theent->d_name, entry.name, sizeof(theent->d_name)); - theent->attribute = entry.attr; - theent->size = entry.filesize; + theent->info.attribute = entry.attr; + theent->info.wrtdate = entry.wrtdate; + theent->info.wrttime = entry.wrttime; + theent->info.size = entry.filesize; theent->startcluster = entry.firstcluster; - theent->wrtdate = entry.wrtdate; - theent->wrttime = entry.wrttime; return theent; } 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 !strcmp("..", sab.direntry->name)) continue; - ce->attribute = sab.direntry->attr; ce->name_len = strlen(sab.direntry->name) + 1; ce->d_name = ((char *)dircache_root + dircache_size); ce->startcluster = sab.direntry->firstcluster; - ce->size = sab.direntry->filesize; - ce->wrtdate = sab.direntry->wrtdate; - ce->wrttime = sab.direntry->wrttime; + ce->info.size = sab.direntry->filesize; + ce->info.attribute = sab.direntry->attr; + ce->info.wrtdate = sab.direntry->wrtdate; + ce->info.wrttime = sab.direntry->wrttime; memcpy(ce->d_name, sab.direntry->name, ce->name_len); dircache_size += ce->name_len; entry_count++; - if(ce->attribute & FAT_ATTR_DIRECTORY) + if(ce->info.attribute & FAT_ATTR_DIRECTORY) dircache_gen_down(ce); ce = dircache_gen_next(ce); @@ -269,18 +269,18 @@ static int sab_process_dir(unsigned long startcluster, struct dircache_entry *ce /* add "." and ".." */ ce->d_name = "."; ce->name_len = 2; - ce->attribute = FAT_ATTR_DIRECTORY; + ce->info.attribute = FAT_ATTR_DIRECTORY; ce->startcluster = startcluster; - ce->size = 0; + ce->info.size = 0; ce->down = first_ce; ce = dircache_gen_next(ce); ce->d_name = ".."; ce->name_len = 3; - ce->attribute = FAT_ATTR_DIRECTORY; + ce->info.attribute = FAT_ATTR_DIRECTORY; ce->startcluster = (first_ce->up ? first_ce->up->startcluster : 0); - ce->size = 0; + ce->info.size = 0; ce->down = first_ce->up; /* second pass: recurse ! */ @@ -311,8 +311,8 @@ static int dircache_scan_and_build(IF_MV2(int volume,) struct dircache_entry *ce snprintf(ce->d_name, VOL_ENUM_POS + 3, VOL_NAMES, volume); ce->name_len = VOL_ENUM_POS + 3; dircache_size += ce->name_len; - ce->attribute = FAT_ATTR_DIRECTORY | FAT_ATTR_VOLUME; - ce->size = 0; + ce->info.attribute = FAT_ATTR_DIRECTORY | FAT_ATTR_VOLUME; + ce->info.size = 0; append_position = dircache_gen_next(ce); ce = dircache_gen_down(ce); } @@ -347,18 +347,15 @@ static int sab_process_dir(struct dircache_entry *ce) !strcmp("..", entry->d_name)) continue; - ce->attribute = entry->attribute; ce->name_len = strlen(entry->d_name) + 1; ce->d_name = ((char *)dircache_root + dircache_size); - ce->size = entry->size; - ce->wrtdate = entry->wrtdate; - ce->wrttime = entry->wrttime; + ce->info = entry->info; memcpy(ce->d_name, entry->d_name, ce->name_len); dircache_size += ce->name_len; entry_count++; - if(entry->attribute & ATTR_DIRECTORY) + if(entry->info.attribute & ATTR_DIRECTORY) { dircache_gen_down(ce); if(ce->down == NULL) @@ -400,16 +397,16 @@ static int sab_process_dir(struct dircache_entry *ce) /* add "." and ".." */ ce->d_name = "."; ce->name_len = 2; - ce->attribute = ATTR_DIRECTORY; - ce->size = 0; + ce->info.attribute = ATTR_DIRECTORY; + ce->info.size = 0; ce->down = first_ce; ce = dircache_gen_next(ce); ce->d_name = ".."; ce->name_len = 3; - ce->attribute = ATTR_DIRECTORY; - ce->size = 0; + ce->info.attribute = ATTR_DIRECTORY; + ce->info.size = 0; ce->down = first_ce->up; closedir_uncached(dir); @@ -1022,13 +1019,11 @@ static struct dircache_entry* dircache_new_entry(const char *path, int attribute return NULL; } - entry->attribute = attribute; entry->name_len = MIN(254, strlen(new)) + 1; entry->d_name = ((char *)dircache_root+dircache_size); entry->startcluster = 0; - entry->wrtdate = 0; - entry->wrttime = 0; - entry->size = 0; + memset(&entry->info, 0, sizeof(entry->info)); + entry->info.attribute = attribute; memcpy(entry->d_name, new, entry->name_len); dircache_size += entry->name_len; @@ -1086,7 +1081,7 @@ void dircache_update_filesize(int fd, long newsize, long startcluster) return ; } - fd_bindings[fd]->size = newsize; + fd_bindings[fd]->info.size = newsize; fd_bindings[fd]->startcluster = startcluster; } void dircache_update_filetime(int fd) @@ -1106,12 +1101,12 @@ void dircache_update_filetime(int fd) return ; } year = now->tm_year+1900-1980; - fd_bindings[fd]->wrtdate = (((year)&0x7f)<<9) | - (((now->tm_mon+1)&0xf)<<5) | - (((now->tm_mday)&0x1f)); - fd_bindings[fd]->wrttime = (((now->tm_hour)&0x1f)<<11) | - (((now->tm_min)&0x3f)<<5) | - (((now->tm_sec/2)&0x1f)); + fd_bindings[fd]->info.wrtdate = (((year)&0x7f)<<9) | + (((now->tm_mon+1)&0xf)<<5) | + (((now->tm_mday)&0x1f)); + fd_bindings[fd]->info.wrttime = (((now->tm_hour)&0x1f)<<11) | + (((now->tm_min)&0x3f)<<5) | + (((now->tm_sec/2)&0x1f)); #endif } @@ -1211,7 +1206,7 @@ void dircache_rename(const char *oldpath, const char *newpath) newpath = absolute_path; } - newentry = dircache_new_entry(newpath, entry->attribute); + newentry = dircache_new_entry(newpath, entry->info.attribute); if (newentry == NULL) { dircache_initialized = false; @@ -1219,10 +1214,10 @@ void dircache_rename(const char *oldpath, const char *newpath) } newentry->down = oldentry.down; - newentry->size = oldentry.size; newentry->startcluster = oldentry.startcluster; - newentry->wrttime = oldentry.wrttime; - newentry->wrtdate = oldentry.wrtdate; + newentry->info.size = oldentry.info.size; + newentry->info.wrtdate = oldentry.info.wrtdate; + newentry->info.wrttime = oldentry.info.wrttime; } void dircache_add_file(const char *path, long startcluster) @@ -1279,7 +1274,7 @@ DIR_CACHED* opendir_cached(const char* name) { pdir->regulardir = NULL; pdir->internal_entry = dircache_get_entry(name, true); - pdir->theent.attribute = -1; /* used to make readdir_cached aware of the first call */ + pdir->theent.info.attribute = -1; /* used to make readdir_cached aware of the first call */ } if (pdir->internal_entry == NULL && pdir->regulardir == NULL) @@ -1306,11 +1301,8 @@ struct dirent_cached* readdir_cached(DIR_CACHED* dir) return NULL; strlcpy(dir->theent.d_name, regentry->d_name, MAX_PATH); - dir->theent.size = regentry->size; dir->theent.startcluster = regentry->startcluster; - dir->theent.attribute = regentry->attribute; - dir->theent.wrttime = regentry->wrttime; - dir->theent.wrtdate = regentry->wrtdate; + dir->theent.info = regentry->info; return &dir->theent; } @@ -1318,7 +1310,7 @@ struct dirent_cached* readdir_cached(DIR_CACHED* dir) /* if theent.attribute=-1 then this is the first call */ /* otherwise, this is is not so we first take the entry's ->next */ /* NOTE: normal file can't have attribute=-1 */ - if(dir->theent.attribute != -1) + if(dir->theent.info.attribute != -1) ce = ce->next; /* skip unused entries */ while(ce != NULL && ce->name_len == 0) @@ -1330,11 +1322,8 @@ struct dirent_cached* readdir_cached(DIR_CACHED* dir) strlcpy(dir->theent.d_name, ce->d_name, MAX_PATH); /* Can't do `dir->theent = *ce` because that modifies the d_name pointer. */ - dir->theent.size = ce->size; dir->theent.startcluster = ce->startcluster; - dir->theent.attribute = ce->attribute; - dir->theent.wrttime = ce->wrttime; - dir->theent.wrtdate = ce->wrtdate; + dir->theent.info = ce->info; dir->internal_entry = ce; //logf("-> %s", ce->name); diff --git a/firmware/common/file.c b/firmware/common/file.c index 6beec9f606..53a1a35b31 100644 --- a/firmware/common/file.c +++ b/firmware/common/file.c @@ -124,8 +124,8 @@ static int open_internal(const char* pathname, int flags, bool use_cache) ce->startcluster, &(file->fatfile), NULL); - file->size = ce->size; - file->attr = ce->attribute; + file->size = ce->info.size; + file->attr = ce->info.attribute; file->cacheoffset = -1; file->fileoffset = 0; @@ -169,8 +169,8 @@ static int open_internal(const char* pathname, int flags, bool use_cache) entry->startcluster, &(file->fatfile), &(dir->fatdir)); - file->size = file->trunc ? 0 : entry->size; - file->attr = entry->attribute; + file->size = file->trunc ? 0 : entry->info.size; + file->attr = entry->info.attribute; break; } } diff --git a/firmware/common/filefuncs.c b/firmware/common/filefuncs.c index 9fe07d69bb..c8ab468bcb 100644 --- a/firmware/common/filefuncs.c +++ b/firmware/common/filefuncs.c @@ -23,6 +23,7 @@ #include "stdlib.h" #include "string.h" #include "debug.h" +#include "file.h" #include "filefuncs.h" #ifdef HAVE_MULTIVOLUME @@ -87,4 +88,12 @@ bool dir_exists(const char *path) closedir(d); return true; } + +#if !(CONFIG_PLATFORM & PLATFORM_ANDROID) +struct dirinfo dir_get_info(struct DIR* parent, struct dirent *entry) +{ + (void)parent; + return entry->info; +} +#endif #endif /* __PCTOOL__ */ -- cgit v1.2.3