// ============================================= // MAIN MODULE // ============================================= int main(int argc, const char* argv[]) { int i; int r = -1; //int count = 0; int nTry = 0; char* cur_device = NULL; char path[1024] = { 0 }; memset(&path, 0, sizeof(path)); FILE* fp_isolist = NULL; fp_isolist = fopen(SISOPATH"/iso_list.txt", "w"); // always overwrite with clean list... cur_device = (char*)malloc(strlen("/ntfs0:")+1); memset(cur_device, 0, strlen("/ntfs0:")+1); // Try to mount devices ... while(nTry < 1000) { //count = 0; // __io_ntfs_usb000 ... __io_ntfs_usb007 for(i = 0; i < 8 ; i++) { int rr = NTFS_Event_Mount(i); if(rr == 1) { // mount device NTFS_UnMount(i); mounts[i] = NULL; mountCount[i] = 0; mountCount[i] = ntfsMountDevice (disc_ntfs[i], &mounts[i], NTFS_DEFAULT | NTFS_RECOVER); if(mountCount[i] > 0) { //count = 1; } // update counter } else if(rr == -1) { // unmount device NTFS_UnMount(i); //count = 1; } } r = -1; r = NTFS_Test_Device("ntfs0"); if(r >= 0) { strcpy(cur_device, (char*)"/ntfs0:"); break; } r = NTFS_Test_Device("ntfs1"); if(r >= 0) { strcpy(cur_device, (char*)"/ntfs1:"); break; } r = NTFS_Test_Device("ntfs2"); if(r >= 0) { strcpy(cur_device, (char*)"/ntfs2:"); break; } r = NTFS_Test_Device("ntfs3"); if(r >= 0) { strcpy(cur_device, (char*)"/ntfs3:"); break; } nTry++; } if(r>=0 && cur_device) { sprintf(path, "%s/PS3ISO" , cur_device); generate_list(fp_isolist, path, 0); sprintf(path, "%s/PSXISO" , cur_device); generate_list(fp_isolist, path, 0); sprintf(path, "%s/BDISO" , cur_device); generate_list(fp_isolist, path, 0); sprintf(path, "%s/DVDISO" , cur_device); generate_list(fp_isolist, path, 0); } if(fp_isolist) { fclose(fp_isolist); *&fp_isolist = NULL; } NTFS_UnMountAll(); // This flag will let "Simple NTFS ISO Mounter" that this was already launched, // allowing it to continue booting normally... FILE* fp = fopen(SISOPATH"/isolist_finished", "w"); if(fp) { fclose(fp); *&fp = NULL; } sysProcessExitSpawn2( SISOPATH"/RELOAD.SELF", NULL, NULL, NULL, 0, 1001, SYS_PROCESS_SPAWN_STACK_SIZE_1M ); return 0; }
s32 main(s32 argc, const char* argv[]) { int count = 0; int n; padInfo padinfo; padData paddata; char *cur_device = "/ntfs0:"; char path[1024]; // map file functions to libc open, fopen, ... NTFS_init_system_io(); tiny3d_Init(1024*1024); tiny3d_Project2D(); u32 * texture_mem = tiny3d_AllocTexture(64*1024*1024); // alloc 64MB of space for textures (this pointer can be global) u32 * texture_pointer; // use to asign texture space without changes texture_mem if(!texture_mem) return 0; // fail! texture_pointer = texture_mem; ResetFont(); texture_pointer = (u32 *) AddFontFromBitmapArray((u8 *) font , (u8 *) texture_pointer, 32, 255, 16, 32, 2, BIT0_FIRST_PIXEL); initConsole(); ioPadInit(7); DbgHeader("NTFS EXT2/3/4 Example"); /* // Mount all NTFS volumes on all inserted block devices mountCount = ntfsMountAll(&mounts, NTFS_DEFAULT | NTFS_RECOVER); // mountCount = ntfsMountDevice (&__io_ntfs_usb000, &mounts, NTFS_DEFAULT | NTFS_RECOVER); if (mountCount == -1) DPrintf("Error whilst mounting devices (%i).\n", errno); else if (mountCount == 0) DPrintf("No NTFS volumes were found and/or mounted.\n"); else DPrintf("%i NTFS volumes(s) mounted!\n\n", mountCount); */ int i; count = 1; while(1) { if(count > 0) { count--; if(count == 0) { int k; initConsole(); for(k = 0; k < 8; k++) { for (i = 0; i < mountCount[k]; i++) DPrintf("%i - %s:/ (%s) (from usb00%i)\n", i + 1, (mounts[k]+i)->name, ntfsGetVolumeName((mounts[k] + i)->name), ((mounts[k] + i)->interface->ioType & 0xff) - '0'); } int r; cur_device = NULL; r = NTFS_Test_Device("ext0"); DPrintf("\nTest ext0 %i\n" , r); if(r>=0 && !cur_device) cur_device = "/ext0:"; r = NTFS_Test_Device("ext1"); DPrintf("Test ext1 %i\n" , r); if(r>=0 && !cur_device) cur_device = "/ext1:"; r = NTFS_Test_Device("ext2"); DPrintf("Test ext2 %i\n" , r); if(r>=0 && !cur_device) cur_device = "/ext2:"; r = NTFS_Test_Device("ext3"); DPrintf("Test ext3 %i\n" , r); if(r>=0 && !cur_device) cur_device = "/ext3:"; r = NTFS_Test_Device("ntfs0"); DPrintf("Test ntfs0 %i\n" , r); if(r>=0 && !cur_device) cur_device = "/ntfs0:"; r = NTFS_Test_Device("ntfs1"); DPrintf("Test ntfs1 %i\n" , r); if(r>=0 && !cur_device) cur_device = "/ntfs1:"; r = NTFS_Test_Device("ntfs2"); DPrintf("Test ntfs2 %i\n" , r); if(r>=0 && !cur_device) cur_device = "/ntfs2:"; r = NTFS_Test_Device("ntfs3"); DPrintf("Test ntfs3 %i\n" , r); if(r>=0 && !cur_device) cur_device = "/ntfs3:"; if(!cur_device) cur_device = "/ntfs0:"; // by default } } DbgHeader("NTFS EXT2/3/4 Example"); DbgMess("Press X to list device, O to test file and /\\ to exit"); for(i = 0; i < 8 ; i++) { int r = NTFS_Event_Mount(i); if(r == 1) { // mount device NTFS_UnMount(i); mounts[i] = NULL; mountCount[i] = 0; mountCount[i] = ntfsMountDevice (disc_ntfs[i], &mounts[i], NTFS_DEFAULT | NTFS_RECOVER); if(mountCount[i]>0) {count = 1;} // update counter } else if(r == -1) { // unmount device NTFS_UnMount(i); count = 1; } } // DbgMess(); DbgDraw(); tiny3d_Flip(); ioPadGetInfo(&padinfo); for(n = 0; n < MAX_PADS; n++) { static u32 btn_flags = 0; if(padinfo.status[n]) { ioPadGetData(n, &paddata); if(paddata.BTN_CROSS) { if((btn_flags & 1)==0){ btn_flags|=1; max_list = 0; initConsole(); count = 300; DPrintf("Listing 10 entries from %s (5 seconds)\n", cur_device); sprintf(path, "%s", cur_device); list(path, 0); } } else btn_flags&=~1; if(paddata.BTN_CIRCLE) { if((btn_flags & 2)==0){ btn_flags|=2; DPrintf("\n\nWriting / Reading a file from %s\n", cur_device); sprintf(path, "%s/0text", cur_device); mkdir(path, 0777); sprintf(path, "%s/0text/test.txt", cur_device); FILE *fp; fp =fopen(path, "wb"); if(fp) { int i; i = fwrite(message, 1, strlen(message), fp); if(i != strlen(message)) DPrintf("Error writing the file!\n"); fclose(fp); } else DPrintf("Error creating the file!\n"); memset(buffer, 0, 1024); sprintf(path, "%s/0text/test.txt", cur_device); fp = fopen(path, "rb"); if(fp) { int i; // NOTE: for files > 2GB you can use 64 bit method #ifdef USE_64BIT_SEEK struct _reent reent1; DPrintf ("Using _lseek64_r for large files\n"); s64 size = _lseek64_r(&reent1, fp->_file, 0, SEEK_END); _lseek64_r(&reent1, fp->_file, 0, SEEK_SET); DPrintf ("Size of file %i bytes\n", (int) size); #else fseek(fp, 0, SEEK_END); int size = ftell(fp); DPrintf ("Size of file %i bytes\n", size); fseek(fp, 0, SEEK_SET); #endif i = fread(buffer, 1, size, fp); if(i != size) DPrintf("Error reading the file %i!\n", i); fclose(fp); } else DPrintf("Error Reading the file!\n"); DPrintf("Readed From file: %s\n\n", buffer); } } else btn_flags&=~2; if(paddata.BTN_TRIANGLE){ goto out; } } } } out:; DPrintf("Umounting\n"); DbgDraw(); tiny3d_Flip(); NTFS_UnMountAll(); return 0; }