source: buchla-68k/orig/IOLIB/CLUSMAP.C@ 06ccda2

Last change on this file since 06ccda2 was 3ae31e9, checked in by Thomas Lopatic <thomas@…>, 8 years ago

Imported original source code.

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