source: buchla-68k/libcio/clusmap.c@ b28a12e

Last change on this file since b28a12e was b28a12e, checked in by Thomas Lopatic <thomas@…>, 7 years ago

Zero redundant declarations.

  • Property mode set to 100644
File size: 7.1 KB
Line 
1/*
2 =============================================================================
3 clusmap.c -- various file structure utilities
4 Version 9 -- 1987-10-29 -- D.N. Lynx Crowe
5 =============================================================================
6*/
7
8#include "ram.h"
9
10static int8_t *mfname[] = { /* FCB flag names */
11
12 "?D0", /* D0 - 0001 */
13 "?D1", /* D1 - 0002 */
14 "?D2", /* D2 - 0004 */
15 "?D3", /* D3 - 0008 */
16
17 "BF ", /* D4 - 0010 */
18 "NB ", /* D5 - 0020 */
19 "TR ", /* D6 - 0040 */
20 "EX ", /* D7 - 0080 */
21
22 "RD ", /* D8 - 0100 */
23 "WR ", /* D9 - 0200 */
24 "AP ", /* D10 - 0400 */
25 "CR ", /* D11 - 0800 */
26
27 "OPN", /* D12 - 1000 */
28 "ERR", /* D13 - 2000 */
29 "BAD", /* D14 - 4000 */
30 "EOF" /* D15 - 8000 */
31};
32
33/*
34
35*/
36
37static int8_t *dfname[] = {
38
39 "RDONLY", /* D0 - 01 */
40 "HIDDEN", /* D1 - 02 */
41 "SYSTEM", /* D2 - 04 */
42 "VOLUME", /* D3 - 08 */
43 "SUBDIR", /* D4 - 10 */
44 "ARCHIV", /* D5 - 20 */
45 "??D6??", /* D6 - 40 */
46 "??D7??" /* D7 - 80 */
47};
48
49static int8_t *ffname[] = {
50
51 "BUSY ", /* D0 - 01 */
52 "ALLBUF", /* D1 - 02 */
53 "DIRTY ", /* D2 - 04 */
54 "EOF ", /* D3 - 08 */
55 "IOERR ", /* D4 - 10 */
56 "??D5??", /* D5 - 20 */
57 "??D6??", /* D6 - 40 */
58 "??D7??" /* D7 - 80 */
59};
60
61/*
62
63*/
64
65/*
66
67*/
68
69/*
70 =============================================================================
71 ClusMap(fcp) -- print a map of the clusters for the file associated with
72 the FCB pointed to by 'fcp'. Nothing is printed if the file isn't open.
73 Returns 0 if a map was printed, -1 otherwise.
74 =============================================================================
75*/
76
77int16_t ClusMap(struct fcb *fcp)
78{
79 int16_t clus, nc;
80 int32_t alsize, bused, bunused;
81
82 if (!(fcp->modefl & FC_OPN)) {
83
84 errno = EINVAL;
85 return(FAILURE);
86 }
87
88 nc = 0;
89 clus = micons(fcp->de.bclust);
90
91 if (clus) {
92
93 printf("Allocated cluster chain for [%-8.8s].[%-3.3s]:\n%6d",
94 fcp->de.fname, fcp->de.fext, clus);
95 nc = 1;
96
97 while (clus < 0xFF0) {
98
99 clus = _gtcl12(_thefat, clus);
100
101 if (clus < 0xFF0) {
102
103 nc++;
104
105 if (0 EQ (nc-1) % 10)
106 printf("\n");
107
108 printf("%6d", clus);
109 }
110 }
111 }
112
113 alsize = nc * _thebpb->clsizb;
114 bused = fcp->curlen;
115 bunused = alsize - bused;
116
117 printf("\nFAT cluster count=%d, asects=%ld\n", nc, fcp->asects);
118 printf("%ld bytes allocated, %ld bytes used", alsize, bused);
119
120 if (alsize GE bused)
121 printf(", %ld bytes unused", bunused);
122
123 printf("\n");
124
125 if (bused GT alsize)
126 printf("ERROR: directory file size exceeds FAT allocation\n");
127
128 if (fcp->asects NE nc)
129 printf("ERROR: FAT cluster count (%d) NE FCB cluster count (%ld)\n",
130 nc, fcp->asects);
131 return(SUCCESS);
132}
133
134/*
135
136*/
137
138/*
139 =============================================================================
140 FCBmode(fcp) -- print FCB mode flags
141 =============================================================================
142*/
143
144struct fcb *FCBmode(struct fcb *fcp)
145{
146 register uint16_t mf;
147 register int16_t i;
148
149 printf(" flags: ");
150 mf = 0x0001;
151
152 for (i = 0; i < 16; i++) {
153
154 if (fcp->modefl & mf)
155 printf("%s ", mfname[i]);
156
157 mf <<= 1;
158 }
159
160 printf("\n atrib: ");
161
162 mf = 0x01;
163
164 for (i = 0; i < 8; i++) {
165
166 if (fcp->de.atrib & mf)
167 printf("%s ", dfname[i]);
168
169 mf <<= 1;
170 }
171
172 printf("\n");
173 return(fcp);
174}
175
176
177/*
178
179*/
180
181/*
182 =============================================================================
183 SnapFCB(fcp) -- print contents of an FCB pointed to by 'fcp'
184 =============================================================================
185*/
186
187struct fcb *SnapFCB(struct fcb *fcp)
188{
189 printf("\nFCB at 0x%08lx: [%-8.8s].[%-3.3s]\n",
190 fcp, fcp->de.fname, fcp->de.fext);
191 FCBmode(fcp);
192
193 printf(" atrib 0x%04x", fcp->de.atrib);
194 printf(" modefl 0x%04x\n", fcp->modefl);
195
196 printf(" crtime 0x%04x", micons(fcp->de.crtime));
197 printf(" crdate 0x%04x\n", micons(fcp->de.crdate));
198
199 printf(" asects %8ld", fcp->asects);
200 printf(" flen %8ld", miconl(fcp->de.flen));
201 printf(" curlen %8ld\n", fcp->curlen);
202
203 printf(" bclust %8d", micons(fcp->de.bclust));
204 printf(" curcls %8d", fcp->curcls);
205 printf(" clsec %8d\n", fcp->clsec);
206
207 printf(" curlsn %8ld", fcp->curlsn);
208 printf(" curdsn %8ld", fcp->curdsn);
209 printf(" offset %8d\n", fcp->offset);
210
211 printf("\n");
212 return(fcp);
213}
214
215/*
216
217*/
218
219/*
220 =============================================================================
221 MapFAT() -- print the first 'ncl' cluster entries from 'fat'
222 =============================================================================
223*/
224
225void MapFAT(int8_t *fat, int16_t ncl, int16_t stops)
226{
227 register int16_t i;
228
229 printf("\nCluster dump of FAT at 0x%08.8lx (%d entries):\n",
230 fat, ncl);
231 printf(" 0: .... .... ");
232
233 for (i = 2; i < ncl; i++) {
234
235 if ((i % 10) EQ 0)
236 printf("\n%4.4d: ", i);
237
238 printf("%4.4d ", _gtcl12(fat, i));
239
240 /* stop every 10 lines if requested */
241
242 if (stops AND (((i / 10) % 10) EQ 0))
243 waitcr();
244 }
245
246 printf("\n");
247}
248
249/*
250
251*/
252
253/*
254 =============================================================================
255 FILEfl() -- print FILE flags
256 =============================================================================
257*/
258
259FILE *FILEfl(FILE *fp)
260{
261 register uint16_t mf;
262 register int16_t i;
263
264 printf(" _flags: ");
265 mf = 0x0001;
266
267 for (i = 0; i < 8; i++) {
268
269 if (fp->_flags & mf)
270 printf("%s ", ffname[i]);
271
272 mf <<= 1;
273 }
274
275 printf("\n");
276 return(fp);
277}
278
279/*
280
281*/
282
283/*
284 =============================================================================
285 FILEpr(fp) -- print contents of a FILE structure pointed to by 'fp'
286 =============================================================================
287*/
288
289void FILEpr(FILE *fp)
290{
291 int16_t (*arg)(), ft;
292 int8_t *ds, *fsn, *fse;
293 struct fcb *fcp;
294
295 if (fp EQ (FILE *)0L) {
296
297 printf("FILEpr(): ERROR - argument was NULL\n");
298 return;
299 }
300
301
302 printf("\nFILE at $%08.8lX", fp);
303
304 arg = chantab[fp->_unit].c_close;
305 ft = 0;
306
307 if (arg EQ _noper) {
308
309 ds = ((struct devtabl *)chantab[fp->_unit].c_arg)->d_name;
310 printf(" is a device: [%s]\n", ds);
311
312 } else if (arg EQ _filecl) {
313
314 ft = 1;
315 fcp = (struct fcb *)chantab[fp->_unit].c_arg;
316 fsn = fcp->de.fname;
317 fse = fcp->de.fext;
318 printf(" is a disk file: [%8.8s].[%3.3s], fcb at $%08.8lX\n",
319 fsn, fse, fcp);
320
321 } else {
322
323 printf(" is of UNKNOWN type: c_close=$%08.8lX, c_arg=$%08.8lX\n",
324 arg, chantab[fp->_unit].c_arg);
325 }
326
327 printf(" _buff=$%08.8lX, _bp=$%08.8lX, _bend=$%08.8lX, _buflen=%u\n",
328 fp->_buff, fp->_bp, fp->_bend, fp->_buflen);
329 printf(" _flags=$%04.4X, _unit=%d, _bytbuf=$%02.2X\n",
330 fp->_flags, fp->_unit, fp->_bytbuf);
331
332 FILEfl(fp);
333
334 if (ft)
335 SnapFCB(fcp);
336 else
337 printf("\n");
338}
339
340/*
341
342*/
343
344/*
345 =============================================================================
346 fd2fcb() -- convert a unit number to a pointer to a fcb
347 =============================================================================
348*/
349
350struct fcb *fd2fcb(int16_t fd)
351{
352 if ((fd < 0) OR (fd > MAXCHAN))
353 return((struct fcb *)NULL);
354
355 return(chantab[fd].c_arg);
356}
357
358/*
359 =============================================================================
360 fp2fcb() -- convert a FILE pointer to a pointer to a fcb
361 =============================================================================
362*/
363
364struct fcb *fp2fcb(FILE *fp)
365{
366 if (fp EQ (FILE *)NULL)
367 return((struct fcb *)NULL);
368
369 return(chantab[fp->_unit].c_arg);
370}
371
Note: See TracBrowser for help on using the repository browser.