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