1 /*---------------------------------------------------------------------------* 2 Project: content API library 3 File: cnt.c 4 5 Copyright (C) 2006 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 $Log: cnt.h,v $ 14 Revision 1.19 2009/07/16 12:27:22 wada_jumpei 15 Added CNTSetAutoFatalMessaging. 16 17 Revision 1.18 2008/04/30 05:51:21 wada_jumpei 18 Added DVD emulation for data titles. 19 20 Revision 1.17 2008/01/28 00:23:09 wada_jumpei 21 Added contentInitHandle[NAND/DVD]Ex for old modules. 22 Modified CNTDir and CNTDirEntry. 23 24 Revision 1.16 2008/01/23 12:50:55 wada_jumpei 25 Modified CNTHandle and CNTFileInfo. 26 27 Revision 1.15 2008/01/10 13:49:38 wada_jumpei 28 Added contentRead[NAND/DVD]Modified and created CNTReadWithOffset. 29 30 Revision 1.14 2007/11/19 02:46:10 wada_jumpei 31 Added CNT_RESULT_DVD_CANCELED. 32 33 Revision 1.13 2007/09/21 00:38:23 johnc 34 Added data title support (CNTInitHandleTitle). 35 Change most all functions to switch between DVD/NAND at runtime. 36 This library should be backward compatible. 37 38 Revision 1.12 2007/06/28 00:01:35 wada_jumpei 39 Fixed definition argument name of CNTInitHandle 40 41 Revision 1.11 2007/04/27 11:05:54 wada_jumpei 42 Added CNTGetFSTSize 43 44 Revision 1.10 2007/03/28 07:59:10 wada_jumpei 45 Added 32 byte alignment check for memory allocator 46 47 Revision 1.9 2006/12/12 07:52:38 wada_jumpei 48 Added OSRegisterVersion and removed restriction of path length 49 50 Revision 1.8 2006/12/06 07:36:12 wada_jumpei 51 Modified error code and error message 52 Added CNTTell to prevent direct access to fileinfo member 53 54 Revision 1.7 2006/10/26 04:28:07 wada_jumpei 55 Added some error code and assertion 56 57 Revision 1.6 2006/10/01 14:49:46 wada_jumpei 58 Added CNTFastOpen and removed unused header file 59 60 Revision 1.5 2006/09/29 08:32:08 shirakae 61 Added CNTConvertPathToEntrynum, CNTEntrynumIsDir 62 63 Revision 1.4 2006/09/26 14:17:48 wada_jumpei 64 Added CNTShutdown for device shutdown 65 66 Revision 1.3 2006/08/24 06:06:23 wada_jumpei 67 Added relative path support and directory access 68 69 Revision 1.2 2006/08/10 12:15:24 wada_jumpei 70 Modified error codes and added some comments 71 72 Revision 1.1 2006/08/10 12:10:30 wada_jumpei 73 Initial check in 74 75 *---------------------------------------------------------------------------*/ 76 77 #ifndef __CNT_H__ 78 #define __CNT_H__ 79 80 #include <revolution/dvd.h> 81 #include <revolution/arc.h> 82 #include <revolution/mem.h> 83 #include <revolution/types.h> 84 85 #ifdef __cplusplus 86 extern "C" { 87 #endif 88 89 /*----------------------------------------------------------------------------* 90 Definition of constant values 91 *----------------------------------------------------------------------------*/ 92 93 /* ---CNT_RESULT_CODE --- */ 94 #define CNT_RESULT_OK 0 95 #define CNT_RESULT_MAXFD (-5000) 96 #define CNT_RESULT_ALLOC_FAILED (-5001) 97 #define CNT_RESULT_READ_ERR (-5003) 98 #define CNT_RESULT_CLOSE_ERR (-5005) 99 #define CNT_RESULT_OUT_OF_MEMORY (-5008) 100 #define CNT_RESULT_INVALID (-5009) 101 #define CNT_RESULT_ACCESS (-5010) 102 #define CNT_RESULT_CORRUPT (-5011) 103 #define CNT_RESULT_ECC_CRIT (-5012) 104 #define CNT_RESULT_AUTHENTICATION (-5013) 105 #define CNT_RESULT_DVD_CANCELED (-5014) 106 #define CNT_RESULT_UNKNOWN (-5063) 107 #define CNT_RESULT_FATAL (-5127) 108 109 /* --- OLD result codes (unused or unified) --- */ 110 //#define CNT_RESULT_OPEN_ERR (-5002) 111 //#define CNT_RESULT_SEEK_ERR (-5004) 112 //#define CNT_RESULT_NOT_EXIST (-5006) 113 //#define CNT_RESULT_NOT_ENOUGH_SPACE (-5007) 114 115 116 /* --- Parametar "whence" in CNTSeek --- */ 117 #define CNT_SEEK_SET 0 // start of the file 118 #define CNT_SEEK_CUR 1 // current point 119 #define CNT_SEEK_END 2 // end of the file (note that "offset" must be negative) 120 121 122 /*----------------------------------------------------------------------------* 123 Definition of structures for CNT API 124 *----------------------------------------------------------------------------*/ 125 126 typedef enum 127 { 128 CNT_TYPE_UNDEFINED = 0, 129 CNT_TYPE_NAND = 1, 130 CNT_TYPE_DVD = 2 131 } CNTType; 132 133 // structure for CNThandle 134 typedef struct 135 { 136 ARCHandle ArcHandle; 137 s32 FileDescriptor; 138 MEMAllocator* allocator; 139 } CNTHandleNAND; 140 141 typedef struct 142 { 143 u32 index; 144 s32 rootDir; 145 s32 currDir; 146 u8 reserved[24]; 147 } CNTHandleDVD; 148 149 typedef struct 150 { 151 union { 152 CNTHandleNAND nand; 153 CNTHandleDVD dvd; 154 } as; 155 u8 type; // CNTType 156 157 } CNTHandle; 158 159 // structure for file access 160 typedef struct 161 { 162 CNTHandleNAND* CntHandle; 163 u32 startOffset; 164 u32 length; 165 s32 readOffset; 166 } CNTFileInfoNAND; 167 168 typedef struct 169 { 170 DVDFileInfo fileInfo; 171 s32 readOffset; 172 } CNTFileInfoDVD; 173 174 typedef struct 175 { 176 union { 177 CNTFileInfoNAND nand; 178 CNTFileInfoDVD dvd; 179 } as; 180 u8 type; // CNTType 181 182 } CNTFileInfo; 183 184 // structure for directory access 185 typedef struct 186 { 187 ARCHandle* handle; // from here, same as ARCDir (type is nand if handle is non-NULL) 188 u32 entryNum; // from here, same as DVDDir 189 u32 location; 190 u32 next; 191 192 u8 type; // CNTType 193 194 } CNTDir; 195 196 typedef struct 197 { 198 ARCHandle* handle; // from here, same as ARCDir (type is nand if handle is non-NULL) 199 u32 entryNum; // from here, same as DVDDir 200 BOOL isDir; 201 char* name; 202 203 u8 type; // CNTType 204 205 } CNTDirEntry; 206 207 /*----------------------------------------------------------------------------* 208 Definition of common APIs 209 *----------------------------------------------------------------------------*/ 210 211 void CNTInit ( void ); 212 void CNTShutdown ( void ); 213 214 /*----------------------------------------------------------------------------* 215 Definition of the APIs for NAND applications 216 *----------------------------------------------------------------------------*/ 217 218 // Handle access API 219 s32 contentInitHandleNAND ( u32 contentIdx, CNTHandleNAND* Cnt, MEMAllocator* allocator ); 220 s32 contentInitHandleNANDEx ( u32 contentIdx, CNTHandle* Cnt, MEMAllocator* allocator ); 221 s32 contentInitHandleTitleNAND ( u64 titleId, u32 contentIdx, CNTHandle* Cnt, MEMAllocator* allocator ); 222 s32 contentReleaseHandleNAND ( CNTHandleNAND* Cnt ); 223 224 // File access API 225 s32 contentOpenNAND ( CNTHandleNAND* Cnt, const char* filename, CNTFileInfoNAND* cf ); 226 s32 contentReadNAND ( CNTFileInfoNAND* cf, void* addr, u32 length, s32 offset ); 227 s32 contentReadNANDModified ( CNTFileInfoNAND* cf, void* addr, u32 length ); 228 s32 contentSeekNAND ( CNTFileInfoNAND* cf, s32 offset, u32 whence ); 229 s32 contentTellNAND ( CNTFileInfoNAND* cf ); 230 u32 contentGetLengthNAND ( CNTFileInfoNAND* cf ); 231 s32 contentCloseNAND ( CNTFileInfoNAND* cf ); 232 233 s32 contentFastOpenNAND ( CNTHandleNAND* Cnt, s32 entrynum, CNTFileInfoNAND* cf ); 234 s32 contentConvertPathToEntrynumNAND ( CNTHandleNAND* Cnt, const char* filename ); 235 236 // Support directory change and relative path 237 s32 contentChangeDirNAND ( CNTHandleNAND* Cnt, const char* dirName ); 238 s32 contentGetCurrentDirNAND ( CNTHandleNAND* Cnt, char* path, u32 maxlen ); 239 240 // Directory access API 241 BOOL contentOpenDirNAND ( CNTHandleNAND* Cnt, const char* dirName, ARCDir* dir ); 242 243 // Get FST length 244 s32 contentGetFSTSizeNAND ( u32 contentIdx, u32* size ); 245 246 /*----------------------------------------------------------------------------* 247 Definition of the APIs for DVD applications 248 *----------------------------------------------------------------------------*/ 249 250 // Handle access API 251 s32 contentInitHandleDVD ( u32 contentIdx, CNTHandleDVD* Cnt, MEMAllocator* allocator ); 252 s32 contentInitHandleDVDEx ( u32 contentIdx, CNTHandle* Cnt, MEMAllocator* allocator ); 253 s32 contentInitHandleTitleDVD ( u64 titleId, u32 contentIdx, CNTHandle* Cnt, MEMAllocator* allocator ); 254 s32 contentReleaseHandleDVD ( CNTHandleDVD* Cnt ); 255 256 // File access API 257 s32 contentOpenDVD ( CNTHandleDVD* Cnt, const char* filename, CNTFileInfoDVD* cf ); 258 s32 contentReadDVD ( CNTFileInfoDVD* cf, void* addr, u32 length, s32 offset ); 259 s32 contentReadDVDModified ( CNTFileInfoDVD* cf, void* addr, u32 length ); 260 s32 contentSeekDVD ( CNTFileInfoDVD* cf, s32 offset, u32 whence ); 261 s32 contentTellDVD ( CNTFileInfoDVD* cf ); 262 u32 contentGetLengthDVD ( CNTFileInfoDVD* cf ); 263 s32 contentCloseDVD ( CNTFileInfoDVD* cf ); 264 265 s32 contentFastOpenDVD ( CNTHandleDVD* Cnt, s32 entrynum, CNTFileInfoDVD* cf ); 266 s32 contentConvertPathToEntrynumDVD ( CNTHandleDVD* Cnt, const char* filename ); 267 268 // Support directory change and relative path 269 s32 contentChangeDirDVD ( CNTHandleDVD* Cnt, const char* dirName ); 270 s32 contentGetCurrentDirDVD ( CNTHandleDVD* Cnt, char* path, u32 maxlen ); 271 272 // Directory access API 273 BOOL contentOpenDirDVD ( CNTHandleDVD* Cnt, const char* dirName, DVDDir* dir ); 274 275 // Get FST length 276 s32 contentGetFSTSizeDVD ( u32 contentIdx, u32* size ); 277 278 /*----------------------------------------------------------------------------* 279 Convert APIs by compile switch "NANDAPP" 280 *----------------------------------------------------------------------------*/ 281 282 #ifdef NANDAPP 283 #define CNTInitHandle( contentIdx, CntHandle, allocator ) contentInitHandleNANDEx( (contentIdx), (CntHandle), (allocator) ) 284 #define CNTInitHandleTitle( titleId, contentIdx, CntHandle, allocator ) contentInitHandleTitleNAND( (titleId), (contentIdx), (CntHandle), (allocator) ) 285 #define CNTGetFSTSize( index, size ) contentGetFSTSizeNAND( (index), (size) ) 286 #else // DVDDiscAPP 287 #define CNTInitHandle( contentIdx, CntHandle, allocator ) contentInitHandleDVDEx( (contentIdx), (CntHandle), (allocator) ) 288 #define CNTInitHandleTitle( titleId, contentIdx, CntHandle, allocator ) contentInitHandleTitleDVD( (titleId), (contentIdx), (CntHandle), (allocator) ) 289 #define CNTGetFSTSize( index, size ) contentGetFSTSizeDVD( (index), (size) ) 290 #endif 291 292 s32 CNTReleaseHandle ( CNTHandle* Cnt ); 293 294 s32 CNTOpen ( CNTHandle* Cnt, const char* filename, CNTFileInfo* cf ); 295 s32 CNTRead ( CNTFileInfo* cf, void* addr, u32 length ); 296 s32 CNTReadWithOffset ( CNTFileInfo* cf, void* addr, u32 length, s32 offset ); 297 s32 CNTSeek ( CNTFileInfo* cf, s32 offset, u32 whence ); 298 s32 CNTTell ( CNTFileInfo* cf ); 299 u32 CNTGetLength ( CNTFileInfo* cf ); 300 s32 CNTClose ( CNTFileInfo* cf ); 301 302 s32 CNTFastOpen ( CNTHandle* Cnt, s32 entrynum, CNTFileInfo* cf ); 303 s32 CNTConvertPathToEntrynum ( CNTHandle* Cnt, const char* filename ); 304 BOOL CNTEntrynumIsDir ( CNTHandle* Cnt, s32 entrynum ); 305 306 s32 CNTChangeDir ( CNTHandle* Cnt, const char* dirName ); 307 s32 CNTGetCurrentDir ( CNTHandle* Cnt, char* path, u32 maxlen ); 308 309 BOOL CNTOpenDir ( CNTHandle* Cnt, const char* dirName, CNTDir* dir ); 310 BOOL CNTReadDir ( CNTDir* dir, CNTDirEntry* dirent ); 311 BOOL CNTCloseDir ( CNTDir* dir ); 312 u32 CNTTellDir ( CNTDir* dir ); 313 void CNTSeekDir ( CNTDir* dir, u32 loc ); 314 void CNTRewindDir ( CNTDir* dir ); 315 316 BOOL CNTSetAutoFatalMessaging ( BOOL enable ); 317 318 #ifdef CNT_READ_BACKWARD_COMPATIBLE 319 #define CNTRead CNTReadWithOffset 320 #endif 321 322 #ifdef __cplusplus 323 } 324 #endif 325 326 #endif // end of __CNT_H__ 327