s32 SetBootState( u8 type , u8 flags , u8 returnto , u8 discstate ) { StateFlags *sf = (StateFlags *)mem_align( 32, sizeof(StateFlags) ); memset( sf, 0, sizeof(StateFlags) ); s32 fd = ISFS_Open("/title/00000001/00000002/data/state.dat", 1|2 ); if(fd < 0) { mem_free( sf ); ISFS_Close(fd); return -1; } s32 ret = ISFS_Read(fd, sf, sizeof(StateFlags)); if(ret != sizeof(StateFlags)) { mem_free( sf ); ISFS_Close(fd); return -2 ; } sf->type = type; sf->returnto = returnto; sf->flags = flags; sf->discstate = discstate; sf->checksum= __CalcChecksum((u32*)sf, sizeof(StateFlags)); if(ISFS_Seek( fd, 0, 0 )<0) { mem_free( sf ); ISFS_Close(fd); return -3; } if(ISFS_Write(fd, sf, sizeof(StateFlags))!=sizeof(StateFlags)) { mem_free( sf ); ISFS_Close(fd); return -4; } ISFS_Close(fd); mem_free( sf ); return 1; }
s32 SetNandBootInfo(void) { static NANDBootInfo BootInfo ATTRIBUTE_ALIGN(32); memset(&BootInfo,0,sizeof(NANDBootInfo)); BootInfo.apptype = 0x80; BootInfo.titletype = 2; if(ES_GetTitleID(&BootInfo.launcher) < 0) BootInfo.launcher = 0x0000000100000002LL; BootInfo.checksum = __CalcChecksum((u32*)&BootInfo,sizeof(NANDBootInfo)); s32 fd = ISFS_Open("/shared2/sys/NANDBOOTINFO", ISFS_OPEN_RW ); if(fd < 0) { return fd; } s32 ret = ISFS_Write(fd, &BootInfo, sizeof(NANDBootInfo)); if(ret < 0) { ISFS_Close(fd); gprintf("SetNandBootInfo : ISFS_Write returned %d\n",ret); return -2; } ISFS_Close(fd); return 1; }
static int __ValidChecksum(void *buf, int len) { u32 *p = (u32*)buf; return p[0] == __CalcChecksum(p, len); }
static void __SetChecksum(void *buf, int len) { u32 *p = (u32*)buf; p[0] = __CalcChecksum(p, len); }