1 /*---------------------------------------------------------------------------*
2 Project: TwlSDK - FS - libraries
3 File: command.h
4
5 Copyright 2007-2008 Nintendo. All rights reserved.
6
7 These coded instructions, statements, and computer programs contain
8 proprietary information of Nintendo of America Inc. and/or Nintendo
9 Company Ltd., and are protected by Federal copyright law. They may
10 not be disclosed to third parties or copied or duplicated in any form,
11 in whole or in part, without the prior written consent of Nintendo.
12
13 $Date:: 2008-12-08#$
14 $Rev: 9544 $
15 $Author: yosizaki $
16
17 *---------------------------------------------------------------------------*/
18
19
20 #if !defined(NITRO_FS_COMMAND_H_)
21 #define NITRO_FS_COMMAND_H_
22
23 #include <nitro/misc.h>
24 #include <nitro/types.h>
25 #include <nitro/fs/archive.h>
26 #include <nitro/fs/file.h>
27 #include <nitro/fs/romfat.h>
28
29
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33
34
35 /*---------------------------------------------------------------------------*/
36 /* Declarations */
37
38 // Structure that packs arguments to temporarily save them to the task list.
39
40 typedef struct FSArgumentForReadFile
41 {
42 void *buffer;
43 u32 length;
44 }
45 FSArgumentForReadFile;
46
47 typedef struct FSArgumentForWriteFile
48 {
49 const void *buffer;
50 u32 length;
51 }
52 FSArgumentForWriteFile;
53
54 typedef struct FSArgumentForSeekDirectory
55 {
56 u32 id;
57 u32 position;
58 }
59 FSArgumentForSeekDirectory;
60
61 typedef struct FSArgumentForReadDirectory
62 {
63 FSDirectoryEntryInfo *info;
64 }
65 FSArgumentForReadDirectory;
66
67 typedef struct FSArgumentForFindPath
68 {
69 u32 baseid;
70 const char *relpath;
71 u32 target_id;
72 BOOL target_is_directory;
73 }
74 FSArgumentForFindPath;
75
76 typedef struct FSArgumentForGetPath
77 {
78 BOOL is_directory;
79 char *buffer;
80 u32 length;
81 }
82 FSArgumentForGetPath;
83
84 typedef struct FSArgumentForOpenFileFast
85 {
86 u32 id;
87 u32 mode;
88 }
89 FSArgumentForOpenFileFast;
90
91 typedef struct FSArgumentForOpenFileDirect
92 {
93 u32 id; // in : requested-id
94 u32 top;
95 u32 bottom;
96 u32 mode;
97 }
98 FSArgumentForOpenFileDirect;
99
100 typedef void FSArgumentForCloseFile;
101 typedef void FSArgumentForActivate;
102 typedef void FSArgumentForIdle;
103 typedef void FSArgumentForSuspend;
104 typedef void FSArgumentForResume;
105
106 typedef struct FSArgumentForOpenFile
107 {
108 u32 baseid;
109 const char *relpath;
110 u32 mode;
111 }
112 FSArgumentForOpenFile;
113
114 typedef struct FSArgumentForSetSeekCache
115 {
116 void *buf;
117 u32 buf_size;
118 }
119 FSArgumentForSetSeekCache;
120
121 typedef struct FSArgumentForSeekFile
122 {
123 int offset;
124 FSSeekFileMode from;
125 }
126 FSArgumentForSeekFile;
127
128 typedef struct FSArgumentForGetFileLength
129 {
130 u32 length;
131 }
132 FSArgumentForGetFileLength;
133
134 typedef struct FSArgumentForGetFilePosition
135 {
136 u32 position;
137 }
138 FSArgumentForGetFilePosition;
139
140 typedef struct FSArgumentForGetArchiveCaps
141 {
142 u32 caps;
143 }
144 FSArgumentForGetArchiveCaps;
145
146 typedef void FSArgumentForMount;
147 typedef void FSArgumentForUnmount;
148
149 typedef struct FSArgumentForCreateFile
150 {
151 u32 baseid;
152 const char *relpath;
153 u32 permit;
154 }
155 FSArgumentForCreateFile;
156
157 typedef struct FSArgumentForDeleteFile
158 {
159 u32 baseid;
160 const char *relpath;
161 }
162 FSArgumentForDeleteFile;
163
164 typedef struct FSArgumentForRenameFile
165 {
166 u32 baseid_src;
167 const char *relpath_src;
168 u32 baseid_dst;
169 const char *relpath_dst;
170 }
171 FSArgumentForRenameFile;
172
173 typedef struct FSArgumentForGetPathInfo
174 {
175 u32 baseid;
176 const char *relpath;
177 FSPathInfo *info;
178 }
179 FSArgumentForGetPathInfo;
180
181 typedef struct FSArgumentForSetPathInfo
182 {
183 u32 baseid;
184 const char *relpath;
185 FSPathInfo *info;
186 }
187 FSArgumentForSetPathInfo;
188
189 typedef FSArgumentForCreateFile FSArgumentForCreateDirectory;
190 typedef FSArgumentForDeleteFile FSArgumentForDeleteDirectory;
191 typedef FSArgumentForRenameFile FSArgumentForRenameDirectory;
192
193 typedef struct FSArgumentForGetArchiveResource
194 {
195 FSArchiveResource *resource;
196 }
197 FSArgumentForGetArchiveResource;
198
199 typedef void FSArgumentForFlushFile;
200
201 typedef struct FSArgumentForSetFileLength
202 {
203 u32 length;
204 }
205 FSArgumentForSetFileLength;
206
207 typedef FSArgumentForOpenFile FSArgumentForOpenDirectory;
208 typedef FSArgumentForCloseFile FSArgumentForCloseDirectory;
209
210
211 /*---------------------------------------------------------------------------*/
212 /* functions */
213
214 /*---------------------------------------------------------------------------*
215 Name: FSi_SendCommand
216
217 Description: Issues a command to an archive.
218 Adjusts the start time and blocks here if it is synchronous.
219
220 Arguments: p_file: FSFile structure that stores the command arguments.
221 command: Command ID
222 blocking: TRUE to block
223
224 Returns: TRUE if the command is successful.
225 *---------------------------------------------------------------------------*/
226 BOOL FSi_SendCommand(FSFile *p_file, FSCommandType command, BOOL blocking);
227
228 /*---------------------------------------------------------------------------*
229 Name: FSi_GetCurrentCommand
230
231 Description: Gets the command that is currently being processed.
232
233 Arguments: file: FSFile structure that stores the command arguments
234
235 Returns: The command that is currently being processed.
236 *---------------------------------------------------------------------------*/
FSi_GetCurrentCommand(const FSFile * file)237 SDK_INLINE FSCommandType FSi_GetCurrentCommand(const FSFile *file)
238 {
239 return (FSCommandType)((file->stat >> FS_FILE_STATUS_CMD_SHIFT) & FS_FILE_STATUS_CMD_MASK);
240 }
241
242 /*---------------------------------------------------------------------------*
243 Name: FSi_WaitForArchiveCompletion
244
245 Description: Waits for asynchronous archive processes to complete.
246 If a command depends on another low-level command, this will be called internally by the procedure.
247
248
249 Arguments: file: FSFile structure that stores the command arguments
250 result: The return value from the archive
251 Processing will actually block only when this is FS_RESULT_PROC_ASYNC.
252
253
254 Returns: The actual processing result
255 *---------------------------------------------------------------------------*/
256 FSResult FSi_WaitForArchiveCompletion(FSFile *file, FSResult result);
257
258 /*---------------------------------------------------------------------------*
259 Name: FSi_GetArchiveChain
260
261 Description: Gets the first registered archive.
262
263 Arguments: None.
264
265 Returns: The first registered archive.
266 *---------------------------------------------------------------------------*/
267 FSArchive* FSi_GetArchiveChain(void);
268
269 /*---------------------------------------------------------------------------*
270 Name: FSi_IsUnreadableRomOffset
271
272 Description: Determines whether the specified ROM offset is unreadable in the current environment.
273
274 Arguments: arc: The calling archive.
275 offset: The ROM offset to check.
276
277 Returns: TRUE if the specified ROM offset is unreadable in the current environment.
278 *---------------------------------------------------------------------------*/
279 BOOL FSi_IsUnreadableRomOffset(FSArchive *arc, u32 offset);
280
281
282 #ifdef __cplusplus
283 } /* extern "C" */
284 #endif
285
286
287 #endif /* NITRO_FS_COMMAND_H_ */
288