source: buchla-68k/orig/IOLIB/BLKRD.C@ 4810254

Last change on this file since 4810254 was 3ae31e9, checked in by Thomas Lopatic <thomas@…>, 8 years ago

Imported original source code.

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