blob: 2bbba963b6b8d2812b5916dd065b458b0863a529 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
#include "libultra_internal.h"
#include "controller.h"
s32 osPfsFileState(OSPfs* pfs, s32 file_no, OSPfsState* state) {
s32 ret;
int pages;
__OSInode inode;
__OSDir dir;
__OSInodeUnit next_page;
int j;
u8 bank;
u8 start_page;
if (file_no >= pfs->dir_size || file_no < 0) {
return PFS_ERR_INVALID;
}
PFS_CHECK_STATUS;
PFS_CHECK_ID;
SET_ACTIVEBANK_TO_ZERO;
ERRCK(__osContRamRead(pfs->queue, pfs->channel, pfs->dir_table + file_no, (u8*) &dir));
if (dir.company_code == 0 || dir.game_code == 0) {
return PFS_ERR_INVALID;
}
if (dir.start_page.ipage < pfs->inode_start_page) {
return PFS_ERR_INCONSISTENT;
}
pages = 0;
start_page = dir.start_page.inode_t.page;
bank = dir.start_page.inode_t.bank;
while (bank < pfs->banks) {
ERRCK(__osPfsRWInode(pfs, &inode, OS_READ, bank));
next_page = inode.inode_page[start_page];
pages++;
while (next_page.ipage >= pfs->inode_start_page) {
pages++;
next_page = inode.inode_page[next_page.inode_t.page];
if (next_page.inode_t.bank != bank) {
bank = next_page.inode_t.bank;
start_page = next_page.inode_t.page;
break;
}
}
if (next_page.ipage == 1) {
break;
}
}
if (next_page.ipage != 1) {
return PFS_ERR_INCONSISTENT;
}
state->file_size = pages << PFS_ONE_PAGE;
state->company_code = dir.company_code;
state->game_code = dir.game_code;
for (j = 0; j < ARRLEN(state->game_name); j++) {
state->game_name[j] = dir.game_name[j];
}
for (j = 0; j < ARRLEN(state->ext_name); j++) {
state->ext_name[j] = dir.ext_name[j];
}
return 0;
}
|