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

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

Zero redundant declarations.

  • Property mode set to 100644
File size: 3.2 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 "ram.h"
29
30/*
31
32*/
33
34#if TBUFFER
35
36/*
37 =============================================================================
38 _secrd(buf, rec) -- read a logical sector via the track buffer
39 =============================================================================
40*/
41
42int32_t _secrd(int8_t *buf, int16_t rec)
43{
44 register int16_t track, side, sector;
45 int32_t brc;
46
47 if (_thebpb->dspt NE 9) /* make sure we can do this */
48 return(ERR07);
49
50 if (_thebpb->recsiz NE 512)
51 return(ERR07);
52
53 track = rec / _thebpb->dspc; /* desired track */
54 _b_tsec = track * _thebpb->dspc; /* base sector of track */
55 sector = rec - _b_tsec; /* logical sector in cylinder */
56
57 if (sector GE _thebpb->dspt) { /* adjust sector and side */
58
59 sector -= _thebpb->dspt; /* sector now in track */
60 side = 1;
61 _b_tsec += _thebpb->dspt;
62
63 } else {
64
65 side = 0;
66 }
67
68#if DEBUGIT
69 if (fsdebug)
70 printf("_secrd($%08.8LX, %d): track=%d, side=%d, sector=%d, _b_tsec=%d\n",
71 buf, rec, track, side, sector, _b_tsec);
72#endif
73
74 if ((track NE _b_trak) OR (side NE _b_side)) { /* track in buffer ? */
75
76 if (brc = BIOS(B_RDWR, 0, &_b_tbuf, _thebpb->dspt, _b_tsec, 0)) {
77
78 _b_trak = -1;
79 _b_side = -1;
80 return(brc);
81 }
82
83 _b_trak = track;
84 _b_side = side;
85 }
86
87 memcpy(buf, (int8_t *)_b_tbuf[sector], 512);
88 return(0L);
89}
90
91#endif
92
93/*
94
95*/
96
97/*
98 =============================================================================
99 blkrd(fcp, buf, ns) -- read 'ns' sectors from file 'fcp' into 'buf'.
100 Returns the number of unread sectors, or 0 if all were read.
101 =============================================================================
102*/
103
104int16_t blkrd(struct fcb *fcp, int8_t *buf, int16_t ns)
105{
106 register int32_t brc; /* bios return code */
107 register int16_t rb; /* _nsic return code */
108
109 if (ns < 0) /* can't read a negative number of sectors */
110 return(ns);
111
112 while (ns--) { /* read a sector at a time */
113
114#if DEBUGIT
115 if (fsdebug)
116 printf("_blkrd(): ns=%d, buf=$%08.8lX, curlsn=%ld, curdsn=%ld, offset=%u\n",
117 ns, buf, fcp->curlsn, fcp->curdsn, fcp->offset);
118#endif
119
120#if TBUFFER
121 if (brc = _secrd(buf, (int16_t)fcp->curdsn)) {
122#else
123 if (brc = BIOS(B_RDWR, 0, buf, 1, (short)fcp->curdsn, 0)) {
124#endif
125
126 _berrno = brc; /* log the error */
127 errno = EIO;
128 return(ns); /* return unread sector count */
129 }
130
131 if (rb = _nsic(fcp, _thebpb, _thefat)) { /* find next sector */
132
133 if (rb EQ -1) /* see if we had an error */
134 errno = EIO; /* set error number */
135
136 return(ns); /* return unread sector count */
137 }
138
139 buf += _thebpb->recsiz; /* advance buffer pointer */
140 }
141
142 return(0); /* return -- all sectors read */
143}
144
Note: See TracBrowser for help on using the repository browser.