2 * Copyright (c) 2008 David E. O'Brien
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of the author nor the names of its contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 #include <sys/cdefs.h>
31 __FBSDID("$FreeBSD$");
33 #include "opt_compat.h"
35 #include <sys/param.h>
37 #include <sys/fcntl.h>
38 #include <sys/filio.h>
40 #include <sys/ioccom.h>
41 #include <sys/mdioctl.h>
43 #include <sys/syscall.h>
44 #include <sys/syscallsubr.h>
45 #include <sys/sysctl.h>
46 #include <sys/sysent.h>
47 #include <sys/sysproto.h>
48 #include <sys/systm.h>
50 #include <compat/freebsd32/freebsd32.h>
51 #include <compat/freebsd32/freebsd32_ioctl.h>
52 #include <compat/freebsd32/freebsd32_proto.h>
54 /* Cannot get exact size in 64-bit due to alignment issue of entire struct. */
55 CTASSERT((sizeof(struct md_ioctl32)+4) == 436);
56 CTASSERT(sizeof(struct ioc_read_toc_entry32) == 8);
57 CTASSERT(sizeof(struct ioc_toc_header32) == 4);
61 freebsd32_ioctl_md(struct thread *td, struct freebsd32_ioctl_args *uap,
65 struct md_ioctl32 md32;
69 if (uap->data == NULL)
70 panic("%s: where is my ioctl data??", __func__);
71 if (uap->com & IOC_IN) {
72 if ((error = copyin(uap->data, &md32, sizeof(md32)))) {
76 CP(md32, mdv, md_version);
77 CP(md32, mdv, md_unit);
78 CP(md32, mdv, md_type);
79 PTRIN_CP(md32, mdv, md_file);
80 CP(md32, mdv, md_mediasize);
81 CP(md32, mdv, md_sectorsize);
82 CP(md32, mdv, md_options);
83 CP(md32, mdv, md_base);
84 CP(md32, mdv, md_fwheads);
85 CP(md32, mdv, md_fwsectors);
86 } else if (uap->com & IOC_OUT) {
88 * Zero the buffer so the user always
89 * gets back something deterministic.
91 bzero(&mdv, sizeof mdv);
108 panic("%s: unknown MDIOC %#x", __func__, uap->com);
110 error = fo_ioctl(fp, com, (caddr_t)&mdv, td->td_ucred, td);
111 if (error == 0 && (com & IOC_OUT)) {
112 CP(mdv, md32, md_version);
113 CP(mdv, md32, md_unit);
114 CP(mdv, md32, md_type);
115 PTROUT_CP(mdv, md32, md_file);
116 CP(mdv, md32, md_mediasize);
117 CP(mdv, md32, md_sectorsize);
118 CP(mdv, md32, md_options);
119 CP(mdv, md32, md_base);
120 CP(mdv, md32, md_fwheads);
121 CP(mdv, md32, md_fwsectors);
122 error = copyout(&md32, uap->data, sizeof(md32));
130 freebsd32_ioctl_ioc_toc_header(struct thread *td,
131 struct freebsd32_ioctl_args *uap, struct file *fp)
133 struct ioc_toc_header toch;
134 struct ioc_toc_header32 toch32;
137 if (uap->data == NULL)
138 panic("%s: where is my ioctl data??", __func__);
140 if ((error = copyin(uap->data, &toch32, sizeof(toch32))))
142 CP(toch32, toch, len);
143 CP(toch32, toch, starting_track);
144 CP(toch32, toch, ending_track);
145 error = fo_ioctl(fp, CDIOREADTOCHEADER, (caddr_t)&toch,
153 freebsd32_ioctl_ioc_read_toc(struct thread *td,
154 struct freebsd32_ioctl_args *uap, struct file *fp)
156 struct ioc_read_toc_entry toce;
157 struct ioc_read_toc_entry32 toce32;
160 if (uap->data == NULL)
161 panic("%s: where is my ioctl data??", __func__);
163 if ((error = copyin(uap->data, &toce32, sizeof(toce32))))
165 CP(toce32, toce, address_format);
166 CP(toce32, toce, starting_track);
167 CP(toce32, toce, data_len);
168 PTRIN_CP(toce32, toce, data);
170 if ((error = fo_ioctl(fp, CDIOREADTOCENTRYS, (caddr_t)&toce,
171 td->td_ucred, td))) {
172 CP(toce, toce32, address_format);
173 CP(toce, toce32, starting_track);
174 CP(toce, toce32, data_len);
175 PTROUT_CP(toce, toce32, data);
176 error = copyout(&toce32, uap->data, sizeof(toce32));
183 freebsd32_ioctl_fiodgname(struct thread *td,
184 struct freebsd32_ioctl_args *uap, struct file *fp)
186 struct fiodgname_arg fgn;
187 struct fiodgname_arg32 fgn32;
190 if ((error = copyin(uap->data, &fgn32, sizeof fgn32)) != 0)
193 PTRIN_CP(fgn32, fgn, buf);
194 error = fo_ioctl(fp, FIODGNAME, (caddr_t)&fgn, td->td_ucred, td);
200 freebsd32_ioctl(struct thread *td, struct freebsd32_ioctl_args *uap)
202 struct ioctl_args ap /*{
210 if ((error = fget(td, uap->fd, &fp)) != 0)
212 if ((fp->f_flag & (FREAD | FWRITE)) == 0) {
218 case MDIOCATTACH_32: /* FALLTHROUGH */
219 case MDIOCDETACH_32: /* FALLTHROUGH */
220 case MDIOCQUERY_32: /* FALLTHROUGH */
222 return freebsd32_ioctl_md(td, uap, fp);
224 case CDIOREADTOCENTRYS_32:
225 return freebsd32_ioctl_ioc_read_toc(td, uap, fp);
227 case CDIOREADTOCHEADER_32:
228 return freebsd32_ioctl_ioc_toc_header(td, uap, fp);
231 return freebsd32_ioctl_fiodgname(td, uap, fp);
237 PTRIN_CP(*uap, ap, data);
238 return ioctl(td, &ap);