From 147b055274bbd2d3dbb4003209d4bcd303368491 Mon Sep 17 00:00:00 2001 From: coah <100182500+coah80@users.noreply.github.com> Date: Wed, 30 Sep 2026 07:29:51 +0000 Subject: [PATCH] fa: 109 small filesystem units fully exact (156 functions) (worker 9aaaf7fc) --- README.md | 4 +- libs/RVL_SDK/include/private/fa/pf_kernel.h | 39 +++ libs/RVL_SDK/include/private/fa/puh_msc.h | 59 ++++ libs/RVL_SDK/include/revolution/fa/pf_stub.h | 33 ++ libs/RVL_SDK/src/fa/api/FAAttach.c | 100 ++++++ libs/RVL_SDK/src/fa/api/FABuffering.c | 8 + libs/RVL_SDK/src/fa/api/FACreate.c | 11 + libs/RVL_SDK/src/fa/api/FACreatedir.c | 8 + libs/RVL_SDK/src/fa/api/FADetach.c | 24 ++ libs/RVL_SDK/src/fa/api/FAErrnum.c | 11 + libs/RVL_SDK/src/fa/api/FAFopen.c | 11 + libs/RVL_SDK/src/fa/api/FAFormat.c | 8 + libs/RVL_SDK/src/fa/api/FAFseek.c | 8 + libs/RVL_SDK/src/fa/api/FAFsfirst.c | 8 + libs/RVL_SDK/src/fa/api/FAFsnext.c | 8 + libs/RVL_SDK/src/fa/api/FAFstat.c | 8 + libs/RVL_SDK/src/fa/api/FAGetdev.c | 8 + libs/RVL_SDK/src/fa/api/FAInit.c | 36 ++ libs/RVL_SDK/src/fa/api/FAMount.c | 8 + libs/RVL_SDK/src/fa/api/FARegistCB.c | 63 ++++ libs/RVL_SDK/src/fa/api/FARemove.c | 8 + libs/RVL_SDK/src/fa/api/FASetThreadPriority.c | 13 + libs/RVL_SDK/src/fa/api/FAUnmount.c | 17 + libs/RVL_SDK/src/fa/driver/msc_drv.c | 16 + libs/RVL_SDK/src/fa/driver/pfd_cmn.c | 39 +++ libs/RVL_SDK/src/fa/driver/sd_drv.c | 31 +- libs/RVL_SDK/src/fa/kernel/pfk_api.c | 121 +++++++ libs/RVL_SDK/src/fa/msc/puh_msc.c | 80 +++++ libs/RVL_SDK/src/fa/msc/puh_msc_blk.c | 318 ++++++++++++++++++ libs/RVL_SDK/src/fa/msc/puh_msc_cmd.c | 94 ++++++ libs/RVL_SDK/src/fa/pdm_api.c | 34 ++ libs/RVL_SDK/src/fa/pf_buffering.c | 8 + libs/RVL_SDK/src/fa/pf_cdelete.c | 33 ++ libs/RVL_SDK/src/fa/pf_chdmod.c | 32 ++ libs/RVL_SDK/src/fa/pf_chmod.c | 32 ++ libs/RVL_SDK/src/fa/pf_cinsert.c | 33 ++ libs/RVL_SDK/src/fa/pf_combine.c | 34 ++ libs/RVL_SDK/src/fa/pf_createdir.c | 32 ++ libs/RVL_SDK/src/fa/pf_cut.c | 36 ++ libs/RVL_SDK/src/fa/pf_derrnum.c | 8 + libs/RVL_SDK/src/fa/pf_divide.c | 34 ++ libs/RVL_SDK/src/fa/pf_fadjust.c | 8 + libs/RVL_SDK/src/fa/pf_fappend.c | 9 + libs/RVL_SDK/src/fa/pf_fchdir.c | 8 + libs/RVL_SDK/src/fa/pf_fconcat.c | 34 ++ libs/RVL_SDK/src/fa/pf_fsetclstlink.c | 8 + libs/RVL_SDK/src/fa/pf_fsexec.c | 8 + libs/RVL_SDK/src/fa/pf_getvol.c | 8 + libs/RVL_SDK/src/fa/pf_getvolcfg.c | 8 + libs/RVL_SDK/src/fa/pf_insert.c | 42 +++ libs/RVL_SDK/src/fa/pf_iswriteprotected.c | 13 + libs/RVL_SDK/src/fa/pf_move.c | 34 ++ libs/RVL_SDK/src/fa/pf_opendir.c | 34 ++ libs/RVL_SDK/src/fa/pf_readdir.c | 8 + libs/RVL_SDK/src/fa/pf_regctx.c | 8 + libs/RVL_SDK/src/fa/pf_rewinddir.c | 8 + libs/RVL_SDK/src/fa/pf_rmvvol.c | 8 + libs/RVL_SDK/src/fa/pf_seekdir.c | 8 + libs/RVL_SDK/src/fa/pf_setclstlink.c | 8 + libs/RVL_SDK/src/fa/pf_setcode.c | 8 + libs/RVL_SDK/src/fa/pf_setencode.c | 8 + libs/RVL_SDK/src/fa/pf_settailbuf.c | 8 + libs/RVL_SDK/src/fa/pf_setupfsi.c | 8 + libs/RVL_SDK/src/fa/pf_setvol.c | 30 ++ libs/RVL_SDK/src/fa/pf_setvolcfg.c | 8 + libs/RVL_SDK/src/fa/pf_stub.c | 152 +++++++++ libs/RVL_SDK/src/fa/pf_stub_standard.c | 272 +++++++++++++++ libs/RVL_SDK/src/fa/pf_stub_unicode.c | 106 ++++++ libs/RVL_SDK/src/fa/pf_telldir.c | 8 + libs/RVL_SDK/src/fa/pf_unregctx.c | 8 + libs/RVL_SDK/src/fa/pf_volume_apiadd.c | 241 +++++++++++++ libs/RVL_SDK/src/fa/pf_w_cdelete.c | 33 ++ libs/RVL_SDK/src/fa/pf_w_chdir.c | 32 ++ libs/RVL_SDK/src/fa/pf_w_chdmod.c | 32 ++ libs/RVL_SDK/src/fa/pf_w_chmod.c | 32 ++ libs/RVL_SDK/src/fa/pf_w_cinsert.c | 33 ++ libs/RVL_SDK/src/fa/pf_w_combine.c | 34 ++ libs/RVL_SDK/src/fa/pf_w_create.c | 34 ++ libs/RVL_SDK/src/fa/pf_w_createdir.c | 32 ++ libs/RVL_SDK/src/fa/pf_w_cut.c | 36 ++ libs/RVL_SDK/src/fa/pf_w_divide.c | 34 ++ libs/RVL_SDK/src/fa/pf_w_fconcat.c | 34 ++ libs/RVL_SDK/src/fa/pf_w_fopen.c | 41 +++ libs/RVL_SDK/src/fa/pf_w_fsexec.c | 8 + libs/RVL_SDK/src/fa/pf_w_fsfirst.c | 32 ++ libs/RVL_SDK/src/fa/pf_w_fsnext.c | 8 + libs/RVL_SDK/src/fa/pf_w_fstat.c | 32 ++ libs/RVL_SDK/src/fa/pf_w_insert.c | 42 +++ libs/RVL_SDK/src/fa/pf_w_mkdir.c | 32 ++ libs/RVL_SDK/src/fa/pf_w_move.c | 34 ++ libs/RVL_SDK/src/fa/pf_w_opendir.c | 34 ++ libs/RVL_SDK/src/fa/pf_w_remove.c | 32 ++ libs/RVL_SDK/src/fa/pf_w_rename.c | 34 ++ libs/RVL_SDK/src/fa/pf_w_rmdir.c | 32 ++ libs/RVL_SDK/src/fa/pf_w_xdivide.c | 34 ++ libs/RVL_SDK/src/fa/pf_xdivide.c | 34 ++ libs/RVL_SDK/src/fa/pfs_attach.c | 14 + libs/RVL_SDK/src/fa/pfs_buffering.c | 14 + libs/RVL_SDK/src/fa/pfs_create.c | 14 + libs/RVL_SDK/src/fa/pfs_createdir.c | 15 + libs/RVL_SDK/src/fa/pfs_detach.c | 13 + libs/RVL_SDK/src/fa/pfs_errnum.c | 12 + libs/RVL_SDK/src/fa/pfs_fclose.c | 13 + libs/RVL_SDK/src/fa/pfs_finfot.c | 14 + libs/RVL_SDK/src/fa/pfs_fopen.c | 14 + libs/RVL_SDK/src/fa/pfs_format.c | 14 + libs/RVL_SDK/src/fa/pfs_fread.c | 16 + libs/RVL_SDK/src/fa/pfs_fseek.c | 15 + libs/RVL_SDK/src/fa/pfs_fsfirst.c | 15 + libs/RVL_SDK/src/fa/pfs_fsnext.c | 13 + libs/RVL_SDK/src/fa/pfs_fstat.c | 14 + libs/RVL_SDK/src/fa/pfs_fwrite.c | 16 + libs/RVL_SDK/src/fa/pfs_getdev.c | 14 + libs/RVL_SDK/src/fa/pfs_init_prfile2.c | 7 + libs/RVL_SDK/src/fa/pfs_mount.c | 13 + libs/RVL_SDK/src/fa/pfs_remove.c | 13 + libs/RVL_SDK/src/fa/pfs_unmount.c | 14 + tools/decomp-assist/fa_zero_batch.attempts.md | 112 ++++++ 118 files changed, 3811 insertions(+), 18 deletions(-) create mode 100644 libs/RVL_SDK/include/private/fa/pf_kernel.h create mode 100644 libs/RVL_SDK/include/private/fa/puh_msc.h create mode 100644 libs/RVL_SDK/include/revolution/fa/pf_stub.h create mode 100644 libs/RVL_SDK/src/fa/api/FAAttach.c create mode 100644 libs/RVL_SDK/src/fa/api/FABuffering.c create mode 100644 libs/RVL_SDK/src/fa/api/FACreate.c create mode 100644 libs/RVL_SDK/src/fa/api/FACreatedir.c create mode 100644 libs/RVL_SDK/src/fa/api/FADetach.c create mode 100644 libs/RVL_SDK/src/fa/api/FAErrnum.c create mode 100644 libs/RVL_SDK/src/fa/api/FAFopen.c create mode 100644 libs/RVL_SDK/src/fa/api/FAFormat.c create mode 100644 libs/RVL_SDK/src/fa/api/FAFseek.c create mode 100644 libs/RVL_SDK/src/fa/api/FAFsfirst.c create mode 100644 libs/RVL_SDK/src/fa/api/FAFsnext.c create mode 100644 libs/RVL_SDK/src/fa/api/FAFstat.c create mode 100644 libs/RVL_SDK/src/fa/api/FAGetdev.c create mode 100644 libs/RVL_SDK/src/fa/api/FAInit.c create mode 100644 libs/RVL_SDK/src/fa/api/FAMount.c create mode 100644 libs/RVL_SDK/src/fa/api/FARegistCB.c create mode 100644 libs/RVL_SDK/src/fa/api/FARemove.c create mode 100644 libs/RVL_SDK/src/fa/api/FASetThreadPriority.c create mode 100644 libs/RVL_SDK/src/fa/api/FAUnmount.c create mode 100644 libs/RVL_SDK/src/fa/driver/msc_drv.c create mode 100644 libs/RVL_SDK/src/fa/driver/pfd_cmn.c create mode 100644 libs/RVL_SDK/src/fa/kernel/pfk_api.c create mode 100644 libs/RVL_SDK/src/fa/msc/puh_msc.c create mode 100644 libs/RVL_SDK/src/fa/msc/puh_msc_blk.c create mode 100644 libs/RVL_SDK/src/fa/msc/puh_msc_cmd.c create mode 100644 libs/RVL_SDK/src/fa/pdm_api.c create mode 100644 libs/RVL_SDK/src/fa/pf_buffering.c create mode 100644 libs/RVL_SDK/src/fa/pf_cdelete.c create mode 100644 libs/RVL_SDK/src/fa/pf_chdmod.c create mode 100644 libs/RVL_SDK/src/fa/pf_chmod.c create mode 100644 libs/RVL_SDK/src/fa/pf_cinsert.c create mode 100644 libs/RVL_SDK/src/fa/pf_combine.c create mode 100644 libs/RVL_SDK/src/fa/pf_createdir.c create mode 100644 libs/RVL_SDK/src/fa/pf_cut.c create mode 100644 libs/RVL_SDK/src/fa/pf_derrnum.c create mode 100644 libs/RVL_SDK/src/fa/pf_divide.c create mode 100644 libs/RVL_SDK/src/fa/pf_fadjust.c create mode 100644 libs/RVL_SDK/src/fa/pf_fappend.c create mode 100644 libs/RVL_SDK/src/fa/pf_fchdir.c create mode 100644 libs/RVL_SDK/src/fa/pf_fconcat.c create mode 100644 libs/RVL_SDK/src/fa/pf_fsetclstlink.c create mode 100644 libs/RVL_SDK/src/fa/pf_fsexec.c create mode 100644 libs/RVL_SDK/src/fa/pf_getvol.c create mode 100644 libs/RVL_SDK/src/fa/pf_getvolcfg.c create mode 100644 libs/RVL_SDK/src/fa/pf_insert.c create mode 100644 libs/RVL_SDK/src/fa/pf_iswriteprotected.c create mode 100644 libs/RVL_SDK/src/fa/pf_move.c create mode 100644 libs/RVL_SDK/src/fa/pf_opendir.c create mode 100644 libs/RVL_SDK/src/fa/pf_readdir.c create mode 100644 libs/RVL_SDK/src/fa/pf_regctx.c create mode 100644 libs/RVL_SDK/src/fa/pf_rewinddir.c create mode 100644 libs/RVL_SDK/src/fa/pf_rmvvol.c create mode 100644 libs/RVL_SDK/src/fa/pf_seekdir.c create mode 100644 libs/RVL_SDK/src/fa/pf_setclstlink.c create mode 100644 libs/RVL_SDK/src/fa/pf_setcode.c create mode 100644 libs/RVL_SDK/src/fa/pf_setencode.c create mode 100644 libs/RVL_SDK/src/fa/pf_settailbuf.c create mode 100644 libs/RVL_SDK/src/fa/pf_setupfsi.c create mode 100644 libs/RVL_SDK/src/fa/pf_setvol.c create mode 100644 libs/RVL_SDK/src/fa/pf_setvolcfg.c create mode 100644 libs/RVL_SDK/src/fa/pf_stub.c create mode 100644 libs/RVL_SDK/src/fa/pf_stub_standard.c create mode 100644 libs/RVL_SDK/src/fa/pf_stub_unicode.c create mode 100644 libs/RVL_SDK/src/fa/pf_telldir.c create mode 100644 libs/RVL_SDK/src/fa/pf_unregctx.c create mode 100644 libs/RVL_SDK/src/fa/pf_volume_apiadd.c create mode 100644 libs/RVL_SDK/src/fa/pf_w_cdelete.c create mode 100644 libs/RVL_SDK/src/fa/pf_w_chdir.c create mode 100644 libs/RVL_SDK/src/fa/pf_w_chdmod.c create mode 100644 libs/RVL_SDK/src/fa/pf_w_chmod.c create mode 100644 libs/RVL_SDK/src/fa/pf_w_cinsert.c create mode 100644 libs/RVL_SDK/src/fa/pf_w_combine.c create mode 100644 libs/RVL_SDK/src/fa/pf_w_create.c create mode 100644 libs/RVL_SDK/src/fa/pf_w_createdir.c create mode 100644 libs/RVL_SDK/src/fa/pf_w_cut.c create mode 100644 libs/RVL_SDK/src/fa/pf_w_divide.c create mode 100644 libs/RVL_SDK/src/fa/pf_w_fconcat.c create mode 100644 libs/RVL_SDK/src/fa/pf_w_fopen.c create mode 100644 libs/RVL_SDK/src/fa/pf_w_fsexec.c create mode 100644 libs/RVL_SDK/src/fa/pf_w_fsfirst.c create mode 100644 libs/RVL_SDK/src/fa/pf_w_fsnext.c create mode 100644 libs/RVL_SDK/src/fa/pf_w_fstat.c create mode 100644 libs/RVL_SDK/src/fa/pf_w_insert.c create mode 100644 libs/RVL_SDK/src/fa/pf_w_mkdir.c create mode 100644 libs/RVL_SDK/src/fa/pf_w_move.c create mode 100644 libs/RVL_SDK/src/fa/pf_w_opendir.c create mode 100644 libs/RVL_SDK/src/fa/pf_w_remove.c create mode 100644 libs/RVL_SDK/src/fa/pf_w_rename.c create mode 100644 libs/RVL_SDK/src/fa/pf_w_rmdir.c create mode 100644 libs/RVL_SDK/src/fa/pf_w_xdivide.c create mode 100644 libs/RVL_SDK/src/fa/pf_xdivide.c create mode 100644 libs/RVL_SDK/src/fa/pfs_attach.c create mode 100644 libs/RVL_SDK/src/fa/pfs_buffering.c create mode 100644 libs/RVL_SDK/src/fa/pfs_create.c create mode 100644 libs/RVL_SDK/src/fa/pfs_createdir.c create mode 100644 libs/RVL_SDK/src/fa/pfs_detach.c create mode 100644 libs/RVL_SDK/src/fa/pfs_errnum.c create mode 100644 libs/RVL_SDK/src/fa/pfs_fclose.c create mode 100644 libs/RVL_SDK/src/fa/pfs_finfot.c create mode 100644 libs/RVL_SDK/src/fa/pfs_fopen.c create mode 100644 libs/RVL_SDK/src/fa/pfs_format.c create mode 100644 libs/RVL_SDK/src/fa/pfs_fread.c create mode 100644 libs/RVL_SDK/src/fa/pfs_fseek.c create mode 100644 libs/RVL_SDK/src/fa/pfs_fsfirst.c create mode 100644 libs/RVL_SDK/src/fa/pfs_fsnext.c create mode 100644 libs/RVL_SDK/src/fa/pfs_fstat.c create mode 100644 libs/RVL_SDK/src/fa/pfs_fwrite.c create mode 100644 libs/RVL_SDK/src/fa/pfs_getdev.c create mode 100644 libs/RVL_SDK/src/fa/pfs_init_prfile2.c create mode 100644 libs/RVL_SDK/src/fa/pfs_mount.c create mode 100644 libs/RVL_SDK/src/fa/pfs_remove.c create mode 100644 libs/RVL_SDK/src/fa/pfs_unmount.c create mode 100644 tools/decomp-assist/fa_zero_batch.attempts.md diff --git a/README.md b/README.md index 72d21f4a..dd66159f 100644 --- a/README.md +++ b/README.md @@ -53,9 +53,9 @@ Progress | Decompiled | Matched | Linked | Data | |:---:|:---:|:---:|:---:| -| 92.68% | 81.49% | 57.21% | 88.99% | +| 93.26% | 82.01% | 57.21% | 89.10% | -units 768/1027 complete, functions 11732/12563 matched. +units 768/1027 complete, functions 11877/12563 matched. decompiled = code with a C/C++ implementation (objdiff fuzzy), matched = byte-exact code, linked = code actually linked into the DOL, data = byte-exact data diff --git a/libs/RVL_SDK/include/private/fa/pf_kernel.h b/libs/RVL_SDK/include/private/fa/pf_kernel.h new file mode 100644 index 00000000..65ff3ded --- /dev/null +++ b/libs/RVL_SDK/include/private/fa/pf_kernel.h @@ -0,0 +1,39 @@ +#ifndef FA_PF_KERNEL_H +#define FA_PF_KERNEL_H + +#include + +typedef struct PFK_TASK_CONFIG { + void* (*entry)(void*); + void* argument; + u32 stack_size; + void* stack; + s32 priority; + OSThread* thread; +} PFK_TASK_CONFIG; + +typedef struct PFK_MAILBOX_CONFIG { + OSMessageQueue* queue; + OSMessage* messages; + s32 count; +} PFK_MAILBOX_CONFIG; + +typedef struct PFK_SEMAPHORE_CONFIG { + u32 initial_count; + u32 maximum_count; + OSSemaphore* semaphore; +} PFK_SEMAPHORE_CONFIG; + +s32 pfk_create_task(PFK_TASK_CONFIG* config); +s32 pfk_start_task(s32 task_id); +s32 pfk_get_task_id(s32* task_id); +s32 pfk_set_task_priority(s32 task_id, s32 priority); +s32 pfk_create_mailbox(PFK_MAILBOX_CONFIG* config); +s32 pfk_receive_message(s32 mailbox, OSMessage* message); +s32 pfk_send_message(s32 mailbox, OSMessage message); +s32 pfk_create_semaphore(PFK_SEMAPHORE_CONFIG* config); +s32 pfk_delete_semaphore(s32 semaphore); +s32 pfk_get_semaphore(s32 semaphore); +s32 pfk_release_semaphore(s32 semaphore); + +#endif diff --git a/libs/RVL_SDK/include/private/fa/puh_msc.h b/libs/RVL_SDK/include/private/fa/puh_msc.h new file mode 100644 index 00000000..5ba5b5e3 --- /dev/null +++ b/libs/RVL_SDK/include/private/fa/puh_msc.h @@ -0,0 +1,59 @@ +#ifndef FA_PUH_MSC_H +#define FA_PUH_MSC_H + +#include + +typedef struct UHF_MSC_DEVICE { + FADisk* disk; + u32 device_id; + u32 interface_id; + u32 endpoint_in; + u32 endpoint_out; + u32 total_blocks; + u32 block_size; + u32 tag; + u32 lun; + u32 flags; + u32 status; + u32 event; +} UHF_MSC_DEVICE; + +typedef struct UHF_MSC_PARAMETERS { + UHF_MSC_DEVICE* device; + void* sense; + u32 timeout; + void* buffer; + u32 length; + u32 sector; + u16 transfer_flags; + u16 block_count; + u32 options; + u32 result_size; + FADisk* disk; +} UHF_MSC_PARAMETERS; + +typedef struct UHF_MSC_MESSAGE { + u32 command; + s32 semaphore; + s32* result; + UHF_MSC_PARAMETERS parameters; + void (*callback)(void*); + void* context; +} UHF_MSC_MESSAGE; + +extern UHF_MSC_DEVICE uhg_msc_blk_device_tbl[8]; +extern s32 uhg_msc_memid_8169971C; +s32 uhf_ker_set_priority(s32 task_id, s32 priority); +void* uhf_ker_get_memory_block(s32 pool, u32 size, u32 alignment); +s32 uhf_ker_release_memory_block(s32 pool, void* block); +s32 uhf_ker_create_sem(u32 initial_count, u32 maximum_count); +s32 uhf_ker_delete_sem(s32 semaphore); +s32 uhf_ker_get_sem(s32 semaphore); +s32 uhf_ker_send_message(s32 mailbox, void* message, u32 flags); +s32 uhf_ker_check_cacheable(void* buffer); +s32 usbh_msc_read10(UHF_MSC_DEVICE* device, u32 sector, u16 count, void* buffer, void* sense); +s32 usbh_msc_write10(UHF_MSC_DEVICE* device, u32 sector, u16 count, void* buffer, void* sense); +s32 uhf_msc_get_message_id(void); +s32 __uhf_msc_cmd_check_sense(const void* sense); + +#endif diff --git a/libs/RVL_SDK/include/revolution/fa/pf_stub.h b/libs/RVL_SDK/include/revolution/fa/pf_stub.h new file mode 100644 index 00000000..b7f9ea94 --- /dev/null +++ b/libs/RVL_SDK/include/revolution/fa/pf_stub.h @@ -0,0 +1,33 @@ +#ifndef FA_PF_STUB_H +#define FA_PF_STUB_H + +#include + +typedef union PF_STUB_RESULT { + s32 status; + u32 count; + void* stream; +} PF_STUB_RESULT; + +typedef struct PF_STUB_MESSAGE { + s32 task_id; + s32 operation; + s8 drive; + u32 value; + u32 count; + const void* object; + const void* data; + void* context; + u32 options; + s32 semaphore; + PF_STUB_RESULT* result_address; + FADisk* disk; + FAPartition* partition; + void (*callback)(s32, void*); + void* callback_context; + PF_STUB_RESULT result; +} PF_STUB_MESSAGE; + +extern s32 pfstub_com_massage(PF_STUB_MESSAGE* message); + +#endif diff --git a/libs/RVL_SDK/src/fa/api/FAAttach.c b/libs/RVL_SDK/src/fa/api/FAAttach.c new file mode 100644 index 00000000..39204214 --- /dev/null +++ b/libs/RVL_SDK/src/fa/api/FAAttach.c @@ -0,0 +1,100 @@ +#include +#include + +typedef struct FA_NAND_ATTACH { + char path[80]; + u32 size; +} FA_NAND_ATTACH; + +typedef struct FA_ATTACH_REQUEST { + FADrvTbl* table; + u32 count; +} FA_ATTACH_REQUEST; + +FADisk* gOpenDisk[26]; +FAPartition* gOpenPartition[26]; +typedef struct FA_DISK_INIT { + s32 (*initialize)(FADiskTbl*, u32); + u32 extension; +} FA_DISK_INIT; + +extern s32 pfd_sddrv_init_drv_tbl(FADiskTbl* table, u32 extension); +extern s32 usbh_msc_blk_init_drv_tbl(FADiskTbl* table, u32 extension); +extern s32 fa_nanddrv_init_drv_tbl(FADiskTbl* table, u32 extension); + +static FA_DISK_INIT diskInitTbl[] = { + {pfd_sddrv_init_drv_tbl, 0}, + {usbh_msc_blk_init_drv_tbl, 0}, + {fa_nanddrv_init_drv_tbl, 0}, +}; + +static struct { + FA_DISK_INIT* entries; + u32 count; +} drvInitFunc = {diskInitTbl, 3}; +extern s32 pdm_open_disk(FA_DISK_INIT* table, FADisk** disk); +extern s32 pdm_open_partition(FADisk* disk, u32 index, FAPartition** partition); +extern s32 pfstub_attach(FA_ATTACH_REQUEST* request, FA_NAND_ATTACH* nand); +extern s32 pfd_sddrv_is_media_insert(void); +extern s32 pfd_mscdrv_is_media_insert(void); + +FAError FAAttach(u32 device, char* nand_path, u32 nand_size, FADrvTbl* table) { + FADisk* disk; + FA_ATTACH_REQUEST request; + FA_NAND_ATTACH nand; + s32 error; + s32 index; + + if (device >= 4) { + return -2; + } + if (table == NULL) { + return -2; + } + if (device == 2 && nand_path == NULL) { + return -2; + } + if (device == 3 && table->pPart == NULL) { + return -2; + } + if (device <= 2) { + if (pdm_open_disk(&drvInitFunc.entries[(u8)device], &disk) != 0) { + return -1; + } + if (pdm_open_partition(disk, 0, &table->pPart) != 0) { + return -1; + } + } + request.table = table; + request.count = 0; + if (device == 2) { + memcpy(nand.path, nand_path, 78); + nand.size = nand_size; + } + if (device == 2) { + error = pfstub_attach(&request, &nand); + } else { + error = pfstub_attach(&request, NULL); + } + if (error != 0) { + return -1; + } + index = table->drive - 'A'; + if (device <= 2) { + gOpenDisk[index] = disk; + gOpenPartition[index] = table->pPart; + if (device == 0) { + if (pfd_sddrv_is_media_insert()) { + request.table->stat |= 0x10; + } + } else if (device == 1) { + if (pfd_mscdrv_is_media_insert()) { + request.table->stat |= 0x10; + } + } + } else { + gOpenDisk[index] = NULL; + gOpenPartition[index] = NULL; + } + return 0; +} diff --git a/libs/RVL_SDK/src/fa/api/FABuffering.c b/libs/RVL_SDK/src/fa/api/FABuffering.c new file mode 100644 index 00000000..b8fceba3 --- /dev/null +++ b/libs/RVL_SDK/src/fa/api/FABuffering.c @@ -0,0 +1,8 @@ +#include + +extern s32 pfstub_buffering(s8 drive, s32 mode); + +FAError FABuffering(s8 drive, s32 mode) { + s32 error = pfstub_buffering(drive, mode); + return (-error | error) >> 31; +} diff --git a/libs/RVL_SDK/src/fa/api/FACreate.c b/libs/RVL_SDK/src/fa/api/FACreate.c new file mode 100644 index 00000000..124bb25a --- /dev/null +++ b/libs/RVL_SDK/src/fa/api/FACreate.c @@ -0,0 +1,11 @@ +#include + +extern FAFILE* pfstub_create(const char* fileName, int mode); + +FAFILE* FACreate(const char* fileName, int mode) { + FAFILE* result = pfstub_create(fileName, mode); + if (result == NULL) { + result = NULL; + } + return result; +} diff --git a/libs/RVL_SDK/src/fa/api/FACreatedir.c b/libs/RVL_SDK/src/fa/api/FACreatedir.c new file mode 100644 index 00000000..6fd676d5 --- /dev/null +++ b/libs/RVL_SDK/src/fa/api/FACreatedir.c @@ -0,0 +1,8 @@ +#include + +extern s32 pfstub_createdir(const char* dirName, s32 mode, FADta* dta); + +s32 FACreatedir(const char* dirName, s32 mode, FADta* dta) { + s32 result = pfstub_createdir(dirName, mode, dta); + return (-result | result) >> 31; +} diff --git a/libs/RVL_SDK/src/fa/api/FADetach.c b/libs/RVL_SDK/src/fa/api/FADetach.c new file mode 100644 index 00000000..1e2df847 --- /dev/null +++ b/libs/RVL_SDK/src/fa/api/FADetach.c @@ -0,0 +1,24 @@ +#include + +extern FADisk* gOpenDisk[26]; +extern FAPartition* gOpenPartition[26]; +extern s32 pfstub_detach(s8 drive); +extern s32 pdm_close_partition(FAPartition* partition); +extern s32 pdm_close_disk(FADisk* disk); + +FAError FADetach(s8 drive) { + FADisk* disk = gOpenDisk[drive - 'A']; + FAPartition* partition = gOpenPartition[drive - 'A']; + if (pfstub_detach(drive) != 0) { + return -1; + } + if (disk != NULL && partition != NULL) { + if (pdm_close_partition(partition) != 0) { + return -1; + } + if (pdm_close_disk(disk) != 0) { + return -1; + } + } + return 0; +} diff --git a/libs/RVL_SDK/src/fa/api/FAErrnum.c b/libs/RVL_SDK/src/fa/api/FAErrnum.c new file mode 100644 index 00000000..91eba014 --- /dev/null +++ b/libs/RVL_SDK/src/fa/api/FAErrnum.c @@ -0,0 +1,11 @@ +#include + +extern s32 pfstub_errnum(void); + +FAError FAErrnum(void) { + s32 error = pfstub_errnum(); + if (error == 5) { + return 5; + } + return error == 0 ? 0 : error; +} diff --git a/libs/RVL_SDK/src/fa/api/FAFopen.c b/libs/RVL_SDK/src/fa/api/FAFopen.c new file mode 100644 index 00000000..d08a011c --- /dev/null +++ b/libs/RVL_SDK/src/fa/api/FAFopen.c @@ -0,0 +1,11 @@ +#include + +extern FAFILE* pfstub_fopen(const char* fileName, const char* mode); + +FAFILE* FAFopen(const char* fileName, const char* mode) { + FAFILE* result = pfstub_fopen(fileName, mode); + if (result == NULL) { + result = NULL; + } + return result; +} diff --git a/libs/RVL_SDK/src/fa/api/FAFormat.c b/libs/RVL_SDK/src/fa/api/FAFormat.c new file mode 100644 index 00000000..1f7b02a4 --- /dev/null +++ b/libs/RVL_SDK/src/fa/api/FAFormat.c @@ -0,0 +1,8 @@ +#include + +extern s32 pfstub_format(s8 drive, u32 mode); + +FAError FAFormat(s8 drive, u32 mode) { + s32 error = pfstub_format(drive, mode); + return (-error | error) >> 31; +} diff --git a/libs/RVL_SDK/src/fa/api/FAFseek.c b/libs/RVL_SDK/src/fa/api/FAFseek.c new file mode 100644 index 00000000..f20b04e1 --- /dev/null +++ b/libs/RVL_SDK/src/fa/api/FAFseek.c @@ -0,0 +1,8 @@ +#include + +extern s32 pfstub_fseek(FAFILE* stream, s32 offset, int origin); + +FAError FAFseek(FAFILE* stream, s32 offset, int origin) { + s32 error = pfstub_fseek(stream, offset, origin); + return (-error | error) >> 31; +} diff --git a/libs/RVL_SDK/src/fa/api/FAFsfirst.c b/libs/RVL_SDK/src/fa/api/FAFsfirst.c new file mode 100644 index 00000000..6e093c46 --- /dev/null +++ b/libs/RVL_SDK/src/fa/api/FAFsfirst.c @@ -0,0 +1,8 @@ +#include + +extern s32 pfstub_fsfirst(const char* dirName, u8 attr, FADta* dta); + +FAError FAFsfirst(const char* dirName, u8 attr, FADta* dta) { + s32 error = pfstub_fsfirst(dirName, attr, dta); + return (-error | error) >> 31; +} diff --git a/libs/RVL_SDK/src/fa/api/FAFsnext.c b/libs/RVL_SDK/src/fa/api/FAFsnext.c new file mode 100644 index 00000000..69b79df3 --- /dev/null +++ b/libs/RVL_SDK/src/fa/api/FAFsnext.c @@ -0,0 +1,8 @@ +#include + +extern s32 pfstub_fsnext(FADta* dta); + +FAError FAFsnext(FADta* dta) { + s32 error = pfstub_fsnext(dta); + return (-error | error) >> 31; +} diff --git a/libs/RVL_SDK/src/fa/api/FAFstat.c b/libs/RVL_SDK/src/fa/api/FAFstat.c new file mode 100644 index 00000000..e5a4ee82 --- /dev/null +++ b/libs/RVL_SDK/src/fa/api/FAFstat.c @@ -0,0 +1,8 @@ +#include + +extern s32 pfstub_fstat(const char* fileName, FAFileStat* stat); + +FAError FAFstat(const char* fileName, FAFileStat* stat) { + s32 error = pfstub_fstat(fileName, stat); + return (-error | error) >> 31; +} diff --git a/libs/RVL_SDK/src/fa/api/FAGetdev.c b/libs/RVL_SDK/src/fa/api/FAGetdev.c new file mode 100644 index 00000000..f7aa2c09 --- /dev/null +++ b/libs/RVL_SDK/src/fa/api/FAGetdev.c @@ -0,0 +1,8 @@ +#include + +extern s32 pfstub_devinf(s8 drive, FADevInf* data); + +FAError FAGetdev(s8 drive, FADevInf* data) { + s32 error = pfstub_devinf(drive, data); + return (-error | error) >> 31; +} diff --git a/libs/RVL_SDK/src/fa/api/FAInit.c b/libs/RVL_SDK/src/fa/api/FAInit.c new file mode 100644 index 00000000..13bd1246 --- /dev/null +++ b/libs/RVL_SDK/src/fa/api/FAInit.c @@ -0,0 +1,36 @@ +#include +#include + +char* __FAVersion = "<< RVL_SDK - FA \trelease build: Apr 20 2010 11:20:14 (0x4199_60831) >>"; +s32 FAFileSysInitialized; +s32 FAInInitializing; +extern s32 FADiskInitialized; +extern s32 pdm_init_diskmanager(s32 config, void* parameter); +extern s32 pfstub_init_prfile2(s32 config, void* parameter); + +FAError FAInit(int flag) { + s32 error; + if (FAInInitializing == 1) { + return -1; + } + FAInInitializing = 1; + if (!FADiskInitialized) { + error = pdm_init_diskmanager(0, NULL); + FADiskInitialized = error == 0; + if (error != 0) { + FAInInitializing = 0; + return -1; + } + } + if (!FAFileSysInitialized) { + error = pfstub_init_prfile2(flag, NULL); + FAFileSysInitialized = error == 0; + if (error == -1) { + FAInInitializing = 0; + return -1; + } + } + FAInInitializing = 0; + OSRegisterVersion(__FAVersion); + return 0; +} diff --git a/libs/RVL_SDK/src/fa/api/FAMount.c b/libs/RVL_SDK/src/fa/api/FAMount.c new file mode 100644 index 00000000..ce4803f7 --- /dev/null +++ b/libs/RVL_SDK/src/fa/api/FAMount.c @@ -0,0 +1,8 @@ +#include + +extern s32 pfstub_mount(s8 drive); + +FAError FAMount(s8 drive) { + s32 error = pfstub_mount(drive); + return (-error | error) >> 31; +} diff --git a/libs/RVL_SDK/src/fa/api/FARegistCB.c b/libs/RVL_SDK/src/fa/api/FARegistCB.c new file mode 100644 index 00000000..62b7bf14 --- /dev/null +++ b/libs/RVL_SDK/src/fa/api/FARegistCB.c @@ -0,0 +1,63 @@ +#include + +typedef struct FA_MEDIA_CALLBACKS { + FAInsertCallback sd_insert; + FAEjectCallback sd_eject; + FAInsertCallback usb_insert; + FAEjectCallback usb_eject; + u32 flags; +} FA_MEDIA_CALLBACKS; + +FA_MEDIA_CALLBACKS gMediaInOutCallback; +extern s32 pfd_sddrv_registar_callback(FAInsertCallback insert, FAEjectCallback eject); +extern s32 pfd_mscdrv_registar_callback(FAInsertCallback insert, FAEjectCallback eject); +void FANotifySDInsert(s8 drive); +void FANotifySDEject(s8 drive); +void FANotifyUSBInsert(s8 drive); +void FANotifyUSBEject(s8 drive); + +FAError FARegistCB(s32 device, FAInsertCallback insert, FAEjectCallback eject) { + s32 error; + switch (device) { + case 0: + gMediaInOutCallback.sd_insert = insert; + gMediaInOutCallback.sd_eject = eject; + error = pfd_sddrv_registar_callback(FANotifySDInsert, FANotifySDEject); + break; + case 1: + gMediaInOutCallback.usb_insert = insert; + gMediaInOutCallback.usb_eject = eject; + error = pfd_mscdrv_registar_callback(FANotifyUSBInsert, FANotifyUSBEject); + break; + default: + return -2; + } + if (error != 0) { + return -1; + } + return 0; +} + +void FANotifySDInsert(s8 drive) { + if (gMediaInOutCallback.sd_insert) { + gMediaInOutCallback.sd_insert(drive); + } +} + +void FANotifySDEject(s8 drive) { + if (gMediaInOutCallback.sd_eject) { + gMediaInOutCallback.sd_eject(drive); + } +} + +void FANotifyUSBInsert(s8 drive) { + if (gMediaInOutCallback.usb_insert) { + gMediaInOutCallback.usb_insert(drive); + } +} + +void FANotifyUSBEject(s8 drive) { + if (gMediaInOutCallback.usb_eject) { + gMediaInOutCallback.usb_eject(drive); + } +} diff --git a/libs/RVL_SDK/src/fa/api/FARemove.c b/libs/RVL_SDK/src/fa/api/FARemove.c new file mode 100644 index 00000000..77894dab --- /dev/null +++ b/libs/RVL_SDK/src/fa/api/FARemove.c @@ -0,0 +1,8 @@ +#include + +extern s32 pfstub_remove(const char* fileName); + +FAError FARemove(const char* fileName) { + s32 error = pfstub_remove(fileName); + return (-error | error) >> 31; +} diff --git a/libs/RVL_SDK/src/fa/api/FASetThreadPriority.c b/libs/RVL_SDK/src/fa/api/FASetThreadPriority.c new file mode 100644 index 00000000..ef25bdb2 --- /dev/null +++ b/libs/RVL_SDK/src/fa/api/FASetThreadPriority.c @@ -0,0 +1,13 @@ +#include + +extern s32 pfstub_set_stub_priority(s32 priority); +extern s32 usbh_msc_set_thread_priority(s32 priority); + +FAError FASetThreadPriority(s32 priority) { + s32 error = pfstub_set_stub_priority(priority); + if (error != 0) { + return error == -2 ? -2 : -1; + } + error = usbh_msc_set_thread_priority(priority); + return (-error | error) >> 31; +} diff --git a/libs/RVL_SDK/src/fa/api/FAUnmount.c b/libs/RVL_SDK/src/fa/api/FAUnmount.c new file mode 100644 index 00000000..fa12026a --- /dev/null +++ b/libs/RVL_SDK/src/fa/api/FAUnmount.c @@ -0,0 +1,17 @@ +#include + +extern s32 pfstub_unmount(s8 drive, u32 force); + +FAError FAUnmount(s8 drive, u32 force) { + s32 error = pfstub_unmount(drive, force); + if (error == -1) { + error = -1; + } else if (error == 1) { + error = 1; + } else if (error == 0) { + error = 0; + } else { + error = -1; + } + return error; +} diff --git a/libs/RVL_SDK/src/fa/driver/msc_drv.c b/libs/RVL_SDK/src/fa/driver/msc_drv.c new file mode 100644 index 00000000..5b07f714 --- /dev/null +++ b/libs/RVL_SDK/src/fa/driver/msc_drv.c @@ -0,0 +1,16 @@ +#include + +static FAInsertCallback g_attach_func; +static FAEjectCallback g_detach_func; + +extern s32 uhf_msc_is_media_insert(void); + +s32 pfd_mscdrv_registar_callback(FAInsertCallback insert, FAEjectCallback eject) { + g_attach_func = insert; + g_detach_func = eject; + return 0; +} + +s32 pfd_mscdrv_is_media_insert(void) { + return uhf_msc_is_media_insert(); +} diff --git a/libs/RVL_SDK/src/fa/driver/pfd_cmn.c b/libs/RVL_SDK/src/fa/driver/pfd_cmn.c new file mode 100644 index 00000000..8197d041 --- /dev/null +++ b/libs/RVL_SDK/src/fa/driver/pfd_cmn.c @@ -0,0 +1,39 @@ +#include +#include + +extern PF_VOLUME_SET pf_vol_set; +extern pf_s32 pdm_part_is_attached_partition(PDM_PARTITION* partition); + +pf_u8 pfd_get_media_drv_char(PDM_DISK* disk, pf_s8* drives, pf_u32 capacity) { + pf_u32 partition_index; + PDM_PARTITION* partition; + PF_VOLUME* volume; + pf_u8 count; + pf_s8* next_drive; + pf_u32 volume_index; + if (drives == NULL || capacity == 0) { + return 0; + } + next_drive = drives; + count = 0; + partition = pdm_disk_set.partition; + for (partition_index = 0; partition_index < 26; partition_index++, partition++) { + if (pdm_part_is_attached_partition(partition) && partition->p_disk == disk) { + volume = pf_vol_set.volumes; + for (volume_index = 0; volume_index < 26; volume++) { + volume_index++; + if (volume->p_part == partition) { + count++; + *next_drive++ = volume->drv_char; + if (count == capacity) { + break; + } + } + } + } + if (count == capacity) { + break; + } + } + return count; +} diff --git a/libs/RVL_SDK/src/fa/driver/sd_drv.c b/libs/RVL_SDK/src/fa/driver/sd_drv.c index 97c02dcc..9292606a 100644 --- a/libs/RVL_SDK/src/fa/driver/sd_drv.c +++ b/libs/RVL_SDK/src/fa/driver/sd_drv.c @@ -1030,13 +1030,13 @@ s32 pfd_sddrv_build_mbr_bpb(u32 total_sectors) { } s32 pfd_sddrv_calc_fat32_mbr_bpb(PFD_SDDRV_FORMAT_DATA* format_data) { - PFD_SDDRV_SIZE_SETTINGS settings; - const PFD_SDDRV_SIZE_DEPEND* size_entry; - u32 entry_index; - u32 cluster_count; - u32 fat_sectors; - u32 fat_sector_count; u32 available_sectors; + u32 fat_sector_count; + u32 fat_sectors; + u32 cluster_count; + u32 entry_index; + const PFD_SDDRV_SIZE_DEPEND* size_entry; + PFD_SDDRV_SIZE_SETTINGS settings; u32 reserved_sectors = 0; u32 data_start_sector; u32 calculated_fat_sectors; @@ -1153,7 +1153,7 @@ s32 pfd_sddrv_store_fat32_mbr_buf(PFD_SDDRV_FORMAT_DATA* format_data, u8* sector } pf_memset(&settings, 0, 0x10); size_entry = sddrv_size_depend_tbl; - for (entry_index = 0; entry_index < 14; entry_index++, size_entry++) { + for (entry_index = 0; entry_index < 14; size_entry++, entry_index++) { if (size_entry->min_sectors < format_data->total_sectors && format_data->total_sectors <= size_entry->max_sectors) { settings.reserved_sectors = sddrv_size_depend_tbl[entry_index].reserved_sectors; settings.fat_copies = sddrv_size_depend_tbl[entry_index].fat_copies; @@ -1430,11 +1430,10 @@ s32 pfd_sddrv_build_fat32_mbr_bpb(u32 total_sectors) { } s32 pfd_sddrv_full_format(void) { - s32 result; - u32 retry_count; - u16 bytes_per_sector; - u32 total_sectors; + FADiskInfo geometry; u32 status; + u32 retry_count; + s32 result; retry_count = 0; do { @@ -1466,21 +1465,21 @@ s32 pfd_sddrv_full_format(void) { if (g_pfd_sddrv_info.media_ejected != 0) { return -33; } - result = pfd_sddrv_get_total_sectors(&total_sectors, &bytes_per_sector); + result = pfd_sddrv_get_total_sectors(&geometry.totalSectors, &geometry.bytesPerSector); if (result != 0) { OSReport("ERR Failed to get total sectors. pfd_sddrv_get_total_sectors()\n"); return result; } if ((status & 0x10000) != 0 && (status & 0x100000) == 0) { - if (total_sectors > 0x400000) { + if (geometry.totalSectors > 0x400000) { return -34; } - result = pfd_sddrv_build_mbr_bpb(total_sectors); + result = pfd_sddrv_build_mbr_bpb(geometry.totalSectors); } else if ((status & 0x10000) != 0 && (status & 0x100000) != 0) { - if (total_sectors > 0x4000000) { + if (geometry.totalSectors > 0x4000000) { return -34; } - result = pfd_sddrv_build_fat32_mbr_bpb(total_sectors); + result = pfd_sddrv_build_fat32_mbr_bpb(geometry.totalSectors); } else { return -31; } diff --git a/libs/RVL_SDK/src/fa/kernel/pfk_api.c b/libs/RVL_SDK/src/fa/kernel/pfk_api.c new file mode 100644 index 00000000..7407a084 --- /dev/null +++ b/libs/RVL_SDK/src/fa/kernel/pfk_api.c @@ -0,0 +1,121 @@ +#include + +s32 pfk_create_task(PFK_TASK_CONFIG* config) { + if (config == NULL) { + OSReport("prfile2:ERR pfk_create_task() invalid param\n"); + return 0; + } + if (!OSCreateThread(config->thread, config->entry, config->argument, + (u8*)config->stack + config->stack_size, config->stack_size, + config->priority, 0)) { + OSReport("prfile2:ERR pfk_create_task() failed to create thread\n"); + return 0; + } + return (s32)config->thread; +} + +s32 pfk_start_task(s32 task_id) { + if (task_id == 0) { + OSReport("prfile2:ERR pfk_start_task() invalid tsk_id\n"); + return -2; + } + if (OSIsThreadSuspended((OSThread*)task_id) == TRUE) { + OSResumeThread((OSThread*)task_id); + } + return 0; +} + +s32 pfk_get_task_id(s32* task_id) { + OSThread* thread; + if (task_id == NULL) { + OSReport("prfile2:ERR pfk_get_task_id() invalid param\n"); + return -2; + } + thread = OSGetCurrentThread(); + if (thread == NULL) { + OSReport("INFO failed to OSGetCurrentThread\n"); + *task_id = 0; + return -3; + } + *task_id = (s32)thread; + return 0; +} + +s32 pfk_set_task_priority(s32 task_id, s32 priority) { + if (priority < 0 || priority > 31) { + return -2; + } + return OSSetThreadPriority((OSThread*)task_id, priority) == TRUE ? 0 : -3; +} + +s32 pfk_create_mailbox(PFK_MAILBOX_CONFIG* config) { + if (config == NULL || config->queue == NULL || config->messages == NULL) { + OSReport("prfile2:ERR pfk_create_mailbox() Invalid Param\n"); + return 0; + } + OSInitMessageQueue(config->queue, config->messages, config->count); + return (s32)config->queue; +} + +s32 pfk_receive_message(s32 mailbox, OSMessage* message) { + if (mailbox == 0) { + OSReport("prfile2:ERR pfk_receive_message() Invalid Param\n"); + return -2; + } + if (!OSReceiveMessage((OSMessageQueue*)mailbox, message, OS_MESSAGE_BLOCK)) { + OSReport("prfile2:ERR pfk_receive_message() Faile to OSReceiveMessage()\n"); + return -3; + } + return 0; +} + +s32 pfk_send_message(s32 mailbox, OSMessage message) { + if (mailbox == 0 || message == NULL) { + OSReport("prfile2:ERR pfk_send_message() Invalid Param\n"); + return -2; + } + if (!OSSendMessage((OSMessageQueue*)mailbox, message, 0)) { + OSReport("prfile2:ERR pfk_send_message() Failed to pfk_send_message()\n"); + return -3; + } + return 0; +} + +s32 pfk_create_semaphore(PFK_SEMAPHORE_CONFIG* config) { + u32 count; + if (config == NULL || config->semaphore == NULL || config->initial_count > config->maximum_count) { + OSReport("prfile2:ERR pfk_create_semaphore() Invalid Param\n"); + return 0; + } + OSInitSemaphore(config->semaphore, config->maximum_count); + for (count = config->maximum_count - config->initial_count; count != 0; count--) { + OSWaitSemaphore(config->semaphore); + } + return (s32)config->semaphore; +} + +s32 pfk_delete_semaphore(s32 semaphore) { + if (semaphore == 0) { + OSReport("prfile2:ERR pfk_delete_semaphore() Invalid Param\n"); + return -2; + } + return 0; +} + +s32 pfk_get_semaphore(s32 semaphore) { + if (semaphore == 0) { + OSReport("prfile2:ERR pfk_get_semaphore() Invalid Param\n"); + return -2; + } + OSWaitSemaphore((OSSemaphore*)semaphore); + return 0; +} + +s32 pfk_release_semaphore(s32 semaphore) { + if (semaphore == 0) { + OSReport("prfile2:ERR pfk_release_semaphore() Invalid Param\n"); + return -2; + } + OSSignalSemaphore((OSSemaphore*)semaphore); + return 0; +} diff --git a/libs/RVL_SDK/src/fa/msc/puh_msc.c b/libs/RVL_SDK/src/fa/msc/puh_msc.c new file mode 100644 index 00000000..c16aef49 --- /dev/null +++ b/libs/RVL_SDK/src/fa/msc/puh_msc.c @@ -0,0 +1,80 @@ +#include + +static s32 st_uhs_msc_status; +static s32 st_uhs_msc_msgid; +static s32 st_uhs_msc_tskid; +s32 uhg_msc_memid_8169971C; +static s32 _uhf_msc_api_send_message(UHF_MSC_PARAMETERS* parameters, u32 command); + +s32 usbh_msc_read10(UHF_MSC_DEVICE* device, u32 sector, u16 count, void* buffer, void* sense) { + UHF_MSC_PARAMETERS parameters = {0}; + if (st_uhs_msc_status != 1) { + return -3; + } + parameters.device = device; + parameters.sector = sector; + parameters.block_count = count; + parameters.buffer = buffer; + parameters.sense = sense; + return _uhf_msc_api_send_message(¶meters, 0x1010a00); +} + +s32 usbh_msc_write10(UHF_MSC_DEVICE* device, u32 sector, u16 count, void* buffer, void* sense) { + UHF_MSC_PARAMETERS parameters = {0}; + if (st_uhs_msc_status != 1) { + return -3; + } + parameters.device = device; + parameters.sector = sector; + parameters.block_count = count; + parameters.buffer = buffer; + parameters.sense = sense; + return _uhf_msc_api_send_message(¶meters, 0x1010b00); +} + +s32 usbh_msc_set_thread_priority(s32 priority) { + s32 error; + if (st_uhs_msc_tskid != 0) { + error = uhf_ker_set_priority(st_uhs_msc_tskid, priority); + if (error != 0) { + return error; + } + } + return 0; +} + +static s32 _uhf_msc_api_send_message(UHF_MSC_PARAMETERS* parameters, u32 command) { + s32 result = 0; + s32 semaphore; + UHF_MSC_MESSAGE* message; + message = uhf_ker_get_memory_block(uhg_msc_memid_8169971C, sizeof(UHF_MSC_MESSAGE), 4); + if (message == NULL) { + return -12; + } + semaphore = uhf_ker_create_sem(0, 0); + if (semaphore <= 0) { + uhf_ker_release_memory_block(uhg_msc_memid_8169971C, message); + return -12; + } + message->command = command; + message->semaphore = semaphore; + message->result = &result; + message->parameters = *parameters; + if (uhf_ker_send_message(st_uhs_msc_msgid, message, 0) != 0) { + uhf_ker_release_memory_block(uhg_msc_memid_8169971C, message); + uhf_ker_delete_sem(semaphore); + return -12; + } + if (uhf_ker_get_sem(semaphore) != 0) { + uhf_ker_delete_sem(semaphore); + return -12; + } + if (uhf_ker_delete_sem(semaphore) != 0) { + return -12; + } + return result; +} + +s32 uhf_msc_get_message_id(void) { + return st_uhs_msc_msgid; +} diff --git a/libs/RVL_SDK/src/fa/msc/puh_msc_blk.c b/libs/RVL_SDK/src/fa/msc/puh_msc_blk.c new file mode 100644 index 00000000..df946377 --- /dev/null +++ b/libs/RVL_SDK/src/fa/msc/puh_msc_blk.c @@ -0,0 +1,318 @@ +#include +#include + +UHF_MSC_DEVICE uhg_msc_blk_device_tbl[8]; +static u8* st_uhs_msc_blk_buf; +extern void pdm_disk_notify_media_insert(FADisk* disk); +s32 uhf_msc_blk_init(FADisk* disk); +s32 uhf_msc_blk_finalize(FADisk* disk); +s32 uhf_msc_blk_mount(FADisk* disk); +s32 uhf_msc_blk_unmount(FADisk* disk); +s32 uhf_msc_blk_format(FADisk* disk, u8* format); +s32 uhf_msc_blk_pread(FADisk* disk, u8* buffer, u32 sector, u32 blocks, u32* completed); +s32 uhf_msc_blk_pwrite(FADisk* disk, u8* buffer, u32 sector, u32 blocks, u32* completed); +s32 uhf_msc_blk_get_disk_info(FADisk* disk, FADiskInfo* info); +s32 _uhf_msc_blk_send_message(UHF_MSC_PARAMETERS* parameters, u32 command); + +FAFuncTbl st_uhs_msc_blk_func = { + uhf_msc_blk_init, + uhf_msc_blk_finalize, + uhf_msc_blk_mount, + uhf_msc_blk_unmount, + uhf_msc_blk_format, + uhf_msc_blk_pread, + uhf_msc_blk_pwrite, + uhf_msc_blk_get_disk_info, +}; + +static inline UHF_MSC_DEVICE* uhf_msc_blk_find_device(FADisk* disk) { + UHF_MSC_DEVICE* entry = uhg_msc_blk_device_tbl; + UHF_MSC_DEVICE* device = NULL; + u32 index; + for (index = 0; index < 8; entry++, index++) { + if (entry->disk == disk) { + device = &uhg_msc_blk_device_tbl[index]; + break; + } + } + return device; +} + +s32 usbh_msc_blk_init_drv_tbl(FADiskTbl* table, u32 extension) { + if (table == NULL) { + return -1; + } + table->uiExt = extension; + table->pFunc = (FAFuncTbl*)&st_uhs_msc_blk_func; + return 0; +} + +s32 uhf_msc_blk_init(FADisk* disk) { + UHF_MSC_PARAMETERS parameters = {0}; + parameters.disk = disk; + return _uhf_msc_blk_send_message(¶meters, 0x1010005); +} + +s32 uhf_msc_blk_get_disk_info(FADisk* disk, FADiskInfo* info) { + UHF_MSC_DEVICE* device; + if (disk == NULL || info == NULL) { + return -1; + } + device = uhf_msc_blk_find_device(disk); + if (device == NULL) { + return -1; + } + info->totalSectors = device->total_blocks; + info->cylinders = 0; + info->heads = 0; + info->sectorsPerTrack = 0; + info->bytesPerSector = device->block_size; + info->mediaAttr = 0; + if (device->flags & 0x1000) { + info->mediaAttr |= 1; + } + info->formatParam = NULL; + return 0; +} + +s32 uhf_msc_blk_mount(FADisk* disk) { + UHF_MSC_DEVICE* device; + if (disk == NULL) { + return -1; + } + device = uhf_msc_blk_find_device(disk); + if (device == NULL) { + return -1; + } + return ((device->flags >> 2) & 1) - 1; +} + +s32 uhf_msc_blk_pread(FADisk* disk, u8* buffer, u32 sector, u32 blocks, u32* completed) { + u16 transfer_blocks; + UHF_MSC_DEVICE* device; + s32 error; + u32 block_size; + u8* transfer_buffer; + u32 transfer_limit; + s32 cacheable; + u8 sense[3] = {0}; + + *completed = 0; + if (disk == NULL || buffer == NULL) { + return -1; + } + if (blocks == 0) { + return 0; + } + device = uhf_msc_blk_find_device(disk); + if (device == NULL) { + return -1; + } + if (!(device->flags & 4)) { + return -1; + } + block_size = device->block_size; + if (block_size == 0) { + return -1; + } + if (uhf_ker_check_cacheable(buffer) == 0) { + transfer_limit = 512 / block_size; + if (transfer_limit == 0) { + return -1; + } + memset(st_uhs_msc_blk_buf, 0, 512); + cacheable = 0; + transfer_buffer = st_uhs_msc_blk_buf; + } else { + transfer_limit = 65536 / block_size; + cacheable = 1; + transfer_buffer = buffer; + } + do { + transfer_blocks = transfer_limit; + if (blocks <= transfer_limit) { + transfer_blocks = blocks; + } + error = usbh_msc_read10(device, sector, transfer_blocks, transfer_buffer, sense); + if (error == 0) { + if (!cacheable) { + memcpy(buffer, transfer_buffer, transfer_blocks * block_size); + buffer += transfer_blocks * block_size; + } else { + transfer_buffer += transfer_blocks * block_size; + } + blocks -= transfer_blocks; + sector += transfer_blocks; + *completed += transfer_blocks; + if (blocks == 0) { + break; + } + } else { + if (error == -15) { + switch (__uhf_msc_cmd_check_sense(sense)) { + case 11: + break; + case 34: + if (device->disk != NULL) { + pdm_disk_notify_media_insert(device->disk); + } + break; + default: + break; + } + error = -1; + break; + } else { + error = -1; + break; + } + } + } while (1); + return error; +} + +s32 uhf_msc_blk_pwrite(FADisk* disk, u8* buffer, u32 sector, u32 blocks, u32* completed) { + u16 transfer_blocks; + UHF_MSC_DEVICE* device; + u32 block_size; + s32 error; + u8* transfer_buffer; + u32 transfer_limit; + s32 cacheable; + u8 sense[3] = {0}; + + *completed = 0; + if (disk == NULL || buffer == NULL) { + return -1; + } + if (blocks == 0) { + return 0; + } + device = uhf_msc_blk_find_device(disk); + if (device == NULL) { + return -1; + } + if (!(device->flags & 4)) { + return -1; + } + block_size = device->block_size; + if (block_size == 0) { + return -1; + } + if (uhf_ker_check_cacheable(buffer) == 0) { + transfer_limit = 512 / block_size; + if (transfer_limit == 0) { + return -1; + } + cacheable = 0; + transfer_buffer = st_uhs_msc_blk_buf; + } else { + transfer_limit = 65536 / block_size; + cacheable = 1; + transfer_buffer = buffer; + } + do { + transfer_blocks = transfer_limit; + if (blocks <= transfer_limit) { + transfer_blocks = blocks; + } + if (!cacheable) { + memcpy(transfer_buffer, buffer, transfer_blocks * block_size); + } + error = usbh_msc_write10(device, sector, transfer_blocks, transfer_buffer, sense); + if (error == 0) { + if (!cacheable) { + buffer += transfer_blocks * block_size; + } + if (cacheable) { + transfer_buffer += transfer_blocks * block_size; + } + blocks -= transfer_blocks; + sector += transfer_blocks; + *completed += transfer_blocks; + if (blocks == 0) { + break; + } + } else { + if (error == -15) { + switch (__uhf_msc_cmd_check_sense(sense)) { + case 11: + case 37: + break; + case 34: + if (device->disk != NULL) { + pdm_disk_notify_media_insert(device->disk); + } + break; + default: + break; + } + error = -1; + break; + } else { + error = -1; + break; + } + } + } while (1); + return error; +} + +s32 uhf_msc_blk_format(FADisk* disk, u8* format) { + return disk == NULL ? -1 : 0; +} + +s32 uhf_msc_blk_finalize(FADisk* disk) { + UHF_MSC_PARAMETERS parameters = {0}; + parameters.disk = disk; + return _uhf_msc_blk_send_message(¶meters, 0x1010006); +} + +s32 uhf_msc_blk_unmount(FADisk* disk) { + return disk == NULL ? -1 : 0; +} + +s32 uhf_msc_is_media_insert(FADisk* disk) { + UHF_MSC_DEVICE* device = uhf_msc_blk_find_device(disk); + if (device == NULL) { + return 0; + } + if (!(device->flags & 4)) { + return 0; + } + pdm_disk_notify_media_insert(disk); + return 1; +} + +s32 _uhf_msc_blk_send_message(UHF_MSC_PARAMETERS* parameters, u32 command) { + s32 result = 0; + s32 semaphore; + UHF_MSC_MESSAGE* message; + s32 mailbox = uhf_msc_get_message_id(); + message = uhf_ker_get_memory_block(uhg_msc_memid_8169971C, sizeof(UHF_MSC_MESSAGE), 4); + if (message == NULL) { + return -1; + } + semaphore = uhf_ker_create_sem(0, 0); + if (semaphore <= 0) { + uhf_ker_release_memory_block(uhg_msc_memid_8169971C, message); + return -1; + } + message->command = command; + message->semaphore = semaphore; + message->result = &result; + message->parameters = *parameters; + if (uhf_ker_send_message(mailbox, message, 0) != 0) { + uhf_ker_release_memory_block(uhg_msc_memid_8169971C, message); + uhf_ker_delete_sem(semaphore); + return -1; + } + if (uhf_ker_get_sem(semaphore) != 0) { + uhf_ker_delete_sem(semaphore); + return -1; + } + if (uhf_ker_delete_sem(semaphore) != 0) { + return -1; + } + return result; +} diff --git a/libs/RVL_SDK/src/fa/msc/puh_msc_cmd.c b/libs/RVL_SDK/src/fa/msc/puh_msc_cmd.c new file mode 100644 index 00000000..b13a3f0e --- /dev/null +++ b/libs/RVL_SDK/src/fa/msc/puh_msc_cmd.c @@ -0,0 +1,94 @@ +#include + +typedef struct UHF_MSC_SENSE { + u8 key; + u8 code; + u8 qualifier; +} UHF_MSC_SENSE; + +s32 __uhf_msc_cmd_check_sense(const UHF_MSC_SENSE* sense) { + s32 code = (sense->key << 16) | (sense->code << 8) | sense->qualifier; + switch (code) { + case 0x0: + return 0; + case 0x11701: + return 1; + case 0x11800: + return 2; + case 0x20401: + return 3; + case 0x20402: + return 4; + case 0x20404: + return 5; + case 0x204ff: + return 6; + case 0x20600: + return 7; + case 0x20800: + return 8; + case 0x20801: + return 9; + case 0x20880: + return 10; + case 0x23a00: + return 11; + case 0x25400: + return 12; + case 0x28000: + return 13; + case 0x2ffff: + return 14; + case 0x30200: + return 15; + case 0x30300: + return 16; + case 0x31000: + return 17; + case 0x31100: + return 18; + case 0x31200: + return 19; + case 0x31300: + return 20; + case 0x31400: + return 21; + case 0x33001: + return 22; + case 0x33101: + return 23; + case 0x51a00: + return 25; + case 0x52000: + return 26; + case 0x52100: + return 27; + case 0x52400: + return 28; + case 0x52500: + return 29; + case 0x52600: + return 30; + case 0x52601: + return 31; + case 0x52602: + return 32; + case 0x53900: + return 33; + case 0x62800: + return 34; + case 0x62900: + return 35; + case 0x62f00: + return 36; + case 0x72700: + return 37; + case 0xb4e00: + return 38; + default: + if ((u32)((sense->key << 8) | sense->code) == 0x0440) { + return 24; + } + return 39; + } +} diff --git a/libs/RVL_SDK/src/fa/pdm_api.c b/libs/RVL_SDK/src/fa/pdm_api.c new file mode 100644 index 00000000..67e3ae9d --- /dev/null +++ b/libs/RVL_SDK/src/fa/pdm_api.c @@ -0,0 +1,34 @@ +#include + +extern s32 pdm_disk_init_disk_manager(s32 config, void* parameter); +extern s32 pdm_disk_add_disk(FADiskTbl* table, FADisk** disk); +extern s32 pdm_disk_del_disk(FADisk* disk); +extern s32 pdm_part_get_partition(FADisk* disk, u16 index, FAPartition** partition); +extern s32 pdm_part_release_partition(FAPartition* partition); + +s32 pdm_init_diskmanager(s32 config, void* parameter) { + return pdm_disk_init_disk_manager(config, parameter); +} + +s32 pdm_open_disk(FADiskTbl* table, FADisk** disk) { + s32 error; + *disk = NULL; + error = pdm_disk_add_disk(table, disk); + return error != 0 ? error : 0; +} + +s32 pdm_close_disk(FADisk* disk) { + return pdm_disk_del_disk(disk); +} + +s32 pdm_open_partition(FADisk* disk, u16 index, FAPartition** partition) { + s32 error; + *partition = NULL; + error = pdm_part_get_partition(disk, index, partition); + return error != 0 ? error : 0; +} + +s32 pdm_close_partition(FAPartition* partition) { + s32 error = pdm_part_release_partition(partition); + return error != 0 ? error : 0; +} diff --git a/libs/RVL_SDK/src/fa/pf_buffering.c b/libs/RVL_SDK/src/fa/pf_buffering.c new file mode 100644 index 00000000..2560b322 --- /dev/null +++ b/libs/RVL_SDK/src/fa/pf_buffering.c @@ -0,0 +1,8 @@ +#include + +extern s32 PFVOL_buffering(s8 drive, u8 mode); +extern s32 PFAPI_convertReturnValue(s32 error); + +s32 pf2_buffering(s32 drive, u32 mode) { + return PFAPI_convertReturnValue(PFVOL_buffering(drive, mode)); +} diff --git a/libs/RVL_SDK/src/fa/pf_cdelete.c b/libs/RVL_SDK/src/fa/pf_cdelete.c new file mode 100644 index 00000000..09bf610d --- /dev/null +++ b/libs/RVL_SDK/src/fa/pf_cdelete.c @@ -0,0 +1,33 @@ +#include + +typedef struct PF_API_STRING { + const s8* head; + const s8* tail; + const s8* current; + u32 code_mode; +} PF_API_STRING; + +typedef struct PF_API_VOLUME_SET { + u8 reserved[0x40]; + s32 last_error; +} PF_API_VOLUME_SET; + +extern PF_API_VOLUME_SET pf_vol_set; +extern s32 PFSTR_InitStr(PF_API_STRING* string, const s8* text, u32 mode); +extern s32 PFAPI_convertReturnValue(s32 error); + +extern s32 PFFILE_cdelete(PF_API_STRING* path, u32 position, u32 count, u32* completed); + +u32 pf2_cdelete(const char* path, u32 position, u32 count) { + PF_API_STRING path_string; + u32 completed = 0; + s32 error; + + error = PFSTR_InitStr(&path_string, (const s8*)path, 1); + if (error == 0) { + error = PFFILE_cdelete(&path_string, position, count, &completed); + } else { + pf_vol_set.last_error = error; + } + return completed; +} diff --git a/libs/RVL_SDK/src/fa/pf_chdmod.c b/libs/RVL_SDK/src/fa/pf_chdmod.c new file mode 100644 index 00000000..04bccf3a --- /dev/null +++ b/libs/RVL_SDK/src/fa/pf_chdmod.c @@ -0,0 +1,32 @@ +#include + +typedef struct PF_API_STRING { + const s8* head; + const s8* tail; + const s8* current; + u32 code_mode; +} PF_API_STRING; + +typedef struct PF_API_VOLUME_SET { + u8 reserved[0x40]; + s32 last_error; +} PF_API_VOLUME_SET; + +extern PF_API_VOLUME_SET pf_vol_set; +extern s32 PFSTR_InitStr(PF_API_STRING* string, const s8* text, u32 mode); +extern s32 PFAPI_convertReturnValue(s32 error); + +extern s32 PFDIR_chdmod(PF_API_STRING* path, u8 attributes); + +s32 pf2_chdmod(const char* path, u32 attributes) { + PF_API_STRING path_string; + s32 error; + + error = PFSTR_InitStr(&path_string, (const s8*)path, 1); + if (error == 0) { + error = PFDIR_chdmod(&path_string, attributes); + } else { + pf_vol_set.last_error = error; + } + return PFAPI_convertReturnValue(error); +} diff --git a/libs/RVL_SDK/src/fa/pf_chmod.c b/libs/RVL_SDK/src/fa/pf_chmod.c new file mode 100644 index 00000000..1fb6b25d --- /dev/null +++ b/libs/RVL_SDK/src/fa/pf_chmod.c @@ -0,0 +1,32 @@ +#include + +typedef struct PF_API_STRING { + const s8* head; + const s8* tail; + const s8* current; + u32 code_mode; +} PF_API_STRING; + +typedef struct PF_API_VOLUME_SET { + u8 reserved[0x40]; + s32 last_error; +} PF_API_VOLUME_SET; + +extern PF_API_VOLUME_SET pf_vol_set; +extern s32 PFSTR_InitStr(PF_API_STRING* string, const s8* text, u32 mode); +extern s32 PFAPI_convertReturnValue(s32 error); + +extern s32 PFDIR_chmod(PF_API_STRING* path, u8 attributes); + +s32 pf2_chmod(const char* path, u32 attributes) { + PF_API_STRING path_string; + s32 error; + + error = PFSTR_InitStr(&path_string, (const s8*)path, 1); + if (error == 0) { + error = PFDIR_chmod(&path_string, attributes); + } else { + pf_vol_set.last_error = error; + } + return PFAPI_convertReturnValue(error); +} diff --git a/libs/RVL_SDK/src/fa/pf_cinsert.c b/libs/RVL_SDK/src/fa/pf_cinsert.c new file mode 100644 index 00000000..903b5a0f --- /dev/null +++ b/libs/RVL_SDK/src/fa/pf_cinsert.c @@ -0,0 +1,33 @@ +#include + +typedef struct PF_API_STRING { + const s8* head; + const s8* tail; + const s8* current; + u32 code_mode; +} PF_API_STRING; + +typedef struct PF_API_VOLUME_SET { + u8 reserved[0x40]; + s32 last_error; +} PF_API_VOLUME_SET; + +extern PF_API_VOLUME_SET pf_vol_set; +extern s32 PFSTR_InitStr(PF_API_STRING* string, const s8* text, u32 mode); +extern s32 PFAPI_convertReturnValue(s32 error); + +extern s32 PFFILE_cinsert(PF_API_STRING* path, u32 position, u32 count, u32* completed); + +u32 pf2_cinsert(const char* path, u32 position, u32 count) { + PF_API_STRING path_string; + u32 completed = 0; + s32 error; + + error = PFSTR_InitStr(&path_string, (const s8*)path, 1); + if (error == 0) { + error = PFFILE_cinsert(&path_string, position, count, &completed); + } else { + pf_vol_set.last_error = error; + } + return completed; +} diff --git a/libs/RVL_SDK/src/fa/pf_combine.c b/libs/RVL_SDK/src/fa/pf_combine.c new file mode 100644 index 00000000..4274d6a8 --- /dev/null +++ b/libs/RVL_SDK/src/fa/pf_combine.c @@ -0,0 +1,34 @@ +#include + +typedef struct PF_API_STRING { + const s8* head; + const s8* tail; + const s8* current; + u32 code_mode; +} PF_API_STRING; + +typedef struct PF_API_VOLUME_SET { + u8 reserved[0x40]; + s32 last_error; +} PF_API_VOLUME_SET; + +extern PF_API_VOLUME_SET pf_vol_set; +extern s32 PFSTR_InitStr(PF_API_STRING* string, const s8* text, u32 mode); +extern s32 PFAPI_convertReturnValue(s32 error); + +extern s32 PFFILE_combine(PF_API_STRING* source, PF_API_STRING* destination); + +s32 pf2_combine(const char* source, const char* destination) { + PF_API_STRING source_string; + PF_API_STRING destination_string; + s32 error; + + error = PFSTR_InitStr(&source_string, (const s8*)source, 1); + error |= PFSTR_InitStr(&destination_string, (const s8*)destination, 1); + if (error == 0) { + error = PFFILE_combine(&source_string, &destination_string); + } else { + pf_vol_set.last_error = error; + } + return PFAPI_convertReturnValue(error); +} diff --git a/libs/RVL_SDK/src/fa/pf_createdir.c b/libs/RVL_SDK/src/fa/pf_createdir.c new file mode 100644 index 00000000..50acefce --- /dev/null +++ b/libs/RVL_SDK/src/fa/pf_createdir.c @@ -0,0 +1,32 @@ +#include + +typedef struct PF_API_STRING { + const s8* head; + const s8* tail; + const s8* current; + u32 code_mode; +} PF_API_STRING; + +typedef struct PF_API_VOLUME_SET { + u8 reserved[0x40]; + s32 last_error; +} PF_API_VOLUME_SET; + +extern PF_API_VOLUME_SET pf_vol_set; +extern s32 PFSTR_InitStr(PF_API_STRING* string, const s8* text, u32 mode); +extern s32 PFAPI_convertReturnValue(s32 error); + +extern s32 PFDIR_createdir(PF_API_STRING* path, s32 mode, FADta* data); + +s32 pf2_createdir(const char* path, s32 mode, FADta* data) { + PF_API_STRING path_string; + s32 error; + + error = PFSTR_InitStr(&path_string, (const s8*)path, 1); + if (error == 0) { + error = PFDIR_createdir(&path_string, mode, data); + } else { + pf_vol_set.last_error = error; + } + return PFAPI_convertReturnValue(error); +} diff --git a/libs/RVL_SDK/src/fa/pf_cut.c b/libs/RVL_SDK/src/fa/pf_cut.c new file mode 100644 index 00000000..435c15e2 --- /dev/null +++ b/libs/RVL_SDK/src/fa/pf_cut.c @@ -0,0 +1,36 @@ +#include + +typedef struct PF_API_STRING { + const s8* head; + const s8* tail; + const s8* current; + u32 code_mode; +} PF_API_STRING; + +typedef struct PF_API_VOLUME_SET { + u8 reserved[0x40]; + s32 last_error; +} PF_API_VOLUME_SET; + +extern PF_API_VOLUME_SET pf_vol_set; +extern s32 PFSTR_InitStr(PF_API_STRING* string, const s8* text, u32 mode); +extern s32 PFAPI_convertReturnValue(s32 error); + +extern s32 PFFILE_cdelete(PF_API_STRING* path, u32 position, u32 count, u32* completed); + +s32 pf2_cut(const char* path, u32 position) { + PF_API_STRING path_string; + u32 completed; + s32 error; + + error = PFSTR_InitStr(&path_string, (const s8*)path, 1); + if (error == 0) { + PFFILE_cdelete(&path_string, position, 1, &completed); + if (completed != 1) { + error = -1; + } + } else { + pf_vol_set.last_error = error; + } + return PFAPI_convertReturnValue(error); +} diff --git a/libs/RVL_SDK/src/fa/pf_derrnum.c b/libs/RVL_SDK/src/fa/pf_derrnum.c new file mode 100644 index 00000000..2fbf5953 --- /dev/null +++ b/libs/RVL_SDK/src/fa/pf_derrnum.c @@ -0,0 +1,8 @@ +#include + +extern s32 PFVOL_derrnum(s8 drive); +extern s32 PFAPI_convertDriverError(s32 error); + +s32 pf2_derrnum(s8 drive) { + return PFAPI_convertDriverError(PFVOL_derrnum(drive)); +} diff --git a/libs/RVL_SDK/src/fa/pf_divide.c b/libs/RVL_SDK/src/fa/pf_divide.c new file mode 100644 index 00000000..f9e26789 --- /dev/null +++ b/libs/RVL_SDK/src/fa/pf_divide.c @@ -0,0 +1,34 @@ +#include + +typedef struct PF_API_STRING { + const s8* head; + const s8* tail; + const s8* current; + u32 code_mode; +} PF_API_STRING; + +typedef struct PF_API_VOLUME_SET { + u8 reserved[0x40]; + s32 last_error; +} PF_API_VOLUME_SET; + +extern PF_API_VOLUME_SET pf_vol_set; +extern s32 PFSTR_InitStr(PF_API_STRING* string, const s8* text, u32 mode); +extern s32 PFAPI_convertReturnValue(s32 error); + +extern s32 PFFILE_divide(PF_API_STRING* source, PF_API_STRING* destination, u32 offset); + +s32 pf2_divide(const char* source, const char* destination, u32 offset) { + PF_API_STRING source_string; + PF_API_STRING destination_string; + s32 error; + + error = PFSTR_InitStr(&source_string, (const s8*)source, 1); + error |= PFSTR_InitStr(&destination_string, (const s8*)destination, 1); + if (error == 0) { + error = PFFILE_divide(&source_string, &destination_string, offset); + } else { + pf_vol_set.last_error = error; + } + return PFAPI_convertReturnValue(error); +} diff --git a/libs/RVL_SDK/src/fa/pf_fadjust.c b/libs/RVL_SDK/src/fa/pf_fadjust.c new file mode 100644 index 00000000..b372a43e --- /dev/null +++ b/libs/RVL_SDK/src/fa/pf_fadjust.c @@ -0,0 +1,8 @@ +#include + +extern s32 PFFILE_fadjust(FAFILE* file); +extern s32 PFAPI_convertReturnValue(s32 error); + +s32 pf2_fadjust(FAFILE* file) { + return PFAPI_convertReturnValue(PFFILE_fadjust(file)); +} diff --git a/libs/RVL_SDK/src/fa/pf_fappend.c b/libs/RVL_SDK/src/fa/pf_fappend.c new file mode 100644 index 00000000..c4a09ce8 --- /dev/null +++ b/libs/RVL_SDK/src/fa/pf_fappend.c @@ -0,0 +1,9 @@ +#include + +extern s32 PFFILE_fappend(FAFILE* file, u32 size, u32* appended_size); + +u32 pf2_fappend(FAFILE* file, u32 size) { + u32 appended_size; + PFFILE_fappend(file, size, &appended_size); + return appended_size; +} diff --git a/libs/RVL_SDK/src/fa/pf_fchdir.c b/libs/RVL_SDK/src/fa/pf_fchdir.c new file mode 100644 index 00000000..bc098354 --- /dev/null +++ b/libs/RVL_SDK/src/fa/pf_fchdir.c @@ -0,0 +1,8 @@ +#include + +extern s32 PFDIR_fchdir(FADIR* directory); +extern s32 PFAPI_convertReturnValue(s32 error); + +s32 pf2_fchdir(FADIR* directory) { + return PFAPI_convertReturnValue(PFDIR_fchdir(directory)); +} diff --git a/libs/RVL_SDK/src/fa/pf_fconcat.c b/libs/RVL_SDK/src/fa/pf_fconcat.c new file mode 100644 index 00000000..d7341b10 --- /dev/null +++ b/libs/RVL_SDK/src/fa/pf_fconcat.c @@ -0,0 +1,34 @@ +#include + +typedef struct PF_API_STRING { + const s8* head; + const s8* tail; + const s8* current; + u32 code_mode; +} PF_API_STRING; + +typedef struct PF_API_VOLUME_SET { + u8 reserved[0x40]; + s32 last_error; +} PF_API_VOLUME_SET; + +extern PF_API_VOLUME_SET pf_vol_set; +extern s32 PFSTR_InitStr(PF_API_STRING* string, const s8* text, u32 mode); +extern s32 PFAPI_convertReturnValue(s32 error); + +extern s32 PFFILE_combine(PF_API_STRING* source, PF_API_STRING* destination); + +s32 pf2_fconcat(const char* source, const char* destination) { + PF_API_STRING source_string; + PF_API_STRING destination_string; + s32 error; + + error = PFSTR_InitStr(&source_string, (const s8*)source, 1); + error |= PFSTR_InitStr(&destination_string, (const s8*)destination, 1); + if (error == 0) { + error = PFFILE_combine(&source_string, &destination_string); + } else { + pf_vol_set.last_error = error; + } + return PFAPI_convertReturnValue(error); +} diff --git a/libs/RVL_SDK/src/fa/pf_fsetclstlink.c b/libs/RVL_SDK/src/fa/pf_fsetclstlink.c new file mode 100644 index 00000000..b5b409d0 --- /dev/null +++ b/libs/RVL_SDK/src/fa/pf_fsetclstlink.c @@ -0,0 +1,8 @@ +#include + +extern s32 PFFILE_fsetclstlink(FAFILE* file, u32 mode, void* setting); +extern s32 PFAPI_convertReturnValue(s32 error); + +s32 pf2_fsetclstlink(FAFILE* file, u32 mode, void* setting) { + return PFAPI_convertReturnValue(PFFILE_fsetclstlink(file, mode, setting)); +} diff --git a/libs/RVL_SDK/src/fa/pf_fsexec.c b/libs/RVL_SDK/src/fa/pf_fsexec.c new file mode 100644 index 00000000..e34ab54e --- /dev/null +++ b/libs/RVL_SDK/src/fa/pf_fsexec.c @@ -0,0 +1,8 @@ +#include + +extern s32 PFDIR_fsexec(FADta* data, u32 flags, u32 mode); +extern s32 PFAPI_convertReturnValue(s32 error); + +s32 pf2_fsexec(FADta* data, u32 flags, u32 mode) { + return PFAPI_convertReturnValue(PFDIR_fsexec(data, flags, mode)); +} diff --git a/libs/RVL_SDK/src/fa/pf_getvol.c b/libs/RVL_SDK/src/fa/pf_getvol.c new file mode 100644 index 00000000..b139fe3e --- /dev/null +++ b/libs/RVL_SDK/src/fa/pf_getvol.c @@ -0,0 +1,8 @@ +#include + +extern s32 PFVOL_getvol(s8 drive, void* volume_info); +extern s32 PFAPI_convertReturnValue(s32 error); + +s32 pf2_getvol(s8 drive, void* volume_info) { + return PFAPI_convertReturnValue(PFVOL_getvol(drive, volume_info)); +} diff --git a/libs/RVL_SDK/src/fa/pf_getvolcfg.c b/libs/RVL_SDK/src/fa/pf_getvolcfg.c new file mode 100644 index 00000000..e5546c7b --- /dev/null +++ b/libs/RVL_SDK/src/fa/pf_getvolcfg.c @@ -0,0 +1,8 @@ +#include + +extern s32 PFVOL_getvolcfg(s8 drive, u32* config); +extern s32 PFAPI_convertReturnValue(s32 error); + +s32 pf2_getvolcfg(s8 drive, u32* config) { + return PFAPI_convertReturnValue(PFVOL_getvolcfg(drive, config)); +} diff --git a/libs/RVL_SDK/src/fa/pf_insert.c b/libs/RVL_SDK/src/fa/pf_insert.c new file mode 100644 index 00000000..5d6946af --- /dev/null +++ b/libs/RVL_SDK/src/fa/pf_insert.c @@ -0,0 +1,42 @@ +#include + +typedef struct PF_API_STRING { + const s8* head; + const s8* tail; + const s8* current; + u32 code_mode; +} PF_API_STRING; + +typedef struct PF_API_VOLUME_SET { + u8 reserved[0x40]; + s32 last_error; +} PF_API_VOLUME_SET; + +extern PF_API_VOLUME_SET pf_vol_set; +extern s32 PFSTR_InitStr(PF_API_STRING* string, const s8* text, u32 mode); +extern s32 PFAPI_convertReturnValue(s32 error); + +extern s32 PFFILE_cinsert(PF_API_STRING* path, u32 position, u32 count, u32* completed); +extern s32 PFFILE_cdelete(PF_API_STRING* path, u32 position, u32 count, u32* completed); + +s32 pf2_insert(const char* path, u32 count) { + PF_API_STRING path_string; + u32 inserted; + u32 deleted; + s32 error; + + error = PFSTR_InitStr(&path_string, (const s8*)path, 1); + if (error == 0) { + PFFILE_cinsert(&path_string, 0, count, &inserted); + if (count != inserted || count == 0) { + if (inserted != 0) { + PFSTR_InitStr(&path_string, (const s8*)path, 1); + PFFILE_cdelete(&path_string, 0, inserted, &deleted); + } + error = -1; + } + } else { + pf_vol_set.last_error = error; + } + return PFAPI_convertReturnValue(error); +} diff --git a/libs/RVL_SDK/src/fa/pf_iswriteprotected.c b/libs/RVL_SDK/src/fa/pf_iswriteprotected.c new file mode 100644 index 00000000..d82ffdf1 --- /dev/null +++ b/libs/RVL_SDK/src/fa/pf_iswriteprotected.c @@ -0,0 +1,13 @@ +#include + +extern s32 PFVOL_iswriteprotected(s8 drive, u32* protected_status); +extern s32 PFAPI_convertReturnValue(s32 error); + +s32 pf2_iswriteprotected(s8 drive) { + u32 protected_status = 0; + s32 error = PFVOL_iswriteprotected(drive, &protected_status); + if (error == 0) { + return protected_status; + } + return PFAPI_convertReturnValue(error); +} diff --git a/libs/RVL_SDK/src/fa/pf_move.c b/libs/RVL_SDK/src/fa/pf_move.c new file mode 100644 index 00000000..0706ec83 --- /dev/null +++ b/libs/RVL_SDK/src/fa/pf_move.c @@ -0,0 +1,34 @@ +#include + +typedef struct PF_API_STRING { + const s8* head; + const s8* tail; + const s8* current; + u32 code_mode; +} PF_API_STRING; + +typedef struct PF_API_VOLUME_SET { + u8 reserved[0x40]; + s32 last_error; +} PF_API_VOLUME_SET; + +extern PF_API_VOLUME_SET pf_vol_set; +extern s32 PFSTR_InitStr(PF_API_STRING* string, const s8* text, u32 mode); +extern s32 PFAPI_convertReturnValue(s32 error); + +extern s32 PFDIR_move(PF_API_STRING* source, PF_API_STRING* destination); + +s32 pf2_move(const char* source, const char* destination) { + PF_API_STRING source_string; + PF_API_STRING destination_string; + s32 error; + + error = PFSTR_InitStr(&source_string, (const s8*)source, 1); + error |= PFSTR_InitStr(&destination_string, (const s8*)destination, 1); + if (error == 0) { + error = PFDIR_move(&source_string, &destination_string); + } else { + pf_vol_set.last_error = error; + } + return PFAPI_convertReturnValue(error); +} diff --git a/libs/RVL_SDK/src/fa/pf_opendir.c b/libs/RVL_SDK/src/fa/pf_opendir.c new file mode 100644 index 00000000..8e0016f5 --- /dev/null +++ b/libs/RVL_SDK/src/fa/pf_opendir.c @@ -0,0 +1,34 @@ +#include + +typedef struct PF_API_STRING { + const s8* head; + const s8* tail; + const s8* current; + u32 code_mode; +} PF_API_STRING; + +typedef struct PF_API_VOLUME_SET { + u8 reserved[0x40]; + s32 last_error; +} PF_API_VOLUME_SET; + +extern PF_API_VOLUME_SET pf_vol_set; +extern s32 PFSTR_InitStr(PF_API_STRING* string, const s8* text, u32 mode); +extern s32 PFAPI_convertReturnValue(s32 error); + +extern s32 PFDIR_opendir(PF_API_STRING* path, FADIR** directory); +extern void* PFAPI_convertReturnValue2NULL(s32 error, void* stream); + +FADIR* pf2_opendir(const char* path) { + PF_API_STRING path_string; + FADIR* directory; + s32 error; + + error = PFSTR_InitStr(&path_string, (const s8*)path, 1); + if (error == 0) { + error = PFDIR_opendir(&path_string, &directory); + } else { + pf_vol_set.last_error = error; + } + return PFAPI_convertReturnValue2NULL(error, directory); +} diff --git a/libs/RVL_SDK/src/fa/pf_readdir.c b/libs/RVL_SDK/src/fa/pf_readdir.c new file mode 100644 index 00000000..96b78c3a --- /dev/null +++ b/libs/RVL_SDK/src/fa/pf_readdir.c @@ -0,0 +1,8 @@ +#include + +extern s32 PFDIR_readdir(FADIR* directory, void* result); +extern s32 PFAPI_convertReturnValue(s32 error); + +s32 pf2_readdir(FADIR* directory, void* result) { + return PFAPI_convertReturnValue(PFDIR_readdir(directory, result)); +} diff --git a/libs/RVL_SDK/src/fa/pf_regctx.c b/libs/RVL_SDK/src/fa/pf_regctx.c new file mode 100644 index 00000000..ec3e6d20 --- /dev/null +++ b/libs/RVL_SDK/src/fa/pf_regctx.c @@ -0,0 +1,8 @@ +#include + +extern s32 PFVOL_regctx(void); +extern s32 PFAPI_convertReturnValue(s32 error); + +s32 pf2_regctx(void) { + return PFAPI_convertReturnValue(PFVOL_regctx()); +} diff --git a/libs/RVL_SDK/src/fa/pf_rewinddir.c b/libs/RVL_SDK/src/fa/pf_rewinddir.c new file mode 100644 index 00000000..396356df --- /dev/null +++ b/libs/RVL_SDK/src/fa/pf_rewinddir.c @@ -0,0 +1,8 @@ +#include + +extern s32 PFDIR_seekdir(FADIR* directory, u32 position); +extern s32 PFAPI_convertReturnValue(s32 error); + +s32 pf2_rewinddir(FADIR* directory) { + return PFAPI_convertReturnValue(PFDIR_seekdir(directory, 0)); +} diff --git a/libs/RVL_SDK/src/fa/pf_rmvvol.c b/libs/RVL_SDK/src/fa/pf_rmvvol.c new file mode 100644 index 00000000..70727a20 --- /dev/null +++ b/libs/RVL_SDK/src/fa/pf_rmvvol.c @@ -0,0 +1,8 @@ +#include + +extern s32 PFVOL_rmvvol(s8 drive); +extern s32 PFAPI_convertReturnValue(s32 error); + +s32 pf2_rmvvol(s8 drive) { + return PFAPI_convertReturnValue(PFVOL_rmvvol(drive)); +} diff --git a/libs/RVL_SDK/src/fa/pf_seekdir.c b/libs/RVL_SDK/src/fa/pf_seekdir.c new file mode 100644 index 00000000..2acd1e99 --- /dev/null +++ b/libs/RVL_SDK/src/fa/pf_seekdir.c @@ -0,0 +1,8 @@ +#include + +extern s32 PFDIR_seekdir(FADIR* directory, u32 position); +extern s32 PFAPI_convertReturnValue(s32 error); + +s32 pf2_seekdir(FADIR* directory, u32 position) { + return PFAPI_convertReturnValue(PFDIR_seekdir(directory, position)); +} diff --git a/libs/RVL_SDK/src/fa/pf_setclstlink.c b/libs/RVL_SDK/src/fa/pf_setclstlink.c new file mode 100644 index 00000000..f8a221fd --- /dev/null +++ b/libs/RVL_SDK/src/fa/pf_setclstlink.c @@ -0,0 +1,8 @@ +#include + +extern s32 PFVOL_setclstlink(s8 drive, s32 mode, void* setting); +extern s32 PFAPI_convertReturnValue(s32 error); + +s32 pf2_setclstlink(s8 drive, s32 mode, void* setting) { + return PFAPI_convertReturnValue(PFVOL_setclstlink(drive, mode, setting)); +} diff --git a/libs/RVL_SDK/src/fa/pf_setcode.c b/libs/RVL_SDK/src/fa/pf_setcode.c new file mode 100644 index 00000000..df85e32b --- /dev/null +++ b/libs/RVL_SDK/src/fa/pf_setcode.c @@ -0,0 +1,8 @@ +#include + +extern s32 PFVOL_setcode(const void* code_set); +extern s32 PFAPI_convertReturnValue(s32 error); + +s32 pf2_setcode(const void* code_set) { + return PFAPI_convertReturnValue(PFVOL_setcode(code_set)); +} diff --git a/libs/RVL_SDK/src/fa/pf_setencode.c b/libs/RVL_SDK/src/fa/pf_setencode.c new file mode 100644 index 00000000..94fbf376 --- /dev/null +++ b/libs/RVL_SDK/src/fa/pf_setencode.c @@ -0,0 +1,8 @@ +#include + +extern s32 PFVOL_setencode(u32 mode); +extern s32 PFAPI_convertReturnValue(s32 error); + +s32 pf2_setencode(u32 mode) { + return PFAPI_convertReturnValue(PFVOL_setencode(mode)); +} diff --git a/libs/RVL_SDK/src/fa/pf_settailbuf.c b/libs/RVL_SDK/src/fa/pf_settailbuf.c new file mode 100644 index 00000000..84152ad8 --- /dev/null +++ b/libs/RVL_SDK/src/fa/pf_settailbuf.c @@ -0,0 +1,8 @@ +#include + +extern s32 PFVOL_settailbuf(s8 drive, u32 count, void* buffer); +extern s32 PFAPI_convertReturnValue(s32 error); + +s32 pf2_settailbuf(s8 drive, u32 count, void* buffer) { + return PFAPI_convertReturnValue(PFVOL_settailbuf(drive, count, buffer)); +} diff --git a/libs/RVL_SDK/src/fa/pf_setupfsi.c b/libs/RVL_SDK/src/fa/pf_setupfsi.c new file mode 100644 index 00000000..bf110eba --- /dev/null +++ b/libs/RVL_SDK/src/fa/pf_setupfsi.c @@ -0,0 +1,8 @@ +#include + +extern s32 PFVOL_setupfsi(s8 drive, u16 mode); +extern s32 PFAPI_convertReturnValue(s32 error); + +s32 pf2_setupfsi(s32 drive, u32 mode) { + return PFAPI_convertReturnValue(PFVOL_setupfsi(drive, mode)); +} diff --git a/libs/RVL_SDK/src/fa/pf_setvol.c b/libs/RVL_SDK/src/fa/pf_setvol.c new file mode 100644 index 00000000..8db6f9a1 --- /dev/null +++ b/libs/RVL_SDK/src/fa/pf_setvol.c @@ -0,0 +1,30 @@ +#include + +typedef struct PF_API_STRING { + const s8* head; + const s8* tail; + const s8* current; + u32 code_mode; +} PF_API_STRING; + +typedef struct PF_API_VOLUME_SET { + u8 reserved[0x40]; + s32 last_error; +} PF_API_VOLUME_SET; + +extern PF_API_VOLUME_SET pf_vol_set; +extern s32 PFSTR_InitStr(PF_API_STRING* string, const s8* text, u32 mode); +extern s32 PFAPI_convertReturnValue(s32 error); + +extern s32 PFVOL_setvol(s8 drive, PF_API_STRING* label); + +s32 pf2_setvol(s8 drive, const char* label) { + PF_API_STRING label_string; + s32 error = PFSTR_InitStr(&label_string, (const s8*)label, 1); + if (error == 0) { + error = PFVOL_setvol(drive, &label_string); + } else { + pf_vol_set.last_error = error; + } + return PFAPI_convertReturnValue(error); +} diff --git a/libs/RVL_SDK/src/fa/pf_setvolcfg.c b/libs/RVL_SDK/src/fa/pf_setvolcfg.c new file mode 100644 index 00000000..2fc9ae56 --- /dev/null +++ b/libs/RVL_SDK/src/fa/pf_setvolcfg.c @@ -0,0 +1,8 @@ +#include + +extern s32 PFVOL_setvolcfg(s8 drive, u32* config); +extern s32 PFAPI_convertReturnValue(s32 error); + +s32 pf2_setvolcfg(s8 drive, u32* config) { + return PFAPI_convertReturnValue(PFVOL_setvolcfg(drive, config)); +} diff --git a/libs/RVL_SDK/src/fa/pf_stub.c b/libs/RVL_SDK/src/fa/pf_stub.c new file mode 100644 index 00000000..a9b4e558 --- /dev/null +++ b/libs/RVL_SDK/src/fa/pf_stub.c @@ -0,0 +1,152 @@ +#include +#include +#include + +typedef struct PF_STUB_VOLUME_CONTEXT { + u8 volume_state[0x64]; + s32 context_id; +} PF_STUB_VOLUME_CONTEXT; + +extern PF_STUB_VOLUME_CONTEXT pf_vol_set; +extern FADisk* gOpenDisk[26]; +extern FAPartition* gOpenPartition[26]; +extern s32 pfd_sddrv_is_media_insert(void); +extern s32 pfd_mscdrv_is_media_insert(FADisk* disk); +extern void pfstub_call_function_standard(PF_STUB_MESSAGE* message); +extern void pfstub_call_function_unicode(PF_STUB_MESSAGE* message); +void* pfstub_entry(void* argument); +s32 pfstub_store_result(PF_STUB_MESSAGE* message); + +void pfstub_init_stub(void) { + PFK_MAILBOX_CONFIG mailbox; + PFK_TASK_CONFIG task; + if (pf_sys_set.initialized == 0) { + mailbox.queue = &pf_sys_set.mailbox; + mailbox.messages = pf_sys_set.messages; + mailbox.count = 20; + pf_sys_set.mailbox_id = pfk_create_mailbox(&mailbox); + task.entry = pfstub_entry; + task.argument = NULL; + task.priority = 16; + task.stack_size = sizeof(pf_sys_set.task_stack); + task.stack = pf_sys_set.task_stack; + task.thread = &pf_sys_set.task; + pf_sys_set.task_id = pfk_create_task(&task); + pfk_start_task(pf_sys_set.task_id); + pf_sys_set.initialized = 1; + } +} + +s32 pfstub_set_stub_priority(s32 priority) { + if (pf_sys_set.initialized != 1) { + return -1; + } + return pfk_set_task_priority(pf_sys_set.task_id, priority); +} + +void* pfstub_entry(void* argument) { + PF_STUB_MESSAGE* received = NULL; + PF_STUB_MESSAGE* message; + for (;;) { + if (pfk_receive_message(pf_sys_set.mailbox_id, (OSMessage*)&received) != 0) { + continue; + } + message = received; + if (message == NULL) { + continue; + } + pf_vol_set.context_id = message->task_id; + if (message->operation >= 0 && message->operation < 100) { + pfstub_call_function_standard(message); + } else if (received->operation >= 100 && received->operation < 200) { + pfstub_call_function_unicode(message); + } else { + message->result.status = -1; + } + if (message->callback == NULL) { + pfk_release_semaphore(message->semaphore); + } else { + if (message->operation == 27) { + FADrvTbl* table = message->context; + s32 index = table->drive - 'A'; + gOpenDisk[index] = message->disk; + gOpenPartition[index] = message->partition; + if (message->value == 0) { + if (pfd_sddrv_is_media_insert()) { + ((FADrvTbl*)message->context)->stat |= 0x10; + } + } else if ((s32)message->value == 1) { + if (pfd_mscdrv_is_media_insert(message->disk)) { + ((FADrvTbl*)message->context)->stat |= 0x10; + } + } + } + message->callback(pfstub_store_result(message), message->callback_context); + } + } +} + +s32 pfstub_com_massage(PF_STUB_MESSAGE* message) { + s32 task_id; + PFK_SEMAPHORE_CONFIG config; + OSSemaphore semaphore; + s32 error; + if (message->callback == NULL) { + config.initial_count = 0; + config.maximum_count = 1; + config.semaphore = &semaphore; + message->semaphore = pfk_create_semaphore(&config); + } else { + message->semaphore = 0; + } + if (pfk_get_task_id(&task_id) != 0) { + return -1; + } + message->task_id = task_id; + if (pfk_send_message(pf_sys_set.mailbox_id, message) != 0) { + return -1; + } + if (message->callback == NULL) { + error = pfk_get_semaphore(message->semaphore); + pfk_delete_semaphore(message->semaphore); + if (error != 0) { + return -1; + } + } + return 0; +} + +s32 pfstub_store_result(PF_STUB_MESSAGE* message) { + s32 error = 0; + if (message->result_address != NULL) { + *message->result_address = message->result; + switch (message->operation) { + case 0: + case 1: + case 54: + case 100: + case 101: + case 122: + if (message->result.stream == NULL) { + error = -1; + } + break; + case 35: + if (message->result.status != (s32)message->value) { + error = -1; + } + break; + case 3: + case 4: + if (message->result.status != (s32)message->count) { + error = -1; + } + break; + default: + break; + } + } else { + error = message->result.status; + } + return error; +} diff --git a/libs/RVL_SDK/src/fa/pf_stub_standard.c b/libs/RVL_SDK/src/fa/pf_stub_standard.c new file mode 100644 index 00000000..154e59f0 --- /dev/null +++ b/libs/RVL_SDK/src/fa/pf_stub_standard.c @@ -0,0 +1,272 @@ +#include + +extern void* pf2_create(const void*, u32); +extern void* pf2_fopen(const void*, const void*); +extern s32 pf2_fclose(const void*); +extern s32 pf2_fread(const void*, u32, u32, const void*); +extern s32 pf2_fwrite(const void*, u32, u32, const void*); +extern s32 pf2_fseek(const void*, u32, u32); +extern s32 pf2_remove(const void*); +extern s32 pf2_rename(const void*, const void*); +extern s32 pf2_mkdir(const void*); +extern s32 pf2_rmdir(const void*); +extern s32 pf2_chdir(const void*); +extern s32 pf2_fstat(const void*, const void*); +extern s32 pf2_chmod(const void*, u32); +extern s32 pf2_mount(s8); +extern s32 pf2_format(s8, const void*); +extern s32 pf2_buffering(s8, u32); +extern s32 pf2_ferror(const void*); +extern s32 pf2_feof(const void*); +extern s32 pf2_errnum(void); +extern s32 pf2_devinf(s8, const void*); +extern s32 pf2_setvol(s8, const void*); +extern s32 pf2_getvol(s8, const void*); +extern s32 pf2_rmvvol(s8); +extern s32 pf2_chdmod(const void*, u32); +extern s32 pf2_fconcat(const void*, const void*); +extern s32 pf2_attach(const void*, const void*); +extern s32 pf2_fsfirst(const void*, u32, const void*); +extern s32 pf2_fsnext(const void*); +extern s32 pf2_setupfsi(s8, u32); +extern s32 pf2_setclstlink(s8, u32, const void*); +extern s32 pf2_fsetclstlink(const void*, u32, const void*); +extern s32 pf2_sync(s8, u32); +extern s32 pf2_fsync(const void*); +extern s32 pf2_fappend(const void*, u32); +extern s32 pf2_settailbuf(s8, u32, const void*); +extern s32 pf2_derrnum(s8); +extern s32 pf2_fsexec(const void*, u32, s32); +extern s32 pf2_unmount(s8, u32); +extern s32 pf2_combine(const void*, const void*); +extern s32 pf2_detach(s8); +extern s32 pf2_divide(const void*, const void*, u32); +extern s32 pf2_xdivide(const void*, const void*, u32); +extern s32 pf2_fadjust(const void*); +extern s32 pf2_finfo(const void*, const void*); +extern s32 pf2_move(const void*, const void*); +extern s32 pf2_cinsert(const void*, u32, u32); +extern s32 pf2_insert(const void*, u32); +extern s32 pf2_cdelete(const void*, u32, u32); +extern s32 pf2_cut(const void*, u32); +extern s32 pf2_setvolcfg(s8, const void*); +extern s32 pf2_getvolcfg(s8, const void*); +extern s32 pf2_setcode(const void*); +extern void* pf2_opendir(const void*); +extern s32 pf2_closedir(const void*); +extern s32 pf2_readdir(const void*, const void*); +extern s32 pf2_telldir(const void*, const void*); +extern s32 pf2_seekdir(const void*, u32); +extern s32 pf2_rewinddir(const void*); +extern s32 pf2_fchdir(const void*); +extern s32 pf2_regctx(void); +extern s32 pf2_unregctx(void); +extern s32 pf2_flock(const void*, u32); +extern s32 pf2_setencode(u32); +extern s32 pf2_createdir(const void*, u32, const void*); +extern s32 pf2_iswriteprotected(s8); + +void pfstub_call_function_standard(PF_STUB_MESSAGE* message) { + switch (message->operation) { + case 0: + message->result.stream = pf2_create(message->object,message->value); + break; + case 1: + message->result.stream = pf2_fopen(message->object,message->data); + break; + case 2: + message->result.status = pf2_fclose(message->object); + break; + case 3: + message->result.status = pf2_fread(message->object,message->value, message->count,message->data); + break; + case 4: + message->result.status = pf2_fwrite(message->object,message->value, message->count,message->data); + break; + case 5: + message->result.status = pf2_fseek(message->object,message->value, message->count); + break; + case 7: + message->result.status = pf2_remove(message->object); + break; + case 8: + message->result.status = pf2_rename(message->object,message->data); + break; + case 0x2e: + message->result.status = pf2_move(message->object,message->data); + break; + case 9: + message->result.status = pf2_mkdir(message->object); + break; + case 0x41: + message->result.status = pf2_createdir(message->object,message->value, message->data); + break; + case 10: + message->result.status = pf2_rmdir(message->object); + break; + case 0xb: + message->result.status = pf2_chdir(message->object); + break; + case 0xc: + message->result.status = pf2_fstat(message->object,message->data); + break; + case 0xd: + message->result.status = pf2_chmod(message->object,message->value); + break; + case 0xe: + message->result.status = pf2_mount(message->drive); + break; + case 0x27: + message->result.status = pf2_unmount(message->drive,message->value); + break; + case 0xf: + message->result.status = pf2_format(message->drive,message->object); + break; + case 0x10: + message->result.status = pf2_buffering(message->drive,message->value); + break; + case 0x11: + message->result.status = pf2_ferror(message->object); + break; + case 0x12: + message->result.status = pf2_feof(message->object); + break; + case 0x13: + message->result.status = pf2_errnum(); + break; + case 0x14: + message->result.status = pf2_devinf(message->drive,message->object); + break; + case 0x15: + message->result.status = pf2_setvol(message->drive,message->object); + break; + case 0x16: + message->result.status = pf2_getvol(message->drive,message->object); + break; + case 0x17: + message->result.status = pf2_rmvvol(message->drive); + break; + case 0x18: + message->result.status = pf2_chdmod(message->object,message->value); + break; + case 0x19: + message->result.status = pf2_fconcat(message->object,message->data); + break; + case 0x1b: + message->result.status = pf2_attach(message->object,message->data); + break; + case 0x29: + message->result.status = pf2_detach(message->drive); + break; + case 0x1c: + message->result.status = pf2_fsfirst(message->object,(u8)message->value, message->data); + break; + case 0x1d: + message->result.status = pf2_fsnext(message->object); + break; + case 0x26: + message->result.status = pf2_fsexec(message->object,message->value, (u8)message->drive); + break; + case 0x1e: + message->result.status = pf2_setupfsi(message->drive,(s16)message->value); + break; + case 0x1f: + message->result.status = pf2_setclstlink(message->drive,message->value, message->object); + break; + case 0x20: + message->result.status = pf2_fsetclstlink(message->object,message->value, message->data); + break; + case 0x21: + message->result.status = pf2_sync(message->drive,message->value); + break; + case 0x22: + message->result.status = pf2_fsync(message->object); + break; + case 0x23: + message->result.status = pf2_fappend(message->object,message->value); + break; + case 0x2c: + message->result.status = pf2_fadjust(message->object); + break; + case 0x2d: + message->result.status = pf2_finfo(message->object,message->data); + break; + case 0x24: + message->result.status = pf2_settailbuf(message->drive,message->value, message->object); + break; + case 0x25: + message->result.status = pf2_derrnum(message->drive); + break; + case 0x28: + message->result.status = pf2_combine(message->object,message->data); + break; + case 0x2a: + message->result.status = pf2_divide(message->object,message->data, message->value); + break; + case 0x2b: + message->result.status = pf2_xdivide(message->object,message->data, message->value); + break; + case 0x2f: + message->result.status = pf2_cinsert(message->object,message->value, message->count); + break; + case 0x30: + message->result.status = pf2_insert(message->object,message->value); + break; + case 0x31: + message->result.status = pf2_cdelete(message->object,message->value, message->count); + break; + case 0x32: + message->result.status = pf2_cut(message->object,message->value); + break; + case 0x33: + message->result.status = pf2_setvolcfg(message->drive,message->object); + break; + case 0x34: + message->result.status = pf2_getvolcfg(message->drive,message->object); + break; + case 0x35: + message->result.status = pf2_setcode(message->object); + break; + case 0x36: + message->result.stream = pf2_opendir(message->object); + break; + case 0x37: + message->result.status = pf2_closedir(message->object); + break; + case 0x38: + message->result.status = pf2_readdir(message->object,message->data); + break; + case 0x39: + message->result.status = pf2_telldir(message->object,message->data); + break; + case 0x3a: + message->result.status = pf2_seekdir(message->object,message->value); + break; + case 0x3b: + message->result.status = pf2_rewinddir(message->object); + break; + case 0x3c: + message->result.status = pf2_fchdir(message->object); + break; + case 0x3d: + message->result.status = pf2_regctx(); + break; + case 0x3e: + message->result.status = pf2_unregctx(); + break; + case 0x3f: + message->result.status = pf2_flock(message->object,message->value); + break; + case 0x40: + message->result.status = pf2_setencode(message->value); + break; + case 0x50: + message->result.status = pf2_iswriteprotected(message->drive); + break; + case 6: + break; + default: + message->result.status = -1; + break; + } +} diff --git a/libs/RVL_SDK/src/fa/pf_stub_unicode.c b/libs/RVL_SDK/src/fa/pf_stub_unicode.c new file mode 100644 index 00000000..6b5534c8 --- /dev/null +++ b/libs/RVL_SDK/src/fa/pf_stub_unicode.c @@ -0,0 +1,106 @@ +#include + +extern void* pf2_w_create(const void*, u32); +extern void* pf2_w_fopen(const void*, const void*); +extern s32 pf2_w_remove(const void*); +extern s32 pf2_w_rename(const void*, const void*); +extern s32 pf2_w_mkdir(const void*); +extern s32 pf2_w_rmdir(const void*); +extern s32 pf2_w_chdir(const void*); +extern s32 pf2_w_fstat(const void*, const void*); +extern s32 pf2_w_chmod(const void*, u32); +extern s32 pf2_w_chdmod(const void*, u32); +extern s32 pf2_w_fconcat(const void*, const void*); +extern s32 pf2_w_fsfirst(const void*, u32, const void*); +extern s32 pf2_w_fsnext(const void*); +extern s32 pf2_w_fsexec(const void*, u32, s32); +extern s32 pf2_w_combine(const void*, const void*); +extern s32 pf2_w_divide(const void*, const void*, u32); +extern s32 pf2_w_xdivide(const void*, const void*, u32); +extern s32 pf2_w_move(const void*, const void*); +extern s32 pf2_w_cinsert(const void*, u32, u32); +extern s32 pf2_w_insert(const void*, u32); +extern s32 pf2_w_cdelete(const void*, u32, u32); +extern s32 pf2_w_cut(const void*, u32); +extern void* pf2_w_opendir(const void*); +extern s32 pf2_w_createdir(const void*, u32, const void*); + +void pfstub_call_function_unicode(PF_STUB_MESSAGE* message) { + switch (message->operation) { + case 100: + message->result.stream = pf2_w_create(message->object,message->value); + break; + case 0x65: + message->result.stream = pf2_w_fopen(message->object,message->data); + break; + case 0x66: + message->result.status = pf2_w_remove(message->object); + break; + case 0x67: + message->result.status = pf2_w_rename(message->object,message->data); + break; + case 0x75: + message->result.status = pf2_w_move(message->object,message->data); + break; + case 0x68: + message->result.status = pf2_w_mkdir(message->object); + break; + case 0x7b: + message->result.status = pf2_w_createdir(message->object,message->value, message->data); + break; + case 0x69: + message->result.status = pf2_w_rmdir(message->object); + break; + case 0x6a: + message->result.status = pf2_w_chdir(message->object); + break; + case 0x6b: + message->result.status = pf2_w_fstat(message->object,message->data); + break; + case 0x6c: + message->result.status = pf2_w_chmod(message->object,message->value); + break; + case 0x6d: + message->result.status = pf2_w_chdmod(message->object,message->value); + break; + case 0x6e: + message->result.status = pf2_w_fconcat(message->object,message->data); + break; + case 0x6f: + message->result.status = pf2_w_fsfirst(message->object,(u8)message->value, message->data); + break; + case 0x70: + message->result.status = pf2_w_fsnext(message->object); + break; + case 0x71: + message->result.status = pf2_w_fsexec(message->object,message->value, (u8)message->drive); + break; + case 0x72: + message->result.status = pf2_w_combine(message->object,message->data); + break; + case 0x73: + message->result.status = pf2_w_divide(message->object,message->data, message->value); + break; + case 0x74: + message->result.status = pf2_w_xdivide(message->object,message->data, message->value); + break; + case 0x76: + message->result.status = pf2_w_cinsert(message->object,message->value, message->count); + break; + case 0x77: + message->result.status = pf2_w_insert(message->object,message->value); + break; + case 0x78: + message->result.status = pf2_w_cdelete(message->object,message->value, message->count); + break; + case 0x79: + message->result.status = pf2_w_cut(message->object,message->value); + break; + case 0x7a: + message->result.stream = pf2_w_opendir(message->object); + break; + default: + message->result.status = -1; + break; + } +} diff --git a/libs/RVL_SDK/src/fa/pf_telldir.c b/libs/RVL_SDK/src/fa/pf_telldir.c new file mode 100644 index 00000000..1115c69d --- /dev/null +++ b/libs/RVL_SDK/src/fa/pf_telldir.c @@ -0,0 +1,8 @@ +#include + +extern s32 PFDIR_telldir(FADIR* directory, u32* position); +extern s32 PFAPI_convertReturnValue(s32 error); + +s32 pf2_telldir(FADIR* directory, u32* position) { + return PFAPI_convertReturnValue(PFDIR_telldir(directory, position)); +} diff --git a/libs/RVL_SDK/src/fa/pf_unregctx.c b/libs/RVL_SDK/src/fa/pf_unregctx.c new file mode 100644 index 00000000..c58fbd29 --- /dev/null +++ b/libs/RVL_SDK/src/fa/pf_unregctx.c @@ -0,0 +1,8 @@ +#include + +extern s32 PFVOL_unregctx(void); +extern s32 PFAPI_convertReturnValue(s32 error); + +s32 pf2_unregctx(void) { + return PFAPI_convertReturnValue(PFVOL_unregctx()); +} diff --git a/libs/RVL_SDK/src/fa/pf_volume_apiadd.c b/libs/RVL_SDK/src/fa/pf_volume_apiadd.c new file mode 100644 index 00000000..a626fcf6 --- /dev/null +++ b/libs/RVL_SDK/src/fa/pf_volume_apiadd.c @@ -0,0 +1,241 @@ +#include + +typedef struct PFVOL_VOLUME PFVOL_VOLUME; + +typedef struct PFVOL_BPB { + u16 bytes_per_sector; + u16 num_reserved_sectors; + u16 num_root_dir_entries; + u8 sectors_per_cluster; + u8 num_FATs; + u32 total_sectors; + u32 sectors_per_FAT; + u32 root_dir_cluster; + u16 fs_info_sector; + u16 backup_boot_sector; + u16 ext_flags; + u8 media; + u8 pad_1b; + s32 fat_type; + u8 log2_bytes_per_sector; + u8 log2_sectors_per_cluster; + u8 num_active_FATs; + u8 pad_23; + u16 num_root_dir_sectors; + u16 pad_26; + u32 active_FAT_sector; + u32 first_root_dir_sector; + u32 first_data_sector; + u32 num_clusters; +} PFVOL_BPB; + +typedef struct PFVOL_DIR_ENTRY { + u16 long_name[261]; + u8 num_entry_LFNs; + u8 ordinal; + u8 check_sum; + u8 pad_20d; + s8 short_name[13]; + u8 small_letter_flag; + u8 attr; + u8 create_time_ms; + u16 create_time; + u16 create_date; + u16 access_date; + u16 modify_time; + u16 modify_date; + u32 file_size; + PFVOL_VOLUME* volume; + u32 path_len; + u32 start_cluster; + u32 entry_sector; + u16 entry_offset; +} PFVOL_DIR_ENTRY; + +typedef struct PFVOL_FAT_HINT { + u32 chain_index; + u32 cluster; + u32 previous_cluster; + u32 reserved; +} PFVOL_FAT_HINT; + +typedef struct PFVOL_LAST_CLUSTER { + u32 num_last_cluster; + u32 max_chain_index; +} PFVOL_LAST_CLUSTER; + +typedef struct PFVOL_FAT_LAST_ACCESS { + u32 chain_index; + u32 cluster; +} PFVOL_FAT_LAST_ACCESS; + +typedef struct PFVOL_CLUSTER_LINK { + u32* buffer; + u16 interval; + u16 interval_offset; + u32 position; + u32 max_count; + u32 save_index; +} PFVOL_CLUSTER_LINK; + +typedef struct PFVOL_FFD { + u32 start_cluster; + u32 flags; + u32* p_start_cluster; + PFVOL_LAST_CLUSTER last_cluster; + PFVOL_FAT_LAST_ACCESS last_access; + PFVOL_CLUSTER_LINK cluster_link; + PFVOL_FAT_HINT* hint; + PFVOL_VOLUME* volume; +} PFVOL_FFD; + +typedef struct PFVOL_STR { + const char* head; + const char* tail; + const char* current; + u32 code_mode; +} PFVOL_STR; + +typedef struct PFVOL_CURRENT_DIR { + u32 stat; + s32 context_id; + PFVOL_DIR_ENTRY directory; +} PFVOL_CURRENT_DIR; + +typedef struct PFVOL_CURRENT_VOLUME { + u32 stat; + s32 context_id; + PFVOL_VOLUME* volume; +} PFVOL_CURRENT_VOLUME; + +typedef struct PFVOL_CONTEXT { + u32 stat; + s32 context_id; +} PFVOL_CONTEXT; + +typedef struct PFVOL_VOLUME_INFO { + s8 label[12]; + u8 attr; + u8 reserved_0d[3]; + u32 time; + u32 date; +} PFVOL_VOLUME_INFO; + +typedef struct PFVOL_CHARCODE { + s32 (*oem2unicode)(const s8*, u16*); + s32 (*unicode2oem)(const u16*, s8*); + s32 (*oem_char_width)(const s8*); + s32 (*is_oem_mb_char)(s8, s32); + s32 (*unicode_char_width)(const u16*); + s32 (*is_unicode_mb_char)(u16, s32); +} PFVOL_CHARCODE; + +typedef struct PFVOL_CACHE_SETTING { + void* pages; + void* buffers; + u16 num_fat_pages; + u16 num_data_pages; + u32 num_fat_buf_size; + u32 num_data_buf_size; +} PFVOL_CACHE_SETTING; + +typedef struct PFVOL_DRIVER { + void* partition; + PFVOL_CACHE_SETTING* cache; + s8 drive; + u8 stat; + u8 pad_0a[2]; +} PFVOL_DRIVER; + +typedef struct PFVOL_OPEN_SFD { + u8 gap_0000[0x3C]; + PFVOL_DIR_ENTRY directory_entry; +} PFVOL_OPEN_SFD; + +typedef struct PFVOL_OPEN_FILE { + u32 stat; + u32 reserved; + PFVOL_OPEN_SFD* stream; + u8 gap_000C[0x24]; +} PFVOL_OPEN_FILE; + +typedef struct PFVOL_CLUSTER_SETTING { + u32* buffer; + u32 max_count; + u16 interval; + u16 reserved; +} PFVOL_CLUSTER_SETTING; + +struct PFVOL_VOLUME { + PFVOL_BPB bpb; + u32 num_free_clusters; + u32 last_free_cluster; + u8 gap_0040[0xD0C]; + PFVOL_OPEN_FILE files[5]; + u8 gap_0E3C[0x7E0]; + u32 num_open_files; + u32 num_open_dirs; + u32 cache_flags; + u16 num_fat_pages; + u16 num_data_pages; + u8 gap_162C[0x10]; + u32 num_fat_buf_size; + u32 num_data_buf_size; + u8 gap_1644[4]; + s8 label[12]; + PFVOL_CURRENT_DIR current_dir[4]; + u32 file_buffer_count; + void* file_buffers; + void* current_file_buffer; + u32 last_error; + u32 last_driver_error; + u32 reserved_1f88; + u16 flags; + s8 drv_char; + u8 drive_state; + u16 fsi_flag; + u16 reserved_1f92; + u16 cluster_link_flags; + u16 cluster_link_interval; + u32* cluster_link_buffer; + u32 cluster_link_capacity; + void* driver_partition; + u8 gap_1fa4[4]; + const u8* format_options; +}; + +typedef struct PFVOL_SET { + u32 flags; + u32 reserved_004; + PFVOL_VOLUME* current_volume; + PFVOL_CURRENT_VOLUME context_volume[3]; + s32 num_attached_drives; + s32 num_mounted_volumes; + u32 config; + void* user_data; + s32 last_error; + s32 last_driver_error; + PFVOL_CHARCODE codeset; + u32 setting; + u8 gap_0064[0x0C]; + PFVOL_CONTEXT context[3]; + PFVOL_VOLUME volumes[26]; +} PFVOL_SET; + +extern PFVOL_SET pf_vol_set; +extern PFVOL_VOLUME* PFVOL_GetVolumeFromDrvChar(s8 drive); + +s32 PFVOL_iswriteprotected(s8 drive, u32* protected_status) { + PFVOL_VOLUME* volume = PFVOL_GetVolumeFromDrvChar(drive); + if (!(volume->flags & 8)) { + pf_vol_set.last_error = 9; + volume->last_error = 9; + return 9; + } + if (volume->flags & 2) { + *protected_status = 1; + } else { + *protected_status = 0; + } + return 0; +} diff --git a/libs/RVL_SDK/src/fa/pf_w_cdelete.c b/libs/RVL_SDK/src/fa/pf_w_cdelete.c new file mode 100644 index 00000000..8d28ed10 --- /dev/null +++ b/libs/RVL_SDK/src/fa/pf_w_cdelete.c @@ -0,0 +1,33 @@ +#include + +typedef struct PF_API_STRING { + const s8* head; + const s8* tail; + const s8* current; + u32 code_mode; +} PF_API_STRING; + +typedef struct PF_API_VOLUME_SET { + u8 reserved[0x40]; + s32 last_error; +} PF_API_VOLUME_SET; + +extern PF_API_VOLUME_SET pf_vol_set; +extern s32 PFSTR_InitStr(PF_API_STRING* string, const s8* text, u32 mode); +extern s32 PFAPI_convertReturnValue(s32 error); + +extern s32 PFFILE_cdelete(PF_API_STRING* path, u32 position, u32 count, u32* completed); + +u32 pf2_w_cdelete(const u16* path, u32 position, u32 count) { + PF_API_STRING path_string; + u32 completed = 0; + s32 error; + + error = PFSTR_InitStr(&path_string, (const s8*)path, 2); + if (error == 0) { + error = PFFILE_cdelete(&path_string, position, count, &completed); + } else { + pf_vol_set.last_error = error; + } + return completed; +} diff --git a/libs/RVL_SDK/src/fa/pf_w_chdir.c b/libs/RVL_SDK/src/fa/pf_w_chdir.c new file mode 100644 index 00000000..4d3ca481 --- /dev/null +++ b/libs/RVL_SDK/src/fa/pf_w_chdir.c @@ -0,0 +1,32 @@ +#include + +typedef struct PF_API_STRING { + const s8* head; + const s8* tail; + const s8* current; + u32 code_mode; +} PF_API_STRING; + +typedef struct PF_API_VOLUME_SET { + u8 reserved[0x40]; + s32 last_error; +} PF_API_VOLUME_SET; + +extern PF_API_VOLUME_SET pf_vol_set; +extern s32 PFSTR_InitStr(PF_API_STRING* string, const s8* text, u32 mode); +extern s32 PFAPI_convertReturnValue(s32 error); + +extern s32 PFDIR_chdir(PF_API_STRING* path); + +s32 pf2_w_chdir(const u16* path) { + PF_API_STRING path_string; + s32 error; + + error = PFSTR_InitStr(&path_string, (const s8*)path, 2); + if (error == 0) { + error = PFDIR_chdir(&path_string); + } else { + pf_vol_set.last_error = error; + } + return PFAPI_convertReturnValue(error); +} diff --git a/libs/RVL_SDK/src/fa/pf_w_chdmod.c b/libs/RVL_SDK/src/fa/pf_w_chdmod.c new file mode 100644 index 00000000..0a8787c6 --- /dev/null +++ b/libs/RVL_SDK/src/fa/pf_w_chdmod.c @@ -0,0 +1,32 @@ +#include + +typedef struct PF_API_STRING { + const s8* head; + const s8* tail; + const s8* current; + u32 code_mode; +} PF_API_STRING; + +typedef struct PF_API_VOLUME_SET { + u8 reserved[0x40]; + s32 last_error; +} PF_API_VOLUME_SET; + +extern PF_API_VOLUME_SET pf_vol_set; +extern s32 PFSTR_InitStr(PF_API_STRING* string, const s8* text, u32 mode); +extern s32 PFAPI_convertReturnValue(s32 error); + +extern s32 PFDIR_chdmod(PF_API_STRING* path, u8 attributes); + +s32 pf2_w_chdmod(const u16* path, u32 attributes) { + PF_API_STRING path_string; + s32 error; + + error = PFSTR_InitStr(&path_string, (const s8*)path, 2); + if (error == 0) { + error = PFDIR_chdmod(&path_string, attributes); + } else { + pf_vol_set.last_error = error; + } + return PFAPI_convertReturnValue(error); +} diff --git a/libs/RVL_SDK/src/fa/pf_w_chmod.c b/libs/RVL_SDK/src/fa/pf_w_chmod.c new file mode 100644 index 00000000..23846807 --- /dev/null +++ b/libs/RVL_SDK/src/fa/pf_w_chmod.c @@ -0,0 +1,32 @@ +#include + +typedef struct PF_API_STRING { + const s8* head; + const s8* tail; + const s8* current; + u32 code_mode; +} PF_API_STRING; + +typedef struct PF_API_VOLUME_SET { + u8 reserved[0x40]; + s32 last_error; +} PF_API_VOLUME_SET; + +extern PF_API_VOLUME_SET pf_vol_set; +extern s32 PFSTR_InitStr(PF_API_STRING* string, const s8* text, u32 mode); +extern s32 PFAPI_convertReturnValue(s32 error); + +extern s32 PFDIR_chmod(PF_API_STRING* path, u8 attributes); + +s32 pf2_w_chmod(const u16* path, u32 attributes) { + PF_API_STRING path_string; + s32 error; + + error = PFSTR_InitStr(&path_string, (const s8*)path, 2); + if (error == 0) { + error = PFDIR_chmod(&path_string, attributes); + } else { + pf_vol_set.last_error = error; + } + return PFAPI_convertReturnValue(error); +} diff --git a/libs/RVL_SDK/src/fa/pf_w_cinsert.c b/libs/RVL_SDK/src/fa/pf_w_cinsert.c new file mode 100644 index 00000000..011abe41 --- /dev/null +++ b/libs/RVL_SDK/src/fa/pf_w_cinsert.c @@ -0,0 +1,33 @@ +#include + +typedef struct PF_API_STRING { + const s8* head; + const s8* tail; + const s8* current; + u32 code_mode; +} PF_API_STRING; + +typedef struct PF_API_VOLUME_SET { + u8 reserved[0x40]; + s32 last_error; +} PF_API_VOLUME_SET; + +extern PF_API_VOLUME_SET pf_vol_set; +extern s32 PFSTR_InitStr(PF_API_STRING* string, const s8* text, u32 mode); +extern s32 PFAPI_convertReturnValue(s32 error); + +extern s32 PFFILE_cinsert(PF_API_STRING* path, u32 position, u32 count, u32* completed); + +u32 pf2_w_cinsert(const u16* path, u32 position, u32 count) { + PF_API_STRING path_string; + u32 completed = 0; + s32 error; + + error = PFSTR_InitStr(&path_string, (const s8*)path, 2); + if (error == 0) { + error = PFFILE_cinsert(&path_string, position, count, &completed); + } else { + pf_vol_set.last_error = error; + } + return completed; +} diff --git a/libs/RVL_SDK/src/fa/pf_w_combine.c b/libs/RVL_SDK/src/fa/pf_w_combine.c new file mode 100644 index 00000000..21f5fbdc --- /dev/null +++ b/libs/RVL_SDK/src/fa/pf_w_combine.c @@ -0,0 +1,34 @@ +#include + +typedef struct PF_API_STRING { + const s8* head; + const s8* tail; + const s8* current; + u32 code_mode; +} PF_API_STRING; + +typedef struct PF_API_VOLUME_SET { + u8 reserved[0x40]; + s32 last_error; +} PF_API_VOLUME_SET; + +extern PF_API_VOLUME_SET pf_vol_set; +extern s32 PFSTR_InitStr(PF_API_STRING* string, const s8* text, u32 mode); +extern s32 PFAPI_convertReturnValue(s32 error); + +extern s32 PFFILE_combine(PF_API_STRING* source, PF_API_STRING* destination); + +s32 pf2_w_combine(const u16* source, const u16* destination) { + PF_API_STRING source_string; + PF_API_STRING destination_string; + s32 error; + + error = PFSTR_InitStr(&source_string, (const s8*)source, 2); + error |= PFSTR_InitStr(&destination_string, (const s8*)destination, 2); + if (error == 0) { + error = PFFILE_combine(&source_string, &destination_string); + } else { + pf_vol_set.last_error = error; + } + return PFAPI_convertReturnValue(error); +} diff --git a/libs/RVL_SDK/src/fa/pf_w_create.c b/libs/RVL_SDK/src/fa/pf_w_create.c new file mode 100644 index 00000000..9f440436 --- /dev/null +++ b/libs/RVL_SDK/src/fa/pf_w_create.c @@ -0,0 +1,34 @@ +#include + +typedef struct PF_API_STRING { + const s8* head; + const s8* tail; + const s8* current; + u32 code_mode; +} PF_API_STRING; + +typedef struct PF_API_VOLUME_SET { + u8 reserved[0x40]; + s32 last_error; +} PF_API_VOLUME_SET; + +extern PF_API_VOLUME_SET pf_vol_set; +extern s32 PFSTR_InitStr(PF_API_STRING* string, const s8* text, u32 mode); +extern s32 PFAPI_convertReturnValue(s32 error); + +extern s32 PFFILE_fopen(PF_API_STRING* path, s32 mode, FAFILE** file); +extern void* PFAPI_convertReturnValue2NULL(s32 error, void* stream); + +FAFILE* pf2_w_create(const u16* path) { + PF_API_STRING path_string; + FAFILE* file; + s32 error; + + error = PFSTR_InitStr(&path_string, (const s8*)path, 2); + if (error == 0) { + error = PFFILE_fopen(&path_string, 25, &file); + } else { + pf_vol_set.last_error = error; + } + return PFAPI_convertReturnValue2NULL(error, file); +} diff --git a/libs/RVL_SDK/src/fa/pf_w_createdir.c b/libs/RVL_SDK/src/fa/pf_w_createdir.c new file mode 100644 index 00000000..ee572bf6 --- /dev/null +++ b/libs/RVL_SDK/src/fa/pf_w_createdir.c @@ -0,0 +1,32 @@ +#include + +typedef struct PF_API_STRING { + const s8* head; + const s8* tail; + const s8* current; + u32 code_mode; +} PF_API_STRING; + +typedef struct PF_API_VOLUME_SET { + u8 reserved[0x40]; + s32 last_error; +} PF_API_VOLUME_SET; + +extern PF_API_VOLUME_SET pf_vol_set; +extern s32 PFSTR_InitStr(PF_API_STRING* string, const s8* text, u32 mode); +extern s32 PFAPI_convertReturnValue(s32 error); + +extern s32 PFDIR_createdir(PF_API_STRING* path, s32 mode, FADta* data); + +s32 pf2_w_createdir(const u16* path, s32 mode, FADta* data) { + PF_API_STRING path_string; + s32 error; + + error = PFSTR_InitStr(&path_string, (const s8*)path, 2); + if (error == 0) { + error = PFDIR_createdir(&path_string, mode, data); + } else { + pf_vol_set.last_error = error; + } + return PFAPI_convertReturnValue(error); +} diff --git a/libs/RVL_SDK/src/fa/pf_w_cut.c b/libs/RVL_SDK/src/fa/pf_w_cut.c new file mode 100644 index 00000000..5b08db6d --- /dev/null +++ b/libs/RVL_SDK/src/fa/pf_w_cut.c @@ -0,0 +1,36 @@ +#include + +typedef struct PF_API_STRING { + const s8* head; + const s8* tail; + const s8* current; + u32 code_mode; +} PF_API_STRING; + +typedef struct PF_API_VOLUME_SET { + u8 reserved[0x40]; + s32 last_error; +} PF_API_VOLUME_SET; + +extern PF_API_VOLUME_SET pf_vol_set; +extern s32 PFSTR_InitStr(PF_API_STRING* string, const s8* text, u32 mode); +extern s32 PFAPI_convertReturnValue(s32 error); + +extern s32 PFFILE_cdelete(PF_API_STRING* path, u32 position, u32 count, u32* completed); + +s32 pf2_w_cut(const u16* path, u32 position) { + PF_API_STRING path_string; + u32 completed; + s32 error; + + error = PFSTR_InitStr(&path_string, (const s8*)path, 2); + if (error == 0) { + PFFILE_cdelete(&path_string, position, 1, &completed); + if (completed != 1) { + error = -1; + } + } else { + pf_vol_set.last_error = error; + } + return PFAPI_convertReturnValue(error); +} diff --git a/libs/RVL_SDK/src/fa/pf_w_divide.c b/libs/RVL_SDK/src/fa/pf_w_divide.c new file mode 100644 index 00000000..a59a2514 --- /dev/null +++ b/libs/RVL_SDK/src/fa/pf_w_divide.c @@ -0,0 +1,34 @@ +#include + +typedef struct PF_API_STRING { + const s8* head; + const s8* tail; + const s8* current; + u32 code_mode; +} PF_API_STRING; + +typedef struct PF_API_VOLUME_SET { + u8 reserved[0x40]; + s32 last_error; +} PF_API_VOLUME_SET; + +extern PF_API_VOLUME_SET pf_vol_set; +extern s32 PFSTR_InitStr(PF_API_STRING* string, const s8* text, u32 mode); +extern s32 PFAPI_convertReturnValue(s32 error); + +extern s32 PFFILE_divide(PF_API_STRING* source, PF_API_STRING* destination, u32 offset); + +s32 pf2_w_divide(const u16* source, const u16* destination, u32 offset) { + PF_API_STRING source_string; + PF_API_STRING destination_string; + s32 error; + + error = PFSTR_InitStr(&source_string, (const s8*)source, 2); + error |= PFSTR_InitStr(&destination_string, (const s8*)destination, 2); + if (error == 0) { + error = PFFILE_divide(&source_string, &destination_string, offset); + } else { + pf_vol_set.last_error = error; + } + return PFAPI_convertReturnValue(error); +} diff --git a/libs/RVL_SDK/src/fa/pf_w_fconcat.c b/libs/RVL_SDK/src/fa/pf_w_fconcat.c new file mode 100644 index 00000000..8a88ab18 --- /dev/null +++ b/libs/RVL_SDK/src/fa/pf_w_fconcat.c @@ -0,0 +1,34 @@ +#include + +typedef struct PF_API_STRING { + const s8* head; + const s8* tail; + const s8* current; + u32 code_mode; +} PF_API_STRING; + +typedef struct PF_API_VOLUME_SET { + u8 reserved[0x40]; + s32 last_error; +} PF_API_VOLUME_SET; + +extern PF_API_VOLUME_SET pf_vol_set; +extern s32 PFSTR_InitStr(PF_API_STRING* string, const s8* text, u32 mode); +extern s32 PFAPI_convertReturnValue(s32 error); + +extern s32 PFFILE_combine(PF_API_STRING* source, PF_API_STRING* destination); + +s32 pf2_w_fconcat(const u16* source, const u16* destination) { + PF_API_STRING source_string; + PF_API_STRING destination_string; + s32 error; + + error = PFSTR_InitStr(&source_string, (const s8*)source, 2); + error |= PFSTR_InitStr(&destination_string, (const s8*)destination, 2); + if (error == 0) { + error = PFFILE_combine(&source_string, &destination_string); + } else { + pf_vol_set.last_error = error; + } + return PFAPI_convertReturnValue(error); +} diff --git a/libs/RVL_SDK/src/fa/pf_w_fopen.c b/libs/RVL_SDK/src/fa/pf_w_fopen.c new file mode 100644 index 00000000..43e94349 --- /dev/null +++ b/libs/RVL_SDK/src/fa/pf_w_fopen.c @@ -0,0 +1,41 @@ +#include + +typedef struct PFF2_STR { + const s8* p_head; + const s8* p_tail; + const s8* p_current; + u32 code_mode; +} PFF2_STR; + +typedef struct PFF2_VOL_SET { + u8 reserved[0x40]; + s32 last_error; +} PFF2_VOL_SET; + +extern PFF2_VOL_SET pf_vol_set; +extern s32 PFWAPI_ParseOpenModeString(const u16* mode_str); +extern s32 PFSTR_InitStr(PFF2_STR* path, const s8* text, u32 code_mode); +extern s32 PFFILE_fopen(PFF2_STR* path, s32 mode, FAFILE** result); +extern FAFILE* PFAPI_convertReturnValue2NULL(s32 err, FAFILE* p_stream); + +FAFILE* pf2_w_fopen(const u16* path, const u16* mode) { + u32 open_mode; + FAFILE* p_file; + PFF2_STR path_str; + s32 err; + + open_mode = PFWAPI_ParseOpenModeString(mode); + if (open_mode == 0) { + pf_vol_set.last_error = 10; + p_file = NULL; + } else { + err = PFSTR_InitStr(&path_str, (const s8*)path, 2); + if (err == 0) { + err = PFFILE_fopen(&path_str, open_mode, &p_file); + } else { + pf_vol_set.last_error = err; + } + p_file = PFAPI_convertReturnValue2NULL(err, p_file); + } + return p_file; +} diff --git a/libs/RVL_SDK/src/fa/pf_w_fsexec.c b/libs/RVL_SDK/src/fa/pf_w_fsexec.c new file mode 100644 index 00000000..914540af --- /dev/null +++ b/libs/RVL_SDK/src/fa/pf_w_fsexec.c @@ -0,0 +1,8 @@ +#include + +extern s32 PFDIR_fsexec(FADta* data, u32 flags, u32 mode); +extern s32 PFAPI_convertReturnValue(s32 error); + +s32 pf2_w_fsexec(FADta* data, u32 flags, u32 mode) { + return PFAPI_convertReturnValue(PFDIR_fsexec(data, flags, mode)); +} diff --git a/libs/RVL_SDK/src/fa/pf_w_fsfirst.c b/libs/RVL_SDK/src/fa/pf_w_fsfirst.c new file mode 100644 index 00000000..06dbaf5d --- /dev/null +++ b/libs/RVL_SDK/src/fa/pf_w_fsfirst.c @@ -0,0 +1,32 @@ +#include + +typedef struct PF_API_STRING { + const s8* head; + const s8* tail; + const s8* current; + u32 code_mode; +} PF_API_STRING; + +typedef struct PF_API_VOLUME_SET { + u8 reserved[0x40]; + s32 last_error; +} PF_API_VOLUME_SET; + +extern PF_API_VOLUME_SET pf_vol_set; +extern s32 PFSTR_InitStr(PF_API_STRING* string, const s8* text, u32 mode); +extern s32 PFAPI_convertReturnValue(s32 error); + +extern s32 PFDIR_fsfirst(PF_API_STRING* path, u8 attributes, FADta* data); + +s32 pf2_w_fsfirst(const u16* path, u8 attributes, FADta* data) { + PF_API_STRING path_string; + s32 error; + + error = PFSTR_InitStr(&path_string, (const s8*)path, 2); + if (error == 0) { + error = PFDIR_fsfirst(&path_string, attributes, data); + } else { + pf_vol_set.last_error = error; + } + return PFAPI_convertReturnValue(error); +} diff --git a/libs/RVL_SDK/src/fa/pf_w_fsnext.c b/libs/RVL_SDK/src/fa/pf_w_fsnext.c new file mode 100644 index 00000000..1d3a9d9e --- /dev/null +++ b/libs/RVL_SDK/src/fa/pf_w_fsnext.c @@ -0,0 +1,8 @@ +#include + +extern s32 PFDIR_fsnext(FADta* data); +extern s32 PFAPI_convertReturnValue(s32 error); + +s32 pf2_w_fsnext(FADta* data) { + return PFAPI_convertReturnValue(PFDIR_fsnext(data)); +} diff --git a/libs/RVL_SDK/src/fa/pf_w_fstat.c b/libs/RVL_SDK/src/fa/pf_w_fstat.c new file mode 100644 index 00000000..90b1c615 --- /dev/null +++ b/libs/RVL_SDK/src/fa/pf_w_fstat.c @@ -0,0 +1,32 @@ +#include + +typedef struct PF_API_STRING { + const s8* head; + const s8* tail; + const s8* current; + u32 code_mode; +} PF_API_STRING; + +typedef struct PF_API_VOLUME_SET { + u8 reserved[0x40]; + s32 last_error; +} PF_API_VOLUME_SET; + +extern PF_API_VOLUME_SET pf_vol_set; +extern s32 PFSTR_InitStr(PF_API_STRING* string, const s8* text, u32 mode); +extern s32 PFAPI_convertReturnValue(s32 error); + +extern s32 PFDIR_fstat(PF_API_STRING* path, FAFileStat* stat); + +s32 pf2_w_fstat(const u16* path, FAFileStat* stat) { + PF_API_STRING path_string; + s32 error; + + error = PFSTR_InitStr(&path_string, (const s8*)path, 2); + if (error == 0) { + error = PFDIR_fstat(&path_string, stat); + } else { + pf_vol_set.last_error = error; + } + return PFAPI_convertReturnValue(error); +} diff --git a/libs/RVL_SDK/src/fa/pf_w_insert.c b/libs/RVL_SDK/src/fa/pf_w_insert.c new file mode 100644 index 00000000..e511d2b7 --- /dev/null +++ b/libs/RVL_SDK/src/fa/pf_w_insert.c @@ -0,0 +1,42 @@ +#include + +typedef struct PF_API_STRING { + const s8* head; + const s8* tail; + const s8* current; + u32 code_mode; +} PF_API_STRING; + +typedef struct PF_API_VOLUME_SET { + u8 reserved[0x40]; + s32 last_error; +} PF_API_VOLUME_SET; + +extern PF_API_VOLUME_SET pf_vol_set; +extern s32 PFSTR_InitStr(PF_API_STRING* string, const s8* text, u32 mode); +extern s32 PFAPI_convertReturnValue(s32 error); + +extern s32 PFFILE_cinsert(PF_API_STRING* path, u32 position, u32 count, u32* completed); +extern s32 PFFILE_cdelete(PF_API_STRING* path, u32 position, u32 count, u32* completed); + +s32 pf2_w_insert(const u16* path, u32 count) { + PF_API_STRING path_string; + u32 inserted; + u32 deleted; + s32 error; + + error = PFSTR_InitStr(&path_string, (const s8*)path, 2); + if (error == 0) { + PFFILE_cinsert(&path_string, 0, count, &inserted); + if (count != inserted || count == 0) { + if (inserted != 0) { + PFSTR_InitStr(&path_string, (const s8*)path, 2); + PFFILE_cdelete(&path_string, 0, inserted, &deleted); + } + error = -1; + } + } else { + pf_vol_set.last_error = error; + } + return PFAPI_convertReturnValue(error); +} diff --git a/libs/RVL_SDK/src/fa/pf_w_mkdir.c b/libs/RVL_SDK/src/fa/pf_w_mkdir.c new file mode 100644 index 00000000..cacf27f8 --- /dev/null +++ b/libs/RVL_SDK/src/fa/pf_w_mkdir.c @@ -0,0 +1,32 @@ +#include + +typedef struct PF_API_STRING { + const s8* head; + const s8* tail; + const s8* current; + u32 code_mode; +} PF_API_STRING; + +typedef struct PF_API_VOLUME_SET { + u8 reserved[0x40]; + s32 last_error; +} PF_API_VOLUME_SET; + +extern PF_API_VOLUME_SET pf_vol_set; +extern s32 PFSTR_InitStr(PF_API_STRING* string, const s8* text, u32 mode); +extern s32 PFAPI_convertReturnValue(s32 error); + +extern s32 PFDIR_mkdir(PF_API_STRING* path); + +s32 pf2_w_mkdir(const u16* path) { + PF_API_STRING path_string; + s32 error; + + error = PFSTR_InitStr(&path_string, (const s8*)path, 2); + if (error == 0) { + error = PFDIR_mkdir(&path_string); + } else { + pf_vol_set.last_error = error; + } + return PFAPI_convertReturnValue(error); +} diff --git a/libs/RVL_SDK/src/fa/pf_w_move.c b/libs/RVL_SDK/src/fa/pf_w_move.c new file mode 100644 index 00000000..cccd9e0e --- /dev/null +++ b/libs/RVL_SDK/src/fa/pf_w_move.c @@ -0,0 +1,34 @@ +#include + +typedef struct PF_API_STRING { + const s8* head; + const s8* tail; + const s8* current; + u32 code_mode; +} PF_API_STRING; + +typedef struct PF_API_VOLUME_SET { + u8 reserved[0x40]; + s32 last_error; +} PF_API_VOLUME_SET; + +extern PF_API_VOLUME_SET pf_vol_set; +extern s32 PFSTR_InitStr(PF_API_STRING* string, const s8* text, u32 mode); +extern s32 PFAPI_convertReturnValue(s32 error); + +extern s32 PFDIR_move(PF_API_STRING* source, PF_API_STRING* destination); + +s32 pf2_w_move(const u16* source, const u16* destination) { + PF_API_STRING source_string; + PF_API_STRING destination_string; + s32 error; + + error = PFSTR_InitStr(&source_string, (const s8*)source, 2); + error |= PFSTR_InitStr(&destination_string, (const s8*)destination, 2); + if (error == 0) { + error = PFDIR_move(&source_string, &destination_string); + } else { + pf_vol_set.last_error = error; + } + return PFAPI_convertReturnValue(error); +} diff --git a/libs/RVL_SDK/src/fa/pf_w_opendir.c b/libs/RVL_SDK/src/fa/pf_w_opendir.c new file mode 100644 index 00000000..2f430b99 --- /dev/null +++ b/libs/RVL_SDK/src/fa/pf_w_opendir.c @@ -0,0 +1,34 @@ +#include + +typedef struct PF_API_STRING { + const s8* head; + const s8* tail; + const s8* current; + u32 code_mode; +} PF_API_STRING; + +typedef struct PF_API_VOLUME_SET { + u8 reserved[0x40]; + s32 last_error; +} PF_API_VOLUME_SET; + +extern PF_API_VOLUME_SET pf_vol_set; +extern s32 PFSTR_InitStr(PF_API_STRING* string, const s8* text, u32 mode); +extern s32 PFAPI_convertReturnValue(s32 error); + +extern s32 PFDIR_opendir(PF_API_STRING* path, FADIR** directory); +extern void* PFAPI_convertReturnValue2NULL(s32 error, void* stream); + +FADIR* pf2_w_opendir(const u16* path) { + PF_API_STRING path_string; + FADIR* directory; + s32 error; + + error = PFSTR_InitStr(&path_string, (const s8*)path, 2); + if (error == 0) { + error = PFDIR_opendir(&path_string, &directory); + } else { + pf_vol_set.last_error = error; + } + return PFAPI_convertReturnValue2NULL(error, directory); +} diff --git a/libs/RVL_SDK/src/fa/pf_w_remove.c b/libs/RVL_SDK/src/fa/pf_w_remove.c new file mode 100644 index 00000000..77bd1fee --- /dev/null +++ b/libs/RVL_SDK/src/fa/pf_w_remove.c @@ -0,0 +1,32 @@ +#include + +typedef struct PF_API_STRING { + const s8* head; + const s8* tail; + const s8* current; + u32 code_mode; +} PF_API_STRING; + +typedef struct PF_API_VOLUME_SET { + u8 reserved[0x40]; + s32 last_error; +} PF_API_VOLUME_SET; + +extern PF_API_VOLUME_SET pf_vol_set; +extern s32 PFSTR_InitStr(PF_API_STRING* string, const s8* text, u32 mode); +extern s32 PFAPI_convertReturnValue(s32 error); + +extern s32 PFFILE_remove(PF_API_STRING* path); + +s32 pf2_w_remove(const u16* path) { + PF_API_STRING path_string; + s32 error; + + error = PFSTR_InitStr(&path_string, (const s8*)path, 2); + if (error == 0) { + error = PFFILE_remove(&path_string); + } else { + pf_vol_set.last_error = error; + } + return PFAPI_convertReturnValue(error); +} diff --git a/libs/RVL_SDK/src/fa/pf_w_rename.c b/libs/RVL_SDK/src/fa/pf_w_rename.c new file mode 100644 index 00000000..e72a7264 --- /dev/null +++ b/libs/RVL_SDK/src/fa/pf_w_rename.c @@ -0,0 +1,34 @@ +#include + +typedef struct PF_API_STRING { + const s8* head; + const s8* tail; + const s8* current; + u32 code_mode; +} PF_API_STRING; + +typedef struct PF_API_VOLUME_SET { + u8 reserved[0x40]; + s32 last_error; +} PF_API_VOLUME_SET; + +extern PF_API_VOLUME_SET pf_vol_set; +extern s32 PFSTR_InitStr(PF_API_STRING* string, const s8* text, u32 mode); +extern s32 PFAPI_convertReturnValue(s32 error); + +extern s32 PFDIR_rename(PF_API_STRING* source, PF_API_STRING* destination); + +s32 pf2_w_rename(const u16* source, const u16* destination) { + PF_API_STRING source_string; + PF_API_STRING destination_string; + s32 error; + + error = PFSTR_InitStr(&source_string, (const s8*)source, 2); + error |= PFSTR_InitStr(&destination_string, (const s8*)destination, 2); + if (error == 0) { + error = PFDIR_rename(&source_string, &destination_string); + } else { + pf_vol_set.last_error = error; + } + return PFAPI_convertReturnValue(error); +} diff --git a/libs/RVL_SDK/src/fa/pf_w_rmdir.c b/libs/RVL_SDK/src/fa/pf_w_rmdir.c new file mode 100644 index 00000000..5f89159b --- /dev/null +++ b/libs/RVL_SDK/src/fa/pf_w_rmdir.c @@ -0,0 +1,32 @@ +#include + +typedef struct PF_API_STRING { + const s8* head; + const s8* tail; + const s8* current; + u32 code_mode; +} PF_API_STRING; + +typedef struct PF_API_VOLUME_SET { + u8 reserved[0x40]; + s32 last_error; +} PF_API_VOLUME_SET; + +extern PF_API_VOLUME_SET pf_vol_set; +extern s32 PFSTR_InitStr(PF_API_STRING* string, const s8* text, u32 mode); +extern s32 PFAPI_convertReturnValue(s32 error); + +extern s32 PFDIR_rmdir(PF_API_STRING* path); + +s32 pf2_w_rmdir(const u16* path) { + PF_API_STRING path_string; + s32 error; + + error = PFSTR_InitStr(&path_string, (const s8*)path, 2); + if (error == 0) { + error = PFDIR_rmdir(&path_string); + } else { + pf_vol_set.last_error = error; + } + return PFAPI_convertReturnValue(error); +} diff --git a/libs/RVL_SDK/src/fa/pf_w_xdivide.c b/libs/RVL_SDK/src/fa/pf_w_xdivide.c new file mode 100644 index 00000000..a74d21e2 --- /dev/null +++ b/libs/RVL_SDK/src/fa/pf_w_xdivide.c @@ -0,0 +1,34 @@ +#include + +typedef struct PF_API_STRING { + const s8* head; + const s8* tail; + const s8* current; + u32 code_mode; +} PF_API_STRING; + +typedef struct PF_API_VOLUME_SET { + u8 reserved[0x40]; + s32 last_error; +} PF_API_VOLUME_SET; + +extern PF_API_VOLUME_SET pf_vol_set; +extern s32 PFSTR_InitStr(PF_API_STRING* string, const s8* text, u32 mode); +extern s32 PFAPI_convertReturnValue(s32 error); + +extern s32 PFFILE_divide(PF_API_STRING* source, PF_API_STRING* destination, u32 offset); + +s32 pf2_w_xdivide(const u16* source, const u16* destination, u32 offset) { + PF_API_STRING source_string; + PF_API_STRING destination_string; + s32 error; + + error = PFSTR_InitStr(&source_string, (const s8*)source, 2); + error |= PFSTR_InitStr(&destination_string, (const s8*)destination, 2); + if (error == 0) { + error = PFFILE_divide(&source_string, &destination_string, offset); + } else { + pf_vol_set.last_error = error; + } + return PFAPI_convertReturnValue(error); +} diff --git a/libs/RVL_SDK/src/fa/pf_xdivide.c b/libs/RVL_SDK/src/fa/pf_xdivide.c new file mode 100644 index 00000000..7ee393cf --- /dev/null +++ b/libs/RVL_SDK/src/fa/pf_xdivide.c @@ -0,0 +1,34 @@ +#include + +typedef struct PF_API_STRING { + const s8* head; + const s8* tail; + const s8* current; + u32 code_mode; +} PF_API_STRING; + +typedef struct PF_API_VOLUME_SET { + u8 reserved[0x40]; + s32 last_error; +} PF_API_VOLUME_SET; + +extern PF_API_VOLUME_SET pf_vol_set; +extern s32 PFSTR_InitStr(PF_API_STRING* string, const s8* text, u32 mode); +extern s32 PFAPI_convertReturnValue(s32 error); + +extern s32 PFFILE_divide(PF_API_STRING* source, PF_API_STRING* destination, u32 offset); + +s32 pf2_xdivide(const char* source, const char* destination, u32 offset) { + PF_API_STRING source_string; + PF_API_STRING destination_string; + s32 error; + + error = PFSTR_InitStr(&source_string, (const s8*)source, 1); + error |= PFSTR_InitStr(&destination_string, (const s8*)destination, 1); + if (error == 0) { + error = PFFILE_divide(&source_string, &destination_string, offset); + } else { + pf_vol_set.last_error = error; + } + return PFAPI_convertReturnValue(error); +} diff --git a/libs/RVL_SDK/src/fa/pfs_attach.c b/libs/RVL_SDK/src/fa/pfs_attach.c new file mode 100644 index 00000000..5a0d7bbc --- /dev/null +++ b/libs/RVL_SDK/src/fa/pfs_attach.c @@ -0,0 +1,14 @@ +#include + +s32 pfstub_attach(FADrvTbl* drives, u32 mode) { + PF_STUB_MESSAGE message; + + message.operation = 27; + message.object = drives; + message.callback = NULL; + message.data = (void*)mode; + if (pfstub_com_massage(&message) == -1) { + return -1; + } + return message.result.status; +} diff --git a/libs/RVL_SDK/src/fa/pfs_buffering.c b/libs/RVL_SDK/src/fa/pfs_buffering.c new file mode 100644 index 00000000..4a7b4cd7 --- /dev/null +++ b/libs/RVL_SDK/src/fa/pfs_buffering.c @@ -0,0 +1,14 @@ +#include + +s32 pfstub_buffering(s8 drive, u32 mode) { + PF_STUB_MESSAGE message; + + message.operation = 16; + message.drive = drive; + message.value = mode; + message.callback = NULL; + if (pfstub_com_massage(&message) == -1) { + return -1; + } + return message.result.status; +} diff --git a/libs/RVL_SDK/src/fa/pfs_create.c b/libs/RVL_SDK/src/fa/pfs_create.c new file mode 100644 index 00000000..d1a3e478 --- /dev/null +++ b/libs/RVL_SDK/src/fa/pfs_create.c @@ -0,0 +1,14 @@ +#include + +FAFILE* pfstub_create(const char* path, int mode) { + PF_STUB_MESSAGE message; + + message.operation = 0; + message.object = path; + message.value = mode; + message.callback = NULL; + if (pfstub_com_massage(&message) == -1) { + return NULL; + } + return message.result.stream; +} diff --git a/libs/RVL_SDK/src/fa/pfs_createdir.c b/libs/RVL_SDK/src/fa/pfs_createdir.c new file mode 100644 index 00000000..3a8b5c16 --- /dev/null +++ b/libs/RVL_SDK/src/fa/pfs_createdir.c @@ -0,0 +1,15 @@ +#include + +s32 pfstub_createdir(const char* path, s32 mode, FADta* data) { + PF_STUB_MESSAGE message; + + message.operation = 65; + message.object = path; + message.value = mode; + message.data = data; + message.callback = NULL; + if (pfstub_com_massage(&message) == -1) { + return -1; + } + return message.result.status; +} diff --git a/libs/RVL_SDK/src/fa/pfs_detach.c b/libs/RVL_SDK/src/fa/pfs_detach.c new file mode 100644 index 00000000..6577fea4 --- /dev/null +++ b/libs/RVL_SDK/src/fa/pfs_detach.c @@ -0,0 +1,13 @@ +#include + +s32 pfstub_detach(s8 drive) { + PF_STUB_MESSAGE message; + + message.operation = 41; + message.drive = drive; + message.callback = NULL; + if (pfstub_com_massage(&message) == -1) { + return -1; + } + return message.result.status; +} diff --git a/libs/RVL_SDK/src/fa/pfs_errnum.c b/libs/RVL_SDK/src/fa/pfs_errnum.c new file mode 100644 index 00000000..7ab1c00f --- /dev/null +++ b/libs/RVL_SDK/src/fa/pfs_errnum.c @@ -0,0 +1,12 @@ +#include + +s32 pfstub_errnum(void) { + PF_STUB_MESSAGE message; + + message.operation = 19; + message.callback = NULL; + if (pfstub_com_massage(&message) == -1) { + return -1; + } + return message.result.status; +} diff --git a/libs/RVL_SDK/src/fa/pfs_fclose.c b/libs/RVL_SDK/src/fa/pfs_fclose.c new file mode 100644 index 00000000..8090bbf8 --- /dev/null +++ b/libs/RVL_SDK/src/fa/pfs_fclose.c @@ -0,0 +1,13 @@ +#include + +s32 pfstub_fclose(FAFILE* stream) { + PF_STUB_MESSAGE message; + + message.operation = 2; + message.object = stream; + message.callback = NULL; + if (pfstub_com_massage(&message) == -1) { + return -1; + } + return message.result.status; +} diff --git a/libs/RVL_SDK/src/fa/pfs_finfot.c b/libs/RVL_SDK/src/fa/pfs_finfot.c new file mode 100644 index 00000000..755dc8dd --- /dev/null +++ b/libs/RVL_SDK/src/fa/pfs_finfot.c @@ -0,0 +1,14 @@ +#include + +s32 pfstub_finfo(FAFILE* stream, FAFileInfo* info) { + PF_STUB_MESSAGE message; + + message.operation = 45; + message.object = stream; + message.data = info; + message.callback = NULL; + if (pfstub_com_massage(&message) == -1) { + return -1; + } + return message.result.status; +} diff --git a/libs/RVL_SDK/src/fa/pfs_fopen.c b/libs/RVL_SDK/src/fa/pfs_fopen.c new file mode 100644 index 00000000..f6528e1c --- /dev/null +++ b/libs/RVL_SDK/src/fa/pfs_fopen.c @@ -0,0 +1,14 @@ +#include + +FAFILE* pfstub_fopen(const char* path, const char* mode) { + PF_STUB_MESSAGE message; + + message.operation = 1; + message.object = path; + message.data = mode; + message.callback = NULL; + if (pfstub_com_massage(&message) == -1) { + return NULL; + } + return message.result.stream; +} diff --git a/libs/RVL_SDK/src/fa/pfs_format.c b/libs/RVL_SDK/src/fa/pfs_format.c new file mode 100644 index 00000000..cd5c7cb4 --- /dev/null +++ b/libs/RVL_SDK/src/fa/pfs_format.c @@ -0,0 +1,14 @@ +#include + +s32 pfstub_format(s8 drive, u32 mode) { + PF_STUB_MESSAGE message; + + message.operation = 15; + message.drive = drive; + message.object = (void*)mode; + message.callback = NULL; + if (pfstub_com_massage(&message) == -1) { + return -1; + } + return message.result.status; +} diff --git a/libs/RVL_SDK/src/fa/pfs_fread.c b/libs/RVL_SDK/src/fa/pfs_fread.c new file mode 100644 index 00000000..24b1fa79 --- /dev/null +++ b/libs/RVL_SDK/src/fa/pfs_fread.c @@ -0,0 +1,16 @@ +#include + +u32 pfstub_fread(void* buffer, u32 size, u32 count, FAFILE* stream) { + PF_STUB_MESSAGE message; + + message.operation = 3; + message.object = buffer; + message.value = size; + message.count = count; + message.data = stream; + message.callback = NULL; + if (pfstub_com_massage(&message) == -1) { + return 0; + } + return message.result.count; +} diff --git a/libs/RVL_SDK/src/fa/pfs_fseek.c b/libs/RVL_SDK/src/fa/pfs_fseek.c new file mode 100644 index 00000000..52a9013f --- /dev/null +++ b/libs/RVL_SDK/src/fa/pfs_fseek.c @@ -0,0 +1,15 @@ +#include + +s32 pfstub_fseek(FAFILE* stream, s32 offset, s32 origin) { + PF_STUB_MESSAGE message; + + message.operation = 5; + message.object = stream; + message.value = offset; + message.count = origin; + message.callback = NULL; + if (pfstub_com_massage(&message) == -1) { + return -1; + } + return message.result.status; +} diff --git a/libs/RVL_SDK/src/fa/pfs_fsfirst.c b/libs/RVL_SDK/src/fa/pfs_fsfirst.c new file mode 100644 index 00000000..14bbd7c7 --- /dev/null +++ b/libs/RVL_SDK/src/fa/pfs_fsfirst.c @@ -0,0 +1,15 @@ +#include + +s32 pfstub_fsfirst(const char* path, u32 attributes, FADta* data) { + PF_STUB_MESSAGE message; + + message.operation = 28; + message.object = path; + message.value = attributes; + message.data = data; + message.callback = NULL; + if (pfstub_com_massage(&message) == -1) { + return -1; + } + return message.result.status; +} diff --git a/libs/RVL_SDK/src/fa/pfs_fsnext.c b/libs/RVL_SDK/src/fa/pfs_fsnext.c new file mode 100644 index 00000000..bda70d09 --- /dev/null +++ b/libs/RVL_SDK/src/fa/pfs_fsnext.c @@ -0,0 +1,13 @@ +#include + +s32 pfstub_fsnext(FADta* data) { + PF_STUB_MESSAGE message; + + message.operation = 29; + message.object = data; + message.callback = NULL; + if (pfstub_com_massage(&message) == -1) { + return -1; + } + return message.result.status; +} diff --git a/libs/RVL_SDK/src/fa/pfs_fstat.c b/libs/RVL_SDK/src/fa/pfs_fstat.c new file mode 100644 index 00000000..95d25dc4 --- /dev/null +++ b/libs/RVL_SDK/src/fa/pfs_fstat.c @@ -0,0 +1,14 @@ +#include + +s32 pfstub_fstat(const char* path, FAFileStat* stat) { + PF_STUB_MESSAGE message; + + message.operation = 12; + message.object = path; + message.data = stat; + message.callback = NULL; + if (pfstub_com_massage(&message) == -1) { + return -1; + } + return message.result.status; +} diff --git a/libs/RVL_SDK/src/fa/pfs_fwrite.c b/libs/RVL_SDK/src/fa/pfs_fwrite.c new file mode 100644 index 00000000..558f1299 --- /dev/null +++ b/libs/RVL_SDK/src/fa/pfs_fwrite.c @@ -0,0 +1,16 @@ +#include + +u32 pfstub_fwrite(void* buffer, u32 size, u32 count, FAFILE* stream) { + PF_STUB_MESSAGE message; + + message.operation = 4; + message.object = buffer; + message.value = size; + message.count = count; + message.data = stream; + message.callback = NULL; + if (pfstub_com_massage(&message) == -1) { + return 0; + } + return message.result.count; +} diff --git a/libs/RVL_SDK/src/fa/pfs_getdev.c b/libs/RVL_SDK/src/fa/pfs_getdev.c new file mode 100644 index 00000000..89f06b8e --- /dev/null +++ b/libs/RVL_SDK/src/fa/pfs_getdev.c @@ -0,0 +1,14 @@ +#include + +s32 pfstub_devinf(s8 drive, FADevInf* info) { + PF_STUB_MESSAGE message; + + message.operation = 20; + message.drive = drive; + message.object = info; + message.callback = NULL; + if (pfstub_com_massage(&message) == -1) { + return -1; + } + return message.result.status; +} diff --git a/libs/RVL_SDK/src/fa/pfs_init_prfile2.c b/libs/RVL_SDK/src/fa/pfs_init_prfile2.c new file mode 100644 index 00000000..f25c0ae7 --- /dev/null +++ b/libs/RVL_SDK/src/fa/pfs_init_prfile2.c @@ -0,0 +1,7 @@ +#include + +extern s32 pf2_init_prfile2(s32 config, void* parameter); + +s32 pfstub_init_prfile2(s32 config, void* parameter) { + return pf2_init_prfile2(config, parameter); +} diff --git a/libs/RVL_SDK/src/fa/pfs_mount.c b/libs/RVL_SDK/src/fa/pfs_mount.c new file mode 100644 index 00000000..7f580463 --- /dev/null +++ b/libs/RVL_SDK/src/fa/pfs_mount.c @@ -0,0 +1,13 @@ +#include + +s32 pfstub_mount(s8 drive) { + PF_STUB_MESSAGE message; + + message.operation = 14; + message.drive = drive; + message.callback = NULL; + if (pfstub_com_massage(&message) == -1) { + return -1; + } + return message.result.status; +} diff --git a/libs/RVL_SDK/src/fa/pfs_remove.c b/libs/RVL_SDK/src/fa/pfs_remove.c new file mode 100644 index 00000000..8dfb335b --- /dev/null +++ b/libs/RVL_SDK/src/fa/pfs_remove.c @@ -0,0 +1,13 @@ +#include + +s32 pfstub_remove(const char* path) { + PF_STUB_MESSAGE message; + + message.operation = 7; + message.object = path; + message.callback = NULL; + if (pfstub_com_massage(&message) == -1) { + return -1; + } + return message.result.status; +} diff --git a/libs/RVL_SDK/src/fa/pfs_unmount.c b/libs/RVL_SDK/src/fa/pfs_unmount.c new file mode 100644 index 00000000..56a3097c --- /dev/null +++ b/libs/RVL_SDK/src/fa/pfs_unmount.c @@ -0,0 +1,14 @@ +#include + +s32 pfstub_unmount(s8 drive, u32 force) { + PF_STUB_MESSAGE message; + + message.operation = 39; + message.drive = drive; + message.value = force; + message.callback = NULL; + if (pfstub_com_massage(&message) == -1) { + return -1; + } + return message.result.status; +} diff --git a/tools/decomp-assist/fa_zero_batch.attempts.md b/tools/decomp-assist/fa_zero_batch.attempts.md new file mode 100644 index 00000000..83cbeddb --- /dev/null +++ b/tools/decomp-assist/fa_zero_batch.attempts.md @@ -0,0 +1,112 @@ +# Remaining FA attempts + +FAAttach: signed then unsigned drive index: 125/125 instructions, saved-register differences remain. Direct repeated drive indexing: 136/125. A separate drive temporary: 128/125. Restored signed index (99.36%). +pfd_get_media_drv_char: cursor enumeration baseline 69/70. Moving count/next-drive initialization after validation changed allocation. Indexed volume lookup and reversing declaration order changed allocation but retained 69/70. Incrementing index inside the loop retained 69/70; no artificial second increment added. +pfstub_entry: signed operation ranges 88/89. Unsigned ranges 85/89. Using received for the second range restored 88/89; compiler still reuses operation rather than reloading it. +uhf_msc_blk_pread/pwrite: ternary transfer count plus early error return: 123/129. Explicit halfword selection and an error-result loop changed branch scheduling. Success-first loop with explicit final break: 127/129. Sense switch and reversed cacheable branch raised fuzzy matching but leave error exits and allocation different. +FAInit: code exact; version pointer's extracted .sdata symbol includes four trailing zero bytes. A scalar version pointer matches the code. The extra zero word has no proven source meaning; no padding introduced. +pfd_st_inter_callback: baseline src 0x104 base 0x114 insns 65/69; 7 difference groups + truth tests in place of zero comparisons: src 0x104 base 0x114 insns 65/69; 7 difference groups + scope the final success result: src 0x104 base 0x114 insns 65/69; 7 difference groups +pfd_st_removal_callback: baseline src 0xf8 base 0x108 insns 62/66; 7 difference groups + truth tests in place of zero comparisons: src 0xf8 base 0x108 insns 62/66; 7 difference groups + scope the final success result: src 0xf8 base 0x108 insns 62/66; 7 difference groups +pfd_sddrv_init: baseline src 0x23c base 0x240 insns 143/144; 8 difference groups + reverse local declaration order: src 0x23c base 0x240 insns 143/144; 14 difference groups + truth tests in place of zero comparisons: src 0x23c base 0x240 insns 143/144; 8 difference groups + scope the final success result: src 0x23c base 0x240 insns 143/144; 8 difference groups +pfd_sddrv_unmount: baseline src 0x30 base 0x34 insns 12/13; 1 difference groups + truth tests in place of zero comparisons: src 0x30 base 0x34 insns 12/13; 1 difference groups + scope the final success result: src 0x30 base 0x34 insns 12/13; 1 difference groups +pfd_sddrv_finalize: baseline src 0xe4 base 0xe4 insns 57/57; diffs 43 + truth tests in place of zero comparisons: src 0xe4 base 0xe4 insns 57/57; diffs 43 + scope the final success result: src 0xe4 base 0xe4 insns 57/57; diffs 43 +pfd_sddrv_get_disk_info: baseline src 0x188 base 0x180 insns 98/96; 1 difference groups + reverse local declaration order: src 0x188 base 0x180 insns 98/96; 1 difference groups + truth tests in place of zero comparisons: src 0x188 base 0x180 insns 98/96; 1 difference groups + scope the final success result: src 0x188 base 0x180 insns 98/96; 1 difference groups +pfd_sddrv_physical_read: baseline src 0x1fc base 0x1fc insns 127/127; diffs 2 + reverse local declaration order: src 0x1fc base 0x1fc insns 127/127; diffs 12 + truth tests in place of zero comparisons: src 0x1fc base 0x1fc insns 127/127; diffs 2 + loop increment order or additive increment: src 0x1fc base 0x1fc insns 127/127; diffs 4 +pfd_sddrv_physical_write: baseline src 0x1fc base 0x1fc insns 127/127; diffs 2 + reverse local declaration order: src 0x1fc base 0x1fc insns 127/127; diffs 12 + truth tests in place of zero comparisons: src 0x1fc base 0x1fc insns 127/127; diffs 2 + loop increment order or additive increment: src 0x1fc base 0x1fc insns 127/127; diffs 4 +pfd_sddrv_get_total_sectors: baseline src 0x13c base 0x140 insns 79/80; 9 difference groups + reverse local declaration order: src 0x13c base 0x140 insns 79/80; 7 difference groups + truth tests in place of zero comparisons: src 0x13c base 0x140 insns 79/80; 9 difference groups + scope the final success result: src 0x13c base 0x140 insns 79/80; 9 difference groups +pfd_sddrv_calc_mbr_bpb: baseline src 0x3bc base 0x2b4 insns 239/173; 20 difference groups + reverse local declaration order: src 0x3bc base 0x2b4 insns 239/173; 18 difference groups + truth tests in place of zero comparisons: src 0x3bc base 0x2b4 insns 239/173; 20 difference groups + scope the final success result: src 0x3bc base 0x2b4 insns 239/173; 20 difference groups +pfd_sddrv_store_bpb_buf: baseline src 0x3d0 base 0x51c insns 244/327; 39 difference groups + reverse local declaration order: src 0x3d0 base 0x51c insns 244/327; 40 difference groups + truth tests in place of zero comparisons: src 0x3d0 base 0x51c insns 244/327; 39 difference groups + loop increment order or additive increment: src 0x3d0 base 0x51c insns 244/327; 39 difference groups +pfd_sddrv_store_mbr_buf: baseline src 0x26c base 0x328 insns 155/202; 19 difference groups + reverse local declaration order: src 0x26c base 0x328 insns 155/202; 19 difference groups + truth tests in place of zero comparisons: src 0x26c base 0x328 insns 155/202; 19 difference groups + loop increment order or additive increment: src 0x26c base 0x328 insns 155/202; 19 difference groups +pfd_sddrv_calc_fat32_mbr_bpb: baseline src 0x20c base 0x214 insns 131/133; 20 difference groups + reverse local declaration order: src 0x20c base 0x214 insns 131/133; 19 difference groups + truth tests in place of zero comparisons: src 0x20c base 0x214 insns 131/133; 20 difference groups + scope the final success result: src 0x20c base 0x214 insns 131/133; 20 difference groups +pfd_sddrv_store_fat32_mbr_buf: baseline src 0x2ec base 0x33c insns 187/207; 28 difference groups + reverse local declaration order: src 0x2ec base 0x33c insns 187/207; 25 difference groups + truth tests in place of zero comparisons: src 0x2ec base 0x33c insns 187/207; 28 difference groups + loop increment order or additive increment: src 0x2ec base 0x33c insns 187/207; 27 difference groups +pfd_sddrv_store_fat32_bpb_buf: baseline src 0x4a0 base 0x5c8 insns 296/370; 40 difference groups + reverse local declaration order: src 0x4a0 base 0x5c8 insns 296/370; 39 difference groups + truth tests in place of zero comparisons: src 0x4a0 base 0x5c8 insns 296/370; 40 difference groups + loop increment order or additive increment: src 0x4a0 base 0x5c8 insns 296/370; 40 difference groups +pfd_sddrv_build_fat32_mbr_bpb: baseline src 0x378 base 0x378 insns 222/222; diffs 211 + reverse local declaration order: src 0x378 base 0x378 insns 222/222; diffs 211 + truth tests in place of zero comparisons: src 0x378 base 0x378 insns 222/222; diffs 211 + scope the final success result: src 0x378 base 0x378 insns 222/222; diffs 211 +pfd_sddrv_full_format: baseline src 0x1d4 base 0x1d4 insns 117/117; diffs 7 + reverse local declaration order: src 0x1d4 base 0x1d4 insns 117/117; diffs 4 + truth tests in place of zero comparisons: src 0x1d4 base 0x1d4 insns 117/117; diffs 7 + loop increment order or additive increment: src 0x1d4 base 0x1d4 insns 117/117; diffs 7 + +pfd_st_inter_callback/pfd_st_removal_callback: integer handle tests and an explicit signed drive test remained 65/69 and 62/66; restored pointer tests. +pfd_sddrv_unmount/pfd_sddrv_finalize: explicit masked equality and inlined flag clearing produced 13/13 with seven register/test differences in unmount; restored the original. +pfd_sddrv_get_disk_info: common result return reduced 98/96 to 97/96 but changed return scheduling. Original extracted function excludes its final addi/bl r epilogue (two instructions follow .endfn). Restored the original; symbol sizes untouched. +pfd_sddrv_full_format: six permutations of scalar declarations with halfword and word output storage left 1-7 stack-offset differences. FADiskInfo geometry captures the actual total-sector/sector-size output layout and gives 117/117, diffs 0. +uhf_msc_blk_pread: separate error assignments in sense/non-sense exits and four local-order variants give 129/129 instructions; best has 17 register differences. +uhf_msc_blk_pwrite: explicit sense case 37 and independent cacheable/noncacheable updates give 129/129; four local-order variants leave 16 register differences. +pfd_sddrv_physical_read/pfd_sddrv_physical_write: initializing the running buffer before the aligned path and using it for direct transfers leaves the same two mr source-register differences. Restored the original. + +pf2_buffering/pf2_setupfsi: final batch check exposed missing argument narrowing. Changing only exported formal arguments to full-width integers restores the original signed drive and byte/halfword mode conversions: both 11/11, diffs 0. + +# Final full gate + +Units fully exact/touched: 109/115; instruction-exact functions: 9 -> 156; objdiff code bytes: 1632 -> 17376; data bytes: 408 -> 2344 + +``` +[libs/RVL_SDK/src/fa/driver/pfd_cmn] below 100: pfd_get_media_drv_char 96.34286 +[libs/RVL_SDK/src/fa/api/FAAttach] below 100: FAAttach 99.36 +[libs/RVL_SDK/src/fa/pf_stub] below 100: pfstub_entry 98.8764 +[libs/RVL_SDK/src/fa/msc/puh_msc_blk] below 100: uhf_msc_blk_pread 99.30232 +[libs/RVL_SDK/src/fa/msc/puh_msc_blk] below 100: uhf_msc_blk_pwrite 99.379845 +[libs/RVL_SDK/src/fa/driver/sd_drv] below 100: pfd_st_inter_callback 93.840576 +[libs/RVL_SDK/src/fa/driver/sd_drv] below 100: pfd_st_removal_callback 90.30303 +[libs/RVL_SDK/src/fa/driver/sd_drv] below 100: pfd_sddrv_init 86.104164 +[libs/RVL_SDK/src/fa/driver/sd_drv] below 100: pfd_sddrv_unmount 90.0 +[libs/RVL_SDK/src/fa/driver/sd_drv] below 100: pfd_sddrv_finalize 92.26316 +[libs/RVL_SDK/src/fa/driver/sd_drv] below 100: pfd_sddrv_get_disk_info 97.916664 +[libs/RVL_SDK/src/fa/driver/sd_drv] below 100: pfd_sddrv_physical_read 99.92126 +[libs/RVL_SDK/src/fa/driver/sd_drv] below 100: pfd_sddrv_physical_write 99.92126 +[libs/RVL_SDK/src/fa/driver/sd_drv] below 100: pfd_sddrv_get_total_sectors 90.9375 +[libs/RVL_SDK/src/fa/driver/sd_drv] below 100: pfd_sddrv_calc_mbr_bpb 20.606936 +[libs/RVL_SDK/src/fa/driver/sd_drv] below 100: pfd_sddrv_store_bpb_buf 37.93578 +[libs/RVL_SDK/src/fa/driver/sd_drv] below 100: pfd_sddrv_store_mbr_buf 42.173267 +[libs/RVL_SDK/src/fa/driver/sd_drv] below 100: pfd_sddrv_calc_fat32_mbr_bpb 85.57143 +[libs/RVL_SDK/src/fa/driver/sd_drv] below 100: pfd_sddrv_store_fat32_mbr_buf 49.444443 +[libs/RVL_SDK/src/fa/driver/sd_drv] below 100: pfd_sddrv_store_fat32_bpb_buf 50.24054 +[libs/RVL_SDK/src/fa/driver/sd_drv] below 100: pfd_sddrv_build_fat32_mbr_bpb 75.14865 +GATE PASS +``` + +Remaining differences: callback/unmount/finalize loads are reused rather than reloaded; init and geometry calculations have branch/integer scheduling differences; sector serialization has endian-store scheduling differences; physical read/write differ in two call argument source registers; build_fat32 retains allocation differences. FA mass-storage read/write have identical 129-instruction streams except register allocation. FAAttach has ten register differences. The disk-info extracted symbol omits its final two epilogue instructions; the version data includes an unexplained trailing zero word. -- 2.49.1