libctru  v2.3.1
romfs.h
Go to the documentation of this file.
1 /**
2  * @file romfs.h
3  * @brief RomFS driver.
4  */
5 #pragma once
6 
7 #include <3ds/types.h>
8 #include <3ds/services/fs.h>
9 
10 /// RomFS header.
11 typedef struct
12 {
13  u32 headerSize; ///< Size of the header.
14  u32 dirHashTableOff; ///< Offset of the directory hash table.
15  u32 dirHashTableSize; ///< Size of the directory hash table.
16  u32 dirTableOff; ///< Offset of the directory table.
17  u32 dirTableSize; ///< Size of the directory table.
18  u32 fileHashTableOff; ///< Offset of the file hash table.
19  u32 fileHashTableSize; ///< Size of the file hash table.
20  u32 fileTableOff; ///< Offset of the file table.
21  u32 fileTableSize; ///< Size of the file table.
22  u32 fileDataOff; ///< Offset of the file data.
23 } romfs_header;
24 
25 /// RomFS directory.
26 typedef struct
27 {
28  u32 parent; ///< Offset of the parent directory.
29  u32 sibling; ///< Offset of the next sibling directory.
30  u32 childDir; ///< Offset of the first child directory.
31  u32 childFile; ///< Offset of the first file.
32  u32 nextHash; ///< Directory hash table pointer.
33  u32 nameLen; ///< Name length.
34  u16 name[]; ///< Name. (UTF-16)
35 } romfs_dir;
36 
37 /// RomFS file.
38 typedef struct
39 {
40  u32 parent; ///< Offset of the parent directory.
41  u32 sibling; ///< Offset of the next sibling file.
42  u64 dataOff; ///< Offset of the file's data.
43  u64 dataSize; ///< Length of the file's data.
44  u32 nextHash; ///< File hash table pointer.
45  u32 nameLen; ///< Name length.
46  u16 name[]; ///< Name. (UTF-16)
47 } romfs_file;
48 
49 /**
50  * @brief Mounts the Application's RomFS.
51  * @param name Device mount name.
52  * @remark This function is intended to be used to access one's own RomFS.
53  * If the application is running as 3DSX, it mounts the embedded RomFS section inside the 3DSX.
54  * If on the other hand it's an NCCH, it behaves identically to \ref romfsMountFromCurrentProcess.
55  */
56 Result romfsMountSelf(const char *name);
57 
58 /**
59  * @brief Mounts RomFS from an open file.
60  * @param fd FSFILE handle of the RomFS image.
61  * @param offset Offset of the RomFS within the file.
62  * @param name Device mount name.
63  */
64 Result romfsMountFromFile(Handle fd, u32 offset, const char *name);
65 
66 /**
67  * @brief Mounts RomFS using the current process host program RomFS.
68  * @param name Device mount name.
69  */
71 
72 /**
73  * @brief Mounts RomFS from the specified title.
74  * @param tid Title ID
75  * @param mediatype Mediatype
76  * @param name Device mount name.
77  */
78 Result romfsMountFromTitle(u64 tid, FS_MediaType mediatype, const char* name);
79 
80 /// Unmounts the RomFS device.
81 Result romfsUnmount(const char *name);
82 
83 /// Wrapper for \ref romfsMountSelf with the default "romfs" device name.
84 static inline Result romfsInit(void)
85 {
86  return romfsMountSelf("romfs");
87 }
88 
89 /// Wrapper for \ref romfsUnmount with the default "romfs" device name.
90 static inline Result romfsExit(void)
91 {
92  return romfsUnmount("romfs");
93 }
Filesystem Services.
FS_MediaType
Media types.
Definition: fs.h:35
static Result romfsInit(void)
Wrapper for romfsMountSelf with the default "romfs" device name.
Definition: romfs.h:84
Result romfsMountFromTitle(u64 tid, FS_MediaType mediatype, const char *name)
Mounts RomFS from the specified title.
Result romfsMountFromCurrentProcess(const char *name)
Mounts RomFS using the current process host program RomFS.
Result romfsMountFromFile(Handle fd, u32 offset, const char *name)
Mounts RomFS from an open file.
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.h:90
Result romfsUnmount(const char *name)
Unmounts the RomFS device.
RomFS directory.
Definition: romfs.h:27
u32 nameLen
Name length.
Definition: romfs.h:33
u32 childDir
Offset of the first child directory.
Definition: romfs.h:30
u32 parent
Offset of the parent directory.
Definition: romfs.h:28
u32 sibling
Offset of the next sibling directory.
Definition: romfs.h:29
u32 childFile
Offset of the first file.
Definition: romfs.h:31
u32 nextHash
Directory hash table pointer.
Definition: romfs.h:32
RomFS file.
Definition: romfs.h:39
u32 sibling
Offset of the next sibling file.
Definition: romfs.h:41
u64 dataSize
Length of the file's data.
Definition: romfs.h:43
u32 nameLen
Name length.
Definition: romfs.h:45
u32 nextHash
File hash table pointer.
Definition: romfs.h:44
u64 dataOff
Offset of the file's data.
Definition: romfs.h:42
u32 parent
Offset of the parent directory.
Definition: romfs.h:40
RomFS header.
Definition: romfs.h:12
u32 headerSize
Size of the header.
Definition: romfs.h:13
u32 fileTableOff
Offset of the file table.
Definition: romfs.h:20
u32 fileHashTableOff
Offset of the file hash table.
Definition: romfs.h:18
u32 dirTableSize
Size of the directory table.
Definition: romfs.h:17
u32 fileDataOff
Offset of the file data.
Definition: romfs.h:22
u32 dirHashTableSize
Size of the directory hash table.
Definition: romfs.h:15
u32 fileTableSize
Size of the file table.
Definition: romfs.h:21
u32 fileHashTableSize
Size of the file hash table.
Definition: romfs.h:19
u32 dirTableOff
Offset of the directory table.
Definition: romfs.h:16
u32 dirHashTableOff
Offset of the directory hash table.
Definition: romfs.h:14
Various system types.
uint64_t u64
64-bit unsigned integer
Definition: types.h:24
u32 Handle
Resource handle.
Definition: types.h:41
s32 Result
Function result.
Definition: types.h:42
uint16_t u16
16-bit unsigned integer
Definition: types.h:22
uint32_t u32
32-bit unsigned integer
Definition: types.h:23