From d760968fda82e92c67034eb2f81a6480d66fca8e Mon Sep 17 00:00:00 2001 From: Ryan Myers Date: Mon, 27 Sep 2021 10:23:30 -0400 Subject: [PATCH] Matched osPfsReFormat and osPfsNumFiles --- .../{unknown_0D0130.c => os/osPfsChecker.c} | 3 +- lib/src/os/osPfsNumFiles.c | 24 +++++++ lib/src/os/osPfsReFormat.c | 66 +++++++++++++++++++ 3 files changed, 91 insertions(+), 2 deletions(-) rename lib/src/{unknown_0D0130.c => os/osPfsChecker.c} (71%) create mode 100644 lib/src/os/osPfsNumFiles.c create mode 100644 lib/src/os/osPfsReFormat.c diff --git a/lib/src/unknown_0D0130.c b/lib/src/os/osPfsChecker.c similarity index 71% rename from lib/src/unknown_0D0130.c rename to lib/src/os/osPfsChecker.c index f7d628c8..11893056 100644 --- a/lib/src/unknown_0D0130.c +++ b/lib/src/os/osPfsChecker.c @@ -7,5 +7,4 @@ GLOBAL_ASM("lib/asm/non_matchings/unknown_0D0130/osPfsChecker.s") GLOBAL_ASM("lib/asm/non_matchings/unknown_0D0130/corrupted_init.s") GLOBAL_ASM("lib/asm/non_matchings/unknown_0D0130/corrupted.s") -GLOBAL_ASM("lib/asm/non_matchings/unknown_0D0130/osPfsReFormat.s") -GLOBAL_ASM("lib/asm/non_matchings/unknown_0D0130/osPfsNumFiles.s") + diff --git a/lib/src/os/osPfsNumFiles.c b/lib/src/os/osPfsNumFiles.c new file mode 100644 index 00000000..9877c381 --- /dev/null +++ b/lib/src/os/osPfsNumFiles.c @@ -0,0 +1,24 @@ +/* The comment below is needed for this file to be picked up by generate_ld */ +/* RAM_POS: 0x800D0390 */ + +#include "libultra_internal.h" +#include "controller.h" + +s32 osPfsNumFiles(OSPfs *pfs, s32 *max_files, s32 *files_used) { + int j; + s32 ret; + __OSDir dir; + int files; + files = 0; + PFS_CHECK_STATUS; + PFS_CHECK_ID; + SET_ACTIVEBANK_TO_ZERO; + for (j = 0; j < pfs->dir_size; j++) { + ERRCK(__osContRamRead(pfs->queue, pfs->channel, pfs->dir_table + j, (u8*)&dir)); + if (dir.company_code != 0 && dir.game_code != 0) + files++; + } + *files_used = files; + *max_files = pfs->dir_size; + return 0; +} diff --git a/lib/src/os/osPfsReFormat.c b/lib/src/os/osPfsReFormat.c new file mode 100644 index 00000000..25d65bf8 --- /dev/null +++ b/lib/src/os/osPfsReFormat.c @@ -0,0 +1,66 @@ +/* The comment below is needed for this file to be picked up by generate_ld */ +/* RAM_POS: 0x800CFF90 */ + +#include "libultra_internal.h" +#include "controller.h" +#include "siint.h" + +s32 osPfsReFormat(OSPfs *pfs, OSMesgQueue *queue, int channel) { + int j; + int i; + __OSInode inode; + u8 tmp_data[32]; + u8 *ptr; + s32 ret; + + __osSiGetAccess(); + ret = __osPfsGetStatus(queue, channel); + + if (ret != 0) { + //Single difference between this and libreultra + //__osSiRelAccess(); + return ret; + } + + pfs->status ^= PFS_INITIALIZED; + pfs->queue = queue; + pfs->channel = channel; + __osSiRelAccess(); + ERRCK(__osGetId(pfs)); + + SET_ACTIVEBANK_TO_ZERO; + for (j = 0; j < ARRLEN(tmp_data); j++) + tmp_data[j] = 0; + + for (j = 0; j < pfs->dir_size; j++) { + ERRCK(__osContRamWrite(queue, channel, pfs->dir_table + j, tmp_data, FALSE)); + } + + for (j = 0; j < pfs->inodeStartPage; j++) + inode.inodePage[j].ipage = 0; + + for (j = pfs->inodeStartPage; j < ARRLEN(inode.inodePage); j++) + inode.inodePage[j].ipage = 3; + + inode.inodePage[0].ipage = __osSumcalc((u8*)&inode.inodePage[pfs->inodeStartPage], + sizeof(__OSInodeUnit) * -pfs->inodeStartPage + sizeof(inode.inodePage)); + ptr = (u8 *)&inode; + + for (j = 0; j < PFS_ONE_PAGE; j++){ + ERRCK(__osContRamWrite(queue, channel, pfs->inode_table + j, ptr + j * BLOCKSIZE, FALSE)); + ERRCK(__osContRamWrite(queue, channel, pfs->minode_table + j, ptr + j * BLOCKSIZE, FALSE)); + } + + for (i = 1; i < pfs->banks; i++) { + for (j = 1; j < ARRLEN(inode.inodePage); j++) + inode.inodePage[j].ipage = 3; + inode.inodePage[0].ipage = __osSumcalc((u8*)&inode.inodePage[1], -sizeof(__OSInodeUnit) + sizeof(inode.inodePage)); + ptr = (u8 *)&inode; + for (j = 0; j < PFS_ONE_PAGE; j++) { + ERRCK(__osContRamWrite(queue, channel, pfs->inode_table + i * PFS_ONE_PAGE + j, ptr + j * BLOCKSIZE, FALSE)); + ERRCK(__osContRamWrite(queue, channel, pfs->minode_table + i * PFS_ONE_PAGE + j, ptr + j * BLOCKSIZE, FALSE)); + } + } + + return 0; +}