-
Notifications
You must be signed in to change notification settings - Fork 2
/
access.c
293 lines (257 loc) · 6.51 KB
/
access.c
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
/* $Id: access.c 49096 2014-07-01 18:48:17Z twilen $ */
/* $Log: access.c $
* Revision 2.6 1999/09/11 16:45:50 Michiel
* Bug (1024 byte blok supprort) in AccessTest fixed
*
* Revision 2.5 1999/07/28 09:24:56 Michiel
* Unneeded anodeblock searches removed
*
* Revision 2.4 1999/05/07 16:49:00 Michiel
* bugfixes etc
*
* Revision 2.3 1999/05/07 09:31:31 Michiel
* bugfix
*
* Revision 2.2 1999/05/04 04:27:13 Michiel
* debugged upto buildrext
*
* Revision 2.1 1999/04/30 12:17:58 Michiel
* Accepts OK disks, bitmapfix and hardlink fix works
*
* Revision 1.2 1999/04/22 15:26:49 Michiel
* compiled
* */
#include <exec/ports.h>
#include <stdlib.h>
#include "pfs3.h"
#include "doctor.h"
#include <string.h>
/**************************************
* Non-checking functions for access to structures on PFS3 disks
**************************************/
/* get a buildblock from the buildblock cache
*/
cachedblock_t *GetBuildBlock(uint16 bloktype, uint32 seqnr)
{
struct buildblock *bbl;
for (bbl = HeadOf(&volume.buildblocks); bbl->next; bbl = bbl->next)
{
if (bbl->b.data->id == bloktype &&
bbl->b.data->indexblock.seqnr == seqnr)
{
return &bbl->b;
}
}
return NULL;
}
/* get reserved block
* anything, except deldir, root, boot, dir and rext
*/
error_t GetResBlock(cachedblock_t *blok, uint16 bloktype, uint32 seqnr, bool fix)
{
cachedblock_t blk, *t;
uint32 blknr, *bp = NULL, index, offset;
error_t error = e_none;
// controleer build block lijst
t = GetBuildBlock(bloktype, seqnr);
if (t)
{
blok->blocknr = t->blocknr;
blok->mode = t->mode;
*blok->data = *t->data;
return e_none;
}
blk.data = pfscalloc(1, SIZEOF_RESBLOCK);
index = seqnr/INDEX_PER_BLOCK;
offset = seqnr%INDEX_PER_BLOCK;
switch(bloktype)
{
case SBLKID:
if (seqnr > MAXSUPER)
{
pfsfree (blk.data);
return e_number_error;
}
bp = &rext.data->superindex[seqnr];
if (!*bp)
{
if (fix)
{
adderror("superindex block not found");
adderror("seq = %lu index = %lu offset = %lu %08lx", seqnr, index, offset, bloktype);
error = RepairSuperIndex(bp, seqnr);
if (error)
*bp = 0;
else
{
volume.writeblock((cachedblock_t *)&rext);
KillAnodeBitmap();
}
}
}
break;
case BMIBLKID:
bp = &rbl->idx.large.bitmapindex[seqnr];
if (!*bp)
{
if (fix)
{
adderror("bitmapindex block not found");
adderror("seq = %lu index = %lu offset = %lu %08lx", seqnr, index, offset, bloktype);
error = RepairBitmapIndex(bp, seqnr);
if (error)
*bp = 0;
else
c_WriteBlock((uint8 *)rbl, ROOTBLOCK + volume.firstblock, volume.blocksize);
}
}
break;
case IBLKID:
if (rbl->options & MODE_SUPERINDEX)
{
error = GetResBlock(&blk, SBLKID, index, fix);
if (error)
{
pfsfree (blk.data);
return error;
}
bp = &blk.data->indexblock.index[offset];
}
else
{
bp = &rbl->idx.small.indexblocks[seqnr];
}
if (!*bp)
{
if (fix)
{
adderror("anodeindex block not found");
adderror("seq = %lu index = %lu offset = %lu %08lx", seqnr, index, offset, bloktype);
error = RepairAnodeIndex(bp, seqnr);
if (error)
*bp = 0;
else
{
/* the anodebitmap, which is made per aib,
* could be too small
*/
KillAnodeBitmap();
if (rbl->options & MODE_SUPERINDEX)
volume.writeblock((cachedblock_t *)&blk);
else
c_WriteBlock((uint8 *)rbl, ROOTBLOCK + volume.firstblock, volume.blocksize);
}
}
}
break;
case ABLKID:
error = GetResBlock(&blk, IBLKID, index, fix);
if (error)
{
pfsfree (blk.data);
return error;
}
bp = &blk.data->indexblock.index[offset];
if (!*bp)
{
if (fix)
{
adderror("anode block not found");
adderror("seq = %lu index = %lu offset = %lu %08lx", seqnr, index, offset, bloktype);
// RepairAnodeBlock already called from RepairAnodeTree
// Pointless to call it again here.
//if (error = RepairAnodeBlock(bp, seqnr))
// *bp = 0;
//else
// volume.writeblock((cachedblock_t *)&blk);
}
}
break;
case BMBLKID:
error = GetResBlock(&blk, BMIBLKID, index, fix);
if (error)
{
pfsfree (blk.data);
return error;
}
bp = &blk.data->indexblock.index[offset];
if (!*bp)
{
if (fix)
{
adderror("bitmap block not found");
adderror("seq = %lu index = %lu offset = %lu %08lx", seqnr, index, offset, bloktype);
error = RepairBitmapBlock(bp, seqnr);
if (error)
*bp = 0;
else
volume.writeblock((cachedblock_t *)&blk);
}
}
break;
}
blknr = *bp;
pfsfree (blk.data);
if (!blknr)
return e_not_found;
error = volume.getblock(blok, blknr);
if (error)
return error;
return e_none;
}
static c_anodeblock_t tablk = { 0 };
static ULONG tanodedata[MAXRESBLOCKSIZE / 4];
static anodeblock_t *tanodeblk = (anodeblock_t*)tanodedata;
bool GetAnode(canode_t *anode, uint32 anodenr, bool fix)
{
anodenr_t *split = (anodenr_t *)&anodenr;
if (!(tablk.data && tanodeblk->seqnr == split->seqnr))
{
tablk.data = tanodeblk;
if (GetResBlock((cachedblock_t *)&tablk, ABLKID, split->seqnr, fix))
{
tablk.data = NULL;
return false;
}
}
if (split->offset > ANODES_PER_BLOCK)
return false;
anode->nr = anodenr;
anode->clustersize = tablk.data->nodes[split->offset].clustersize;
anode->blocknr = tablk.data->nodes[split->offset].blocknr;
anode->next = tablk.data->nodes[split->offset].next;
return true;
}
bool SaveAnode(canode_t *anode, uint32 nr)
{
anodenr_t *split = (anodenr_t *)&nr;
c_anodeblock_t ablk;
uint32 buffer[MAXRESBLOCKSIZE/4];
tablk.data = NULL; /* kill anode read cache */
ablk.data = (anodeblock_t *)buffer;
if (GetResBlock((cachedblock_t *)&ablk, ABLKID, split->seqnr, false))
return false;
if (split->offset > ANODES_PER_BLOCK)
return false;
ablk.data->nodes[split->offset].clustersize = anode->clustersize;
ablk.data->nodes[split->offset].blocknr = anode->blocknr;
ablk.data->nodes[split->offset].next = anode->next;
volume.writeblock((cachedblock_t *)&ablk);
return true;
}
ULONG GetDEFileSize(struct direntry *direntry, struct extrafields *extra, ULONG *high)
{
*high = 0;
if (rbl->options & MODE_LARGEFILE)
*high = extra->fsizex;
return direntry->fsize;
}
ULONG GetDDFileSize(struct deldirentry *dde, ULONG *high)
{
*high = 0;
if ((rbl->options & MODE_LARGEFILE) && dde->filename[0] <= DELENTRYFNSIZE) {
*high = dde->fsizex;
return dde->fsize;
}
return dde->fsize;
}