firmware: speed up directory scanning

This commit is contained in:
ikari 2011-11-10 15:31:58 +01:00
parent 60efa60bb4
commit 3fda86125c
7 changed files with 56 additions and 27 deletions

View File

@ -2822,6 +2822,46 @@ FRESULT f_readdir (
}
FRESULT l_opendirbycluster (
FATFS *fs,
DIR *dj,
const TCHAR *path,
DWORD clust
)
{
FRESULT res;
res = chk_mounted(&path, &fs, 0);
DEF_NAMEBUF;
INIT_BUF(*dj);
dj->sclust = clust;
dj->fs = fs;
dj->id = fs->id;
dj->dir = 0;
res = dir_sdi(dj, 0);
FREE_BUF();
return res;
}
FRESULT l_openfilebycluster (
FATFS *fs, /* Pointer to file system object */
FIL *fp, /* Pointer to the blank file object */
const TCHAR *path,
DWORD clust, /* Cluster number to be opened */
DWORD fsize /* File size to be assumed */
)
{
chk_mounted(&path, &fs, 0);
fp->flag = FA_READ;
fp->org_clust = clust;
fp->fsize = fsize;
fp->fptr = 0;
fp->dsect = 0;
fp->fs = fs;
return FR_OK;
}
#if _FS_MINIMIZE == 0
/*-----------------------------------------------------------------------*/
@ -2854,27 +2894,6 @@ FRESULT f_stat (
LEAVE_FF(dj.fs, res);
}
FRESULT l_openfilebycluster (
FATFS *fs, /* Pointer to file system object */
FIL *fp, /* Pointer to the blank file object */
const TCHAR *path,
DWORD clust, /* Cluster number to be opened */
DWORD fsize /* File size to be assumed */
)
{
chk_mounted(&path, &fs, 0);
fp->flag = FA_READ;
fp->org_clust = clust;
fp->fsize = fsize;
fp->fptr = 0;
fp->dsect = 0;
fp->fs = fs;
return FR_OK;
}
#if !_FS_READONLY
/*-----------------------------------------------------------------------*/
/* Get Number of Free Clusters */

View File

@ -398,6 +398,7 @@ typedef enum {
/* Low Level functions */
FRESULT l_openfilebycluster(FATFS *fs, FIL *fp, const TCHAR *path, DWORD clust, DWORD fsize); /* Open a file by its start cluster using supplied file size */
FRESULT l_opendirbycluster (FATFS *fs, DIR *dj, const TCHAR *path, DWORD clust);
/* application level functions */
FRESULT f_mount (BYTE, FATFS*); /* Mount/Unmount a logical drive */

View File

@ -47,6 +47,10 @@ void file_reinit(void) {
file_init();
}
FRESULT dir_open_by_filinfo(DIR* dir, FILINFO* fno) {
return l_opendirbycluster(&fatfs, dir, (TCHAR*)"", fno->clust);
}
void file_open_by_filinfo(FILINFO* fno) {
file_res = l_openfilebycluster(&fatfs, &file_handle, (TCHAR*)"", fno->clust, fno->fsize);
}

View File

@ -41,6 +41,7 @@ enum filestates file_status;
void file_init(void);
void file_open(uint8_t* filename, BYTE flags);
FRESULT dir_open_by_filinfo(DIR* dir, FILINFO* fno_param);
void file_open_by_filinfo(FILINFO* fno);
void file_close(void);
void file_seek(uint32_t offset);

View File

@ -53,7 +53,7 @@ uint16_t scan_flat(const char* path) {
return numentries;
}
uint32_t scan_dir(char* path, char mkdb, uint32_t this_dir_tgt) {
uint32_t scan_dir(char* path, FILINFO* fno_param, char mkdb, uint32_t this_dir_tgt) {
DIR dir;
FILINFO fno;
FRESULT res;
@ -103,7 +103,11 @@ uint32_t scan_dir(char* path, char mkdb, uint32_t this_dir_tgt) {
sram_writelong(0L, next_subdir_tgt - 4);
}
}
res = f_opendir(&dir, (TCHAR*)path);
if(fno_param) {
res = dir_open_by_filinfo(&dir, fno_param);
} else {
res = f_opendir(&dir, path);
}
if (res == FR_OK) {
if(pass && parent_tgt && mkdb) {
/* write backlink to parent dir
@ -162,7 +166,7 @@ uint32_t scan_dir(char* path, char mkdb, uint32_t this_dir_tgt) {
db_tgt += sizeof(next_subdir_tgt) + sizeof(len) + pathlen + 2;
}
parent_tgt = this_dir_tgt;
scan_dir(path, mkdb, next_subdir_tgt);
scan_dir(path, &fno, mkdb, next_subdir_tgt);
dir_tgt += 4;
was_empty = 0;
}

View File

@ -50,7 +50,7 @@ char fs_path[256];
SNES_FTYPE determine_filetype(char* filename);
//uint32_t scan_fs();
uint16_t scan_flat(const char* path);
uint32_t scan_dir(char* path, char mkdb, uint32_t this_subdir_tgt);
uint32_t scan_dir(char* path, FILINFO* fno_param, char mkdb, uint32_t this_subdir_tgt);
FRESULT get_db_id(uint32_t*);
int get_num_dirent(uint32_t addr);
void sort_all_dir(uint32_t endaddr);

View File

@ -145,7 +145,7 @@ printf("PCONP=%lx\n", LPC_SC->PCONP);
if((mem_magic != 0x12345678) || (mem_dir_id != saved_dir_id) || (newcard)) {
newcard = 0;
/* generate fs footprint (interesting files only) */
uint32_t curr_dir_id = scan_dir(fs_path, 0, 0);
uint32_t curr_dir_id = scan_dir(fs_path, NULL, 0, 0);
printf("curr dir id = %lx\n", curr_dir_id);
/* files changed or no database found? */
if((get_db_id(&saved_dir_id) != FR_OK)
@ -154,7 +154,7 @@ printf("PCONP=%lx\n", LPC_SC->PCONP);
printf("saved dir id = %lx\n", saved_dir_id);
printf("rebuilding database...");
snes_bootprint(" rebuilding database ... \0");
curr_dir_id = scan_dir(fs_path, 1, 0);
curr_dir_id = scan_dir(fs_path, NULL, 1, 0);
sram_writeblock(&curr_dir_id, SRAM_DB_ADDR, 4);
uint32_t endaddr, direndaddr;
sram_readblock(&endaddr, SRAM_DB_ADDR+4, 4);