2 * Copyright (c) 2007 The DragonFly Project. All rights reserved.
4 * This code is derived from software contributed to The DragonFly Project
5 * by Matthew Dillon <dillon@backplane.com>
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * 3. Neither the name of The DragonFly Project nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific, prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
29 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
31 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * $DragonFly: src/test/syslink/test2.c,v 1.1 2007/06/29 17:18:42 dillon Exp $
36 #include <sys/types.h>
37 #include <sys/syslink.h>
38 #include <sys/syslink_msg.h>
45 static void reader(int fd
);
46 static void writer(int fd
);
51 main(int ac
, char **av
)
53 union syslink_info_all info
;
57 bzero(&info
, sizeof(info
));
58 if (syslink(SYSLINK_CMD_NEW
, &info
.head
, sizeof(info
)) < 0) {
62 printf("fds %d %d\n", info
.cmd_new
.fds
[0], info
.cmd_new
.fds
[1]);
64 reader(info
.cmd_new
.fds
[0]);
66 writer(info
.cmd_new
.fds
[1]);
68 while (wait(NULL
) > 0)
77 union syslink_small_msg cmd
;
78 union syslink_small_msg rep
;
84 dmabuf
= mmap(NULL
, BUFSIZE
, PROT_READ
|PROT_WRITE
, MAP_ANON
, -1, 0);
86 bzero(&cmd
, sizeof(cmd
));
87 cmd
.msg
.sm_bytes
= sizeof(struct syslink_msg
);
88 cmd
.msg
.sm_proto
= SMPROTO_BSDVFS
;
90 cmd
.msg
.sm_head
.se_cmd
= 0 | SE_CMDF_DMAR
| SE_CMDF_DMAW
;
91 cmd
.msg
.sm_head
.se_bytes
= sizeof(cmd
.msg
.sm_head
);
97 iov
[0].iov_base
= (char *)&cmd
;
98 iov
[0].iov_len
= cmd
.msg
.sm_bytes
;
99 iov
[1].iov_base
= (char *)dmabuf
;
100 iov
[1].iov_len
= BUFSIZE
;
106 /*printf("write n = %d dmabuf[0] = %d\n", n, dmabuf[0]);*/
107 n
= writev(fd
, iov
, 2);
109 if (bytes
% (1024 * 1024 * 1024) == 0) {
110 printf("%lld\r", bytes
);
114 printf("write error %s\n", strerror(errno
));
115 } else if (waitforit
) {
116 /* fake up a pipeline */
119 n
= read(fd
, &rep
, sizeof(rep
));
120 /*printf("read-reply %d %lld dmabuf[0] = %d\n",
121 n, rep.msg.sm_msgid, dmabuf[0]);*/
131 union syslink_small_msg cmd
;
132 union syslink_small_msg rep
;
136 dmabuf
= mmap(NULL
, BUFSIZE
, PROT_READ
|PROT_WRITE
, MAP_ANON
, -1, 0);
138 bzero(&rep
, sizeof(rep
));
139 rep
.msg
.sm_bytes
= sizeof(struct syslink_msg
);
140 rep
.msg
.sm_proto
= SMPROTO_BSDVFS
| SM_PROTO_REPLY
;
141 rep
.msg
.sm_head
.se_cmd
= SE_CMDF_REPLY
;
142 rep
.msg
.sm_head
.se_bytes
= sizeof(rep
.msg
.sm_head
);
147 iov
[0].iov_base
= (char *)&cmd
;
148 iov
[0].iov_len
= sizeof(cmd
);
149 iov
[1].iov_base
= (char *)dmabuf
;
150 iov
[1].iov_len
= BUFSIZE
;
152 n
= readv(fd
, iov
, 2);
153 if (n
< 0 && errno
== ENOSPC
) {
154 printf("no space\n");
158 printf("read error %s\n", strerror(errno
));
160 /*printf("read n = %d dmabuf[0] = %d [4095] = %d\n",
161 n, dmabuf[0], dmabuf[4095]);*/
162 rep
.msg
.sm_msgid
= cmd
.msg
.sm_msgid
;
163 dmabuf
[0] = -dmabuf
[0];
164 iov
[0].iov_base
= (char *)&rep
;
165 iov
[0].iov_len
= rep
.msg
.sm_bytes
;
166 /*n = write(fd, &rep, rep.msg.sm_bytes);*/
167 n
= writev(fd
, iov
, 2);
169 printf("reply error %s\n", strerror(errno
));