Skip to content

Commit

Permalink
Fixed romfs_dir struct for the parent field and fixed romfs_dev.h for…
Browse files Browse the repository at this point in the history
…matting.
  • Loading branch information
yellows8 committed Feb 13, 2018
1 parent f5606bf commit 67af341
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 31 deletions.
53 changes: 27 additions & 26 deletions nx/include/switch/runtime/devices/romfs_dev.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -60,7 +61,7 @@ struct romfs_mount;
Result romfsMount(struct romfs_mount **mount);
static inline Result romfsInit(void)
{
return romfsMount(NULL);
return romfsMount(NULL);
}

/**
Expand All @@ -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
Expand All @@ -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);
}

10 changes: 5 additions & 5 deletions nx/source/runtime/devices/romfs_dev.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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, "..");
Expand Down

0 comments on commit 67af341

Please sign in to comment.