libctru  v1.6.0
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 
9 /// RomFS header.
10 typedef struct
11 {
12  u32 headerSize; ///< Size of the header.
13  u32 dirHashTableOff; ///< Offset of the directory hash table.
14  u32 dirHashTableSize; ///< Size of the directory hash table.
15  u32 dirTableOff; ///< Offset of the directory table.
16  u32 dirTableSize; ///< Size of the directory table.
17  u32 fileHashTableOff; ///< Offset of the file hash table.
18  u32 fileHashTableSize; ///< Size of the file hash table.
19  u32 fileTableOff; ///< Offset of the file table.
20  u32 fileTableSize; ///< Size of the file table.
21  u32 fileDataOff; ///< Offset of the file data.
22 } romfs_header;
23 
24 /// RomFS directory.
25 typedef struct
26 {
27  u32 parent; ///< Offset of the parent directory.
28  u32 sibling; ///< Offset of the next sibling directory.
29  u32 childDir; ///< Offset of the first child directory.
30  u32 childFile; ///< Offset of the first file.
31  u32 nextHash; ///< Directory hash table pointer.
32  u32 nameLen; ///< Name length.
33  u16 name[]; ///< Name. (UTF-16)
34 } romfs_dir;
35 
36 /// RomFS file.
37 typedef struct
38 {
39  u32 parent; ///< Offset of the parent directory.
40  u32 sibling; ///< Offset of the next sibling file.
41  u64 dataOff; ///< Offset of the file's data.
42  u64 dataSize; ///< Length of the file's data.
43  u32 nextHash; ///< File hash table pointer.
44  u32 nameLen; ///< Name length.
45  u16 name[]; ///< Name. (UTF-16)
46 } romfs_file;
47 
48 struct romfs_mount;
49 
50 /**
51  * @brief Mounts the Application's RomFS.
52  * @param mount Output mount handle
53  */
54 Result romfsMount(struct romfs_mount **mount);
55 static inline Result romfsInit(void)
56 {
57  return romfsMount(NULL);
58 }
59 
60 /**
61  * @brief Mounts RomFS from an open file.
62  * @param file Handle of the RomFS file.
63  * @param offset Offset of the RomFS within the file.
64  * @param mount Output mount handle
65  */
66 Result romfsMountFromFile(Handle file, u32 offset, struct romfs_mount **mount);
67 static inline Result romfsInitFromFile(Handle file, u32 offset)
68 {
69  return romfsMountFromFile(file, offset, NULL);
70 }
71 
72 /// Bind the RomFS mount
73 Result romfsBind(struct romfs_mount *mount);
74 
75 /// Unmounts the RomFS device.
76 Result romfsUnmount(struct romfs_mount *mount);
77 static inline Result romfsExit(void)
78 {
79  return romfsUnmount(NULL);
80 }
u32 parent
Offset of the parent directory.
Definition: romfs.h:27
u32 sibling
Offset of the next sibling file.
Definition: romfs.h:40
Various system types.
u32 fileTableOff
Offset of the file table.
Definition: romfs.h:19
u32 fileHashTableSize
Size of the file hash table.
Definition: romfs.h:18
s32 Result
Function result.
Definition: types.h:42
u32 dirTableOff
Offset of the directory table.
Definition: romfs.h:15
uint16_t u16
16-bit unsigned integer
Definition: types.h:22
RomFS directory.
Definition: romfs.h:25
Result romfsMountFromFile(Handle file, u32 offset, struct romfs_mount **mount)
Mounts RomFS from an open file.
u32 fileTableSize
Size of the file table.
Definition: romfs.h:20
u64 dataOff
Offset of the file's data.
Definition: romfs.h:41
u32 nameLen
Name length.
Definition: romfs.h:32
u32 sibling
Offset of the next sibling directory.
Definition: romfs.h:28
u64 dataSize
Length of the file's data.
Definition: romfs.h:42
u32 nextHash
File hash table pointer.
Definition: romfs.h:43
u32 Handle
Resource handle.
Definition: types.h:41
u32 headerSize
Size of the header.
Definition: romfs.h:12
Result romfsMount(struct romfs_mount **mount)
Mounts the Application's RomFS.
uint64_t u64
64-bit unsigned integer
Definition: types.h:24
u32 dirTableSize
Size of the directory table.
Definition: romfs.h:16
u32 dirHashTableOff
Offset of the directory hash table.
Definition: romfs.h:13
uint32_t u32
32-bit unsigned integer
Definition: types.h:23
u32 nameLen
Name length.
Definition: romfs.h:44
RomFS header.
Definition: romfs.h:10
RomFS file.
Definition: romfs.h:37
u32 parent
Offset of the parent directory.
Definition: romfs.h:39
Result romfsBind(struct romfs_mount *mount)
Bind the RomFS mount.
u32 fileHashTableOff
Offset of the file hash table.
Definition: romfs.h:17
u32 dirHashTableSize
Size of the directory hash table.
Definition: romfs.h:14
u32 childDir
Offset of the first child directory.
Definition: romfs.h:29
u32 fileDataOff
Offset of the file data.
Definition: romfs.h:21
u32 childFile
Offset of the first file.
Definition: romfs.h:30
Result romfsUnmount(struct romfs_mount *mount)
Unmounts the RomFS device.
u32 nextHash
Directory hash table pointer.
Definition: romfs.h:31