pfsfilestate.c
2.65 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/**************************************************************************
* *
* Copyright (C) 1995, Silicon Graphics, Inc. *
* *
* These coded instructions, statements, and computer programs contain *
* unpublished proprietary information of Silicon Graphics, Inc., and *
* are protected by Federal copyright law. They may not be disclosed *
* to third parties or copied or duplicated in any form, in whole or *
* in part, without the prior written consent of Silicon Graphics, Inc. *
* *
**************************************************************************/
#include "osint.h"
#include "controller.h"
s32
osPfsFileState(OSPfs *pfs, s32 file_no, OSPfsState *state)
{
s32 ret;
int pages;
__OSInode inode;
__OSDir dir;
__OSInodeUnit next_page;
u8 bank;
/*
* typedef struct {
* u32 file_size;
* u32 game_code;
* u16 company_code;
* char ext_name[4];
* char game_name[16];
* } OSPfsState;
*/
/* Check valid ID and parameters */
if ((file_no >= (s32)pfs->dir_size) || (file_no < 0))
return(PFS_ERR_INVALID);
if (!(pfs->status & PFS_INITIALIZED))
return(PFS_ERR_INVALID);
if ((ret=__osCheckId(pfs)) != 0){
return(ret);
}
/* get dir and inode structures */
#ifdef _PFS_1M_EXTENSION
if ((ret = __osPfsSelectIdBank(pfs)) != 0) return(ret);
#else
if (pfs->activebank != 0)
if ((ret = __osPfsSelectBank(pfs, 0)) != 0) return(ret);
#endif
if ((ret = __osContRamRead(pfs->queue, pfs->channel,
(u16)(pfs->dir_table + (int)file_no), (u8 *)&dir)) != 0)
return(ret);
if ((dir.company_code == 0) || (dir.game_code == 0))
return(PFS_ERR_INVALID);
/* get file status and calculate file size */
pages = 0;
next_page = dir.start_page;
bank = 255;
while(1) {
if (next_page.ipage < pfs->inode_start_page) {
break;
} else if (next_page.inode_t.bank != bank) {
bank = next_page.inode_t.bank;
if ((ret = __osPfsRWInode(pfs, &inode, PFS_READ, bank)) != 0)
return(ret);
}
pages++;
next_page = inode.inode_page[next_page.inode_t.page];
}
if (next_page.ipage != PFS_EOF)
return(PFS_ERR_INCONSISTENT);
state->file_size = (u32)(pages * PFS_PAGE_SIZE);
state->company_code = dir.company_code;
state->game_code = dir.game_code;
bcopy(dir.game_name, state->game_name, PFS_FILE_NAME_LEN);
bcopy(dir.ext_name, state->ext_name, PFS_FILE_EXT_LEN);
ret = __osPfsGetStatus(pfs->queue, pfs->channel);
return(ret);
}