mirror of
https://github.com/wiiu-env/libiosuhax.git
synced 2025-01-11 17:39:09 +01:00
Formatting
This commit is contained in:
parent
69532cf9d9
commit
0e1af0e341
3
.gitignore
vendored
3
.gitignore
vendored
@ -3,3 +3,6 @@
|
||||
*.bz2
|
||||
release/
|
||||
lib/
|
||||
.idea/
|
||||
cmake-build-debug/
|
||||
CMakeLists.txt
|
||||
|
@ -21,8 +21,7 @@
|
||||
* 3. This notice may not be removed or altered from any source
|
||||
* distribution.
|
||||
***************************************************************************/
|
||||
#ifndef _LIB_IOSUHAX_H_
|
||||
#define _LIB_IOSUHAX_H_
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
@ -36,8 +35,7 @@ extern "C" {
|
||||
#define IOS_ERROR_UNKNOWN 0xFFFFFFF7
|
||||
#define IOS_ERROR_NOEXISTS 0xFFFFFFFA
|
||||
|
||||
typedef struct
|
||||
{
|
||||
typedef struct {
|
||||
uint32_t flag;
|
||||
uint32_t permission;
|
||||
uint32_t owner_id;
|
||||
@ -51,8 +49,7 @@ typedef struct
|
||||
uint32_t unk2[0x0D];
|
||||
} fileStat_s;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
typedef struct {
|
||||
fileStat_s stat;
|
||||
char name[0x100];
|
||||
} directoryEntry_s;
|
||||
@ -70,43 +67,61 @@ int IOSUHAX_memread(uint32_t address, uint8_t * out_buffer, uint32_t size); /
|
||||
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_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_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);
|
||||
|
||||
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_CloseDir(int fsaFd, int handle);
|
||||
|
||||
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_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_StatFile(int fsaFd, int fileHandle, fileStat_s *out_data);
|
||||
|
||||
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_RawClose(int fsaFd, int device_handle);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
@ -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.
|
||||
//! 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 unmount_fs(const char *virt_name);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
@ -43,10 +43,15 @@ typedef uint32_t sec_t;
|
||||
#define FEATURE_MEDIUM_CANWRITE 0x00000002
|
||||
|
||||
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_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 {
|
||||
|
168
source/iosuhax.c
168
source/iosuhax.c
@ -69,8 +69,7 @@ static int iosuhaxHandle = -1;
|
||||
#define ALIGN(align) __attribute__((aligned(align)))
|
||||
#define ROUNDUP(x, align) (((x) + ((align) - 1)) & ~((align) - 1))
|
||||
|
||||
int IOSUHAX_Open(const char *dev)
|
||||
{
|
||||
int IOSUHAX_Open(const char *dev) {
|
||||
if (iosuhaxHandle >= 0)
|
||||
return iosuhaxHandle;
|
||||
|
||||
@ -81,8 +80,7 @@ int IOSUHAX_Open(const char *dev)
|
||||
*res = 0;
|
||||
|
||||
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);
|
||||
iosuhaxHandle = -1;
|
||||
}
|
||||
@ -91,8 +89,7 @@ int IOSUHAX_Open(const char *dev)
|
||||
return iosuhaxHandle;
|
||||
}
|
||||
|
||||
int IOSUHAX_Close(void)
|
||||
{
|
||||
int IOSUHAX_Close(void) {
|
||||
if (iosuhaxHandle < 0)
|
||||
return 0;
|
||||
|
||||
@ -101,8 +98,7 @@ int IOSUHAX_Close(void)
|
||||
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)
|
||||
return iosuhaxHandle;
|
||||
|
||||
@ -119,8 +115,7 @@ int IOSUHAX_memwrite(uint32_t address, const uint8_t * buffer, uint32_t size)
|
||||
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)
|
||||
return iosuhaxHandle;
|
||||
|
||||
@ -129,8 +124,7 @@ int IOSUHAX_memread(uint32_t address, uint8_t * out_buffer, uint32_t size)
|
||||
|
||||
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));
|
||||
if (!tmp_buf)
|
||||
return -2;
|
||||
@ -145,8 +139,7 @@ int IOSUHAX_memread(uint32_t address, uint8_t * out_buffer, uint32_t size)
|
||||
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)
|
||||
return iosuhaxHandle;
|
||||
|
||||
@ -158,8 +151,7 @@ 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);
|
||||
}
|
||||
|
||||
int IOSUHAX_kern_write32(uint32_t address, uint32_t value)
|
||||
{
|
||||
int IOSUHAX_kern_write32(uint32_t address, uint32_t value) {
|
||||
if (iosuhaxHandle < 0)
|
||||
return iosuhaxHandle;
|
||||
|
||||
@ -170,8 +162,7 @@ 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);
|
||||
}
|
||||
|
||||
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)
|
||||
return iosuhaxHandle;
|
||||
|
||||
@ -180,8 +171,7 @@ int IOSUHAX_kern_read32(uint32_t address, uint32_t* out_buffer, uint32_t count)
|
||||
|
||||
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));
|
||||
if (!tmp_buf)
|
||||
return -2;
|
||||
@ -196,16 +186,14 @@ int IOSUHAX_kern_read32(uint32_t address, uint32_t* out_buffer, uint32_t count)
|
||||
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)
|
||||
return iosuhaxHandle;
|
||||
|
||||
ALIGN(0x20) uint32_t arguments[0x40 >> 2];
|
||||
arguments[0] = svc_id;
|
||||
|
||||
if(args && arg_cnt)
|
||||
{
|
||||
if (args && arg_cnt) {
|
||||
if (arg_cnt > 8)
|
||||
arg_cnt = 8;
|
||||
|
||||
@ -220,8 +208,7 @@ int IOSUHAX_SVC(uint32_t svc_id, uint32_t * args, uint32_t arg_cnt)
|
||||
return *result;
|
||||
}
|
||||
|
||||
int IOSUHAX_FSA_Open(void)
|
||||
{
|
||||
int IOSUHAX_FSA_Open(void) {
|
||||
if (iosuhaxHandle < 0)
|
||||
return iosuhaxHandle;
|
||||
|
||||
@ -234,8 +221,7 @@ int IOSUHAX_FSA_Open(void)
|
||||
return io_buf[0];
|
||||
}
|
||||
|
||||
int IOSUHAX_FSA_Close(int fsaFd)
|
||||
{
|
||||
int IOSUHAX_FSA_Close(int fsaFd) {
|
||||
if (iosuhaxHandle < 0)
|
||||
return iosuhaxHandle;
|
||||
|
||||
@ -249,8 +235,7 @@ int IOSUHAX_FSA_Close(int fsaFd)
|
||||
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)
|
||||
return iosuhaxHandle;
|
||||
|
||||
@ -281,8 +266,7 @@ int IOSUHAX_FSA_Mount(int fsaFd, const char* device_path, const char* volume_pat
|
||||
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)
|
||||
return iosuhaxHandle;
|
||||
|
||||
@ -304,8 +288,7 @@ int IOSUHAX_FSA_Unmount(int fsaFd, const char* path, uint32_t flags)
|
||||
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)
|
||||
return iosuhaxHandle;
|
||||
|
||||
@ -326,8 +309,7 @@ int IOSUHAX_FSA_FlushVolume(int fsaFd, const char *volume_path)
|
||||
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)
|
||||
return iosuhaxHandle;
|
||||
|
||||
@ -347,8 +329,7 @@ int IOSUHAX_FSA_GetDeviceInfo(int fsaFd, const char* device_path, int type, uint
|
||||
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));
|
||||
if(res < 0)
|
||||
{
|
||||
if (res < 0) {
|
||||
free(io_buf);
|
||||
return res;
|
||||
}
|
||||
@ -358,8 +339,7 @@ int IOSUHAX_FSA_GetDeviceInfo(int fsaFd, const char* device_path, int type, uint
|
||||
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)
|
||||
return iosuhaxHandle;
|
||||
|
||||
@ -378,8 +358,7 @@ int IOSUHAX_FSA_MakeDir(int fsaFd, const char* path, uint32_t flags)
|
||||
|
||||
int 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);
|
||||
return res;
|
||||
}
|
||||
@ -388,8 +367,7 @@ int IOSUHAX_FSA_MakeDir(int fsaFd, const char* path, uint32_t flags)
|
||||
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)
|
||||
return iosuhaxHandle;
|
||||
|
||||
@ -408,8 +386,7 @@ int IOSUHAX_FSA_OpenDir(int fsaFd, const char* path, int* outHandle)
|
||||
int result_vec[2];
|
||||
|
||||
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);
|
||||
return res;
|
||||
}
|
||||
@ -419,8 +396,7 @@ int IOSUHAX_FSA_OpenDir(int fsaFd, const char* path, int* outHandle)
|
||||
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)
|
||||
return iosuhaxHandle;
|
||||
|
||||
@ -437,15 +413,13 @@ int IOSUHAX_FSA_ReadDir(int fsaFd, int handle, directoryEntry_s* out_data)
|
||||
|
||||
int result_vec_size = 4 + sizeof(directoryEntry_s);
|
||||
uint8_t *result_vec = (uint8_t *) memalign(0x20, result_vec_size);
|
||||
if(!result_vec)
|
||||
{
|
||||
if (!result_vec) {
|
||||
free(io_buf);
|
||||
return -2;
|
||||
}
|
||||
|
||||
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(io_buf);
|
||||
return res;
|
||||
@ -458,8 +432,7 @@ int IOSUHAX_FSA_ReadDir(int fsaFd, int handle, directoryEntry_s* out_data)
|
||||
return result;
|
||||
}
|
||||
|
||||
int IOSUHAX_FSA_RewindDir(int fsaFd, int dirHandle)
|
||||
{
|
||||
int IOSUHAX_FSA_RewindDir(int fsaFd, int dirHandle) {
|
||||
if (iosuhaxHandle < 0)
|
||||
return iosuhaxHandle;
|
||||
|
||||
@ -477,8 +450,7 @@ int IOSUHAX_FSA_RewindDir(int fsaFd, int dirHandle)
|
||||
int 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);
|
||||
return res;
|
||||
}
|
||||
@ -487,8 +459,7 @@ int IOSUHAX_FSA_RewindDir(int fsaFd, int dirHandle)
|
||||
return result;
|
||||
}
|
||||
|
||||
int IOSUHAX_FSA_CloseDir(int fsaFd, int handle)
|
||||
{
|
||||
int IOSUHAX_FSA_CloseDir(int fsaFd, int handle) {
|
||||
if (iosuhaxHandle < 0)
|
||||
return iosuhaxHandle;
|
||||
|
||||
@ -506,8 +477,7 @@ int IOSUHAX_FSA_CloseDir(int fsaFd, int handle)
|
||||
int 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);
|
||||
return res;
|
||||
}
|
||||
@ -516,8 +486,7 @@ int IOSUHAX_FSA_CloseDir(int fsaFd, int handle)
|
||||
return result;
|
||||
}
|
||||
|
||||
int IOSUHAX_FSA_ChangeDir(int fsaFd, const char *path)
|
||||
{
|
||||
int IOSUHAX_FSA_ChangeDir(int fsaFd, const char *path) {
|
||||
if (iosuhaxHandle < 0)
|
||||
return iosuhaxHandle;
|
||||
|
||||
@ -536,8 +505,7 @@ int IOSUHAX_FSA_ChangeDir(int fsaFd, const char *path)
|
||||
int 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);
|
||||
return res;
|
||||
}
|
||||
@ -546,8 +514,7 @@ int IOSUHAX_FSA_ChangeDir(int fsaFd, const char *path)
|
||||
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)
|
||||
return iosuhaxHandle;
|
||||
|
||||
@ -568,8 +535,7 @@ int IOSUHAX_FSA_OpenFile(int fsaFd, const char* path, const char* mode, int* out
|
||||
int result_vec[2];
|
||||
|
||||
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);
|
||||
return res;
|
||||
}
|
||||
@ -579,8 +545,7 @@ int IOSUHAX_FSA_OpenFile(int fsaFd, const char* path, const char* mode, int* out
|
||||
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)
|
||||
return iosuhaxHandle;
|
||||
|
||||
@ -601,15 +566,13 @@ int IOSUHAX_FSA_ReadFile(int fsaFd, void* data, uint32_t size, uint32_t cnt, int
|
||||
int out_buf_size = ((size * cnt + 0x40) + 0x3F) & ~0x3F;
|
||||
|
||||
uint32_t *out_buffer = (uint32_t *) memalign(0x40, out_buf_size);
|
||||
if(!out_buffer)
|
||||
{
|
||||
if (!out_buffer) {
|
||||
free(io_buf);
|
||||
return -2;
|
||||
}
|
||||
|
||||
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(io_buf);
|
||||
return res;
|
||||
@ -625,8 +588,7 @@ int IOSUHAX_FSA_ReadFile(int fsaFd, void* data, uint32_t size, uint32_t cnt, int
|
||||
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)
|
||||
return iosuhaxHandle;
|
||||
|
||||
@ -649,8 +611,7 @@ int IOSUHAX_FSA_WriteFile(int fsaFd, const void* data, uint32_t size, uint32_t c
|
||||
|
||||
int 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);
|
||||
return res;
|
||||
}
|
||||
@ -658,8 +619,7 @@ int IOSUHAX_FSA_WriteFile(int fsaFd, const void* data, uint32_t size, uint32_t c
|
||||
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)
|
||||
return iosuhaxHandle;
|
||||
|
||||
@ -676,15 +636,13 @@ int IOSUHAX_FSA_StatFile(int fsaFd, int fileHandle, fileStat_s* out_data)
|
||||
|
||||
int out_buf_size = 4 + sizeof(fileStat_s);
|
||||
uint32_t *out_buffer = (uint32_t *) memalign(0x20, out_buf_size);
|
||||
if(!out_buffer)
|
||||
{
|
||||
if (!out_buffer) {
|
||||
free(io_buf);
|
||||
return -2;
|
||||
}
|
||||
|
||||
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(out_buffer);
|
||||
return res;
|
||||
@ -698,8 +656,7 @@ int IOSUHAX_FSA_StatFile(int fsaFd, int fileHandle, fileStat_s* out_data)
|
||||
return result;
|
||||
}
|
||||
|
||||
int IOSUHAX_FSA_CloseFile(int fsaFd, int fileHandle)
|
||||
{
|
||||
int IOSUHAX_FSA_CloseFile(int fsaFd, int fileHandle) {
|
||||
if (iosuhaxHandle < 0)
|
||||
return iosuhaxHandle;
|
||||
|
||||
@ -717,8 +674,7 @@ int IOSUHAX_FSA_CloseFile(int fsaFd, int fileHandle)
|
||||
int 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);
|
||||
return res;
|
||||
}
|
||||
@ -727,8 +683,7 @@ int IOSUHAX_FSA_CloseFile(int fsaFd, int fileHandle)
|
||||
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)
|
||||
return iosuhaxHandle;
|
||||
|
||||
@ -747,8 +702,7 @@ int IOSUHAX_FSA_SetFilePos(int fsaFd, int fileHandle, uint32_t position)
|
||||
int 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);
|
||||
return res;
|
||||
}
|
||||
@ -757,8 +711,7 @@ int IOSUHAX_FSA_SetFilePos(int fsaFd, int fileHandle, uint32_t position)
|
||||
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)
|
||||
return iosuhaxHandle;
|
||||
|
||||
@ -776,15 +729,13 @@ int IOSUHAX_FSA_GetStat(int fsaFd, const char *path, fileStat_s* out_data)
|
||||
|
||||
int out_buf_size = 4 + sizeof(fileStat_s);
|
||||
uint32_t *out_buffer = (uint32_t *) memalign(0x20, out_buf_size);
|
||||
if(!out_buffer)
|
||||
{
|
||||
if (!out_buffer) {
|
||||
free(io_buf);
|
||||
return -2;
|
||||
}
|
||||
|
||||
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(out_buffer);
|
||||
return res;
|
||||
@ -798,8 +749,7 @@ int IOSUHAX_FSA_GetStat(int fsaFd, const char *path, fileStat_s* out_data)
|
||||
return result;
|
||||
}
|
||||
|
||||
int IOSUHAX_FSA_Remove(int fsaFd, const char *path)
|
||||
{
|
||||
int IOSUHAX_FSA_Remove(int fsaFd, const char *path) {
|
||||
if (iosuhaxHandle < 0)
|
||||
return iosuhaxHandle;
|
||||
|
||||
@ -823,8 +773,7 @@ int IOSUHAX_FSA_Remove(int fsaFd, const char *path)
|
||||
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)
|
||||
return iosuhaxHandle;
|
||||
|
||||
@ -846,8 +795,7 @@ int IOSUHAX_FSA_ChangeMode(int fsaFd, const char* path, int mode)
|
||||
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)
|
||||
return iosuhaxHandle;
|
||||
|
||||
@ -871,8 +819,7 @@ int IOSUHAX_FSA_RawOpen(int fsaFd, const char* device_path, int* outHandle)
|
||||
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)
|
||||
return iosuhaxHandle;
|
||||
|
||||
@ -892,8 +839,7 @@ int IOSUHAX_FSA_RawRead(int fsaFd, void* data, uint32_t block_size, uint32_t blo
|
||||
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);
|
||||
if(res >= 0)
|
||||
{
|
||||
if (res >= 0) {
|
||||
//! data is put to offset 0x40 to align the buffer output
|
||||
memcpy(data, ((uint8_t *) io_buf) + 0x40, block_size * block_cnt);
|
||||
|
||||
@ -904,8 +850,7 @@ int IOSUHAX_FSA_RawRead(int fsaFd, void* data, uint32_t block_size, uint32_t blo
|
||||
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)
|
||||
return iosuhaxHandle;
|
||||
|
||||
@ -934,8 +879,7 @@ int IOSUHAX_FSA_RawWrite(int fsaFd, const void* data, uint32_t block_size, uint3
|
||||
}
|
||||
|
||||
|
||||
int IOSUHAX_FSA_RawClose(int fsaFd, int device_handle)
|
||||
{
|
||||
int IOSUHAX_FSA_RawClose(int fsaFd, int device_handle) {
|
||||
if (iosuhaxHandle < 0)
|
||||
return iosuhaxHandle;
|
||||
|
||||
|
@ -59,8 +59,7 @@ typedef struct _fs_dev_dir_entry_t {
|
||||
int dirHandle;
|
||||
} 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;
|
||||
char name[128] = {0};
|
||||
int i;
|
||||
@ -85,8 +84,7 @@ static fs_dev_private_t *fs_dev_get_device_data(const char *path)
|
||||
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
|
||||
if (!path)
|
||||
return NULL;
|
||||
@ -107,8 +105,7 @@ static char *fs_dev_real_path (const char *path, fs_dev_private_t *dev)
|
||||
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);
|
||||
if (!dev) {
|
||||
r->_errno = ENODEV;
|
||||
@ -175,8 +172,7 @@ static int fs_dev_open_r (struct _reent *r, void *fileStruct, const char *path,
|
||||
|
||||
free(real_path);
|
||||
|
||||
if(result == 0)
|
||||
{
|
||||
if (result == 0) {
|
||||
fileStat_s stats;
|
||||
result = IOSUHAX_FSA_StatFile(dev->fsaFd, fd, &stats);
|
||||
if (result != 0) {
|
||||
@ -198,8 +194,7 @@ 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;
|
||||
if (!file->dev) {
|
||||
r->_errno = ENODEV;
|
||||
@ -212,16 +207,14 @@ static int fs_dev_close_r (struct _reent *r, void *fd)
|
||||
|
||||
OSUnlockMutex(file->dev->pMutex);
|
||||
|
||||
if(result < 0)
|
||||
{
|
||||
if (result < 0) {
|
||||
r->_errno = result;
|
||||
return -1;
|
||||
}
|
||||
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;
|
||||
if (!file->dev) {
|
||||
r->_errno = ENODEV;
|
||||
@ -230,8 +223,7 @@ static off_t fs_dev_seek_r (struct _reent *r, void *fd, off_t pos, int dir)
|
||||
|
||||
OSLockMutex(file->dev->pMutex);
|
||||
|
||||
switch(dir)
|
||||
{
|
||||
switch (dir) {
|
||||
case SEEK_SET:
|
||||
file->pos = pos;
|
||||
break;
|
||||
@ -250,24 +242,21 @@ static off_t fs_dev_seek_r (struct _reent *r, void *fd, off_t pos, int dir)
|
||||
|
||||
OSUnlockMutex(file->dev->pMutex);
|
||||
|
||||
if(result == 0)
|
||||
{
|
||||
if (result == 0) {
|
||||
return file->pos;
|
||||
}
|
||||
|
||||
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;
|
||||
if (!file->dev) {
|
||||
r->_errno = ENODEV;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(!file->write)
|
||||
{
|
||||
if (!file->write) {
|
||||
r->_errno = EACCES;
|
||||
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;
|
||||
|
||||
while(done < len)
|
||||
{
|
||||
while (done < len) {
|
||||
size_t write_size = len - done;
|
||||
|
||||
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;
|
||||
break;
|
||||
}
|
||||
else if(result == 0)
|
||||
{
|
||||
} else if (result == 0) {
|
||||
if (write_size > 0)
|
||||
done = 0;
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
done += 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;
|
||||
}
|
||||
|
||||
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;
|
||||
if (!file->dev) {
|
||||
r->_errno = ENODEV;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(!file->read)
|
||||
{
|
||||
if (!file->read) {
|
||||
r->_errno = EACCES;
|
||||
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;
|
||||
|
||||
while(done < len)
|
||||
{
|
||||
while (done < len) {
|
||||
size_t read_size = len - done;
|
||||
|
||||
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;
|
||||
done = 0;
|
||||
break;
|
||||
}
|
||||
else if(result == 0)
|
||||
{
|
||||
} else if (result == 0) {
|
||||
//! TODO: error on read_size > 0
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
done += result;
|
||||
file->pos += result;
|
||||
}
|
||||
@ -349,8 +324,7 @@ 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;
|
||||
if (!file->dev) {
|
||||
r->_errno = ENODEV;
|
||||
@ -387,8 +361,7 @@ static int fs_dev_fstat_r (struct _reent *r, void *fd, struct stat *st)
|
||||
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;
|
||||
if (!file->dev) {
|
||||
r->_errno = ENODEV;
|
||||
@ -400,8 +373,7 @@ static int fs_dev_ftruncate_r (struct _reent *r, void *fd, off_t len)
|
||||
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;
|
||||
if (!file->dev) {
|
||||
r->_errno = ENODEV;
|
||||
@ -413,8 +385,7 @@ static int fs_dev_fsync_r (struct _reent *r, void *fd)
|
||||
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);
|
||||
if (!dev) {
|
||||
r->_errno = ENODEV;
|
||||
@ -464,14 +435,12 @@ static int fs_dev_stat_r (struct _reent *r, const char *path, struct stat *st)
|
||||
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;
|
||||
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);
|
||||
if (!dev) {
|
||||
r->_errno = ENODEV;
|
||||
@ -501,8 +470,7 @@ static int fs_dev_unlink_r (struct _reent *r, const char *name)
|
||||
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);
|
||||
if (!dev) {
|
||||
r->_errno = ENODEV;
|
||||
@ -532,8 +500,7 @@ static int fs_dev_chdir_r (struct _reent *r, const char *name)
|
||||
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);
|
||||
if (!dev) {
|
||||
r->_errno = ENODEV;
|
||||
@ -573,8 +540,7 @@ 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);
|
||||
if (!dev) {
|
||||
r->_errno = ENODEV;
|
||||
@ -604,8 +570,7 @@ static int fs_dev_mkdir_r (struct _reent *r, const char *path, int mode)
|
||||
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);
|
||||
if (!dev) {
|
||||
r->_errno = ENODEV;
|
||||
@ -635,8 +600,7 @@ static int fs_dev_chmod_r (struct _reent *r, const char *path, int mode)
|
||||
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);
|
||||
if (!dev) {
|
||||
r->_errno = ENODEV;
|
||||
@ -699,8 +663,7 @@ static int fs_dev_statvfs_r (struct _reent *r, const char *path, struct statvfs
|
||||
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);
|
||||
if (!dev) {
|
||||
r->_errno = ENODEV;
|
||||
@ -726,8 +689,7 @@ static DIR_ITER *fs_dev_diropen_r (struct _reent *r, DIR_ITER *dirState, const c
|
||||
|
||||
OSUnlockMutex(dev->pMutex);
|
||||
|
||||
if(result < 0)
|
||||
{
|
||||
if (result < 0) {
|
||||
r->_errno = result;
|
||||
return NULL;
|
||||
}
|
||||
@ -738,8 +700,7 @@ static DIR_ITER *fs_dev_diropen_r (struct _reent *r, DIR_ITER *dirState, const c
|
||||
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;
|
||||
if (!dirIter->dev) {
|
||||
r->_errno = ENODEV;
|
||||
@ -752,16 +713,14 @@ static int fs_dev_dirclose_r (struct _reent *r, DIR_ITER *dirState)
|
||||
|
||||
OSUnlockMutex(dirIter->dev->pMutex);
|
||||
|
||||
if(result < 0)
|
||||
{
|
||||
if (result < 0) {
|
||||
r->_errno = result;
|
||||
return -1;
|
||||
}
|
||||
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;
|
||||
if (!dirIter->dev) {
|
||||
r->_errno = ENODEV;
|
||||
@ -774,16 +733,14 @@ static int fs_dev_dirreset_r (struct _reent *r, DIR_ITER *dirState)
|
||||
|
||||
OSUnlockMutex(dirIter->dev->pMutex);
|
||||
|
||||
if(result < 0)
|
||||
{
|
||||
if (result < 0) {
|
||||
r->_errno = result;
|
||||
return -1;
|
||||
}
|
||||
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;
|
||||
if (!dirIter->dev) {
|
||||
r->_errno = ENODEV;
|
||||
@ -795,8 +752,7 @@ static int fs_dev_dirnext_r (struct _reent *r, DIR_ITER *dirState, char *filenam
|
||||
directoryEntry_s *dir_entry = malloc(sizeof(directoryEntry_s));
|
||||
|
||||
int result = IOSUHAX_FSA_ReadDir(dirIter->dev->fsaFd, dirIter->dirHandle, dir_entry);
|
||||
if(result < 0)
|
||||
{
|
||||
if (result < 0) {
|
||||
free(dir_entry);
|
||||
r->_errno = result;
|
||||
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
|
||||
strcpy(filename, dir_entry->name);
|
||||
|
||||
if(st)
|
||||
{
|
||||
if (st) {
|
||||
memset(st, 0, sizeof(struct stat));
|
||||
st->st_mode = (dir_entry->stat.flag & 0x80000000) ? S_IFDIR : S_IFREG;
|
||||
st->st_nlink = 1;
|
||||
@ -856,8 +811,7 @@ static const devoptab_t devops_fs = {
|
||||
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;
|
||||
char *devname = NULL;
|
||||
char *devpath = NULL;
|
||||
@ -928,8 +882,7 @@ static int fs_dev_add_device (const char *name, const char *mount_path, int fsaF
|
||||
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;
|
||||
char name[128] = {0};
|
||||
int i;
|
||||
@ -948,8 +901,7 @@ static int fs_dev_remove_device (const char *path)
|
||||
if (strcmp(name, devoptab->name) == 0) {
|
||||
devoptab_list[i] = devoptab_list[0];
|
||||
|
||||
if(devoptab->deviceData)
|
||||
{
|
||||
if (devoptab->deviceData) {
|
||||
fs_dev_private_t *priv = (fs_dev_private_t *) devoptab->deviceData;
|
||||
|
||||
if (priv->mounted)
|
||||
@ -969,17 +921,14 @@ static int fs_dev_remove_device (const char *path)
|
||||
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;
|
||||
|
||||
if(dev_path)
|
||||
{
|
||||
if (dev_path) {
|
||||
isMounted = 1;
|
||||
|
||||
int res = IOSUHAX_FSA_Mount(fsaFd, dev_path, mount_path, 2, 0, 0);
|
||||
if(res != 0)
|
||||
{
|
||||
if (res != 0) {
|
||||
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);
|
||||
}
|
||||
|
||||
int unmount_fs(const char *virt_name)
|
||||
{
|
||||
int unmount_fs(const char *virt_name) {
|
||||
return fs_dev_remove_device(virt_name);
|
||||
}
|
||||
|
@ -36,10 +36,8 @@ static int fsaFdUsb = 0;
|
||||
static int sdioFd = 0;
|
||||
static int usbFd = 0;
|
||||
|
||||
static void IOSUHAX_disc_io_initialize(void)
|
||||
{
|
||||
if(initialized == 0)
|
||||
{
|
||||
static void IOSUHAX_disc_io_initialize(void) {
|
||||
if (initialized == 0) {
|
||||
initialized = 1;
|
||||
fsaFdSd = -1;
|
||||
fsaFdUsb = -1;
|
||||
@ -48,27 +46,21 @@ 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();
|
||||
|
||||
if (IOSUHAX_Open(NULL) < 0)
|
||||
return false;
|
||||
|
||||
if(fsaFd == FSA_REF_SD)
|
||||
{
|
||||
if(fsaFdSd < 0)
|
||||
{
|
||||
if (fsaFd == FSA_REF_SD) {
|
||||
if (fsaFdSd < 0) {
|
||||
fsaFdSd = IOSUHAX_FSA_Open();
|
||||
}
|
||||
|
||||
if (fsaFdSd >= 0)
|
||||
return true;
|
||||
}
|
||||
else if(fsaFd == FSA_REF_USB)
|
||||
{
|
||||
if(fsaFdUsb < 0)
|
||||
{
|
||||
} else if (fsaFd == FSA_REF_USB) {
|
||||
if (fsaFdUsb < 0) {
|
||||
fsaFdUsb = IOSUHAX_FSA_Open();
|
||||
}
|
||||
|
||||
@ -79,36 +71,27 @@ static bool IOSUHAX_disc_io_fsa_open(int fsaFd)
|
||||
return false;
|
||||
}
|
||||
|
||||
static void IOSUHAX_disc_io_fsa_close(int fsaFd)
|
||||
{
|
||||
if(fsaFd == FSA_REF_SD)
|
||||
{
|
||||
if(fsaFdSd >= 0)
|
||||
{
|
||||
static void IOSUHAX_disc_io_fsa_close(int fsaFd) {
|
||||
if (fsaFd == FSA_REF_SD) {
|
||||
if (fsaFdSd >= 0) {
|
||||
IOSUHAX_FSA_Close(fsaFdSd);
|
||||
fsaFdSd = -1;
|
||||
}
|
||||
}
|
||||
else if(fsaFd == FSA_REF_USB)
|
||||
{
|
||||
if(fsaFdUsb >= 0)
|
||||
{
|
||||
} else if (fsaFd == FSA_REF_USB) {
|
||||
if (fsaFdUsb >= 0) {
|
||||
IOSUHAX_FSA_Close(fsaFdUsb);
|
||||
fsaFdUsb = -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static bool IOSUHAX_sdio_startup(void)
|
||||
{
|
||||
static bool IOSUHAX_sdio_startup(void) {
|
||||
if (!IOSUHAX_disc_io_fsa_open(FSA_REF_SD))
|
||||
return false;
|
||||
|
||||
if(sdioFd < 0)
|
||||
{
|
||||
if (sdioFd < 0) {
|
||||
int res = IOSUHAX_FSA_RawOpen(fsaFdSd, "/dev/sdcard01", &sdioFd);
|
||||
if(res < 0)
|
||||
{
|
||||
if (res < 0) {
|
||||
IOSUHAX_disc_io_fsa_close(FSA_REF_SD);
|
||||
sdioFd = -1;
|
||||
}
|
||||
@ -117,19 +100,16 @@ static bool IOSUHAX_sdio_startup(void)
|
||||
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()
|
||||
return initialized && (fsaFdSd >= 0) && (sdioFd >= 0);
|
||||
}
|
||||
|
||||
static bool IOSUHAX_sdio_clearStatus(void)
|
||||
{
|
||||
static bool IOSUHAX_sdio_clearStatus(void) {
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool IOSUHAX_sdio_shutdown(void)
|
||||
{
|
||||
static bool IOSUHAX_sdio_shutdown(void) {
|
||||
if (!IOSUHAX_sdio_isInserted())
|
||||
return false;
|
||||
|
||||
@ -139,28 +119,24 @@ static bool IOSUHAX_sdio_shutdown(void)
|
||||
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())
|
||||
return false;
|
||||
|
||||
int res = IOSUHAX_FSA_RawRead(fsaFdSd, buffer, 512, numSectors, sector, sdioFd);
|
||||
if(res < 0)
|
||||
{
|
||||
if (res < 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
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())
|
||||
return false;
|
||||
|
||||
int res = IOSUHAX_FSA_RawWrite(fsaFdSd, buffer, 512, numSectors, sector, sdioFd);
|
||||
if(res < 0)
|
||||
{
|
||||
if (res < 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -179,19 +155,15 @@ const DISC_INTERFACE IOSUHAX_sdio_disc_interface =
|
||||
IOSUHAX_sdio_shutdown
|
||||
};
|
||||
|
||||
static bool IOSUHAX_usb_startup(void)
|
||||
{
|
||||
static bool IOSUHAX_usb_startup(void) {
|
||||
if (!IOSUHAX_disc_io_fsa_open(FSA_REF_USB))
|
||||
return false;
|
||||
|
||||
if(usbFd < 0)
|
||||
{
|
||||
if (usbFd < 0) {
|
||||
int res = IOSUHAX_FSA_RawOpen(fsaFdUsb, "/dev/usb01", &usbFd);
|
||||
if(res < 0)
|
||||
{
|
||||
if (res < 0) {
|
||||
res = IOSUHAX_FSA_RawOpen(fsaFdUsb, "/dev/usb02", &usbFd);
|
||||
if(res < 0)
|
||||
{
|
||||
if (res < 0) {
|
||||
IOSUHAX_disc_io_fsa_close(FSA_REF_USB);
|
||||
usbFd = -1;
|
||||
}
|
||||
@ -200,18 +172,15 @@ static bool IOSUHAX_usb_startup(void)
|
||||
return (usbFd >= 0);
|
||||
}
|
||||
|
||||
static bool IOSUHAX_usb_isInserted(void)
|
||||
{
|
||||
static bool IOSUHAX_usb_isInserted(void) {
|
||||
return initialized && (fsaFdUsb >= 0) && (usbFd >= 0);
|
||||
}
|
||||
|
||||
static bool IOSUHAX_usb_clearStatus(void)
|
||||
{
|
||||
static bool IOSUHAX_usb_clearStatus(void) {
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool IOSUHAX_usb_shutdown(void)
|
||||
{
|
||||
static bool IOSUHAX_usb_shutdown(void) {
|
||||
if (!IOSUHAX_usb_isInserted())
|
||||
return false;
|
||||
|
||||
@ -221,28 +190,24 @@ static bool IOSUHAX_usb_shutdown(void)
|
||||
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())
|
||||
return false;
|
||||
|
||||
int res = IOSUHAX_FSA_RawRead(fsaFdUsb, buffer, 512, numSectors, sector, usbFd);
|
||||
if(res < 0)
|
||||
{
|
||||
if (res < 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
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())
|
||||
return false;
|
||||
|
||||
int res = IOSUHAX_FSA_RawWrite(fsaFdUsb, buffer, 512, numSectors, sector, usbFd);
|
||||
if(res < 0)
|
||||
{
|
||||
if (res < 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -11,14 +11,18 @@ extern "C" {
|
||||
//! Mutex functions
|
||||
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
extern void OSInitMutex(void *mutex);
|
||||
|
||||
extern void OSLockMutex(void *mutex);
|
||||
|
||||
extern void OSUnlockMutex(void *mutex);
|
||||
|
||||
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
//! 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_Open(char *path, unsigned int mode);
|
||||
|
||||
extern int IOS_Close(int fd);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
Loading…
x
Reference in New Issue
Block a user