]>
git.saurik.com Git - apple/xnu.git/blob - bsd/netat/adsp_Write.c
4d2b1a6326eac70390d4cd7eb845d0e6993bfa47
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 */
71 cnt
= pb
->u
.ioParams
.reqCount
- pb
->u
.ioParams
.actCount
;
72 eom
= pb
->u
.ioParams
.eom
? F_EOM
: 0;
74 if (cnt
== 0 && eom
== 0) /* Nothing to do here, complete it */
77 /* The 1st mbuf in the pb->mp chain (mb) is the adspcmd structure.
78 The 2nd mbuf (nmb) will be the beginning of the data. */
81 if (gbuf_len(mb
) > sizeof(struct adspcmd
)) {
82 if ((nmb
= gbuf_dupb(mb
)) == 0) {
83 gbuf_wset(mb
,sizeof(struct adspcmd
));
84 err
= errDSPQueueSize
;
87 gbuf_wset(mb
,sizeof(struct adspcmd
));
88 gbuf_rinc(nmb
,sizeof(struct adspcmd
));
89 gbuf_cont(nmb
) = gbuf_cont(mb
);
90 } else if (nmb
== 0) {
91 if ((nmb
= gbuf_alloc(1, PRI_LO
)) == 0) {
98 sp
->sData
= 1; /* note that there is data to send */
99 if ((mb
= sp
->csbuf_mb
)) { /* add to the current message */
102 sp
->csbuf_mb
= nmb
; /* mark the buffer we are currently filling */
104 if ((mb
= sp
->sbuf_mb
)) {
105 while (gbuf_next(mb
))
107 gbuf_next(mb
) = sp
->csbuf_mb
; /* add the current item */
109 sp
->sbuf_mb
= sp
->csbuf_mb
;
110 sp
->csbuf_mb
= 0; /* if its done, no current buffer */
112 pb
->u
.ioParams
.actCount
+= cnt
; /* Update count field in param blk */
114 if (pb
->u
.ioParams
.actCount
== pb
->u
.ioParams
.reqCount
) {
115 /* Write is complete */
117 if (pb
->u
.ioParams
.flush
) /* flush the send Q? */
122 atalk_notify(sp
->gref
, EIO
);
127 } /* FillSendQueue */
133 * --> ccbRefNum refnum of connection end
134 * --> reqCount requested number of bytes to write
135 * --> dataPtr pointer to buffer for reading bytes into
136 * --> eom one if end-of-message, zero otherwise
139 * <-- actCount actual number of bytes written
142 * errRefNum bad connection refnum
143 * errState connection is not open
144 * errAborted request aborted by Remove or Close call
146 int adspWrite(sp
, pb
) /* (DSPPBPtr pb) */
152 pb
->ioResult
= errRefNum
;
153 return EINVAL
; /* no stream, so drop the message */
156 if (sp
->state
!= sOpen
) { /* Not allowed */
157 pb
->ioResult
= errState
;
158 atalk_notify(sp
->gref
, ENOTCONN
);
163 pb
->u
.ioParams
.actCount
= 0; /* Set # of bytes so far to zero */
165 FillSendQueue(sp
, pb
); /* Copy from write param block to send queue */
167 CheckSend(sp
); /* See if we should send anything */
177 register gbuf_t
*mp
, *tmp
;
178 unsigned char current
;
179 int current_valid
= 0;
183 if (mp
= sp
->sbuf_mb
) {
184 current
= *mp
->b_rptr
;
189 current
= CheckData(tmp
->b_rptr
, tmp
->b_wptr
- tmp
->b_rptr
,
196 if (mp
= sp
->csbuf_mb
) {
197 if (current_valid
== 0)
198 current
= *mp
->b_rptr
;
201 current
= CheckData(tmp
->b_rptr
, tmp
->b_wptr
- tmp
->b_rptr
,
209 int adsp_bad_block_count
;
210 char *adsp_bad_block
;
212 CheckData(block
, size
, current
)
217 register int anError
= 0;
220 for (i
= 0; i
< size
; i
++) {
221 if ((block
[i
] & 0xff) != (current
& 0xff)) {
223 adsp_bad_block
= block
;
231 adsp_bad_block_count
++;