static int myIoGetstat(const char *path, SceIoStat *stat) { int ret; if(g_keys_bin_found || g_is_custom_ps1) { if(strstr(path, PGD_ID)) { stat->st_mode = 0x21FF; stat->st_attr = 0x20; stat->st_size = 152; ret = 0; printk("%s: [FAKE]\n", __func__); } else if (0 == strcmp(path, ACT_DAT)) { stat->st_mode = 0x21FF; stat->st_attr = 0x20; stat->st_size = 4152; ret = 0; printk("%s: [FAKE]\n", __func__); } else { ret = sceIoGetstat(path, stat); } } else { ret = sceIoGetstat(path, stat); } printk("%s: %s -> 0x%08X\n", __func__, path, ret); return ret; }
int FileCopy(char* srcPath, char* destPath, char* fileName) { SceIoStat fileStat; char path[258]; sprintf(path,"%s/%s",srcPath, fileName); if(sceIoGetstat(path, &fileStat) < 0) return -1; u8* data = malloc(fileStat.st_size); SceUID fileId = sceIoOpen(path, PSP_O_RDONLY, 0777); if(fileId < 0) { printf("Fail opening %s\n",path); free(data); return -1; } sceIoRead(fileId, data, fileStat.st_size); sceIoClose(fileId); sprintf(path,"%s/%s",destPath, fileName); fileId = sceIoOpen(path, PSP_O_WRONLY | PSP_O_CREAT, 0777); if(fileId < 0) { printf("Fail opening %s\n",path); return -1; } sceIoWrite(fileId, data, fileStat.st_size); sceIoClose(fileId); free(data); return 0; }
void getSubFiles(char* pDir, CStringList& pOut, CString* search) { SceUID dir; if ((dir = sceIoDopen(pDir)) <= 0) return; SceIoDirent ent; SceIoStat statx; while (sceIoDread(dir, &ent) > 0) { CString fullName = CString() << pDir << ent.d_name; sceIoGetstat(fullName.text(), &statx); if (!(statx.st_mode & S_IFDIR)) { if (search != 0) { CString s( *search ); CString m( ent.d_name ); s.replaceAll( "%", "*" ); s << ".txt"; if (m.match( s.text()) == false) continue; } pOut.add( ent.d_name ); } } sceIoDclose(dir); }
/** * Get file size * @param fileName name of file in unicode format * @param fileNameLen length of file name * @return size of file in bytes if successful, -1 otherwise */ javacall_int64 javacall_file_sizeof(const javacall_utf16 * fileName, int fileNameLen) { /* javacall_handle handle = 0; int flags = 0; javacall_result rslt1 = javacall_file_open(fileName, fileNameLen, flags, &handle); if (rslt1 != JAVACALL_OK) { return -1; } long size = javacall_file_sizeofopenfile(handle); javacall_file_close(handle); return size; */ int res; SceIoStat stat; char* pszOsFilename = javacall_UNICODEsToUtf8(fileName, fileNameLen); if (pszOsFilename == NULL) { return JAVACALL_FAIL; } res = sceIoGetstat(pszOsFilename, &stat); if (res < 0) { printf("File %s doesn't exist\n", pszOsFilename); return -1; } else { return stat.st_size; } }
SceUID load_mod_file(u32 number) { int ret = -1; SceIoStat stat; for(u32 i = 0; i < ITEMSOF(mod_path); i++) { if(i == 0) { if(loaded_mib) { sprintf(filename, mod_path[0], loaded_mib, number); } else { continue; } } else { sprintf(filename, mod_path[i], number); } SET_DEVICENAME(filename, model_go); kprintf("trying to open %s\n", filename); memset(&stat, 0, sizeof(stat)); if(sceIoGetstat(filename, &stat) >= 0) { ret = sceIoOpen(filename, PSP_O_RDONLY, 0777); break; } } return ret; }
static int mkdir_recursive(const char *path) { int exit_status = 1; SceIoStat stat; if (sceIoGetstat(path, &stat) == 0){ /* If not a directory, cannot continue; otherwise success */ exit_status = SCE_S_ISDIR(stat.st_mode); return exit_status; } /* First, try creating its parent directory */ char *slash_pos = strrchr(path, '/'); if (!slash_pos); /* Top level */ else if (slash_pos != path && slash_pos[-1] == ':'); /* Top level */ else { char *parent = strdup(path); parent[slash_pos - path] = '\0'; exit_status = mkdir_recursive(parent); free(parent); } if (exit_status && slash_pos[1] != '\0') { int status = sceIoMkdir(path, 0777); if (status != 0) exit_status = 0; } return exit_status; }
/* Function to open the file pointed to by the path. * */ void *PspIoStream::open() { DEBUG_ENTER_FUNC(); if (PowerMan.beginCriticalSection()) { // No need to open? Just return the _handle resume() already opened PSP_DEBUG_PRINT_FUNC("suspended\n"); } _handle = sceIoOpen(_path.c_str(), _writeMode ? PSP_O_WRONLY | PSP_O_CREAT | PSP_O_TRUNC : PSP_O_RDONLY, 0777); if (!_handle) { _error = true; _handle = NULL; } // Get the file size. This way is much faster than going to the end of the file and back SceIoStat stat; sceIoGetstat(_path.c_str(), &stat); _fileSize = *((uint32 *)(void *)&stat.st_size); // 4GB file (32 bits) is big enough for us PSP_DEBUG_PRINT("%s filesize[%d]\n", _path.c_str(), _fileSize); PowerMan.registerForSuspend(this); // Register with the powermanager to be suspended PowerMan.endCriticalSection(); return (void *)_handle; }
int vpbp_getstat(const char * file, SceIoStat * stat) { int ret; VirtualPBP *vpbp; lock(); vpbp = get_vpbp_by_path(file); if (vpbp == NULL) { printk("%s: Unknown file %s in vpbp list\n", __func__, file); unlock(); return -30; } ret = sceIoGetstat(vpbp->name, stat); stat->st_mode = 0x21FF; stat->st_attr = 0x20; stat->st_size = vpbp->iso_total_size; memcpy(&stat->st_ctime, &vpbp->ctime, sizeof(ScePspDateTime)); memcpy(&stat->st_mtime, &vpbp->ctime, sizeof(ScePspDateTime)); memcpy(&stat->st_atime, &vpbp->ctime, sizeof(ScePspDateTime)); unlock(); return ret; }
int hook_sceIoGetstat(const char *file, SceIoStat *stat) { sceKernelCheckCallback(); char tmpPath[MAX_PATH_LENGTH]; char *tmp=TranslateVFS(tmpPath, file); return sceIoGetstat(tmp, stat); }
int hook_sceIoGetstat(const char *file, SceIoStat *stat) { state_machine_checkState(); char tmpPath[MAX_PATH_LENGTH]; char *tmp=TranslateVFS(tmpPath, file); return sceIoGetstat(tmp, stat); }
int FileExist(char* basePath, char* dirPath, char* fileName) { SceIoStat fileStat; char path[1024]; sprintf(path,"%s%s/%s",basePath, dirPath, fileName); if(sceIoGetstat(path, &fileStat) < 0) // no file return 0; return 1; }
int is_file_exist(const char *path) { SceIoStat stat; int ret; ret = sceIoGetstat(path, &stat); return ret == 0 ? 1 : 0; }
/* Returns size of file in bytes or <0 if error */ int pl_file_get_file_size(const char *path) { SceIoStat stat; memset(&stat, 0, sizeof(stat)); if (sceIoGetstat(path, &stat) < 0) return -1; return (int)stat.st_size; }
static bool music_is_file_exist(const char *filename) { SceIoStat sta; if (sceIoGetstat(filename, &sta) < 0) { return false; } return true; }
int Dir_NotExist(const char *PathDirectory) { SceIoStat stato; sceIoGetstat( PathDirectory, &stato); if ( stato.st_mode & FIO_S_IFDIR ) { return 1; }else{ return 0; } }
static bool path_stat(const char *path, enum stat_mode mode) { #if defined(VITA) || defined(PSP) SceIoStat buf; char *tmp = strdup(path); size_t len = strlen(tmp); if (tmp[len-1] == '/') tmp[len-1]='\0'; if (sceIoGetstat(tmp, &buf) < 0) { free(tmp); return false; } free(tmp); #elif defined(__CELLOS_LV2__) CellFsStat buf; if (cellFsStat(path, &buf) < 0) return false; #elif defined(_WIN32) DWORD ret = GetFileAttributes(path); if (ret == INVALID_FILE_ATTRIBUTES) return false; #else struct stat buf; if (stat(path, &buf) < 0) return false; #endif switch (mode) { case IS_DIRECTORY: #if defined(VITA) || defined(PSP) return FIO_S_ISDIR(buf.st_mode); #elif defined(__CELLOS_LV2__) return ((buf.st_mode & S_IFMT) == S_IFDIR); #elif defined(_WIN32) return (ret & FILE_ATTRIBUTE_DIRECTORY); #else return S_ISDIR(buf.st_mode); #endif case IS_CHARACTER_SPECIAL: #if defined(VITA) || defined(PSP) || defined(__CELLOS_LV2__) || defined(_WIN32) return false; #else return S_ISCHR(buf.st_mode); #endif case IS_VALID: return true; } return false; }
int getPathInfo(char *path, uint32_t *size, uint32_t *folders, uint32_t *files) { SceUID dfd = sceIoDopen(path); if (dfd >= 0) { int res = 0; do { SceIoDirent dir; memset(&dir, 0, sizeof(SceIoDirent)); res = sceIoDread(dfd, &dir); if (res > 0) { if (strcmp(dir.d_name, ".") == 0 || strcmp(dir.d_name, "..") == 0) continue; char *new_path = malloc(strlen(path) + strlen(dir.d_name) + 2); snprintf(new_path, MAX_PATH_LENGTH, "%s/%s", path, dir.d_name); if (SCE_S_ISDIR(dir.d_stat.st_mode)) { getPathInfo(new_path, size, folders, files); } else { if (size) (*size) += dir.d_stat.st_size; if (files) (*files)++; } free(new_path); } } while (res > 0); sceIoDclose(dfd); if (folders) (*folders)++; } else { if (size) { SceIoStat stat; memset(&stat, 0, sizeof(SceIoStat)); int res = sceIoGetstat(path, &stat); if (res < 0) return res; (*size) += stat.st_size; } if (files) (*files)++; } return 0; }
/* Subroutine sceHttpStorageGetstat - Address 0x000002F0 Exported in sceHttpStorage_driver Exported in sceHttpStorage */ u32 sceHttpStorageGetstat(int a0, int a1) { s32 oldk1 = pspShiftK1(); //0x310 if (((oldk1 << 11) & a1) >= 0) { //0x318 if (a0 != 0) { //0x320 if (a0 != ((oldk1 << 11) & a1)) { pspSetK1(oldk1); return 0x80000100; } int stat = sceIoGetstat("flash1:/net/http/cookie.dat", (SceIoStat *) a1); pspSetK1(oldk1); return stat; } int stat = sceIoGetstat("flash1:/net/http/auth.dat", (SceIoStat *) a1); pspSetK1(oldk1); return stat; } pspSetK1(oldk1); return 0x800001FF; }
int check_game(game_info_t* game_info) { // get the game's module info SceModule* module = NULL; while (module == NULL) { sceKernelDelayThread(1000000); module = sceKernelFindModuleByAddress(0x08804000); } // set the module id and game name game_info->module_id = module->modid; strcpy(game_info->game_name, module->modname); // get the game's global pointer // NOTE: the SceModule structure is incorrect, text_addr is actually the gp_value unsigned int module_gp = module->text_addr; // add the offset to the global pointer, add the offset to the character pointer, // set the size and file name based on the game name if (strcmp("MonsterHunterPSP", game_info->game_name) == 0) { module_gp -= 0x6e60; game_info->character = (char *) 648; game_info->size = 0x46a0; strcat(game_info->file_name, "mhp.bin"); } else if (strcmp("MonsterHunterPortable2nd", game_info->game_name) == 0) { module_gp -= 0x7e5c; game_info->character = (char *) 1060; game_info->size = 0x13ef4; strcat(game_info->file_name, "mhp2.bin"); } else if (strcmp("MonsterHunterPortable2ndG", game_info->game_name) == 0) { module_gp -= 0x7648; game_info->character = (char *) 1184; game_info->size = 0x6a938; strcat(game_info->file_name, "mhp2g.bin"); } else if (strcmp("MonsterHunterPortable3rd", game_info->game_name) == 0) { module_gp += 0x88fc0; game_info->character = (char *) 2140; game_info->size = 0x5f378; strcat(game_info->file_name, "mhp3.bin"); } else { return 0; } // wait for the global pointer to be filled while (*((unsigned int *) module_gp) == 0) sceKernelDelayThread(1000000); // set the character pointer game_info->character += *((unsigned int *) module_gp); // check if a save file already exists SceIoStat stat; if (sceIoGetstat(game_info->file_name, &stat) < 0) game_info->file_exists = 0; else game_info->file_exists = 1; return 1; }
static int get_iso_file_size(const char *path, u32 *file_size) { int ret; SceIoStat stat; ret = sceIoGetstat(path, &stat); if (ret < 0) return ret; *file_size = stat.st_size; return 0; }
int is_game_folder(const char *base, const char *path) { SceIoStat stat; char buffer[256]; for(u32 i = 0; i < ITEMSOF(eboot_types); i++) { sce_paf_private_memset(&stat, 0 , sizeof(SceIoStat)); sce_paf_private_snprintf(buffer, 256, "%s/%s/%s", base, path, eboot_types[i]); if(sceIoGetstat(buffer, &stat) >= 0) { return 1; } } return 0; }
int compare_file_buffer(const char *path, void *file_buf, int size) { SceUID fd = -1; int ret; SceIoStat srcstat; ret = sceIoGetstat(path, &srcstat); if (ret != 0) { goto not_equal; } if (srcstat.st_size != size) { goto not_equal; } ret = sceIoOpen(path, PSP_O_RDONLY, 0777); if (ret < 0) { goto not_equal; } fd = ret; ret = sizeof(g_buf); ret = sceIoRead(fd, g_buf, ret); while (ret > 0) { if (memcmp(g_buf, file_buf, ret)) { goto not_equal; } file_buf += ret; ret = sceIoRead(fd, g_buf, ret); } if (ret < 0) { goto not_equal; } sceIoClose(fd); return 0; not_equal: if (fd >= 0) sceIoClose(fd); return 1; }
// Screen shot保存 boolean PSPEMU_SaveScreenShot(void) { char szFullPath[MAX_PATH]; uint32 nCount = 0; SceIoStat stat; // 保存するファイル名のパスを作る sceIoMkdir("ms0:/PSP/PHOTO" ,0777); sceIoMkdir("ms0:/PSP/PHOTO/NesterJ" ,0777); do { sprintf(szFullPath, "ms0:/PSP/PHOTO/NesterJ/%s%04d.png", NES_ROM_GetRomName(), nCount); nCount++; } while (sceIoGetstat(szFullPath, &stat) >= 0); // szFullPathに保存する return CreateScreenShotFile(szFullPath); }
static void cmd_SIZE_func(ClientInfo *client) { SceIoStat stat; char path[PATH_MAX]; char cmd[64]; /* Get the filename to retrieve its size */ gen_filepath(client, path); /* Check if the file exists */ if (sceIoGetstat(path, &stat) < 0) { client_send_ctrl_msg(client, "550 The file doesn't exist.\n"); return; } /* Send the size of the file */ sprintf(cmd, "213: %lld\n", stat.st_size); client_send_ctrl_msg(client, cmd); }
static SceUID open_file(const char *file) { int ret = -1; SceIoStat stat; char path[256]; strcpy(path, filepath); strrchr(path, '/')[1] = 0; strcat(path, file); kprintf("trying to open %s\n", path); memset(&stat, 0, sizeof(stat)); if(sceIoGetstat(path, &stat) >= 0) { ret = sceIoOpen(path, PSP_O_RDONLY, 0777); kprintf("got fd: %08X\n", ret); } else { kprintf("File not found\n"); } return ret; }
SDL_bool dr_load_driver_dir(char *dirname) { DIR *pdir; struct stat buf; struct SceIoDirent *pfile; if (!(pdir=_opendir (dirname))) { printf("Couldn't find %s\n",dirname); return SDL_FALSE; } while(pfile=_readdir(pdir)) { char *filename=alloca(strlen(pfile->d_name)+strlen(dirname)+2); sprintf(filename,"%s/%s",dirname,pfile->d_name); sceIoGetstat(filename,&buf); if (S_ISREG(buf.st_mode)) { dr_load_driver(filename); } } _closedir(pdir); return SDL_TRUE; }
extern bool utils_del_file(const char *file) { int result; SceIoStat stat; memset(&stat, 0, sizeof(SceIoStat)); result = sceIoGetstat(file, &stat); if (result < 0) return false; stat.st_attr &= ~0x0F; result = sceIoChstat(file, &stat, 3); if (result < 0) return false; result = sceIoRemove(file); if (result < 0) return false; return true; }
int fileListGetMountPointEntries(FileList *list) { int i; for (i = 0; i < N_MOUNT_POINTS; i++) { if (mount_points[i]) { FileListEntry *entry = malloc(sizeof(FileListEntry)); strcpy(entry->name, mount_points[i]); entry->is_folder = 1; entry->type = FILE_TYPE_UNKNOWN; SceIoStat stat; memset(&stat, 0, sizeof(SceIoStat)); sceIoGetstat(entry->name, &stat); memcpy(&entry->time, (SceRtcTime *)&stat.st_mtime, sizeof(SceRtcTime)); fileListAddEntry(list, entry, SORT_BY_NAME_AND_FOLDER); } } return 0; }
int DeleteRecursive(const char * p_path, const char * p_extension) { SceUID fh; IO::Filename file; fh = sceIoDopen(p_path); if( fh ) { while(sceIoDread( fh, &gDirEntry.Dirent )) { SceIoStat stat; IO::Path::Combine(file, p_path, gDirEntry.Dirent.d_name); sceIoGetstat( file, &stat ); if( (stat.st_mode & 0x1000) == 0x1000 ) { if(strcmp(gDirEntry.Dirent.d_name, ".") && strcmp(gDirEntry.Dirent.d_name, "..")) { //printf("Found directory\n"); } } else { if (_strcmpi(FindExtension( file ), p_extension) == 0) { //DBGConsole_Msg(0, "Deleting [C%s]",file); sceIoRemove( file ); } } } sceIoDclose( fh ); } else { //DBGConsole_Msg(0, "Couldn't open the directory"); } return 0; }
int module_start(SceSize args, void* argp) { char keypath[128]; int ret; SceIoStat stat; psp_fw_version = sceKernelDevkitVersion(); setup_patch_offset_table(psp_fw_version); psp_model = sceKernelGetModel(); memset(&conf, 0, sizeof(conf)); sctrlSEGetConfig(&conf); printk_init("ms0:/popcorn.txt"); printk("Popcorn: init_file = %s psp_fw_version = 0x%08X psp_model = %d\n", sceKernelInitFileName(), (uint)psp_fw_version, (int)psp_model); get_keypath(keypath, sizeof(keypath)); ret = sceIoGetstat(keypath, &stat); g_keys_bin_found = 0; if(ret == 0) { ret = load_key(keypath, g_keys, sizeof(g_keys)); if(ret == 0) { g_keys_bin_found = 1; printk("keys.bin found\n"); } } g_is_custom_ps1 = is_custom_ps1(); g_icon0_status = get_icon0_status(); if(g_is_custom_ps1) { setup_psx_fw_version(psp_fw_version); } g_previous = sctrlHENSetStartModuleHandler(&popcorn_patch_chain); patch_scePops_Manager(); sync_cache(); return 0; }