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

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

Added missing includes and declarations.

  • 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#include "memory.h"
35
36/*
37
38*/
39
40#if DEBUGIT
41extern short fsdebug; /* file system debug switch */
42#endif
43
44extern int16_t _nsic(struct fcb *fcp, struct bpb *bpp, int8_t *fp);
45
46extern int32_t _berrno; /* last file system bios error number */
47
48extern uint16_t _thefat[]; /* current file allocation table */
49
50extern 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 */
55
56extern int16_t _b_tbuf[9][256]; /* the track buffer */
57
58extern int16_t _b_trak; /* current track */
59extern int16_t _b_side; /* current side */
60extern int16_t _b_sect; /* current sector */
61extern 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 =============================================================================
75*/
76
77int32_t _secrd(int8_t *buf, int16_t rec)
78{
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;
120 }
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.
136 =============================================================================
137*/
138
139int16_t blkrd(struct fcb *fcp, int8_t *buf, int16_t ns)
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);
153#endif
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}
Note: See TracBrowser for help on using the repository browser.