int parseDiff( const char * file, tSceModule * mod ) { int off = inCtf( file ); if ( off < 0 ) { log( "there's no patch for %s\n", file ); return 0; } int ctf = sceIoOpen( cxmb_theme_file, PSP_O_RDONLY, 0644 ); if ( ctf < 0 ) { log( "no ctf file found!\n" ); return -1; } sceIoLseek( ctf, ctf_header[off].start, PSP_SEEK_SET ); log( "patch %s!\nstart: %08x\nsize: %08x\n", file, ctf_header[off].start, ctf_header[off].size ); unsigned int attr[2]; int i = 0; while( i < ctf_header[off].size ) { sceIoRead( ctf, attr, 8 ); sceIoRead( ctf, ( void * )( mod->text_addr + attr[0] ), attr[1] ); i ++; } sceIoClose( ctf ); sceKernelIcacheInvalidateAll(); sceKernelDcacheWritebackInvalidateAll(); log( "%s patched!\n", file ); return 0; }
int IoClose_new( PspIoDrvFileArg * arg ) { PspIoDrvArg * drv = arg->drv; int num = isRedirected( arg ); if( num >= 0 && arg->fs_num == 0 ) { arg->drv = ms_drv; handler_count --; memcpy( &ctf_handler[num], &ctf_handler[num + 1], sizeof( CtfHandler ) * ( handler_count - num ) ); int ret = fatms_drv->funcs->IoClose( arg ); arg->drv = drv; return ret; } if ( arg->arg == t_record ) { log( "write finished!\n" ); int fd = sceIoOpen( CXMB_CONF_FILE, PSP_O_RDWR | PSP_O_CREAT | PSP_O_TRUNC, 0777 ); if ( fd < 0 ) { log( "failed in openning %s\n", CXMB_CONF_FILE ); } else { sceIoWrite( fd, selected_theme_file, strlen( selected_theme_file ) + 1 ); sceIoClose( fd ); } IoClose( arg ); sceKernelSignalSema( sema, 1 ); } arg->drv = drv; int ret = IoClose(arg); return ret; }
int retro_fclose(RFILE *stream) { if (!stream) return -1; #if defined(VITA) || defined(PSP) if (stream->fd > 0) sceIoClose(stream->fd); #elif defined(__CELLOS_LV2__) if (stream->fd > 0) cellFsClose(stream->fd); #else #if defined(HAVE_BUFFERED_IO) if ((stream->hints & RFILE_HINT_UNBUFFERED) == 0) { if (stream->fp) fclose(stream->fp); } else #endif #ifdef HAVE_MMAP if (stream->hints & RFILE_HINT_MMAP) munmap(stream->mapped, stream->mapsize); #endif if (stream->fd > 0) close(stream->fd); #endif free(stream); return 0; }
/* ** ** [func] - fclose. ** [desc] - if stream is a valid FILE stream and able to close the stream file ** then returns 0. else returns EOF. ** [entr] - FILE *stream; the pointer to the FILE stream. ** [exit] - int; 0 if able to close the stream file. else EOF. ** [prec] - stream is a valid FILE pointer. ** [post] - the stream file is closed. ** */ int fclose(FILE *stream) { int ret; /* test the file stream type. */ switch(LOCAL_FILE(stream)->type) { case STD_IOBUF_TYPE_NONE: case STD_IOBUF_TYPE_GE: case STD_IOBUF_TYPE_STDOUTHOST: /* cannot close stdin, stdout, or stderr. */ // duh.. this is wrong. One SHOULD be able to close // std*. That's a common unix doing. However, I doubt // allowing this madness could be a good idea. ret = EOF; break; default: if ((LOCAL_FILE(stream)->fd >= 0) && (sceIoClose(LOCAL_FILE(stream)->fd) >= 0)) { LOCAL_FILE(stream)->type = STD_IOBUF_TYPE_NONE; LOCAL_FILE(stream)->fd = -1; LOCAL_FILE(stream)->cnt = 0; LOCAL_FILE(stream)->flag = 0; ret = 0; } else ret = EOF; } return (ret); }
static void pspgl_ge_writefile (void *buf, unsigned long len) { int fd = sceIoOpen(PSPGL_GE_DUMPFILE, PSP_O_CREAT | PSP_O_APPEND | PSP_O_WRONLY, 0644); sceIoWrite(fd, buf, len); sceIoClose(fd); }
frame_t *frame_factory_from_cfg_file(const char *cfg_file) { SceUID fd = -1; frame_cfg_t *cfg = NULL; frame_t *ret = NULL; fd = sceIoOpen(cfg_file, PSP_O_RDONLY, 0777); if (fd < 0) { printf("can't open cfg file!\n"); goto cleanup; } cfg = frame_factory_read_cfg(fd); if (cfg == NULL) { printf("read cfg failed!\n"); goto cleanup; } ret = frame_factory_from_cfg(cfg); cleanup: if (fd >= 0) { sceIoClose(fd); } if (cfg != NULL) { free(cfg); } return ret; }
static void receive_file(ClientInfo *client, const char *path) { unsigned char *buffer; SceUID fd; unsigned int bytes_recv; DEBUG("Opening: %s\n", path); if ((fd = sceIoOpen(path, PSP2_O_CREAT | PSP2_O_WRONLY | PSP2_O_TRUNC, 0777)) >= 0) { buffer = malloc(FILE_BUF_SIZE); if (buffer == NULL) { client_send_ctrl_msg(client, "550 Could not allocate memory.\n"); return; } client_open_data_connection(client); client_send_ctrl_msg(client, "150 Opening Image mode data transfer.\n"); while ((bytes_recv = client_send_recv_raw(client, buffer, FILE_BUF_SIZE)) > 0) { sceIoWrite(fd, buffer, bytes_recv); } sceIoClose(fd); free(buffer); client_send_ctrl_msg(client, "226 Transfer completed.\n"); client_close_data_connection(client); } else { client_send_ctrl_msg(client, "550 File not found.\n"); } }
int load_quest_index() { mib_table = NULL; mib_elems = 0; k1 = pspSdkSetK1(0); model_go = sceKernelGetModel() == 4 ? 1 : 0; strcpy(filename, "xxx:/mhp3rd/quest/mib_id.dat"); SET_DEVICENAME(filename, model_go); kprintf("trying to open %s\n", filename); SceUID fd = sceIoOpen(filename, PSP_O_RDONLY, 0777); if(fd < 0) { kprintf("Cannot find mib_id.dat\n"); pspSdkSetK1(k1); return fd; } SceSize size = (SceSize)sceIoLseek(fd, 0, PSP_SEEK_END); sceIoLseek(fd, 0, PSP_SEEK_SET); index_id = sceKernelAllocPartitionMemory(PSP_MEMORY_PARTITION_KERNEL, "mhp3mib", PSP_SMEM_High, size, NULL); if(index_id >= 0) { mib_table = sceKernelGetBlockHeadAddr(index_id); sceIoRead(fd, mib_table, size); mib_elems = size / (sizeof(u32) * 2); quest_number = mib_table + mib_elems; kprintf("index size: %i bytes, entries: %i\n", size, index_elems); } else { kprintf("failed to allocate memory for table\n"); } sceIoClose(fd); pspSdkSetK1(k1); return 0; }
int diva_poll(SceUID fd, SceInt64 *res) { int ret; u32 k1; if(wait_fd >= 0 && fd == datafd) { kprintf("polling for fd: %08X\n", wait_fd); k1 = pspSdkSetK1(0); ret = sceIoPollAsync(wait_fd, res); if(ret <= 0) { if(ret == 0) { kprintf("Async read completed: %i bytes\n", (u32)*res); *res = wait_size; } else { kprintf("polling error: %08X\n", ret); } sceIoClose(wait_fd); wait_fd = -1; } else { kprintf("poll result: %08X\n", ret); } pspSdkSetK1(k1); return ret; } return sceIoPollAsync(fd, res); }
static int is_encrypted(const char *path) { SceUID fd = -1; u32 magic; u32 result = 0; fd = sceIoOpen(path, PSP_O_RDONLY, 0); if (fd < 0) { goto exit; } if (sizeof(magic) != sceIoRead(fd, &magic, sizeof(magic))) { goto exit; } if (CRYPT_MAGIC == magic) { result = 1; } exit: if (fd >= 0) { sceIoClose(fd); fd = -1; } return result; }
bool save_passwords(void) { password *pwd; SceUID fd; char path[PATH_MAX]; u32 magic; STRCPY_S(path, scene_appdir()); STRCAT_S(path, "password.lst"); rc4_prepare_key((u8 *) CRYPT_KEY, sizeof(CRYPT_KEY) - 1, &g_key); fd = sceIoOpen(path, PSP_O_WRONLY | PSP_O_CREAT | PSP_O_TRUNC, 0777); if (fd < 0) { return false; } magic = CRYPT_MAGIC; sceIoWrite(fd, &magic, sizeof(magic)); for (pwd = g_pwd_head.next; pwd != NULL; pwd = pwd->next) { write_chars(fd, pwd->b->ptr, strlen(pwd->b->ptr)); write_chars(fd, "\r\n", sizeof("\r\n") - 1); } sceIoClose(fd); return true; }
int locate_umd_img1(const char *umdfile, size_t file_offset, SceUID * pfd) { int ret = -1; char buf[9] = { 0 }; size_t stread = 0; if (!umdfile || !pfd || file_offset < 0) return -1; *pfd = -1; do { struct UMDHeaderDataEx *pEx; if ((*pfd = sceIoOpen(umdfile, PSP_O_RDONLY, 0777)) < 0) { return -2; } if (0 < sceIoLseek(*pfd, file_offset, SEEK_SET)) return -3; if ((stread = sceIoRead(*pfd, buf, 9)) < 0) { dbg_printf(d, "%s read umd file head chunk error!", __func__); break; } pEx = (struct UMDHeaderDataEx *) &buf; if (!pEx || pEx->Mark != '$' || pEx->Length < 9) break; return pEx->Length - 9; } while (false); if (*pfd) { sceIoClose(*pfd); *pfd = -1; } return ret; }
static int MP3SleepCheck(void) { if (Sleep) { if (mp3_fd >= 0) sceIoClose(mp3_fd); mp3_sleep = 1; do { sceKernelDelayThread(5000000); } while (Sleep); mp3_sleep = 0; if ((mp3_fd = sceIoOpen(MP3_file, PSP_O_RDONLY, 0777)) < 0) { mp3_fd = -1; mp3_status = MP3_STOP; ui_popup(TEXT(COULD_NOT_REOPEN_MP3_FILEx), strrchr(MP3_file, '/') + 1); return 1; } sceIoLseek(mp3_fd, mp3_filepos, PSP_SEEK_SET); } else if (mp3_status == MP3_STOP) { return 1; } return 0; }
int makeTestFile(const char *name) { SceUID fd = sceIoOpen(name, PSP_O_WRONLY | PSP_O_CREAT, 0777); if (fd < 0) { return fd; } return sceIoClose(fd); }
int filestream_close(RFILE *stream) { if (!stream) goto error; if (stream->ext) free(stream->ext); #if defined(PSP) if (stream->fd > 0) sceIoClose(stream->fd); #else #if defined(HAVE_BUFFERED_IO) if ((stream->hints & RFILE_HINT_UNBUFFERED) == 0) { if (stream->fp) fclose(stream->fp); } else #endif #ifdef HAVE_MMAP if (stream->hints & RFILE_HINT_MMAP) munmap(stream->mapped, stream->mapsize); #endif if (stream->fd > 0) close(stream->fd); #endif free(stream); return 0; error: return -1; }
pgeObj *pgeObjLoad(const char *filename) { int fd = sceIoOpen(filename, PSP_O_RDONLY, 0777); if(fd < 0) return NULL; long filesize; filesize = sceIoLseek32(fd, 0, PSP_SEEK_END); sceIoLseek32(fd, 0, PSP_SEEK_SET); unsigned char *data = pgeMalloc(filesize); if(!data) return NULL; sceIoRead(fd, data, filesize); sceIoClose(fd); pgeObj *obj = pgeObjLoadInternal(data, filesize); if(data) pgeFree(data); return obj; }
/********************************************//** * \brief Loads file to memory * * \returns Zero on success, otherwise error ***********************************************/ int uvl_load_file (const char *filename, ///< File to load void **data, ///< Output pointer to data PsvSSize *size) ///< Output pointer to data size { PsvUID fd; PsvUID memblock; char *base; PsvOff filesz; PsvOff nread; PsvSSize nbytes; fd = sceIoOpen (filename, PSP2_O_RDONLY, 0); if (fd < 0) { LOG ("Failed to open %s for reading.", filename); return -1; } filesz = sceIoLseek (fd, 0LL, PSP2_SEEK_END); if (filesz < 0) { LOG ("Failed to find file size: 0x%X", filesz); return -1; } sceIoLseek (fd, 0LL, PSP2_SEEK_SET); memblock = sceKernelAllocMemBlock ("UVLTemp", 0xC20D060, (filesz + 0xFFF) & ~0xFFF, NULL); if (memblock < 0) { LOG ("Failed allocate %u bytes of memory.", memblock); return -1; } if (sceKernelGetMemBlockBase (memblock, &base) < 0) { LOG ("Failed to locate base for block 0x%08X.", memblock); return -1; } base = (char *)(((u32_t)base + 0xFFF) & ~0xFFF); // align memory base nbytes = 0; while ((nread = sceIoRead (fd, base+nbytes, filesz)) < filesz-nbytes) { nbytes += nread; } if (nbytes < 0) { LOG ("Failed to read %s: 0x%08X", filename, nbytes); return -1; } IF_DEBUG LOG ("Read %u bytes from %s", nbytes, filename); if (sceIoClose (fd) < 0) { LOG ("Failed to close file."); return -1; } *data = base; *size = nbytes; return 0; }
void __pspgl_vram_dump (void) { unsigned long vram_start = (unsigned long) sceGeEdramGetAddr(); unsigned long vram_size = (unsigned long) sceGeEdramGetSize() * 4; unsigned long header [4]; unsigned char vram_copy [0x10000]; int fd; int i; fd = sceIoOpen(PSPGL_GE_DUMPFILE, PSP_O_CREAT | PSP_O_APPEND | PSP_O_WRONLY, 0644); if (pspgl_curctx) { struct pspgl_surface *s = pspgl_curctx->draw; struct pspgl_dump_surfaces surf; header[0] = PSPGL_GE_DUMP_SURFACES; header[1] = sizeof(header) + sizeof(surf); header[2] = 0; header[3] = 0; memset(&surf, 0, sizeof(surf)); surf.pixfmt = s->pixfmt; surf.alpha_mask = s->alpha_mask; surf.stencil_mask = s->stencil_mask; surf.front.start = s->color_front->base - sceGeEdramGetAddr(); surf.front.size = s->height * s->pixelperline * (s->pixfmt == GE_RGBA_8888 ? 4 : 2); surf.front.stride = s->pixelperline; surf.back.start = s->color_back->base - sceGeEdramGetAddr(); surf.back.size = s->height * s->pixelperline * (s->pixfmt == GE_RGBA_8888 ? 4 : 2); surf.back.stride = s->pixelperline; if (s->depth_buffer) { surf.depth.start = s->depth_buffer->base - sceGeEdramGetAddr(); surf.depth.size = s->height * s->pixelperline * 2; surf.depth.stride = s->pixelperline; } sceIoWrite(fd, header, sizeof(header)); sceIoWrite(fd, &surf, sizeof(surf)); } header[0] = PSPGL_GE_DUMP_VRAM; header[1] = sizeof(header) + vram_size; header[2] = vram_start; header[3] = vram_size; sceIoWrite(fd, header, sizeof(header)); /* copy in blocks, direct writes from VRAM to file don't seem to work... */ for (i=0; i<vram_size/sizeof(vram_copy); i++, vram_start+=sizeof(vram_copy)) { memcpy(vram_copy, (void *) vram_start, sizeof(vram_copy)); sceIoWrite(fd, (void *) vram_copy, sizeof(vram_copy)); } sceIoClose(fd); }
int fileGetSize(char *filein) { SceUID fd = sceIoOpen(filein, PSP_O_RDONLY, 0777); if (fd < 0) return -1; fsize = sceIoLseek(fd, 0, SEEK_END); sceIoLseek(fd, 0, SEEK_SET); sceIoClose(fd); return fsize; }
void releaseWaveData(WAVDATA* p_wav) // WAVE释放 { if (p_wav->fd==-1) free(p_wav->buffer); else sceIoClose(p_wav->fd); memset(p_wav, 0, sizeof(WAVDATA)); }
void OGG_FreeTune(){ ov_clear(&OGG_VorbisFile); if (OGG_file >= 0) sceIoClose(OGG_file); OGG_file = -1; OGG_tempmixleft = 0; memset(OGG_mixBuffer, 0, sizeof(OGG_mixBuffer)); }
static void debugOut(const char *text) { int fd = sceIoOpen("debug.txt", PSP_O_WRONLY|PSP_O_CREAT|PSP_O_APPEND, 0777); sceIoWrite(fd, text, strlen(text)); sceIoClose(fd); }
int MFFileNative_Close(MFFile* fileHandle) { MFCALLSTACK; sceIoClose((SceUID)fileHandle->pFilesysData); return 0; }
void my_print(const char* str) { int fdLog = sceIoOpen("ms0:/err.txt", PSP_O_WRONLY|PSP_O_APPEND, 0777); if (fdLog > 0) { sceIoWrite(fdLog, (void*)str, strlen(str)); sceIoClose(fdLog); } }
extern void conf_save() { int fd = sceIoOpen(CONFIG_DIR, PSP_O_WRONLY | PSP_O_CREAT | PSP_O_TRUNC, 0777); if(fd >= 0) { sceIoWrite(fd, &config, sizeof(config)); } sceIoClose(fd); }
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //Manage suspend: /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// int MP3ME_suspend(){ MP3ME_suspendPosition = MP3ME_filePos; MP3ME_suspendIsPlaying = MP3ME_isPlaying; MP3ME_isPlaying = 0; sceIoClose(MP3ME_handle); MP3ME_handle = -1; return 0; }
extern void conf_load() { //memset(&config, 0, sizeof(config)); config.skey = PSP_CTRL_NOTE; config.ssskey = PSP_CTRL_VOLDOWN + PSP_CTRL_SELECT; config.bg_color = 0xb0c0c0c0; config.txtrowbytes = 54; config.jpg_quality = 90; config.suspend_skey = PSP_CTRL_RIGHT|PSP_CTRL_LEFT |PSP_ANA_RIGHT|PSP_CTRL_LTRIGGER; config.standby_skey = PSP_CTRL_RIGHT|PSP_CTRL_LEFT |PSP_ANA_RIGHT|PSP_CTRL_LTRIGGER; config.savekey = PSP_CTRL_RIGHT|PSP_CTRL_LEFT |PSP_ANA_RIGHT|PSP_CTRL_LTRIGGER; config.loadkey = PSP_CTRL_RIGHT|PSP_CTRL_LEFT |PSP_ANA_RIGHT|PSP_CTRL_LTRIGGER; //memset(&keyset, 0, sizeof(keyset)); memset(keyset.turbo_key_interval, 2, 12); int i; for(i=0;i<16;i++){ //keyset.keymap_skey[i] = turbo_key_tab[i]; //keyset.keymap_table[i] = turbo_key_tab[i]; keyset.stick_table[i] = turbo_key_tab[i]; keyset.stick_skey[i] = PSP_CTRL_UP|PSP_CTRL_DOWN|PSP_ANA_RIGHT|PSP_ANA_LEFT; } for(i=0;i<12;i++){ keyset.turbo_skey[i] = PSP_CTRL_UP|PSP_CTRL_DOWN|PSP_ANA_RIGHT|PSP_ANA_LEFT; } int j; for(i=0;i<MAX_KEYLIST;i++) { //memset((u8 *)&g_keylist[i], 0, sizeof(t_keylist_table)); g_keylist[i].idx = -1; g_keylist[i].reversekey = PSP_CTRL_RTRIGGER; //g_keylist[i].count = 0; //g_keylist[i].lastkey_stamp = 0; for(j=0;j<MAX_KEYSET;j++) { //g_keylist[i].list[j].btn = 0; //g_keylist[i].list[j].x = 127; //g_keylist[i].list[j].y = 127; g_keylist[i].list[j].stamp = 7; } } int dl = sceIoDopen(TAB_DIR); if(dl < 0) TAB_DIR[16]=0; else sceIoDclose(dl); int fd = sceIoOpen(CONFIG_DIR, PSP_O_RDONLY, 0777); if(fd >= 0) { sceIoRead(fd, &config, sizeof(config)); } sceIoClose(fd); }
HostCoreConf * readConf( HostCoreConf * hc_conf ) { const char * labels[] = { "Quick Key", "IP", "Port", "Password", "Connection", "Block Size", }; const int items_count = 6; char buf[128]; int fd = sceIoOpen( CONF_FILE, PSP_O_RDONLY, 0644 ); memset( hc_conf, 0, sizeof( HostCoreConf ) ); if ( fd >= 0 ) { while( readLine( fd, buf, 128 ) >= 0 ) { stripSpace( buf ); if ( buf[0] == '#' || buf[0] == 0 ) continue; int i; for ( i = 0; i < items_count; i ++ ) { if ( !strncmp( labels[i], buf, strlen( labels[i] ) ) ) { char * start = strchr( buf, '"' ); if ( !start ) continue; char * end = strchr( start + 1, '"' ); if ( !end ) continue; *end = 0; if ( strlen( start + 1 ) < 16 ) strcpy( ( char * )hc_conf + ( 16 * i ), start + 1 ); } } } sceIoClose( fd ); } else { log( "Error opening conf\n" ); } if ( hc_conf->key[0] == 0 ) strcpy( hc_conf->key, "800000" ); if ( hc_conf->ip[0] == 0 ) strcpy( hc_conf->ip, "192.168.0.1" ); if ( hc_conf->port[0] == 0 ) strcpy( hc_conf->port, "7513" ); if ( hc_conf->entry[0] == 0 ) strcpy( hc_conf->entry, "1" ); if ( hc_conf->entry[0] == 0 ) strcpy( hc_conf->blocksize, "2048" ); return hc_conf; }
static int pgeTextureLoadPngFile(const char* filename, pgeTexture* texture) { png_structp png_ptr; int fd; fd = sceIoOpen(filename, PSP_O_RDONLY, 0777); if(fd < 0) { debugOut("7\n"); return 0; } unsigned char sig[4]; sceIoRead(fd, &sig, 4); sceIoLseek(fd, 0, PSP_SEEK_SET); if(png_sig_cmp(sig, 0, 4)) { debugOut("8\n"); return 0; } png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); if(png_ptr == NULL) { debugOut("9\n"); sceIoClose(fd); return 0; } png_set_read_fn(png_ptr, &fd, (png_rw_ptr)pgeTextureReadPngFile); int result = pgeTextureLoadPngInternal(png_ptr, texture); sceIoClose(fd); return result; }
int cefiveconfig_save(CEFiveConfig* prConfig, const char* sFilename) { SceUID fd = -1; int r = 0; if (prConfig == NULL || sFilename == NULL) { return CEFIVECONFIG_NULLPTR; } fd = sceIoOpen(sFilename, PSP_O_WRONLY|PSP_O_CREAT, 0664); if (fd < 0) { return CEFIVECONFIG_IOERROR; } r = cefiveconfig_write(prConfig, fd); if (r != CEFIVECONFIG_SUCCESS) { sceIoClose(fd); return CEFIVECONFIG_FAILURE; } sceIoClose(fd); return CEFIVECONFIG_SUCCESS; }