2 * Copyright (c) 1990,1991 Regents of The University of Michigan.
5 * Permission to use, copy, modify, and distribute this software and
6 * its documentation for any purpose and without fee is hereby granted,
7 * provided that the above copyright notice appears in all copies and
8 * that both that copyright notice and this permission notice appear
9 * in supporting documentation, and that the name of The University
10 * of Michigan not be used in advertising or publicity pertaining to
11 * distribution of the software without specific, written prior
12 * permission. This software is supplied as is without expressed or
13 * implied warranties of any kind.
15 * Research Systems Unix Group
16 * The University of Michigan
18 * 535 W. William Street
21 * netatalk@itd.umich.edu
25 #include <sys/types.h>
27 #include <netatalk/endian.h>
28 #include <netatalk/at.h>
29 #include <atalk/atp.h>
30 #include <atalk/asp.h>
32 #if defined(BSD) || defined(BSD4_3)
33 #define memmove(a, b, n) bcopy((b), (a), (n))
36 int asp_wrtcont(ASP asp, char *buf, int *buflen)
38 struct iovec iov[ ASP_MAXPACKETS ];
39 struct atp_block atpb;
41 int iovcnt = ASP_MAXPACKETS;
46 *p++ = ASPFUNC_WRTCONT;
48 seq = htons( asp->asp_seq );
49 memcpy( p, &seq, sizeof(seq));
51 blen = htons(*buflen);
52 memcpy( p, &blen, sizeof(blen));
55 for ( iovcnt = 0; iovcnt < ASP_MAXPACKETS; iovcnt++ ) {
56 iov[iovcnt].iov_base = buf + iovcnt*ASP_CMDMAXSIZ;
57 iov[ iovcnt ].iov_len = ASP_CMDMAXSIZ;
60 oport = asp->asp_sat.sat_port;
61 atpb.atp_saddr = &asp->asp_sat;
62 atpb.atp_saddr->sat_port = asp->asp_wss;
63 atpb.atp_sreqdata = buf;
64 atpb.atp_sreqdlen = p - buf;
66 atpb.atp_sreqtries = 5;
68 if ( atp_sreq( asp->asp_atp, &atpb, iovcnt, ATP_XO ) < 0 ) {
69 asp->asp_sat.sat_port = oport;
72 asp->write_count += atpb.atp_sreqdlen;
74 atpb.atp_rresiov = iov;
75 atpb.atp_rresiovcnt = iovcnt;
76 if ( atp_rresp( asp->asp_atp, &atpb ) < 0 ) {
77 asp->asp_sat.sat_port = oport;
81 asp->asp_sat.sat_port = oport;
83 /* get rid of the 4-byte headers */
85 for ( iovcnt = 0; iovcnt < atpb.atp_rresiovcnt; iovcnt++ ) {
86 memmove(p, (char *) iov[ iovcnt ].iov_base + ASP_HDRSIZ,
87 iov[ iovcnt ].iov_len - ASP_HDRSIZ );
88 p += ( iov[ iovcnt ].iov_len - ASP_HDRSIZ );
92 asp->read_count += *buflen;