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 #define VF_SEEK_CUR (0x01) 41 #define VF_SEEK_SET (0x00) 42 #define VF_SEEK_END (0x02) 43 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 #define VF_DTA_GET_FILE_ATTR(dta) ((dta).attribute) 110 #define VF_DTA_GET_FILE_NAME_P(dta) ((dta).fileName) 111 #define VF_DTA_GET_LONG_FILE_NAME_P(dta) ((dta).longName) 112 #define VF_DTA_GET_FILE_SIZE(dta) ((dta).fileSize) 113 #define VF_DTA_GET_FILE_SECONDS(dta) VFiConvertFileTimeToSeconds((dta).date, (dta).time) 114 115 116 //Event 117 #define VF_EVENT_NONE (0x00) 118 #define VF_EVENT_INSERTED (0x01) 119 #define VF_EVENT_EJECTED (0x02) 120 121 //Sync Mode 122 #define VF_SYNC_MODE_ON (0x00) /* default */ 123 #define VF_SYNC_MODE_OFF (0x01) 124 125 //Buffering mode 126 #define VF_WRTSOON (0x1) /* write soon */ 127 #define VF_NWRTSOON (0x0) /* not write soon */ 128 #define VF_AUTOSYNC (0x2) /* cache is not used effectively */ 129 #define VF_NAUTOSYNC (0x0) /* cache is used effectively */ 130 #define VF_FAT_WRITE_THRU (0x4) 131 132 #define VF_EJECT_SAFE_WITH_WRITE_THRU (VF_WRTSOON) 133 #define VF_EJECT_SAFE_WITH_WRITE_BACK (VF_NWRTSOON | VF_AUTOSYNC | VF_FAT_WRITE_THRU) 134 #define VF_WRITE_BACK_ON_SIGNIF_API (VF_NWRTSOON | VF_AUTOSYNC) 135 #define VF_WRITE_BACK_CACHE (VF_NWRTSOON | VF_NAUTOSYNC) 136 137 //Sync cache mode 138 #define VF_INVALIDATE (0x1) 139 #define VF_NINVALIDATE (0x0) 140 141 //cache 142 #define VF_CACHE_SIZE_MIN (0x2800) 143 144 145 /*---------------------------------------------------------------------------* 146 * Types/Declarations 147 *---------------------------------------------------------------------------*/ 148 149 typedef void VFFile; 150 typedef void VFDir; 151 typedef void VFVol; 152 typedef s32 VFDevErr; 153 typedef s32 VFErr; 154 typedef u16 VFWchar; 155 typedef u32 VFEvent; 156 157 typedef void (*VFEventCallback)( VFEvent event ); 158 159 typedef struct VFDta { 160 VFFile* file; 161 VFDir* dir; 162 VFVol* vol; 163 164 u32 parentStartCluster; 165 u32 parentPos; 166 167 u32 status; 168 u8 numEntryLFNs; 169 u8 ordinal; 170 u8 check_sum; 171 u8 attr; 172 s8 regExp[VF_PATH_BUF_SIZE]; 173 174 u16 time; 175 u16 date; 176 u32 fileSize; 177 178 u8 attribute; 179 s8 fileName[VF_SHORT_NAME_BUF_SIZE]; 180 s8 longName[VF_LONG_NAME_PATH_SIZE + 2]; 181 s8 pad[2]; 182 } VFDta; 183 184 typedef struct VFWDta { 185 VFFile* file; 186 VFDir* dir; 187 VFVol* vol; 188 189 u32 parentStartCluster; 190 u32 parentPos; 191 u32 status; 192 u8 numEntryLFNs; 193 u8 ordinal; 194 u8 check_sum; 195 u8 attr; 196 s8 regExp[VF_PATH_BUF_SIZE]; 197 198 u16 time; 199 u16 date; 200 201 u32 fileSize; 202 u8 attribute; 203 s8 fileName[VF_SHORT_NAME_BUF_SIZE]; 204 s8 longName[VF_LONG_NAME_PATH_BUF_SIZE + 2]; 205 206 VFWchar regExpUni[VF_LONG_NAME_PATH_CHARS + 1]; 207 VFWchar fileNameUni[VF_SHORT_DOT_NAME_CHARS + 1]; 208 VFWchar longNameUni[VF_LONG_NAME_CHARS + 1]; 209 s8 pad[2]; 210 } VFWDta; 211 212 typedef struct VFTime { 213 s32 sec; 214 s32 min; 215 s32 hour; 216 s32 day; 217 s32 month; 218 s32 year; 219 } VFTime; 220 221 typedef void (*VFTimeStampCallback)( VFTime* time ); 222 223 224 /*---------------------------------------------------------------------------* 225 * Function Prototypes 226 *---------------------------------------------------------------------------*/ 227 228 extern void VFInit ( ); 229 extern void VFInitEx ( void* heapStartAddress, u32 size ); 230 extern void VFFinalize ( ); 231 extern s32 VFIsAvailable( ); 232 233 extern VFDevErr VFCreateSystemFileNANDFlash ( const char* sysFileName, u32 fileSize ); 234 extern VFDevErr VFCreateSystemFileRam ( void* memory, u32 fileSize ); 235 236 extern VFErr VFAttachDriveNANDFlash ( const char* drive ); 237 extern VFErr VFAttachDriveNANDFlashW ( const VFWchar* drive ); 238 extern VFErr VFAttachDriveNANDFlashCache ( const char* drive, void* cacheAddress, u32 cacheSize ); 239 extern VFErr VFAttachDriveNANDFlashCacheW( const VFWchar* drive, void* cacheAddress, u32 cacheSize ); 240 extern VFErr VFAttachDriveRam ( const char* drive ); 241 extern VFErr VFAttachDriveRamW ( const VFWchar* drive ); 242 extern VFErr VFAttachDriveRamCache ( const char* drive, void* cacheAddress, u32 cacheSize ); 243 extern VFErr VFAttachDriveRamCacheW ( const VFWchar* drive, void* cacheAddress, u32 cacheSize ); 244 extern VFErr VFAttachDriveDVD ( const char* drive ); 245 extern VFErr VFAttachDriveDVDW ( const VFWchar* drive ); 246 extern VFErr VFAttachDriveDVDCache ( const char* drive, void* cacheAddress, u32 cacheSize ); 247 extern VFErr VFAttachDriveDVDCacheW ( const VFWchar* drive, void* cacheAddress, u32 cacheSize ); 248 extern VFErr VFDetachDrive ( const char* drive ); 249 extern VFErr VFDetachDriveW ( const VFWchar* drive ); 250 251 extern VFErr VFActivateDriveNANDFlash ( const char* drive, const char* sysFileName ); 252 extern VFErr VFActivateDriveNANDFlashW ( const VFWchar* drive, const char* sysFileName ); 253 extern VFErr VFActivateDriveRam ( const char* drive, void* memory ); 254 extern VFErr VFActivateDriveRamW ( const VFWchar* drive, void* memory ); 255 extern VFErr VFActivateDriveDVD ( const char* drive, const char* sysFileName ); 256 extern VFErr VFActivateDriveDVDW ( const VFWchar* drive, const char* sysFileName ); 257 extern VFErr VFInactivateDrive ( const char* drive ); 258 extern VFErr VFInactivateDriveW ( const VFWchar* drive ); 259 extern VFErr VFInactivateDriveForce ( const char* drive ); 260 extern VFErr VFInactivateDriveForceW ( const VFWchar* drive ); 261 262 extern VFErr VFMountDriveNANDFlash ( const char* drive, const char* sysFileName ); 263 extern VFErr VFMountDriveNANDFlashW ( const VFWchar* drive, const char* sysFileName ); 264 extern VFErr VFMountDriveNANDFlashCache ( const char* drive, const char* sysFileName, void* cacheAddress, u32 cacheSize ); 265 extern VFErr VFMountDriveNANDFlashCacheW ( const VFWchar* drive, const char* sysFileName, void* cacheAddress, u32 cacheSize ); 266 extern VFErr VFMountDriveRam ( const char* drive, void* memory ); 267 extern VFErr VFMountDriveRamW ( const VFWchar* drive, void* memory ); 268 extern VFErr VFMountDriveRamCache ( const char* drive, void* memory, void* cacheAddress, u32 cache_size ); 269 extern VFErr VFMountDriveRamCacheW ( const VFWchar* drive, void* memory, void* cacheAddress, u32 cache_size ); 270 extern VFErr VFMountDriveDVD ( const char* drive, const char* sysFileName ); 271 extern VFErr VFMountDriveDVDW ( const VFWchar* drive, const char* sysFileName ); 272 extern VFErr VFMountDriveDVDCache ( const char* drive, const char* sysFileName, void* cacheAddress, u32 cacheSize ); 273 extern VFErr VFMountDriveDVDCacheW ( const VFWchar* drive, const char* sysFileName, void* cacheAddress, u32 cacheSize ); 274 extern VFErr VFUnmountDrive ( const char* drive ); 275 extern VFErr VFUnmountDriveW ( const VFWchar* drive ); 276 extern VFErr VFUnmountDriveForce ( const char* drive ); 277 extern VFErr VFUnmountDriveForceW ( const VFWchar* drive ); 278 279 extern VFFile* VFCreateFile ( const char* path, u32 attr ); 280 extern VFFile* VFCreateFileW ( const VFWchar* path, u32 attr ); 281 extern VFFile* VFOpenFile ( const char* path, const char* mode, u32 attr ); 282 extern VFFile* VFOpenFileW ( const VFWchar* path, const VFWchar* mode, u32 attr ); 283 extern VFErr VFCloseFile ( VFFile* file ); 284 285 extern VFErr VFSeekFile ( VFFile* file, s32 offset, s32 origin ); 286 extern VFErr VFReadFile ( VFFile* file, void* buf, u32 size , u32* read_size ); 287 extern VFErr VFWriteFile ( VFFile* file, const void* buf, u32 size ); 288 extern VFErr VFDeleteFile ( const char* path ); 289 extern VFErr VFDeleteFileW ( const VFWchar* path ); 290 extern VFErr VFRenameFile ( const char* old_name, const char* new_name ); 291 extern VFErr VFRenameFileW ( const VFWchar* old_name, const VFWchar* new_name ); 292 extern VFErr VFMoveFile ( const char* src_name, const char* dst_name ); 293 extern VFErr VFMoveFileW ( const VFWchar* src_name, const VFWchar* dst_name ); 294 extern VFErr VFRenameDir ( const char* old_name, const char* new_name ); 295 extern VFErr VFRenameDirW ( const VFWchar* old_name, const VFWchar* new_name ); 296 extern VFErr VFMoveDir ( const char* src_name, const char* dst_name ); 297 extern VFErr VFMoveDirW ( const VFWchar* src_name, const VFWchar* dst_name ); 298 extern VFErr VFCreateDir ( const char* dirName ); 299 extern VFErr VFCreateDirW ( const VFWchar* dirName ); 300 extern VFErr VFChangeDir ( const char* dirName ); 301 extern VFErr VFChangeDirW ( const VFWchar* dirName ); 302 extern VFErr VFDeleteDir ( const char* dirName ); 303 extern VFErr VFDeleteDirW ( const VFWchar* dirName ); 304 extern s32 VFGetFileSize ( const char* path ); 305 extern s32 VFGetFileSizeW ( const VFWchar* path ); 306 extern VFErr VFGetFileSizeU32 ( const char* path, u32* file_size ); 307 extern VFErr VFGetFileSizeU32W ( const VFWchar* path, u32* file_size ); 308 extern VFErr VFFileSearchFirst ( VFDta* dta, const char* path, u8 attr ); 309 extern VFErr VFFileSearchFirstW ( VFWDta* dta, const VFWchar* path, u8 attr ); 310 extern VFErr VFFileSearchNext ( VFDta* dta ); 311 extern VFErr VFFileSearchNextW ( VFWDta* dta ); 312 313 extern VFErr VFGetLastError ( void ); 314 315 extern VFDevErr VFGetLastDeviceError ( const char* drive ); 316 extern VFDevErr VFGetLastDeviceErrorW ( const VFWchar* drive ); 317 extern s32 VFGetDriveFreeSize ( const char* drive ); 318 extern s32 VFGetDriveFreeSizeW ( const VFWchar* drive ); 319 extern VFErr VFGetDriveFreeSizeU64 ( const char* drive, u64* free_size ); 320 extern VFErr VFGetDriveFreeSizeU64W ( const VFWchar* drive, u64* free_size ); 321 extern s32 VFGetOffsetByFd ( VFFile* file ); 322 extern VFErr VFGetOffsetU32ByFd ( VFFile* file, u32* offset ); 323 extern s32 VFGetFileSizeByFd ( VFFile* file ); 324 extern VFErr VFGetFileSizeU32ByFd ( VFFile* file, u32* file_size ); 325 326 extern VFErr VFCutFileSize ( const char* path, u32 fileSize ); 327 extern VFErr VFCutFileSizeW ( const VFWchar* path, u32 fileSize ); 328 329 extern VFErr VFFormatDrive ( const char* drive ); 330 extern VFErr VFFormatDriveW ( const VFWchar* drive ); 331 332 extern VFErr VFSetSyncMode ( const char* drive, u32 mode ); 333 extern VFErr VFSetSyncModeW ( const VFWchar* drive, u32 mode ); 334 335 extern VFErr VFSync ( const char* drive, s32 mode ); 336 extern VFErr VFSyncW ( const VFWchar* drive, s32 mode ); 337 extern VFErr VFFileSync ( VFFile* file ); 338 339 extern VFErr VFBuffering ( const char* drive, s32 mode ); 340 extern VFErr VFBufferingW ( const VFWchar* drive, s32 mode ); 341 342 extern VFDevErr VFDeleteSystemFileNANDFlash ( const char* sysFileName ); 343 extern VFTimeStampCallback VFSetTimeStampCallback ( VFTimeStampCallback i_timestamp_callback ); 344 extern const char* VFGetApiErrorString ( VFErr error ); 345 346 //internal function 347 extern s64 VFiConvertFileTimeToSeconds ( u16 date, u16 time ); 348 //test proc 349 350 351 #ifdef __cplusplus 352 } 353 #endif // __cplusplus 354 #endif // __VF_H__ 355