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->com & IOC_IN) {
70 if ((error = copyin(uap->data, &md32, sizeof(md32)))) {
73 CP(md32, mdv, md_version);
74 CP(md32, mdv, md_unit);
75 CP(md32, mdv, md_type);
76 PTRIN_CP(md32, mdv, md_file);
77 CP(md32, mdv, md_mediasize);
78 CP(md32, mdv, md_sectorsize);
79 CP(md32, mdv, md_options);
80 CP(md32, mdv, md_base);
81 CP(md32, mdv, md_fwheads);
82 CP(md32, mdv, md_fwsectors);
83 } else if (uap->com & IOC_OUT) {
85 * Zero the buffer so the user always
86 * gets back something deterministic.
88 bzero(&mdv, sizeof mdv);
105 panic("%s: unknown MDIOC %#x", __func__, uap->com);
107 error = fo_ioctl(fp, com, (caddr_t)&mdv, td->td_ucred, td);
108 if (error == 0 && (com & IOC_OUT)) {
109 CP(mdv, md32, md_version);
110 CP(mdv, md32, md_unit);
111 CP(mdv, md32, md_type);
112 PTROUT_CP(mdv, md32, md_file);
113 CP(mdv, md32, md_mediasize);
114 CP(mdv, md32, md_sectorsize);
115 CP(mdv, md32, md_options);
116 CP(mdv, md32, md_base);
117 CP(mdv, md32, md_fwheads);
118 CP(mdv, md32, md_fwsectors);
119 error = copyout(&md32, uap->data, sizeof(md32));
126 freebsd32_ioctl_ioc_toc_header(struct thread *td,
127 struct freebsd32_ioctl_args *uap, struct file *fp)
129 struct ioc_toc_header toch;
130 struct ioc_toc_header32 toch32;
133 if ((error = copyin(uap->data, &toch32, sizeof(toch32))))
135 CP(toch32, toch, len);
136 CP(toch32, toch, starting_track);
137 CP(toch32, toch, ending_track);
138 error = fo_ioctl(fp, CDIOREADTOCHEADER, (caddr_t)&toch,
145 freebsd32_ioctl_ioc_read_toc(struct thread *td,
146 struct freebsd32_ioctl_args *uap, struct file *fp)
148 struct ioc_read_toc_entry toce;
149 struct ioc_read_toc_entry32 toce32;
152 if ((error = copyin(uap->data, &toce32, sizeof(toce32))))
154 CP(toce32, toce, address_format);
155 CP(toce32, toce, starting_track);
156 CP(toce32, toce, data_len);
157 PTRIN_CP(toce32, toce, data);
159 if ((error = fo_ioctl(fp, CDIOREADTOCENTRYS, (caddr_t)&toce,
160 td->td_ucred, td))) {
161 CP(toce, toce32, address_format);
162 CP(toce, toce32, starting_track);
163 CP(toce, toce32, data_len);
164 PTROUT_CP(toce, toce32, data);
165 error = copyout(&toce32, uap->data, sizeof(toce32));
171 freebsd32_ioctl_fiodgname(struct thread *td,
172 struct freebsd32_ioctl_args *uap, struct file *fp)
174 struct fiodgname_arg fgn;
175 struct fiodgname_arg32 fgn32;
178 if ((error = copyin(uap->data, &fgn32, sizeof fgn32)) != 0)
181 PTRIN_CP(fgn32, fgn, buf);
182 error = fo_ioctl(fp, FIODGNAME, (caddr_t)&fgn, td->td_ucred, td);
187 freebsd32_ioctl(struct thread *td, struct freebsd32_ioctl_args *uap)
189 struct ioctl_args ap /*{
197 if ((error = fget(td, uap->fd, &fp)) != 0)
199 if ((fp->f_flag & (FREAD | FWRITE)) == 0) {
205 case MDIOCATTACH_32: /* FALLTHROUGH */
206 case MDIOCDETACH_32: /* FALLTHROUGH */
207 case MDIOCQUERY_32: /* FALLTHROUGH */
209 error = freebsd32_ioctl_md(td, uap, fp);
212 case CDIOREADTOCENTRYS_32:
213 error = freebsd32_ioctl_ioc_read_toc(td, uap, fp);
216 case CDIOREADTOCHEADER_32:
217 error = freebsd32_ioctl_ioc_toc_header(td, uap, fp);
221 error = freebsd32_ioctl_fiodgname(td, uap, fp);
228 PTRIN_CP(*uap, ap, data);
229 return ioctl(td, &ap);