Formatting

This commit is contained in:
Maschell 2021-09-24 19:38:34 +02:00
parent 69532cf9d9
commit 0e1af0e341
8 changed files with 498 additions and 613 deletions

3
.gitignore vendored
View File

@ -3,3 +3,6 @@
*.bz2 *.bz2
release/ release/
lib/ lib/
.idea/
cmake-build-debug/
CMakeLists.txt

View File

@ -21,8 +21,7 @@
* 3. This notice may not be removed or altered from any source * 3. This notice may not be removed or altered from any source
* distribution. * distribution.
***************************************************************************/ ***************************************************************************/
#ifndef _LIB_IOSUHAX_H_ #pragma once
#define _LIB_IOSUHAX_H_
#include <stdint.h> #include <stdint.h>
@ -36,26 +35,24 @@ extern "C" {
#define IOS_ERROR_UNKNOWN 0xFFFFFFF7 #define IOS_ERROR_UNKNOWN 0xFFFFFFF7
#define IOS_ERROR_NOEXISTS 0xFFFFFFFA #define IOS_ERROR_NOEXISTS 0xFFFFFFFA
typedef struct typedef struct {
{
uint32_t flag; uint32_t flag;
uint32_t permission; uint32_t permission;
uint32_t owner_id; uint32_t owner_id;
uint32_t group_id; uint32_t group_id;
uint32_t size; // size in bytes uint32_t size; // size in bytes
uint32_t physsize; // physical size on disk in bytes uint32_t physsize; // physical size on disk in bytes
uint32_t unk[3]; uint32_t unk[3];
uint32_t id; uint32_t id;
uint32_t ctime; uint32_t ctime;
uint32_t mtime; uint32_t mtime;
uint32_t unk2[0x0D]; uint32_t unk2[0x0D];
}fileStat_s; } fileStat_s;
typedef struct typedef struct {
{
fileStat_s stat; fileStat_s stat;
char name[0x100]; char name[0x100];
}directoryEntry_s; } directoryEntry_s;
#define DIR_ENTRY_IS_DIRECTORY 0x80000000 #define DIR_ENTRY_IS_DIRECTORY 0x80000000
@ -65,48 +62,66 @@ typedef struct
int IOSUHAX_Open(const char *dev); // if dev == NULL the default path /dev/iosuhax will be used int IOSUHAX_Open(const char *dev); // if dev == NULL the default path /dev/iosuhax will be used
int IOSUHAX_Close(void); int IOSUHAX_Close(void);
int IOSUHAX_memwrite(uint32_t address, const uint8_t * buffer, uint32_t size); // IOSU external input int IOSUHAX_memwrite(uint32_t address, const uint8_t *buffer, uint32_t size); // IOSU external input
int IOSUHAX_memread(uint32_t address, uint8_t * out_buffer, uint32_t size); // IOSU external output int IOSUHAX_memread(uint32_t address, uint8_t *out_buffer, uint32_t size); // IOSU external output
int IOSUHAX_memcpy(uint32_t dst, uint32_t src, uint32_t size); // IOSU internal memcpy only int IOSUHAX_memcpy(uint32_t dst, uint32_t src, uint32_t size); // IOSU internal memcpy only
int IOSUHAX_kern_write32(uint32_t address, uint32_t value); int IOSUHAX_kern_write32(uint32_t address, uint32_t value);
int IOSUHAX_kern_read32(uint32_t address, uint32_t* out_buffer, uint32_t count);
int IOSUHAX_SVC(uint32_t svc_id, uint32_t * args, uint32_t arg_cnt); int IOSUHAX_kern_read32(uint32_t address, uint32_t *out_buffer, uint32_t count);
int IOSUHAX_SVC(uint32_t svc_id, uint32_t *args, uint32_t arg_cnt);
int IOSUHAX_FSA_Open(); int IOSUHAX_FSA_Open();
int IOSUHAX_FSA_Close(int fsaFd); 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_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); 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);
int IOSUHAX_FSA_MakeDir(int fsaFd, const char *path, uint32_t flags);
int IOSUHAX_FSA_OpenDir(int fsaFd, const char *path, int *outHandle);
int IOSUHAX_FSA_ReadDir(int fsaFd, int handle, directoryEntry_s *out_data);
int IOSUHAX_FSA_MakeDir(int fsaFd, const char* path, uint32_t flags);
int IOSUHAX_FSA_OpenDir(int fsaFd, const char* path, int* outHandle);
int IOSUHAX_FSA_ReadDir(int fsaFd, int handle, directoryEntry_s* out_data);
int IOSUHAX_FSA_RewindDir(int fsaFd, int dirHandle); int IOSUHAX_FSA_RewindDir(int fsaFd, int dirHandle);
int IOSUHAX_FSA_CloseDir(int fsaFd, int handle); int IOSUHAX_FSA_CloseDir(int fsaFd, int handle);
int IOSUHAX_FSA_ChangeDir(int fsaFd, const char *path); int IOSUHAX_FSA_ChangeDir(int fsaFd, const char *path);
int IOSUHAX_FSA_OpenFile(int fsaFd, const char* path, const char* mode, int* outHandle); int IOSUHAX_FSA_OpenFile(int fsaFd, const char *path, const char *mode, int *outHandle);
int IOSUHAX_FSA_ReadFile(int fsaFd, void* data, uint32_t size, uint32_t cnt, int fileHandle, uint32_t flags);
int IOSUHAX_FSA_WriteFile(int fsaFd, const void* data, uint32_t size, uint32_t cnt, int fileHandle, uint32_t flags); int IOSUHAX_FSA_ReadFile(int fsaFd, void *data, uint32_t size, uint32_t cnt, int fileHandle, uint32_t flags);
int IOSUHAX_FSA_StatFile(int fsaFd, int fileHandle, fileStat_s* out_data);
int IOSUHAX_FSA_CloseFile(int fsaFd, int fileHandle); int IOSUHAX_FSA_WriteFile(int fsaFd, const void *data, uint32_t size, uint32_t cnt, int fileHandle, uint32_t flags);
int IOSUHAX_FSA_SetFilePos(int fsaFd, int fileHandle, uint32_t position);
int IOSUHAX_FSA_GetStat(int fsaFd, const char *path, fileStat_s* out_data); int IOSUHAX_FSA_StatFile(int fsaFd, int fileHandle, fileStat_s *out_data);
int IOSUHAX_FSA_Remove(int fsaFd, const char *path);
int IOSUHAX_FSA_ChangeMode(int fsaFd, const char* path, int mode); int IOSUHAX_FSA_CloseFile(int fsaFd, int fileHandle);
int IOSUHAX_FSA_SetFilePos(int fsaFd, int fileHandle, uint32_t position);
int IOSUHAX_FSA_GetStat(int fsaFd, const char *path, fileStat_s *out_data);
int IOSUHAX_FSA_Remove(int fsaFd, const char *path);
int IOSUHAX_FSA_ChangeMode(int fsaFd, const char *path, int mode);
int IOSUHAX_FSA_RawOpen(int fsaFd, const char *device_path, int *outHandle);
int IOSUHAX_FSA_RawRead(int fsaFd, void *data, uint32_t block_size, uint32_t block_cnt, uint64_t sector_offset, int device_handle);
int IOSUHAX_FSA_RawWrite(int fsaFd, const void *data, uint32_t block_size, uint32_t block_cnt, uint64_t sector_offset, int device_handle);
int IOSUHAX_FSA_RawOpen(int fsaFd, const char* device_path, int* outHandle);
int IOSUHAX_FSA_RawRead(int fsaFd, void* data, uint32_t block_size, uint32_t block_cnt, uint64_t sector_offset, int device_handle);
int IOSUHAX_FSA_RawWrite(int fsaFd, const void* data, uint32_t block_size, uint32_t block_cnt, uint64_t sector_offset, int device_handle);
int IOSUHAX_FSA_RawClose(int fsaFd, int device_handle); int IOSUHAX_FSA_RawClose(int fsaFd, int device_handle);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
#endif

View File

@ -33,6 +33,7 @@ extern "C" {
//! dev_path: (optional) if a device should be mounted to the mount_path. If NULL no IOSUHAX_FSA_Mount is not executed. //! dev_path: (optional) if a device should be mounted to the mount_path. If NULL no IOSUHAX_FSA_Mount is not executed.
//! mount_path: path to map to virtual device name //! mount_path: path to map to virtual device name
int mount_fs(const char *virt_name, int fsaFd, const char *dev_path, const char *mount_path); int mount_fs(const char *virt_name, int fsaFd, const char *dev_path, const char *mount_path);
int unmount_fs(const char *virt_name); int unmount_fs(const char *virt_name);
#ifdef __cplusplus #ifdef __cplusplus

View File

@ -42,25 +42,30 @@ typedef uint32_t sec_t;
#define FEATURE_MEDIUM_CANREAD 0x00000001 #define FEATURE_MEDIUM_CANREAD 0x00000001
#define FEATURE_MEDIUM_CANWRITE 0x00000002 #define FEATURE_MEDIUM_CANWRITE 0x00000002
typedef bool (* FN_MEDIUM_STARTUP)(void) ; typedef bool (*FN_MEDIUM_STARTUP)(void);
typedef bool (* FN_MEDIUM_ISINSERTED)(void) ;
typedef bool (* FN_MEDIUM_READSECTORS)(uint32_t sector, uint32_t numSectors, void* buffer) ; typedef bool (*FN_MEDIUM_ISINSERTED)(void);
typedef bool (* FN_MEDIUM_WRITESECTORS)(uint32_t sector, uint32_t numSectors, const void* buffer) ;
typedef bool (* FN_MEDIUM_CLEARSTATUS)(void) ; typedef bool (*FN_MEDIUM_READSECTORS)(uint32_t sector, uint32_t numSectors, void *buffer);
typedef bool (* FN_MEDIUM_SHUTDOWN)(void) ;
typedef bool (*FN_MEDIUM_WRITESECTORS)(uint32_t sector, uint32_t numSectors, const void *buffer);
typedef bool (*FN_MEDIUM_CLEARSTATUS)(void);
typedef bool (*FN_MEDIUM_SHUTDOWN)(void);
struct DISC_INTERFACE_STRUCT { struct DISC_INTERFACE_STRUCT {
unsigned long ioType ; unsigned long ioType;
unsigned long features ; unsigned long features;
FN_MEDIUM_STARTUP startup ; FN_MEDIUM_STARTUP startup;
FN_MEDIUM_ISINSERTED isInserted ; FN_MEDIUM_ISINSERTED isInserted;
FN_MEDIUM_READSECTORS readSectors ; FN_MEDIUM_READSECTORS readSectors;
FN_MEDIUM_WRITESECTORS writeSectors ; FN_MEDIUM_WRITESECTORS writeSectors;
FN_MEDIUM_CLEARSTATUS clearStatus ; FN_MEDIUM_CLEARSTATUS clearStatus;
FN_MEDIUM_SHUTDOWN shutdown ; FN_MEDIUM_SHUTDOWN shutdown;
} ; };
typedef struct DISC_INTERFACE_STRUCT DISC_INTERFACE ; typedef struct DISC_INTERFACE_STRUCT DISC_INTERFACE;
#endif #endif
extern const DISC_INTERFACE IOSUHAX_sdio_disc_interface; extern const DISC_INTERFACE IOSUHAX_sdio_disc_interface;

View File

@ -69,20 +69,18 @@ static int iosuhaxHandle = -1;
#define ALIGN(align) __attribute__((aligned(align))) #define ALIGN(align) __attribute__((aligned(align)))
#define ROUNDUP(x, align) (((x) + ((align) - 1)) & ~((align) - 1)) #define ROUNDUP(x, align) (((x) + ((align) - 1)) & ~((align) - 1))
int IOSUHAX_Open(const char *dev) int IOSUHAX_Open(const char *dev) {
{ if (iosuhaxHandle >= 0)
if(iosuhaxHandle >= 0)
return iosuhaxHandle; return iosuhaxHandle;
iosuhaxHandle = IOS_Open((char*)(dev ? dev : "/dev/iosuhax"), 0); iosuhaxHandle = IOS_Open((char *) (dev ? dev : "/dev/iosuhax"), 0);
if(iosuhaxHandle >= 0 && dev) //make sure device is actually iosuhax if (iosuhaxHandle >= 0 && dev) //make sure device is actually iosuhax
{ {
ALIGN(0x20) int res[0x20 >> 2]; ALIGN(0x20) int res[0x20 >> 2];
*res = 0; *res = 0;
IOS_Ioctl(iosuhaxHandle, IOCTL_CHECK_IF_IOSUHAX, (void*)0, 0, res, 4); IOS_Ioctl(iosuhaxHandle, IOCTL_CHECK_IF_IOSUHAX, (void *) 0, 0, res, 4);
if(*res != IOSUHAX_MAGIC_WORD) if (*res != IOSUHAX_MAGIC_WORD) {
{
IOS_Close(iosuhaxHandle); IOS_Close(iosuhaxHandle);
iosuhaxHandle = -1; iosuhaxHandle = -1;
} }
@ -91,9 +89,8 @@ int IOSUHAX_Open(const char *dev)
return iosuhaxHandle; return iosuhaxHandle;
} }
int IOSUHAX_Close(void) int IOSUHAX_Close(void) {
{ if (iosuhaxHandle < 0)
if(iosuhaxHandle < 0)
return 0; return 0;
int res = IOS_Close(iosuhaxHandle); int res = IOS_Close(iosuhaxHandle);
@ -101,13 +98,12 @@ int IOSUHAX_Close(void)
return res; return res;
} }
int IOSUHAX_memwrite(uint32_t address, const uint8_t * buffer, uint32_t size) int IOSUHAX_memwrite(uint32_t address, const uint8_t *buffer, uint32_t size) {
{ if (iosuhaxHandle < 0)
if(iosuhaxHandle < 0)
return iosuhaxHandle; return iosuhaxHandle;
uint32_t *io_buf = (uint32_t*)memalign(0x20, ROUNDUP(size + 4, 0x20)); uint32_t *io_buf = (uint32_t *) memalign(0x20, ROUNDUP(size + 4, 0x20));
if(!io_buf) if (!io_buf)
return -2; return -2;
io_buf[0] = address; io_buf[0] = address;
@ -119,35 +115,32 @@ int IOSUHAX_memwrite(uint32_t address, const uint8_t * buffer, uint32_t size)
return res; return res;
} }
int IOSUHAX_memread(uint32_t address, uint8_t * out_buffer, uint32_t size) int IOSUHAX_memread(uint32_t address, uint8_t *out_buffer, uint32_t size) {
{ if (iosuhaxHandle < 0)
if(iosuhaxHandle < 0)
return iosuhaxHandle; return iosuhaxHandle;
ALIGN(0x20) int io_buf[0x20 >> 2]; ALIGN(0x20) int io_buf[0x20 >> 2];
io_buf[0] = address; io_buf[0] = address;
void* tmp_buf = NULL; void *tmp_buf = NULL;
if(((uintptr_t)out_buffer & 0x1F) || (size & 0x1F)) if (((uintptr_t) out_buffer & 0x1F) || (size & 0x1F)) {
{ tmp_buf = (uint32_t *) memalign(0x20, ROUNDUP(size, 0x20));
tmp_buf = (uint32_t*)memalign(0x20, ROUNDUP(size, 0x20)); if (!tmp_buf)
if(!tmp_buf) return -2;
return -2;
} }
int res = IOS_Ioctl(iosuhaxHandle, IOCTL_MEM_READ, io_buf, sizeof(address), tmp_buf ? tmp_buf : out_buffer, size); int res = IOS_Ioctl(iosuhaxHandle, IOCTL_MEM_READ, io_buf, sizeof(address), tmp_buf ? tmp_buf : out_buffer, size);
if(res >= 0 && tmp_buf) if (res >= 0 && tmp_buf)
memcpy(out_buffer, tmp_buf, size); memcpy(out_buffer, tmp_buf, size);
free(tmp_buf); free(tmp_buf);
return res; return res;
} }
int IOSUHAX_memcpy(uint32_t dst, uint32_t src, uint32_t size) int IOSUHAX_memcpy(uint32_t dst, uint32_t src, uint32_t size) {
{ if (iosuhaxHandle < 0)
if(iosuhaxHandle < 0)
return iosuhaxHandle; return iosuhaxHandle;
ALIGN(0x20) uint32_t io_buf[0x20 >> 2]; ALIGN(0x20) uint32_t io_buf[0x20 >> 2];
@ -158,9 +151,8 @@ int IOSUHAX_memcpy(uint32_t dst, uint32_t src, uint32_t size)
return IOS_Ioctl(iosuhaxHandle, IOCTL_MEMCPY, io_buf, 3 * sizeof(uint32_t), 0, 0); return IOS_Ioctl(iosuhaxHandle, IOCTL_MEMCPY, io_buf, 3 * sizeof(uint32_t), 0, 0);
} }
int IOSUHAX_kern_write32(uint32_t address, uint32_t value) int IOSUHAX_kern_write32(uint32_t address, uint32_t value) {
{ if (iosuhaxHandle < 0)
if(iosuhaxHandle < 0)
return iosuhaxHandle; return iosuhaxHandle;
ALIGN(0x20) uint32_t io_buf[0x20 >> 2]; ALIGN(0x20) uint32_t io_buf[0x20 >> 2];
@ -170,43 +162,39 @@ int IOSUHAX_kern_write32(uint32_t address, uint32_t value)
return IOS_Ioctl(iosuhaxHandle, IOCTL_KERN_WRITE32, io_buf, 2 * sizeof(uint32_t), 0, 0); return IOS_Ioctl(iosuhaxHandle, IOCTL_KERN_WRITE32, io_buf, 2 * sizeof(uint32_t), 0, 0);
} }
int IOSUHAX_kern_read32(uint32_t address, uint32_t* out_buffer, uint32_t count) int IOSUHAX_kern_read32(uint32_t address, uint32_t *out_buffer, uint32_t count) {
{ if (iosuhaxHandle < 0)
if(iosuhaxHandle < 0)
return iosuhaxHandle; return iosuhaxHandle;
ALIGN(0x20) uint32_t io_buf[0x20 >> 2]; ALIGN(0x20) uint32_t io_buf[0x20 >> 2];
io_buf[0] = address; io_buf[0] = address;
void* tmp_buf = NULL; void *tmp_buf = NULL;
if(((uintptr_t)out_buffer & 0x1F) || ((count * 4) & 0x1F)) if (((uintptr_t) out_buffer & 0x1F) || ((count * 4) & 0x1F)) {
{ tmp_buf = (uint32_t *) memalign(0x20, ROUNDUP((count * 4), 0x20));
tmp_buf = (uint32_t*)memalign(0x20, ROUNDUP((count * 4), 0x20)); if (!tmp_buf)
if(!tmp_buf) return -2;
return -2;
} }
int res = IOS_Ioctl(iosuhaxHandle, IOCTL_KERN_READ32, io_buf, sizeof(address), tmp_buf ? tmp_buf : out_buffer, count * 4); int res = IOS_Ioctl(iosuhaxHandle, IOCTL_KERN_READ32, io_buf, sizeof(address), tmp_buf ? tmp_buf : out_buffer, count * 4);
if(res >= 0 && tmp_buf) if (res >= 0 && tmp_buf)
memcpy(out_buffer, tmp_buf, count * 4); memcpy(out_buffer, tmp_buf, count * 4);
free(tmp_buf); free(tmp_buf);
return res; return res;
} }
int IOSUHAX_SVC(uint32_t svc_id, uint32_t * args, uint32_t arg_cnt) int IOSUHAX_SVC(uint32_t svc_id, uint32_t *args, uint32_t arg_cnt) {
{ if (iosuhaxHandle < 0)
if(iosuhaxHandle < 0)
return iosuhaxHandle; return iosuhaxHandle;
ALIGN(0x20) uint32_t arguments[0x40 >> 2]; ALIGN(0x20) uint32_t arguments[0x40 >> 2];
arguments[0] = svc_id; arguments[0] = svc_id;
if(args && arg_cnt) if (args && arg_cnt) {
{ if (arg_cnt > 8)
if(arg_cnt > 8)
arg_cnt = 8; arg_cnt = 8;
memcpy(arguments + 1, args, arg_cnt * 4); memcpy(arguments + 1, args, arg_cnt * 4);
@ -214,44 +202,41 @@ int IOSUHAX_SVC(uint32_t svc_id, uint32_t * args, uint32_t arg_cnt)
ALIGN(0x20) int result[0x20 >> 2]; ALIGN(0x20) int result[0x20 >> 2];
int ret = IOS_Ioctl(iosuhaxHandle, IOCTL_SVC, arguments, (1 + arg_cnt) * 4, result, 4); int ret = IOS_Ioctl(iosuhaxHandle, IOCTL_SVC, arguments, (1 + arg_cnt) * 4, result, 4);
if(ret < 0) if (ret < 0)
return ret; return ret;
return *result; return *result;
} }
int IOSUHAX_FSA_Open(void) int IOSUHAX_FSA_Open(void) {
{ if (iosuhaxHandle < 0)
if(iosuhaxHandle < 0)
return iosuhaxHandle; return iosuhaxHandle;
ALIGN(0x20) int io_buf[0x20 >> 2]; ALIGN(0x20) int io_buf[0x20 >> 2];
int res = IOS_Ioctl(iosuhaxHandle, IOCTL_FSA_OPEN, 0, 0, io_buf, sizeof(int)); int res = IOS_Ioctl(iosuhaxHandle, IOCTL_FSA_OPEN, 0, 0, io_buf, sizeof(int));
if(res < 0) if (res < 0)
return res; return res;
return io_buf[0]; return io_buf[0];
} }
int IOSUHAX_FSA_Close(int fsaFd) int IOSUHAX_FSA_Close(int fsaFd) {
{ if (iosuhaxHandle < 0)
if(iosuhaxHandle < 0)
return iosuhaxHandle; return iosuhaxHandle;
ALIGN(0x20) int io_buf[0x20 >> 2]; ALIGN(0x20) int io_buf[0x20 >> 2];
io_buf[0] = fsaFd; io_buf[0] = fsaFd;
int res = IOS_Ioctl(iosuhaxHandle, IOCTL_FSA_CLOSE, io_buf, sizeof(fsaFd), io_buf, sizeof(fsaFd)); int res = IOS_Ioctl(iosuhaxHandle, IOCTL_FSA_CLOSE, io_buf, sizeof(fsaFd), io_buf, sizeof(fsaFd));
if(res < 0) if (res < 0)
return res; return res;
return io_buf[0]; return io_buf[0];
} }
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_Mount(int fsaFd, const char *device_path, const char *volume_path, uint32_t flags, const char *arg_string, int arg_string_len) {
{ if (iosuhaxHandle < 0)
if(iosuhaxHandle < 0)
return iosuhaxHandle; return iosuhaxHandle;
const int input_cnt = 6; const int input_cnt = 6;
@ -265,25 +250,24 @@ int IOSUHAX_FSA_Mount(int fsaFd, const char* device_path, const char* volume_pat
io_buf[1] = sizeof(uint32_t) * input_cnt; io_buf[1] = sizeof(uint32_t) * input_cnt;
io_buf[2] = io_buf[1] + strlen(device_path) + 1; io_buf[2] = io_buf[1] + strlen(device_path) + 1;
io_buf[3] = flags; io_buf[3] = flags;
io_buf[4] = arg_string_len ? ( io_buf[2] + strlen(volume_path) + 1) : 0; io_buf[4] = arg_string_len ? (io_buf[2] + strlen(volume_path) + 1) : 0;
io_buf[5] = arg_string_len; io_buf[5] = arg_string_len;
strcpy(((char*)io_buf) + io_buf[1], device_path); strcpy(((char *) io_buf) + io_buf[1], device_path);
strcpy(((char*)io_buf) + io_buf[2], volume_path); strcpy(((char *) io_buf) + io_buf[2], volume_path);
if(arg_string_len) if (arg_string_len)
memcpy(((char*)io_buf) + io_buf[4], arg_string, arg_string_len); memcpy(((char *) io_buf) + io_buf[4], arg_string, arg_string_len);
int res = IOS_Ioctl(iosuhaxHandle, IOCTL_FSA_MOUNT, io_buf, io_buf_size, io_buf, 4); int res = IOS_Ioctl(iosuhaxHandle, IOCTL_FSA_MOUNT, io_buf, io_buf_size, io_buf, 4);
if(res < 0) if (res < 0)
return res; return res;
return io_buf[0]; return io_buf[0];
} }
int IOSUHAX_FSA_Unmount(int fsaFd, const char* path, uint32_t flags) int IOSUHAX_FSA_Unmount(int fsaFd, const char *path, uint32_t flags) {
{ if (iosuhaxHandle < 0)
if(iosuhaxHandle < 0)
return iosuhaxHandle; return iosuhaxHandle;
const int input_cnt = 3; const int input_cnt = 3;
@ -295,18 +279,17 @@ int IOSUHAX_FSA_Unmount(int fsaFd, const char* path, uint32_t flags)
io_buf[0] = fsaFd; io_buf[0] = fsaFd;
io_buf[1] = sizeof(uint32_t) * input_cnt; io_buf[1] = sizeof(uint32_t) * input_cnt;
io_buf[2] = flags; io_buf[2] = flags;
strcpy(((char*)io_buf) + io_buf[1], path); strcpy(((char *) io_buf) + io_buf[1], path);
int res = IOS_Ioctl(iosuhaxHandle, IOCTL_FSA_UNMOUNT, io_buf, io_buf_size, io_buf, 4); int res = IOS_Ioctl(iosuhaxHandle, IOCTL_FSA_UNMOUNT, io_buf, io_buf_size, io_buf, 4);
if(res < 0) if (res < 0)
return res; return res;
return io_buf[0]; return io_buf[0];
} }
int IOSUHAX_FSA_FlushVolume(int fsaFd, const char *volume_path) int IOSUHAX_FSA_FlushVolume(int fsaFd, const char *volume_path) {
{ if (iosuhaxHandle < 0)
if(iosuhaxHandle < 0)
return iosuhaxHandle; return iosuhaxHandle;
const int input_cnt = 2; const int input_cnt = 2;
@ -317,38 +300,36 @@ int IOSUHAX_FSA_FlushVolume(int fsaFd, const char *volume_path)
io_buf[0] = fsaFd; io_buf[0] = fsaFd;
io_buf[1] = sizeof(uint32_t) * input_cnt; io_buf[1] = sizeof(uint32_t) * input_cnt;
strcpy(((char*)io_buf) + io_buf[1], volume_path); strcpy(((char *) io_buf) + io_buf[1], volume_path);
int res = IOS_Ioctl(iosuhaxHandle, IOCTL_FSA_FLUSHVOLUME, io_buf, io_buf_size, io_buf, 4); int res = IOS_Ioctl(iosuhaxHandle, IOCTL_FSA_FLUSHVOLUME, io_buf, io_buf_size, io_buf, 4);
if(res < 0) if (res < 0)
return res; return res;
return io_buf[0]; return io_buf[0];
} }
int IOSUHAX_FSA_GetDeviceInfo(int fsaFd, const char* device_path, int type, uint32_t* out_data) int IOSUHAX_FSA_GetDeviceInfo(int fsaFd, const char *device_path, int type, uint32_t *out_data) {
{ if (iosuhaxHandle < 0)
if(iosuhaxHandle < 0)
return iosuhaxHandle; return iosuhaxHandle;
const int input_cnt = 3; const int input_cnt = 3;
int io_buf_size = sizeof(uint32_t) * input_cnt + strlen(device_path) + 1; int io_buf_size = sizeof(uint32_t) * input_cnt + strlen(device_path) + 1;
uint32_t *io_buf = (uint32_t*)memalign(0x20, io_buf_size); uint32_t *io_buf = (uint32_t *) memalign(0x20, io_buf_size);
if(!io_buf) if (!io_buf)
return -2; return -2;
io_buf[0] = fsaFd; io_buf[0] = fsaFd;
io_buf[1] = sizeof(uint32_t) * input_cnt; io_buf[1] = sizeof(uint32_t) * input_cnt;
io_buf[2] = type; io_buf[2] = type;
strcpy(((char*)io_buf) + io_buf[1], device_path); strcpy(((char *) io_buf) + io_buf[1], device_path);
uint32_t out_buf[1 + 0x64 / 4]; uint32_t out_buf[1 + 0x64 / 4];
int res = IOS_Ioctl(iosuhaxHandle, IOCTL_FSA_GETDEVICEINFO, io_buf, io_buf_size, out_buf, sizeof(out_buf)); int res = IOS_Ioctl(iosuhaxHandle, IOCTL_FSA_GETDEVICEINFO, io_buf, io_buf_size, out_buf, sizeof(out_buf));
if(res < 0) if (res < 0) {
{
free(io_buf); free(io_buf);
return res; return res;
} }
@ -358,28 +339,26 @@ int IOSUHAX_FSA_GetDeviceInfo(int fsaFd, const char* device_path, int type, uint
return out_buf[0]; return out_buf[0];
} }
int IOSUHAX_FSA_MakeDir(int fsaFd, const char* path, uint32_t flags) int IOSUHAX_FSA_MakeDir(int fsaFd, const char *path, uint32_t flags) {
{ if (iosuhaxHandle < 0)
if(iosuhaxHandle < 0)
return iosuhaxHandle; return iosuhaxHandle;
const int input_cnt = 3; const int input_cnt = 3;
int io_buf_size = sizeof(uint32_t) * input_cnt + strlen(path) + 1; int io_buf_size = sizeof(uint32_t) * input_cnt + strlen(path) + 1;
uint32_t *io_buf = (uint32_t*)memalign(0x20, io_buf_size); uint32_t *io_buf = (uint32_t *) memalign(0x20, io_buf_size);
if(!io_buf) if (!io_buf)
return -2; return -2;
io_buf[0] = fsaFd; io_buf[0] = fsaFd;
io_buf[1] = sizeof(uint32_t) * input_cnt; io_buf[1] = sizeof(uint32_t) * input_cnt;
io_buf[2] = flags; io_buf[2] = flags;
strcpy(((char*)io_buf) + io_buf[1], path); strcpy(((char *) io_buf) + io_buf[1], path);
int result; int result;
int res = IOS_Ioctl(iosuhaxHandle, IOCTL_FSA_MAKEDIR, io_buf, io_buf_size, &result, sizeof(result)); int res = IOS_Ioctl(iosuhaxHandle, IOCTL_FSA_MAKEDIR, io_buf, io_buf_size, &result, sizeof(result));
if(res < 0) if (res < 0) {
{
free(io_buf); free(io_buf);
return res; return res;
} }
@ -388,28 +367,26 @@ int IOSUHAX_FSA_MakeDir(int fsaFd, const char* path, uint32_t flags)
return result; return result;
} }
int IOSUHAX_FSA_OpenDir(int fsaFd, const char* path, int* outHandle) int IOSUHAX_FSA_OpenDir(int fsaFd, const char *path, int *outHandle) {
{ if (iosuhaxHandle < 0)
if(iosuhaxHandle < 0)
return iosuhaxHandle; return iosuhaxHandle;
const int input_cnt = 2; const int input_cnt = 2;
int io_buf_size = sizeof(uint32_t) * input_cnt + strlen(path) + 1; int io_buf_size = sizeof(uint32_t) * input_cnt + strlen(path) + 1;
uint32_t *io_buf = (uint32_t*)memalign(0x20, io_buf_size); uint32_t *io_buf = (uint32_t *) memalign(0x20, io_buf_size);
if(!io_buf) if (!io_buf)
return -2; return -2;
io_buf[0] = fsaFd; io_buf[0] = fsaFd;
io_buf[1] = sizeof(uint32_t) * input_cnt; io_buf[1] = sizeof(uint32_t) * input_cnt;
strcpy(((char*)io_buf) + io_buf[1], path); strcpy(((char *) io_buf) + io_buf[1], path);
int result_vec[2]; int result_vec[2];
int res = IOS_Ioctl(iosuhaxHandle, IOCTL_FSA_OPENDIR, io_buf, io_buf_size, result_vec, sizeof(result_vec)); int res = IOS_Ioctl(iosuhaxHandle, IOCTL_FSA_OPENDIR, io_buf, io_buf_size, result_vec, sizeof(result_vec));
if(res < 0) if (res < 0) {
{
free(io_buf); free(io_buf);
return res; return res;
} }
@ -419,56 +396,52 @@ int IOSUHAX_FSA_OpenDir(int fsaFd, const char* path, int* outHandle)
return result_vec[0]; return result_vec[0];
} }
int IOSUHAX_FSA_ReadDir(int fsaFd, int handle, directoryEntry_s* out_data) int IOSUHAX_FSA_ReadDir(int fsaFd, int handle, directoryEntry_s *out_data) {
{ if (iosuhaxHandle < 0)
if(iosuhaxHandle < 0)
return iosuhaxHandle; return iosuhaxHandle;
const int input_cnt = 2; const int input_cnt = 2;
int io_buf_size = sizeof(uint32_t) * input_cnt; int io_buf_size = sizeof(uint32_t) * input_cnt;
uint32_t *io_buf = (uint32_t*)memalign(0x20, io_buf_size); uint32_t *io_buf = (uint32_t *) memalign(0x20, io_buf_size);
if(!io_buf) if (!io_buf)
return -2; return -2;
io_buf[0] = fsaFd; io_buf[0] = fsaFd;
io_buf[1] = handle; io_buf[1] = handle;
int result_vec_size = 4 + sizeof(directoryEntry_s); int result_vec_size = 4 + sizeof(directoryEntry_s);
uint8_t *result_vec = (uint8_t*) memalign(0x20, result_vec_size); uint8_t *result_vec = (uint8_t *) memalign(0x20, result_vec_size);
if(!result_vec) if (!result_vec) {
{
free(io_buf); free(io_buf);
return -2; return -2;
} }
int res = IOS_Ioctl(iosuhaxHandle, IOCTL_FSA_READDIR, io_buf, io_buf_size, result_vec, result_vec_size); int res = IOS_Ioctl(iosuhaxHandle, IOCTL_FSA_READDIR, io_buf, io_buf_size, result_vec, result_vec_size);
if(res < 0) if (res < 0) {
{
free(result_vec); free(result_vec);
free(io_buf); free(io_buf);
return res; return res;
} }
int result = *(int*)result_vec; int result = *(int *) result_vec;
memcpy(out_data, result_vec + 4, sizeof(directoryEntry_s)); memcpy(out_data, result_vec + 4, sizeof(directoryEntry_s));
free(io_buf); free(io_buf);
free(result_vec); free(result_vec);
return result; return result;
} }
int IOSUHAX_FSA_RewindDir(int fsaFd, int dirHandle) int IOSUHAX_FSA_RewindDir(int fsaFd, int dirHandle) {
{ if (iosuhaxHandle < 0)
if(iosuhaxHandle < 0)
return iosuhaxHandle; return iosuhaxHandle;
const int input_cnt = 2; const int input_cnt = 2;
int io_buf_size = sizeof(uint32_t) * input_cnt; int io_buf_size = sizeof(uint32_t) * input_cnt;
uint32_t *io_buf = (uint32_t*)memalign(0x20, io_buf_size); uint32_t *io_buf = (uint32_t *) memalign(0x20, io_buf_size);
if(!io_buf) if (!io_buf)
return -2; return -2;
io_buf[0] = fsaFd; io_buf[0] = fsaFd;
@ -477,8 +450,7 @@ int IOSUHAX_FSA_RewindDir(int fsaFd, int dirHandle)
int result; int result;
int res = IOS_Ioctl(iosuhaxHandle, IOCTL_FSA_REWINDDIR, io_buf, io_buf_size, &result, sizeof(result)); int res = IOS_Ioctl(iosuhaxHandle, IOCTL_FSA_REWINDDIR, io_buf, io_buf_size, &result, sizeof(result));
if(res < 0) if (res < 0) {
{
free(io_buf); free(io_buf);
return res; return res;
} }
@ -487,17 +459,16 @@ int IOSUHAX_FSA_RewindDir(int fsaFd, int dirHandle)
return result; return result;
} }
int IOSUHAX_FSA_CloseDir(int fsaFd, int handle) int IOSUHAX_FSA_CloseDir(int fsaFd, int handle) {
{ if (iosuhaxHandle < 0)
if(iosuhaxHandle < 0)
return iosuhaxHandle; return iosuhaxHandle;
const int input_cnt = 2; const int input_cnt = 2;
int io_buf_size = sizeof(uint32_t) * input_cnt; int io_buf_size = sizeof(uint32_t) * input_cnt;
uint32_t *io_buf = (uint32_t*)memalign(0x20, io_buf_size); uint32_t *io_buf = (uint32_t *) memalign(0x20, io_buf_size);
if(!io_buf) if (!io_buf)
return -2; return -2;
io_buf[0] = fsaFd; io_buf[0] = fsaFd;
@ -506,8 +477,7 @@ int IOSUHAX_FSA_CloseDir(int fsaFd, int handle)
int result; int result;
int res = IOS_Ioctl(iosuhaxHandle, IOCTL_FSA_CLOSEDIR, io_buf, io_buf_size, &result, sizeof(result)); int res = IOS_Ioctl(iosuhaxHandle, IOCTL_FSA_CLOSEDIR, io_buf, io_buf_size, &result, sizeof(result));
if(res < 0) if (res < 0) {
{
free(io_buf); free(io_buf);
return res; return res;
} }
@ -516,28 +486,26 @@ int IOSUHAX_FSA_CloseDir(int fsaFd, int handle)
return result; return result;
} }
int IOSUHAX_FSA_ChangeDir(int fsaFd, const char *path) int IOSUHAX_FSA_ChangeDir(int fsaFd, const char *path) {
{ if (iosuhaxHandle < 0)
if(iosuhaxHandle < 0)
return iosuhaxHandle; return iosuhaxHandle;
const int input_cnt = 2; const int input_cnt = 2;
int io_buf_size = sizeof(uint32_t) * input_cnt + strlen(path) + 1; int io_buf_size = sizeof(uint32_t) * input_cnt + strlen(path) + 1;
uint32_t *io_buf = (uint32_t*)memalign(0x20, io_buf_size); uint32_t *io_buf = (uint32_t *) memalign(0x20, io_buf_size);
if(!io_buf) if (!io_buf)
return -2; return -2;
io_buf[0] = fsaFd; io_buf[0] = fsaFd;
io_buf[1] = sizeof(uint32_t) * input_cnt; io_buf[1] = sizeof(uint32_t) * input_cnt;
strcpy(((char*)io_buf) + io_buf[1], path); strcpy(((char *) io_buf) + io_buf[1], path);
int result; int result;
int res = IOS_Ioctl(iosuhaxHandle, IOCTL_FSA_CHDIR, io_buf, io_buf_size, &result, sizeof(result)); int res = IOS_Ioctl(iosuhaxHandle, IOCTL_FSA_CHDIR, io_buf, io_buf_size, &result, sizeof(result));
if(res < 0) if (res < 0) {
{
free(io_buf); free(io_buf);
return res; return res;
} }
@ -546,30 +514,28 @@ int IOSUHAX_FSA_ChangeDir(int fsaFd, const char *path)
return result; return result;
} }
int IOSUHAX_FSA_OpenFile(int fsaFd, const char* path, const char* mode, int* outHandle) int IOSUHAX_FSA_OpenFile(int fsaFd, const char *path, const char *mode, int *outHandle) {
{ if (iosuhaxHandle < 0)
if(iosuhaxHandle < 0)
return iosuhaxHandle; return iosuhaxHandle;
const int input_cnt = 3; const int input_cnt = 3;
int io_buf_size = sizeof(uint32_t) * input_cnt + strlen(path) + strlen(mode) + 2; int io_buf_size = sizeof(uint32_t) * input_cnt + strlen(path) + strlen(mode) + 2;
uint32_t *io_buf = (uint32_t*)memalign(0x20, io_buf_size); uint32_t *io_buf = (uint32_t *) memalign(0x20, io_buf_size);
if(!io_buf) if (!io_buf)
return -2; return -2;
io_buf[0] = fsaFd; io_buf[0] = fsaFd;
io_buf[1] = sizeof(uint32_t) * input_cnt; io_buf[1] = sizeof(uint32_t) * input_cnt;
io_buf[2] = io_buf[1] + strlen(path) + 1; io_buf[2] = io_buf[1] + strlen(path) + 1;
strcpy(((char*)io_buf) + io_buf[1], path); strcpy(((char *) io_buf) + io_buf[1], path);
strcpy(((char*)io_buf) + io_buf[2], mode); strcpy(((char *) io_buf) + io_buf[2], mode);
int result_vec[2]; int result_vec[2];
int res = IOS_Ioctl(iosuhaxHandle, IOCTL_FSA_OPENFILE, io_buf, io_buf_size, result_vec, sizeof(result_vec)); int res = IOS_Ioctl(iosuhaxHandle, IOCTL_FSA_OPENFILE, io_buf, io_buf_size, result_vec, sizeof(result_vec));
if(res < 0) if (res < 0) {
{
free(io_buf); free(io_buf);
return res; return res;
} }
@ -579,17 +545,16 @@ int IOSUHAX_FSA_OpenFile(int fsaFd, const char* path, const char* mode, int* out
return result_vec[0]; return result_vec[0];
} }
int IOSUHAX_FSA_ReadFile(int fsaFd, void* data, uint32_t size, uint32_t cnt, int fileHandle, uint32_t flags) int IOSUHAX_FSA_ReadFile(int fsaFd, void *data, uint32_t size, uint32_t cnt, int fileHandle, uint32_t flags) {
{ if (iosuhaxHandle < 0)
if(iosuhaxHandle < 0)
return iosuhaxHandle; return iosuhaxHandle;
const int input_cnt = 5; const int input_cnt = 5;
int io_buf_size = sizeof(uint32_t) * input_cnt; int io_buf_size = sizeof(uint32_t) * input_cnt;
uint32_t *io_buf = (uint32_t*)memalign(0x20, io_buf_size); uint32_t *io_buf = (uint32_t *) memalign(0x20, io_buf_size);
if(!io_buf) if (!io_buf)
return -2; return -2;
io_buf[0] = fsaFd; io_buf[0] = fsaFd;
@ -600,23 +565,21 @@ int IOSUHAX_FSA_ReadFile(int fsaFd, void* data, uint32_t size, uint32_t cnt, int
int out_buf_size = ((size * cnt + 0x40) + 0x3F) & ~0x3F; int out_buf_size = ((size * cnt + 0x40) + 0x3F) & ~0x3F;
uint32_t *out_buffer = (uint32_t*)memalign(0x40, out_buf_size); uint32_t *out_buffer = (uint32_t *) memalign(0x40, out_buf_size);
if(!out_buffer) if (!out_buffer) {
{
free(io_buf); free(io_buf);
return -2; return -2;
} }
int res = IOS_Ioctl(iosuhaxHandle, IOCTL_FSA_READFILE, io_buf, io_buf_size, out_buffer, out_buf_size); int res = IOS_Ioctl(iosuhaxHandle, IOCTL_FSA_READFILE, io_buf, io_buf_size, out_buffer, out_buf_size);
if(res < 0) if (res < 0) {
{
free(out_buffer); free(out_buffer);
free(io_buf); free(io_buf);
return res; return res;
} }
//! data is put to offset 0x40 to align the buffer output //! data is put to offset 0x40 to align the buffer output
memcpy(data, ((uint8_t*)out_buffer) + 0x40, size * cnt); memcpy(data, ((uint8_t *) out_buffer) + 0x40, size * cnt);
int result = out_buffer[0]; int result = out_buffer[0];
@ -625,17 +588,16 @@ int IOSUHAX_FSA_ReadFile(int fsaFd, void* data, uint32_t size, uint32_t cnt, int
return result; return result;
} }
int IOSUHAX_FSA_WriteFile(int fsaFd, const void* data, uint32_t size, uint32_t cnt, int fileHandle, uint32_t flags) int IOSUHAX_FSA_WriteFile(int fsaFd, const void *data, uint32_t size, uint32_t cnt, int fileHandle, uint32_t flags) {
{ if (iosuhaxHandle < 0)
if(iosuhaxHandle < 0)
return iosuhaxHandle; return iosuhaxHandle;
const int input_cnt = 5; const int input_cnt = 5;
int io_buf_size = ((sizeof(uint32_t) * input_cnt + size * cnt + 0x40) + 0x3F) & ~0x3F; int io_buf_size = ((sizeof(uint32_t) * input_cnt + size * cnt + 0x40) + 0x3F) & ~0x3F;
uint32_t *io_buf = (uint32_t*)memalign(0x20, io_buf_size); uint32_t *io_buf = (uint32_t *) memalign(0x20, io_buf_size);
if(!io_buf) if (!io_buf)
return -2; return -2;
io_buf[0] = fsaFd; io_buf[0] = fsaFd;
@ -645,12 +607,11 @@ int IOSUHAX_FSA_WriteFile(int fsaFd, const void* data, uint32_t size, uint32_t c
io_buf[4] = flags; io_buf[4] = flags;
//! data is put to offset 0x40 to align the buffer input //! data is put to offset 0x40 to align the buffer input
memcpy(((uint8_t*)io_buf) + 0x40, data, size * cnt); memcpy(((uint8_t *) io_buf) + 0x40, data, size * cnt);
int result; int result;
int res = IOS_Ioctl(iosuhaxHandle, IOCTL_FSA_WRITEFILE, io_buf, io_buf_size, &result, sizeof(result)); int res = IOS_Ioctl(iosuhaxHandle, IOCTL_FSA_WRITEFILE, io_buf, io_buf_size, &result, sizeof(result));
if(res < 0) if (res < 0) {
{
free(io_buf); free(io_buf);
return res; return res;
} }
@ -658,33 +619,30 @@ int IOSUHAX_FSA_WriteFile(int fsaFd, const void* data, uint32_t size, uint32_t c
return result; return result;
} }
int IOSUHAX_FSA_StatFile(int fsaFd, int fileHandle, fileStat_s* out_data) int IOSUHAX_FSA_StatFile(int fsaFd, int fileHandle, fileStat_s *out_data) {
{ if (iosuhaxHandle < 0)
if(iosuhaxHandle < 0)
return iosuhaxHandle; return iosuhaxHandle;
const int input_cnt = 2; const int input_cnt = 2;
int io_buf_size = sizeof(uint32_t) * input_cnt; int io_buf_size = sizeof(uint32_t) * input_cnt;
uint32_t *io_buf = (uint32_t*)memalign(0x20, io_buf_size); uint32_t *io_buf = (uint32_t *) memalign(0x20, io_buf_size);
if(!io_buf) if (!io_buf)
return -2; return -2;
io_buf[0] = fsaFd; io_buf[0] = fsaFd;
io_buf[1] = fileHandle; io_buf[1] = fileHandle;
int out_buf_size = 4 + sizeof(fileStat_s); int out_buf_size = 4 + sizeof(fileStat_s);
uint32_t *out_buffer = (uint32_t*)memalign(0x20, out_buf_size); uint32_t *out_buffer = (uint32_t *) memalign(0x20, out_buf_size);
if(!out_buffer) if (!out_buffer) {
{
free(io_buf); free(io_buf);
return -2; return -2;
} }
int res = IOS_Ioctl(iosuhaxHandle, IOCTL_FSA_STATFILE, io_buf, io_buf_size, out_buffer, out_buf_size); int res = IOS_Ioctl(iosuhaxHandle, IOCTL_FSA_STATFILE, io_buf, io_buf_size, out_buffer, out_buf_size);
if(res < 0) if (res < 0) {
{
free(io_buf); free(io_buf);
free(out_buffer); free(out_buffer);
return res; return res;
@ -698,17 +656,16 @@ int IOSUHAX_FSA_StatFile(int fsaFd, int fileHandle, fileStat_s* out_data)
return result; return result;
} }
int IOSUHAX_FSA_CloseFile(int fsaFd, int fileHandle) int IOSUHAX_FSA_CloseFile(int fsaFd, int fileHandle) {
{ if (iosuhaxHandle < 0)
if(iosuhaxHandle < 0)
return iosuhaxHandle; return iosuhaxHandle;
const int input_cnt = 2; const int input_cnt = 2;
int io_buf_size = sizeof(uint32_t) * input_cnt; int io_buf_size = sizeof(uint32_t) * input_cnt;
uint32_t *io_buf = (uint32_t*)memalign(0x20, io_buf_size); uint32_t *io_buf = (uint32_t *) memalign(0x20, io_buf_size);
if(!io_buf) if (!io_buf)
return -2; return -2;
io_buf[0] = fsaFd; io_buf[0] = fsaFd;
@ -717,8 +674,7 @@ int IOSUHAX_FSA_CloseFile(int fsaFd, int fileHandle)
int result; int result;
int res = IOS_Ioctl(iosuhaxHandle, IOCTL_FSA_CLOSEFILE, io_buf, io_buf_size, &result, sizeof(result)); int res = IOS_Ioctl(iosuhaxHandle, IOCTL_FSA_CLOSEFILE, io_buf, io_buf_size, &result, sizeof(result));
if(res < 0) if (res < 0) {
{
free(io_buf); free(io_buf);
return res; return res;
} }
@ -727,17 +683,16 @@ int IOSUHAX_FSA_CloseFile(int fsaFd, int fileHandle)
return result; return result;
} }
int IOSUHAX_FSA_SetFilePos(int fsaFd, int fileHandle, uint32_t position) int IOSUHAX_FSA_SetFilePos(int fsaFd, int fileHandle, uint32_t position) {
{ if (iosuhaxHandle < 0)
if(iosuhaxHandle < 0)
return iosuhaxHandle; return iosuhaxHandle;
const int input_cnt = 3; const int input_cnt = 3;
int io_buf_size = sizeof(uint32_t) * input_cnt; int io_buf_size = sizeof(uint32_t) * input_cnt;
uint32_t *io_buf = (uint32_t*)memalign(0x20, io_buf_size); uint32_t *io_buf = (uint32_t *) memalign(0x20, io_buf_size);
if(!io_buf) if (!io_buf)
return -2; return -2;
io_buf[0] = fsaFd; io_buf[0] = fsaFd;
@ -747,8 +702,7 @@ int IOSUHAX_FSA_SetFilePos(int fsaFd, int fileHandle, uint32_t position)
int result; int result;
int res = IOS_Ioctl(iosuhaxHandle, IOCTL_FSA_SETFILEPOS, io_buf, io_buf_size, &result, sizeof(result)); int res = IOS_Ioctl(iosuhaxHandle, IOCTL_FSA_SETFILEPOS, io_buf, io_buf_size, &result, sizeof(result));
if(res < 0) if (res < 0) {
{
free(io_buf); free(io_buf);
return res; return res;
} }
@ -757,34 +711,31 @@ int IOSUHAX_FSA_SetFilePos(int fsaFd, int fileHandle, uint32_t position)
return result; return result;
} }
int IOSUHAX_FSA_GetStat(int fsaFd, const char *path, fileStat_s* out_data) int IOSUHAX_FSA_GetStat(int fsaFd, const char *path, fileStat_s *out_data) {
{ if (iosuhaxHandle < 0)
if(iosuhaxHandle < 0)
return iosuhaxHandle; return iosuhaxHandle;
const int input_cnt = 2; const int input_cnt = 2;
int io_buf_size = sizeof(uint32_t) * input_cnt + strlen(path) + 1; int io_buf_size = sizeof(uint32_t) * input_cnt + strlen(path) + 1;
uint32_t *io_buf = (uint32_t*)memalign(0x20, io_buf_size); uint32_t *io_buf = (uint32_t *) memalign(0x20, io_buf_size);
if(!io_buf) if (!io_buf)
return -2; return -2;
io_buf[0] = fsaFd; io_buf[0] = fsaFd;
io_buf[1] = sizeof(uint32_t) * input_cnt; io_buf[1] = sizeof(uint32_t) * input_cnt;
strcpy(((char*)io_buf) + io_buf[1], path); strcpy(((char *) io_buf) + io_buf[1], path);
int out_buf_size = 4 + sizeof(fileStat_s); int out_buf_size = 4 + sizeof(fileStat_s);
uint32_t *out_buffer = (uint32_t*)memalign(0x20, out_buf_size); uint32_t *out_buffer = (uint32_t *) memalign(0x20, out_buf_size);
if(!out_buffer) if (!out_buffer) {
{
free(io_buf); free(io_buf);
return -2; return -2;
} }
int res = IOS_Ioctl(iosuhaxHandle, IOCTL_FSA_GETSTAT, io_buf, io_buf_size, out_buffer, out_buf_size); int res = IOS_Ioctl(iosuhaxHandle, IOCTL_FSA_GETSTAT, io_buf, io_buf_size, out_buffer, out_buf_size);
if(res < 0) if (res < 0) {
{
free(io_buf); free(io_buf);
free(out_buffer); free(out_buffer);
return res; return res;
@ -798,34 +749,32 @@ int IOSUHAX_FSA_GetStat(int fsaFd, const char *path, fileStat_s* out_data)
return result; return result;
} }
int IOSUHAX_FSA_Remove(int fsaFd, const char *path) int IOSUHAX_FSA_Remove(int fsaFd, const char *path) {
{ if (iosuhaxHandle < 0)
if(iosuhaxHandle < 0)
return iosuhaxHandle; return iosuhaxHandle;
const int input_cnt = 2; const int input_cnt = 2;
int io_buf_size = sizeof(uint32_t) * input_cnt + strlen(path) + 1; int io_buf_size = sizeof(uint32_t) * input_cnt + strlen(path) + 1;
uint32_t *io_buf = (uint32_t*)memalign(0x20, ROUNDUP(io_buf_size, 0x20)); uint32_t *io_buf = (uint32_t *) memalign(0x20, ROUNDUP(io_buf_size, 0x20));
if(!io_buf) if (!io_buf)
return -2; return -2;
io_buf[0] = fsaFd; io_buf[0] = fsaFd;
io_buf[1] = sizeof(uint32_t) * input_cnt; io_buf[1] = sizeof(uint32_t) * input_cnt;
strcpy(((char*)io_buf) + io_buf[1], path); strcpy(((char *) io_buf) + io_buf[1], path);
int res = IOS_Ioctl(iosuhaxHandle, IOCTL_FSA_REMOVE, io_buf, io_buf_size, io_buf, 4); int res = IOS_Ioctl(iosuhaxHandle, IOCTL_FSA_REMOVE, io_buf, io_buf_size, io_buf, 4);
if(res >= 0) if (res >= 0)
res = io_buf[0]; res = io_buf[0];
free(io_buf); free(io_buf);
return res; return res;
} }
int IOSUHAX_FSA_ChangeMode(int fsaFd, const char* path, int mode) int IOSUHAX_FSA_ChangeMode(int fsaFd, const char *path, int mode) {
{ if (iosuhaxHandle < 0)
if(iosuhaxHandle < 0)
return iosuhaxHandle; return iosuhaxHandle;
const int input_cnt = 3; const int input_cnt = 3;
@ -837,18 +786,17 @@ int IOSUHAX_FSA_ChangeMode(int fsaFd, const char* path, int mode)
io_buf[0] = fsaFd; io_buf[0] = fsaFd;
io_buf[1] = sizeof(uint32_t) * input_cnt; io_buf[1] = sizeof(uint32_t) * input_cnt;
io_buf[2] = mode; io_buf[2] = mode;
strcpy(((char*)io_buf) + io_buf[1], path); strcpy(((char *) io_buf) + io_buf[1], path);
int res = IOS_Ioctl(iosuhaxHandle, IOCTL_FSA_CHANGEMODE, io_buf, io_buf_size, io_buf, 4); int res = IOS_Ioctl(iosuhaxHandle, IOCTL_FSA_CHANGEMODE, io_buf, io_buf_size, io_buf, 4);
if(res < 0) if (res < 0)
return res; return res;
return io_buf[0]; return io_buf[0];
} }
int IOSUHAX_FSA_RawOpen(int fsaFd, const char* device_path, int* outHandle) int IOSUHAX_FSA_RawOpen(int fsaFd, const char *device_path, int *outHandle) {
{ if (iosuhaxHandle < 0)
if(iosuhaxHandle < 0)
return iosuhaxHandle; return iosuhaxHandle;
const int input_cnt = 2; const int input_cnt = 2;
@ -859,29 +807,28 @@ int IOSUHAX_FSA_RawOpen(int fsaFd, const char* device_path, int* outHandle)
io_buf[0] = fsaFd; io_buf[0] = fsaFd;
io_buf[1] = sizeof(uint32_t) * input_cnt; io_buf[1] = sizeof(uint32_t) * input_cnt;
strcpy(((char*)io_buf) + io_buf[1], device_path); strcpy(((char *) io_buf) + io_buf[1], device_path);
int res = IOS_Ioctl(iosuhaxHandle, IOCTL_FSA_RAW_OPEN, io_buf, io_buf_size, io_buf, 2 * sizeof(int)); int res = IOS_Ioctl(iosuhaxHandle, IOCTL_FSA_RAW_OPEN, io_buf, io_buf_size, io_buf, 2 * sizeof(int));
if(res < 0) if (res < 0)
return res; return res;
if(outHandle) if (outHandle)
*outHandle = io_buf[1]; *outHandle = io_buf[1];
return io_buf[0]; return io_buf[0];
} }
int IOSUHAX_FSA_RawRead(int fsaFd, void* data, uint32_t block_size, uint32_t block_cnt, uint64_t sector_offset, int device_handle) int IOSUHAX_FSA_RawRead(int fsaFd, void *data, uint32_t block_size, uint32_t block_cnt, uint64_t sector_offset, int device_handle) {
{ if (iosuhaxHandle < 0)
if(iosuhaxHandle < 0)
return iosuhaxHandle; return iosuhaxHandle;
const int input_cnt = 6; const int input_cnt = 6;
int io_buf_size = 0x40 + block_size * block_cnt; int io_buf_size = 0x40 + block_size * block_cnt;
uint32_t *io_buf = (uint32_t*)memalign(0x40, ROUNDUP(io_buf_size, 0x40)); uint32_t *io_buf = (uint32_t *) memalign(0x40, ROUNDUP(io_buf_size, 0x40));
if(!io_buf) if (!io_buf)
return -2; return -2;
io_buf[0] = fsaFd; io_buf[0] = fsaFd;
@ -892,10 +839,9 @@ int IOSUHAX_FSA_RawRead(int fsaFd, void* data, uint32_t block_size, uint32_t blo
io_buf[5] = device_handle; io_buf[5] = device_handle;
int res = IOS_Ioctl(iosuhaxHandle, IOCTL_FSA_RAW_READ, io_buf, sizeof(uint32_t) * input_cnt, io_buf, io_buf_size); int res = IOS_Ioctl(iosuhaxHandle, IOCTL_FSA_RAW_READ, io_buf, sizeof(uint32_t) * input_cnt, io_buf, io_buf_size);
if(res >= 0) if (res >= 0) {
{
//! data is put to offset 0x40 to align the buffer output //! data is put to offset 0x40 to align the buffer output
memcpy(data, ((uint8_t*)io_buf) + 0x40, block_size * block_cnt); memcpy(data, ((uint8_t *) io_buf) + 0x40, block_size * block_cnt);
res = io_buf[0]; res = io_buf[0];
} }
@ -904,15 +850,14 @@ int IOSUHAX_FSA_RawRead(int fsaFd, void* data, uint32_t block_size, uint32_t blo
return res; return res;
} }
int IOSUHAX_FSA_RawWrite(int fsaFd, const void* data, uint32_t block_size, uint32_t block_cnt, uint64_t sector_offset, int device_handle) int IOSUHAX_FSA_RawWrite(int fsaFd, const void *data, uint32_t block_size, uint32_t block_cnt, uint64_t sector_offset, int device_handle) {
{ if (iosuhaxHandle < 0)
if(iosuhaxHandle < 0)
return iosuhaxHandle; return iosuhaxHandle;
int io_buf_size = ROUNDUP(0x40 + block_size * block_cnt, 0x40); int io_buf_size = ROUNDUP(0x40 + block_size * block_cnt, 0x40);
uint32_t *io_buf = (uint32_t*)memalign(0x40, io_buf_size); uint32_t *io_buf = (uint32_t *) memalign(0x40, io_buf_size);
if(!io_buf) if (!io_buf)
return -2; return -2;
io_buf[0] = fsaFd; io_buf[0] = fsaFd;
@ -923,20 +868,19 @@ int IOSUHAX_FSA_RawWrite(int fsaFd, const void* data, uint32_t block_size, uint3
io_buf[5] = device_handle; io_buf[5] = device_handle;
//! data is put to offset 0x40 to align the buffer input //! data is put to offset 0x40 to align the buffer input
memcpy(((uint8_t*)io_buf) + 0x40, data, block_size * block_cnt); memcpy(((uint8_t *) io_buf) + 0x40, data, block_size * block_cnt);
int res = IOS_Ioctl(iosuhaxHandle, IOCTL_FSA_RAW_WRITE, io_buf, io_buf_size, io_buf, 4); int res = IOS_Ioctl(iosuhaxHandle, IOCTL_FSA_RAW_WRITE, io_buf, io_buf_size, io_buf, 4);
if(res >= 0) if (res >= 0)
res = io_buf[0]; res = io_buf[0];
free(io_buf); free(io_buf);
return res; return res;
} }
int IOSUHAX_FSA_RawClose(int fsaFd, int device_handle) int IOSUHAX_FSA_RawClose(int fsaFd, int device_handle) {
{ if (iosuhaxHandle < 0)
if(iosuhaxHandle < 0)
return iosuhaxHandle; return iosuhaxHandle;
const int input_cnt = 2; const int input_cnt = 2;
@ -949,8 +893,8 @@ int IOSUHAX_FSA_RawClose(int fsaFd, int device_handle)
io_buf[1] = device_handle; io_buf[1] = device_handle;
int res = IOS_Ioctl(iosuhaxHandle, IOCTL_FSA_RAW_CLOSE, io_buf, io_buf_size, io_buf, 4); int res = IOS_Ioctl(iosuhaxHandle, IOCTL_FSA_RAW_CLOSE, io_buf, io_buf_size, io_buf, 4);
if(res < 0) if (res < 0)
return res; return res;
return io_buf[0]; return io_buf[0];
} }

View File

@ -59,8 +59,7 @@ typedef struct _fs_dev_dir_entry_t {
int dirHandle; int dirHandle;
} fs_dev_dir_entry_t; } fs_dev_dir_entry_t;
static fs_dev_private_t *fs_dev_get_device_data(const char *path) static fs_dev_private_t *fs_dev_get_device_data(const char *path) {
{
const devoptab_t *devoptab = NULL; const devoptab_t *devoptab = NULL;
char name[128] = {0}; char name[128] = {0};
int i; int i;
@ -77,7 +76,7 @@ static fs_dev_private_t *fs_dev_get_device_data(const char *path)
devoptab = devoptab_list[i]; devoptab = devoptab_list[i];
if (devoptab && devoptab->name) { if (devoptab && devoptab->name) {
if (strcmp(name, devoptab->name) == 0) { if (strcmp(name, devoptab->name) == 0) {
return (fs_dev_private_t *)devoptab->deviceData; return (fs_dev_private_t *) devoptab->deviceData;
} }
} }
} }
@ -85,8 +84,7 @@ static fs_dev_private_t *fs_dev_get_device_data(const char *path)
return NULL; return NULL;
} }
static char *fs_dev_real_path (const char *path, fs_dev_private_t *dev) static char *fs_dev_real_path(const char *path, fs_dev_private_t *dev) {
{
// Sanity check // Sanity check
if (!path) if (!path)
return NULL; return NULL;
@ -98,8 +96,8 @@ static char *fs_dev_real_path (const char *path, fs_dev_private_t *dev)
int mount_len = strlen(dev->mount_path); int mount_len = strlen(dev->mount_path);
char *new_name = (char*)malloc(mount_len + strlen(path) + 1); char *new_name = (char *) malloc(mount_len + strlen(path) + 1);
if(new_name) { if (new_name) {
strcpy(new_name, dev->mount_path); strcpy(new_name, dev->mount_path);
strcpy(new_name + mount_len, path); strcpy(new_name + mount_len, path);
return new_name; return new_name;
@ -107,15 +105,14 @@ static char *fs_dev_real_path (const char *path, fs_dev_private_t *dev)
return new_name; return new_name;
} }
static int fs_dev_open_r (struct _reent *r, void *fileStruct, const char *path, int flags, int mode) static int fs_dev_open_r(struct _reent *r, void *fileStruct, const char *path, int flags, int mode) {
{
fs_dev_private_t *dev = fs_dev_get_device_data(path); fs_dev_private_t *dev = fs_dev_get_device_data(path);
if(!dev) { if (!dev) {
r->_errno = ENODEV; r->_errno = ENODEV;
return -1; return -1;
} }
fs_dev_file_state_t *file = (fs_dev_file_state_t *)fileStruct; fs_dev_file_state_t *file = (fs_dev_file_state_t *) fileStruct;
file->dev = dev; file->dev = dev;
// Determine which mode the file is opened for // Determine which mode the file is opened for
@ -139,17 +136,17 @@ static int fs_dev_open_r (struct _reent *r, void *fileStruct, const char *path,
file->write = 1; file->write = 1;
file->append = 0; file->append = 0;
fsMode = "w"; fsMode = "w";
} else if(flags == 0x602) { } else if (flags == 0x602) {
file->read = 1; file->read = 1;
file->write = 1; file->write = 1;
file->append = 0; file->append = 0;
fsMode = "w+"; fsMode = "w+";
} else if(flags == 0x209) { } else if (flags == 0x209) {
file->read = 0; file->read = 0;
file->write = 1; file->write = 1;
file->append = 1; file->append = 1;
fsMode = "a"; fsMode = "a";
} else if(flags == 0x20A) { } else if (flags == 0x20A) {
file->read = 1; file->read = 1;
file->write = 1; file->write = 1;
file->append = 1; file->append = 1;
@ -165,7 +162,7 @@ static int fs_dev_open_r (struct _reent *r, void *fileStruct, const char *path,
OSLockMutex(dev->pMutex); OSLockMutex(dev->pMutex);
char *real_path = fs_dev_real_path(path, dev); char *real_path = fs_dev_real_path(path, dev);
if(!path) { if (!path) {
r->_errno = ENOMEM; r->_errno = ENOMEM;
OSUnlockMutex(dev->pMutex); OSUnlockMutex(dev->pMutex);
return -1; return -1;
@ -175,11 +172,10 @@ static int fs_dev_open_r (struct _reent *r, void *fileStruct, const char *path,
free(real_path); free(real_path);
if(result == 0) if (result == 0) {
{
fileStat_s stats; fileStat_s stats;
result = IOSUHAX_FSA_StatFile(dev->fsaFd, fd, &stats); result = IOSUHAX_FSA_StatFile(dev->fsaFd, fd, &stats);
if(result != 0) { if (result != 0) {
IOSUHAX_FSA_CloseFile(dev->fsaFd, fd); IOSUHAX_FSA_CloseFile(dev->fsaFd, fd);
r->_errno = result; r->_errno = result;
OSUnlockMutex(dev->pMutex); OSUnlockMutex(dev->pMutex);
@ -189,7 +185,7 @@ static int fs_dev_open_r (struct _reent *r, void *fileStruct, const char *path,
file->pos = 0; file->pos = 0;
file->len = stats.size; file->len = stats.size;
OSUnlockMutex(dev->pMutex); OSUnlockMutex(dev->pMutex);
return (int)file; return (int) file;
} }
r->_errno = result; r->_errno = result;
@ -198,10 +194,9 @@ static int fs_dev_open_r (struct _reent *r, void *fileStruct, const char *path,
} }
static int fs_dev_close_r (struct _reent *r, void *fd) static int fs_dev_close_r(struct _reent *r, void *fd) {
{ fs_dev_file_state_t *file = (fs_dev_file_state_t *) fd;
fs_dev_file_state_t *file = (fs_dev_file_state_t *)fd; if (!file->dev) {
if(!file->dev) {
r->_errno = ENODEV; r->_errno = ENODEV;
return -1; return -1;
} }
@ -212,62 +207,56 @@ static int fs_dev_close_r (struct _reent *r, void *fd)
OSUnlockMutex(file->dev->pMutex); OSUnlockMutex(file->dev->pMutex);
if(result < 0) if (result < 0) {
{
r->_errno = result; r->_errno = result;
return -1; return -1;
} }
return 0; return 0;
} }
static off_t fs_dev_seek_r (struct _reent *r, void *fd, off_t pos, int dir) static off_t fs_dev_seek_r(struct _reent *r, void *fd, off_t pos, int dir) {
{ fs_dev_file_state_t *file = (fs_dev_file_state_t *) fd;
fs_dev_file_state_t *file = (fs_dev_file_state_t *)fd; if (!file->dev) {
if(!file->dev) {
r->_errno = ENODEV; r->_errno = ENODEV;
return 0; return 0;
} }
OSLockMutex(file->dev->pMutex); OSLockMutex(file->dev->pMutex);
switch(dir) switch (dir) {
{ case SEEK_SET:
case SEEK_SET: file->pos = pos;
file->pos = pos; break;
break; case SEEK_CUR:
case SEEK_CUR: file->pos += pos;
file->pos += pos; break;
break; case SEEK_END:
case SEEK_END: file->pos = file->len + pos;
file->pos = file->len + pos; break;
break; default:
default: r->_errno = EINVAL;
r->_errno = EINVAL; return -1;
return -1;
} }
int result = IOSUHAX_FSA_SetFilePos(file->dev->fsaFd, file->fd, file->pos); int result = IOSUHAX_FSA_SetFilePos(file->dev->fsaFd, file->fd, file->pos);
OSUnlockMutex(file->dev->pMutex); OSUnlockMutex(file->dev->pMutex);
if(result == 0) if (result == 0) {
{
return file->pos; return file->pos;
} }
return result; return result;
} }
static ssize_t fs_dev_write_r (struct _reent *r, void *fd, const char *ptr, size_t len) static ssize_t fs_dev_write_r(struct _reent *r, void *fd, const char *ptr, size_t len) {
{ fs_dev_file_state_t *file = (fs_dev_file_state_t *) fd;
fs_dev_file_state_t *file = (fs_dev_file_state_t *)fd; if (!file->dev) {
if(!file->dev) {
r->_errno = ENODEV; r->_errno = ENODEV;
return 0; return 0;
} }
if(!file->write) if (!file->write) {
{
r->_errno = EACCES; r->_errno = EACCES;
return 0; return 0;
} }
@ -276,24 +265,18 @@ static ssize_t fs_dev_write_r (struct _reent *r, void *fd, const char *ptr, size
size_t done = 0; size_t done = 0;
while(done < len) while (done < len) {
{
size_t write_size = len - done; size_t write_size = len - done;
int result = IOSUHAX_FSA_WriteFile(file->dev->fsaFd, ptr + done, 0x01, write_size, file->fd, 0); int result = IOSUHAX_FSA_WriteFile(file->dev->fsaFd, ptr + done, 0x01, write_size, file->fd, 0);
if(result < 0) if (result < 0) {
{
r->_errno = result; r->_errno = result;
break; break;
} } else if (result == 0) {
else if(result == 0) if (write_size > 0)
{
if(write_size > 0)
done = 0; done = 0;
break; break;
} } else {
else
{
done += result; done += result;
file->pos += result; file->pos += result;
} }
@ -303,16 +286,14 @@ static ssize_t fs_dev_write_r (struct _reent *r, void *fd, const char *ptr, size
return done; return done;
} }
static ssize_t fs_dev_read_r (struct _reent *r, void *fd, char *ptr, size_t len) static ssize_t fs_dev_read_r(struct _reent *r, void *fd, char *ptr, size_t len) {
{ fs_dev_file_state_t *file = (fs_dev_file_state_t *) fd;
fs_dev_file_state_t *file = (fs_dev_file_state_t *)fd; if (!file->dev) {
if(!file->dev) {
r->_errno = ENODEV; r->_errno = ENODEV;
return 0; return 0;
} }
if(!file->read) if (!file->read) {
{
r->_errno = EACCES; r->_errno = EACCES;
return 0; return 0;
} }
@ -321,24 +302,18 @@ static ssize_t fs_dev_read_r (struct _reent *r, void *fd, char *ptr, size_t len)
size_t done = 0; size_t done = 0;
while(done < len) while (done < len) {
{
size_t read_size = len - done; size_t read_size = len - done;
int result = IOSUHAX_FSA_ReadFile(file->dev->fsaFd, ptr + done, 0x01, read_size, file->fd, 0); int result = IOSUHAX_FSA_ReadFile(file->dev->fsaFd, ptr + done, 0x01, read_size, file->fd, 0);
if(result < 0) if (result < 0) {
{
r->_errno = result; r->_errno = result;
done = 0; done = 0;
break; break;
} } else if (result == 0) {
else if(result == 0)
{
//! TODO: error on read_size > 0 //! TODO: error on read_size > 0
break; break;
} } else {
else
{
done += result; done += result;
file->pos += result; file->pos += result;
} }
@ -349,10 +324,9 @@ static ssize_t fs_dev_read_r (struct _reent *r, void *fd, char *ptr, size_t len)
} }
static int fs_dev_fstat_r (struct _reent *r, void *fd, struct stat *st) static int fs_dev_fstat_r(struct _reent *r, void *fd, struct stat *st) {
{ fs_dev_file_state_t *file = (fs_dev_file_state_t *) fd;
fs_dev_file_state_t *file = (fs_dev_file_state_t *)fd; if (!file->dev) {
if(!file->dev) {
r->_errno = ENODEV; r->_errno = ENODEV;
return -1; return -1;
} }
@ -363,8 +337,8 @@ static int fs_dev_fstat_r (struct _reent *r, void *fd, struct stat *st)
memset(st, 0, sizeof(struct stat)); memset(st, 0, sizeof(struct stat));
fileStat_s stats; fileStat_s stats;
int result = IOSUHAX_FSA_StatFile(file->dev->fsaFd, (int)fd, &stats); int result = IOSUHAX_FSA_StatFile(file->dev->fsaFd, (int) fd, &stats);
if(result != 0) { if (result != 0) {
r->_errno = result; r->_errno = result;
OSUnlockMutex(file->dev->pMutex); OSUnlockMutex(file->dev->pMutex);
return -1; return -1;
@ -387,10 +361,9 @@ static int fs_dev_fstat_r (struct _reent *r, void *fd, struct stat *st)
return 0; return 0;
} }
static int fs_dev_ftruncate_r (struct _reent *r, void *fd, off_t len) static int fs_dev_ftruncate_r(struct _reent *r, void *fd, off_t len) {
{ fs_dev_file_state_t *file = (fs_dev_file_state_t *) fd;
fs_dev_file_state_t *file = (fs_dev_file_state_t *)fd; if (!file->dev) {
if(!file->dev) {
r->_errno = ENODEV; r->_errno = ENODEV;
return -1; return -1;
} }
@ -400,10 +373,9 @@ static int fs_dev_ftruncate_r (struct _reent *r, void *fd, off_t len)
return -1; return -1;
} }
static int fs_dev_fsync_r (struct _reent *r, void *fd) static int fs_dev_fsync_r(struct _reent *r, void *fd) {
{ fs_dev_file_state_t *file = (fs_dev_file_state_t *) fd;
fs_dev_file_state_t *file = (fs_dev_file_state_t *)fd; if (!file->dev) {
if(!file->dev) {
r->_errno = ENODEV; r->_errno = ENODEV;
return -1; return -1;
} }
@ -413,10 +385,9 @@ static int fs_dev_fsync_r (struct _reent *r, void *fd)
return -1; return -1;
} }
static int fs_dev_stat_r (struct _reent *r, const char *path, struct stat *st) static int fs_dev_stat_r(struct _reent *r, const char *path, struct stat *st) {
{
fs_dev_private_t *dev = fs_dev_get_device_data(path); fs_dev_private_t *dev = fs_dev_get_device_data(path);
if(!dev) { if (!dev) {
r->_errno = ENODEV; r->_errno = ENODEV;
return -1; return -1;
} }
@ -427,7 +398,7 @@ static int fs_dev_stat_r (struct _reent *r, const char *path, struct stat *st)
memset(st, 0, sizeof(struct stat)); memset(st, 0, sizeof(struct stat));
char *real_path = fs_dev_real_path(path, dev); char *real_path = fs_dev_real_path(path, dev);
if(!real_path) { if (!real_path) {
r->_errno = ENOMEM; r->_errno = ENOMEM;
OSUnlockMutex(dev->pMutex); OSUnlockMutex(dev->pMutex);
return -1; return -1;
@ -439,14 +410,14 @@ static int fs_dev_stat_r (struct _reent *r, const char *path, struct stat *st)
free(real_path); free(real_path);
if(result < 0) { if (result < 0) {
r->_errno = result; r->_errno = result;
OSUnlockMutex(dev->pMutex); OSUnlockMutex(dev->pMutex);
return -1; return -1;
} }
// mark root also as directory // mark root also as directory
st->st_mode = ((stats.flag & 0x80000000) || (strlen(dev->mount_path) + 1 == strlen(real_path)))? S_IFDIR : S_IFREG; st->st_mode = ((stats.flag & 0x80000000) || (strlen(dev->mount_path) + 1 == strlen(real_path))) ? S_IFDIR : S_IFREG;
st->st_nlink = 1; st->st_nlink = 1;
st->st_size = stats.size; st->st_size = stats.size;
st->st_blocks = (stats.size + 511) >> 9; st->st_blocks = (stats.size + 511) >> 9;
@ -464,16 +435,14 @@ static int fs_dev_stat_r (struct _reent *r, const char *path, struct stat *st)
return 0; return 0;
} }
static int fs_dev_link_r (struct _reent *r, const char *existing, const char *newLink) static int fs_dev_link_r(struct _reent *r, const char *existing, const char *newLink) {
{
r->_errno = ENOTSUP; r->_errno = ENOTSUP;
return -1; return -1;
} }
static int fs_dev_unlink_r (struct _reent *r, const char *name) static int fs_dev_unlink_r(struct _reent *r, const char *name) {
{
fs_dev_private_t *dev = fs_dev_get_device_data(name); fs_dev_private_t *dev = fs_dev_get_device_data(name);
if(!dev) { if (!dev) {
r->_errno = ENODEV; r->_errno = ENODEV;
return -1; return -1;
} }
@ -481,7 +450,7 @@ static int fs_dev_unlink_r (struct _reent *r, const char *name)
OSLockMutex(dev->pMutex); OSLockMutex(dev->pMutex);
char *real_path = fs_dev_real_path(name, dev); char *real_path = fs_dev_real_path(name, dev);
if(!real_path) { if (!real_path) {
r->_errno = ENOMEM; r->_errno = ENOMEM;
OSUnlockMutex(dev->pMutex); OSUnlockMutex(dev->pMutex);
return -1; return -1;
@ -493,7 +462,7 @@ static int fs_dev_unlink_r (struct _reent *r, const char *name)
OSUnlockMutex(dev->pMutex); OSUnlockMutex(dev->pMutex);
if(result < 0) { if (result < 0) {
r->_errno = result; r->_errno = result;
return -1; return -1;
} }
@ -501,10 +470,9 @@ static int fs_dev_unlink_r (struct _reent *r, const char *name)
return result; return result;
} }
static int fs_dev_chdir_r (struct _reent *r, const char *name) static int fs_dev_chdir_r(struct _reent *r, const char *name) {
{
fs_dev_private_t *dev = fs_dev_get_device_data(name); fs_dev_private_t *dev = fs_dev_get_device_data(name);
if(!dev) { if (!dev) {
r->_errno = ENODEV; r->_errno = ENODEV;
return -1; return -1;
} }
@ -512,7 +480,7 @@ static int fs_dev_chdir_r (struct _reent *r, const char *name)
OSLockMutex(dev->pMutex); OSLockMutex(dev->pMutex);
char *real_path = fs_dev_real_path(name, dev); char *real_path = fs_dev_real_path(name, dev);
if(!real_path) { if (!real_path) {
r->_errno = ENOMEM; r->_errno = ENOMEM;
OSUnlockMutex(dev->pMutex); OSUnlockMutex(dev->pMutex);
return -1; return -1;
@ -524,7 +492,7 @@ static int fs_dev_chdir_r (struct _reent *r, const char *name)
OSUnlockMutex(dev->pMutex); OSUnlockMutex(dev->pMutex);
if(result < 0) { if (result < 0) {
r->_errno = result; r->_errno = result;
return -1; return -1;
} }
@ -532,10 +500,9 @@ static int fs_dev_chdir_r (struct _reent *r, const char *name)
return 0; return 0;
} }
static int fs_dev_rename_r (struct _reent *r, const char *oldName, const char *newName) static int fs_dev_rename_r(struct _reent *r, const char *oldName, const char *newName) {
{
fs_dev_private_t *dev = fs_dev_get_device_data(oldName); fs_dev_private_t *dev = fs_dev_get_device_data(oldName);
if(!dev) { if (!dev) {
r->_errno = ENODEV; r->_errno = ENODEV;
return -1; return -1;
} }
@ -543,13 +510,13 @@ static int fs_dev_rename_r (struct _reent *r, const char *oldName, const char *n
OSLockMutex(dev->pMutex); OSLockMutex(dev->pMutex);
char *real_oldpath = fs_dev_real_path(oldName, dev); char *real_oldpath = fs_dev_real_path(oldName, dev);
if(!real_oldpath) { if (!real_oldpath) {
r->_errno = ENOMEM; r->_errno = ENOMEM;
OSUnlockMutex(dev->pMutex); OSUnlockMutex(dev->pMutex);
return -1; return -1;
} }
char *real_newpath = fs_dev_real_path(newName, dev); char *real_newpath = fs_dev_real_path(newName, dev);
if(!real_newpath) { if (!real_newpath) {
r->_errno = ENOMEM; r->_errno = ENOMEM;
free(real_oldpath); free(real_oldpath);
OSUnlockMutex(dev->pMutex); OSUnlockMutex(dev->pMutex);
@ -564,7 +531,7 @@ static int fs_dev_rename_r (struct _reent *r, const char *oldName, const char *n
OSUnlockMutex(dev->pMutex); OSUnlockMutex(dev->pMutex);
if(result < 0) { if (result < 0) {
r->_errno = result; r->_errno = result;
return -1; return -1;
} }
@ -573,10 +540,9 @@ static int fs_dev_rename_r (struct _reent *r, const char *oldName, const char *n
} }
static int fs_dev_mkdir_r (struct _reent *r, const char *path, int mode) static int fs_dev_mkdir_r(struct _reent *r, const char *path, int mode) {
{
fs_dev_private_t *dev = fs_dev_get_device_data(path); fs_dev_private_t *dev = fs_dev_get_device_data(path);
if(!dev) { if (!dev) {
r->_errno = ENODEV; r->_errno = ENODEV;
return -1; return -1;
} }
@ -584,7 +550,7 @@ static int fs_dev_mkdir_r (struct _reent *r, const char *path, int mode)
OSLockMutex(dev->pMutex); OSLockMutex(dev->pMutex);
char *real_path = fs_dev_real_path(path, dev); char *real_path = fs_dev_real_path(path, dev);
if(!real_path) { if (!real_path) {
r->_errno = ENOMEM; r->_errno = ENOMEM;
OSUnlockMutex(dev->pMutex); OSUnlockMutex(dev->pMutex);
return -1; return -1;
@ -596,7 +562,7 @@ static int fs_dev_mkdir_r (struct _reent *r, const char *path, int mode)
OSUnlockMutex(dev->pMutex); OSUnlockMutex(dev->pMutex);
if(result < 0) { if (result < 0) {
r->_errno = result; r->_errno = result;
return -1; return -1;
} }
@ -604,10 +570,9 @@ static int fs_dev_mkdir_r (struct _reent *r, const char *path, int mode)
return 0; return 0;
} }
static int fs_dev_chmod_r (struct _reent *r, const char *path, int mode) static int fs_dev_chmod_r(struct _reent *r, const char *path, int mode) {
{
fs_dev_private_t *dev = fs_dev_get_device_data(path); fs_dev_private_t *dev = fs_dev_get_device_data(path);
if(!dev) { if (!dev) {
r->_errno = ENODEV; r->_errno = ENODEV;
return -1; return -1;
} }
@ -615,7 +580,7 @@ static int fs_dev_chmod_r (struct _reent *r, const char *path, int mode)
OSLockMutex(dev->pMutex); OSLockMutex(dev->pMutex);
char *real_path = fs_dev_real_path(path, dev); char *real_path = fs_dev_real_path(path, dev);
if(!real_path) { if (!real_path) {
r->_errno = ENOMEM; r->_errno = ENOMEM;
OSUnlockMutex(dev->pMutex); OSUnlockMutex(dev->pMutex);
return -1; return -1;
@ -627,7 +592,7 @@ static int fs_dev_chmod_r (struct _reent *r, const char *path, int mode)
OSUnlockMutex(dev->pMutex); OSUnlockMutex(dev->pMutex);
if(result < 0) { if (result < 0) {
r->_errno = result; r->_errno = result;
return -1; return -1;
} }
@ -635,10 +600,9 @@ static int fs_dev_chmod_r (struct _reent *r, const char *path, int mode)
return 0; return 0;
} }
static int fs_dev_statvfs_r (struct _reent *r, const char *path, struct statvfs *buf) static int fs_dev_statvfs_r(struct _reent *r, const char *path, struct statvfs *buf) {
{
fs_dev_private_t *dev = fs_dev_get_device_data(path); fs_dev_private_t *dev = fs_dev_get_device_data(path);
if(!dev) { if (!dev) {
r->_errno = ENODEV; r->_errno = ENODEV;
return -1; return -1;
} }
@ -649,7 +613,7 @@ static int fs_dev_statvfs_r (struct _reent *r, const char *path, struct statvfs
memset(buf, 0, sizeof(struct statvfs)); memset(buf, 0, sizeof(struct statvfs));
char *real_path = fs_dev_real_path(path, dev); char *real_path = fs_dev_real_path(path, dev);
if(!real_path) { if (!real_path) {
r->_errno = ENOMEM; r->_errno = ENOMEM;
OSUnlockMutex(dev->pMutex); OSUnlockMutex(dev->pMutex);
return -1; return -1;
@ -657,11 +621,11 @@ static int fs_dev_statvfs_r (struct _reent *r, const char *path, struct statvfs
uint64_t size; uint64_t size;
int result = IOSUHAX_FSA_GetDeviceInfo(dev->fsaFd, real_path, 0x00, (uint32_t*)&size); int result = IOSUHAX_FSA_GetDeviceInfo(dev->fsaFd, real_path, 0x00, (uint32_t *) &size);
free(real_path); free(real_path);
if(result < 0) { if (result < 0) {
r->_errno = result; r->_errno = result;
OSUnlockMutex(dev->pMutex); OSUnlockMutex(dev->pMutex);
return -1; return -1;
@ -686,7 +650,7 @@ static int fs_dev_statvfs_r (struct _reent *r, const char *path, struct statvfs
buf->f_ffree = 0xffffffff; buf->f_ffree = 0xffffffff;
// File system id // File system id
buf->f_fsid = (int)dev; buf->f_fsid = (int) dev;
// Bit mask of f_flag values. // Bit mask of f_flag values.
buf->f_flag = 0; buf->f_flag = 0;
@ -699,20 +663,19 @@ static int fs_dev_statvfs_r (struct _reent *r, const char *path, struct statvfs
return 0; return 0;
} }
static DIR_ITER *fs_dev_diropen_r (struct _reent *r, DIR_ITER *dirState, const char *path) static DIR_ITER *fs_dev_diropen_r(struct _reent *r, DIR_ITER *dirState, const char *path) {
{
fs_dev_private_t *dev = fs_dev_get_device_data(path); fs_dev_private_t *dev = fs_dev_get_device_data(path);
if(!dev) { if (!dev) {
r->_errno = ENODEV; r->_errno = ENODEV;
return NULL; return NULL;
} }
fs_dev_dir_entry_t *dirIter = (fs_dev_dir_entry_t *)dirState->dirStruct; fs_dev_dir_entry_t *dirIter = (fs_dev_dir_entry_t *) dirState->dirStruct;
OSLockMutex(dev->pMutex); OSLockMutex(dev->pMutex);
char *real_path = fs_dev_real_path(path, dev); char *real_path = fs_dev_real_path(path, dev);
if(!real_path) { if (!real_path) {
r->_errno = ENOMEM; r->_errno = ENOMEM;
OSUnlockMutex(dev->pMutex); OSUnlockMutex(dev->pMutex);
return NULL; return NULL;
@ -726,8 +689,7 @@ static DIR_ITER *fs_dev_diropen_r (struct _reent *r, DIR_ITER *dirState, const c
OSUnlockMutex(dev->pMutex); OSUnlockMutex(dev->pMutex);
if(result < 0) if (result < 0) {
{
r->_errno = result; r->_errno = result;
return NULL; return NULL;
} }
@ -738,10 +700,9 @@ static DIR_ITER *fs_dev_diropen_r (struct _reent *r, DIR_ITER *dirState, const c
return dirState; return dirState;
} }
static int fs_dev_dirclose_r (struct _reent *r, DIR_ITER *dirState) static int fs_dev_dirclose_r(struct _reent *r, DIR_ITER *dirState) {
{ fs_dev_dir_entry_t *dirIter = (fs_dev_dir_entry_t *) dirState->dirStruct;
fs_dev_dir_entry_t *dirIter = (fs_dev_dir_entry_t *)dirState->dirStruct; if (!dirIter->dev) {
if(!dirIter->dev) {
r->_errno = ENODEV; r->_errno = ENODEV;
return -1; return -1;
} }
@ -752,18 +713,16 @@ static int fs_dev_dirclose_r (struct _reent *r, DIR_ITER *dirState)
OSUnlockMutex(dirIter->dev->pMutex); OSUnlockMutex(dirIter->dev->pMutex);
if(result < 0) if (result < 0) {
{
r->_errno = result; r->_errno = result;
return -1; return -1;
} }
return 0; return 0;
} }
static int fs_dev_dirreset_r (struct _reent *r, DIR_ITER *dirState) static int fs_dev_dirreset_r(struct _reent *r, DIR_ITER *dirState) {
{ fs_dev_dir_entry_t *dirIter = (fs_dev_dir_entry_t *) dirState->dirStruct;
fs_dev_dir_entry_t *dirIter = (fs_dev_dir_entry_t *)dirState->dirStruct; if (!dirIter->dev) {
if(!dirIter->dev) {
r->_errno = ENODEV; r->_errno = ENODEV;
return -1; return -1;
} }
@ -774,29 +733,26 @@ static int fs_dev_dirreset_r (struct _reent *r, DIR_ITER *dirState)
OSUnlockMutex(dirIter->dev->pMutex); OSUnlockMutex(dirIter->dev->pMutex);
if(result < 0) if (result < 0) {
{
r->_errno = result; r->_errno = result;
return -1; return -1;
} }
return 0; return 0;
} }
static int fs_dev_dirnext_r (struct _reent *r, DIR_ITER *dirState, char *filename, struct stat *st) static int fs_dev_dirnext_r(struct _reent *r, DIR_ITER *dirState, char *filename, struct stat *st) {
{ fs_dev_dir_entry_t *dirIter = (fs_dev_dir_entry_t *) dirState->dirStruct;
fs_dev_dir_entry_t *dirIter = (fs_dev_dir_entry_t *)dirState->dirStruct; if (!dirIter->dev) {
if(!dirIter->dev) {
r->_errno = ENODEV; r->_errno = ENODEV;
return -1; return -1;
} }
OSLockMutex(dirIter->dev->pMutex); OSLockMutex(dirIter->dev->pMutex);
directoryEntry_s * dir_entry = malloc(sizeof(directoryEntry_s)); directoryEntry_s *dir_entry = malloc(sizeof(directoryEntry_s));
int result = IOSUHAX_FSA_ReadDir(dirIter->dev->fsaFd, dirIter->dirHandle, dir_entry); int result = IOSUHAX_FSA_ReadDir(dirIter->dev->fsaFd, dirIter->dirHandle, dir_entry);
if(result < 0) if (result < 0) {
{
free(dir_entry); free(dir_entry);
r->_errno = result; r->_errno = result;
OSUnlockMutex(dirIter->dev->pMutex); OSUnlockMutex(dirIter->dev->pMutex);
@ -806,8 +762,7 @@ static int fs_dev_dirnext_r (struct _reent *r, DIR_ITER *dirState, char *filenam
// Fetch the current entry // Fetch the current entry
strcpy(filename, dir_entry->name); strcpy(filename, dir_entry->name);
if(st) if (st) {
{
memset(st, 0, sizeof(struct stat)); memset(st, 0, sizeof(struct stat));
st->st_mode = (dir_entry->stat.flag & 0x80000000) ? S_IFDIR : S_IFREG; st->st_mode = (dir_entry->stat.flag & 0x80000000) ? S_IFDIR : S_IFREG;
st->st_nlink = 1; st->st_nlink = 1;
@ -829,35 +784,34 @@ static int fs_dev_dirnext_r (struct _reent *r, DIR_ITER *dirState, char *filenam
// NTFS device driver devoptab // NTFS device driver devoptab
static const devoptab_t devops_fs = { static const devoptab_t devops_fs = {
NULL, /* Device name */ NULL, /* Device name */
sizeof (fs_dev_file_state_t), sizeof(fs_dev_file_state_t),
fs_dev_open_r, fs_dev_open_r,
fs_dev_close_r, fs_dev_close_r,
fs_dev_write_r, fs_dev_write_r,
fs_dev_read_r, fs_dev_read_r,
fs_dev_seek_r, fs_dev_seek_r,
fs_dev_fstat_r, fs_dev_fstat_r,
fs_dev_stat_r, fs_dev_stat_r,
fs_dev_link_r, fs_dev_link_r,
fs_dev_unlink_r, fs_dev_unlink_r,
fs_dev_chdir_r, fs_dev_chdir_r,
fs_dev_rename_r, fs_dev_rename_r,
fs_dev_mkdir_r, fs_dev_mkdir_r,
sizeof (fs_dev_dir_entry_t), sizeof(fs_dev_dir_entry_t),
fs_dev_diropen_r, fs_dev_diropen_r,
fs_dev_dirreset_r, fs_dev_dirreset_r,
fs_dev_dirnext_r, fs_dev_dirnext_r,
fs_dev_dirclose_r, fs_dev_dirclose_r,
fs_dev_statvfs_r, fs_dev_statvfs_r,
fs_dev_ftruncate_r, fs_dev_ftruncate_r,
fs_dev_fsync_r, fs_dev_fsync_r,
fs_dev_chmod_r, fs_dev_chmod_r,
NULL, /* fs_dev_fchmod_r */ NULL, /* fs_dev_fchmod_r */
NULL /* Device data */ NULL /* Device data */
}; };
static int fs_dev_add_device (const char *name, const char *mount_path, int fsaFd, int isMounted) static int fs_dev_add_device(const char *name, const char *mount_path, int fsaFd, int isMounted) {
{
devoptab_t *dev = NULL; devoptab_t *dev = NULL;
char *devname = NULL; char *devname = NULL;
char *devpath = NULL; char *devpath = NULL;
@ -877,18 +831,18 @@ static int fs_dev_add_device (const char *name, const char *mount_path, int fsaF
} }
// Use the space allocated at the end of the devoptab for storing the device name // Use the space allocated at the end of the devoptab for storing the device name
devname = (char*)(dev + 1); devname = (char *) (dev + 1);
strcpy(devname, name); strcpy(devname, name);
// create private data // create private data
fs_dev_private_t *priv = (fs_dev_private_t *)malloc(sizeof(fs_dev_private_t) + strlen(mount_path) + 1); fs_dev_private_t *priv = (fs_dev_private_t *) malloc(sizeof(fs_dev_private_t) + strlen(mount_path) + 1);
if(!priv) { if (!priv) {
free(dev); free(dev);
errno = ENOMEM; errno = ENOMEM;
return -1; return -1;
} }
devpath = (char*)(priv+1); devpath = (char *) (priv + 1);
strcpy(devpath, mount_path); strcpy(devpath, mount_path);
// setup private data // setup private data
@ -897,7 +851,7 @@ static int fs_dev_add_device (const char *name, const char *mount_path, int fsaF
priv->mounted = isMounted; priv->mounted = isMounted;
priv->pMutex = malloc(OS_MUTEX_SIZE); priv->pMutex = malloc(OS_MUTEX_SIZE);
if(!priv->pMutex) { if (!priv->pMutex) {
free(dev); free(dev);
free(priv); free(priv);
errno = ENOMEM; errno = ENOMEM;
@ -928,8 +882,7 @@ static int fs_dev_add_device (const char *name, const char *mount_path, int fsaF
return -1; return -1;
} }
static int fs_dev_remove_device (const char *path) static int fs_dev_remove_device(const char *path) {
{
const devoptab_t *devoptab = NULL; const devoptab_t *devoptab = NULL;
char name[128] = {0}; char name[128] = {0};
int i; int i;
@ -948,19 +901,18 @@ static int fs_dev_remove_device (const char *path)
if (strcmp(name, devoptab->name) == 0) { if (strcmp(name, devoptab->name) == 0) {
devoptab_list[i] = devoptab_list[0]; devoptab_list[i] = devoptab_list[0];
if(devoptab->deviceData) if (devoptab->deviceData) {
{ fs_dev_private_t *priv = (fs_dev_private_t *) devoptab->deviceData;
fs_dev_private_t *priv = (fs_dev_private_t *)devoptab->deviceData;
if(priv->mounted) if (priv->mounted)
IOSUHAX_FSA_Unmount(priv->fsaFd, priv->mount_path, 2); IOSUHAX_FSA_Unmount(priv->fsaFd, priv->mount_path, 2);
if(priv->pMutex) if (priv->pMutex)
free(priv->pMutex); free(priv->pMutex);
free(devoptab->deviceData); free(devoptab->deviceData);
} }
free((devoptab_t*)devoptab); free((devoptab_t *) devoptab);
return 0; return 0;
} }
} }
@ -969,17 +921,14 @@ static int fs_dev_remove_device (const char *path)
return -1; return -1;
} }
int mount_fs(const char *virt_name, int fsaFd, const char *dev_path, const char *mount_path) int mount_fs(const char *virt_name, int fsaFd, const char *dev_path, const char *mount_path) {
{
int isMounted = 0; int isMounted = 0;
if(dev_path) if (dev_path) {
{
isMounted = 1; isMounted = 1;
int res = IOSUHAX_FSA_Mount(fsaFd, dev_path, mount_path, 2, 0, 0); int res = IOSUHAX_FSA_Mount(fsaFd, dev_path, mount_path, 2, 0, 0);
if(res != 0) if (res != 0) {
{
return res; return res;
} }
} }
@ -987,7 +936,6 @@ int mount_fs(const char *virt_name, int fsaFd, const char *dev_path, const char
return fs_dev_add_device(virt_name, mount_path, fsaFd, isMounted); return fs_dev_add_device(virt_name, mount_path, fsaFd, isMounted);
} }
int unmount_fs(const char *virt_name) int unmount_fs(const char *virt_name) {
{
return fs_dev_remove_device(virt_name); return fs_dev_remove_device(virt_name);
} }

View File

@ -36,10 +36,8 @@ static int fsaFdUsb = 0;
static int sdioFd = 0; static int sdioFd = 0;
static int usbFd = 0; static int usbFd = 0;
static void IOSUHAX_disc_io_initialize(void) static void IOSUHAX_disc_io_initialize(void) {
{ if (initialized == 0) {
if(initialized == 0)
{
initialized = 1; initialized = 1;
fsaFdSd = -1; fsaFdSd = -1;
fsaFdUsb = -1; fsaFdUsb = -1;
@ -48,67 +46,52 @@ static void IOSUHAX_disc_io_initialize(void)
} }
} }
static bool IOSUHAX_disc_io_fsa_open(int fsaFd) static bool IOSUHAX_disc_io_fsa_open(int fsaFd) {
{
IOSUHAX_disc_io_initialize(); IOSUHAX_disc_io_initialize();
if(IOSUHAX_Open(NULL) < 0) if (IOSUHAX_Open(NULL) < 0)
return false; return false;
if(fsaFd == FSA_REF_SD) if (fsaFd == FSA_REF_SD) {
{ if (fsaFdSd < 0) {
if(fsaFdSd < 0)
{
fsaFdSd = IOSUHAX_FSA_Open(); fsaFdSd = IOSUHAX_FSA_Open();
} }
if(fsaFdSd >= 0) if (fsaFdSd >= 0)
return true; return true;
} } else if (fsaFd == FSA_REF_USB) {
else if(fsaFd == FSA_REF_USB) if (fsaFdUsb < 0) {
{
if(fsaFdUsb < 0)
{
fsaFdUsb = IOSUHAX_FSA_Open(); fsaFdUsb = IOSUHAX_FSA_Open();
} }
if(fsaFdUsb >= 0) if (fsaFdUsb >= 0)
return true; return true;
} }
return false; return false;
} }
static void IOSUHAX_disc_io_fsa_close(int fsaFd) static void IOSUHAX_disc_io_fsa_close(int fsaFd) {
{ if (fsaFd == FSA_REF_SD) {
if(fsaFd == FSA_REF_SD) if (fsaFdSd >= 0) {
{
if(fsaFdSd >= 0)
{
IOSUHAX_FSA_Close(fsaFdSd); IOSUHAX_FSA_Close(fsaFdSd);
fsaFdSd = -1; fsaFdSd = -1;
} }
} } else if (fsaFd == FSA_REF_USB) {
else if(fsaFd == FSA_REF_USB) if (fsaFdUsb >= 0) {
{
if(fsaFdUsb >= 0)
{
IOSUHAX_FSA_Close(fsaFdUsb); IOSUHAX_FSA_Close(fsaFdUsb);
fsaFdUsb = -1; fsaFdUsb = -1;
} }
} }
} }
static bool IOSUHAX_sdio_startup(void) static bool IOSUHAX_sdio_startup(void) {
{ if (!IOSUHAX_disc_io_fsa_open(FSA_REF_SD))
if(!IOSUHAX_disc_io_fsa_open(FSA_REF_SD))
return false; return false;
if(sdioFd < 0) if (sdioFd < 0) {
{
int res = IOSUHAX_FSA_RawOpen(fsaFdSd, "/dev/sdcard01", &sdioFd); int res = IOSUHAX_FSA_RawOpen(fsaFdSd, "/dev/sdcard01", &sdioFd);
if(res < 0) if (res < 0) {
{
IOSUHAX_disc_io_fsa_close(FSA_REF_SD); IOSUHAX_disc_io_fsa_close(FSA_REF_SD);
sdioFd = -1; sdioFd = -1;
} }
@ -117,20 +100,17 @@ static bool IOSUHAX_sdio_startup(void)
return (sdioFd >= 0); return (sdioFd >= 0);
} }
static bool IOSUHAX_sdio_isInserted(void) static bool IOSUHAX_sdio_isInserted(void) {
{
//! TODO: check for SD card inserted with IOSUHAX_FSA_GetDeviceInfo() //! TODO: check for SD card inserted with IOSUHAX_FSA_GetDeviceInfo()
return initialized && (fsaFdSd >= 0) && (sdioFd >= 0); return initialized && (fsaFdSd >= 0) && (sdioFd >= 0);
} }
static bool IOSUHAX_sdio_clearStatus(void) static bool IOSUHAX_sdio_clearStatus(void) {
{
return true; return true;
} }
static bool IOSUHAX_sdio_shutdown(void) static bool IOSUHAX_sdio_shutdown(void) {
{ if (!IOSUHAX_sdio_isInserted())
if(!IOSUHAX_sdio_isInserted())
return false; return false;
IOSUHAX_FSA_RawClose(fsaFdSd, sdioFd); IOSUHAX_FSA_RawClose(fsaFdSd, sdioFd);
@ -139,28 +119,24 @@ static bool IOSUHAX_sdio_shutdown(void)
return true; return true;
} }
static bool IOSUHAX_sdio_readSectors(uint32_t sector, uint32_t numSectors, void* buffer) static bool IOSUHAX_sdio_readSectors(uint32_t sector, uint32_t numSectors, void *buffer) {
{ if (!IOSUHAX_sdio_isInserted())
if(!IOSUHAX_sdio_isInserted())
return false; return false;
int res = IOSUHAX_FSA_RawRead(fsaFdSd, buffer, 512, numSectors, sector, sdioFd); int res = IOSUHAX_FSA_RawRead(fsaFdSd, buffer, 512, numSectors, sector, sdioFd);
if(res < 0) if (res < 0) {
{
return false; return false;
} }
return true; return true;
} }
static bool IOSUHAX_sdio_writeSectors(uint32_t sector, uint32_t numSectors, const void* buffer) static bool IOSUHAX_sdio_writeSectors(uint32_t sector, uint32_t numSectors, const void *buffer) {
{ if (!IOSUHAX_sdio_isInserted())
if(!IOSUHAX_sdio_isInserted())
return false; return false;
int res = IOSUHAX_FSA_RawWrite(fsaFdSd, buffer, 512, numSectors, sector, sdioFd); int res = IOSUHAX_FSA_RawWrite(fsaFdSd, buffer, 512, numSectors, sector, sdioFd);
if(res < 0) if (res < 0) {
{
return false; return false;
} }
@ -168,30 +144,26 @@ static bool IOSUHAX_sdio_writeSectors(uint32_t sector, uint32_t numSectors, cons
} }
const DISC_INTERFACE IOSUHAX_sdio_disc_interface = const DISC_INTERFACE IOSUHAX_sdio_disc_interface =
{ {
DEVICE_TYPE_WII_U_SD, DEVICE_TYPE_WII_U_SD,
FEATURE_MEDIUM_CANREAD | FEATURE_MEDIUM_CANWRITE | FEATURE_WII_U_SD, FEATURE_MEDIUM_CANREAD | FEATURE_MEDIUM_CANWRITE | FEATURE_WII_U_SD,
IOSUHAX_sdio_startup, IOSUHAX_sdio_startup,
IOSUHAX_sdio_isInserted, IOSUHAX_sdio_isInserted,
IOSUHAX_sdio_readSectors, IOSUHAX_sdio_readSectors,
IOSUHAX_sdio_writeSectors, IOSUHAX_sdio_writeSectors,
IOSUHAX_sdio_clearStatus, IOSUHAX_sdio_clearStatus,
IOSUHAX_sdio_shutdown IOSUHAX_sdio_shutdown
}; };
static bool IOSUHAX_usb_startup(void) static bool IOSUHAX_usb_startup(void) {
{ if (!IOSUHAX_disc_io_fsa_open(FSA_REF_USB))
if(!IOSUHAX_disc_io_fsa_open(FSA_REF_USB))
return false; return false;
if(usbFd < 0) if (usbFd < 0) {
{
int res = IOSUHAX_FSA_RawOpen(fsaFdUsb, "/dev/usb01", &usbFd); int res = IOSUHAX_FSA_RawOpen(fsaFdUsb, "/dev/usb01", &usbFd);
if(res < 0) if (res < 0) {
{
res = IOSUHAX_FSA_RawOpen(fsaFdUsb, "/dev/usb02", &usbFd); res = IOSUHAX_FSA_RawOpen(fsaFdUsb, "/dev/usb02", &usbFd);
if(res < 0) if (res < 0) {
{
IOSUHAX_disc_io_fsa_close(FSA_REF_USB); IOSUHAX_disc_io_fsa_close(FSA_REF_USB);
usbFd = -1; usbFd = -1;
} }
@ -200,19 +172,16 @@ static bool IOSUHAX_usb_startup(void)
return (usbFd >= 0); return (usbFd >= 0);
} }
static bool IOSUHAX_usb_isInserted(void) static bool IOSUHAX_usb_isInserted(void) {
{
return initialized && (fsaFdUsb >= 0) && (usbFd >= 0); return initialized && (fsaFdUsb >= 0) && (usbFd >= 0);
} }
static bool IOSUHAX_usb_clearStatus(void) static bool IOSUHAX_usb_clearStatus(void) {
{
return true; return true;
} }
static bool IOSUHAX_usb_shutdown(void) static bool IOSUHAX_usb_shutdown(void) {
{ if (!IOSUHAX_usb_isInserted())
if(!IOSUHAX_usb_isInserted())
return false; return false;
IOSUHAX_FSA_RawClose(fsaFdUsb, usbFd); IOSUHAX_FSA_RawClose(fsaFdUsb, usbFd);
@ -221,28 +190,24 @@ static bool IOSUHAX_usb_shutdown(void)
return true; return true;
} }
static bool IOSUHAX_usb_readSectors(uint32_t sector, uint32_t numSectors, void* buffer) static bool IOSUHAX_usb_readSectors(uint32_t sector, uint32_t numSectors, void *buffer) {
{ if (!IOSUHAX_usb_isInserted())
if(!IOSUHAX_usb_isInserted())
return false; return false;
int res = IOSUHAX_FSA_RawRead(fsaFdUsb, buffer, 512, numSectors, sector, usbFd); int res = IOSUHAX_FSA_RawRead(fsaFdUsb, buffer, 512, numSectors, sector, usbFd);
if(res < 0) if (res < 0) {
{
return false; return false;
} }
return true; return true;
} }
static bool IOSUHAX_usb_writeSectors(uint32_t sector, uint32_t numSectors, const void* buffer) static bool IOSUHAX_usb_writeSectors(uint32_t sector, uint32_t numSectors, const void *buffer) {
{ if (!IOSUHAX_usb_isInserted())
if(!IOSUHAX_usb_isInserted())
return false; return false;
int res = IOSUHAX_FSA_RawWrite(fsaFdUsb, buffer, 512, numSectors, sector, usbFd); int res = IOSUHAX_FSA_RawWrite(fsaFdUsb, buffer, 512, numSectors, sector, usbFd);
if(res < 0) if (res < 0) {
{
return false; return false;
} }
@ -250,13 +215,13 @@ static bool IOSUHAX_usb_writeSectors(uint32_t sector, uint32_t numSectors, const
} }
const DISC_INTERFACE IOSUHAX_usb_disc_interface = const DISC_INTERFACE IOSUHAX_usb_disc_interface =
{ {
DEVICE_TYPE_WII_U_USB, DEVICE_TYPE_WII_U_USB,
FEATURE_MEDIUM_CANREAD | FEATURE_MEDIUM_CANWRITE | FEATURE_WII_U_USB, FEATURE_MEDIUM_CANREAD | FEATURE_MEDIUM_CANWRITE | FEATURE_WII_U_USB,
IOSUHAX_usb_startup, IOSUHAX_usb_startup,
IOSUHAX_usb_isInserted, IOSUHAX_usb_isInserted,
IOSUHAX_usb_readSectors, IOSUHAX_usb_readSectors,
IOSUHAX_usb_writeSectors, IOSUHAX_usb_writeSectors,
IOSUHAX_usb_clearStatus, IOSUHAX_usb_clearStatus,
IOSUHAX_usb_shutdown IOSUHAX_usb_shutdown
}; };

View File

@ -10,15 +10,19 @@ extern "C" {
//!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- //!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//! Mutex functions //! Mutex functions
//!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- //!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
extern void OSInitMutex(void* mutex); extern void OSInitMutex(void *mutex);
extern void OSLockMutex(void* mutex);
extern void OSUnlockMutex(void* mutex); extern void OSLockMutex(void *mutex);
extern void OSUnlockMutex(void *mutex);
//!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- //!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//! IOS function //! IOS function
//!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- //!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
extern int IOS_Ioctl(int fd, unsigned int request, void *input_buffer,unsigned int input_buffer_len, void *output_buffer, unsigned int output_buffer_len); extern int IOS_Ioctl(int fd, unsigned int request, void *input_buffer, unsigned int input_buffer_len, void *output_buffer, unsigned int output_buffer_len);
extern int IOS_Open(char *path, unsigned int mode); extern int IOS_Open(char *path, unsigned int mode);
extern int IOS_Close(int fd); extern int IOS_Close(int fd);
#ifdef __cplusplus #ifdef __cplusplus