libnx v4.9.0
Loading...
Searching...
No Matches
romfs_dev.h
Go to the documentation of this file.
1/**
2 * @file romfs_dev.h
3 * @brief RomFS driver.
4 * @author yellows8
5 * @author mtheall
6 * @author fincs
7 * @copyright libnx Authors
8 */
9#pragma once
10
11#include "../../types.h"
12#include "../../services/fs.h"
13#include "../../services/ncm_types.h"
14
15/// RomFS header.
16typedef struct
17{
18 u64 headerSize; ///< Size of the header.
19 u64 dirHashTableOff; ///< Offset of the directory hash table.
20 u64 dirHashTableSize; ///< Size of the directory hash table.
21 u64 dirTableOff; ///< Offset of the directory table.
22 u64 dirTableSize; ///< Size of the directory table.
23 u64 fileHashTableOff; ///< Offset of the file hash table.
24 u64 fileHashTableSize; ///< Size of the file hash table.
25 u64 fileTableOff; ///< Offset of the file table.
26 u64 fileTableSize; ///< Size of the file table.
27 u64 fileDataOff; ///< Offset of the file data.
29
30/// RomFS directory.
31typedef struct
32{
33 u32 parent; ///< Offset of the parent directory.
34 u32 sibling; ///< Offset of the next sibling directory.
35 u32 childDir; ///< Offset of the first child directory.
36 u32 childFile; ///< Offset of the first file.
37 u32 nextHash; ///< Directory hash table pointer.
38 u32 nameLen; ///< Name length.
39 uint8_t name[]; ///< Name. (UTF-8)
40} romfs_dir;
41
42/// RomFS file.
43typedef struct
44{
45 u32 parent; ///< Offset of the parent directory.
46 u32 sibling; ///< Offset of the next sibling file.
47 u64 dataOff; ///< Offset of the file's data.
48 u64 dataSize; ///< Length of the file's data.
49 u32 nextHash; ///< File hash table pointer.
50 u32 nameLen; ///< Name length.
51 uint8_t name[]; ///< Name. (UTF-8)
53
54/**
55 * @brief Mounts the Application's RomFS.
56 * @param name Device mount name.
57 * @remark This function is intended to be used to access one's own RomFS.
58 * If the application is running as NRO, it mounts the embedded RomFS section inside the NRO.
59 * If on the other hand it's an NSO, it behaves identically to \ref romfsMountFromCurrentProcess.
60 */
61Result romfsMountSelf(const char *name);
62
63/**
64 * @brief Mounts RomFS from an open file.
65 * @param file FsFile of the RomFS image.
66 * @param offset Offset of the RomFS within the file.
67 * @param name Device mount name.
68 */
69Result romfsMountFromFile(FsFile file, u64 offset, const char *name);
70
71/**
72 * @brief Mounts RomFS from an open storage.
73 * @param storage FsStorage of the RomFS image.
74 * @param offset Offset of the RomFS within the storage.
75 * @param name Device mount name.
76 */
77Result romfsMountFromStorage(FsStorage storage, u64 offset, const char *name);
78
79/**
80 * @brief Mounts RomFS using the current process host program RomFS.
81 * @param name Device mount name.
82 */
84
85/**
86 * @brief Mounts RomFS of a running program.
87 * @note Permission needs to be set in the NPDM.
88 * @param program_id ProgramId to mount.
89 * @param name Device mount name.
90 */
91Result romfsMountDataStorageFromProgram(u64 program_id, const char *name);
92
93/**
94 * @brief Mounts RomFS from a file path in a mounted fsdev device.
95 * @param path File path.
96 * @param offset Offset of the RomFS within the file.
97 * @param name Device mount name.
98 */
99Result romfsMountFromFsdev(const char *path, u64 offset, const char *name);
100
101/**
102 * @brief Mounts RomFS from SystemData.
103 * @param dataId SystemDataId to mount.
104 * @param storageId Storage ID to mount from.
105 * @param name Device mount name.
106 */
107Result romfsMountFromDataArchive(u64 dataId, NcmStorageId storageId, const char *name);
108
109/// Unmounts the RomFS device.
110Result romfsUnmount(const char *name);
111
112/// Wrapper for \ref romfsMountSelf with the default "romfs" device name.
113static inline Result romfsInit(void)
114{
115 return romfsMountSelf("romfs");
116}
117
118/// Wrapper for \ref romfsUnmount with the default "romfs" device name.
119static inline Result romfsExit(void)
120{
121 return romfsUnmount("romfs");
122}
NcmStorageId
StorageId.
Definition ncm_types.h:12
Result romfsMountFromFsdev(const char *path, u64 offset, const char *name)
Mounts RomFS from a file path in a mounted fsdev device.
static Result romfsInit(void)
Wrapper for romfsMountSelf with the default "romfs" device name.
Definition romfs_dev.h:113
Result romfsMountFromStorage(FsStorage storage, u64 offset, const char *name)
Mounts RomFS from an open storage.
Result romfsMountFromFile(FsFile file, u64 offset, const char *name)
Mounts RomFS from an open file.
Result romfsMountFromCurrentProcess(const char *name)
Mounts RomFS using the current process host program RomFS.
Result romfsMountFromDataArchive(u64 dataId, NcmStorageId storageId, const char *name)
Mounts RomFS from SystemData.
Result romfsMountDataStorageFromProgram(u64 program_id, const char *name)
Mounts RomFS of a running program.
Result romfsMountSelf(const char *name)
Mounts the Application's RomFS.
static Result romfsExit(void)
Wrapper for romfsUnmount with the default "romfs" device name.
Definition romfs_dev.h:119
Result romfsUnmount(const char *name)
Unmounts the RomFS device.
Definition fs.h:31
Definition fs.h:39
RomFS directory.
Definition romfs_dev.h:32
u32 nameLen
Name length.
Definition romfs_dev.h:38
u32 childDir
Offset of the first child directory.
Definition romfs_dev.h:35
u32 parent
Offset of the parent directory.
Definition romfs_dev.h:33
u32 sibling
Offset of the next sibling directory.
Definition romfs_dev.h:34
u32 childFile
Offset of the first file.
Definition romfs_dev.h:36
u32 nextHash
Directory hash table pointer.
Definition romfs_dev.h:37
RomFS file.
Definition romfs_dev.h:44
u32 sibling
Offset of the next sibling file.
Definition romfs_dev.h:46
u64 dataSize
Length of the file's data.
Definition romfs_dev.h:48
u32 nameLen
Name length.
Definition romfs_dev.h:50
u32 nextHash
File hash table pointer.
Definition romfs_dev.h:49
u64 dataOff
Offset of the file's data.
Definition romfs_dev.h:47
u32 parent
Offset of the parent directory.
Definition romfs_dev.h:45
RomFS header.
Definition romfs_dev.h:17
u64 fileDataOff
Offset of the file data.
Definition romfs_dev.h:27
u64 fileHashTableSize
Size of the file hash table.
Definition romfs_dev.h:24
u64 dirTableSize
Size of the directory table.
Definition romfs_dev.h:22
u64 dirTableOff
Offset of the directory table.
Definition romfs_dev.h:21
u64 dirHashTableSize
Size of the directory hash table.
Definition romfs_dev.h:20
u64 fileTableSize
Size of the file table.
Definition romfs_dev.h:26
u64 fileHashTableOff
Offset of the file hash table.
Definition romfs_dev.h:23
u64 headerSize
Size of the header.
Definition romfs_dev.h:18
u64 dirHashTableOff
Offset of the directory hash table.
Definition romfs_dev.h:19
u64 fileTableOff
Offset of the file table.
Definition romfs_dev.h:25
uint64_t u64
64-bit unsigned integer.
Definition types.h:22
u32 Result
Function error code result type.
Definition types.h:44
uint32_t u32
32-bit unsigned integer.
Definition types.h:21