[f40a309] | 1 | /*
|
---|
| 2 | =============================================================================
|
---|
| 3 | clusmap.c -- various file structure utilities
|
---|
| 4 | Version 9 -- 1987-10-29 -- D.N. Lynx Crowe
|
---|
| 5 | =============================================================================
|
---|
| 6 | */
|
---|
| 7 |
|
---|
[6262b5c] | 8 | #include "all.h"
|
---|
[f40a309] | 9 |
|
---|
[7258c6a] | 10 | extern int16_t micons(int16_t wi);
|
---|
| 11 | extern uint16_t _gtcl12(int8_t *fat, uint16_t cl);
|
---|
| 12 | extern int32_t miconl(int32_t wi);
|
---|
[f40a309] | 13 |
|
---|
| 14 | extern struct bpb *_thebpb;
|
---|
[7258c6a] | 15 | extern uint16_t _thefat[];
|
---|
[f40a309] | 16 |
|
---|
[7258c6a] | 17 | extern int16_t _filecl(struct fcb *fp);
|
---|
| 18 | extern int16_t _noper(void);
|
---|
[f40a309] | 19 |
|
---|
[e225e77] | 20 | extern void xtrap15(void);
|
---|
| 21 |
|
---|
[f40a309] | 22 | /* |
---|
| 23 |
|
---|
| 24 | */
|
---|
[7258c6a] | 25 |
|
---|
[f40a309] | 26 | static int8_t *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 |
|
---|
[7258c6a] | 51 | */
|
---|
[f40a309] | 52 |
|
---|
| 53 | static int8_t *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 */
|
---|
[7258c6a] | 63 | };
|
---|
[f40a309] | 64 |
|
---|
| 65 | static int8_t *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 | /* |
---|
[6262b5c] | 78 |
|
---|
[f40a309] | 79 | */
|
---|
[7258c6a] | 80 |
|
---|
[f40a309] | 81 | int16_t waitcr(void)
|
---|
| 82 | {
|
---|
| 83 | int8_t c;
|
---|
| 84 |
|
---|
| 85 | BIOS(B_PUTC, CON_DEV, '\007');
|
---|
| 86 |
|
---|
[60288f5] | 87 | while ('\r' NE (c = (0x7F & BIOS(B_GETC, CON_DEV))))
|
---|
| 88 | if (c EQ '\007')
|
---|
[f40a309] | 89 | xtrap15();
|
---|
| 90 |
|
---|
| 91 | return(c);
|
---|
| 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.
|
---|
[7258c6a] | 102 | Returns 0 if a map was printed, -1 otherwise.
|
---|
[f40a309] | 103 | =============================================================================
|
---|
[7258c6a] | 104 | */
|
---|
| 105 |
|
---|
[f40a309] | 106 | int16_t ClusMap(struct fcb *fcp)
|
---|
| 107 | {
|
---|
| 108 | int16_t clus, nc;
|
---|
| 109 | int32_t 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 | /*
|
---|
[0580615] | 168 | =============================================================================
|
---|
[f40a309] | 169 | FCBmode(fcp) -- print FCB mode flags
|
---|
[7258c6a] | 170 | =============================================================================
|
---|
| 171 | */
|
---|
[f40a309] | 172 |
|
---|
| 173 | struct fcb *FCBmode(struct fcb *fcp)
|
---|
| 174 | {
|
---|
| 175 | register uint16_t mf;
|
---|
| 176 | register int16_t 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 |
|
---|
[0580615] | 210 | /*
|
---|
[f40a309] | 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 | */
|
---|
[7258c6a] | 247 |
|
---|
[f40a309] | 248 | /*
|
---|
[7258c6a] | 249 | =============================================================================
|
---|
[f40a309] | 250 | MapFAT() -- print the first 'ncl' cluster entries from 'fat'
|
---|
| 251 | =============================================================================
|
---|
| 252 | */
|
---|
| 253 |
|
---|
| 254 | void MapFAT(int8_t *fat, int16_t ncl, int16_t stops)
|
---|
| 255 | {
|
---|
| 256 | register int16_t 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 |
|
---|
[0580615] | 280 | */
|
---|
[f40a309] | 281 |
|
---|
[7258c6a] | 282 | /*
|
---|
| 283 | =============================================================================
|
---|
[f40a309] | 284 | FILEfl() -- print FILE flags
|
---|
| 285 | =============================================================================
|
---|
| 286 | */
|
---|
| 287 |
|
---|
| 288 | FILE *FILEfl(FILE *fp)
|
---|
| 289 | {
|
---|
| 290 | register uint16_t mf;
|
---|
| 291 | register int16_t 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 | /* |
---|
[0580615] | 309 |
|
---|
[f40a309] | 310 | */
|
---|
[7258c6a] | 311 |
|
---|
| 312 | /*
|
---|
[f40a309] | 313 | =============================================================================
|
---|
| 314 | FILEpr(fp) -- print contents of a FILE structure pointed to by 'fp'
|
---|
| 315 | =============================================================================
|
---|
| 316 | */
|
---|
| 317 |
|
---|
| 318 | void FILEpr(FILE *fp)
|
---|
| 319 | {
|
---|
| 320 | int16_t (*arg)(), ft;
|
---|
| 321 | int8_t *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 | }
|
---|
[df097bf] | 329 |
|
---|
[f40a309] | 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 |
|
---|
[7258c6a] | 369 | /* |
---|
[f40a309] | 370 |
|
---|
| 371 | */
|
---|
| 372 |
|
---|
| 373 | /*
|
---|
| 374 | =============================================================================
|
---|
| 375 | fd2fcb() -- convert a unit number to a pointer to a fcb
|
---|
| 376 | =============================================================================
|
---|
| 377 | */
|
---|
| 378 |
|
---|
| 379 | struct fcb *fd2fcb(int16_t fd)
|
---|
| 380 | {
|
---|
| 381 | if ((fd < 0) OR (fd > MAXCHAN))
|
---|
| 382 | return((struct fcb *)NULL);
|
---|
[0580615] | 383 |
|
---|
[f40a309] | 384 | return(chantab[fd].c_arg);
|
---|
| 385 | }
|
---|
| 386 |
|
---|
| 387 | /*
|
---|
| 388 | =============================================================================
|
---|
| 389 | fp2fcb() -- convert a FILE pointer to a pointer to a fcb
|
---|
[6262b5c] | 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 | }
|
---|
| 400 |
|
---|