int read_cobra_config(void) { int fd; if (cellFsOpen(COBRA_CONFIG_FILE, CELL_FS_O_RDONLY, &fd, 0, NULL, 0) == 0) { uint64_t r; cellFsRead(fd, &config, sizeof(config), &r); cellFsClose(fd); } if (config.size > 4096 || checksum(&config) != config.checksum) { memset(&config, 0, sizeof(config)); } else { check_and_correct(&config); } config.size = sizeof(config); bd_video_region = config.bd_video_region; dvd_video_region = config.dvd_video_region; // Removed. Now condition_ps2softemu has another meaning and it is set automatically in storage_ext if no BC console //condition_ps2softemu = config.ps2softemu; //DPRINTF("Configuration read. bd_video_region=%d,dvd_video_region=%d\nspoof_version = %04X, spoof_revision = %d\n", bd_video_region, dvd_video_region, config.spoof_version, config.spoof_revision); return 0; }
int filestream_close(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; }
int disable_cobra_stage() { cellFsUtilMount_h("CELL_FS_IOS:BUILTIN_FLSH1", "CELL_FS_FAT", "/dev_habib", 0, 0, 0, 0, 0); CellFsStat stat; cellFsStat(CB_LOCATION, &stat); uint64_t len=stat.st_size; uint8_t *buf; uint64_t size; int src; int dst; page_allocate_auto(NULL, 0x40000, 0x2F, (void **)&buf); if (cellFsOpen(CB_LOCATION, CELL_FS_O_RDONLY, &src, 0, NULL, 0) == 0) { cellFsRead(src, buf, len, &size); cellFsClose(src); } else { page_free(NULL, buf, 0x2F); return -1; } if (cellFsOpen(CB_LOCATION".bak", CELL_FS_O_WRONLY | CELL_FS_O_CREAT | CELL_FS_O_TRUNC, &dst, 0666, NULL, 0) == 0) { cellFsWrite(dst, buf, len, &size); cellFsClose(dst); } else { page_free(NULL, buf, 0x2F); return -1; } page_free(NULL, buf, 0x2F); cellFsUnlink(CB_LOCATION); size=0x5343450000000000; cellFsOpen("/dev_hdd0/tmp/loadoptical", CELL_FS_O_WRONLY | CELL_FS_O_CREAT | CELL_FS_O_TRUNC, &dst, 0666, NULL, 0); cellFsWrite(dst, &size, 4, &size); cellFsClose(dst); return 0; }
int cellGifDecClose(u32 mainHandle, u32 subHandle) { CellGifDecSubHandle* subHandle_data; if(!cellGifDec->CheckId(subHandle, subHandle_data)) return CELL_GIFDEC_ERROR_FATAL; cellFsClose(subHandle_data->fd); Emu.GetIdManager().RemoveID(subHandle); return CELL_OK; }
int cellPngDecClose(u32 mainHandle, u32 subHandle) { cellPngDec.Warning("cellPngDecClose(mainHandle=0x%x,subHandle=0x%x)", mainHandle, subHandle); CellPngDecSubHandle* subHandle_data; if(!cellPngDec.CheckId(subHandle, subHandle_data)) return CELL_PNGDEC_ERROR_FATAL; cellFsClose(subHandle_data->fd); Emu.GetIdManager().RemoveID(subHandle); return CELL_OK; }
int cellJpgDecClose(u32 mainHandle, u32 subHandle) { ID sub_handle_id_data; if(!cellJpgDec.CheckId(subHandle, sub_handle_id_data)) return CELL_JPGDEC_ERROR_FATAL; auto subHandle_data = (CellJpgDecSubHandle*)sub_handle_id_data.m_data; cellFsClose(subHandle_data->fd); Emu.GetIdManager().RemoveID(subHandle); return CELL_OK; }
/* * Function: getFileSize() * File: main.c * Project: ArtemisPS3-PRX * Description: Gets the file size of a file * Arguments: * path: path to file * Return: size of file */ int getFileSize(const char * path) { int fd = 0, size = 0; if(cellFsOpen(path, CELL_FS_O_RDONLY, &fd, NULL, 0) == CELL_FS_SUCCEEDED) { u64 pos; cellFsLseek(fd, 0, CELL_FS_SEEK_END, &pos); size = (int)pos; cellFsClose(fd); } return size; }
int write_cobra_config(void) { int fd; uint64_t w; int ret = 0; if (cellFsOpen(COBRA_CONFIG_FILE, CELL_FS_O_WRONLY|CELL_FS_O_CREAT|CELL_FS_O_TRUNC, &fd, 0666, NULL, 0) != 0) { return ENODEV; } if (cellFsWrite(fd, &config, sizeof(config), &w) != 0) ret = ENODEV; cellFsClose(fd); return ret; }
/* * Function: readFile() * File: main.c * Project: ArtemisPS3-PRX * Description: Reads a file * Arguments: * path: path to file to read * buffer: buffer to store the file contents toascii * size: number of bytes to read from the file * Return: Returns 0 if failed, 1 if succeeded */ int readFile(const char * path, char * buffer, int size) { int fd, ret = 0; if(cellFsOpen(path, CELL_FS_O_RDONLY, &fd, NULL, 0) == CELL_FS_SUCCEEDED) { u64 read_e = 0, pos; //, write_e cellFsLseek(fd, 0, CELL_FS_SEEK_SET, &pos); if (cellFsRead(fd, (void *)buffer, size, &read_e)==CELL_FS_SUCCEEDED) { ret = 1; } cellFsClose(fd); } buffer[size] = '\0'; return ret; }
/* * Function: art_process() * File: main.c * Project: ArtemisPS3-PRX * Description: Processes an entire codelist once * Arguments: * forceWrite: whether the user activated Artemis (1) or a constant write (0) * Return: void */ static void art_process(int forceWrite) { int fd = 0; if (attachedPID) { doForceWrite = forceWrite; //Force load userCodes on forceWrite if (forceWrite && userCodes) { reset_heap(); userCodes = NULL; } if (!userCodes) { int fileSize = getFileSize("/dev_hdd0/tmp/art.txt"); userCodes = (char *)mem_alloc(fileSize + 2); memset(userCodes, 0, fileSize + 2); if(cellFsOpen("/dev_hdd0/tmp/art.txt", CELL_FS_O_RDONLY, &fd, NULL, 0) == CELL_FS_SUCCEEDED) { u64 read_e = 0, pos; cellFsLseek(fd, 0, CELL_FS_SEEK_SET, &pos); cellFsRead(fd, (void *)userCodes, fileSize, &read_e); cellFsClose(fd); } userCodes[fileSize] = '\n'; } if (attachedPID != NULL && attachedPID != 0) { ConvertCodes(attachedPID, userCodes); sys_timer_sleep(0.1); } } doForceWrite = 0; }
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); #elif defined(HAVE_BUFFERED_IO) if (stream->fd) fclose(stream->fd); #else if (stream->fd > 0) close(stream->fd); #endif free(stream); return 0; }
int sys_load_mamba(char *mamba_file) { if (mamba_loaded == 1) return ECANCELED; mamba_file = get_secure_user_ptr(mamba_file); CellFsStat stat; int ret = cellFsStat(mamba_file, &stat); if (ret == 0) { int fd; ret = cellFsOpen(mamba_file, CELL_FS_O_RDONLY, &fd, 0, NULL, 0); if (ret == 0) { uint32_t psize = stat.st_size; void *mamba = alloc(psize, 0x27); if (mamba) { uint64_t rs; ret = cellFsRead(fd, mamba, psize, &rs); cellFsClose(fd); if (ret != 0) { dealloc(mamba, 0x27); mamba = NULL; return ret; } mamba_loaded = 1; f_desc_t f; f.toc = (void *)MKA(TOC); int (* func)(void); f.addr = mamba; func = (void *)&f; func(); return 0; } return ENOMEM; } } return ret; }
int main(void) { void *stage2 = NULL; f_desc_t f; int (* func)(void); int ret; #ifdef DEBUG debug_init(); DPRINTF("Stage 1 hello.\n"); #endif f.addr = flash_mount_clone; f.toc = (void *)MKA(TOC); func = (void *)&f; ret = func(); if (ret != 0 && ret != 1) { DPRINTF("Flash mount failed!\n"); } else { CellFsStat stat; DPRINTF("Flash mounted\n"); if (cellFsStat(STAGE2_FILE, &stat) == 0) { int fd; if (cellFsOpen(STAGE2_FILE, CELL_FS_O_RDONLY, &fd, 0, NULL, 0) == 0) { uint32_t psize = stat.st_size; DPRINTF("Payload size = %d\n", psize); stage2 = alloc(psize, 0x27); if (stage2) { uint64_t rs; if (cellFsRead(fd, stage2, psize, &rs) != 0) { DPRINTF("Stage 2 read fail.\n"); dealloc(stage2, 0x27); stage2 = NULL; } } else { DPRINTF("Cannot allocate stage2\n"); } cellFsClose(fd); } } else { DPRINTF("There is no stage 2, booting system.\n"); } } if (stage2) { f.addr = stage2; func = (void *)&f; DPRINTF("Calling stage 2...\n"); func(); } return ret; }
int main(void) { int ret; int k; int fd; char temp[128]; ntfs_md *mounts; ret = cellSysmoduleLoadModule(CELL_SYSMODULE_FS); if (ret != CELL_OK) return ret; ret = cellFsOpen("/dev_hdd0/libntfs_sample_log.txt", CELL_FS_O_RDWR|CELL_FS_O_CREAT, &LOG, NULL, 0); if(ret) return ret; log_printf("*** LOG ***\n"); log_printf("\n*** PS3_NTFS_IsInserted ***\n\n"); for(k = 0; k < 8; k++) { if(PS3_NTFS_IsInserted(k)) log_printf("- PS3_NTFS_IsInserted(%d) = true\n", k); else log_printf("- PS3_NTFS_IsInserted(%d) = false\n", k); } log_printf("\n*** ntfsFindPartitions ***\n"); sec_t *partitions = NULL; int partition_number = ntfsFindPartitions(disc_ntfs[0], &partitions); log_printf("- ntfsFindPartitions = %d\n", partition_number); log_printf("\n*** ntfsMount ***\n"); if(ntfsMount("ntfs0", disc_ntfs[0], partitions[0], CACHE_DEFAULT_PAGE_COUNT, CACHE_DEFAULT_PAGE_SIZE, NTFS_DEFAULT | NTFS_RECOVER)) log_printf("- ntfsMount = true\n"); else log_printf("- ntfsMount = false\n"); if(partitions) free(partitions); log_printf("\n*** ntfsUnmount ***\n"); ntfsUnmount("ntfs0", 1); log_printf("\n*** ntfsMountDevice ***\n"); ret = ntfsMountDevice(disc_ntfs[0], &mounts, NTFS_DEFAULT | NTFS_RECOVER); log_printf("- ntfsMountDevice = %d\n", ret); log_printf("- mount->name = %s\n", mounts->name); log_printf("\n*** ntfsUnmount ***\n"); ntfsUnmount(mounts->name, 1); log_printf("\n*** ntfsMountAll ***\n"); int mountCount = ntfsMountAll(&mounts, NTFS_DEFAULT | NTFS_RECOVER ); log_printf("- ntfsMountAll = %d\n", mountCount); log_printf("- mount[0].name = %s\n", mounts[0].name); log_printf("\n*** ntfsGetVolumeName ***\n"); const char *OldName = ntfsGetVolumeName(mounts[0].name); if(OldName) log_printf("- Old name : '%s'\n", OldName); else log_printf("- Error %d\n", ps3ntfs_errno()); /* need to re-mount the device after SetVolumeName to 'update' the value of GetVolumeName log_printf("\n*** ntfsSetVolumeName ***\n"); if(ntfsSetVolumeName(mounts[0].name, "NTFS_VOLUME")) log_printf("- ntfsSetVolumeName = true\n"); else log_printf("- ntfsSetVolumeName = false - %d \n", ps3ntfs_errno()); const char *NewName = ntfsGetVolumeName(mounts[0].name); if(NewName) log_printf("- New name : '%s'\n", NewName); else log_printf("- Error %d\n", ps3ntfs_errno()); */ log_printf("\n*** ps3ntfs_mkdir ***\n"); sprintf(temp, "%s:/viper6", mounts[0].name); if(ps3ntfs_mkdir(temp, 0777) == 0) log_printf("- ps3ntfs_mkdir = true\n"); else log_printf("- ps3ntfs_mkdir = false\n"); log_printf("\n*** ps3ntfs_open ***\n"); strcat(temp, (char*) "/ntfs.txt"); for(k=0; k<5000; k++) { // force fd = ps3ntfs_open(temp, O_CREAT | O_WRONLY | O_TRUNC, 0777); if(fd>0) break; } if(fd > 0) { log_printf("- ps3ntfs_open = success\n"); log_printf("\n*** ps3ntfs_write ***\n"); ret = ps3ntfs_write(fd, message, strlen(message)); log_printf("- ps3ntfs_write = %d\n", ret); if(ret != (int) strlen(message)) log_printf("- Error writing the file!\n"); log_printf("\n*** ps3ntfs_close ***\n"); ret = ps3ntfs_close(fd); log_printf("- ps3ntfs_close = %d\n", ret); } else log_printf("- ps3ntfs_open = failed - %s\n", temp); struct stat st; log_printf("\n*** ps3ntfs_stat ***\n"); ret = ps3ntfs_stat(temp, &st); log_printf("- ps3ntfs_stat = %d\n", ret); log_printf("- SIZE = %d\n", st.st_size); log_printf("- last_access_time = %d\n", st.st_atime); log_printf("- last_mft_change_time = %d\n", st.st_ctime); log_printf("- last_data_change_time = %d\n", st.st_mtime); log_printf("- st_dev (id) = %d\n", st.st_dev); log_printf("- st uid = %d\n", st.st_uid); log_printf("- st gid = %d\n", st.st_gid); log_printf("- st ino = %d\n", st.st_ino); log_printf("\n*** ps3ntfs_open ***\n"); for(k=0; k<5000; k++) { // force fd = ps3ntfs_open(temp, O_RDONLY, 0); if(fd > 0) break; } log_printf("- ps3ntfs_open = %d\n", fd); if(fd > 0) { log_printf("- ps3ntfs_open = success\n"); log_printf("\n*** ps3ntfs_fstat ***\n"); ret = ps3ntfs_fstat(fd, &st); log_printf("- ps3ntfs_fstat = %d\n", ret); log_printf("- SIZE = %d\n", st.st_size); log_printf("- last_access_time = %d\n", st.st_atime); log_printf("- last_mft_change_time = %d\n", st.st_ctime); log_printf("- last_data_change_time = %d\n", st.st_mtime); log_printf("- st_dev (id) = %d\n", st.st_dev); log_printf("- st uid = %d\n", st.st_uid); log_printf("- st gid = %d\n", st.st_gid); log_printf("- st ino = %d\n", st.st_ino); log_printf("\n*** ps3ntfs_seek ***\n"); int size = ps3ntfs_seek(fd, 0, SEEK_END); log_printf("- ps3ntfs_seek - size = %d\n", size); ps3ntfs_seek(fd, 0, SEEK_SET); log_printf("\n*** ps3ntfs_read ***\n"); ret = ps3ntfs_read(fd, buffer, size); log_printf("- ps3ntfs_read : '%s'\n", buffer); if(ret != size) log_printf("Error reading the file!\n"); log_printf("\n*** ps3ntfs_close ***\n"); ret = ps3ntfs_close(fd); log_printf("- ps3ntfs_close = %d\n", ret); } else log_printf("- ps3ntfs_open = failed - %s\n", temp); sprintf(buffer, "%s:/viper6/ntfs_newname.txt", mounts[0].name); log_printf("\n*** ps3ntfs_rename ***\n"); for(k=0; k<5000; k++) { // force ret = ps3ntfs_rename(temp, buffer); if(ret==0) break; } if(ret==0) log_printf("- ps3ntfs_rename = %d\n", ret); else log_printf("- ps3ntfs_rename = %d - %s > %s\n", ret, temp, buffer); DIR_ITER *pdir; char filename[255]; log_printf("\n*** ps3ntfs_diropen ***\n"); sprintf(temp, "%s:/viper6", mounts[0].name); for(k=0; k<5000; k++) { // force pdir = ps3ntfs_diropen(temp); if (pdir) break; } if (pdir) { log_printf("- ps3ntfs_diropen = success\n"); log_printf("\n*** ps3ntfs_dirnext ***\n"); while (ps3ntfs_dirnext(pdir, filename, &st) == 0) { if ((strcmp(filename, ".") == 0) || (strcmp(filename, "..") == 0)) continue; log_printf("- ps3ntfs_dirnext = File : %s/\n", filename); log_printf("- last_access_time = %d\n", st.st_atime); log_printf("- last_mft_change_time = %d\n", st.st_ctime); log_printf("- last_data_change_time = %d\n", st.st_mtime); } log_printf("\n*** ps3ntfs_dirreset ***\n"); ret = ps3ntfs_dirreset(pdir); log_printf("- ps3ntfs_dirreset = %d\n", ret); log_printf("\n*** ps3ntfs_dirclose ***\n"); ret = ps3ntfs_dirclose(pdir); log_printf("- ps3ntfs_dirclose = %d\n", ret); } else log_printf("- ps3ntfs_diropen = failed\n"); log_printf("\n*** ps3ntfs_open ***\n"); strcat(temp, (char*)"/unlink.txt"); for(k=0; k<5000; k++) { // force fd = ps3ntfs_open(temp, O_CREAT | O_WRONLY | O_TRUNC, 0777); if(fd > 0) break; } if(fd > 0) { log_printf("- ps3ntfs_open = success\n"); log_printf("\n*** ps3ntfs_close ***\n"); ret = ps3ntfs_close(fd); log_printf("- ps3ntfs_close = %d\n", ret); } else log_printf("- ps3ntfs_open = failed\n"); log_printf("\n*** ps3ntfs_unlink ***\n"); for(k=0; k<5000; k++) { // force ret = ps3ntfs_unlink(temp); if(ret==0) break; } log_printf("- ps3ntfs_unlink = %d\n", ret); log_printf("\n*** ntfsUnmount ***\n"); for (k = 0; k < mountCount; k++) ntfsUnmount(mounts[k].name, 1); log_printf("\n*** PS3_NTFS_Shutdown ***\n\n"); for(k = 0; k < 8; k++) { if(PS3_NTFS_Shutdown(k)) log_printf("- PS3_NTFS_Shutdown(%d) = true\n", k); else log_printf("- PS3_NTFS_Shutdown(%d) = false\n", k); } /* // Debugging for time related functions in ntfstime.h struct timespec { time_t tv_sec; long tv_nsec; } ; struct timespec now; typedef uint64_t u64; typedef u64 sle64; typedef sle64 ntfs_time; //sys_time_sec_t time_s; //sys_time_nsec_t time_n_s; //sys_time_get_current_time(&time_s, &time_n_s); //now.tv_sec = time_s; //now.tv_nsec = time_n_s; now.tv_sec = time((time_t*)NULL); now.tv_nsec = 0; log_printf("- test now.tv_sec = %d\n", now.tv_sec); log_printf("- test now.tv_nsec = %d\n", now.tv_nsec); ntfs_time ntfstime; struct timespec unixtime; #define NTFS_TIME_OFFSET ((s64)(369 * 365 + 89) * 24 * 3600 * 10000000) s64 units; units = (s64)now.tv_sec * 10000000 + NTFS_TIME_OFFSET + now.tv_nsec/100; ntfstime = (cpu_to_sle64(units)); log_printf("- timespec2ntfs = %d\n", ntfstime); struct timespec spec; s64 cputime; cputime = sle64_to_cpu(ntfstime); spec.tv_sec = (cputime - (NTFS_TIME_OFFSET)) / 10000000; spec.tv_nsec = (cputime - (NTFS_TIME_OFFSET) - (s64)spec.tv_sec*10000000)*100; //force zero nsec for overflowing dates if ((spec.tv_nsec < 0) || (spec.tv_nsec > 999999999)) spec.tv_nsec = 0; unixtime = spec; log_printf("- ntfs2timespec = %d\n", unixtime); */ // End debugging /* TODO int ps3ntfs_file_to_sectors(const char *path, uint32_t *sec_out, uint32_t *size_out, int max, int phys); int ps3ntfs_get_fd_from_FILE(FILE *fp); s64 ps3ntfs_seek64(int fd, s64 pos, int dir); int ps3ntfs_link(const char *existing, const char *newLink); int ps3ntfs_statvfs(const char *path, struct statvfs *buf); int ps3ntfs_ftruncate(int fd, off_t len); int ps3ntfs_fsync(int fd); void NTFS_init_system_io(void); void NTFS_deinit_system_io(void); Standard functions supported: open_r -> for stdio.h fopen()... close_r -> for stdio.h fclose()... read_r -> for stdio.h fread()... write_r -> for stdio.h fwrite()... lseek_r -> for stdio.h fseek()... lseek64_r -> for using with large files (see ps3_example_stdio for this) fstat_r -> for stat.h fstat() stat_r -> for stat.h stat() ftruncate_r -> for unistd.h ftruncate() truncate_r -> for unistd.h truncate() fsync_r -> for stdio.h fflush() link_r -> for unistd.h link() unlink_r -> for unistd.h unlink() rename_r -> for stdio.h rename() mkdir_r -> for stat.h mkdir() rmdir_r -> for unistd.h rmdir() */ cellFsClose(LOG); return 0; }