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

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

No more warnings in libcio.

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