Files
SpaghettiKart/src/os/osPfsChecker.c
T
coco875 a1f0d32d66 Update decomp clang (#67)
* Update menus.c (#634)

* Update common_data.yml (#635)

* Renames for screenId and other changes (#636)

* screenId renames

* Rename surface map to collision mesh (#637)

* Rename some stack vars (#638)

* Fix syntax error (#639)

* Rename some stack vars

* Update collision.c

* Collision Documentation (#640)

* Collision related renames

* update doxygen (#649)

* change bool (#644)

Co-authored-by: MegaMech <MegaMech@users.noreply.github.com>

* Update (#642)

* Delete trig_tables_bss.c (#650)

* fix typo audio (#656)

* fix typo src actor (#657)

Co-authored-by: MegaMech <MegaMech@users.noreply.github.com>

* fix typo include (#658)

* fix course (#659)

* fix typo debug (#660)

* fix typo data (#661)

* replace number with const (#665)

* fix typo buffers (#655)

* fix typo buffers

* tweak ld file

* rename to sMemoryPool

* add a warning

---------

* fix typo src (#654)

* fix typo src

* fix non matcing

* Update code_80091750.c

---------

* fix typo racing (#653)

* fix typo racing

* get it match

* replace G_LINE3D to G_QUAD

---------

* fix typo src (#652)

* fix ending typo (#651)

* Action more info when it doesn't match and fix first diff (#662)

* Update linux-compile.yml

* fix first-diff

* Update first-diff.py

---------

* document texture of kart (#663)

* document texture of kart

* change screenPlayerId to screenId

* some documentation around object

* Revert "some documentation around object"

This reverts commit cbb39078e036bf2a417bed67359e910213acab28.

* more rename

---------

* Make evaluate_collision_players_palm_tree better (#667)

This matches just the same as before,	but using those two casts instead of
shifts seems more likely to be accurate to the original source code

Signed-off-by: Gabriel Ravier <gabravier@gmail.com>

* add fedora instruciton (#666)

* start documenting animation (#668)

* start documenting animation

* Update course_data.c

* change comment

* update libultra asm (#648)

* update libultra asm

* fix gcc __osThreadTail

---------

* Document Vehicles (#641)

* start doc collision

* fix merge

* finish rename fonction related to vehicle

* document around waypoint of vehicle

* make some modification

* make some change and rename one

* copy_ to oldPos

* doc smoke ferry and train

* some rename

* fix some renaming

* precise index

* rename a funciton

* simplify waypoint_vehicles

* change some name

* change some name

* rename move_to_point_direction

* fix some conflict

* Update code_80005FD0.c

* Update code_80005FD0.h

---------

* Label a save info loop (#645)

* save info

* more gcc progress

* fix a value and do a rename (#669)

* update clang and add action (#664)

* update clang and add action

* try clang on course folder only

* forget two file

* Update course_displaylists.inc.c

* forget few other file

* Update course_vertices.inc.c

* format all code while get it match

* second pass

* format other dir

* disable clang format on bad ido code

* fix some tabulation

* revert format on tool dir

* Update clang-format.yml

* ignore gbi.h

* add some read me instruction

* fix error

* format and fixing error

* Update README.md

---------

* Update linkonly_generator.py (#670)

* format more file

* update

* fix compilation issue

* remove course_metadata folder

* re add course metadata folder

* fix banshee bordwalk crash

* fix windows eurk

* Update CMakeLists.txt

---------
2024-08-27 17:47:39 -06:00

198 lines
6.3 KiB
C

#include "libultra_internal.h"
#include "controller.h"
s32 corrupted_init(OSPfs* pfs, __OSInodeCache* cache);
s32 corrupted(OSPfs* pfs, __OSInodeUnit fpage, __OSInodeCache* cache);
s32 osPfsChecker(OSPfs* pfs) {
int j; // 1156
s32 ret; // 1152
__OSInodeUnit next_page;
__OSInode checked_inode;
__OSInode tmp_inode; // 636
__OSDir tmp_dir;
__OSInodeUnit file_next_node[16];
__OSInodeCache cache; // 56
int fixed; // 52
u8 bank; // 51
s32 cc; // 44
s32 cl; // 40
int offset; // 36
fixed = 0;
ret = __osCheckId(pfs);
if (ret == PFS_ERR_NEW_PACK) {
ret = __osGetId(pfs);
}
if (ret != 0) {
return ret;
}
ERRCK(corrupted_init(pfs, &cache));
for (j = 0; j < pfs->dir_size; j++) {
ERRCK(__osContRamRead(pfs->queue, pfs->channel, pfs->dir_table + j, (u8*) &tmp_dir));
if (tmp_dir.company_code != 0 && tmp_dir.game_code != 0) {
next_page = tmp_dir.start_page;
cc = 0;
cl = 0;
bank = 255;
while (next_page.ipage >= pfs->inode_start_page && next_page.inode_t.bank < pfs->banks &&
next_page.inode_t.page > 0 && next_page.inode_t.page < 128) {
if (bank != next_page.inode_t.bank) {
bank = next_page.inode_t.bank;
ret = __osPfsRWInode(pfs, &tmp_inode, OS_READ, bank);
if (ret != 0 && ret != PFS_ERR_INCONSISTENT) {
return ret;
}
}
cc = corrupted(pfs, next_page, &cache) - cl;
if (cc != 0) {
break;
}
cl = 1;
next_page = tmp_inode.inode_page[next_page.inode_t.page];
}
if (cc == 0 && next_page.ipage == 1) {
continue;
}
tmp_dir.company_code = 0;
tmp_dir.game_code = 0;
tmp_dir.start_page.ipage = 0;
tmp_dir.status = DIR_STATUS_EMPTY;
tmp_dir.data_sum = 0;
SET_ACTIVEBANK_TO_ZERO;
ERRCK(__osContRamWrite(pfs->queue, pfs->channel, pfs->dir_table + j, (u8*) &tmp_dir, false));
fixed++;
} else {
if (tmp_dir.company_code == 0 && tmp_dir.game_code == 0) {
continue;
}
tmp_dir.company_code = 0;
tmp_dir.game_code = 0;
tmp_dir.start_page.ipage = 0;
tmp_dir.status = DIR_STATUS_EMPTY;
tmp_dir.data_sum = 0;
SET_ACTIVEBANK_TO_ZERO;
ERRCK(__osContRamWrite(pfs->queue, pfs->channel, pfs->dir_table + j, (u8*) &tmp_dir, false));
fixed++;
}
}
for (j = 0; j < pfs->dir_size; j++) {
ERRCK(__osContRamRead(pfs->queue, pfs->channel, pfs->dir_table + j, (u8*) &tmp_dir));
if (tmp_dir.company_code != 0 && tmp_dir.game_code != 0 &&
tmp_dir.start_page.ipage >= ((__OSInodeUnit*) &(pfs->inode_start_page) + 1)->ipage) // weird
{
file_next_node[j].ipage = tmp_dir.start_page.ipage;
} else {
file_next_node[j].ipage = 0;
}
}
for (bank = 0; bank < pfs->banks; bank++) {
ret = __osPfsRWInode(pfs, &tmp_inode, 0, bank);
if (ret != 0 && ret != PFS_ERR_INCONSISTENT) {
return ret;
}
if (bank > 0) {
offset = 1;
} else {
offset = pfs->inode_start_page;
}
for (j = 0; j < offset; j++) {
checked_inode.inode_page[j].ipage = tmp_inode.inode_page[j].ipage;
}
for (; j < 128; j++) {
checked_inode.inode_page[j].ipage = 3;
}
for (j = 0; j < pfs->dir_size; j++) {
while (file_next_node[j].inode_t.bank == bank &&
file_next_node[j].ipage >= ((__OSInodeUnit*) &(pfs->inode_start_page) + 1)->ipage) {
u8 pp = file_next_node[j].inode_t.page;
file_next_node[j] = checked_inode.inode_page[pp] = tmp_inode.inode_page[pp];
}
}
ERRCK(__osPfsRWInode(pfs, &checked_inode, OS_WRITE, bank));
}
if (fixed) {
pfs->status |= PFS_CORRUPTED;
} else {
pfs->status &= ~PFS_CORRUPTED;
}
return 0;
}
s32 corrupted_init(OSPfs* pfs, __OSInodeCache* cache) {
int i;
int n;
int offset;
u8 bank;
__OSInodeUnit tpage;
__OSInode tmp_inode;
s32 ret;
for (i = 0; i < ARRLEN(cache->map); i++) {
cache->map[i] = 0;
}
cache->bank = -1;
for (bank = 0; bank < pfs->banks; bank++) {
if (bank > 0) {
offset = 1;
} else {
offset = pfs->inode_start_page;
}
ret = __osPfsRWInode(pfs, &tmp_inode, OS_READ, bank);
if (ret != 0 && ret != PFS_ERR_INCONSISTENT) {
return ret;
}
for (i = offset; i < ARRLEN(tmp_inode.inode_page); i++) {
tpage = tmp_inode.inode_page[i];
if (tpage.ipage >= pfs->inode_start_page && tpage.inode_t.bank != bank) {
n = (tpage.inode_t.page / 4) + ((tpage.inode_t.bank % PFS_ONE_PAGE) * BLOCKSIZE);
cache->map[n] |= 1 << (bank % PFS_ONE_PAGE);
}
}
}
return 0;
}
s32 corrupted(OSPfs* pfs, __OSInodeUnit fpage, __OSInodeCache* cache) {
int j;
int n;
int hit;
u8 bank;
int offset;
s32 ret;
hit = 0;
ret = 0;
n = (fpage.inode_t.page / 4) + (fpage.inode_t.bank % 8) * BLOCKSIZE;
for (bank = 0; bank < pfs->banks; bank++) {
if (bank > 0) {
offset = 1;
} else {
offset = pfs->inode_start_page;
}
if (bank == fpage.inode_t.bank || cache->map[n] & (1 << (bank % 8))) {
if (bank != cache->bank) {
ret = __osPfsRWInode(pfs, &cache->inode, 0, bank);
if (ret != 0 && ret != PFS_ERR_INCONSISTENT) {
return ret;
}
cache->bank = bank;
}
for (j = offset; hit < 2 && (j < ARRLEN(cache->inode.inode_page)); j++) {
if (cache->inode.inode_page[j].ipage == fpage.ipage) {
hit++;
}
}
if (1 < hit) {
return PFS_ERR_NEW_PACK;
}
}
}
return hit;
}