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

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

Use standard integer types.

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