diff --git a/nx/include/switch/runtime/devices/romfs_dev.h b/nx/include/switch/runtime/devices/romfs_dev.h index e72c4a7b..9efa12a3 100644 --- a/nx/include/switch/runtime/devices/romfs_dev.h +++ b/nx/include/switch/runtime/devices/romfs_dev.h @@ -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. diff --git a/nx/source/runtime/devices/romfs_dev.c b/nx/source/runtime/devices/romfs_dev.c index 8736fd98..93aadb7c 100644 --- a/nx/source/runtime/devices/romfs_dev.c +++ b/nx/source/runtime/devices/romfs_dev.c @@ -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)