Deleted Added
full compact
linux_ioctl.c (125997) linux_ioctl.c (130453)
1/*
2 * Copyright (c) 1994-1995 S�ren Schmidt
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 13 unchanged lines hidden (view full) ---

22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29#include <sys/cdefs.h>
1/*
2 * Copyright (c) 1994-1995 S�ren Schmidt
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 13 unchanged lines hidden (view full) ---

22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29#include <sys/cdefs.h>
30__FBSDID("$FreeBSD: head/sys/compat/linux/linux_ioctl.c 125997 2004-02-19 12:38:12Z bms $");
30__FBSDID("$FreeBSD: head/sys/compat/linux/linux_ioctl.c 130453 2004-06-14 07:26:23Z phk $");
31
32#include <sys/param.h>
33#include <sys/systm.h>
34#include <sys/sysproto.h>
35#include <sys/cdio.h>
36#include <sys/dvdio.h>
37#include <sys/conf.h>
38#include <sys/disk.h>

--- 5 unchanged lines hidden (view full) ---

44#include <sys/filio.h>
45#include <sys/kbio.h>
46#include <sys/linker_set.h>
47#include <sys/malloc.h>
48#include <sys/proc.h>
49#include <sys/socket.h>
50#include <sys/sockio.h>
51#include <sys/soundcard.h>
31
32#include <sys/param.h>
33#include <sys/systm.h>
34#include <sys/sysproto.h>
35#include <sys/cdio.h>
36#include <sys/dvdio.h>
37#include <sys/conf.h>
38#include <sys/disk.h>

--- 5 unchanged lines hidden (view full) ---

44#include <sys/filio.h>
45#include <sys/kbio.h>
46#include <sys/linker_set.h>
47#include <sys/malloc.h>
48#include <sys/proc.h>
49#include <sys/socket.h>
50#include <sys/sockio.h>
51#include <sys/soundcard.h>
52#include <sys/stdint.h>
52#include <sys/tty.h>
53#include <sys/uio.h>
54#include <net/if.h>
55#include <net/if_dl.h>
56#include <net/if_types.h>
57
58#include <machine/../linux/linux.h>
59#include <machine/../linux/linux_proto.h>
60
61#include <compat/linux/linux_ioctl.h>
62#include <compat/linux/linux_mib.h>
63#include <compat/linux/linux_util.h>
64
65static linux_ioctl_function_t linux_ioctl_cdrom;
66static linux_ioctl_function_t linux_ioctl_vfat;
67static linux_ioctl_function_t linux_ioctl_console;
53#include <sys/tty.h>
54#include <sys/uio.h>
55#include <net/if.h>
56#include <net/if_dl.h>
57#include <net/if_types.h>
58
59#include <machine/../linux/linux.h>
60#include <machine/../linux/linux_proto.h>
61
62#include <compat/linux/linux_ioctl.h>
63#include <compat/linux/linux_mib.h>
64#include <compat/linux/linux_util.h>
65
66static linux_ioctl_function_t linux_ioctl_cdrom;
67static linux_ioctl_function_t linux_ioctl_vfat;
68static linux_ioctl_function_t linux_ioctl_console;
69static linux_ioctl_function_t linux_ioctl_hdio;
68static linux_ioctl_function_t linux_ioctl_disk;
69static linux_ioctl_function_t linux_ioctl_socket;
70static linux_ioctl_function_t linux_ioctl_sound;
71static linux_ioctl_function_t linux_ioctl_termio;
72static linux_ioctl_function_t linux_ioctl_private;
73static linux_ioctl_function_t linux_ioctl_drm;
74static linux_ioctl_function_t linux_ioctl_special;
75
76static struct linux_ioctl_handler cdrom_handler =
77{ linux_ioctl_cdrom, LINUX_IOCTL_CDROM_MIN, LINUX_IOCTL_CDROM_MAX };
78static struct linux_ioctl_handler vfat_handler =
79{ linux_ioctl_vfat, LINUX_IOCTL_VFAT_MIN, LINUX_IOCTL_VFAT_MAX };
80static struct linux_ioctl_handler console_handler =
81{ linux_ioctl_console, LINUX_IOCTL_CONSOLE_MIN, LINUX_IOCTL_CONSOLE_MAX };
70static linux_ioctl_function_t linux_ioctl_disk;
71static linux_ioctl_function_t linux_ioctl_socket;
72static linux_ioctl_function_t linux_ioctl_sound;
73static linux_ioctl_function_t linux_ioctl_termio;
74static linux_ioctl_function_t linux_ioctl_private;
75static linux_ioctl_function_t linux_ioctl_drm;
76static linux_ioctl_function_t linux_ioctl_special;
77
78static struct linux_ioctl_handler cdrom_handler =
79{ linux_ioctl_cdrom, LINUX_IOCTL_CDROM_MIN, LINUX_IOCTL_CDROM_MAX };
80static struct linux_ioctl_handler vfat_handler =
81{ linux_ioctl_vfat, LINUX_IOCTL_VFAT_MIN, LINUX_IOCTL_VFAT_MAX };
82static struct linux_ioctl_handler console_handler =
83{ linux_ioctl_console, LINUX_IOCTL_CONSOLE_MIN, LINUX_IOCTL_CONSOLE_MAX };
84static struct linux_ioctl_handler hdio_handler =
85{ linux_ioctl_hdio, LINUX_IOCTL_HDIO_MIN, LINUX_IOCTL_HDIO_MAX };
82static struct linux_ioctl_handler disk_handler =
83{ linux_ioctl_disk, LINUX_IOCTL_DISK_MIN, LINUX_IOCTL_DISK_MAX };
84static struct linux_ioctl_handler socket_handler =
85{ linux_ioctl_socket, LINUX_IOCTL_SOCKET_MIN, LINUX_IOCTL_SOCKET_MAX };
86static struct linux_ioctl_handler sound_handler =
87{ linux_ioctl_sound, LINUX_IOCTL_SOUND_MIN, LINUX_IOCTL_SOUND_MAX };
88static struct linux_ioctl_handler termio_handler =
89{ linux_ioctl_termio, LINUX_IOCTL_TERMIO_MIN, LINUX_IOCTL_TERMIO_MAX };
90static struct linux_ioctl_handler private_handler =
91{ linux_ioctl_private, LINUX_IOCTL_PRIVATE_MIN, LINUX_IOCTL_PRIVATE_MAX };
92static struct linux_ioctl_handler drm_handler =
93{ linux_ioctl_drm, LINUX_IOCTL_DRM_MIN, LINUX_IOCTL_DRM_MAX };
94
95DATA_SET(linux_ioctl_handler_set, cdrom_handler);
96DATA_SET(linux_ioctl_handler_set, vfat_handler);
97DATA_SET(linux_ioctl_handler_set, console_handler);
86static struct linux_ioctl_handler disk_handler =
87{ linux_ioctl_disk, LINUX_IOCTL_DISK_MIN, LINUX_IOCTL_DISK_MAX };
88static struct linux_ioctl_handler socket_handler =
89{ linux_ioctl_socket, LINUX_IOCTL_SOCKET_MIN, LINUX_IOCTL_SOCKET_MAX };
90static struct linux_ioctl_handler sound_handler =
91{ linux_ioctl_sound, LINUX_IOCTL_SOUND_MIN, LINUX_IOCTL_SOUND_MAX };
92static struct linux_ioctl_handler termio_handler =
93{ linux_ioctl_termio, LINUX_IOCTL_TERMIO_MIN, LINUX_IOCTL_TERMIO_MAX };
94static struct linux_ioctl_handler private_handler =
95{ linux_ioctl_private, LINUX_IOCTL_PRIVATE_MIN, LINUX_IOCTL_PRIVATE_MAX };
96static struct linux_ioctl_handler drm_handler =
97{ linux_ioctl_drm, LINUX_IOCTL_DRM_MIN, LINUX_IOCTL_DRM_MAX };
98
99DATA_SET(linux_ioctl_handler_set, cdrom_handler);
100DATA_SET(linux_ioctl_handler_set, vfat_handler);
101DATA_SET(linux_ioctl_handler_set, console_handler);
102DATA_SET(linux_ioctl_handler_set, hdio_handler);
98DATA_SET(linux_ioctl_handler_set, disk_handler);
99DATA_SET(linux_ioctl_handler_set, socket_handler);
100DATA_SET(linux_ioctl_handler_set, sound_handler);
101DATA_SET(linux_ioctl_handler_set, termio_handler);
102DATA_SET(linux_ioctl_handler_set, private_handler);
103DATA_SET(linux_ioctl_handler_set, drm_handler);
104
105struct handler_element
106{
107 TAILQ_ENTRY(handler_element) list;
108 int (*func)(struct thread *, struct linux_ioctl_args *);
109 int low, high, span;
110};
111
112static TAILQ_HEAD(, handler_element) handlers =
113 TAILQ_HEAD_INITIALIZER(handlers);
114
103DATA_SET(linux_ioctl_handler_set, disk_handler);
104DATA_SET(linux_ioctl_handler_set, socket_handler);
105DATA_SET(linux_ioctl_handler_set, sound_handler);
106DATA_SET(linux_ioctl_handler_set, termio_handler);
107DATA_SET(linux_ioctl_handler_set, private_handler);
108DATA_SET(linux_ioctl_handler_set, drm_handler);
109
110struct handler_element
111{
112 TAILQ_ENTRY(handler_element) list;
113 int (*func)(struct thread *, struct linux_ioctl_args *);
114 int low, high, span;
115};
116
117static TAILQ_HEAD(, handler_element) handlers =
118 TAILQ_HEAD_INITIALIZER(handlers);
119
120/*
121 * hdio related ioctls for VMWare support
122 */
123
124struct linux_hd_geometry {
125 u_int8_t heads;
126 u_int8_t sectors;
127 u_int16_t cylinders;
128 u_int32_t start;
129};
130
131struct linux_hd_big_geometry {
132 u_int8_t heads;
133 u_int8_t sectors;
134 u_int32_t cylinders;
135 u_int32_t start;
136};
137
115static int
138static int
139linux_ioctl_hdio(struct thread *td, struct linux_ioctl_args *args)
140{
141 struct file *fp;
142 int error;
143 u_int sectorsize, fwcylinders, fwheads, fwsectors;
144 off_t mediasize, bytespercyl;
145
146 if ((error = fget(td, args->fd, &fp)) != 0)
147 return (error);
148 switch (args->cmd & 0xffff) {
149 case LINUX_HDIO_GET_GEO:
150 case LINUX_HDIO_GET_GEO_BIG:
151 error = fo_ioctl(fp, DIOCGMEDIASIZE,
152 (caddr_t)&mediasize, td->td_ucred, td);
153 if (!error)
154 error = fo_ioctl(fp, DIOCGSECTORSIZE,
155 (caddr_t)&sectorsize, td->td_ucred, td);
156 if (!error)
157 error = fo_ioctl(fp, DIOCGFWHEADS,
158 (caddr_t)&fwheads, td->td_ucred, td);
159 if (!error)
160 error = fo_ioctl(fp, DIOCGFWSECTORS,
161 (caddr_t)&fwsectors, td->td_ucred, td);
162 /*
163 * XXX: DIOCGFIRSTOFFSET is not yet implemented, so
164 * so pretend that GEOM always says 0. This is NOT VALID
165 * for slices or partitions, only the per-disk raw devices.
166 */
167
168 fdrop(fp, td);
169 if (error)
170 return (error);
171 /*
172 * 1. Calculate the number of bytes in a cylinder,
173 * given the firmware's notion of heads and sectors
174 * per cylinder.
175 * 2. Calculate the number of cylinders, given the total
176 * size of the media.
177 * All internal calculations should have 64-bit precision.
178 */
179 bytespercyl = (off_t) sectorsize * fwheads * fwsectors;
180 fwcylinders = mediasize / bytespercyl;
181#if defined(DEBUG)
182 linux_msg(td, "HDIO_GET_GEO: mediasize %jd, c/h/s %d/%d/%d, "
183 "bpc %jd",
184 (intmax_t)mediasize, fwcylinders, fwheads, fwsectors,
185 (intmax_t)bytespercyl);
186#endif
187 if ((args->cmd & 0xffff) == LINUX_HDIO_GET_GEO) {
188 struct linux_hd_geometry hdg;
189
190 hdg.cylinders = fwcylinders;
191 hdg.heads = fwheads;
192 hdg.sectors = fwsectors;
193 hdg.start = 0;
194 error = copyout(&hdg, (void *)args->arg, sizeof(hdg));
195 } else if ((args->cmd & 0xffff) == LINUX_HDIO_GET_GEO_BIG) {
196 struct linux_hd_big_geometry hdbg;
197
198 hdbg.cylinders = fwcylinders;
199 hdbg.heads = fwheads;
200 hdbg.sectors = fwsectors;
201 hdbg.start = 0;
202 error = copyout(&hdbg, (void *)args->arg, sizeof(hdbg));
203 }
204 return (error);
205 break;
206 default:
207 /* XXX */
208 linux_msg(td,
209 "ioctl fd=%d, cmd=0x%x ('%c',%d) is not implemented",
210 args->fd, (int)(args->cmd & 0xffff),
211 (int)(args->cmd & 0xff00) >> 8,
212 (int)(args->cmd & 0xff));
213 break;
214 }
215 fdrop(fp, td);
216 return (ENOIOCTL);
217}
218
219static int
116linux_ioctl_disk(struct thread *td, struct linux_ioctl_args *args)
117{
118 struct file *fp;
119 int error;
120 u_int sectorsize;
121 off_t mediasize;
122
123 if ((error = fget(td, args->fd, &fp)) != 0)

--- 9 unchanged lines hidden (view full) ---

133 if (error)
134 return (error);
135 sectorsize = mediasize / sectorsize;
136 /*
137 * XXX: How do we know we return the right size of integer ?
138 */
139 return (copyout(&sectorsize, (void *)args->arg,
140 sizeof(sectorsize)));
220linux_ioctl_disk(struct thread *td, struct linux_ioctl_args *args)
221{
222 struct file *fp;
223 int error;
224 u_int sectorsize;
225 off_t mediasize;
226
227 if ((error = fget(td, args->fd, &fp)) != 0)

--- 9 unchanged lines hidden (view full) ---

237 if (error)
238 return (error);
239 sectorsize = mediasize / sectorsize;
240 /*
241 * XXX: How do we know we return the right size of integer ?
242 */
243 return (copyout(&sectorsize, (void *)args->arg,
244 sizeof(sectorsize)));
245 break;
141 }
142 fdrop(fp, td);
143 return (ENOIOCTL);
144}
145
146/*
147 * termio related ioctls
148 */

--- 2309 unchanged lines hidden ---
246 }
247 fdrop(fp, td);
248 return (ENOIOCTL);
249}
250
251/*
252 * termio related ioctls
253 */

--- 2309 unchanged lines hidden ---