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