libnx/nx/include/switch/runtime/devices/romfs_dev.h
fincs c77b88d868
Major cleanup and refactor of fsdev and romfsdev, see details:
fsdev:
- Removed fsdevGetDefaultFileSystem and default-fs handling
- Refactored CWD support to have (dynamically allocated) per-device CWDs
  (CWD support as a whole can be turned off with __nx_fsdev_support_cwd)
- Optimized calls by passing pointer to device through r->deviceData
- Use the per-thread path buffer directly as the argument to FS functions
- Removed redundant cross-device check in fsdev_rename
- Fixed string comparison logic in fsdevFindDevice
- fsdev_fixpath now accepts an input device in order to skip device
  lookup (extensively used along with r->deviceData)
- Mounting a filesystem now automatically sets the default device
  if there wasn't any previous default device (or if it's stdnull)
- fsdevMountSdmc no longer sets cwd to the folder containing the
  executable - this logic was moved to a new internal function
  called on startup by default (and it is now disabled for NSOs)
- Other miscellaneous optimizations

romfsdev:
- Cleaned up romfsMount* functions, removed unused/unnecessary logic
- Changed romfsMount* functions to return real result codes
- Renamed romfsMount to romfsMountSelf and improved documentation
- Removed romfsInitFromFile and romfsInitFromStorage (use Mount instead)
- Added documentation for romfsInit and romfsExit
2019-10-20 22:22:04 +02:00

114 lines
3.6 KiB
C

/**
* @file romfs_dev.h
* @brief RomFS driver.
* @author yellows8
* @author mtheall
* @author fincs
* @copyright libnx Authors
*/
#pragma once
#include "../../types.h"
#include "../../services/fs.h"
/// 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.
} romfs_header;
/// RomFS directory.
typedef struct
{
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)
} romfs_file;
/**
* @brief Mounts the Application's RomFS.
* @param name Device mount name.
* @remark This function is intended to be used to access one's own RomFS.
* If the application is running as NRO, it mounts the embedded RomFS section inside the NRO.
* If on the other hand it's an NSO, it behaves identically to \ref romfsMountFromCurrentProcess.
*/
Result romfsMountSelf(const char *name);
/**
* @brief Mounts RomFS from an open file.
* @param file FsFile of the RomFS image.
* @param offset Offset of the RomFS within the file.
* @param name Device mount name.
*/
Result romfsMountFromFile(FsFile file, u64 offset, const char *name);
/**
* @brief Mounts RomFS from an open storage.
* @param storage FsStorage of the RomFS image.
* @param offset Offset of the RomFS within the storage.
* @param name Device mount name.
*/
Result romfsMountFromStorage(FsStorage storage, u64 offset, const char *name);
/**
* @brief Mounts RomFS using the current process host title RomFS.
* @param name Device mount name.
*/
Result romfsMountFromCurrentProcess(const char *name);
/**
* @brief Mounts RomFS from a file path in a mounted fsdev device.
* @param path File path.
* @param offset Offset of the RomFS within the file.
* @param name Device mount name.
*/
Result romfsMountFromFsdev(const char *path, u64 offset, const char *name);
/**
* @brief Mounts RomFS from a system data archive.
* @param dataId Title ID of system data archive to mount.
* @param storageId Storage ID to mount from.
* @param name Device mount name.
*/
Result romfsMountFromDataArchive(u64 dataId, FsStorageId storageId, const char *name);
/// Unmounts the RomFS device.
Result romfsUnmount(const char *name);
/// Wrapper for \ref romfsMountSelf with the default "romfs" device name.
static inline Result romfsInit(void)
{
return romfsMountSelf("romfs");
}
/// Wrapper for \ref romfsUnmount with the default "romfs" device name.
static inline Result romfsExit(void)
{
return romfsUnmount("romfs");
}