[f40a309] | 1 | /*
|
---|
| 2 | =============================================================================
|
---|
| 3 | blkrd.c -- read a block of 0..32767 sectors
|
---|
| 4 | Version 10 -- 1988-01-08 -- D.N. Lynx Crowe
|
---|
| 5 |
|
---|
| 6 | int
|
---|
| 7 | blkrd(fcp, buf, ns)
|
---|
| 8 | struct fcb *fcp;
|
---|
| 9 | char *buf;
|
---|
| 10 | int ns;
|
---|
| 11 |
|
---|
| 12 | Reads 'ns' sectors from file 'fcp' into 'buf'.
|
---|
| 13 | Returns the number of unread sectors, or 0 if all were read.
|
---|
| 14 |
|
---|
| 15 | long
|
---|
| 16 | _secrd(buf, rec)
|
---|
| 17 | register char *buf;
|
---|
| 18 | register short rec;
|
---|
| 19 |
|
---|
| 20 | Reads a logical sector via the track buffer.
|
---|
| 21 | Functionally equivalent to the BIOS B_RDWR read function
|
---|
| 22 | with the addition of transparent write-thru track buffering.
|
---|
| 23 | =============================================================================
|
---|
| 24 | */
|
---|
| 25 |
|
---|
| 26 | #define DEBUGIT 0
|
---|
| 27 |
|
---|
[6262b5c] | 28 | #include "all.h"
|
---|
[e225e77] | 29 |
|
---|
[f40a309] | 30 | /* |
---|
| 31 |
|
---|
| 32 | */
|
---|
| 33 |
|
---|
| 34 | #if DEBUGIT
|
---|
| 35 | extern short fsdebug; /* file system debug switch */
|
---|
| 36 | #endif
|
---|
[7258c6a] | 37 |
|
---|
[f40a309] | 38 | extern int16_t _nsic(struct fcb *fcp, struct bpb *bpp, int8_t *fp);
|
---|
[7258c6a] | 39 |
|
---|
[f40a309] | 40 | extern int32_t _berrno; /* last file system bios error number */
|
---|
[7258c6a] | 41 |
|
---|
[f40a309] | 42 | extern uint16_t _thefat[]; /* current file allocation table */
|
---|
| 43 |
|
---|
| 44 | extern struct bpb *_thebpb; /* current bios parameter block */
|
---|
| 45 |
|
---|
| 46 | #if TBUFFER
|
---|
| 47 |
|
---|
| 48 | /* WARNING: this ONLY works for 512 byte sectors, 9 sectors per track */
|
---|
[7258c6a] | 49 |
|
---|
[f40a309] | 50 | extern int16_t _b_tbuf[9][256]; /* the track buffer */
|
---|
[7258c6a] | 51 |
|
---|
| 52 | extern int16_t _b_trak; /* current track */
|
---|
| 53 | extern int16_t _b_side; /* current side */
|
---|
| 54 | extern int16_t _b_sect; /* current sector */
|
---|
[f40a309] | 55 | extern int16_t _b_tsec; /* current base sector of current track */
|
---|
| 56 |
|
---|
| 57 | #endif
|
---|
| 58 |
|
---|
| 59 | /* |
---|
| 60 |
|
---|
| 61 | */
|
---|
| 62 |
|
---|
| 63 | #if TBUFFER
|
---|
| 64 |
|
---|
| 65 | /*
|
---|
| 66 | =============================================================================
|
---|
| 67 | _secrd(buf, rec) -- read a logical sector via the track buffer
|
---|
| 68 | =============================================================================
|
---|
[7258c6a] | 69 | */
|
---|
[f40a309] | 70 |
|
---|
[7258c6a] | 71 | int32_t _secrd(int8_t *buf, int16_t rec)
|
---|
| 72 | {
|
---|
[f40a309] | 73 | register int16_t track, side, sector;
|
---|
| 74 | int32_t brc;
|
---|
| 75 |
|
---|
| 76 | if (_thebpb->dspt NE 9) /* make sure we can do this */
|
---|
| 77 | return(ERR07);
|
---|
| 78 |
|
---|
| 79 | if (_thebpb->recsiz NE 512)
|
---|
| 80 | return(ERR07);
|
---|
| 81 |
|
---|
| 82 | track = rec / _thebpb->dspc; /* desired track */
|
---|
| 83 | _b_tsec = track * _thebpb->dspc; /* base sector of track */
|
---|
| 84 | sector = rec - _b_tsec; /* logical sector in cylinder */
|
---|
| 85 |
|
---|
| 86 | if (sector GE _thebpb->dspt) { /* adjust sector and side */
|
---|
| 87 |
|
---|
| 88 | sector -= _thebpb->dspt; /* sector now in track */
|
---|
| 89 | side = 1;
|
---|
| 90 | _b_tsec += _thebpb->dspt;
|
---|
| 91 |
|
---|
| 92 | } else {
|
---|
| 93 |
|
---|
| 94 | side = 0;
|
---|
| 95 | }
|
---|
| 96 |
|
---|
| 97 | #if DEBUGIT
|
---|
| 98 | if (fsdebug)
|
---|
| 99 | printf("_secrd($%08.8LX, %d): track=%d, side=%d, sector=%d, _b_tsec=%d\n",
|
---|
| 100 | buf, rec, track, side, sector, _b_tsec);
|
---|
| 101 | #endif
|
---|
| 102 |
|
---|
| 103 | if ((track NE _b_trak) OR (side NE _b_side)) { /* track in buffer ? */
|
---|
| 104 |
|
---|
| 105 | if (brc = BIOS(B_RDWR, 0, &_b_tbuf, _thebpb->dspt, _b_tsec, 0)) {
|
---|
| 106 |
|
---|
| 107 | _b_trak = -1;
|
---|
| 108 | _b_side = -1;
|
---|
| 109 | return(brc);
|
---|
| 110 | }
|
---|
| 111 |
|
---|
| 112 | _b_trak = track;
|
---|
| 113 | _b_side = side;
|
---|
[7258c6a] | 114 | }
|
---|
[f40a309] | 115 |
|
---|
| 116 | memcpy(buf, (int8_t *)_b_tbuf[sector], 512);
|
---|
| 117 | return(0L);
|
---|
| 118 | }
|
---|
| 119 |
|
---|
| 120 | #endif
|
---|
| 121 |
|
---|
| 122 | /* |
---|
| 123 |
|
---|
| 124 | */
|
---|
| 125 |
|
---|
| 126 | /*
|
---|
| 127 | =============================================================================
|
---|
| 128 | blkrd(fcp, buf, ns) -- read 'ns' sectors from file 'fcp' into 'buf'.
|
---|
| 129 | Returns the number of unread sectors, or 0 if all were read.
|
---|
[7258c6a] | 130 | =============================================================================
|
---|
[f40a309] | 131 | */
|
---|
[7258c6a] | 132 |
|
---|
| 133 | int16_t blkrd(struct fcb *fcp, int8_t *buf, int16_t ns)
|
---|
[f40a309] | 134 | {
|
---|
| 135 | register int32_t brc; /* bios return code */
|
---|
| 136 | register int16_t rb; /* _nsic return code */
|
---|
| 137 |
|
---|
| 138 | if (ns < 0) /* can't read a negative number of sectors */
|
---|
| 139 | return(ns);
|
---|
| 140 |
|
---|
| 141 | while (ns--) { /* read a sector at a time */
|
---|
| 142 |
|
---|
| 143 | #if DEBUGIT
|
---|
| 144 | if (fsdebug)
|
---|
| 145 | printf("_blkrd(): ns=%d, buf=$%08.8lX, curlsn=%ld, curdsn=%ld, offset=%u\n",
|
---|
| 146 | ns, buf, fcp->curlsn, fcp->curdsn, fcp->offset);
|
---|
[7258c6a] | 147 | #endif
|
---|
[f40a309] | 148 |
|
---|
| 149 | #if TBUFFER
|
---|
| 150 | if (brc = _secrd(buf, (int16_t)fcp->curdsn)) {
|
---|
| 151 | #else
|
---|
| 152 | if (brc = BIOS(B_RDWR, 0, buf, 1, (short)fcp->curdsn, 0)) {
|
---|
| 153 | #endif
|
---|
| 154 |
|
---|
| 155 | _berrno = brc; /* log the error */
|
---|
| 156 | errno = EIO;
|
---|
| 157 | return(ns); /* return unread sector count */
|
---|
| 158 | }
|
---|
| 159 |
|
---|
| 160 | if (rb = _nsic(fcp, _thebpb, _thefat)) { /* find next sector */
|
---|
| 161 |
|
---|
| 162 | if (rb EQ -1) /* see if we had an error */
|
---|
| 163 | errno = EIO; /* set error number */
|
---|
| 164 |
|
---|
| 165 | return(ns); /* return unread sector count */
|
---|
| 166 | }
|
---|
| 167 |
|
---|
| 168 | buf += _thebpb->recsiz; /* advance buffer pointer */
|
---|
| 169 | }
|
---|
[6262b5c] | 170 |
|
---|
| 171 | return(0); /* return -- all sectors read */
|
---|
| 172 | }
|
---|
| 173 |
|
---|