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 short micons(short wi);
|
---|
15 | extern unsigned _gtcl12(char *fat, unsigned cl);
|
---|
16 | extern long miconl(long wi);
|
---|
17 |
|
---|
18 | extern struct bpb *_thebpb;
|
---|
19 | extern unsigned _thefat[];
|
---|
20 |
|
---|
21 | extern int _filecl(struct fcb *fp);
|
---|
22 | extern int _noper(void);
|
---|
23 |
|
---|
24 | /* |
---|
25 |
|
---|
26 | */
|
---|
27 |
|
---|
28 | static char *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 |
|
---|
55 | static char *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 |
|
---|
67 | static char *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 |
|
---|
83 | static int waitcr(void)
|
---|
84 | {
|
---|
85 | char 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 |
|
---|
94 | /* |
---|
95 |
|
---|
96 | */
|
---|
97 |
|
---|
98 | /*
|
---|
99 | =============================================================================
|
---|
100 | ClusMap(fcp) -- print a map of the clusters for the file associated with
|
---|
101 | the FCB pointed to by 'fcp'. Nothing is printed if the file isn't open.
|
---|
102 | Returns 0 if a map was printed, -1 otherwise.
|
---|
103 | =============================================================================
|
---|
104 | */
|
---|
105 |
|
---|
106 | int ClusMap(struct fcb *fcp)
|
---|
107 | {
|
---|
108 | int clus, nc;
|
---|
109 | long alsize, bused, bunused;
|
---|
110 |
|
---|
111 | if (!(fcp->modefl & FC_OPN)) {
|
---|
112 |
|
---|
113 | errno = EINVAL;
|
---|
114 | return(FAILURE);
|
---|
115 | }
|
---|
116 |
|
---|
117 | nc = 0;
|
---|
118 | clus = micons(fcp->de.bclust);
|
---|
119 |
|
---|
120 | if (clus) {
|
---|
121 |
|
---|
122 | printf("Allocated cluster chain for [%-8.8s].[%-3.3s]:\n%6d",
|
---|
123 | fcp->de.fname, fcp->de.fext, clus);
|
---|
124 | nc = 1;
|
---|
125 |
|
---|
126 | while (clus < 0xFF0) {
|
---|
127 |
|
---|
128 | clus = _gtcl12(_thefat, clus);
|
---|
129 |
|
---|
130 | if (clus < 0xFF0) {
|
---|
131 |
|
---|
132 | nc++;
|
---|
133 |
|
---|
134 | if (0 EQ (nc-1) % 10)
|
---|
135 | printf("\n");
|
---|
136 |
|
---|
137 | printf("%6d", clus);
|
---|
138 | }
|
---|
139 | }
|
---|
140 | }
|
---|
141 |
|
---|
142 | alsize = nc * _thebpb->clsizb;
|
---|
143 | bused = fcp->curlen;
|
---|
144 | bunused = alsize - bused;
|
---|
145 |
|
---|
146 | printf("\nFAT cluster count=%d, asects=%ld\n", nc, fcp->asects);
|
---|
147 | printf("%ld bytes allocated, %ld bytes used", alsize, bused);
|
---|
148 |
|
---|
149 | if (alsize GE bused)
|
---|
150 | printf(", %ld bytes unused", bunused);
|
---|
151 |
|
---|
152 | printf("\n");
|
---|
153 |
|
---|
154 | if (bused GT alsize)
|
---|
155 | printf("ERROR: directory file size exceeds FAT allocation\n");
|
---|
156 |
|
---|
157 | if (fcp->asects NE nc)
|
---|
158 | printf("ERROR: FAT cluster count (%d) NE FCB cluster count (%ld)\n",
|
---|
159 | nc, fcp->asects);
|
---|
160 | return(SUCCESS);
|
---|
161 | }
|
---|
162 |
|
---|
163 | /* |
---|
164 |
|
---|
165 | */
|
---|
166 |
|
---|
167 | /*
|
---|
168 | =============================================================================
|
---|
169 | FCBmode(fcp) -- print FCB mode flags
|
---|
170 | =============================================================================
|
---|
171 | */
|
---|
172 |
|
---|
173 | struct fcb *FCBmode(struct fcb *fcp)
|
---|
174 | {
|
---|
175 | register unsigned short mf;
|
---|
176 | register short i;
|
---|
177 |
|
---|
178 | printf(" flags: ");
|
---|
179 | mf = 0x0001;
|
---|
180 |
|
---|
181 | for (i = 0; i < 16; i++) {
|
---|
182 |
|
---|
183 | if (fcp->modefl & mf)
|
---|
184 | printf("%s ", mfname[i]);
|
---|
185 |
|
---|
186 | mf <<= 1;
|
---|
187 | }
|
---|
188 |
|
---|
189 | printf("\n atrib: ");
|
---|
190 |
|
---|
191 | mf = 0x01;
|
---|
192 |
|
---|
193 | for (i = 0; i < 8; i++) {
|
---|
194 |
|
---|
195 | if (fcp->de.atrib & mf)
|
---|
196 | printf("%s ", dfname[i]);
|
---|
197 |
|
---|
198 | mf <<= 1;
|
---|
199 | }
|
---|
200 |
|
---|
201 | printf("\n");
|
---|
202 | return(fcp);
|
---|
203 | }
|
---|
204 |
|
---|
205 |
|
---|
206 | /* |
---|
207 |
|
---|
208 | */
|
---|
209 |
|
---|
210 | /*
|
---|
211 | =============================================================================
|
---|
212 | SnapFCB(fcp) -- print contents of an FCB pointed to by 'fcp'
|
---|
213 | =============================================================================
|
---|
214 | */
|
---|
215 |
|
---|
216 | struct fcb *SnapFCB(struct fcb *fcp)
|
---|
217 | {
|
---|
218 | printf("\nFCB at 0x%08lx: [%-8.8s].[%-3.3s]\n",
|
---|
219 | fcp, fcp->de.fname, fcp->de.fext);
|
---|
220 | FCBmode(fcp);
|
---|
221 |
|
---|
222 | printf(" atrib 0x%04x", fcp->de.atrib);
|
---|
223 | printf(" modefl 0x%04x\n", fcp->modefl);
|
---|
224 |
|
---|
225 | printf(" crtime 0x%04x", micons(fcp->de.crtime));
|
---|
226 | printf(" crdate 0x%04x\n", micons(fcp->de.crdate));
|
---|
227 |
|
---|
228 | printf(" asects %8ld", fcp->asects);
|
---|
229 | printf(" flen %8ld", miconl(fcp->de.flen));
|
---|
230 | printf(" curlen %8ld\n", fcp->curlen);
|
---|
231 |
|
---|
232 | printf(" bclust %8d", micons(fcp->de.bclust));
|
---|
233 | printf(" curcls %8d", fcp->curcls);
|
---|
234 | printf(" clsec %8d\n", fcp->clsec);
|
---|
235 |
|
---|
236 | printf(" curlsn %8ld", fcp->curlsn);
|
---|
237 | printf(" curdsn %8ld", fcp->curdsn);
|
---|
238 | printf(" offset %8d\n", fcp->offset);
|
---|
239 |
|
---|
240 | printf("\n");
|
---|
241 | return(fcp);
|
---|
242 | }
|
---|
243 |
|
---|
244 | /* |
---|
245 |
|
---|
246 | */
|
---|
247 |
|
---|
248 | /*
|
---|
249 | =============================================================================
|
---|
250 | MapFAT() -- print the first 'ncl' cluster entries from 'fat'
|
---|
251 | =============================================================================
|
---|
252 | */
|
---|
253 |
|
---|
254 | void MapFAT(char *fat, short ncl, short stops)
|
---|
255 | {
|
---|
256 | register int i;
|
---|
257 |
|
---|
258 | printf("\nCluster dump of FAT at 0x%08.8lx (%d entries):\n",
|
---|
259 | fat, ncl);
|
---|
260 | printf(" 0: .... .... ");
|
---|
261 |
|
---|
262 | for (i = 2; i < ncl; i++) {
|
---|
263 |
|
---|
264 | if ((i % 10) EQ 0)
|
---|
265 | printf("\n%4.4d: ", i);
|
---|
266 |
|
---|
267 | printf("%4.4d ", _gtcl12(fat, i));
|
---|
268 |
|
---|
269 | /* stop every 10 lines if requested */
|
---|
270 |
|
---|
271 | if (stops AND (((i / 10) % 10) EQ 0))
|
---|
272 | waitcr();
|
---|
273 | }
|
---|
274 |
|
---|
275 | printf("\n");
|
---|
276 | }
|
---|
277 |
|
---|
278 | /* |
---|
279 |
|
---|
280 | */
|
---|
281 |
|
---|
282 | /*
|
---|
283 | =============================================================================
|
---|
284 | FILEfl() -- print FILE flags
|
---|
285 | =============================================================================
|
---|
286 | */
|
---|
287 |
|
---|
288 | FILE *FILEfl(FILE *fp)
|
---|
289 | {
|
---|
290 | register unsigned short mf;
|
---|
291 | register short i;
|
---|
292 |
|
---|
293 | printf(" _flags: ");
|
---|
294 | mf = 0x0001;
|
---|
295 |
|
---|
296 | for (i = 0; i < 8; i++) {
|
---|
297 |
|
---|
298 | if (fp->_flags & mf)
|
---|
299 | printf("%s ", ffname[i]);
|
---|
300 |
|
---|
301 | mf <<= 1;
|
---|
302 | }
|
---|
303 |
|
---|
304 | printf("\n");
|
---|
305 | return(fp);
|
---|
306 | }
|
---|
307 |
|
---|
308 | /* |
---|
309 |
|
---|
310 | */
|
---|
311 |
|
---|
312 | /*
|
---|
313 | =============================================================================
|
---|
314 | FILEpr(fp) -- print contents of a FILE structure pointed to by 'fp'
|
---|
315 | =============================================================================
|
---|
316 | */
|
---|
317 |
|
---|
318 | void FILEpr(FILE *fp)
|
---|
319 | {
|
---|
320 | int (*arg)(), ft;
|
---|
321 | char *ds, *fsn, *fse;
|
---|
322 | struct fcb *fcp;
|
---|
323 |
|
---|
324 | if (fp EQ (FILE *)0L) {
|
---|
325 |
|
---|
326 | printf("FILEpr(): ERROR - argument was NULL\n");
|
---|
327 | return;
|
---|
328 | }
|
---|
329 |
|
---|
330 |
|
---|
331 | printf("\nFILE at $%08.8lX", fp);
|
---|
332 |
|
---|
333 | arg = chantab[fp->_unit].c_close;
|
---|
334 | ft = 0;
|
---|
335 |
|
---|
336 | if (arg EQ _noper) {
|
---|
337 |
|
---|
338 | ds = ((struct devtabl *)chantab[fp->_unit].c_arg)->d_name;
|
---|
339 | printf(" is a device: [%s]\n", ds);
|
---|
340 |
|
---|
341 | } else if (arg EQ _filecl) {
|
---|
342 |
|
---|
343 | ft = 1;
|
---|
344 | fcp = (struct fcb *)chantab[fp->_unit].c_arg;
|
---|
345 | fsn = fcp->de.fname;
|
---|
346 | fse = fcp->de.fext;
|
---|
347 | printf(" is a disk file: [%8.8s].[%3.3s], fcb at $%08.8lX\n",
|
---|
348 | fsn, fse, fcp);
|
---|
349 |
|
---|
350 | } else {
|
---|
351 |
|
---|
352 | printf(" is of UNKNOWN type: c_close=$%08.8lX, c_arg=$%08.8lX\n",
|
---|
353 | arg, chantab[fp->_unit].c_arg);
|
---|
354 | }
|
---|
355 |
|
---|
356 | printf(" _buff=$%08.8lX, _bp=$%08.8lX, _bend=$%08.8lX, _buflen=%u\n",
|
---|
357 | fp->_buff, fp->_bp, fp->_bend, fp->_buflen);
|
---|
358 | printf(" _flags=$%04.4X, _unit=%d, _bytbuf=$%02.2X\n",
|
---|
359 | fp->_flags, fp->_unit, fp->_bytbuf);
|
---|
360 |
|
---|
361 | FILEfl(fp);
|
---|
362 |
|
---|
363 | if (ft)
|
---|
364 | SnapFCB(fcp);
|
---|
365 | else
|
---|
366 | printf("\n");
|
---|
367 | }
|
---|
368 |
|
---|
369 | /* |
---|
370 |
|
---|
371 | */
|
---|
372 |
|
---|
373 | /*
|
---|
374 | =============================================================================
|
---|
375 | fd2fcb() -- convert a unit number to a pointer to a fcb
|
---|
376 | =============================================================================
|
---|
377 | */
|
---|
378 |
|
---|
379 | struct fcb *fd2fcb(short fd)
|
---|
380 | {
|
---|
381 | if ((fd < 0) OR (fd > MAXCHAN))
|
---|
382 | return((struct fcb *)NULL);
|
---|
383 |
|
---|
384 | return(chantab[fd].c_arg);
|
---|
385 | }
|
---|
386 |
|
---|
387 | /*
|
---|
388 | =============================================================================
|
---|
389 | fp2fcb() -- convert a FILE pointer to a pointer to a fcb
|
---|
390 | =============================================================================
|
---|
391 | */
|
---|
392 |
|
---|
393 | struct fcb *fp2fcb(FILE *fp)
|
---|
394 | {
|
---|
395 | if (fp EQ (FILE *)NULL)
|
---|
396 | return((struct fcb *)NULL);
|
---|
397 |
|
---|
398 | return(chantab[fp->_unit].c_arg);
|
---|
399 | }
|
---|