1/* 2 * $Id: asp_write.c,v 1.4 2009-10-22 12:35:39 franklahm Exp $ 3 * 4 * Copyright (c) 1990,1991 Regents of The University of Michigan. 5 * All Rights Reserved. 6 * 7 * Permission to use, copy, modify, and distribute this software and 8 * its documentation for any purpose and without fee is hereby granted, 9 * provided that the above copyright notice appears in all copies and 10 * that both that copyright notice and this permission notice appear 11 * in supporting documentation, and that the name of The University 12 * of Michigan not be used in advertising or publicity pertaining to 13 * distribution of the software without specific, written prior 14 * permission. This software is supplied as is without expressed or 15 * implied warranties of any kind. 16 * 17 * Research Systems Unix Group 18 * The University of Michigan 19 * c/o Mike Clark 20 * 535 W. William Street 21 * Ann Arbor, Michigan 22 * +1-313-763-0525 23 * netatalk@itd.umich.edu 24 */ 25 26#ifdef HAVE_CONFIG_H 27#include "config.h" 28#endif /* HAVE_CONFIG_H */ 29 30#include <string.h> 31#include <sys/types.h> 32#include <sys/uio.h> 33#include <netatalk/endian.h> 34#include <netatalk/at.h> 35#include <atalk/atp.h> 36#include <atalk/asp.h> 37 38#if defined(BSD) || defined(BSD4_3) 39#define memmove(a, b, n) bcopy((b), (a), (n)) 40#endif /* BSD || BSD4_3 */ 41 42int asp_wrtcont(ASP asp, char *buf, size_t *buflen) 43{ 44 struct iovec iov[ ASP_MAXPACKETS ]; 45 struct atp_block atpb; 46 char *p; 47 int iovcnt = ASP_MAXPACKETS; 48 u_int16_t blen, seq; 49 u_int8_t oport; 50 51 p = buf; 52 *p++ = ASPFUNC_WRTCONT; 53 *p++ = asp->asp_sid; 54 seq = htons( asp->asp_seq ); 55 memcpy( p, &seq, sizeof(seq)); 56 p += sizeof(seq); 57 blen = htons(*buflen); 58 memcpy( p, &blen, sizeof(blen)); 59 p += sizeof(blen); 60 61 for ( iovcnt = 0; iovcnt < ASP_MAXPACKETS; iovcnt++ ) { 62 iov[iovcnt].iov_base = buf + iovcnt*ASP_CMDMAXSIZ; 63 iov[ iovcnt ].iov_len = ASP_CMDMAXSIZ; 64 } 65 66 oport = asp->asp_sat.sat_port; 67 atpb.atp_saddr = &asp->asp_sat; 68 atpb.atp_saddr->sat_port = asp->asp_wss; 69 atpb.atp_sreqdata = buf; 70 atpb.atp_sreqdlen = p - buf; 71 atpb.atp_sreqto = 2; 72 atpb.atp_sreqtries = 5; 73 74 if ( atp_sreq( asp->asp_atp, &atpb, iovcnt, ATP_XO ) < 0 ) { 75 asp->asp_sat.sat_port = oport; 76 return( -1 ); 77 } 78 asp->write_count += atpb.atp_sreqdlen; 79 80 atpb.atp_rresiov = iov; 81 atpb.atp_rresiovcnt = iovcnt; 82 if ( atp_rresp( asp->asp_atp, &atpb ) < 0 ) { 83 asp->asp_sat.sat_port = oport; 84 return( -1 ); 85 } 86 87 asp->asp_sat.sat_port = oport; 88 89 /* get rid of the 4-byte headers */ 90 p = buf; 91 for ( iovcnt = 0; iovcnt < atpb.atp_rresiovcnt; iovcnt++ ) { 92 memmove(p, (char *) iov[ iovcnt ].iov_base + ASP_HDRSIZ, 93 iov[ iovcnt ].iov_len - ASP_HDRSIZ ); 94 p += ( iov[ iovcnt ].iov_len - ASP_HDRSIZ ); 95 } 96 97 *buflen = p - buf; 98 asp->read_count += *buflen; 99 return 0; 100} 101