source: buchla-68k/libcio/blkrd.c@ 0580615

Last change on this file since 0580615 was 0580615, checked in by Thomas Lopatic <thomas@…>, 7 years ago

Point of no return.

  • Property mode set to 100644
File size: 4.0 KB
Line 
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(struct fcb *fcp, struct bpb *bpp, char *fp);
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 _secrd(char *buf, short rec)
76{
77 register short track, side, sector;
78 long brc;
79
80 if (_thebpb->dspt NE 9) /* make sure we can do this */
81 return(ERR07);
82
83 if (_thebpb->recsiz NE 512)
84 return(ERR07);
85
86 track = rec / _thebpb->dspc; /* desired track */
87 _b_tsec = track * _thebpb->dspc; /* base sector of track */
88 sector = rec - _b_tsec; /* logical sector in cylinder */
89
90 if (sector GE _thebpb->dspt) { /* adjust sector and side */
91
92 sector -= _thebpb->dspt; /* sector now in track */
93 side = 1;
94 _b_tsec += _thebpb->dspt;
95
96 } else {
97
98 side = 0;
99 }
100
101#if DEBUGIT
102 if (fsdebug)
103 printf("_secrd($%08.8LX, %d): track=%d, side=%d, sector=%d, _b_tsec=%d\n",
104 buf, rec, track, side, sector, _b_tsec);
105#endif
106
107 if ((track NE _b_trak) OR (side NE _b_side)) { /* track in buffer ? */
108
109 if (brc = BIOS(B_RDWR, 0, &_b_tbuf, _thebpb->dspt, _b_tsec, 0)) {
110
111 _b_trak = -1;
112 _b_side = -1;
113 return(brc);
114 }
115
116 _b_trak = track;
117 _b_side = side;
118 }
119
120 memcpy(buf, (char *)_b_tbuf[sector], 512);
121 return(0L);
122}
123
124#endif
125
126/*
127
128*/
129
130/*
131 =============================================================================
132 blkrd(fcp, buf, ns) -- read 'ns' sectors from file 'fcp' into 'buf'.
133 Returns the number of unread sectors, or 0 if all were read.
134 =============================================================================
135*/
136
137int blkrd(struct fcb *fcp, char *buf, int ns)
138{
139 register long brc; /* bios return code */
140 register int rb; /* _nsic return code */
141
142 if (ns < 0) /* can't read a negative number of sectors */
143 return(ns);
144
145 while (ns--) { /* read a sector at a time */
146
147#if DEBUGIT
148 if (fsdebug)
149 printf("_blkrd(): ns=%d, buf=$%08.8lX, curlsn=%ld, curdsn=%ld, offset=%u\n",
150 ns, buf, fcp->curlsn, fcp->curdsn, fcp->offset);
151#endif
152
153#if TBUFFER
154 if (brc = _secrd(buf, (short)fcp->curdsn)) {
155#else
156 if (brc = BIOS(B_RDWR, 0, buf, 1, (short)fcp->curdsn, 0)) {
157#endif
158
159 _berrno = brc; /* log the error */
160 errno = EIO;
161 return(ns); /* return unread sector count */
162 }
163
164 if (rb = _nsic(fcp, _thebpb, _thefat)) { /* find next sector */
165
166 if (rb EQ -1) /* see if we had an error */
167 errno = EIO; /* set error number */
168
169 return(ns); /* return unread sector count */
170 }
171
172 buf += _thebpb->recsiz; /* advance buffer pointer */
173 }
174
175 return(0); /* return -- all sectors read */
176}
Note: See TracBrowser for help on using the repository browser.