Home | History | Annotate | Line # | Download | only in netbsd32
netbsd32_ioctl.c revision 1.30.2.1
      1 /*	$NetBSD: netbsd32_ioctl.c,v 1.30.2.1 2007/04/10 13:26:28 ad 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  * 3. The name of the author may not be used to endorse or promote products
     16  *    derived from this software without specific prior written permission.
     17  *
     18  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     19  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     20  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     21  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     22  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
     23  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
     24  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
     25  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
     26  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     27  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     28  * SUCH DAMAGE.
     29  */
     30 
     31 /*
     32  * handle ioctl conversions from netbsd32 -> 64-bit kernel
     33  */
     34 
     35 #include <sys/cdefs.h>
     36 __KERNEL_RCSID(0, "$NetBSD: netbsd32_ioctl.c,v 1.30.2.1 2007/04/10 13:26:28 ad Exp $");
     37 
     38 #if defined(_KERNEL_OPT)
     39 #include "opt_ktrace.h"
     40 #endif
     41 
     42 #include <sys/param.h>
     43 #include <sys/systm.h>
     44 #include <sys/filedesc.h>
     45 #include <sys/ioctl.h>
     46 #include <sys/file.h>
     47 #include <sys/proc.h>
     48 #include <sys/socketvar.h>
     49 #include <sys/audioio.h>
     50 #include <sys/disklabel.h>
     51 #include <sys/dkio.h>
     52 #include <sys/malloc.h>
     53 #include <sys/sockio.h>
     54 #include <sys/socket.h>
     55 #include <sys/ttycom.h>
     56 #include <sys/mount.h>
     57 #include <sys/syscallargs.h>
     58 #ifdef KTRACE
     59 #include <sys/ktrace.h>
     60 #endif
     61 
     62 #ifdef __sparc__
     63 #include <dev/sun/fbio.h>
     64 #include <machine/openpromio.h>
     65 #endif
     66 
     67 #include <net/if.h>
     68 #include <net/route.h>
     69 
     70 #include <netinet/in.h>
     71 #include <netinet/in_var.h>
     72 #include <netinet/igmp.h>
     73 #include <netinet/igmp_var.h>
     74 #include <netinet/ip_mroute.h>
     75 
     76 #include <compat/netbsd32/netbsd32.h>
     77 #include <compat/netbsd32/netbsd32_ioctl.h>
     78 #include <compat/netbsd32/netbsd32_syscallargs.h>
     79 
     80 /* prototypes for the converters */
     81 static inline void netbsd32_to_partinfo(struct netbsd32_partinfo *,
     82 					  struct partinfo *, u_long);
     83 #if 0
     84 static inline void netbsd32_to_format_op(struct netbsd32_format_op *,
     85 					   struct format_op *, u_long);
     86 #endif
     87 static inline void netbsd32_to_ifreq(struct netbsd32_ifreq *, struct ifreq *,
     88 				       u_long cmd);
     89 static inline void netbsd32_to_ifconf(struct netbsd32_ifconf *,
     90 					struct ifconf *, u_long);
     91 static inline void netbsd32_to_ifmediareq(struct netbsd32_ifmediareq *,
     92 					    struct ifmediareq *, u_long);
     93 static inline void netbsd32_to_ifdrv(struct netbsd32_ifdrv *, struct ifdrv *,
     94 				       u_long);
     95 static inline void netbsd32_to_sioc_vif_req(struct netbsd32_sioc_vif_req *,
     96 					      struct sioc_vif_req *, u_long);
     97 static inline void netbsd32_to_sioc_sg_req(struct netbsd32_sioc_sg_req *,
     98 					     struct sioc_sg_req *, u_long);
     99 static inline void netbsd32_from_partinfo(struct partinfo *,
    100 					    struct netbsd32_partinfo *, u_long);
    101 #if 0
    102 static inline void netbsd32_from_format_op(struct format_op *,
    103 					     struct netbsd32_format_op *,
    104 					     u_long);
    105 #endif
    106 static inline void netbsd32_from_ifreq(struct ifreq *,
    107                                          struct netbsd32_ifreq *, u_long);
    108 static inline void netbsd32_from_ifconf(struct ifconf *,
    109 					  struct netbsd32_ifconf *, u_long);
    110 static inline void netbsd32_from_ifmediareq(struct ifmediareq *,
    111 					      struct netbsd32_ifmediareq *,
    112 					      u_long);
    113 static inline void netbsd32_from_ifdrv(struct ifdrv *,
    114 					 struct netbsd32_ifdrv *, u_long);
    115 static inline void netbsd32_from_sioc_vif_req(struct sioc_vif_req *,
    116 						struct netbsd32_sioc_vif_req *,
    117 						u_long);
    118 static inline void netbsd32_from_sioc_sg_req(struct sioc_sg_req *,
    119 					       struct netbsd32_sioc_sg_req *,
    120 					       u_long);
    121 
    122 /* convert to/from different structures */
    123 
    124 static inline void
    125 netbsd32_to_partinfo(s32p, p, cmd)
    126 	struct netbsd32_partinfo *s32p;
    127 	struct partinfo *p;
    128 	u_long cmd;
    129 {
    130 
    131 	p->disklab = (struct disklabel *)NETBSD32PTR64(s32p->disklab);
    132 	p->part = (struct partition *)NETBSD32PTR64(s32p->part);
    133 }
    134 
    135 #if 0
    136 static inline void
    137 netbsd32_to_format_op(s32p, p, cmd)
    138 	struct netbsd32_format_op *s32p;
    139 	struct format_op *p;
    140 	u_long cmd;
    141 {
    142 
    143 	p->df_buf = (char *)NETBSD32PTR64(s32p->df_buf);
    144 	p->df_count = s32p->df_count;
    145 	p->df_startblk = s32p->df_startblk;
    146 	memcpy(p->df_reg, s32p->df_reg, sizeof(s32p->df_reg));
    147 }
    148 #endif
    149 
    150 static inline void
    151 netbsd32_to_ifreq(s32p, p, cmd)
    152 	struct netbsd32_ifreq *s32p;
    153 	struct ifreq *p;
    154 	u_long cmd;
    155 {
    156 
    157 	memcpy(p, s32p, sizeof *s32p);
    158 	/*
    159 	 * XXX
    160 	 * struct ifreq says the same, but sometimes the ifr_data
    161 	 * union member needs to be converted to 64 bits... this
    162 	 * is very driver specific and so we ignore it for now..
    163 	 */
    164 	if (cmd == SIOCGIFDATA || cmd == SIOCZIFDATA)
    165 		p->ifr_data = (void *)NETBSD32PTR64(s32p->ifr_data);
    166 }
    167 
    168 static inline void
    169 netbsd32_to_ifconf(s32p, p, cmd)
    170 	struct netbsd32_ifconf *s32p;
    171 	struct ifconf *p;
    172 	u_long cmd;
    173 {
    174 
    175 	p->ifc_len = s32p->ifc_len;
    176 	/* ifc_buf & ifc_req are the same size so this works */
    177 	p->ifc_buf = (void *)NETBSD32PTR64(s32p->ifc_buf);
    178 }
    179 
    180 static inline void
    181 netbsd32_to_ifmediareq(s32p, p, cmd)
    182 	struct netbsd32_ifmediareq *s32p;
    183 	struct ifmediareq *p;
    184 	u_long cmd;
    185 {
    186 
    187 	memcpy(p, s32p, sizeof *s32p);
    188 	p->ifm_ulist = (int *)NETBSD32PTR64(s32p->ifm_ulist);
    189 }
    190 
    191 static inline void
    192 netbsd32_to_ifdrv(s32p, p, cmd)
    193 	struct netbsd32_ifdrv *s32p;
    194 	struct ifdrv *p;
    195 	u_long cmd;
    196 {
    197 
    198 	memcpy(p, s32p, sizeof *s32p);
    199 	p->ifd_data = (void *)NETBSD32PTR64(s32p->ifd_data);
    200 }
    201 
    202 static inline void
    203 netbsd32_to_sioc_vif_req(s32p, p, cmd)
    204 	struct netbsd32_sioc_vif_req *s32p;
    205 	struct sioc_vif_req *p;
    206 	u_long cmd;
    207 {
    208 
    209 	p->vifi = s32p->vifi;
    210 	p->icount = (u_long)s32p->icount;
    211 	p->ocount = (u_long)s32p->ocount;
    212 	p->ibytes = (u_long)s32p->ibytes;
    213 	p->obytes = (u_long)s32p->obytes;
    214 }
    215 
    216 static inline void
    217 netbsd32_to_sioc_sg_req(s32p, p, cmd)
    218 	struct netbsd32_sioc_sg_req *s32p;
    219 	struct sioc_sg_req *p;
    220 	u_long cmd;
    221 {
    222 
    223 	p->src = s32p->src;
    224 	p->grp = s32p->grp;
    225 	p->pktcnt = (u_long)s32p->pktcnt;
    226 	p->bytecnt = (u_long)s32p->bytecnt;
    227 	p->wrong_if = (u_long)s32p->wrong_if;
    228 }
    229 
    230 /*
    231  * handle ioctl conversions from 64-bit kernel -> netbsd32
    232  */
    233 
    234 static inline void
    235 netbsd32_from_partinfo(p, s32p, cmd)
    236 	struct partinfo *p;
    237 	struct netbsd32_partinfo *s32p;
    238 	u_long cmd;
    239 {
    240 
    241 	NETBSD32PTR32(s32p->disklab, p->disklab);
    242 	NETBSD32PTR32(s32p->part, p->part);
    243 }
    244 
    245 #if 0
    246 static inline void
    247 netbsd32_from_format_op(p, s32p, cmd)
    248 	struct format_op *p;
    249 	struct netbsd32_format_op *s32p;
    250 	u_long cmd;
    251 {
    252 
    253 /* filled in */
    254 #if 0
    255 	s32p->df_buf = (netbsd32_charp)p->df_buf;
    256 #endif
    257 	s32p->df_count = p->df_count;
    258 	s32p->df_startblk = p->df_startblk;
    259 	memcpy(s32p->df_reg, p->df_reg, sizeof(p->df_reg));
    260 }
    261 #endif
    262 
    263 static inline void
    264 netbsd32_from_ifreq(p, s32p, cmd)
    265 	struct ifreq *p;
    266 	struct netbsd32_ifreq *s32p;
    267 	u_long cmd;
    268 {
    269 
    270 	/*
    271 	 * XXX
    272 	 * struct ifreq says the same, but sometimes the ifr_data
    273 	 * union member needs to be converted to 64 bits... this
    274 	 * is very driver specific and so we ignore it for now..
    275 	 */
    276 	*s32p->ifr_name = *p->ifr_name;
    277 	if (cmd == SIOCGIFDATA || cmd == SIOCZIFDATA)
    278 		NETBSD32PTR32(s32p->ifr_data, p->ifr_data);
    279 }
    280 
    281 static inline void
    282 netbsd32_from_ifconf(p, s32p, cmd)
    283 	struct ifconf *p;
    284 	struct netbsd32_ifconf *s32p;
    285 	u_long cmd;
    286 {
    287 
    288 	s32p->ifc_len = p->ifc_len;
    289 	/* ifc_buf & ifc_req are the same size so this works */
    290 	NETBSD32PTR32(s32p->ifc_buf, p->ifc_buf);
    291 }
    292 
    293 static inline void
    294 netbsd32_from_ifmediareq(p, s32p, cmd)
    295 	struct ifmediareq *p;
    296 	struct netbsd32_ifmediareq *s32p;
    297 	u_long cmd;
    298 {
    299 
    300 	memcpy(s32p, p, sizeof *p);
    301 /* filled in? */
    302 #if 0
    303 	s32p->ifm_ulist = (netbsd32_intp_t)p->ifm_ulist;
    304 #endif
    305 }
    306 
    307 static inline void
    308 netbsd32_from_ifdrv(p, s32p, cmd)
    309 	struct ifdrv *p;
    310 	struct netbsd32_ifdrv *s32p;
    311 	u_long cmd;
    312 {
    313 
    314 	memcpy(s32p, p, sizeof *p);
    315 /* filled in? */
    316 #if 0
    317 	s32p->ifm_data = (netbsd32_u_longp_t)p->ifm_data;
    318 #endif
    319 }
    320 
    321 static inline void
    322 netbsd32_from_sioc_vif_req(p, s32p, cmd)
    323 	struct sioc_vif_req *p;
    324 	struct netbsd32_sioc_vif_req *s32p;
    325 	u_long cmd;
    326 {
    327 
    328 	s32p->vifi = p->vifi;
    329 	s32p->icount = (netbsd32_u_long)p->icount;
    330 	s32p->ocount = (netbsd32_u_long)p->ocount;
    331 	s32p->ibytes = (netbsd32_u_long)p->ibytes;
    332 	s32p->obytes = (netbsd32_u_long)p->obytes;
    333 }
    334 
    335 static inline void
    336 netbsd32_from_sioc_sg_req(p, s32p, cmd)
    337 	struct sioc_sg_req *p;
    338 	struct netbsd32_sioc_sg_req *s32p;
    339 	u_long cmd;
    340 {
    341 
    342 	s32p->src = p->src;
    343 	s32p->grp = p->grp;
    344 	s32p->pktcnt = (netbsd32_u_long)p->pktcnt;
    345 	s32p->bytecnt = (netbsd32_u_long)p->bytecnt;
    346 	s32p->wrong_if = (netbsd32_u_long)p->wrong_if;
    347 }
    348 
    349 
    350 /*
    351  * main ioctl syscall.
    352  *
    353  * ok, here we are in the biggy.  we have to do fix ups depending
    354  * on the ioctl command before and afterwards.
    355  */
    356 int
    357 netbsd32_ioctl(l, v, retval)
    358 	struct lwp *l;
    359 	void *v;
    360 	register_t *retval;
    361 {
    362 	struct netbsd32_ioctl_args /* {
    363 		syscallarg(int) fd;
    364 		syscallarg(netbsd32_u_long) com;
    365 		syscallarg(netbsd32_voidp) data;
    366 	} */ *uap = v;
    367 	struct proc *p = l->l_proc;
    368 	struct file *fp;
    369 	struct filedesc *fdp;
    370 	u_long com;
    371 	int error = 0;
    372 	u_int size, size32;
    373 	void *data, *memp = NULL;
    374 	void *data32, *memp32 = NULL;
    375 	int tmp;
    376 #define STK_PARAMS	128
    377 	u_long stkbuf[STK_PARAMS/sizeof(u_long)];
    378 	u_long stkbuf32[STK_PARAMS/sizeof(u_long)];
    379 
    380 	/*
    381 	 * we need to translate some commands (_IOW) before calling sys_ioctl,
    382 	 * some after (_IOR), and some both (_IOWR).
    383 	 */
    384 #if 0
    385 	{
    386 char *dirs[8] = { "NONE!", "VOID", "OUT", "VOID|OUT!", "IN", "VOID|IN!",
    387 		"INOUT", "VOID|IN|OUT!" };
    388 
    389 printf("netbsd32_ioctl(%d, %x, %x): %s group %c base %d len %d\n",
    390        SCARG(uap, fd), SCARG(uap, com), SCARG(uap, data),
    391        dirs[((SCARG(uap, com) & IOC_DIRMASK)>>29)],
    392        IOCGROUP(SCARG(uap, com)), IOCBASECMD(SCARG(uap, com)),
    393        IOCPARM_LEN(SCARG(uap, com)));
    394 	}
    395 #endif
    396 
    397 	fdp = p->p_fd;
    398 	if ((fp = fd_getfile(fdp, SCARG(uap, fd))) == NULL)
    399 		return (EBADF);
    400 
    401 	FILE_USE(fp);
    402 
    403 	if ((fp->f_flag & (FREAD | FWRITE)) == 0) {
    404 		error = EBADF;
    405 		goto out;
    406 	}
    407 
    408 	switch (com = SCARG(uap, com)) {
    409 	case FIONCLEX:
    410 		fdp->fd_ofileflags[SCARG(uap, fd)] &= ~UF_EXCLOSE;
    411 		goto out;
    412 
    413 	case FIOCLEX:
    414 		fdp->fd_ofileflags[SCARG(uap, fd)] |= UF_EXCLOSE;
    415 		goto out;
    416 	}
    417 
    418 	/*
    419 	 * Interpret high order word to find amount of data to be
    420 	 * copied to/from the user's address space.
    421 	 */
    422 	size32 = IOCPARM_LEN(com);
    423 	if (size32 > IOCPARM_MAX) {
    424 		error = ENOTTY;
    425 		goto out;
    426 	}
    427 	memp = NULL;
    428 	if (size32 > sizeof(stkbuf)) {
    429 		memp32 = malloc((u_long)size32, M_IOCTLOPS, M_WAITOK);
    430 		data32 = memp32;
    431 	} else
    432 		data32 = (void *)stkbuf32;
    433 	if (com&IOC_IN) {
    434 		if (size32) {
    435 			error = copyin(SCARG_P32(uap, data), data32, size32);
    436 			if (error) {
    437 				if (memp32)
    438 					free(memp32, M_IOCTLOPS);
    439 				goto out;
    440 			}
    441 #ifdef KTRACE
    442 			if (KTRPOINT(p, KTR_GENIO)) {
    443 				struct iovec iov;
    444 				iov.iov_base = SCARG_P32(uap, data);
    445 				iov.iov_len = size32;
    446 				ktrgenio(l, SCARG(uap, fd), UIO_WRITE, &iov,
    447 				    size32, 0);
    448 			}
    449 #endif
    450 		} else
    451 			*(void **)data32 = SCARG_P32(uap, data);
    452 	} else if ((com&IOC_OUT) && size32)
    453 		/*
    454 		 * Zero the buffer so the user always
    455 		 * gets back something deterministic.
    456 		 */
    457 		memset(data32, 0, size32);
    458 	else if (com&IOC_VOID)
    459 		*(void **)data32 = SCARG_P32(uap, data);
    460 
    461 	/*
    462 	 * convert various structures, pointers, and other objects that
    463 	 * change size from 32 bit -> 64 bit, for all ioctl commands.
    464 	 */
    465 	switch (SCARG(uap, com)) {
    466 	case FIONBIO:
    467 		if ((tmp = *(int *)data32) != 0)
    468 			fp->f_flag |= FNONBLOCK;
    469 		else
    470 			fp->f_flag &= ~FNONBLOCK;
    471 		error = (*fp->f_ops->fo_ioctl)(fp, FIONBIO, (void *)&tmp, l);
    472 		break;
    473 
    474 	case FIOASYNC:
    475 		if ((tmp = *(int *)data32) != 0)
    476 			fp->f_flag |= FASYNC;
    477 		else
    478 			fp->f_flag &= ~FASYNC;
    479 		error = (*fp->f_ops->fo_ioctl)(fp, FIOASYNC, (void *)&tmp, l);
    480 		break;
    481 
    482 	case DIOCGPART32:
    483 		IOCTL_STRUCT_CONV_TO(DIOCGPART, partinfo);
    484 #if 0	/* not implemented by anything */
    485 	case DIOCRFORMAT32:
    486 		IOCTL_STRUCT_CONV_TO(DIOCRFORMAT, format_op);
    487 	case DIOCWFORMAT32:
    488 		IOCTL_STRUCT_CONV_TO(DIOCWFORMAT, format_op);
    489 #endif
    490 
    491 /*
    492  * only a few ifreq syscalls need conversion and those are
    493  * all driver specific... XXX
    494  */
    495 #if 0
    496 	case SIOCGADDRROM3232:
    497 		IOCTL_STRUCT_CONV_TO(SIOCGADDRROM32, ifreq);
    498 	case SIOCGCHIPID32:
    499 		IOCTL_STRUCT_CONV_TO(SIOCGCHIPID, ifreq);
    500 	case SIOCSIFADDR32:
    501 		IOCTL_STRUCT_CONV_TO(SIOCSIFADDR, ifreq);
    502 	case OSIOCGIFADDR32:
    503 		IOCTL_STRUCT_CONV_TO(OSIOCGIFADDR, ifreq);
    504 	case SIOCGIFADDR32:
    505 		IOCTL_STRUCT_CONV_TO(SIOCGIFADDR, ifreq);
    506 	case SIOCSIFDSTADDR32:
    507 		IOCTL_STRUCT_CONV_TO(SIOCSIFDSTADDR, ifreq);
    508 	case OSIOCGIFDSTADDR32:
    509 		IOCTL_STRUCT_CONV_TO(OSIOCGIFDSTADDR, ifreq);
    510 	case SIOCGIFDSTADDR32:
    511 		IOCTL_STRUCT_CONV_TO(SIOCGIFDSTADDR, ifreq);
    512 	case OSIOCGIFBRDADDR32:
    513 		IOCTL_STRUCT_CONV_TO(OSIOCGIFBRDADDR, ifreq);
    514 	case SIOCGIFBRDADDR32:
    515 		IOCTL_STRUCT_CONV_TO(SIOCGIFBRDADDR, ifreq);
    516 	case SIOCSIFBRDADDR32:
    517 		IOCTL_STRUCT_CONV_TO(SIOCSIFBRDADDR, ifreq);
    518 	case OSIOCGIFNETMASK32:
    519 		IOCTL_STRUCT_CONV_TO(OSIOCGIFNETMASK, ifreq);
    520 	case SIOCGIFNETMASK32:
    521 		IOCTL_STRUCT_CONV_TO(SIOCGIFNETMASK, ifreq);
    522 	case SIOCSIFNETMASK32:
    523 		IOCTL_STRUCT_CONV_TO(SIOCSIFNETMASK, ifreq);
    524 	case SIOCGIFMETRIC32:
    525 		IOCTL_STRUCT_CONV_TO(SIOCGIFMETRIC, ifreq);
    526 	case SIOCSIFMETRIC32:
    527 		IOCTL_STRUCT_CONV_TO(SIOCSIFMETRIC, ifreq);
    528 	case SIOCDIFADDR32:
    529 		IOCTL_STRUCT_CONV_TO(SIOCDIFADDR, ifreq);
    530 	case SIOCADDMULTI32:
    531 		IOCTL_STRUCT_CONV_TO(SIOCADDMULTI, ifreq);
    532 	case SIOCDELMULTI32:
    533 		IOCTL_STRUCT_CONV_TO(SIOCDELMULTI, ifreq);
    534 	case SIOCSIFMEDIA32:
    535 		IOCTL_STRUCT_CONV_TO(SIOCSIFMEDIA, ifreq);
    536 	case SIOCSIFMTU32:
    537 		IOCTL_STRUCT_CONV_TO(SIOCSIFMTU, ifreq);
    538 	case SIOCGIFMTU32:
    539 		IOCTL_STRUCT_CONV_TO(SIOCGIFMTU, ifreq);
    540 	case BIOCGETIF32:
    541 		IOCTL_STRUCT_CONV_TO(BIOCGETIF, ifreq);
    542 	case BIOCSETIF32:
    543 		IOCTL_STRUCT_CONV_TO(BIOCSETIF, ifreq);
    544 	case SIOCPHASE132:
    545 		IOCTL_STRUCT_CONV_TO(SIOCPHASE1, ifreq);
    546 	case SIOCPHASE232:
    547 		IOCTL_STRUCT_CONV_TO(SIOCPHASE2, ifreq);
    548 #endif
    549 
    550 	case OSIOCGIFCONF32:
    551 		IOCTL_STRUCT_CONV_TO(OSIOCGIFCONF, ifconf);
    552 	case SIOCGIFCONF32:
    553 		IOCTL_STRUCT_CONV_TO(SIOCGIFCONF, ifconf);
    554 
    555 	case SIOCGIFFLAGS32:
    556 		IOCTL_STRUCT_CONV_TO(SIOCGIFFLAGS, ifreq);
    557 	case SIOCSIFFLAGS32:
    558 		IOCTL_STRUCT_CONV_TO(SIOCSIFFLAGS, ifreq);
    559 
    560 	case SIOCGIFMEDIA32:
    561 		IOCTL_STRUCT_CONV_TO(SIOCGIFMEDIA, ifmediareq);
    562 
    563 	case SIOCSDRVSPEC32:
    564 		IOCTL_STRUCT_CONV_TO(SIOCSDRVSPEC, ifdrv);
    565 
    566 	case SIOCGETVIFCNT32:
    567 		IOCTL_STRUCT_CONV_TO(SIOCGETVIFCNT, sioc_vif_req);
    568 
    569 	case SIOCGETSGCNT32:
    570 		IOCTL_STRUCT_CONV_TO(SIOCGETSGCNT, sioc_sg_req);
    571 
    572 	default:
    573 #ifdef NETBSD32_MD_IOCTL
    574 		error = netbsd32_md_ioctl(fp, com, data32, l);
    575 #else
    576 		error = (*fp->f_ops->fo_ioctl)(fp, com, data32, l);
    577 #endif
    578 		break;
    579 	}
    580 
    581 	if (error == EPASSTHROUGH)
    582 		error = ENOTTY;
    583 
    584 	/*
    585 	 * Copy any data to user, size was
    586 	 * already set and checked above.
    587 	 */
    588 	if (error == 0 && (com&IOC_OUT) && size32) {
    589 		error = copyout(data32, SCARG_P32(uap, data), size32);
    590 #ifdef KTRACE
    591 		if (KTRPOINT(p, KTR_GENIO)) {
    592 			struct iovec iov;
    593 			iov.iov_base = SCARG_P32(uap, data);
    594 			iov.iov_len = size32;
    595 			ktrgenio(l, SCARG(uap, fd), UIO_READ, &iov,
    596 			    size32, error);
    597 		}
    598 #endif
    599 	}
    600 
    601 	/* if we malloced data, free it here */
    602 	if (memp32)
    603 		free(memp32, M_IOCTLOPS);
    604 	if (memp)
    605 		free(memp, M_IOCTLOPS);
    606 
    607  out:
    608 	FILE_UNUSE(fp, l);
    609 	return (error);
    610 }
    611