]>
git.saurik.com Git - apple/xnu.git/blob - bsd/netat/adsp_Write.c
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
20 * @APPLE_LICENSE_HEADER_END@
23 * From Mike Shoemaker v01.13 06/21/90 mbs for MacOS
27 * 06/29/95 - Modified to handle flow control for writing (Tuyen Nguyen)
28 * 09/07/95 - Modified for performance (Tuyen Nguyen)
29 * Modified for MP, 1996 by Tuyen Nguyen
30 * Modified, April 9, 1997 by Tuyen Nguyen for MacOSX.
33 #include <sys/errno.h>
34 #include <sys/types.h>
35 #include <sys/param.h>
36 #include <machine/spl.h>
37 #include <sys/systm.h>
38 #include <sys/kernel.h>
40 #include <sys/filedesc.h>
41 #include <sys/fcntl.h>
43 #include <sys/socket.h>
45 #include <netat/sysglue.h>
46 #include <netat/appletalk.h>
47 #include <netat/at_pcb.h>
48 #include <netat/debug.h>
49 #include <netat/adsp.h>
50 #include <netat/adsp_internal.h>
62 int FillSendQueue(sp
, pb
) /* (CCBPtr sp) */
64 register struct adspcmd
*pb
; /* The write PB we're playing with */
67 int eom
; /* True if should set eom in header */
68 int cnt
; /* # of bytes in this write */
72 cnt
= pb
->u
.ioParams
.reqCount
- pb
->u
.ioParams
.actCount
;
73 eom
= pb
->u
.ioParams
.eom
? F_EOM
: 0;
75 if (cnt
== 0 && eom
== 0) /* Nothing to do here, complete it */
78 /* The 1st mbuf in the pb->mp chain (mb) is the adspcmd structure.
79 The 2nd mbuf (nmb) will be the beginning of the data. */
82 if (gbuf_len(mb
) > sizeof(struct adspcmd
)) {
83 if ((nmb
= gbuf_dupb(mb
)) == 0) {
84 gbuf_wset(mb
,sizeof(struct adspcmd
));
85 err
= errDSPQueueSize
;
88 gbuf_wset(mb
,sizeof(struct adspcmd
));
89 gbuf_rinc(nmb
,sizeof(struct adspcmd
));
90 gbuf_cont(nmb
) = gbuf_cont(mb
);
91 } else if (nmb
== 0) {
92 if ((nmb
= gbuf_alloc(1, PRI_LO
)) == 0) {
99 ATDISABLE(s
, sp
->lock
);
100 sp
->sData
= 1; /* note that there is data to send */
101 if ((mb
= sp
->csbuf_mb
)) { /* add to the current message */
104 sp
->csbuf_mb
= nmb
; /* mark the buffer we are currently filling */
106 if ((mb
= sp
->sbuf_mb
)) {
107 while (gbuf_next(mb
))
109 gbuf_next(mb
) = sp
->csbuf_mb
; /* add the current item */
111 sp
->sbuf_mb
= sp
->csbuf_mb
;
112 sp
->csbuf_mb
= 0; /* if its done, no current buffer */
114 pb
->u
.ioParams
.actCount
+= cnt
; /* Update count field in param blk */
115 ATENABLE(s
, sp
->lock
);
117 if (pb
->u
.ioParams
.actCount
== pb
->u
.ioParams
.reqCount
) {
118 /* Write is complete */
120 if (pb
->u
.ioParams
.flush
) /* flush the send Q? */
125 atalk_notify(sp
->gref
, EIO
);
130 } /* FillSendQueue */
136 * --> ccbRefNum refnum of connection end
137 * --> reqCount requested number of bytes to write
138 * --> dataPtr pointer to buffer for reading bytes into
139 * --> eom one if end-of-message, zero otherwise
142 * <-- actCount actual number of bytes written
145 * errRefNum bad connection refnum
146 * errState connection is not open
147 * errAborted request aborted by Remove or Close call
149 int adspWrite(sp
, pb
) /* (DSPPBPtr pb) */
156 pb
->ioResult
= errRefNum
;
157 return EINVAL
; /* no stream, so drop the message */
160 ATDISABLE(s
, sp
->lock
);
161 if (sp
->state
!= sOpen
) { /* Not allowed */
162 pb
->ioResult
= errState
;
163 ATENABLE(s
, sp
->lock
);
164 atalk_notify(sp
->gref
, ENOTCONN
);
169 pb
->u
.ioParams
.actCount
= 0; /* Set # of bytes so far to zero */
170 ATENABLE(s
, sp
->lock
);
172 FillSendQueue(sp
, pb
); /* Copy from write param block to send queue */
174 CheckSend(sp
); /* See if we should send anything */
184 register gbuf_t
*mp
, *tmp
;
185 unsigned char current
;
186 int current_valid
= 0;
190 if (mp
= sp
->sbuf_mb
) {
191 current
= *mp
->b_rptr
;
196 current
= CheckData(tmp
->b_rptr
, tmp
->b_wptr
- tmp
->b_rptr
,
203 if (mp
= sp
->csbuf_mb
) {
204 if (current_valid
== 0)
205 current
= *mp
->b_rptr
;
208 current
= CheckData(tmp
->b_rptr
, tmp
->b_wptr
- tmp
->b_rptr
,
216 int adsp_bad_block_count
;
217 char *adsp_bad_block
;
219 CheckData(block
, size
, current
)
224 register int anError
= 0;
227 for (i
= 0; i
< size
; i
++) {
228 if ((block
[i
] & 0xff) != (current
& 0xff)) {
230 adsp_bad_block
= block
;
238 adsp_bad_block_count
++;