Home | History | Annotate | Line # | Download | only in netbsd32
netbsd32_ioctl.c revision 1.77
      1 /*	$NetBSD: netbsd32_ioctl.c,v 1.77 2015/05/31 22:19:41 roy Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1998, 2001 Matthew R. Green
      5  * All rights reserved.
      6  *
      7  * Redistribution and use in source and binary forms, with or without
      8  * modification, are permitted provided that the following conditions
      9  * are met:
     10  * 1. Redistributions of source code must retain the above copyright
     11  *    notice, this list of conditions and the following disclaimer.
     12  * 2. Redistributions in binary form must reproduce the above copyright
     13  *    notice, this list of conditions and the following disclaimer in the
     14  *    documentation and/or other materials provided with the distribution.
     15  *
     16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     17  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     18  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     19  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     20  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
     21  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
     22  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
     23  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
     24  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     25  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     26  * SUCH DAMAGE.
     27  */
     28 
     29 /*
     30  * handle ioctl conversions from netbsd32 -> 64-bit kernel
     31  */
     32 
     33 #include <sys/cdefs.h>
     34 __KERNEL_RCSID(0, "$NetBSD: netbsd32_ioctl.c,v 1.77 2015/05/31 22:19:41 roy Exp $");
     35 
     36 #include "pppoe.h"
     37 #include "sppp.h"
     38 
     39 #include <sys/param.h>
     40 #include <sys/systm.h>
     41 #include <sys/filedesc.h>
     42 #include <sys/ioctl.h>
     43 #include <sys/file.h>
     44 #include <sys/proc.h>
     45 #include <sys/socketvar.h>
     46 #include <sys/audioio.h>
     47 #include <sys/disklabel.h>
     48 #include <sys/dkio.h>
     49 #include <sys/ataio.h>
     50 #include <sys/sockio.h>
     51 #include <sys/socket.h>
     52 #include <sys/ttycom.h>
     53 #include <sys/mount.h>
     54 #include <sys/syscallargs.h>
     55 #include <sys/ktrace.h>
     56 #include <sys/kmem.h>
     57 #include <sys/envsys.h>
     58 #include <sys/wdog.h>
     59 #include <sys/clockctl.h>
     60 #include <sys/exec_elf.h>
     61 #include <sys/ksyms.h>
     62 
     63 #ifdef __sparc__
     64 #include <dev/sun/fbio.h>
     65 #include <machine/openpromio.h>
     66 #endif
     67 
     68 #include <net/if.h>
     69 #include <net/route.h>
     70 
     71 #if NPPPOE > 0
     72 #include <net/if_pppoe.h>
     73 #endif
     74 #if NSPPP > 0
     75 #include <net/if_sppp.h>
     76 #endif
     77 
     78 #include <net/bpf.h>
     79 #include <netinet/in.h>
     80 #include <netinet/in_var.h>
     81 #include <netinet/igmp.h>
     82 #include <netinet/igmp_var.h>
     83 #include <netinet/ip_mroute.h>
     84 
     85 #include <compat/sys/sockio.h>
     86 
     87 #include <compat/netbsd32/netbsd32.h>
     88 #include <compat/netbsd32/netbsd32_ioctl.h>
     89 #include <compat/netbsd32/netbsd32_syscallargs.h>
     90 
     91 #include <dev/vndvar.h>
     92 
     93 /* convert to/from different structures */
     94 
     95 static inline void
     96 netbsd32_to_partinfo(struct netbsd32_partinfo *s32p, struct partinfo *p, u_long cmd)
     97 {
     98 
     99 	p->disklab = (struct disklabel *)NETBSD32PTR64(s32p->disklab);
    100 	p->part = (struct partition *)NETBSD32PTR64(s32p->part);
    101 }
    102 
    103 #if 0
    104 static inline void
    105 netbsd32_to_format_op(struct netbsd32_format_op *s32p, struct format_op *p, u_long cmd)
    106 {
    107 
    108 	p->df_buf = (char *)NETBSD32PTR64(s32p->df_buf);
    109 	p->df_count = s32p->df_count;
    110 	p->df_startblk = s32p->df_startblk;
    111 	memcpy(p->df_reg, s32p->df_reg, sizeof(s32p->df_reg));
    112 }
    113 #endif
    114 
    115 static inline void
    116 netbsd32_to_ifreq(struct netbsd32_ifreq *s32p, struct ifreq *p, u_long cmd)
    117 {
    118 
    119 	memcpy(p, s32p, sizeof *s32p);
    120 	/*
    121 	 * XXX
    122 	 * struct ifreq says the same, but sometimes the ifr_data
    123 	 * union member needs to be converted to 64 bits... this
    124 	 * is very driver specific and so we ignore it for now..
    125 	 */
    126 	if (cmd == SIOCGIFDATA || cmd == SIOCZIFDATA)
    127 		p->ifr_data = (void *)NETBSD32PTR64(s32p->ifr_data);
    128 }
    129 
    130 static inline void
    131 netbsd32_to_oifreq(struct netbsd32_oifreq *s32p, struct oifreq *p, u_long cmd)
    132 {
    133 
    134 	memcpy(p, s32p, sizeof *s32p);
    135 	/*
    136 	 * XXX
    137 	 * struct ifreq says the same, but sometimes the ifr_data
    138 	 * union member needs to be converted to 64 bits... this
    139 	 * is very driver specific and so we ignore it for now..
    140 	 */
    141 	if (cmd == SIOCGIFDATA || cmd == SIOCZIFDATA)
    142 		p->ifr_data = (void *)NETBSD32PTR64(s32p->ifr_data);
    143 }
    144 
    145 static inline void
    146 netbsd32_to_if_addrprefreq(const struct netbsd32_if_addrprefreq *ifap32,
    147 	struct if_addrprefreq *ifap, u_long cmd)
    148 {
    149 	strlcpy(ifap->ifap_name, ifap32->ifap_name, sizeof(ifap->ifap_name));
    150 	ifap->ifap_preference = ifap32->ifap_preference;
    151 	memcpy(&ifap->ifap_addr, &ifap32->ifap_addr,
    152 	    max(ifap32->ifap_addr.ss_len, _SS_MAXSIZE));
    153 }
    154 
    155 static inline void
    156 netbsd32_to_ifconf(struct netbsd32_ifconf *s32p, struct ifconf *p, u_long cmd)
    157 {
    158 
    159 	p->ifc_len = s32p->ifc_len;
    160 	/* ifc_buf & ifc_req are the same size so this works */
    161 	p->ifc_buf = (void *)NETBSD32PTR64(s32p->ifc_buf);
    162 }
    163 
    164 static inline void
    165 netbsd32_to_ifmediareq(struct netbsd32_ifmediareq *s32p, struct ifmediareq *p, u_long cmd)
    166 {
    167 
    168 	memcpy(p, s32p, sizeof *s32p);
    169 	p->ifm_ulist = (int *)NETBSD32PTR64(s32p->ifm_ulist);
    170 }
    171 
    172 #if NPPPOE > 0
    173 static inline void
    174 netbsd32_to_pppoediscparms(struct netbsd32_pppoediscparms *s32p,
    175     struct pppoediscparms *p, u_long cmd)
    176 {
    177 
    178 	memcpy(p->ifname, s32p->ifname, sizeof p->ifname);
    179 	memcpy(p->eth_ifname, s32p->eth_ifname, sizeof p->eth_ifname);
    180 	p->ac_name = (char *)NETBSD32PTR64(s32p->ac_name);
    181 	p->ac_name_len = s32p->ac_name_len;
    182 	p->service_name = (char *)NETBSD32PTR64(s32p->service_name);
    183 	p->service_name_len = s32p->service_name_len;
    184 }
    185 #endif
    186 
    187 #if NSPPP > 0
    188 static inline void
    189 netbsd32_to_spppauthcfg(struct netbsd32_spppauthcfg *s32p,
    190     struct spppauthcfg *p, u_long cmd)
    191 {
    192 
    193 	memcpy(p->ifname, s32p->ifname, sizeof p->ifname);
    194 	p->hisauth = s32p->hisauth;
    195 	p->myauth = s32p->myauth;
    196 	p->myname_length = s32p->myname_length;
    197 	p->mysecret_length = s32p->mysecret_length;
    198 	p->hisname_length = s32p->hisname_length;
    199 	p->hissecret_length = s32p->hissecret_length;
    200 	p->myauthflags = s32p->myauthflags;
    201 	p->hisauthflags = s32p->hisauthflags;
    202 	p->myname = (char *)NETBSD32PTR64(s32p->myname);
    203 	p->mysecret = (char *)NETBSD32PTR64(s32p->mysecret);
    204 	p->hisname = (char *)NETBSD32PTR64(s32p->hisname);
    205 	p->hissecret = (char *)NETBSD32PTR64(s32p->hissecret);
    206 }
    207 #endif
    208 
    209 static inline void
    210 netbsd32_to_ifdrv(struct netbsd32_ifdrv *s32p, struct ifdrv *p, u_long cmd)
    211 {
    212 
    213 	memcpy(p->ifd_name, s32p->ifd_name, sizeof p->ifd_name);
    214 	p->ifd_cmd = s32p->ifd_cmd;
    215 	p->ifd_len = s32p->ifd_len;
    216 	p->ifd_data = (void *)NETBSD32PTR64(s32p->ifd_data);
    217 }
    218 
    219 static inline void
    220 netbsd32_to_sioc_vif_req(struct netbsd32_sioc_vif_req *s32p, struct sioc_vif_req *p, u_long cmd)
    221 {
    222 
    223 	p->vifi = s32p->vifi;
    224 	p->icount = (u_long)s32p->icount;
    225 	p->ocount = (u_long)s32p->ocount;
    226 	p->ibytes = (u_long)s32p->ibytes;
    227 	p->obytes = (u_long)s32p->obytes;
    228 }
    229 
    230 static inline void
    231 netbsd32_to_sioc_sg_req(struct netbsd32_sioc_sg_req *s32p, struct sioc_sg_req *p, u_long cmd)
    232 {
    233 
    234 	p->src = s32p->src;
    235 	p->grp = s32p->grp;
    236 	p->pktcnt = (u_long)s32p->pktcnt;
    237 	p->bytecnt = (u_long)s32p->bytecnt;
    238 	p->wrong_if = (u_long)s32p->wrong_if;
    239 }
    240 
    241 static inline void
    242 netbsd32_to_atareq(struct netbsd32_atareq *s32p, struct atareq *p, u_long cmd)
    243 {
    244 	p->flags = (u_long)s32p->flags;
    245 	p->command = s32p->command;
    246 	p->features = s32p->features;
    247 	p->sec_count = s32p->sec_count;
    248 	p->sec_num = s32p->sec_num;
    249 	p->head = s32p->head;
    250 	p->cylinder = s32p->cylinder;
    251 	p->databuf =  (char *)NETBSD32PTR64(s32p->databuf);
    252 	p->datalen = (u_long)s32p->datalen;
    253 	p->timeout = s32p->timeout;
    254 	p->retsts = s32p->retsts;
    255 	p->error = s32p->error;
    256 }
    257 
    258 static inline void
    259 netbsd32_to_vnd_ioctl(struct netbsd32_vnd_ioctl *s32p, struct vnd_ioctl *p, u_long cmd)
    260 {
    261 
    262 	p->vnd_file = (char *)NETBSD32PTR64(s32p->vnd_file);
    263 	p->vnd_flags = s32p->vnd_flags;
    264 	p->vnd_geom = s32p->vnd_geom;
    265 	p->vnd_osize = s32p->vnd_osize;
    266 	p->vnd_size = s32p->vnd_size;
    267 }
    268 
    269 static inline void
    270 netbsd32_to_vnd_user(struct netbsd32_vnd_user *s32p, struct vnd_user *p, u_long cmd)
    271 {
    272 
    273 	p->vnu_unit = s32p->vnu_unit;
    274 	p->vnu_dev = s32p->vnu_dev;
    275 	p->vnu_ino = s32p->vnu_ino;
    276 }
    277 
    278 static inline void
    279 netbsd32_to_vnd_ioctl50(struct netbsd32_vnd_ioctl50 *s32p, struct vnd_ioctl50 *p, u_long cmd)
    280 {
    281 
    282 	p->vnd_file = (char *)NETBSD32PTR64(s32p->vnd_file);
    283 	p->vnd_flags = s32p->vnd_flags;
    284 	p->vnd_geom = s32p->vnd_geom;
    285 	p->vnd_size = s32p->vnd_size;
    286 }
    287 
    288 static inline void
    289 netbsd32_to_plistref(struct netbsd32_plistref *s32p, struct plistref *p, u_long cmd)
    290 {
    291 
    292 	p->pref_plist = NETBSD32PTR64(s32p->pref_plist);
    293 	p->pref_len = s32p->pref_len;
    294 }
    295 
    296 static inline void
    297 netbsd32_to_u_long(netbsd32_u_long *s32p, u_long *p, u_long cmd)
    298 {
    299 
    300 	*p = (u_long)*s32p;
    301 }
    302 
    303 static inline void
    304 netbsd32_to_wdog_conf(struct netbsd32_wdog_conf *s32p, struct wdog_conf *p, u_long cmd)
    305 {
    306 
    307 	p->wc_names = (char *)NETBSD32PTR64(s32p->wc_names);
    308 	p->wc_count = s32p->wc_count;
    309 }
    310 
    311 static inline void
    312 netbsd32_to_bpf_program(struct netbsd32_bpf_program *s32p, struct bpf_program *p, u_long cmd)
    313 {
    314 
    315 	p->bf_insns = (void *)NETBSD32PTR64(s32p->bf_insns);
    316 	p->bf_len = s32p->bf_len;
    317 }
    318 
    319 static inline void
    320 netbsd32_to_bpf_dltlist(struct netbsd32_bpf_dltlist *s32p, struct bpf_dltlist *p, u_long cmd)
    321 {
    322 
    323 	p->bfl_list = (void *)NETBSD32PTR64(s32p->bfl_list);
    324 	p->bfl_len = s32p->bfl_len;
    325 }
    326 
    327 /* wsdisplay stuff */
    328 static inline void
    329 netbsd32_to_wsdisplay_addscreendata(struct netbsd32_wsdisplay_addscreendata *asd32,
    330 					       struct wsdisplay_addscreendata *asd,
    331 					       u_long cmd)
    332 {
    333 	asd->screentype = (char *)NETBSD32PTR64(asd32->screentype);
    334 	asd->emul = (char *)NETBSD32PTR64(asd32->emul);
    335 	asd->idx = asd32->idx;
    336 }
    337 
    338 static inline void
    339 netbsd32_to_ieee80211req(struct netbsd32_ieee80211req *ireq32,
    340 			 struct ieee80211req *ireq, u_long cmd)
    341 {
    342 	strncpy(ireq->i_name, ireq32->i_name, IFNAMSIZ);
    343 	ireq->i_type = ireq32->i_type;
    344 	ireq->i_val = ireq32->i_val;
    345 	ireq->i_len = ireq32->i_len;
    346 	ireq->i_data = NETBSD32PTR64(ireq32->i_data);
    347 }
    348 
    349 static inline void
    350 netbsd32_to_ieee80211_nwkey(struct netbsd32_ieee80211_nwkey *nwk32,
    351 					       struct ieee80211_nwkey *nwk,
    352 					       u_long cmd)
    353 {
    354 	int i;
    355 
    356 	strncpy(nwk->i_name, nwk32->i_name, IFNAMSIZ);
    357 	nwk->i_wepon = nwk32->i_wepon;
    358 	nwk->i_defkid = nwk32->i_defkid;
    359 	for (i = 0; i < IEEE80211_WEP_NKID; i++) {
    360 		nwk->i_key[i].i_keylen = nwk32->i_key[i].i_keylen;
    361 		nwk->i_key[i].i_keydat =
    362 		    NETBSD32PTR64(nwk32->i_key[i].i_keydat);
    363 	}
    364 }
    365 
    366 static inline void
    367 netbsd32_to_wsdisplay_cursor(struct netbsd32_wsdisplay_cursor *c32,
    368 					       struct wsdisplay_cursor *c,
    369 					       u_long cmd)
    370 {
    371 	c->which = c32->which;
    372 	c->enable = c32->enable;
    373 	c->pos.x = c32->pos.x;
    374 	c->pos.y = c32->pos.y;
    375 	c->hot.x = c32->hot.x;
    376 	c->hot.y = c32->hot.y;
    377 	c->size.x = c32->size.x;
    378 	c->size.y = c32->size.y;
    379 	c->cmap.index = c32->cmap.index;
    380 	c->cmap.count = c32->cmap.count;
    381 	c->cmap.red = NETBSD32PTR64(c32->cmap.red);
    382 	c->cmap.green = NETBSD32PTR64(c32->cmap.green);
    383 	c->cmap.blue = NETBSD32PTR64(c32->cmap.blue);
    384 	c->image = NETBSD32PTR64(c32->image);
    385 	c->mask = NETBSD32PTR64(c32->mask);
    386 }
    387 
    388 static inline void
    389 netbsd32_to_wsdisplay_cmap(struct netbsd32_wsdisplay_cmap *c32,
    390 					       struct wsdisplay_cmap *c,
    391 					       u_long cmd)
    392 {
    393 	c->index = c32->index;
    394 	c->count = c32->count;
    395 	c->red   = NETBSD32PTR64(c32->red);
    396 	c->green = NETBSD32PTR64(c32->green);
    397 	c->blue  = NETBSD32PTR64(c32->blue);
    398 }
    399 
    400 static inline void
    401 netbsd32_to_clockctl_settimeofday(
    402     const struct netbsd32_clockctl_settimeofday *s32p,
    403     struct clockctl_settimeofday *p,
    404     u_long cmd)
    405 {
    406 
    407 	p->tv = NETBSD32PTR64(s32p->tv);
    408 	p->tzp = NETBSD32PTR64(s32p->tzp);
    409 }
    410 
    411 static inline void
    412 netbsd32_to_clockctl_adjtime(
    413     const struct netbsd32_clockctl_adjtime *s32p,
    414     struct clockctl_adjtime *p,
    415     u_long cmd)
    416 {
    417 
    418 	p->delta = NETBSD32PTR64(s32p->delta);
    419 	p->olddelta = NETBSD32PTR64(s32p->olddelta);
    420 }
    421 
    422 static inline void
    423 netbsd32_to_clockctl_clock_settime(
    424     const struct netbsd32_clockctl_clock_settime *s32p,
    425     struct clockctl_clock_settime *p,
    426     u_long cmd)
    427 {
    428 
    429 	p->clock_id = s32p->clock_id;
    430 	p->tp = NETBSD32PTR64(s32p->tp);
    431 }
    432 
    433 static inline void
    434 netbsd32_to_clockctl_ntp_adjtime(
    435     const struct netbsd32_clockctl_ntp_adjtime *s32p,
    436     struct clockctl_ntp_adjtime *p,
    437     u_long cmd)
    438 {
    439 
    440 	p->tp = NETBSD32PTR64(s32p->tp);
    441 	p->retval = s32p->retval;
    442 }
    443 
    444 static inline void
    445 netbsd32_to_ksyms_gsymbol(
    446     const struct netbsd32_ksyms_gsymbol *s32p,
    447     struct ksyms_gsymbol *p,
    448     u_long cmd)
    449 {
    450 
    451 	p->kg_name = NETBSD32PTR64(s32p->kg_name);
    452 }
    453 
    454 static inline void
    455 netbsd32_to_ksyms_gvalue(
    456     const struct netbsd32_ksyms_gvalue *s32p,
    457     struct ksyms_gvalue *p,
    458     u_long cmd)
    459 {
    460 
    461 	p->kv_name = NETBSD32PTR64(s32p->kv_name);
    462 }
    463 
    464 /*
    465  * handle ioctl conversions from 64-bit kernel -> netbsd32
    466  */
    467 
    468 static inline void
    469 netbsd32_from_partinfo(struct partinfo *p, struct netbsd32_partinfo *s32p, u_long cmd)
    470 {
    471 
    472 	NETBSD32PTR32(s32p->disklab, p->disklab);
    473 	NETBSD32PTR32(s32p->part, p->part);
    474 }
    475 
    476 #if 0
    477 static inline void
    478 netbsd32_from_format_op(struct format_op *p, struct netbsd32_format_op *s32p, u_long cmd)
    479 {
    480 
    481 /* filled in */
    482 #if 0
    483 	s32p->df_buf = (netbsd32_charp)p->df_buf;
    484 #endif
    485 	s32p->df_count = p->df_count;
    486 	s32p->df_startblk = p->df_startblk;
    487 	memcpy(s32p->df_reg, p->df_reg, sizeof(p->df_reg));
    488 }
    489 #endif
    490 
    491 static inline void
    492 netbsd32_from_ifreq(struct ifreq *p, struct netbsd32_ifreq *s32p, u_long cmd)
    493 {
    494 
    495 	/*
    496 	 * XXX
    497 	 * struct ifreq says the same, but sometimes the ifr_data
    498 	 * union member needs to be converted to 64 bits... this
    499 	 * is very driver specific and so we ignore it for now..
    500 	 */
    501 	memcpy(s32p, p, sizeof *s32p);
    502 	if (cmd == SIOCGIFDATA || cmd == SIOCZIFDATA)
    503 		NETBSD32PTR32(s32p->ifr_data, p->ifr_data);
    504 }
    505 
    506 static inline void
    507 netbsd32_from_oifreq(struct oifreq *p, struct netbsd32_oifreq *s32p, u_long cmd)
    508 {
    509 
    510 	/*
    511 	 * XXX
    512 	 * struct ifreq says the same, but sometimes the ifr_data
    513 	 * union member needs to be converted to 64 bits... this
    514 	 * is very driver specific and so we ignore it for now..
    515 	 */
    516 	memcpy(s32p, p, sizeof *s32p);
    517 	if (cmd == SIOCGIFDATA || cmd == SIOCZIFDATA)
    518 		NETBSD32PTR32(s32p->ifr_data, p->ifr_data);
    519 }
    520 
    521 static inline void
    522 netbsd32_from_if_addrprefreq(const struct if_addrprefreq *ifap,
    523 	struct netbsd32_if_addrprefreq *ifap32, u_long cmd)
    524 {
    525 	strlcpy(ifap32->ifap_name, ifap->ifap_name, sizeof(ifap32->ifap_name));
    526 	ifap32->ifap_preference = ifap->ifap_preference;
    527 	memcpy(&ifap32->ifap_addr, &ifap->ifap_addr,
    528 	    max(ifap->ifap_addr.ss_len, _SS_MAXSIZE));
    529 }
    530 
    531 static inline void
    532 netbsd32_from_ifconf(struct ifconf *p, struct netbsd32_ifconf *s32p, u_long cmd)
    533 {
    534 
    535 	s32p->ifc_len = p->ifc_len;
    536 	/* ifc_buf & ifc_req are the same size so this works */
    537 	NETBSD32PTR32(s32p->ifc_buf, p->ifc_buf);
    538 }
    539 
    540 static inline void
    541 netbsd32_from_ifmediareq(struct ifmediareq *p, struct netbsd32_ifmediareq *s32p, u_long cmd)
    542 {
    543 
    544 	memcpy(s32p, p, sizeof *p);
    545 /* filled in? */
    546 #if 0
    547 	s32p->ifm_ulist = (netbsd32_intp_t)p->ifm_ulist;
    548 #endif
    549 }
    550 
    551 #if NPPPOE > 0
    552 static inline void
    553 netbsd32_from_pppoediscparms(struct pppoediscparms *p,
    554     struct netbsd32_pppoediscparms *s32p, u_long cmd)
    555 {
    556 
    557 	memcpy(s32p->ifname, p->ifname, sizeof s32p->ifname);
    558 	memcpy(s32p->eth_ifname, p->eth_ifname, sizeof s32p->eth_ifname);
    559 	NETBSD32PTR32(s32p->ac_name, p->ac_name);
    560 	s32p->ac_name_len = p->ac_name_len;
    561 	NETBSD32PTR32(s32p->service_name, p->service_name);
    562 	s32p->service_name_len = p->service_name_len;
    563 }
    564 #endif
    565 
    566 #if NSPPP > 0
    567 static inline void
    568 netbsd32_from_spppauthcfg(struct spppauthcfg *p,
    569     struct netbsd32_spppauthcfg *s32p, u_long cmd)
    570 {
    571 
    572 	memcpy(s32p->ifname, p->ifname, sizeof s32p->ifname);
    573 	s32p->hisauth = p->hisauth;
    574 	s32p->myauth = p->myauth;
    575 	s32p->myname_length = p->myname_length;
    576 	s32p->mysecret_length = p->mysecret_length;
    577 	s32p->hisname_length = p->hisname_length;
    578 	s32p->hissecret_length = p->hissecret_length;
    579 	s32p->myauthflags = p->myauthflags;
    580 	s32p->hisauthflags = p->hisauthflags;
    581 	NETBSD32PTR32(s32p->myname, p->myname);
    582 	NETBSD32PTR32(s32p->mysecret, p->mysecret);
    583 	NETBSD32PTR32(s32p->hisname, p->hisname);
    584 	NETBSD32PTR32(s32p->hissecret, p->hissecret);
    585 }
    586 #endif
    587 
    588 static inline void
    589 netbsd32_from_ifdrv(struct ifdrv *p, struct netbsd32_ifdrv *s32p, u_long cmd)
    590 {
    591 
    592 	memcpy(s32p->ifd_name, p->ifd_name, sizeof s32p->ifd_name);
    593 	s32p->ifd_cmd = p->ifd_cmd;
    594 	s32p->ifd_len = p->ifd_len;
    595 	NETBSD32PTR32(s32p->ifd_data, p->ifd_data);
    596 }
    597 
    598 static inline void
    599 netbsd32_from_sioc_vif_req(struct sioc_vif_req *p, struct netbsd32_sioc_vif_req *s32p, u_long cmd)
    600 {
    601 
    602 	s32p->vifi = p->vifi;
    603 	s32p->icount = (netbsd32_u_long)p->icount;
    604 	s32p->ocount = (netbsd32_u_long)p->ocount;
    605 	s32p->ibytes = (netbsd32_u_long)p->ibytes;
    606 	s32p->obytes = (netbsd32_u_long)p->obytes;
    607 }
    608 
    609 static inline void
    610 netbsd32_from_sioc_sg_req(struct sioc_sg_req *p, struct netbsd32_sioc_sg_req *s32p, u_long cmd)
    611 {
    612 
    613 	s32p->src = p->src;
    614 	s32p->grp = p->grp;
    615 	s32p->pktcnt = (netbsd32_u_long)p->pktcnt;
    616 	s32p->bytecnt = (netbsd32_u_long)p->bytecnt;
    617 	s32p->wrong_if = (netbsd32_u_long)p->wrong_if;
    618 }
    619 
    620 static inline void
    621 netbsd32_from_atareq(struct atareq *p, struct netbsd32_atareq *s32p, u_long cmd)
    622 {
    623 	s32p->flags = (netbsd32_u_long)p->flags;
    624 	s32p->command = p->command;
    625 	s32p->features = p->features;
    626 	s32p->sec_count = p->sec_count;
    627 	s32p->sec_num = p->sec_num;
    628 	s32p->head = p->head;
    629 	s32p->cylinder = p->cylinder;
    630 	NETBSD32PTR32(s32p->databuf, p->databuf);
    631 	s32p->datalen = (netbsd32_u_long)p->datalen;
    632 	s32p->timeout = p->timeout;
    633 	s32p->retsts = p->retsts;
    634 	s32p->error = p->error;
    635 }
    636 
    637 static inline void
    638 netbsd32_from_vnd_ioctl(struct vnd_ioctl *p, struct netbsd32_vnd_ioctl *s32p, u_long cmd)
    639 {
    640 
    641 	s32p->vnd_flags = p->vnd_flags;
    642 	s32p->vnd_geom = p->vnd_geom;
    643 	s32p->vnd_osize = p->vnd_osize;
    644 	s32p->vnd_size = p->vnd_size;
    645 }
    646 
    647 static inline void
    648 netbsd32_from_vnd_user(struct vnd_user *p, struct netbsd32_vnd_user *s32p, u_long cmd)
    649 {
    650 
    651 	s32p->vnu_unit = p->vnu_unit;
    652 	s32p->vnu_dev = p->vnu_dev;
    653 	s32p->vnu_ino = p->vnu_ino;
    654 }
    655 
    656 static inline void
    657 netbsd32_from_vnd_ioctl50(struct vnd_ioctl50 *p, struct netbsd32_vnd_ioctl50 *s32p, u_long cmd)
    658 {
    659 
    660 	s32p->vnd_flags = p->vnd_flags;
    661 	s32p->vnd_geom = p->vnd_geom;
    662 	s32p->vnd_size = p->vnd_size;
    663 }
    664 
    665 static inline void
    666 netbsd32_from_plistref(struct plistref *p, struct netbsd32_plistref *s32p, u_long cmd)
    667 {
    668 
    669 	NETBSD32PTR32(s32p->pref_plist, p->pref_plist);
    670 	s32p->pref_len = p->pref_len;
    671 }
    672 
    673 static inline void
    674 netbsd32_from_wdog_conf(struct wdog_conf *p, struct netbsd32_wdog_conf *s32p, u_long cmd)
    675 {
    676 
    677 	NETBSD32PTR32(s32p->wc_names, p->wc_names);
    678 	s32p->wc_count = p->wc_count;
    679 }
    680 
    681 /* wsdisplay stuff */
    682 static inline void
    683 netbsd32_from_wsdisplay_addscreendata(struct wsdisplay_addscreendata *asd,
    684 					struct netbsd32_wsdisplay_addscreendata *asd32,
    685 					u_long cmd)
    686 {
    687 	NETBSD32PTR32(asd32->screentype, asd->screentype);
    688 	NETBSD32PTR32(asd32->emul, asd->emul);
    689 	asd32->idx = asd->idx;
    690 }
    691 
    692 static inline void
    693 netbsd32_from_wsdisplay_cursor(struct wsdisplay_cursor *c,
    694 					       struct netbsd32_wsdisplay_cursor *c32,
    695 					       u_long cmd)
    696 {
    697 	c32->which = c->which;
    698 	c32->enable = c->enable;
    699 	c32->pos.x = c->pos.x;
    700 	c32->pos.y = c->pos.y;
    701 	c32->hot.x = c->hot.x;
    702 	c32->hot.y = c->hot.y;
    703 	c32->size.x = c->size.x;
    704 	c32->size.y = c->size.y;
    705 	c32->cmap.index = c->cmap.index;
    706 	c32->cmap.count = c->cmap.count;
    707 	NETBSD32PTR32(c32->cmap.red, c->cmap.red);
    708 	NETBSD32PTR32(c32->cmap.green, c->cmap.green);
    709 	NETBSD32PTR32(c32->cmap.blue, c->cmap.blue);
    710 	NETBSD32PTR32(c32->image, c->image);
    711 	NETBSD32PTR32(c32->mask, c->mask);
    712 }
    713 
    714 static inline void
    715 netbsd32_from_wsdisplay_cmap(struct wsdisplay_cmap *c,
    716 					   struct netbsd32_wsdisplay_cmap *c32,
    717 					   u_long cmd)
    718 {
    719 	c32->index = c->index;
    720 	c32->count = c->count;
    721 	NETBSD32PTR32(c32->red, c->red);
    722 	NETBSD32PTR32(c32->green, c->green);
    723 	NETBSD32PTR32(c32->blue, c->blue);
    724 }
    725 
    726 static inline void
    727 netbsd32_from_ieee80211req(struct ieee80211req *ireq,
    728 			   struct netbsd32_ieee80211req *ireq32, u_long cmd)
    729 {
    730 	strncpy(ireq32->i_name, ireq->i_name, IFNAMSIZ);
    731 	ireq32->i_type = ireq->i_type;
    732 	ireq32->i_val = ireq->i_val;
    733 	ireq32->i_len = ireq->i_len;
    734 	NETBSD32PTR32(ireq32->i_data, ireq->i_data);
    735 }
    736 
    737 static inline void
    738 netbsd32_from_ieee80211_nwkey(struct ieee80211_nwkey *nwk,
    739 				struct netbsd32_ieee80211_nwkey *nwk32,
    740 				u_long cmd)
    741 {
    742 	int i;
    743 
    744 	strncpy(nwk32->i_name, nwk->i_name, IFNAMSIZ);
    745 	nwk32->i_wepon = nwk->i_wepon;
    746 	nwk32->i_defkid = nwk->i_defkid;
    747 	for (i = 0; i < IEEE80211_WEP_NKID; i++) {
    748 		nwk32->i_key[i].i_keylen = nwk->i_key[i].i_keylen;
    749 		NETBSD32PTR32(nwk32->i_key[i].i_keydat,
    750 				nwk->i_key[i].i_keydat);
    751 	}
    752 }
    753 
    754 static inline void
    755 netbsd32_from_bpf_program(struct bpf_program *p, struct netbsd32_bpf_program *s32p, u_long cmd)
    756 {
    757 
    758 	NETBSD32PTR32(s32p->bf_insns, p->bf_insns);
    759 	s32p->bf_len = p->bf_len;
    760 }
    761 
    762 static inline void
    763 netbsd32_from_bpf_dltlist(struct bpf_dltlist *p, struct netbsd32_bpf_dltlist *s32p, u_long cmd)
    764 {
    765 
    766 	NETBSD32PTR32(s32p->bfl_list, p->bfl_list);
    767 	s32p->bfl_len = p->bfl_len;
    768 }
    769 
    770 static inline void
    771 netbsd32_from_u_long(u_long *p, netbsd32_u_long *s32p, u_long cmd)
    772 {
    773 
    774 	*s32p = (netbsd32_u_long)*p;
    775 }
    776 
    777 static inline void
    778 netbsd32_from_clockctl_settimeofday(
    779     const struct clockctl_settimeofday *p,
    780     struct netbsd32_clockctl_settimeofday *s32p,
    781     u_long cmd)
    782 {
    783 
    784 	NETBSD32PTR32(s32p->tv, p->tv);
    785 	NETBSD32PTR32(s32p->tzp, p->tzp);
    786 }
    787 
    788 static inline void
    789 netbsd32_from_clockctl_adjtime(
    790     const struct clockctl_adjtime *p,
    791     struct netbsd32_clockctl_adjtime *s32p,
    792     u_long cmd)
    793 {
    794 
    795 	NETBSD32PTR32(s32p->delta, p->delta);
    796 	NETBSD32PTR32(s32p->olddelta, p->olddelta);
    797 }
    798 
    799 static inline void
    800 netbsd32_from_clockctl_clock_settime(
    801     const struct clockctl_clock_settime *p,
    802     struct netbsd32_clockctl_clock_settime *s32p,
    803     u_long cmd)
    804 {
    805 
    806 	s32p->clock_id = p->clock_id;
    807 	NETBSD32PTR32(s32p->tp, p->tp);
    808 }
    809 
    810 static inline void
    811 netbsd32_from_clockctl_ntp_adjtime(
    812     const struct clockctl_ntp_adjtime *p,
    813     struct netbsd32_clockctl_ntp_adjtime *s32p,
    814     u_long cmd)
    815 {
    816 
    817 	NETBSD32PTR32(s32p->tp, p->tp);
    818 	s32p->retval = p->retval;
    819 }
    820 
    821 static inline void
    822 netbsd32_from_ksyms_gsymbol(
    823     const struct ksyms_gsymbol *p,
    824     struct netbsd32_ksyms_gsymbol *s32p,
    825     u_long cmd)
    826 {
    827 
    828 	NETBSD32PTR32(s32p->kg_name, p->kg_name);
    829 	s32p->kg_sym = p->kg_sym;
    830 }
    831 
    832 static inline void
    833 netbsd32_from_ksyms_gvalue(
    834     const struct ksyms_gvalue *p,
    835     struct netbsd32_ksyms_gvalue *s32p,
    836     u_long cmd)
    837 {
    838 
    839 	NETBSD32PTR32(s32p->kv_name, p->kv_name);
    840 	s32p->kv_value = p->kv_value;
    841 }
    842 
    843 /*
    844  * main ioctl syscall.
    845  *
    846  * ok, here we are in the biggy.  we have to do fix ups depending
    847  * on the ioctl command before and afterwards.
    848  */
    849 int
    850 netbsd32_ioctl(struct lwp *l, const struct netbsd32_ioctl_args *uap, register_t *retval)
    851 {
    852 	/* {
    853 		syscallarg(int) fd;
    854 		syscallarg(netbsd32_u_long) com;
    855 		syscallarg(netbsd32_voidp) data;
    856 	} */
    857 	struct proc *p = l->l_proc;
    858 	struct file *fp;
    859 	struct filedesc *fdp;
    860 	u_long com;
    861 	int error = 0;
    862 	size_t size;
    863 	size_t alloc_size32, size32;
    864 	void *data, *memp = NULL;
    865 	void *data32, *memp32 = NULL;
    866 	unsigned int fd;
    867 	fdfile_t *ff;
    868 	int tmp;
    869 #define STK_PARAMS	128
    870 	uint64_t stkbuf[STK_PARAMS/sizeof(uint64_t)];
    871 	uint64_t stkbuf32[STK_PARAMS/sizeof(uint64_t)];
    872 
    873 	/*
    874 	 * we need to translate some commands (_IOW) before calling sys_ioctl,
    875 	 * some after (_IOR), and some both (_IOWR).
    876 	 */
    877 #if 0
    878 	{
    879 		const char * const dirs[8] = {
    880 		    "NONE!", "VOID", "OUT", "VOID|OUT!", "IN", "VOID|IN!",
    881 		    "INOUT", "VOID|IN|OUT!"
    882 		};
    883 
    884 		printf("netbsd32_ioctl(%d, %x, %x): "
    885 		    "%s group %c base %d len %d\n",
    886 		    SCARG(uap, fd), SCARG(uap, com), SCARG(uap, data).i32,
    887 		    dirs[((SCARG(uap, com) & IOC_DIRMASK)>>29)],
    888 		    IOCGROUP(SCARG(uap, com)), IOCBASECMD(SCARG(uap, com)),
    889 		    IOCPARM_LEN(SCARG(uap, com)));
    890 	}
    891 #endif
    892 
    893 	memp = NULL;
    894 	memp32 = NULL;
    895 	alloc_size32 = 0;
    896 	size32 = 0;
    897 	size = 0;
    898 
    899 	fdp = p->p_fd;
    900 	fd = SCARG(uap, fd);
    901 	if ((fp = fd_getfile(fd)) == NULL)
    902 		return (EBADF);
    903 	if ((fp->f_flag & (FREAD | FWRITE)) == 0) {
    904 		error = EBADF;
    905 		goto out;
    906 	}
    907 
    908 	ff = fdp->fd_dt->dt_ff[SCARG(uap, fd)];
    909 	switch (com = SCARG(uap, com)) {
    910 	case FIOCLEX:
    911 		ff->ff_exclose = true;
    912 		fdp->fd_exclose = true;
    913 		goto out;
    914 
    915 	case FIONCLEX:
    916 		ff->ff_exclose = false;
    917 		goto out;
    918 	}
    919 
    920 	/*
    921 	 * Interpret high order word to find amount of data to be
    922 	 * copied to/from the user's address space.
    923 	 */
    924 	size32 = IOCPARM_LEN(com);
    925 	alloc_size32 = size32;
    926 
    927 	/*
    928 	 * The disklabel is now padded to a multiple of 8 bytes however the old
    929 	 * disklabel on 32bit platforms wasn't.  This leaves a difference in
    930 	 * size of 4 bytes between the two but are otherwise identical.
    931 	 * To deal with this, we allocate enough space for the new disklabel
    932 	 * but only copyin/out the smaller amount.
    933 	 */
    934 	if (IOCGROUP(com) == 'd') {
    935 		u_long ncom = com ^ (DIOCGDINFO ^ DIOCGDINFO32);
    936 		switch (ncom) {
    937 		case DIOCGDINFO:
    938 		case DIOCWDINFO:
    939 		case DIOCSDINFO:
    940 		case DIOCGDEFLABEL:
    941 			com = ncom;
    942 			if (IOCPARM_LEN(DIOCGDINFO32) < IOCPARM_LEN(DIOCGDINFO))
    943 				alloc_size32 = IOCPARM_LEN(DIOCGDINFO);
    944 			break;
    945 		}
    946 	}
    947 	if (alloc_size32 > IOCPARM_MAX) {
    948 		error = ENOTTY;
    949 		goto out;
    950 	}
    951 	if (alloc_size32 > sizeof(stkbuf)) {
    952 		memp32 = kmem_alloc(alloc_size32, KM_SLEEP);
    953 		data32 = memp32;
    954 	} else
    955 		data32 = (void *)stkbuf32;
    956 	if ((com >> IOCPARM_SHIFT) == 0)  {
    957 		/* UNIX-style ioctl. */
    958 		data32 = SCARG_P32(uap, data);
    959 	} else {
    960 		if (com&IOC_IN) {
    961 			if (size32) {
    962 				error = copyin(SCARG_P32(uap, data), data32,
    963 				    size32);
    964 				if (error) {
    965 					goto out;
    966 				}
    967 				/*
    968 				 * The data between size and alloc_size has
    969 				 * not been overwritten.  It shouldn't matter
    970 				 * but let's clear that anyway.
    971 				 */
    972 				if (__predict_false(size32 < alloc_size32)) {
    973 					memset((char *)data32+size32, 0,
    974 					    alloc_size32 - size32);
    975 				}
    976 				ktrgenio(fd, UIO_WRITE, SCARG_P32(uap, data),
    977 				    size32, 0);
    978 			} else
    979 				*(void **)data32 = SCARG_P32(uap, data);
    980 		} else if ((com&IOC_OUT) && size32) {
    981 			/*
    982 			 * Zero the buffer so the user always
    983 			 * gets back something deterministic.
    984 			 */
    985 			memset(data32, 0, alloc_size32);
    986 		} else if (com&IOC_VOID) {
    987 			*(void **)data32 = SCARG_P32(uap, data);
    988 		}
    989 	}
    990 
    991 	/*
    992 	 * convert various structures, pointers, and other objects that
    993 	 * change size from 32 bit -> 64 bit, for all ioctl commands.
    994 	 */
    995 	switch (SCARG(uap, com)) {
    996 	case FIONBIO:
    997 		mutex_enter(&fp->f_lock);
    998 		if ((tmp = *(int *)data32) != 0)
    999 			fp->f_flag |= FNONBLOCK;
   1000 		else
   1001 			fp->f_flag &= ~FNONBLOCK;
   1002 		mutex_exit(&fp->f_lock);
   1003 		error = (*fp->f_ops->fo_ioctl)(fp, FIONBIO, (void *)&tmp);
   1004 		break;
   1005 
   1006 	case FIOASYNC:
   1007 		mutex_enter(&fp->f_lock);
   1008 		if ((tmp = *(int *)data32) != 0)
   1009 			fp->f_flag |= FASYNC;
   1010 		else
   1011 			fp->f_flag &= ~FASYNC;
   1012 		mutex_exit(&fp->f_lock);
   1013 		error = (*fp->f_ops->fo_ioctl)(fp, FIOASYNC, (void *)&tmp);
   1014 		break;
   1015 
   1016 	case AUDIO_WSEEK32:
   1017 		IOCTL_CONV_TO(AUDIO_WSEEK, u_long);
   1018 
   1019 	case DIOCGPART32:
   1020 		IOCTL_STRUCT_CONV_TO(DIOCGPART, partinfo);
   1021 #if 0	/* not implemented by anything */
   1022 	case DIOCRFORMAT32:
   1023 		IOCTL_STRUCT_CONV_TO(DIOCRFORMAT, format_op);
   1024 	case DIOCWFORMAT32:
   1025 		IOCTL_STRUCT_CONV_TO(DIOCWFORMAT, format_op);
   1026 #endif
   1027 
   1028 	case ATAIOCCOMMAND32:
   1029 		IOCTL_STRUCT_CONV_TO(ATAIOCCOMMAND, atareq);
   1030 
   1031 	case SIOCIFGCLONERS32:
   1032 		{
   1033 			struct netbsd32_if_clonereq *req =
   1034 			    (struct netbsd32_if_clonereq *)data32;
   1035 			char *buf = NETBSD32PTR64(req->ifcr_buffer);
   1036 
   1037 			error = if_clone_list(req->ifcr_count,
   1038 			    buf, &req->ifcr_total);
   1039 			break;
   1040 		}
   1041 
   1042 /*
   1043  * only a few ifreq syscalls need conversion and those are
   1044  * all driver specific... XXX
   1045  */
   1046 #if 0
   1047 	case SIOCGADDRROM3232:
   1048 		IOCTL_STRUCT_CONV_TO(SIOCGADDRROM32, ifreq);
   1049 	case SIOCGCHIPID32:
   1050 		IOCTL_STRUCT_CONV_TO(SIOCGCHIPID, ifreq);
   1051 	case SIOCSIFADDR32:
   1052 		IOCTL_STRUCT_CONV_TO(SIOCSIFADDR, ifreq);
   1053 	case OSIOCGIFADDR32:
   1054 		IOCTL_STRUCT_CONV_TO(OSIOCGIFADDR, ifreq);
   1055 	case SIOCGIFADDR32:
   1056 		IOCTL_STRUCT_CONV_TO(SIOCGIFADDR, ifreq);
   1057 	case SIOCSIFDSTADDR32:
   1058 		IOCTL_STRUCT_CONV_TO(SIOCSIFDSTADDR, ifreq);
   1059 	case OSIOCGIFDSTADDR32:
   1060 		IOCTL_STRUCT_CONV_TO(OSIOCGIFDSTADDR, ifreq);
   1061 	case SIOCGIFDSTADDR32:
   1062 		IOCTL_STRUCT_CONV_TO(SIOCGIFDSTADDR, ifreq);
   1063 	case OSIOCGIFBRDADDR32:
   1064 		IOCTL_STRUCT_CONV_TO(OSIOCGIFBRDADDR, ifreq);
   1065 	case SIOCGIFBRDADDR32:
   1066 		IOCTL_STRUCT_CONV_TO(SIOCGIFBRDADDR, ifreq);
   1067 	case SIOCSIFBRDADDR32:
   1068 		IOCTL_STRUCT_CONV_TO(SIOCSIFBRDADDR, ifreq);
   1069 	case OSIOCGIFNETMASK32:
   1070 		IOCTL_STRUCT_CONV_TO(OSIOCGIFNETMASK, ifreq);
   1071 	case SIOCGIFNETMASK32:
   1072 		IOCTL_STRUCT_CONV_TO(SIOCGIFNETMASK, ifreq);
   1073 	case SIOCSIFNETMASK32:
   1074 		IOCTL_STRUCT_CONV_TO(SIOCSIFNETMASK, ifreq);
   1075 	case SIOCGIFMETRIC32:
   1076 		IOCTL_STRUCT_CONV_TO(SIOCGIFMETRIC, ifreq);
   1077 	case SIOCSIFMETRIC32:
   1078 		IOCTL_STRUCT_CONV_TO(SIOCSIFMETRIC, ifreq);
   1079 	case SIOCDIFADDR32:
   1080 		IOCTL_STRUCT_CONV_TO(SIOCDIFADDR, ifreq);
   1081 	case SIOCADDMULTI32:
   1082 		IOCTL_STRUCT_CONV_TO(SIOCADDMULTI, ifreq);
   1083 	case SIOCDELMULTI32:
   1084 		IOCTL_STRUCT_CONV_TO(SIOCDELMULTI, ifreq);
   1085 	case SIOCSIFMEDIA32:
   1086 		IOCTL_STRUCT_CONV_TO(SIOCSIFMEDIA, ifreq);
   1087 	case SIOCSIFMTU32:
   1088 		IOCTL_STRUCT_CONV_TO(SIOCSIFMTU, ifreq);
   1089 	case SIOCGIFMTU32:
   1090 		IOCTL_STRUCT_CONV_TO(SIOCGIFMTU, ifreq);
   1091 	case BIOCGETIF32:
   1092 		IOCTL_STRUCT_CONV_TO(BIOCGETIF, ifreq);
   1093 	case BIOCSETIF32:
   1094 		IOCTL_STRUCT_CONV_TO(BIOCSETIF, ifreq);
   1095 	case SIOCPHASE132:
   1096 		IOCTL_STRUCT_CONV_TO(SIOCPHASE1, ifreq);
   1097 	case SIOCPHASE232:
   1098 		IOCTL_STRUCT_CONV_TO(SIOCPHASE2, ifreq);
   1099 #endif
   1100 
   1101 	case OOSIOCGIFCONF32:
   1102 		IOCTL_STRUCT_CONV_TO(OOSIOCGIFCONF, ifconf);
   1103 	case OSIOCGIFCONF32:
   1104 		IOCTL_STRUCT_CONV_TO(OSIOCGIFCONF, ifconf);
   1105 	case SIOCGIFCONF32:
   1106 		IOCTL_STRUCT_CONV_TO(SIOCGIFCONF, ifconf);
   1107 
   1108 	case SIOCGIFFLAGS32:
   1109 		IOCTL_STRUCT_CONV_TO(SIOCGIFFLAGS, ifreq);
   1110 	case SIOCSIFFLAGS32:
   1111 		IOCTL_STRUCT_CONV_TO(SIOCSIFFLAGS, ifreq);
   1112 
   1113 	case SIOCGIFADDRPREF32:
   1114 		IOCTL_STRUCT_CONV_TO(SIOCGIFADDRPREF, if_addrprefreq);
   1115 	case SIOCSIFADDRPREF32:
   1116 		IOCTL_STRUCT_CONV_TO(SIOCSIFADDRPREF, if_addrprefreq);
   1117 
   1118 
   1119 	case OSIOCGIFFLAGS32:
   1120 		IOCTL_STRUCT_CONV_TO(OSIOCGIFFLAGS, oifreq);
   1121 	case OSIOCSIFFLAGS32:
   1122 		IOCTL_STRUCT_CONV_TO(OSIOCSIFFLAGS, oifreq);
   1123 
   1124 	case SIOCGIFMEDIA32:
   1125 		IOCTL_STRUCT_CONV_TO(SIOCGIFMEDIA, ifmediareq);
   1126 
   1127 #if NPPPOE > 0
   1128 	case PPPOESETPARMS32:
   1129 		IOCTL_STRUCT_CONV_TO(PPPOESETPARMS, pppoediscparms);
   1130 	case PPPOEGETPARMS32:
   1131 		IOCTL_STRUCT_CONV_TO(PPPOEGETPARMS, pppoediscparms);
   1132 #endif
   1133 #if NSPPP > 0
   1134 	case SPPPGETAUTHCFG32:
   1135 		IOCTL_STRUCT_CONV_TO(SPPPGETAUTHCFG, spppauthcfg);
   1136 	case SPPPSETAUTHCFG32:
   1137 		IOCTL_STRUCT_CONV_TO(SPPPSETAUTHCFG, spppauthcfg);
   1138 #endif
   1139 
   1140 	case SIOCSDRVSPEC32:
   1141 		IOCTL_STRUCT_CONV_TO(SIOCSDRVSPEC, ifdrv);
   1142 	case SIOCGDRVSPEC32:
   1143 		IOCTL_STRUCT_CONV_TO(SIOCGDRVSPEC, ifdrv);
   1144 
   1145 	case SIOCGETVIFCNT32:
   1146 		IOCTL_STRUCT_CONV_TO(SIOCGETVIFCNT, sioc_vif_req);
   1147 
   1148 	case SIOCGETSGCNT32:
   1149 		IOCTL_STRUCT_CONV_TO(SIOCGETSGCNT, sioc_sg_req);
   1150 
   1151 	case VNDIOCSET32:
   1152 		IOCTL_STRUCT_CONV_TO(VNDIOCSET, vnd_ioctl);
   1153 
   1154 	case VNDIOCCLR32:
   1155 		IOCTL_STRUCT_CONV_TO(VNDIOCCLR, vnd_ioctl);
   1156 
   1157 	case VNDIOCGET32:
   1158 		IOCTL_STRUCT_CONV_TO(VNDIOCGET, vnd_user);
   1159 
   1160 	case VNDIOCSET5032:
   1161 		IOCTL_STRUCT_CONV_TO(VNDIOCSET50, vnd_ioctl50);
   1162 
   1163 	case VNDIOCCLR5032:
   1164 		IOCTL_STRUCT_CONV_TO(VNDIOCCLR50, vnd_ioctl50);
   1165 
   1166 	case ENVSYS_GETDICTIONARY32:
   1167 		IOCTL_STRUCT_CONV_TO(ENVSYS_GETDICTIONARY, plistref);
   1168 	case ENVSYS_SETDICTIONARY32:
   1169 		IOCTL_STRUCT_CONV_TO(ENVSYS_SETDICTIONARY, plistref);
   1170 	case ENVSYS_REMOVEPROPS32:
   1171 		IOCTL_STRUCT_CONV_TO(ENVSYS_REMOVEPROPS, plistref);
   1172 
   1173 	case WDOGIOC_GWDOGS32:
   1174 		IOCTL_STRUCT_CONV_TO(WDOGIOC_GWDOGS, wdog_conf);
   1175 
   1176 	case BIOCSETF32:
   1177 		IOCTL_STRUCT_CONV_TO(BIOCSETF, bpf_program);
   1178 	case BIOCSTCPF32:
   1179 		IOCTL_STRUCT_CONV_TO(BIOCSTCPF, bpf_program);
   1180 	case BIOCSUDPF32:
   1181 		IOCTL_STRUCT_CONV_TO(BIOCSUDPF, bpf_program);
   1182 	case BIOCGDLTLIST32:
   1183 		IOCTL_STRUCT_CONV_TO(BIOCGDLTLIST, bpf_dltlist);
   1184 
   1185 	case WSDISPLAYIO_ADDSCREEN32:
   1186 		IOCTL_STRUCT_CONV_TO(WSDISPLAYIO_ADDSCREEN, wsdisplay_addscreendata);
   1187 
   1188 	case WSDISPLAYIO_GCURSOR32:
   1189 		IOCTL_STRUCT_CONV_TO(WSDISPLAYIO_GCURSOR, wsdisplay_cursor);
   1190 	case WSDISPLAYIO_SCURSOR32:
   1191 		IOCTL_STRUCT_CONV_TO(WSDISPLAYIO_SCURSOR, wsdisplay_cursor);
   1192 
   1193 	case WSDISPLAYIO_GETCMAP32:
   1194 		IOCTL_STRUCT_CONV_TO(WSDISPLAYIO_GETCMAP, wsdisplay_cmap);
   1195 	case WSDISPLAYIO_PUTCMAP32:
   1196 		IOCTL_STRUCT_CONV_TO(WSDISPLAYIO_PUTCMAP, wsdisplay_cmap);
   1197 
   1198 	case SIOCS8021132:
   1199 		IOCTL_STRUCT_CONV_TO(SIOCS80211, ieee80211req);
   1200 	case SIOCG8021132:
   1201 		IOCTL_STRUCT_CONV_TO(SIOCG80211, ieee80211req);
   1202 	case SIOCS80211NWKEY32:
   1203 		IOCTL_STRUCT_CONV_TO(SIOCS80211NWKEY, ieee80211_nwkey);
   1204 	case SIOCG80211NWKEY32:
   1205 		IOCTL_STRUCT_CONV_TO(SIOCG80211NWKEY, ieee80211_nwkey);
   1206 
   1207 	case POWER_EVENT_RECVDICT32:
   1208 		IOCTL_STRUCT_CONV_TO(POWER_EVENT_RECVDICT, plistref);
   1209 
   1210 	case CLOCKCTL_SETTIMEOFDAY32:
   1211 		IOCTL_STRUCT_CONV_TO(CLOCKCTL_SETTIMEOFDAY,
   1212 		    clockctl_settimeofday);
   1213 	case CLOCKCTL_ADJTIME32:
   1214 		IOCTL_STRUCT_CONV_TO(CLOCKCTL_ADJTIME, clockctl_adjtime);
   1215 	case CLOCKCTL_CLOCK_SETTIME32:
   1216 		IOCTL_STRUCT_CONV_TO(CLOCKCTL_CLOCK_SETTIME,
   1217 		    clockctl_clock_settime);
   1218 	case CLOCKCTL_NTP_ADJTIME32:
   1219 		IOCTL_STRUCT_CONV_TO(CLOCKCTL_NTP_ADJTIME,
   1220 		    clockctl_ntp_adjtime);
   1221 
   1222 	case KIOCGSYMBOL32:
   1223 		IOCTL_STRUCT_CONV_TO(KIOCGSYMBOL, ksyms_gsymbol);
   1224 	case KIOCGVALUE32:
   1225 		IOCTL_STRUCT_CONV_TO(KIOCGVALUE, ksyms_gvalue);
   1226 
   1227 	default:
   1228 #ifdef NETBSD32_MD_IOCTL
   1229 		error = netbsd32_md_ioctl(fp, com, data32, l);
   1230 #else
   1231 		error = (*fp->f_ops->fo_ioctl)(fp, com, data32);
   1232 #endif
   1233 		break;
   1234 	}
   1235 
   1236 	if (error == EPASSTHROUGH)
   1237 		error = ENOTTY;
   1238 
   1239 	/*
   1240 	 * Copy any data to user, size was
   1241 	 * already set and checked above.
   1242 	 */
   1243 	if (error == 0 && (com&IOC_OUT) && size32) {
   1244 		error = copyout(data32, SCARG_P32(uap, data), size32);
   1245 		ktrgenio(fd, UIO_READ, SCARG_P32(uap, data),
   1246 		    size32, error);
   1247 	}
   1248 
   1249  out:
   1250 	/* If we allocated data, free it here. */
   1251 	if (memp32)
   1252 		kmem_free(memp32, alloc_size32);
   1253 	if (memp)
   1254 		kmem_free(memp, size);
   1255 	fd_putfile(fd);
   1256 	return (error);
   1257 }
   1258