libnx  v4.2.2
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.
16 typedef 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.
28 } romfs_header;
29 
30 /// RomFS directory.
31 typedef 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.
43 typedef 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)
52 } romfs_file;
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  */
61 Result 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  */
69 Result 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  */
77 Result 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  */
83 Result romfsMountFromCurrentProcess(const char *name);
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  */
91 Result 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  */
99 Result 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  */
107 Result romfsMountFromDataArchive(u64 dataId, NcmStorageId storageId, const char *name);
108 
109 /// Unmounts the RomFS device.
110 Result romfsUnmount(const char *name);
111 
112 /// Wrapper for \ref romfsMountSelf with the default "romfs" device name.
113 static inline Result romfsInit(void)
114 {
115  return romfsMountSelf("romfs");
116 }
117 
118 /// Wrapper for \ref romfsUnmount with the default "romfs" device name.
119 static inline Result romfsExit(void)
120 {
121  return romfsUnmount("romfs");
122 }
romfs_header
RomFS header.
Definition: romfs_dev.h:16
FsFile
Definition: fs.h:31
romfsMountFromFsdev
Result romfsMountFromFsdev(const char *path, u64 offset, const char *name)
Mounts RomFS from a file path in a mounted fsdev device.
romfs_dir::parent
u32 parent
Offset of the parent directory.
Definition: romfs_dev.h:33
NcmStorageId
NcmStorageId
StorageId.
Definition: ncm_types.h:12
romfs_dir::nextHash
u32 nextHash
Directory hash table pointer.
Definition: romfs_dev.h:37
romfs_dir::nameLen
u32 nameLen
Name length.
Definition: romfs_dev.h:38
romfs_header::fileHashTableSize
u64 fileHashTableSize
Size of the file hash table.
Definition: romfs_dev.h:24
romfs_file::dataOff
u64 dataOff
Offset of the file's data.
Definition: romfs_dev.h:47
romfs_header::fileTableSize
u64 fileTableSize
Size of the file table.
Definition: romfs_dev.h:26
romfsMountDataStorageFromProgram
Result romfsMountDataStorageFromProgram(u64 program_id, const char *name)
Mounts RomFS of a running program.
romfsMountFromStorage
Result romfsMountFromStorage(FsStorage storage, u64 offset, const char *name)
Mounts RomFS from an open storage.
romfs_dir
RomFS directory.
Definition: romfs_dev.h:31
romfs_dir::sibling
u32 sibling
Offset of the next sibling directory.
Definition: romfs_dev.h:34
romfs_file::nextHash
u32 nextHash
File hash table pointer.
Definition: romfs_dev.h:49
romfsMountFromCurrentProcess
Result romfsMountFromCurrentProcess(const char *name)
Mounts RomFS using the current process host program RomFS.
romfs_file::dataSize
u64 dataSize
Length of the file's data.
Definition: romfs_dev.h:48
u32
uint32_t u32
32-bit unsigned integer.
Definition: types.h:21
romfs_file::nameLen
u32 nameLen
Name length.
Definition: romfs_dev.h:50
romfsMountFromDataArchive
Result romfsMountFromDataArchive(u64 dataId, NcmStorageId storageId, const char *name)
Mounts RomFS from SystemData.
romfs_header::fileDataOff
u64 fileDataOff
Offset of the file data.
Definition: romfs_dev.h:27
romfsMountSelf
Result romfsMountSelf(const char *name)
Mounts the Application's RomFS.
FsStorage
Definition: fs.h:39
u64
uint64_t u64
64-bit unsigned integer.
Definition: types.h:22
romfsInit
static Result romfsInit(void)
Wrapper for romfsMountSelf with the default "romfs" device name.
Definition: romfs_dev.h:113
Result
u32 Result
Function error code result type.
Definition: types.h:44
romfs_dir::childDir
u32 childDir
Offset of the first child directory.
Definition: romfs_dev.h:35
romfs_header::headerSize
u64 headerSize
Size of the header.
Definition: romfs_dev.h:18
romfs_header::dirTableSize
u64 dirTableSize
Size of the directory table.
Definition: romfs_dev.h:22
romfs_header::dirHashTableSize
u64 dirHashTableSize
Size of the directory hash table.
Definition: romfs_dev.h:20
romfsExit
static Result romfsExit(void)
Wrapper for romfsUnmount with the default "romfs" device name.
Definition: romfs_dev.h:119
romfs_file::parent
u32 parent
Offset of the parent directory.
Definition: romfs_dev.h:45
romfsUnmount
Result romfsUnmount(const char *name)
Unmounts the RomFS device.
romfs_header::dirTableOff
u64 dirTableOff
Offset of the directory table.
Definition: romfs_dev.h:21
romfs_file::sibling
u32 sibling
Offset of the next sibling file.
Definition: romfs_dev.h:46
romfs_header::fileHashTableOff
u64 fileHashTableOff
Offset of the file hash table.
Definition: romfs_dev.h:23
romfs_dir::childFile
u32 childFile
Offset of the first file.
Definition: romfs_dev.h:36
romfs_file
RomFS file.
Definition: romfs_dev.h:43
romfs_header::dirHashTableOff
u64 dirHashTableOff
Offset of the directory hash table.
Definition: romfs_dev.h:19
romfs_header::fileTableOff
u64 fileTableOff
Offset of the file table.
Definition: romfs_dev.h:25
romfsMountFromFile
Result romfsMountFromFile(FsFile file, u64 offset, const char *name)
Mounts RomFS from an open file.