]> arthur.barton.de Git - netatalk.git/blob - libatalk/asp/asp_write.c
Initial revision
[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 #include <string.h>
25 #include <sys/types.h>
26 #include <sys/uio.h>
27 #include <netatalk/endian.h>
28 #include <netatalk/at.h>
29 #include <atalk/atp.h>
30 #include <atalk/asp.h>
31
32 #if defined(BSD) || defined(BSD4_3)
33 #define memmove(a, b, n)   bcopy((b), (a), (n))
34 #endif
35
36 int asp_wrtcont(ASP asp, char *buf, int *buflen)
37 {
38     struct iovec        iov[ ASP_MAXPACKETS ];
39     struct atp_block    atpb;
40     char                *p;
41     int                 iovcnt = ASP_MAXPACKETS;
42     u_int16_t           blen, seq;
43     u_int8_t            oport;
44
45     p = buf;
46     *p++ = ASPFUNC_WRTCONT;
47     *p++ = asp->asp_sid;
48     seq = htons( asp->asp_seq );
49     memcpy( p, &seq, sizeof(seq));
50     p += sizeof(seq);
51     blen = htons(*buflen);
52     memcpy( p, &blen, sizeof(blen));
53     p += sizeof(blen);
54
55     for ( iovcnt = 0; iovcnt < ASP_MAXPACKETS; iovcnt++ ) {
56         iov[iovcnt].iov_base = buf + iovcnt*ASP_CMDMAXSIZ;
57         iov[ iovcnt ].iov_len = ASP_CMDMAXSIZ;
58     }
59
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;
65     atpb.atp_sreqto = 2;
66     atpb.atp_sreqtries = 5;
67
68     if ( atp_sreq( asp->asp_atp, &atpb, iovcnt, ATP_XO ) < 0 ) {
69         asp->asp_sat.sat_port = oport;
70         return( -1 );
71     }
72     asp->write_count += atpb.atp_sreqdlen;
73
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;
78         return( -1 );
79     }
80
81     asp->asp_sat.sat_port = oport;
82
83     /* get rid of the 4-byte headers */
84     p = buf;
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 );
89     }
90
91     *buflen = p - buf;
92     asp->read_count += *buflen;
93     return 0;
94 }