From 67af341594cd9d2721a0c19f6c068038b1ca9786 Mon Sep 17 00:00:00 2001 From: yellows8 Date: Tue, 13 Feb 2018 17:50:21 -0500 Subject: [PATCH] Fixed romfs_dir struct for the parent field and fixed romfs_dev.h formatting. --- nx/include/switch/runtime/devices/romfs_dev.h | 53 ++++++++++--------- nx/source/runtime/devices/romfs_dev.c | 10 ++-- 2 files changed, 32 insertions(+), 31 deletions(-) diff --git a/nx/include/switch/runtime/devices/romfs_dev.h b/nx/include/switch/runtime/devices/romfs_dev.h index 22ed18f5..d6dee80c 100644 --- a/nx/include/switch/runtime/devices/romfs_dev.h +++ b/nx/include/switch/runtime/devices/romfs_dev.h @@ -16,39 +16,40 @@ /// RomFS header. typedef struct { - u64 headerSize; ///< Size of the header. - u64 dirHashTableOff; ///< Offset of the directory hash table. - u64 dirHashTableSize; ///< Size of the directory hash table. - u64 dirTableOff; ///< Offset of the directory table. - u64 dirTableSize; ///< Size of the directory table. - u64 fileHashTableOff; ///< Offset of the file hash table. - u64 fileHashTableSize; ///< Size of the file hash table. - u64 fileTableOff; ///< Offset of the file table. - u64 fileTableSize; ///< Size of the file table. - u64 fileDataOff; ///< Offset of the file data. + u64 headerSize; ///< Size of the header. + u64 dirHashTableOff; ///< Offset of the directory hash table. + u64 dirHashTableSize; ///< Size of the directory hash table. + u64 dirTableOff; ///< Offset of the directory table. + u64 dirTableSize; ///< Size of the directory table. + u64 fileHashTableOff; ///< Offset of the file hash table. + u64 fileHashTableSize; ///< Size of the file hash table. + u64 fileTableOff; ///< Offset of the file table. + u64 fileTableSize; ///< Size of the file table. + u64 fileDataOff; ///< Offset of the file data. } romfs_header; /// RomFS directory. typedef struct { - u32 sibling; ///< Offset of the next sibling directory. - u32 childDir; ///< Offset of the first child directory. - u32 childFile; ///< Offset of the first file. - u32 nextHash; ///< Directory hash table pointer. - u32 nameLen; ///< Name length. - uint8_t name[]; ///< Name. (UTF-8) + u32 parent; ///< Offset of the parent directory. + u32 sibling; ///< Offset of the next sibling directory. + u32 childDir; ///< Offset of the first child directory. + u32 childFile; ///< Offset of the first file. + u32 nextHash; ///< Directory hash table pointer. + u32 nameLen; ///< Name length. + uint8_t name[]; ///< Name. (UTF-8) } romfs_dir; /// RomFS file. typedef struct { - u32 parent; ///< Offset of the parent directory. - u32 sibling; ///< Offset of the next sibling file. - u64 dataOff; ///< Offset of the file's data. - u64 dataSize; ///< Length of the file's data. - u32 nextHash; ///< File hash table pointer. - u32 nameLen; ///< Name length. - uint8_t name[]; ///< Name. (UTF-8) + u32 parent; ///< Offset of the parent directory. + u32 sibling; ///< Offset of the next sibling file. + u64 dataOff; ///< Offset of the file's data. + u64 dataSize; ///< Length of the file's data. + u32 nextHash; ///< File hash table pointer. + u32 nameLen; ///< Name length. + uint8_t name[]; ///< Name. (UTF-8) } romfs_file; struct romfs_mount; @@ -60,7 +61,7 @@ struct romfs_mount; Result romfsMount(struct romfs_mount **mount); static inline Result romfsInit(void) { - return romfsMount(NULL); + return romfsMount(NULL); } /** @@ -72,7 +73,7 @@ static inline Result romfsInit(void) Result romfsMountFromFile(FsFile file, u64 offset, struct romfs_mount **mount); static inline Result romfsInitFromFile(FsFile file, u64 offset) { - return romfsMountFromFile(file, offset, NULL); + return romfsMountFromFile(file, offset, NULL); } /// Bind the RomFS mount @@ -82,6 +83,6 @@ Result romfsBind(struct romfs_mount *mount); Result romfsUnmount(struct romfs_mount *mount); static inline Result romfsExit(void) { - return romfsUnmount(NULL); + return romfsUnmount(NULL); } diff --git a/nx/source/runtime/devices/romfs_dev.c b/nx/source/runtime/devices/romfs_dev.c index d58f046a..fd2a415d 100644 --- a/nx/source/runtime/devices/romfs_dev.c +++ b/nx/source/runtime/devices/romfs_dev.c @@ -294,7 +294,7 @@ Result romfsMountCommon(romfs_mount *mount) mount->dirTable = malloc(mount->header.dirTableSize); if (!mount->dirTable) goto fail; - if (!_romfs_read_chk(mount, mount->header.dirTableOff + 4, mount->dirTable, mount->header.dirTableSize)) + if (!_romfs_read_chk(mount, mount->header.dirTableOff, mount->dirTable, mount->header.dirTableSize)) goto fail; mount->fileHashTable = (u32*)malloc(mount->header.fileHashTableSize); @@ -411,7 +411,7 @@ static romfs_dir* searchForDir(romfs_mount *mount, romfs_dir* parent, const uint for (curOff = mount->dirHashTable[hash]; curOff != romFS_none; curOff = curDir->nextHash) { curDir = romFS_dir(mount, curOff); - //if (curDir->parent != parentOff) continue;//TODO: How to handle parent here? + if (curDir->parent != parentOff) continue; if (curDir->nameLen != namelen) continue; if (memcmp(curDir->name, name, namelen) != 0) continue; return curDir; @@ -478,7 +478,7 @@ static int navigateToDir(romfs_mount *mount, romfs_dir** ppDir, const char** pPa if (!component[1]) continue; if (component[1]=='.' && !component[2]) { - //*ppDir = romFS_dir(mount, (*ppDir)->parent);//TODO: How to handle parent here? + *ppDir = romFS_dir(mount, (*ppDir)->parent); continue; } } @@ -762,10 +762,10 @@ int romfs_dirnext(struct _reent *r, DIR_ITER *dirState, char *filename, struct s else if(iter->state == 1) { /* '..' entry */ - //romfs_dir* dir = romFS_dir(iter->mount, iter->dir->parent);//TODO: How to handle parent here? + romfs_dir* dir = romFS_dir(iter->mount, iter->dir->parent); memset(filestat, 0, sizeof(*filestat)); - //filestat->st_ino = dir_inode(iter->mount, dir); + filestat->st_ino = dir_inode(iter->mount, dir); filestat->st_mode = romFS_dir_mode; strcpy(filename, "..");