pfsreformat.c
3.32 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
/**************************************************************************
* *
* 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"
#include "siint.h"
/*
* This function reformat the whole file system except pack id
* which is assigned by Nintendo.
*/
s32
osPfsReFormat(OSPfs *pfs, OSMesgQueue *queue, int channel)
{
int j, i;
__OSInode inode;
u8 tmp_data[BLOCKSIZE];
u8 *ptr;
s32 ret;
/* Block to get resource token */
__osSiGetAccess();
if ((ret = __osPfsGetStatus(queue, channel)) != 0) {
__osSiRelAccess();
return(ret);
}
pfs->status ^= PFS_INITIALIZED;
pfs->queue = queue;
pfs->channel = channel;
/* Check vaild id */
__osSiRelAccess();
if ((ret = __osGetId(pfs)) != 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
/* make dir */
for(j = 0; j < BLOCKSIZE ; j++)
tmp_data[j] = 0;
for(j = 0; j < pfs->dir_size ; j++) {
ret = __osContRamWrite(queue, channel, (u16)(pfs->dir_table+j),
tmp_data, 0);
if (ret != 0)
return(ret);
}
/* make inode table for bank 0 */
for(j = 0 ; j < pfs->inode_start_page ; j++)
inode.inode_page[j].ipage = 0;
for(j = pfs->inode_start_page ; j < PFS_INODE_SIZE_PER_PAGE; j++)
inode.inode_page[j].ipage = PFS_PAGE_NOT_USED;
inode.inode_page[0].ipage = (u16)__osSumcalc((u8 *)(inode.inode_page +
pfs->inode_start_page),(PFS_INODE_SIZE_PER_PAGE -pfs->inode_start_page)*2 );
ptr = (u8 *)(&inode);
for(j = 0; j < PFS_ONE_PAGE ; j++) {
ret =__osContRamWrite(queue, channel,
(u16)(pfs->inode_table+j), (u8 *)(ptr + (j * BLOCKSIZE)), 0);
if (ret != 0)
return(ret);
ret =__osContRamWrite(queue, channel,
(u16)(pfs->minode_table+j), (u8 *)(ptr + (j * BLOCKSIZE)), 0);
if (ret != 0)
return(ret);
}
/* make inode table for bank 1 to bank n */
for (i = 1; i < pfs->banks; i++) {
for(j = 1 ; j < PFS_INODE_SIZE_PER_PAGE; j++)
inode.inode_page[j].ipage = PFS_PAGE_NOT_USED;
inode.inode_page[0].ipage =
(u16)__osSumcalc((u8 *)(inode.inode_page + 1),
(PFS_INODE_SIZE_PER_PAGE - 1) * 2);
ptr = (u8 *)(&inode);
for(j = 0; j < PFS_ONE_PAGE ; j++) {
ret =__osContRamWrite(queue, channel,
(u16)(pfs->inode_table + (i * PFS_ONE_PAGE) +j),
(u8 *)(ptr + (j * BLOCKSIZE)), 0);
if (ret != 0)
return(ret);
ret =__osContRamWrite(queue, channel,
(u16)(pfs->minode_table + (i * PFS_ONE_PAGE) +j),
(u8 *)(ptr + (j * BLOCKSIZE)), 0);
if (ret != 0)
return(ret);
}
}
return(0);
}