source: buchla-68k/libcio/blkwr.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: 4.9 KB
Line 
1/*
2 =============================================================================
3 blkwr.c -- write a block of 0..32767 sectors
4 Version 14 -- 1987-12-15 -- D.N. Lynx Crowe
5
6 int
7 blkwr(fcp, buf, ns)
8 struct fcb *fcp;
9 char *buf;
10 int ns;
11
12 Writes 'ns' sectors from file 'fcp' into 'buf'.
13 Returns the number of unwritten sectors,
14 or 0 if all were written.
15 =============================================================================
16*/
17
18#define DEBUGIT 0
19
20#include "ram.h"
21
22#if TBUFFER
23
24/*
25 =============================================================================
26 _secwr(buf, rec) -- write a logical sector into the track buffer
27 =============================================================================
28*/
29
30int32_t _secwr(int8_t *buf, int16_t rec)
31{
32 register int16_t track, side, sector;
33
34 if (_thebpb->dspt NE 9) /* make sure we can do this */
35 return(ERR07);
36
37 if (_thebpb->recsiz NE 512)
38 return(ERR07);
39
40 track = rec / _thebpb->dspc; /* desired track */
41 sector = rec - (track * _thebpb->dspc); /* logical sector */
42
43 if (sector GE _thebpb->dspt) { /* adjust sector and side */
44
45 sector -= _thebpb->dspt;
46 side = 1;
47
48 } else {
49
50 side = 0;
51 }
52
53#if DEBUGIT
54 if (fsdebug) {
55
56 printf("_secwr($%08.8LX, %d): track=%d, side=%d, sector=%d\n",
57 buf, rec, track, side, sector);
58 printf("_secwr(): _b_trak=%d, _b_side=%d, _b_sect=%d, _b_tsec=%d\n",
59 _b_trak, _b_side, _b_sect, _b_tsec);
60 }
61#endif
62
63 if ((track NE _b_trak) OR (side NE _b_side)) /* track in buffer ? */
64 return(0L);
65
66 memcpy((int8_t *)_b_tbuf[sector], buf, 512); /* update the buffer */
67
68#if DEBUGIT
69 if (fsdebug)
70 printf("_secwr(): updated track buffer\n");
71#endif
72
73 return(0L);
74}
75
76#endif
77
78/*
79
80*/
81
82/*
83 =============================================================================
84 blkwr(fcp, buf, ns) -- write 'ns' sectors from file 'fcp' into 'buf'.
85 Returns the number of unwritten sectors, or 0 if all were written.
86 =============================================================================
87*/
88
89int16_t blkwr(struct fcb *fcp, int8_t *buf, int16_t ns)
90{
91 int32_t rc;
92 int16_t clustr;
93
94 while (ns > 0) { /* write a sector at a time */
95
96 if (fcp->asects) {
97
98 if (fcp->curlsn LT fcp->asects) {
99
100#if DEBUGIT
101 if (fsdebug)
102 printf("blkwr(): [1] ns=%d, curlsn=%ld, curdsn=%ld, curcls=%u, buf=$%08lX\n",
103 ns, fcp->curlsn, fcp->curdsn, fcp->curcls, buf);
104#endif
105
106 if (rc = BIOS(B_RDWR, 1, buf, 1, (int16_t)fcp->curdsn, 0)) {
107
108#if DEBUGIT
109 if (fsdebug)
110 printf("blkwr(): B_RDWR failed, rc=%ld\n", rc);
111#endif
112
113 _berrno = rc; /* log the error */
114 errno = EIO;
115 return(ns); /* return unwritten sector count */
116 }
117
118#if TBUFFER
119 _secwr(buf, (int16_t)fcp->curdsn);
120#endif
121
122 rc = _nsic(fcp, _thebpb, _thefat);
123
124#if DEBUGIT
125 if (fsdebug)
126 printf("blkwr(): _nsic() rc=%ld\n", rc);
127#endif
128
129 if (--ns EQ 0) /* done if no more to do */
130 return(0);
131
132 if (rc < 0) { /* bad cluster ? */
133
134 errno = EIO; /* set error number */
135 return(ns); /* return unwritten sector count */
136 }
137
138 buf += _thebpb->recsiz;
139/*
140
141*/
142 } else if (fcp->curlsn EQ fcp->asects) {
143
144 if (_alcnew(fcp)) { /* allocate a cluster */
145
146 errno = EIO; /* set error number */
147 return(ns); /* return unwritten sector count */
148 }
149
150 fcp->modefl &= ~FC_EOF; /* clear EOF flag */
151
152#if DEBUGIT
153 if (fsdebug)
154 printf("blkwr(): [2] ns=%d, curlsn=%ld, curdsn=%ld, curcls=%u, buf=$%08lX\n",
155 ns, fcp->curlsn, fcp->curdsn, fcp->curcls, buf);
156#endif
157
158 if (rc = BIOS(B_RDWR, 1, buf, 1, (int16_t)fcp->curdsn, 0)) {
159
160#if DEBUGIT
161 if (fsdebug)
162 printf("blkwr(): B_RDWR failed, rc=%ld\n", rc);
163#endif
164
165 _berrno = rc; /* log the error */
166 errno = EIO;
167 return(ns); /* return unwritten sector count */
168 }
169
170#if TBUFFER
171 _secwr(buf, (int16_t)fcp->curdsn);
172#endif
173
174 ++fcp->curlsn;
175 ++fcp->clsec;
176 ++fcp->curdsn;
177
178 if (--ns EQ 0)
179 return(0);
180
181 buf += _thebpb->recsiz; /* advance buffer pointer */
182 }
183/*
184
185*/
186 } else {
187
188 if (0 EQ (clustr = _newcls())) {
189
190 errno = EIO;
191 return(ns);
192 }
193
194 fcp->de.bclust = micons(clustr);
195 _ptcl12(_thefat, clustr, 0x0FF8);
196 _fatmod = TRUE;
197 fcp->curdsn = _cl2lsn(_thebpb, clustr);
198 fcp->curcls = clustr;
199 fcp->clsec = 0;
200 fcp->asects = _thebpb->clsiz;
201 fcp->modefl &= ~FC_EOF;
202
203 fcp->modefl &= ~FC_EOF; /* clear EOF flag */
204
205#if DEBUGIT
206 if (fsdebug)
207 printf("blkwr(): [3] ns=%d, curlsn=%ld, curdsn=%ld, curcls=%u, buf=$%08lX\n",
208 ns, fcp->curlsn, fcp->curdsn, fcp->curcls, buf);
209#endif
210
211 if (rc = BIOS(B_RDWR, 1, buf, 1, (int16_t)fcp->curdsn, 0)) {
212
213#if DEBUGIT
214 if (fsdebug)
215 printf("blkwr(): B_RDWR failed, rc=%ld\n", rc);
216#endif
217
218 _berrno = rc; /* log the error */
219 errno = EIO;
220 return(ns); /* return unwritten sector count */
221 }
222
223#if TBUFFER
224 _secwr(buf, (int16_t)fcp->curdsn);
225#endif
226
227 ++fcp->curlsn;
228 ++fcp->clsec;
229 ++fcp->curdsn;
230
231 if (--ns EQ 0)
232 return(0);
233
234 buf += _thebpb->recsiz; /* advance buffer pointer */
235 }
236 }
237
238 return(ns); /* return (will be zero or negative) */
239}
240
Note: See TracBrowser for help on using the repository browser.