mirror of https://github.com/zeldaret/mm.git
pfsfreeblocks OK (#423)
* pfsfreeblocks OK * Update src/libultra/io/pfsfreeblocks.c Co-authored-by: Tharo <17233964+Thar0@users.noreply.github.com> Co-authored-by: Tharo <17233964+Thar0@users.noreply.github.com>
This commit is contained in:
parent
2664f75ac2
commit
8ebdb50470
|
|
@ -1,3 +1,37 @@
|
|||
#include "global.h"
|
||||
#include "PR/pfs.h"
|
||||
|
||||
#pragma GLOBAL_ASM("asm/non_matchings/boot/pfsfreeblocks/osPfsFreeBlocks.s")
|
||||
s32 osPfsFreeBlocks(OSPfs* pfs, s32* leftoverBytes) {
|
||||
s32 j;
|
||||
s32 pages = 0;
|
||||
__OSInode inode;
|
||||
s32 ret = 0;
|
||||
u8 bank;
|
||||
s32 offset;
|
||||
|
||||
if (!(pfs->status & PFS_INITIALIZED)) {
|
||||
return PFS_ERR_INVALID;
|
||||
}
|
||||
|
||||
ret = __osCheckId(pfs);
|
||||
if (ret != 0) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
for (bank = PFS_ID_BANK_256K; bank < pfs->banks; bank++) {
|
||||
ret = __osPfsRWInode(pfs, &inode, PFS_READ, bank);
|
||||
if (ret != 0) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
offset = ((bank > PFS_ID_BANK_256K) ? 1 : pfs->inodeStartPage);
|
||||
for (j = offset; j < PFS_INODE_SIZE_PER_PAGE; j++) {
|
||||
if (inode.inodePage[j].ipage == PFS_PAGE_NOT_USED) {
|
||||
pages++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
*leftoverBytes = pages * PFS_ONE_PAGE * BLOCKSIZE;
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue