Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions ctrtool/romfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "types.h"
#include "romfs.h"
#include "utils.h"
#include "filepath.h"

void romfs_init(romfs_context* ctx)
{
Expand Down Expand Up @@ -86,12 +87,14 @@ void romfs_process(romfs_context* ctx, u32 actions)
fseek(ctx->file, dirblockoffset, SEEK_SET);
fread(ctx->dirblock, 1, dirblocksize, ctx->file);
}
else perror("ctx->dirblock\n");

if (ctx->fileblock)
{
fseek(ctx->file, fileblockoffset, SEEK_SET);
fread(ctx->fileblock, 1, fileblocksize, ctx->file);
}
else perror("ctx->fileblock\n");

if (actions & InfoFlag)
romfs_print(ctx);
Expand Down Expand Up @@ -223,8 +226,10 @@ void romfs_visit_dir(romfs_context* ctx, u32 diroffset, u32 depth, u32 actions,
childoffset = getle32(entry->childoffset);
fileoffset = getle32(entry->fileoffset);

if (fileoffset != (~0))
romfs_visit_file(ctx, fileoffset, depth+1, actions, &currentpath);
while(fileoffset != (~0))
{
fileoffset=romfs_visit_file(ctx, fileoffset, depth+1, actions, &currentpath);
}

if (childoffset != (~0))
romfs_visit_dir(ctx, childoffset, depth+1, actions, &currentpath);
Expand All @@ -234,15 +239,15 @@ void romfs_visit_dir(romfs_context* ctx, u32 diroffset, u32 depth, u32 actions,
}


void romfs_visit_file(romfs_context* ctx, u32 fileoffset, u32 depth, u32 actions, filepath* rootpath)
u32 romfs_visit_file(romfs_context *ctx, u32 fileoffset, u32 depth, u32 actions, filepath *rootpath)
{
u32 siblingoffset = 0;
filepath currentpath;
romfs_fileentry* entry = &ctx->fileentry;


if (!romfs_fileblock_readentry(ctx, fileoffset, entry))
return;
return 0;


// fprintf(stdout, "%08X %08X %016llX %016llX %08X ",
Expand All @@ -262,7 +267,7 @@ void romfs_visit_file(romfs_context* ctx, u32 fileoffset, u32 depth, u32 actions
else
{
fprintf(stderr, "Error creating directory in root %s\n", rootpath->pathname);
return;
return 0;
}
}
else
Expand All @@ -279,9 +284,7 @@ void romfs_visit_file(romfs_context* ctx, u32 fileoffset, u32 depth, u32 actions
}

siblingoffset = getle32(entry->siblingoffset);

if (siblingoffset != (~0))
romfs_visit_file(ctx, siblingoffset, depth, actions, rootpath);
return siblingoffset;
}

void romfs_extract_datafile(romfs_context* ctx, u64 offset, u64 size, filepath* path)
Expand Down
2 changes: 1 addition & 1 deletion ctrtool/romfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ int romfs_dirblock_readentry(romfs_context* ctx, u32 diroffset, romfs_direntry*
int romfs_fileblock_read(romfs_context* ctx, u32 fileoffset, u32 filesize, void* buffer);
int romfs_fileblock_readentry(romfs_context* ctx, u32 fileoffset, romfs_fileentry* entry);
void romfs_visit_dir(romfs_context* ctx, u32 diroffset, u32 depth, u32 actions, filepath* rootpath);
void romfs_visit_file(romfs_context* ctx, u32 fileoffset, u32 depth, u32 actions, filepath* rootpath);
u32 romfs_visit_file(romfs_context *ctx, u32 fileoffset, u32 depth, u32 actions, filepath *rootpath);
void romfs_extract_datafile(romfs_context* ctx, u64 offset, u64 size, filepath* path);
void romfs_process(romfs_context* ctx, u32 actions);
void romfs_print(romfs_context* ctx);
Expand Down
2 changes: 1 addition & 1 deletion ctrtool/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#endif

#ifndef MAX_PATH
#define MAX_PATH 255
#define MAX_PATH 260
#endif

#ifdef __cplusplus
Expand Down