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