summaryrefslogtreecommitdiffstats
path: root/firmware/common/dircache.c
diff options
context:
space:
mode:
authorThomas Martitz <kugel@rockbox.org>2010-09-01 21:29:34 +0000
committerThomas Martitz <kugel@rockbox.org>2010-09-01 21:29:34 +0000
commit6eaab4d00446c070c655f0e6c9a872532a776b6f (patch)
tree69610996dd0a6092459b14e164d4e48e03b1e5bb /firmware/common/dircache.c
parent8e0a0babc57db3e9edc06f3e269fb47c27292ed5 (diff)
downloadrockbox-6eaab4d00446c070c655f0e6c9a872532a776b6f.tar.gz
rockbox-6eaab4d00446c070c655f0e6c9a872532a776b6f.zip
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
Diffstat (limited to 'firmware/common/dircache.c')
-rw-r--r--firmware/common/dircache.c79
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
!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);