2 * $Id: asp_write.c,v 1.4 2009-10-22 12:35:39 franklahm Exp $
4 * Copyright (c) 1990,1991 Regents of The University of Michigan.
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.
17 * Research Systems Unix Group
18 * The University of Michigan
20 * 535 W. William Street
23 * netatalk@itd.umich.edu
28 #endif /* HAVE_CONFIG_H */
31 #include <sys/types.h>
33 #include <netatalk/endian.h>
34 #include <netatalk/at.h>
35 #include <atalk/atp.h>
36 #include <atalk/asp.h>
38 #if defined(BSD) || defined(BSD4_3)
39 #define memmove(a, b, n) bcopy((b), (a), (n))
40 #endif /* BSD || BSD4_3 */
42 int asp_wrtcont(ASP asp, char *buf, size_t *buflen)
44 struct iovec iov[ ASP_MAXPACKETS ];
45 struct atp_block atpb;
47 int iovcnt = ASP_MAXPACKETS;
52 *p++ = ASPFUNC_WRTCONT;
54 seq = htons( asp->asp_seq );
55 memcpy( p, &seq, sizeof(seq));
57 blen = htons(*buflen);
58 memcpy( p, &blen, sizeof(blen));
61 for ( iovcnt = 0; iovcnt < ASP_MAXPACKETS; iovcnt++ ) {
62 iov[iovcnt].iov_base = buf + iovcnt*ASP_CMDMAXSIZ;
63 iov[ iovcnt ].iov_len = ASP_CMDMAXSIZ;
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;
72 atpb.atp_sreqtries = 5;
74 if ( atp_sreq( asp->asp_atp, &atpb, iovcnt, ATP_XO ) < 0 ) {
75 asp->asp_sat.sat_port = oport;
78 asp->write_count += atpb.atp_sreqdlen;
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;
87 asp->asp_sat.sat_port = oport;
89 /* get rid of the 4-byte headers */
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 );
98 asp->read_count += *buflen;