diff --git a/source/iosuhax.c b/source/iosuhax.c index 5039a9a..e7321d0 100644 --- a/source/iosuhax.c +++ b/source/iosuhax.c @@ -26,6 +26,8 @@ #include "os_functions.h" #include "iosuhax.h" +#define IOSUHAX_MAGIC_WORD 0x4E696365 + #define IOCTL_MEM_WRITE 0x00 #define IOCTL_MEM_READ 0x01 #define IOCTL_SVC 0x02 @@ -59,6 +61,8 @@ #define IOCTL_FSA_RAW_WRITE 0x56 #define IOCTL_FSA_RAW_CLOSE 0x57 #define IOCTL_FSA_CHANGEMODE 0x58 +#define IOCTL_FSA_FLUSHVOLUME 0x59 +#define IOCTL_CHECK_IF_IOSUHAX 0x5B static int iosuhaxHandle = -1; @@ -68,6 +72,17 @@ int IOSUHAX_Open(const char *dev) return iosuhaxHandle; iosuhaxHandle = IOS_Open((char*)(dev ? dev : "/dev/iosuhax"), 0); + if(iosuhaxHandle >= 0 && dev) //make sure device is actually iosuhax + { + unsigned int res = 0; + IOS_Ioctl(iosuhaxHandle, IOCTL_CHECK_IF_IOSUHAX, (void*)0, 0, &res, 4); + if(res != IOSUHAX_MAGIC_WORD) + { + IOS_Close(iosuhaxHandle); + iosuhaxHandle = -1; + } + } + return iosuhaxHandle; } @@ -241,6 +256,36 @@ int IOSUHAX_FSA_Unmount(int fsaFd, const char* path, uint32_t flags) return result; } +int IOSUHAX_FSA_FlushVolume(int fsaFd, const char *volume_path) +{ + if(iosuhaxHandle < 0) + return iosuhaxHandle; + + const int input_cnt = 2; + + int io_buf_size = sizeof(uint32_t) * input_cnt + strlen(volume_path) + 1; + + uint32_t *io_buf = (uint32_t*)memalign(0x20, io_buf_size); + if(!io_buf) + return -2; + + io_buf[0] = fsaFd; + io_buf[1] = sizeof(uint32_t) * input_cnt; + strcpy(((char*)io_buf) + io_buf[1], volume_path); + + int result; + + int res = IOS_Ioctl(iosuhaxHandle, IOCTL_FSA_FLUSHVOLUME, io_buf, io_buf_size, &result, sizeof(result)); + if(res < 0) + { + free(io_buf); + return res; + } + + free(io_buf); + return result; +} + int IOSUHAX_FSA_GetDeviceInfo(int fsaFd, const char* device_path, int type, uint32_t* out_data) { if(iosuhaxHandle < 0) diff --git a/source/iosuhax.h b/source/iosuhax.h index 0b091ad..4e52ebf 100644 --- a/source/iosuhax.h +++ b/source/iosuhax.h @@ -76,6 +76,7 @@ int IOSUHAX_FSA_Close(int fsaFd); int IOSUHAX_FSA_Mount(int fsaFd, const char* device_path, const char* volume_path, uint32_t flags, const char* arg_string, int arg_string_len); int IOSUHAX_FSA_Unmount(int fsaFd, const char* path, uint32_t flags); +int IOSUHAX_FSA_FlushVolume(int fsaFd, const char* volume_path); int IOSUHAX_FSA_GetDeviceInfo(int fsaFd, const char* device_path, int type, uint32_t* out_data);