]>
Commit | Line | Data |
---|---|---|
1c79356b A |
1 | /* |
2 | * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. | |
3 | * | |
4 | * @APPLE_LICENSE_HEADER_START@ | |
5 | * | |
d7e50217 | 6 | * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. |
1c79356b | 7 | * |
d7e50217 A |
8 | * This file contains Original Code and/or Modifications of Original Code |
9 | * as defined in and that are subject to the Apple Public Source License | |
10 | * Version 2.0 (the 'License'). You may not use this file except in | |
11 | * compliance with the License. Please obtain a copy of the License at | |
12 | * http://www.opensource.apple.com/apsl/ and read it before using this | |
13 | * file. | |
14 | * | |
15 | * The Original Code and all software distributed under the License are | |
16 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER | |
1c79356b A |
17 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, |
18 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
d7e50217 A |
19 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. |
20 | * Please see the License for the specific language governing rights and | |
21 | * limitations under the License. | |
1c79356b A |
22 | * |
23 | * @APPLE_LICENSE_HEADER_END@ | |
24 | */ | |
25 | /* dspWrite.c | |
26 | * From Mike Shoemaker v01.13 06/21/90 mbs for MacOS | |
27 | */ | |
28 | /* | |
29 | * Change log: | |
30 | * 06/29/95 - Modified to handle flow control for writing (Tuyen Nguyen) | |
31 | * 09/07/95 - Modified for performance (Tuyen Nguyen) | |
32 | * Modified for MP, 1996 by Tuyen Nguyen | |
33 | * Modified, April 9, 1997 by Tuyen Nguyen for MacOSX. | |
34 | */ | |
35 | ||
36 | #include <sys/errno.h> | |
37 | #include <sys/types.h> | |
38 | #include <sys/param.h> | |
39 | #include <machine/spl.h> | |
40 | #include <sys/systm.h> | |
41 | #include <sys/kernel.h> | |
42 | #include <sys/proc.h> | |
43 | #include <sys/filedesc.h> | |
44 | #include <sys/fcntl.h> | |
45 | #include <sys/mbuf.h> | |
46 | #include <sys/socket.h> | |
47 | ||
48 | #include <netat/sysglue.h> | |
49 | #include <netat/appletalk.h> | |
50 | #include <netat/at_pcb.h> | |
51 | #include <netat/debug.h> | |
52 | #include <netat/adsp.h> | |
53 | #include <netat/adsp_internal.h> | |
54 | ||
55 | void completepb(); | |
56 | ||
57 | /* | |
58 | * FillSendQueue | |
59 | * | |
60 | * INPUTS: | |
61 | * sp stream | |
62 | * OUTPUTS: | |
63 | * none | |
64 | */ | |
65 | int FillSendQueue(sp, pb) /* (CCBPtr sp) */ | |
66 | register CCBPtr sp; | |
67 | register struct adspcmd *pb; /* The write PB we're playing with */ | |
68 | { | |
69 | gbuf_t *mb, *nmb; | |
70 | int eom; /* True if should set eom in header */ | |
71 | int cnt; /* # of bytes in this write */ | |
72 | int err = 0; | |
73 | int s; | |
74 | ||
75 | cnt = pb->u.ioParams.reqCount - pb->u.ioParams.actCount; | |
76 | eom = pb->u.ioParams.eom ? F_EOM : 0; | |
77 | ||
78 | if (cnt == 0 && eom == 0) /* Nothing to do here, complete it */ | |
79 | goto unlink; | |
80 | ||
81 | /* The 1st mbuf in the pb->mp chain (mb) is the adspcmd structure. | |
82 | The 2nd mbuf (nmb) will be the beginning of the data. */ | |
83 | mb = pb->mp; | |
84 | nmb = gbuf_cont(mb); | |
85 | if (gbuf_len(mb) > sizeof(struct adspcmd)) { | |
86 | if ((nmb = gbuf_dupb(mb)) == 0) { | |
87 | gbuf_wset(mb,sizeof(struct adspcmd)); | |
88 | err = errDSPQueueSize; | |
89 | goto unlink; | |
90 | } | |
91 | gbuf_wset(mb,sizeof(struct adspcmd)); | |
92 | gbuf_rinc(nmb,sizeof(struct adspcmd)); | |
93 | gbuf_cont(nmb) = gbuf_cont(mb); | |
94 | } else if (nmb == 0) { | |
95 | if ((nmb = gbuf_alloc(1, PRI_LO)) == 0) { | |
96 | err = errENOBUFS; | |
97 | goto unlink; | |
98 | } | |
99 | } | |
100 | gbuf_cont(mb) = 0; | |
101 | ||
102 | ATDISABLE(s, sp->lock); | |
103 | sp->sData = 1; /* note that there is data to send */ | |
104 | if ((mb = sp->csbuf_mb)) { /* add to the current message */ | |
105 | gbuf_linkb(mb, nmb); | |
106 | } else | |
107 | sp->csbuf_mb = nmb; /* mark the buffer we are currently filling */ | |
108 | if (eom) { | |
109 | if ((mb = sp->sbuf_mb)) { | |
110 | while (gbuf_next(mb)) | |
111 | mb = gbuf_next(mb); | |
112 | gbuf_next(mb) = sp->csbuf_mb; /* add the current item */ | |
113 | } else | |
114 | sp->sbuf_mb = sp->csbuf_mb; | |
115 | sp->csbuf_mb = 0; /* if its done, no current buffer */ | |
116 | } | |
117 | pb->u.ioParams.actCount += cnt; /* Update count field in param blk */ | |
118 | ATENABLE(s, sp->lock); | |
119 | ||
120 | if (pb->u.ioParams.actCount == pb->u.ioParams.reqCount) { | |
121 | /* Write is complete */ | |
122 | unlink: | |
123 | if (pb->u.ioParams.flush) /* flush the send Q? */ | |
124 | sp->writeFlush = 1; | |
125 | ||
126 | pb->ioResult = err; | |
127 | if (err) | |
128 | atalk_notify(sp->gref, EIO); | |
129 | gbuf_freem(pb->mp); | |
130 | } | |
131 | ||
132 | return 0; | |
133 | } /* FillSendQueue */ | |
134 | ||
135 | /* | |
136 | * dspWrite | |
137 | * | |
138 | * INPUTS: | |
139 | * --> ccbRefNum refnum of connection end | |
140 | * --> reqCount requested number of bytes to write | |
141 | * --> dataPtr pointer to buffer for reading bytes into | |
142 | * --> eom one if end-of-message, zero otherwise | |
143 | * | |
144 | * OUTPUTS: | |
145 | * <-- actCount actual number of bytes written | |
146 | * | |
147 | * ERRORS: | |
148 | * errRefNum bad connection refnum | |
149 | * errState connection is not open | |
150 | * errAborted request aborted by Remove or Close call | |
151 | */ | |
152 | int adspWrite(sp, pb) /* (DSPPBPtr pb) */ | |
153 | CCBPtr sp; | |
154 | struct adspcmd *pb; | |
155 | { | |
156 | int s; | |
157 | ||
158 | if (sp == 0) { | |
159 | pb->ioResult = errRefNum; | |
160 | return EINVAL; /* no stream, so drop the message */ | |
161 | } | |
162 | ||
163 | ATDISABLE(s, sp->lock); | |
164 | if (sp->state != sOpen) { /* Not allowed */ | |
165 | pb->ioResult = errState; | |
166 | ATENABLE(s, sp->lock); | |
167 | atalk_notify(sp->gref, ENOTCONN); | |
168 | gbuf_freem(pb->mp); | |
169 | return 0; | |
170 | } | |
171 | ||
172 | pb->u.ioParams.actCount = 0; /* Set # of bytes so far to zero */ | |
173 | ATENABLE(s, sp->lock); | |
174 | ||
175 | FillSendQueue(sp, pb); /* Copy from write param block to send queue */ | |
176 | ||
177 | CheckSend(sp); /* See if we should send anything */ | |
178 | return 0; | |
179 | } | |
180 | ||
181 | #ifdef notdef | |
182 | int adsp_check = 1; | |
183 | ||
184 | CheckQueue(sp) | |
185 | CCBPtr sp; | |
186 | { | |
187 | register gbuf_t *mp, *tmp; | |
188 | unsigned char current; | |
189 | int current_valid = 0; | |
190 | ||
191 | if (adsp_check == 0) | |
192 | return; | |
193 | if (mp = sp->sbuf_mb) { | |
194 | current = *mp->b_rptr; | |
195 | current_valid = 1; | |
196 | while (mp) { | |
197 | tmp = mp; | |
198 | while (tmp) { | |
199 | current = CheckData(tmp->b_rptr, tmp->b_wptr - tmp->b_rptr, | |
200 | current); | |
201 | tmp = tmp->b_cont; | |
202 | } | |
203 | mp = mp->b_next; | |
204 | } | |
205 | } | |
206 | if (mp = sp->csbuf_mb) { | |
207 | if (current_valid == 0) | |
208 | current = *mp->b_rptr; | |
209 | tmp = mp; | |
210 | while (tmp) { | |
211 | current = CheckData(tmp->b_rptr, tmp->b_wptr - tmp->b_rptr, | |
212 | current); | |
213 | tmp = tmp->b_cont; | |
214 | } | |
215 | } | |
216 | } | |
217 | ||
218 | ||
219 | int adsp_bad_block_count; | |
220 | char *adsp_bad_block; | |
221 | ||
222 | CheckData(block, size, current) | |
223 | char *block; | |
224 | int size; | |
225 | u_char current; | |
226 | { | |
227 | register int anError = 0; | |
228 | register int i; | |
229 | ||
230 | for (i = 0; i < size; i++) { | |
231 | if ((block[i] & 0xff) != (current & 0xff)) { | |
232 | if (!anError) { | |
233 | adsp_bad_block = block; | |
234 | } | |
235 | anError++; | |
236 | } | |
237 | current++; | |
238 | } | |
239 | ||
240 | if (anError) { | |
241 | adsp_bad_block_count++; | |
242 | } | |
243 | return current; | |
244 | } | |
245 | #endif |