pfsdeletefile.c
3.45 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/**************************************************************************
* *
* 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
osPfsDeleteFile(OSPfs *pfs, u16 company_code, u32 game_code,
u8 *game_name, u8 *ext_name)
{
s32 file_no;
s32 ret;
__OSInode inode ;
__OSDir dir;
__OSInodeUnit last_page;
u8 startpage;
u8 bank;
if ((company_code == 0) || (game_code == 0))
return(PFS_ERR_INVALID);
if ((ret = osPfsFindFile(pfs, company_code, game_code,
game_name, ext_name, &file_no))!= 0)
return(ret);
#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
/* get dir structure */
if ((ret = __osContRamRead(pfs->queue, pfs->channel,
(u16)(pfs->dir_table + (int)file_no), (u8 *)&dir)) != 0)
return(ret);
/* release pages */
/* loop through all the banks */
startpage = dir.start_page.inode_t.page;
for (bank = dir.start_page.inode_t.bank ; bank < pfs->banks; ) {
if ((ret = __osPfsRWInode(pfs, &inode, PFS_READ, bank)) != 0)
return(ret);
if ((ret = __osPfsReleasePages(pfs, &inode, startpage,
bank, &last_page )) != 0)
return(ret);
if ((ret = __osPfsRWInode(pfs, &inode, PFS_WRITE, bank)) != 0)
return(ret);
if (last_page.ipage == PFS_EOF)
break;
bank = last_page.inode_t.bank;
startpage = last_page.inode_t.page;
}
if (bank >= pfs->banks)
return(PFS_ERR_INCONSISTENT);
/* update dir */
bzero(&dir, sizeof(__OSDir));
ret = __osContRamWrite(pfs->queue, pfs->channel,
(u16)(pfs->dir_table + (int)file_no), (u8 *)&dir, 0);
return(ret);
}
s32
__osPfsReleasePages(OSPfs *pfs, __OSInode *inode, u8 start_page, u8 bank,
__OSInodeUnit *last_page)
{
__OSInodeUnit next_page, old_page;
s32 ret = 0;
next_page.ipage = (u16)((bank<<8) + start_page);
do {
old_page = next_page;
next_page = inode->inode_page[next_page.inode_t.page];
inode->inode_page[old_page.inode_t.page].ipage = PFS_PAGE_NOT_USED;
} while (next_page.ipage >= pfs->inode_start_page &&
next_page.inode_t.bank == bank);
*last_page = next_page;
return(ret);
}
#if 0
s32
__osBlockSum(OSPfs *pfs, u8 page_no, u16 *sum, u8 bank)
{
int i;
s32 ret = 0;
u8 data[BLOCKSIZE];
if ((ret = __osPfsSelectBank(pfs, bank)) != 0)
return(ret);
for (i = 0; i < PFS_ONE_PAGE; i++) {
ret = __osContRamRead(pfs->queue, pfs->channel,
(u16)(page_no * PFS_ONE_PAGE + i), (u8 *)&data);
if (ret != 0) {
break;
}
*sum = (u16)(*sum + __osSumcalc((u8 *)&data, BLOCKSIZE));
}
#ifdef _PFS_1M_EXTENSION
ret = __osPfsSelectIdBank(pfs);
#else
if (pfs->activebank != 0)
ret = __osPfsSelectBank(pfs, 0);
#endif
return(ret);
}
#endif