Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Wrapper to turn romfs_file into romfs_fileobj
Useful for turning romfs_direntry files into readable files
  • Loading branch information
Bulmanator committed Jun 14, 2024
commit 6218f4875c9164b5d57372f338c4bba15e3f6e58
8 changes: 8 additions & 0 deletions nx/include/switch/runtime/devices/romfs_dev.h
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,14 @@ Result romfsFindFile(const char *path, romfs_fileobj *file);
*/
Result romfsFindFileInMount(romfs_mount *mount, const char *path, romfs_fileobj *file);

/**
* @brief Wrapper function for turning a romfs_file into a romfs_fileobj to be operated on, this
* is useful for creating readable files from a romfs_direntry
* @param mount The mount the file came from
* @param file The file information
*/
romfs_fileobj romfsFileObj(romfs_mount *mount, romfs_file *file);

/**
* @brief Reads data from the specified RomFS file.
* @param file The RomFS file to read from.
Expand Down
10 changes: 10 additions & 0 deletions nx/source/runtime/devices/romfs_dev.c
Original file line number Diff line number Diff line change
Expand Up @@ -685,6 +685,16 @@ Result romfsFindFileInMount(romfs_mount *mount, const char *path, romfs_fileobj
return 0;
}

romfs_fileobj romfsFileObj(romfs_mount *mount, romfs_file *file)
{
romfs_fileobj result = { 0 };
result.mount = mount;
result.file = file;
result.offset = mount->header.fileDataOff + file->dataOff;

return result;
}

Result romfsReadFile(romfs_fileobj *file, void *buffer, u64 size, u64 offset, u64 *nread)
{
if (nread == NULL || file == NULL || buffer == NULL)
Expand Down