]> arthur.barton.de Git - netatalk.git/blob - libatalk/asp/asp_write.c
2c5aea39d59425920ee6131e4e5c09eab68c3b99
[netatalk.git] / libatalk / asp / asp_write.c
1 /*
2  * Copyright (c) 1990,1991 Regents of The University of Michigan.
3  * All Rights Reserved.
4  *
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.
14  *
15  *      Research Systems Unix Group
16  *      The University of Michigan
17  *      c/o Mike Clark
18  *      535 W. William Street
19  *      Ann Arbor, Michigan
20  *      +1-313-763-0525
21  *      netatalk@itd.umich.edu
22  */
23
24 #ifdef HAVE_CONFIG_H
25 #include "config.h"
26 #endif
27
28 #include <string.h>
29 #include <sys/types.h>
30 #include <sys/uio.h>
31 #include <netatalk/endian.h>
32 #include <netatalk/at.h>
33 #include <atalk/atp.h>
34 #include <atalk/asp.h>
35
36 #if defined(BSD) || defined(BSD4_3)
37 #define memmove(a, b, n)   bcopy((b), (a), (n))
38 #endif
39
40 int asp_wrtcont(ASP asp, char *buf, int *buflen)
41 {
42     struct iovec        iov[ ASP_MAXPACKETS ];
43     struct atp_block    atpb;
44     char                *p;
45     int                 iovcnt = ASP_MAXPACKETS;
46     u_int16_t           blen, seq;
47     u_int8_t            oport;
48
49     p = buf;
50     *p++ = ASPFUNC_WRTCONT;
51     *p++ = asp->asp_sid;
52     seq = htons( asp->asp_seq );
53     memcpy( p, &seq, sizeof(seq));
54     p += sizeof(seq);
55     blen = htons(*buflen);
56     memcpy( p, &blen, sizeof(blen));
57     p += sizeof(blen);
58
59     for ( iovcnt = 0; iovcnt < ASP_MAXPACKETS; iovcnt++ ) {
60         iov[iovcnt].iov_base = buf + iovcnt*ASP_CMDMAXSIZ;
61         iov[ iovcnt ].iov_len = ASP_CMDMAXSIZ;
62     }
63
64     oport = asp->asp_sat.sat_port;
65     atpb.atp_saddr = &asp->asp_sat;
66     atpb.atp_saddr->sat_port = asp->asp_wss;
67     atpb.atp_sreqdata = buf;
68     atpb.atp_sreqdlen = p - buf;
69     atpb.atp_sreqto = 2;
70     atpb.atp_sreqtries = 5;
71
72     if ( atp_sreq( asp->asp_atp, &atpb, iovcnt, ATP_XO ) < 0 ) {
73         asp->asp_sat.sat_port = oport;
74         return( -1 );
75     }
76     asp->write_count += atpb.atp_sreqdlen;
77
78     atpb.atp_rresiov = iov;
79     atpb.atp_rresiovcnt = iovcnt;
80     if ( atp_rresp( asp->asp_atp, &atpb ) < 0 ) {
81         asp->asp_sat.sat_port = oport;
82         return( -1 );
83     }
84
85     asp->asp_sat.sat_port = oport;
86
87     /* get rid of the 4-byte headers */
88     p = buf;
89     for ( iovcnt = 0; iovcnt < atpb.atp_rresiovcnt; iovcnt++ ) {
90         memmove(p, (char *) iov[ iovcnt ].iov_base + ASP_HDRSIZ, 
91                 iov[ iovcnt ].iov_len - ASP_HDRSIZ );
92         p += ( iov[ iovcnt ].iov_len - ASP_HDRSIZ );
93     }
94
95     *buflen = p - buf;
96     asp->read_count += *buflen;
97     return 0;
98 }