1 /*---------------------------------------------------------------------------* 2 Project: Revolution Virtual File System library 3 File: vf.h 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 14 #ifndef __VF_H__ 15 #define __VF_H__ 16 17 #ifdef __cplusplus 18 extern "C" { 19 #endif // __cplusplus 20 21 #include <stddef.h> 22 23 /*---------------------------------------------------------------------------* 24 * Includes 25 *---------------------------------------------------------------------------*/ 26 #if defined(RVL_OS) 27 #include <revolution/types.h> 28 #else 29 #include <revolution/vf/VFPrivate.h> 30 #endif 31 32 33 /*---------------------------------------------------------------------------* 34 * Definitions 35 *---------------------------------------------------------------------------*/ 36 37 #define VF_IS_UNAVAILABLE (0) 38 #define VF_IS_AVAILABLE (1) 39 40 41 #define VF_SEEK_CUR (0x01) 42 #define VF_SEEK_SET (0x00) 43 #define VF_SEEK_END (0x02) 44 45 #define VF_ERR_SUCCESS (0) 46 #define VF_ERR_EPERM 1 /* Operation is not possible */ 47 #define VF_ERR_ENOENT 2 /* No such file or directory */ 48 #define VF_ERR_EIO 5 /* I/O Error(Driver Error) */ 49 #define VF_ERR_ENOEXEC 8 /* Not Executable by internal */ 50 #define VF_ERR_EBADF 9 /* Bad file descriptor */ 51 #define VF_ERR_ENOMEM 12 /* Not enough system memory */ 52 #define VF_ERR_EACCES 13 /* Permission denied */ 53 #define VF_ERR_EBUSY 16 /* Can not use system resouces */ 54 #define VF_ERR_EEXIST 17 /* File already exists */ 55 #define VF_ERR_EISDIR 21 /* find directory when file req */ 56 #define VF_ERR_EINVAL 22 /* Invalid argument */ 57 #define VF_ERR_ENFILE 23 /* Too many open files(system) */ 58 #define VF_ERR_EMFILE 24 /* Too many open files(user) */ 59 #define VF_ERR_EFBIG 27 /* Over file size limit(4GB-1) */ 60 #define VF_ERR_ENOSPC 28 /* Device out of space */ 61 #define VF_ERR_ENOLCK 46 /* Can not lock the file */ 62 #define VF_ERR_ENOSYS 88 /* Not implement function */ 63 #define VF_ERR_ENOTEMPTY 90 /* Directory is not empty */ 64 //#define VF_ERR_DFNC 0x1000 /* Driver Error */ 65 #define VF_ERR_SYSTEM (-1) /* system error(general error) */ 66 67 #define VF_ERR_BASE (0xb000) 68 #define VF_ERR_NOT_EXIST_FILE (VF_ERR_BASE + 0x01) 69 #define VF_ERR_CANNOT_ALLOC_DRV (VF_ERR_BASE + 0x02) 70 #define VF_ERR_NOT_ALLOCATED_DRV (VF_ERR_BASE + 0x03) 71 #define VF_ERR_ALREADY_ATTACHED_DRV_NAME (VF_ERR_BASE + 0x04) 72 #define VF_ERR_ALREADY_MOUNTED_DRV_NAME (VF_ERR_BASE + 0x05) 73 #define VF_ERR_VFF_FILE_FORMAT (VF_ERR_BASE + 0x06) 74 75 76 #define VF_DRIVE_WORKSIZE (16 * 1024) 77 #if defined(RVL_OS) 78 #define VF_DRIVE_MAX (26) 79 #else 80 #define VF_DRIVE_MAX (2) 81 #endif 82 83 #define VF_DRIVE_NAME_MAX (7) 84 #define VF_DRIVE_NAME_MAX_INC_NULL (VF_DRIVE_NAME_MAX + 1) 85 86 #define VF_LONG_NAME_PATH_CHARS (260-1) 87 #define VF_LONG_NAME_PATH_SIZE (VF_LONG_NAME_PATH_CHARS * 2) 88 #define VF_LONG_NAME_PATH_BUF_SIZE (VF_LONG_NAME_PATH_SIZE + 2) 89 #define VF_PATH_BUF_SIZE VF_LONG_NAME_PATH_BUF_SIZE 90 91 #define VF_SHORT_DOT_NAME_SIZE (12) 92 #define VF_SHORT_NAME_BUF_SIZE (VF_SHORT_DOT_NAME_SIZE + 1) 93 94 #define VF_SHORT_DOT_NAME_CHARS (12) 95 #define VF_LONG_NAME_CHARS (255) 96 97 98 //File attributes 99 #define VF_ATTR_RDONLY ((u8)0x01) /* read only */ 100 #define VF_ATTR_HIDDEN ((u8)0x02) /* hidden */ 101 #define VF_ATTR_SYSTEM ((u8)0x04) /* system */ 102 #define VF_ATTR_VOLUME ((u8)0x08) /* volume label */ 103 #define VF_ATTR_DIR ((u8)0x10) /* subdirectory */ 104 #define VF_ATTR_ARCH ((u8)0x20) /* archives */ 105 #define VF_ATTR_NONE ((u8)0x40) /* none */ 106 #define VF_ATTR_ALL ((u8)0x7f) /* for fsfirst function */ 107 #define VF_ATTR_CAND ((u8)0x80) /* AND mode */ 108 109 110 #define VF_DTA_GET_FILE_ATTR(dta) ((dta).attribute) 111 #define VF_DTA_GET_FILE_NAME_P(dta) ((dta).fileName) 112 #define VF_DTA_GET_LONG_FILE_NAME_P(dta) ((dta).longName) 113 #define VF_DTA_GET_FILE_SIZE(dta) ((dta).fileSize) 114 #define VF_DTA_GET_FILE_SECONDS(dta) \ 115 VFiConvertFileTimeToSeconds((dta).date, (dta).time) 116 117 118 119 //Event 120 #define VF_EVENT_NONE (0x00) 121 #define VF_EVENT_INSERTED (0x01) 122 #define VF_EVENT_EJECTED (0x02) 123 124 125 //Sync Mode 126 #define VF_SYNC_MODE_ON (0x00) //default 127 #define VF_SYNC_MODE_OFF (0x01) 128 129 //Buffering mode 130 #define VF_WRTSOON (0x1) /* write soon */ 131 #define VF_NWRTSOON (0x0) /* not write soon */ 132 #define VF_AUTOSYNC (0x2) /* cache is not used effectively */ 133 #define VF_NAUTOSYNC (0x0) /* cache is used effectively */ 134 #define VF_FAT_WRITE_THRU (0x4) 135 136 #define VF_EJECT_SAFE_WITH_WRITE_THRU (VF_WRTSOON) 137 #define VF_EJECT_SAFE_WITH_WRITE_BACK (VF_NWRTSOON | VF_AUTOSYNC | VF_FAT_WRITE_THRU) 138 #define VF_WRITE_BACK_ON_SIGNIF_API (VF_NWRTSOON | VF_AUTOSYNC) 139 #define VF_WRITE_BACK_CACHE (VF_NWRTSOON | VF_NAUTOSYNC) 140 141 //Sync cache mode 142 #define VF_INVALIDATE (0x1) 143 #define VF_NINVALIDATE (0x0) 144 145 146 //cache 147 #define VF_CACHE_SIZE_MIN (0x2800) 148 149 /*---------------------------------------------------------------------------* 150 * Types/Declarations 151 *---------------------------------------------------------------------------*/ 152 153 typedef void VFFile; 154 typedef void VFDir; 155 typedef void VFVol; 156 typedef s32 VFDevErr; 157 typedef s32 VFErr; 158 typedef u16 VFWchar; 159 typedef u32 VFEvent; 160 161 typedef void (*VFEventCallback)( VFEvent event ); 162 163 typedef struct VFDta { 164 VFFile* file; 165 VFDir* dir; 166 VFVol* vol; 167 168 u32 parentStartCluster; 169 u32 parentPos; 170 171 u32 status; 172 u8 numEntryLFNs; 173 u8 ordinal; 174 u8 check_sum; 175 u8 attr; 176 s8 regExp[VF_PATH_BUF_SIZE]; 177 178 u16 time; 179 u16 date; 180 u32 fileSize; 181 182 u8 attribute; 183 s8 fileName[VF_SHORT_NAME_BUF_SIZE]; 184 s8 longName[VF_LONG_NAME_PATH_SIZE + 2]; 185 s8 pad[2]; 186 } VFDta; 187 188 typedef struct VFWDta { 189 VFFile* file; 190 VFDir* dir; 191 VFVol* vol; 192 193 u32 parentStartCluster; 194 u32 parentPos; 195 u32 status; 196 u8 numEntryLFNs; 197 u8 ordinal; 198 u8 check_sum; 199 u8 attr; 200 s8 regExp[VF_PATH_BUF_SIZE]; 201 202 u16 time; 203 u16 date; 204 205 u32 fileSize; 206 u8 attribute; 207 s8 fileName[VF_SHORT_NAME_BUF_SIZE]; 208 s8 longName[VF_LONG_NAME_PATH_BUF_SIZE + 2]; 209 210 VFWchar regExpUni[VF_LONG_NAME_PATH_CHARS + 1]; 211 VFWchar fileNameUni[VF_SHORT_DOT_NAME_CHARS + 1]; 212 VFWchar longNameUni[VF_LONG_NAME_CHARS + 1]; 213 s8 pad[2]; 214 } VFWDta; 215 216 typedef struct VFTime { 217 s32 sec; 218 s32 min; 219 s32 hour; 220 s32 day; 221 s32 month; 222 s32 year; 223 } VFTime; 224 225 typedef void (*VFTimeStampCallback)( VFTime* time ); 226 227 /*---------------------------------------------------------------------------* 228 * Function Prototypes 229 *---------------------------------------------------------------------------*/ 230 231 extern void VFInit ( ); 232 extern void VFInitEx ( void* heapStartAddress, u32 size ); 233 extern void VFFinalize ( ); 234 extern s32 VFIsAvailable( ); 235 236 extern VFDevErr VFCreateSystemFileNANDFlash( const char* sysFileName, u32 fileSize ); 237 extern VFDevErr VFCreateSystemFileRam ( void* memory, u32 fileSize ); 238 239 240 extern VFErr VFAttachDriveNANDFlash ( const char* drive ); 241 extern VFErr VFAttachDriveNANDFlashW ( const VFWchar* drive ); 242 extern VFErr VFAttachDriveNANDFlashCache( const char* drive, void* cacheAddress, u32 cacheSize ); 243 extern VFErr VFAttachDriveNANDFlashCacheW( const VFWchar* drive, void* cacheAddress, u32 cacheSize ); 244 extern VFErr VFAttachDriveRam ( const char* drive ); 245 extern VFErr VFAttachDriveRamW ( const VFWchar* drive ); 246 extern VFErr VFAttachDriveRamCache ( const char* drive, void* cacheAddress, u32 cacheSize ); 247 extern VFErr VFAttachDriveRamCacheW ( const VFWchar* drive, void* cacheAddress, u32 cacheSize ); 248 extern VFErr VFAttachDriveDVD ( const char* drive ); 249 extern VFErr VFAttachDriveDVDW ( const VFWchar* drive ); 250 extern VFErr VFAttachDriveDVDCache ( const char* drive, void* cacheAddress, u32 cacheSize ); 251 extern VFErr VFAttachDriveDVDCacheW ( const VFWchar* drive, void* cacheAddress, u32 cacheSize ); 252 extern VFErr VFDetachDrive ( const char* drive ); 253 extern VFErr VFDetachDriveW ( const VFWchar* drive ); 254 255 256 extern VFErr VFActivateDriveNANDFlash ( const char* drive, const char* sysFileName ); 257 extern VFErr VFActivateDriveNANDFlashW ( const VFWchar* drive, const char* sysFileName ); 258 extern VFErr VFActivateDriveRam ( const char* drive, void* memory ); 259 extern VFErr VFActivateDriveRamW ( const VFWchar* drive, void* memory ); 260 extern VFErr VFActivateDriveDVD ( const char* drive, const char* sysFileName ); 261 extern VFErr VFActivateDriveDVDW ( const VFWchar* drive, const char* sysFileName ); 262 extern VFErr VFInactivateDrive ( const char* drive ); 263 extern VFErr VFInactivateDriveW ( const VFWchar* drive ); 264 extern VFErr VFInactivateDriveForce ( const char* drive ); 265 extern VFErr VFInactivateDriveForceW ( const VFWchar* drive ); 266 267 268 extern VFErr VFMountDriveNANDFlash ( const char* drive, const char* sysFileName ); 269 extern VFErr VFMountDriveNANDFlashW ( const VFWchar* drive, const char* sysFileName ); 270 extern VFErr VFMountDriveNANDFlashCache ( const char* drive, const char* sysFileName, void* cacheAddress, u32 cacheSize ); 271 extern VFErr VFMountDriveNANDFlashCacheW( const VFWchar* drive, const char* sysFileName, void* cacheAddress, u32 cacheSize ); 272 extern VFErr VFMountDriveRam ( const char* drive, void* memory ); 273 extern VFErr VFMountDriveRamW ( const VFWchar* drive, void* memory ); 274 extern VFErr VFMountDriveRamCache ( const char* drive, void* memory, void* cacheAddress, u32 cache_size ); 275 extern VFErr VFMountDriveRamCacheW ( const VFWchar* drive, void* memory, void* cacheAddress, u32 cache_size ); 276 extern VFErr VFMountDriveDVD ( const char* drive, const char* sysFileName ); 277 extern VFErr VFMountDriveDVDW ( const VFWchar* drive, const char* sysFileName ); 278 extern VFErr VFMountDriveDVDCache ( const char* drive, const char* sysFileName, void* cacheAddress, u32 cacheSize ); 279 extern VFErr VFMountDriveDVDCacheW ( const VFWchar* drive, const char* sysFileName, void* cacheAddress, u32 cacheSize ); 280 extern VFErr VFUnmountDrive ( const char* drive ); 281 extern VFErr VFUnmountDriveW ( const VFWchar* drive ); 282 extern VFErr VFUnmountDriveForce ( const char* drive ); 283 extern VFErr VFUnmountDriveForceW ( const VFWchar* drive ); 284 285 286 extern VFFile* VFCreateFile ( const char* path, u32 attr ); 287 extern VFFile* VFCreateFileW ( const VFWchar* path, u32 attr ); 288 extern VFFile* VFOpenFile ( const char* path, const char* mode, u32 attr ); 289 extern VFFile* VFOpenFileW ( const VFWchar* path, const VFWchar* mode, u32 attr ); 290 extern VFErr VFCloseFile ( VFFile* file ); 291 292 extern VFErr VFSeekFile ( VFFile* file, s32 offset, s32 origin ); 293 extern VFErr VFReadFile ( VFFile* file, void* buf, u32 size , u32* read_size ); 294 extern VFErr VFWriteFile ( VFFile* file, const void* buf, u32 size ); 295 extern VFErr VFDeleteFile ( const char* path ); 296 extern VFErr VFDeleteFileW ( const VFWchar* path ); 297 extern VFErr VFRenameFile ( const char* old_name, const char* new_name ); 298 extern VFErr VFRenameFileW ( const VFWchar* old_name, const VFWchar* new_name ); 299 extern VFErr VFMoveFile ( const char* src_name, const char* dst_name ); 300 extern VFErr VFMoveFileW ( const VFWchar* src_name, const VFWchar* dst_name ); 301 extern VFErr VFRenameDir ( const char* old_name, const char* new_name ); 302 extern VFErr VFRenameDirW ( const VFWchar* old_name, const VFWchar* new_name ); 303 extern VFErr VFMoveDir ( const char* src_name, const char* dst_name ); 304 extern VFErr VFMoveDirW ( const VFWchar* src_name, const VFWchar* dst_name ); 305 extern VFErr VFCreateDir ( const char* dirName ); 306 extern VFErr VFCreateDirW ( const VFWchar* dirName ); 307 extern VFErr VFChangeDir ( const char* dirName ); 308 extern VFErr VFChangeDirW ( const VFWchar* dirName ); 309 extern VFErr VFDeleteDir ( const char* dirName ); 310 extern VFErr VFDeleteDirW ( const VFWchar* dirName ); 311 extern s32 VFGetFileSize ( const char* path ); 312 extern s32 VFGetFileSizeW ( const VFWchar* path ); 313 extern VFErr VFFileSearchFirst ( VFDta* dta, const char* path, u8 attr ); 314 extern VFErr VFFileSearchFirstW ( VFWDta* dta, const VFWchar* path, u8 attr ); 315 extern VFErr VFFileSearchNext ( VFDta* dta ); 316 extern VFErr VFFileSearchNextW ( VFWDta* dta ); 317 318 extern VFErr VFGetLastError ( void ); 319 320 extern VFDevErr VFGetLastDeviceError ( const char* drive ); 321 extern VFDevErr VFGetLastDeviceErrorW ( const VFWchar* drive ); 322 extern s32 VFGetDriveFreeSize ( const char* drive ); 323 extern s32 VFGetDriveFreeSizeW ( const VFWchar* drive ); 324 extern s32 VFGetOffsetByFd ( VFFile* file ); 325 extern s32 VFGetFileSizeByFd ( VFFile* file ); 326 327 extern VFErr VFCutFileSize ( const char* path, u32 fileSize ); 328 extern VFErr VFCutFileSizeW ( const VFWchar* path, u32 fileSize ); 329 330 extern VFErr VFFormatDrive ( const char* drive ); 331 extern VFErr VFFormatDriveW ( const VFWchar* drive ); 332 333 extern VFErr VFSetSyncMode ( const char* drive, u32 mode ); 334 extern VFErr VFSetSyncModeW ( const VFWchar* drive, u32 mode ); 335 336 extern VFErr VFSync ( const char* drive, s32 mode ); 337 extern VFErr VFSyncW ( const VFWchar* drive, s32 mode ); 338 extern VFErr VFFileSync ( VFFile* file ); 339 340 extern VFErr VFBuffering ( const char* drive, s32 mode ); 341 extern VFErr VFBufferingW ( const VFWchar* drive, s32 mode ); 342 343 extern VFDevErr VFDeleteSystemFileNANDFlash( const char* sysFileName ); 344 extern VFTimeStampCallback VFSetTimeStampCallback ( VFTimeStampCallback i_timestamp_callback ); 345 extern const char* VFGetApiErrorString ( VFErr error ); 346 347 //internal function 348 extern s64 VFiConvertFileTimeToSeconds( u16 date, u16 time ); 349 // test proc 350 351 352 #ifdef __cplusplus 353 } 354 #endif // __cplusplus 355 #endif // __VF_H__ 356