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