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