int Playlog_Delete(void) { s32 res = -1; //Open play_rec.dat s32 fd = IOS_Open(PLAYRECPATH, IPC_OPEN_RW); if(fd < 0) return fd; PlayRec * playrec_buf = memalign(32, ALIGN32(sizeof(PlayRec))); if(!playrec_buf) goto cleanup; //Read play_rec.dat if(IOS_Read(fd, playrec_buf, sizeof(PlayRec)) != sizeof(PlayRec)) goto cleanup; if(IOS_Seek(fd, 0, 0) < 0) goto cleanup; // invalidate checksum playrec_buf->checksum = 0; if(IOS_Write(fd, playrec_buf, sizeof(PlayRec)) != sizeof(PlayRec)) goto cleanup; res = 0; cleanup: free(playrec_buf); IOS_Close(fd); return res; }
int Playlog_Update(const char * ID, const u16 * title) { if(!ID || !title) return -1; //If not started from SystemMenu, create playlog Playlog_Create(); s32 fd = -1, res = -1; u32 sum = 0; u8 i; //Open play_rec.dat fd = IOS_Open(PLAYRECPATH, IPC_OPEN_RW); if(fd == -106) { //In case the play_rec.dat wasn´t found create one and try again int ret = Playlog_Create(); if(ret < 0) return ret; fd = IOS_Open(PLAYRECPATH, IPC_OPEN_RW); } if(fd < 0) return res; PlayRec * playrec_buf = memalign(32, ALIGN32(sizeof(PlayRec))); //! Should be 32 byte aligned if(!playrec_buf) { IOS_Close(fd); return res; } memset(playrec_buf, 0, sizeof(PlayRec)); u64 stime = getWiiTime(); playrec_buf->ticks_boot = stime; playrec_buf->ticks_last = stime; //Update channel name and ID memcpy(playrec_buf->name, title, 84); memcpy(playrec_buf->title_id, ID, 6); //Calculate and update checksum for(i = 0; i < 31; i++) sum += playrec_buf->data[i]; playrec_buf->checksum = sum; //Write play_rec.dat if(IOS_Write(fd, playrec_buf, sizeof(PlayRec)) == sizeof(PlayRec)) res = 0; IOS_Close(fd); free(playrec_buf); return res; }
int Playlog_Delete(void) //Make Wiiflow not show in playlog { //Open play_rec.dat s32 playrec_fd = IOS_Open(PLAYRECPATH, IPC_OPEN_RW); if(playrec_fd < 0) goto error_2; //Read play_rec.dat if(IOS_Read(playrec_fd, &playrec_buf, sizeof(playrec_buf)) != sizeof(playrec_buf)) goto error_1; if(IOS_Seek(playrec_fd, 0, 0) < 0) goto error_1; // invalidate checksum playrec_buf.checksum=0; if(IOS_Write(playrec_fd, &playrec_buf, sizeof(playrec_buf)) != sizeof(playrec_buf)) goto error_1; IOS_Close(playrec_fd); return 0; error_1: IOS_Close(playrec_fd); error_2: return -1; }
int Playlog_Update(const char ID[6], const u8 title[84]) { gprintf("Update Play log\n"); u32 sum = 0; u8 i; //Open play_rec.dat s32 playrec_fd = IOS_Open(PLAYRECPATH, IPC_OPEN_RW); if(playrec_fd == -106) { gprintf("IOS_Open error ret: %i\n",playrec_fd); IOS_Close(playrec_fd); //In case the play_rec.dat wasn´t found create one and try again if(ISFS_CreateFile(PLAYRECPATH,0,3,3,3) < 0 ) goto error_2; playrec_fd = IOS_Open(PLAYRECPATH, IPC_OPEN_RW); if(playrec_fd < 0) goto error_2; } else if(playrec_fd < 0) goto error_2; u64 stime = getWiiTime(); playrec_buf.ticks_boot = stime; playrec_buf.ticks_last = stime; //Update channel name and ID memcpy(playrec_buf.name, title, 84); strcpy(playrec_buf.title_id, ID); memset(playrec_buf.padding2, 0, 18); //Calculate and update checksum for(i=0; i<31; i++) sum += playrec_buf.data[i]; playrec_buf.checksum=sum; //Write play_rec.dat if(IOS_Write(playrec_fd, &playrec_buf, sizeof(playrec_buf)) != sizeof(playrec_buf)) goto error_1; IOS_Close(playrec_fd); return 0; error_1: gprintf("error_1\n"); IOS_Close(playrec_fd); error_2: gprintf("error_2\n"); return -1; }
static s32 __WII_WriteNANDBootInfo(void) { int fd; int ret; __SetChecksum(&nandboot, sizeof(nandboot)); fd = IOS_Open(__nandbootinfo,IPC_OPEN_READ|IPC_OPEN_WRITE); if(fd < 0) { return WII_EINTERNAL; } ret = IOS_Write(fd, &nandboot, sizeof(nandboot)); IOS_Close(fd); if(ret != sizeof(nandboot)) { return WII_EINTERNAL; } return 0; }
static s32 __WII_WriteStateFlags(void) { int fd; int ret; __SetChecksum(&stateflags, sizeof(stateflags)); fd = IOS_Open(__stateflags,IPC_OPEN_READ|IPC_OPEN_WRITE); if(fd < 0) { return WII_EINTERNAL; } ret = IOS_Write(fd, &stateflags, sizeof(stateflags)); IOS_Close(fd); if(ret != sizeof(stateflags)) { return WII_EINTERNAL; } return 0; }
/* This creates the file in the TMP dir and then moves it to the destination overwriting it! To work correctly on the real nand we must have the same filename for the source and destination! */ s32 NANDWriteFileSafe( char *pathdst, void *data, u32 size ) { char *path = (char*)heap_alloc_aligned( 0, 0x40, 32 ); s32 i=0; //Extract filename //search backwards for slash for( i=strlen(pathdst); i > 0; --i ) if( pathdst[i] == '/' ) break; _sprintf( path, "/tmp%s", pathdst + i ); s32 r = ISFS_CreateFile( path, 0, 3, 3, 3 ); if( r == FS_EEXIST2 ) { ISFS_Delete( path ); r = ISFS_CreateFile( path, 0, 3, 3, 3 ); if( r < 0 ) { //dbgprintf("ISFS_CreateFile(%s):%d\n",path,r); heap_free( 0, path ); return r; } } else { if( r < 0 ) { //dbgprintf("ISFS_CreateFile(%s):%d\n",path,r); heap_free( 0, path ); return r; } } s32 fd = IOS_Open( path, 2 ); if( fd < 0 ) { //dbgprintf("IOS_Open(%s):%d\n",path,r); heap_free( 0, path ); return r; } r = IOS_Write( fd, data, size ); if( r < 0 || r != size ) { //dbgprintf("IOS_Write():%d\n",r); IOS_Close( fd ); heap_free( 0, path ); return r; } IOS_Close( fd ); r = ISFS_Rename( path, pathdst ); if( r < 0 ) { //dbgprintf("ISFS_Rename(%s,%s):%d\n",path,pathdst,r); heap_free( 0, path ); return r; } heap_free( 0, path ); return r; }
int mload_write(const void * buf, u32 size) { if(mload_init()<0) return -1; return IOS_Write(mload_fd, buf, size); }