libnx
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 
14 /// RomFS header.
15 typedef struct
16 {
17  u64 headerSize; ///< Size of the header.
18  u64 dirHashTableOff; ///< Offset of the directory hash table.
19  u64 dirHashTableSize; ///< Size of the directory hash table.
20  u64 dirTableOff; ///< Offset of the directory table.
21  u64 dirTableSize; ///< Size of the directory table.
22  u64 fileHashTableOff; ///< Offset of the file hash table.
23  u64 fileHashTableSize; ///< Size of the file hash table.
24  u64 fileTableOff; ///< Offset of the file table.
25  u64 fileTableSize; ///< Size of the file table.
26  u64 fileDataOff; ///< Offset of the file data.
27 } romfs_header;
28 
29 /// RomFS directory.
30 typedef struct
31 {
32  u32 parent; ///< Offset of the parent directory.
33  u32 sibling; ///< Offset of the next sibling directory.
34  u32 childDir; ///< Offset of the first child directory.
35  u32 childFile; ///< Offset of the first file.
36  u32 nextHash; ///< Directory hash table pointer.
37  u32 nameLen; ///< Name length.
38  uint8_t name[]; ///< Name. (UTF-8)
39 } romfs_dir;
40 
41 /// RomFS file.
42 typedef struct
43 {
44  u32 parent; ///< Offset of the parent directory.
45  u32 sibling; ///< Offset of the next sibling file.
46  u64 dataOff; ///< Offset of the file's data.
47  u64 dataSize; ///< Length of the file's data.
48  u32 nextHash; ///< File hash table pointer.
49  u32 nameLen; ///< Name length.
50  uint8_t name[]; ///< Name. (UTF-8)
51 } romfs_file;
52 
53 struct romfs_mount;
54 
55 /**
56  * @brief Mounts the Application's RomFS.
57  * @param mount Output mount handle
58  */
59 Result romfsMount(struct romfs_mount **mount);
60 static inline Result romfsInit(void)
61 {
62  return romfsMount(NULL);
63 }
64 
65 /**
66  * @brief Mounts RomFS from an open file.
67  * @param file FsFile of the RomFS image.
68  * @param offset Offset of the RomFS within the file.
69  * @param mount Output mount handle
70  */
71 Result romfsMountFromFile(FsFile file, u64 offset, struct romfs_mount **mount);
72 static inline Result romfsInitFromFile(FsFile file, u64 offset)
73 {
74  return romfsMountFromFile(file, offset, NULL);
75 }
76 
77 /**
78  * @brief Mounts RomFS from an open storage.
79  * @param storage FsStorage of the RomFS image.
80  * @param offset Offset of the RomFS within the storage.
81  * @param mount Output mount handle
82  */
83 Result romfsMountFromStorage(FsStorage storage, u64 offset, struct romfs_mount **mount);
84 static inline Result romfsInitFromStorage(FsStorage storage, u64 offset)
85 {
86  return romfsMountFromStorage(storage, offset, NULL);
87 }
88 
89 /// Bind the RomFS mount
90 Result romfsBind(struct romfs_mount *mount);
91 
92 /// Unmounts the RomFS device.
93 Result romfsUnmount(struct romfs_mount *mount);
94 static inline Result romfsExit(void)
95 {
96  return romfsUnmount(NULL);
97 }
98 
u32 parent
Offset of the parent directory.
Definition: romfs_dev.h:32
u32 sibling
Offset of the next sibling file.
Definition: romfs_dev.h:45
RomFS directory.
Definition: romfs_dev.h:30
u64 dataOff
Offset of the file&#39;s data.
Definition: romfs_dev.h:46
u32 nameLen
Name length.
Definition: romfs_dev.h:37
u32 sibling
Offset of the next sibling directory.
Definition: romfs_dev.h:33
u64 dataSize
Length of the file&#39;s data.
Definition: romfs_dev.h:47
u64 fileHashTableSize
Size of the file hash table.
Definition: romfs_dev.h:23
u32 nextHash
File hash table pointer.
Definition: romfs_dev.h:48
Result romfsMountFromFile(FsFile file, u64 offset, struct romfs_mount **mount)
Mounts RomFS from an open file.
u32 Result
Function error code result type.
Definition: types.h:46
uint64_t u64
64-bit unsigned integer.
Definition: types.h:24
u64 dirTableSize
Size of the directory table.
Definition: romfs_dev.h:21
uint32_t u32
32-bit unsigned integer.
Definition: types.h:23
u64 fileTableSize
Size of the file table.
Definition: romfs_dev.h:25
u32 nameLen
Name length.
Definition: romfs_dev.h:49
Result romfsUnmount(struct romfs_mount *mount)
Unmounts the RomFS device.
RomFS header.
Definition: romfs_dev.h:15
RomFS file.
Definition: romfs_dev.h:42
u32 parent
Offset of the parent directory.
Definition: romfs_dev.h:44
u64 dirHashTableSize
Size of the directory hash table.
Definition: romfs_dev.h:19
u64 dirTableOff
Offset of the directory table.
Definition: romfs_dev.h:20
u64 headerSize
Size of the header.
Definition: romfs_dev.h:17
u32 childDir
Offset of the first child directory.
Definition: romfs_dev.h:34
u64 dirHashTableOff
Offset of the directory hash table.
Definition: romfs_dev.h:18
u64 fileDataOff
Offset of the file data.
Definition: romfs_dev.h:26
Definition: fs.h:27
u32 childFile
Offset of the first file.
Definition: romfs_dev.h:35
Result romfsBind(struct romfs_mount *mount)
Bind the RomFS mount.
Result romfsMountFromStorage(FsStorage storage, u64 offset, struct romfs_mount **mount)
Mounts RomFS from an open storage.
u64 fileTableOff
Offset of the file table.
Definition: romfs_dev.h:24
u32 nextHash
Directory hash table pointer.
Definition: romfs_dev.h:36
u64 fileHashTableOff
Offset of the file hash table.
Definition: romfs_dev.h:22
Definition: fs.h:35
Result romfsMount(struct romfs_mount **mount)
Mounts the Application&#39;s RomFS.