[makerom] Misc

This commit is contained in:
jakcron
2015-11-11 01:55:20 +08:00
parent 3cb804ee6a
commit 88c0f66c4a
3 changed files with 45 additions and 51 deletions
+21 -21
View File
@@ -28,9 +28,9 @@ int fs_InitDir(u16 *path, u32 pathlen, fs_dir *dir)
memcpy(dir->name,path,dir->name_len); memcpy(dir->name,path,dir->name_len);
dir->m_dir = 10; dir->m_child = 10;
dir->u_dir = 0; dir->u_child = 0;
dir->dir = calloc(dir->m_dir,sizeof(fs_dir)); dir->child = calloc(dir->m_child,sizeof(fs_dir));
dir->m_file = 10; dir->m_file = 10;
dir->u_file = 0; dir->u_file = 0;
@@ -41,13 +41,13 @@ int fs_InitDir(u16 *path, u32 pathlen, fs_dir *dir)
int fs_ManageDirSlot(fs_dir *dir) int fs_ManageDirSlot(fs_dir *dir)
{ {
if(dir->u_dir >= dir->m_dir) if(dir->u_child >= dir->m_child)
{ {
dir->m_dir *= 2; dir->m_child *= 2;
fs_dir *tmp = calloc(dir->m_dir,sizeof(fs_dir)); fs_dir *tmp = calloc(dir->m_child,sizeof(fs_dir));
memcpy(tmp,dir->dir,sizeof(fs_dir)*dir->u_dir); memcpy(tmp,dir->child,sizeof(fs_dir)*dir->u_child);
free(dir->dir); free(dir->child);
dir->dir = tmp; dir->child = tmp;
} }
return 0; return 0;
} }
@@ -158,9 +158,9 @@ bool fs_EntryIsDirNav(fs_entry *entry)
int fs_AddDir(fs_entry *entry, fs_dir *dir) int fs_AddDir(fs_entry *entry, fs_dir *dir)
{ {
fs_ManageDirSlot(dir); fs_ManageDirSlot(dir);
u32 current_slot = dir->u_dir; u32 current_slot = dir->u_child;
dir->u_dir++; dir->u_child++;
return fs_OpenDir(entry->fs_name,entry->name,entry->name_len,&dir->dir[current_slot]); return fs_OpenDir(entry->fs_name,entry->name,entry->name_len,&dir->child[current_slot]);
} }
int fs_AddFile(fs_entry *entry, fs_dir *dir) int fs_AddFile(fs_entry *entry, fs_dir *dir)
@@ -286,10 +286,10 @@ void fs_PrintDir(fs_dir *dir, u32 depth) // This is just for simple debugging, p
#endif #endif
} }
} }
if(dir->u_dir) if(dir->u_child)
{ {
for(u32 i = 0; i < dir->u_dir; i++) for(u32 i = 0; i < dir->u_child; i++)
fs_PrintDir(&dir->dir[i],depth+1); fs_PrintDir(&dir->child[i],depth+1);
} }
} }
@@ -305,13 +305,13 @@ void fs_FreeDir(fs_dir *dir)
//printf("free dir names and\n"); //printf("free dir names and\n");
for(u32 i = 0; i < dir->u_dir; i++) for(u32 i = 0; i < dir->u_child; i++)
{ {
free(dir->dir[i].name); free(dir->child[i].name);
fs_FreeDir(&dir->dir[i]); fs_FreeDir(&dir->child[i]);
} }
//printf("free dir struct\n"); //printf("free dir struct\n");
free(dir->dir); free(dir->child);
} }
@@ -323,6 +323,6 @@ void fs_FreeFiles(fs_dir *dir)
fclose(dir->file[i].fp); fclose(dir->file[i].fp);
} }
for(u32 i = 0; i < dir->u_dir; i++) for(u32 i = 0; i < dir->u_child; i++)
fs_FreeFiles(&dir->dir[i]); fs_FreeFiles(&dir->child[i]);
} }
+3 -3
View File
@@ -44,9 +44,9 @@ struct fs_dir
fs_romfs_char *name; fs_romfs_char *name;
u32 name_len; u32 name_len;
struct fs_dir *dir; struct fs_dir *child;
u32 m_dir; u32 m_child;
u32 u_dir; u32 u_child;
struct fs_file *file; struct fs_file *file;
u32 m_file; u32 m_file;
+21 -27
View File
@@ -59,7 +59,7 @@ int PrepareBuildRomFsBinary(ncch_settings *ncchset, romfs_buildctx *ctx)
free(fs_raw); free(fs_raw);
/* Abort romfs making, if no wanted files/directories were found */ /* Abort romfs making, if no wanted files/directories were found */
if(ctx->fs->u_file == 0 && ctx->fs->u_dir == 0){ if(ctx->fs->u_file == 0 && ctx->fs->u_child == 0){
ctx->romfsSize = 0; ctx->romfsSize = 0;
goto finish; goto finish;
} }
@@ -132,10 +132,9 @@ bool IsDirWanted(fs_dir *dir, void *filter_criteria)
break; break;
} }
} }
fs_dir *tmp = (fs_dir*)dir->dir; for(u32 i = 0; i < dir->u_child; i++)
for(u32 i = 0; i < dir->u_dir; i++)
{ {
if(IsDirWanted(&tmp[i],filter_criteria)) if(IsDirWanted(&dir->child[i],filter_criteria))
{ {
ret = true; ret = true;
break; break;
@@ -158,13 +157,12 @@ void CalcDirSize(romfs_buildctx *ctx, fs_dir *fs)
ctx->m_dataLen = align(ctx->m_dataLen,0x10) + fs->file[i].size; ctx->m_dataLen = align(ctx->m_dataLen,0x10) + fs->file[i].size;
} }
fs_dir *dir = (fs_dir*)fs->dir; for(u32 i = 0; i < fs->u_child; i++)
for(u32 i = 0; i < fs->u_dir; i++)
{ {
CalcDirSize(ctx,&dir[i]); CalcDirSize(ctx,&fs->child[i]);
} }
ctx->fileNum += fs->u_file; ctx->fileNum += fs->u_file;
ctx->dirNum += fs->u_dir; ctx->dirNum += fs->u_child;
} }
u32 GetHashTableCount(u32 num) u32 GetHashTableCount(u32 num)
@@ -214,23 +212,20 @@ int FilterRomFS(fs_dir *fs_raw, fs_dir *fs_filtered, void *filter_criteria)
fs_filtered->name = calloc(fs_filtered->name_len+2,1); fs_filtered->name = calloc(fs_filtered->name_len+2,1);
memcpy(fs_filtered->name,fs_raw->name,fs_filtered->name_len); memcpy(fs_filtered->name,fs_raw->name,fs_filtered->name_len);
fs_filtered->u_dir = 0; fs_filtered->u_child = 0;
fs_filtered->m_dir = fs_raw->u_dir; fs_filtered->m_child = fs_raw->u_child;
fs_filtered->dir = calloc(fs_filtered->m_dir,sizeof(fs_dir)); fs_filtered->child = calloc(fs_filtered->m_child,sizeof(fs_dir));
fs_filtered->u_file = 0; fs_filtered->u_file = 0;
fs_filtered->m_file = fs_raw->u_file; fs_filtered->m_file = fs_raw->u_file;
fs_filtered->file = calloc(fs_filtered->m_file,sizeof(fs_file)); fs_filtered->file = calloc(fs_filtered->m_file,sizeof(fs_file));
for(u32 i = 0; i < fs_raw->u_child; i++)
fs_dir *dir_raw = (fs_dir*)fs_raw->dir;
fs_dir *dir_filtered = (fs_dir*)fs_filtered->dir;
for(u32 i = 0; i < fs_raw->u_dir; i++)
{ {
if(IsDirWanted(&dir_raw[i],filter_criteria)) if(IsDirWanted(&fs_raw->child[i],filter_criteria))
{ {
FilterRomFS(&dir_raw[i],&dir_filtered[fs_filtered->u_dir],filter_criteria); FilterRomFS(&fs_raw->child[i],&fs_filtered->child[fs_filtered->u_child],filter_criteria);
fs_filtered->u_dir++; fs_filtered->u_child++;
} }
} }
@@ -421,34 +416,33 @@ void AddDirChildrenToRomfs(romfs_buildctx *ctx, fs_dir *fs, u32 parent, u32 dir)
} }
} }
if (fs->u_dir) if (fs->u_child)
{ {
/* Prepare to store child addresses */ /* Prepare to store child addresses */
u32 *childs = calloc(fs->u_dir, sizeof(u32)); u32 *childs = calloc(fs->u_child, sizeof(u32));
/* Create child directory entries*/ /* Create child directory entries*/
u32_to_u8(entry->childoffset, ctx->u_dirTableLen, LE); u32_to_u8(entry->childoffset, ctx->u_dirTableLen, LE);
fs_dir *subdir = (fs_dir*)fs->dir; for (u32 i = 0; i < fs->u_child; i++)
for (u32 i = 0; i < fs->u_dir; i++)
{ {
/* Store address fo child */ /* Store address fo child */
childs[i] = ctx->u_dirTableLen; childs[i] = ctx->u_dirTableLen;
u32 dir_sibling = 0; u32 dir_sibling = 0;
if (i >= fs->u_dir - 1) if (i >= fs->u_child - 1)
dir_sibling = ROMFS_UNUSED_ENTRY; dir_sibling = ROMFS_UNUSED_ENTRY;
else else
dir_sibling = ctx->u_dirTableLen + sizeof(romfs_direntry) + (u32)align(subdir[i].name_len, 4); dir_sibling = ctx->u_dirTableLen + sizeof(romfs_direntry) + (u32)align(fs->child[i].name_len, 4);
/* Create child directory entry */ /* Create child directory entry */
AddDirToRomfs(ctx, &subdir[i], dir, dir_sibling); AddDirToRomfs(ctx, &fs->child[i], dir, dir_sibling);
} }
/* Populate child's childs */ /* Populate child's childs */
for (u32 i = 0; i < fs->u_dir; i++) for (u32 i = 0; i < fs->u_child; i++)
{ {
AddDirChildrenToRomfs(ctx, &subdir[i], dir, childs[i]); AddDirChildrenToRomfs(ctx, &fs->child[i], dir, childs[i]);
} }
free(childs); free(childs);