rndpseudo_50.c revision 1.1.6.2 1 1.1.6.2 yamt /* $NetBSD: rndpseudo_50.c,v 1.1.6.2 2012/04/17 00:07:14 yamt Exp $ */
2 1.1.6.2 yamt
3 1.1.6.2 yamt /*-
4 1.1.6.2 yamt * Copyright (c) 1997-2011 The NetBSD Foundation, Inc.
5 1.1.6.2 yamt * All rights reserved.
6 1.1.6.2 yamt *
7 1.1.6.2 yamt * This code is derived from software contributed to The NetBSD Foundation
8 1.1.6.2 yamt * by Michael Graff <explorer (at) flame.org> and Thor Lancelot Simon.
9 1.1.6.2 yamt *
10 1.1.6.2 yamt * Redistribution and use in source and binary forms, with or without
11 1.1.6.2 yamt * modification, are permitted provided that the following conditions
12 1.1.6.2 yamt * are met:
13 1.1.6.2 yamt * 1. Redistributions of source code must retain the above copyright
14 1.1.6.2 yamt * notice, this list of conditions and the following disclaimer.
15 1.1.6.2 yamt * 2. Redistributions in binary form must reproduce the above copyright
16 1.1.6.2 yamt * notice, this list of conditions and the following disclaimer in the
17 1.1.6.2 yamt * documentation and/or other materials provided with the distribution.
18 1.1.6.2 yamt *
19 1.1.6.2 yamt * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 1.1.6.2 yamt * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 1.1.6.2 yamt * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 1.1.6.2 yamt * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 1.1.6.2 yamt * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 1.1.6.2 yamt * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 1.1.6.2 yamt * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 1.1.6.2 yamt * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 1.1.6.2 yamt * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 1.1.6.2 yamt * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 1.1.6.2 yamt * POSSIBILITY OF SUCH DAMAGE.
30 1.1.6.2 yamt */
31 1.1.6.2 yamt
32 1.1.6.2 yamt #include <sys/cdefs.h>
33 1.1.6.2 yamt __KERNEL_RCSID(0, "$NetBSD: rndpseudo_50.c,v 1.1.6.2 2012/04/17 00:07:14 yamt Exp $");
34 1.1.6.2 yamt
35 1.1.6.2 yamt #if defined(_KERNEL_OPT)
36 1.1.6.2 yamt #include "opt_compat_netbsd.h"
37 1.1.6.2 yamt #include "opt_compat_netbsd32.h"
38 1.1.6.2 yamt #endif
39 1.1.6.2 yamt
40 1.1.6.2 yamt #include <sys/param.h>
41 1.1.6.2 yamt #include <sys/file.h>
42 1.1.6.2 yamt
43 1.1.6.2 yamt #include <sys/rnd.h>
44 1.1.6.2 yamt #include <compat/sys/rnd.h>
45 1.1.6.2 yamt
46 1.1.6.2 yamt /*
47 1.1.6.2 yamt * Convert from rndsource_t to rndsource50_t, for the results from
48 1.1.6.2 yamt * RNDGETNUM50 and RNDGETNAME50.
49 1.1.6.2 yamt */
50 1.1.6.2 yamt static void
51 1.1.6.2 yamt rndsource_to_rndsource50(rndsource_t *r, rndsource50_t *r50)
52 1.1.6.2 yamt {
53 1.1.6.2 yamt memset(r50, 0, sizeof(*r50));
54 1.1.6.2 yamt strlcpy(r50->name, r->name, sizeof(r50->name));
55 1.1.6.2 yamt r50->total = r->total;
56 1.1.6.2 yamt r50->type = r->type;
57 1.1.6.2 yamt r50->flags = r->flags;
58 1.1.6.2 yamt }
59 1.1.6.2 yamt
60 1.1.6.2 yamt #ifdef COMPAT_NETBSD32
61 1.1.6.2 yamt /*
62 1.1.6.2 yamt * Convert from rndsource_t to rndsource50_32_t, for the results from
63 1.1.6.2 yamt * RNDGETNUM50_32 and RNDGETNAME50_32.
64 1.1.6.2 yamt */
65 1.1.6.2 yamt static void
66 1.1.6.2 yamt rndsource_to_rndsource50_32(rndsource_t *r, rndsource50_32_t *r50_32)
67 1.1.6.2 yamt {
68 1.1.6.2 yamt memset(r50_32, 0, sizeof(*r50_32));
69 1.1.6.2 yamt strlcpy(r50_32->name, r->name, sizeof(r50_32->name));
70 1.1.6.2 yamt r50_32->total = r->total;
71 1.1.6.2 yamt r50_32->type = r->type;
72 1.1.6.2 yamt r50_32->flags = r->flags;
73 1.1.6.2 yamt }
74 1.1.6.2 yamt #endif /* COMPAT_NETBSD32 */
75 1.1.6.2 yamt
76 1.1.6.2 yamt /*
77 1.1.6.2 yamt * COMPAT_50 handling for rnd_ioctl. This is called from rnd_ioctl.
78 1.1.6.2 yamt *
79 1.1.6.2 yamt * It also handles the case of (COMPAT_50 && COMPAT_NETBSD32).
80 1.1.6.2 yamt */
81 1.1.6.2 yamt int
82 1.1.6.2 yamt compat_50_rnd_ioctl(struct file *fp, u_long cmd, void *addr)
83 1.1.6.2 yamt {
84 1.1.6.2 yamt int ret = 0;
85 1.1.6.2 yamt
86 1.1.6.2 yamt switch (cmd) {
87 1.1.6.2 yamt
88 1.1.6.2 yamt case RNDGETSRCNUM50:
89 1.1.6.2 yamt {
90 1.1.6.2 yamt rndstat_t rstbuf = {.start = 0};
91 1.1.6.2 yamt rndstat50_t *rst50 = (rndstat50_t *)addr;
92 1.1.6.2 yamt int count;
93 1.1.6.2 yamt
94 1.1.6.2 yamt if (rst50->count > RND_MAXSTATCOUNT50)
95 1.1.6.2 yamt return EINVAL;
96 1.1.6.2 yamt
97 1.1.6.2 yamt rstbuf.start = rst50->start;
98 1.1.6.2 yamt rstbuf.count = rst50->count;
99 1.1.6.2 yamt
100 1.1.6.2 yamt ret = (fp->f_ops->fo_ioctl)(fp, RNDGETSRCNUM, &rstbuf);
101 1.1.6.2 yamt if (ret != 0)
102 1.1.6.2 yamt return ret;
103 1.1.6.2 yamt
104 1.1.6.2 yamt for (count = 0; count < rst50->count; count++) {
105 1.1.6.2 yamt rndsource_to_rndsource50(&rstbuf.source[count],
106 1.1.6.2 yamt &rst50->source[count]);
107 1.1.6.2 yamt }
108 1.1.6.2 yamt rst50->count = rstbuf.count;
109 1.1.6.2 yamt
110 1.1.6.2 yamt break;
111 1.1.6.2 yamt }
112 1.1.6.2 yamt
113 1.1.6.2 yamt #ifdef COMPAT_NETBSD32
114 1.1.6.2 yamt case RNDGETSRCNUM50_32:
115 1.1.6.2 yamt {
116 1.1.6.2 yamt rndstat_t rstbuf = {.start = 0};
117 1.1.6.2 yamt rndstat50_32_t *rst50_32 = (rndstat50_32_t *)addr;
118 1.1.6.2 yamt int count;
119 1.1.6.2 yamt
120 1.1.6.2 yamt if (rst50_32->count > RND_MAXSTATCOUNT50)
121 1.1.6.2 yamt return (EINVAL);
122 1.1.6.2 yamt
123 1.1.6.2 yamt rstbuf.start = rst50_32->start;
124 1.1.6.2 yamt rstbuf.count = rst50_32->count;
125 1.1.6.2 yamt
126 1.1.6.2 yamt ret = (fp->f_ops->fo_ioctl)(fp, RNDGETSRCNUM, &rstbuf);
127 1.1.6.2 yamt if (ret != 0)
128 1.1.6.2 yamt return ret;
129 1.1.6.2 yamt
130 1.1.6.2 yamt for (count = 0; count < rst50_32->count; count++) {
131 1.1.6.2 yamt rndsource_to_rndsource50_32(&rstbuf.source[count],
132 1.1.6.2 yamt &rst50_32->source[count]);
133 1.1.6.2 yamt }
134 1.1.6.2 yamt rst50_32->count = rstbuf.count;
135 1.1.6.2 yamt
136 1.1.6.2 yamt break;
137 1.1.6.2 yamt }
138 1.1.6.2 yamt #endif /* COMPAT_NETBSD32 */
139 1.1.6.2 yamt
140 1.1.6.2 yamt case RNDGETSRCNAME50:
141 1.1.6.2 yamt {
142 1.1.6.2 yamt rndstat_name_t rstnmbuf = {.name[0] = 0};
143 1.1.6.2 yamt rndstat_name50_t *rstnm50;
144 1.1.6.2 yamt rstnm50 = (rndstat_name50_t *)addr;
145 1.1.6.2 yamt
146 1.1.6.2 yamt strlcpy(rstnmbuf.name, rstnm50->name, sizeof(rstnmbuf.name));
147 1.1.6.2 yamt
148 1.1.6.2 yamt ret = (fp->f_ops->fo_ioctl)(fp, RNDGETSRCNAME, &rstnmbuf);
149 1.1.6.2 yamt if (ret != 0)
150 1.1.6.2 yamt return ret;
151 1.1.6.2 yamt
152 1.1.6.2 yamt rndsource_to_rndsource50(&rstnmbuf.source, &rstnm50->source);
153 1.1.6.2 yamt
154 1.1.6.2 yamt break;
155 1.1.6.2 yamt }
156 1.1.6.2 yamt
157 1.1.6.2 yamt #ifdef COMPAT_NETBSD32
158 1.1.6.2 yamt case RNDGETSRCNAME50_32:
159 1.1.6.2 yamt {
160 1.1.6.2 yamt rndstat_name_t rstnmbuf = {.name[0] = 0};
161 1.1.6.2 yamt rndstat_name50_32_t *rstnm50_32;
162 1.1.6.2 yamt rstnm50_32 = (rndstat_name50_32_t *)addr;
163 1.1.6.2 yamt
164 1.1.6.2 yamt strlcpy(rstnmbuf.name, rstnm50_32->name, sizeof(rstnmbuf.name));
165 1.1.6.2 yamt
166 1.1.6.2 yamt ret = (fp->f_ops->fo_ioctl)(fp, RNDGETSRCNAME, &rstnmbuf);
167 1.1.6.2 yamt if (ret != 0)
168 1.1.6.2 yamt return ret;
169 1.1.6.2 yamt
170 1.1.6.2 yamt rndsource_to_rndsource50_32(&rstnmbuf.source,
171 1.1.6.2 yamt &rstnm50_32->source);
172 1.1.6.2 yamt
173 1.1.6.2 yamt break;
174 1.1.6.2 yamt }
175 1.1.6.2 yamt #endif
176 1.1.6.2 yamt
177 1.1.6.2 yamt default:
178 1.1.6.2 yamt return ENOTTY;
179 1.1.6.2 yamt }
180 1.1.6.2 yamt
181 1.1.6.2 yamt return ret;
182 1.1.6.2 yamt }
183