Home | History | Annotate | Line # | Download | only in netbsd32
netbsd32_ioctl.c revision 1.105
      1 /*	$NetBSD: netbsd32_ioctl.c,v 1.105 2019/11/18 04:09:53 rin 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.105 2019/11/18 04:09:53 rin Exp $");
     35 
     36 #if defined(_KERNEL_OPT)
     37 #include "opt_ntp.h"
     38 #endif
     39 
     40 #include <sys/param.h>
     41 #include <sys/systm.h>
     42 #include <sys/filedesc.h>
     43 #include <sys/ioctl.h>
     44 #include <sys/file.h>
     45 #include <sys/proc.h>
     46 #include <sys/socketvar.h>
     47 #include <sys/audioio.h>
     48 #include <sys/disklabel.h>
     49 #include <sys/dkio.h>
     50 #include <sys/ataio.h>
     51 #include <sys/sockio.h>
     52 #include <sys/socket.h>
     53 #include <sys/ttycom.h>
     54 #include <sys/mount.h>
     55 #include <sys/syscallargs.h>
     56 #include <sys/ktrace.h>
     57 #include <sys/kmem.h>
     58 #include <sys/envsys.h>
     59 #include <sys/wdog.h>
     60 #include <sys/clockctl.h>
     61 #include <sys/exec_elf.h>
     62 #include <sys/ksyms.h>
     63 #include <sys/drvctlio.h>
     64 #include <sys/compat_stub.h>
     65 
     66 #ifdef __sparc__
     67 #include <dev/sun/fbio.h>
     68 #include <machine/openpromio.h>
     69 #endif
     70 
     71 #include <net/if.h>
     72 #include <net/route.h>
     73 
     74 #include <net/if_pppoe.h>
     75 #include <net/if_sppp.h>
     76 
     77 #include <net/bpf.h>
     78 #include <netinet/in.h>
     79 #include <netinet/in_var.h>
     80 #include <netinet/igmp.h>
     81 #include <netinet/igmp_var.h>
     82 #include <netinet/ip_mroute.h>
     83 
     84 #include <compat/sys/sockio.h>
     85 
     86 #include <compat/netbsd32/netbsd32.h>
     87 #include <compat/netbsd32/netbsd32_ioctl.h>
     88 #include <compat/netbsd32/netbsd32_syscallargs.h>
     89 #include <compat/netbsd32/netbsd32_conv.h>
     90 
     91 #include <dev/vndvar.h>
     92 
     93 /* convert to/from different structures */
     94 
     95 #if 0
     96 static inline void
     97 netbsd32_to_format_op(struct netbsd32_format_op *s32p,
     98     struct format_op *p, u_long cmd)
     99 {
    100 
    101 	p->df_buf = (char *)NETBSD32PTR64(s32p->df_buf);
    102 	p->df_count = s32p->df_count;
    103 	p->df_startblk = s32p->df_startblk;
    104 	memcpy(p->df_reg, s32p->df_reg, sizeof(s32p->df_reg));
    105 }
    106 #endif
    107 
    108 static inline void
    109 netbsd32_to_ifreq(struct netbsd32_ifreq *s32p, struct ifreq *p, u_long cmd)
    110 {
    111 
    112 	memcpy(p, s32p, sizeof *s32p);
    113 	/*
    114 	 * XXX
    115 	 * struct ifreq says the same, but sometimes the ifr_data
    116 	 * union member needs to be converted to 64 bits... this
    117 	 * is very driver specific and so we ignore it for now..
    118 	 */
    119 	switch (cmd) {
    120 	case SIOCGIFDATA:
    121 	case SIOCZIFDATA:
    122 	case SIOCGIFGENERIC:
    123 	case SIOCSIFGENERIC:
    124 		p->ifr_data = (void *)NETBSD32PTR64(s32p->ifr_data);
    125 		break;
    126 	}
    127 }
    128 
    129 static inline void
    130 netbsd32_to_oifreq(struct netbsd32_oifreq *s32p, struct oifreq *p, u_long cmd)
    131 {
    132 
    133 	memcpy(p, s32p, sizeof *s32p);
    134 	/*
    135 	 * XXX
    136 	 * struct ifreq says the same, but sometimes the ifr_data
    137 	 * union member needs to be converted to 64 bits... this
    138 	 * is very driver specific and so we ignore it for now..
    139 	 */
    140 	if (cmd == SIOCGIFDATA || cmd == SIOCZIFDATA)
    141 		p->ifr_data = (void *)NETBSD32PTR64(s32p->ifr_data);
    142 }
    143 
    144 static inline void
    145 netbsd32_to_if_addrprefreq(const struct netbsd32_if_addrprefreq *ifap32,
    146     struct if_addrprefreq *ifap, u_long cmd)
    147 {
    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 	    uimin(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,
    166     struct ifmediareq *p, u_long cmd)
    167 {
    168 
    169 	memcpy(p, s32p, sizeof *s32p);
    170 	p->ifm_ulist = (int *)NETBSD32PTR64(s32p->ifm_ulist);
    171 }
    172 
    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 
    186 static inline void
    187 netbsd32_to_spppauthcfg(struct netbsd32_spppauthcfg *s32p,
    188     struct spppauthcfg *p, u_long cmd)
    189 {
    190 
    191 	memcpy(p->ifname, s32p->ifname, sizeof p->ifname);
    192 	p->hisauth = s32p->hisauth;
    193 	p->myauth = s32p->myauth;
    194 	p->myname_length = s32p->myname_length;
    195 	p->mysecret_length = s32p->mysecret_length;
    196 	p->hisname_length = s32p->hisname_length;
    197 	p->hissecret_length = s32p->hissecret_length;
    198 	p->myauthflags = s32p->myauthflags;
    199 	p->hisauthflags = s32p->hisauthflags;
    200 	p->myname = (char *)NETBSD32PTR64(s32p->myname);
    201 	p->mysecret = (char *)NETBSD32PTR64(s32p->mysecret);
    202 	p->hisname = (char *)NETBSD32PTR64(s32p->hisname);
    203 	p->hissecret = (char *)NETBSD32PTR64(s32p->hissecret);
    204 }
    205 
    206 static inline void
    207 netbsd32_to_ifdrv(struct netbsd32_ifdrv *s32p, struct ifdrv *p, u_long cmd)
    208 {
    209 
    210 	memcpy(p->ifd_name, s32p->ifd_name, sizeof p->ifd_name);
    211 	p->ifd_cmd = s32p->ifd_cmd;
    212 	p->ifd_len = s32p->ifd_len;
    213 	p->ifd_data = (void *)NETBSD32PTR64(s32p->ifd_data);
    214 }
    215 
    216 static inline void
    217 netbsd32_to_sioc_vif_req(struct netbsd32_sioc_vif_req *s32p,
    218     struct sioc_vif_req *p, u_long cmd)
    219 {
    220 
    221 	p->vifi = s32p->vifi;
    222 	p->icount = (u_long)s32p->icount;
    223 	p->ocount = (u_long)s32p->ocount;
    224 	p->ibytes = (u_long)s32p->ibytes;
    225 	p->obytes = (u_long)s32p->obytes;
    226 }
    227 
    228 static inline void
    229 netbsd32_to_sioc_sg_req(struct netbsd32_sioc_sg_req *s32p,
    230     struct sioc_sg_req *p, u_long cmd)
    231 {
    232 
    233 	p->src = s32p->src;
    234 	p->grp = s32p->grp;
    235 	p->pktcnt = (u_long)s32p->pktcnt;
    236 	p->bytecnt = (u_long)s32p->bytecnt;
    237 	p->wrong_if = (u_long)s32p->wrong_if;
    238 }
    239 
    240 static inline void
    241 netbsd32_to_atareq(struct netbsd32_atareq *s32p, struct atareq *p, u_long cmd)
    242 {
    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,
    260     struct vnd_ioctl *p, u_long cmd)
    261 {
    262 
    263 	p->vnd_file = (char *)NETBSD32PTR64(s32p->vnd_file);
    264 	p->vnd_flags = s32p->vnd_flags;
    265 	p->vnd_geom = s32p->vnd_geom;
    266 	p->vnd_osize = s32p->vnd_osize;
    267 	p->vnd_size = s32p->vnd_size;
    268 }
    269 
    270 static inline void
    271 netbsd32_to_vnd_user(struct netbsd32_vnd_user *s32p,
    272     struct vnd_user *p, u_long cmd)
    273 {
    274 
    275 	p->vnu_unit = s32p->vnu_unit;
    276 	p->vnu_dev = s32p->vnu_dev;
    277 	p->vnu_ino = s32p->vnu_ino;
    278 }
    279 
    280 static inline void
    281 netbsd32_to_vnd_ioctl50(struct netbsd32_vnd_ioctl50 *s32p,
    282     struct vnd_ioctl50 *p, u_long cmd)
    283 {
    284 
    285 	p->vnd_file = (char *)NETBSD32PTR64(s32p->vnd_file);
    286 	p->vnd_flags = s32p->vnd_flags;
    287 	p->vnd_geom = s32p->vnd_geom;
    288 	p->vnd_size = s32p->vnd_size;
    289 }
    290 
    291 static inline void
    292 netbsd32_to_plistref(struct netbsd32_plistref *s32p,
    293     struct plistref *p, u_long cmd)
    294 {
    295 
    296 	p->pref_plist = NETBSD32PTR64(s32p->pref_plist);
    297 	p->pref_len = s32p->pref_len;
    298 }
    299 
    300 static inline void
    301 netbsd32_to_nvlist_ref_t(netbsd32_nvlist_ref_t *s32p,
    302     nvlist_ref_t *p, u_long cmd)
    303 {
    304 
    305 	p->buf = NETBSD32PTR64(s32p->buf);
    306 	p->len = s32p->len;
    307 	p->flags = s32p->flags;
    308 }
    309 
    310 static inline void
    311 netbsd32_to_u_long(netbsd32_u_long *s32p, u_long *p, u_long cmd)
    312 {
    313 
    314 	*p = (u_long)*s32p;
    315 }
    316 
    317 static inline void
    318 netbsd32_to_voidp(netbsd32_voidp *s32p, voidp *p, u_long cmd)
    319 {
    320 
    321 	*p = (void *)NETBSD32PTR64(*s32p);
    322 }
    323 
    324 static inline void
    325 netbsd32_to_wdog_conf(struct netbsd32_wdog_conf *s32p,
    326     struct wdog_conf *p, u_long cmd)
    327 {
    328 
    329 	p->wc_names = (char *)NETBSD32PTR64(s32p->wc_names);
    330 	p->wc_count = s32p->wc_count;
    331 }
    332 
    333 static inline void
    334 netbsd32_to_npf_ioctl_table(const struct netbsd32_npf_ioctl_table *s32p,
    335     struct npf_ioctl_table *p, u_long cmd)
    336 {
    337 
    338        p->nct_cmd = s32p->nct_cmd;
    339        p->nct_name = NETBSD32PTR64(s32p->nct_name);
    340        switch (s32p->nct_cmd) {
    341        case NPF_CMD_TABLE_LOOKUP:
    342        case NPF_CMD_TABLE_ADD:
    343        case NPF_CMD_TABLE_REMOVE:
    344                p->nct_data.ent = s32p->nct_data.ent;
    345                break;
    346        case NPF_CMD_TABLE_LIST:
    347                p->nct_data.buf.buf = NETBSD32PTR64(s32p->nct_data.buf.buf);
    348                p->nct_data.buf.len = s32p->nct_data.buf.len;
    349                break;
    350        }
    351 }
    352 
    353 static inline void
    354 netbsd32_to_bpf_program(struct netbsd32_bpf_program *s32p,
    355     struct bpf_program *p, u_long cmd)
    356 {
    357 
    358 	p->bf_insns = (void *)NETBSD32PTR64(s32p->bf_insns);
    359 	p->bf_len = s32p->bf_len;
    360 }
    361 
    362 static inline void
    363 netbsd32_to_bpf_dltlist(struct netbsd32_bpf_dltlist *s32p,
    364     struct bpf_dltlist *p, u_long cmd)
    365 {
    366 
    367 	p->bfl_list = (void *)NETBSD32PTR64(s32p->bfl_list);
    368 	p->bfl_len = s32p->bfl_len;
    369 }
    370 
    371 /* wsdisplay stuff */
    372 static inline void
    373 netbsd32_to_wsdisplay_addscreendata(
    374     struct netbsd32_wsdisplay_addscreendata *asd32,
    375     struct wsdisplay_addscreendata *asd, u_long cmd)
    376 {
    377 
    378 	asd->screentype = (char *)NETBSD32PTR64(asd32->screentype);
    379 	asd->emul = (char *)NETBSD32PTR64(asd32->emul);
    380 	asd->idx = asd32->idx;
    381 }
    382 
    383 static inline void
    384 netbsd32_to_ieee80211req(struct netbsd32_ieee80211req *ireq32,
    385     struct ieee80211req *ireq, u_long cmd)
    386 {
    387 
    388 	strlcpy(ireq->i_name, ireq32->i_name, IFNAMSIZ);
    389 	ireq->i_type = ireq32->i_type;
    390 	ireq->i_val = ireq32->i_val;
    391 	ireq->i_len = ireq32->i_len;
    392 	ireq->i_data = NETBSD32PTR64(ireq32->i_data);
    393 }
    394 
    395 static inline void
    396 netbsd32_to_ieee80211_nwkey(struct netbsd32_ieee80211_nwkey *nwk32,
    397     struct ieee80211_nwkey *nwk, u_long cmd)
    398 {
    399 	int i;
    400 
    401 	strlcpy(nwk->i_name, nwk32->i_name, IFNAMSIZ);
    402 	nwk->i_wepon = nwk32->i_wepon;
    403 	nwk->i_defkid = nwk32->i_defkid;
    404 	for (i = 0; i < IEEE80211_WEP_NKID; i++) {
    405 		nwk->i_key[i].i_keylen = nwk32->i_key[i].i_keylen;
    406 		nwk->i_key[i].i_keydat =
    407 		    NETBSD32PTR64(nwk32->i_key[i].i_keydat);
    408 	}
    409 }
    410 
    411 static inline void
    412 netbsd32_to_wsdisplay_cursor(struct netbsd32_wsdisplay_cursor *c32,
    413     struct wsdisplay_cursor *c, u_long cmd)
    414 {
    415 
    416 	c->which = c32->which;
    417 	c->enable = c32->enable;
    418 	c->pos.x = c32->pos.x;
    419 	c->pos.y = c32->pos.y;
    420 	c->hot.x = c32->hot.x;
    421 	c->hot.y = c32->hot.y;
    422 	c->size.x = c32->size.x;
    423 	c->size.y = c32->size.y;
    424 	c->cmap.index = c32->cmap.index;
    425 	c->cmap.count = c32->cmap.count;
    426 	c->cmap.red = NETBSD32PTR64(c32->cmap.red);
    427 	c->cmap.green = NETBSD32PTR64(c32->cmap.green);
    428 	c->cmap.blue = NETBSD32PTR64(c32->cmap.blue);
    429 	c->image = NETBSD32PTR64(c32->image);
    430 	c->mask = NETBSD32PTR64(c32->mask);
    431 }
    432 
    433 static inline void
    434 netbsd32_to_wsdisplay_cmap(struct netbsd32_wsdisplay_cmap *c32,
    435     struct wsdisplay_cmap *c, u_long cmd)
    436 {
    437 
    438 	c->index = c32->index;
    439 	c->count = c32->count;
    440 	c->red   = NETBSD32PTR64(c32->red);
    441 	c->green = NETBSD32PTR64(c32->green);
    442 	c->blue  = NETBSD32PTR64(c32->blue);
    443 }
    444 
    445 static inline void
    446 netbsd32_to_wsdisplay_font(struct netbsd32_wsdisplay_font *f32,
    447     struct wsdisplay_font *f, u_long cmd)
    448 {
    449 
    450 	f->name = NETBSD32PTR64(f32->name);
    451 	f->firstchar = f32->firstchar;
    452 	f->numchars = f32->numchars;
    453 	f->encoding = f32->encoding;
    454 	f->fontwidth = f32->fontwidth;
    455 	f->fontheight = f32->fontheight;
    456 	f->stride = f32->stride;
    457 	f->bitorder = f32->bitorder;
    458 	f->byteorder = f32->byteorder;
    459 	f->data = NETBSD32PTR64(f32->data);
    460 }
    461 
    462 static inline void
    463 netbsd32_to_wsdisplay_usefontdata(struct netbsd32_wsdisplay_usefontdata *f32,
    464     struct wsdisplay_usefontdata *f, u_long cmd)
    465 {
    466 
    467 	f->name = NETBSD32PTR64(f32->name);
    468 }
    469 
    470 static inline void
    471 netbsd32_to_clockctl_settimeofday(
    472     const struct netbsd32_clockctl_settimeofday *s32p,
    473     struct clockctl_settimeofday *p, u_long cmd)
    474 {
    475 
    476 	p->tv = NETBSD32PTR64(s32p->tv);
    477 	p->tzp = NETBSD32PTR64(s32p->tzp);
    478 }
    479 
    480 static inline void
    481 netbsd32_to_clockctl_adjtime(
    482     const struct netbsd32_clockctl_adjtime *s32p,
    483     struct clockctl_adjtime *p, u_long cmd)
    484 {
    485 
    486 	p->delta = NETBSD32PTR64(s32p->delta);
    487 	p->olddelta = NETBSD32PTR64(s32p->olddelta);
    488 }
    489 
    490 static inline void
    491 netbsd32_to_clockctl_clock_settime(
    492     const struct netbsd32_clockctl_clock_settime *s32p,
    493     struct clockctl_clock_settime *p, u_long cmd)
    494 {
    495 
    496 	p->clock_id = s32p->clock_id;
    497 	p->tp = NETBSD32PTR64(s32p->tp);
    498 }
    499 
    500 #ifdef NTP
    501 static inline void
    502 netbsd32_to_clockctl_ntp_adjtime(
    503     const struct netbsd32_clockctl_ntp_adjtime *s32p,
    504     struct clockctl_ntp_adjtime *p, u_long cmd)
    505 {
    506 
    507 	p->tp = NETBSD32PTR64(s32p->tp);
    508 	p->retval = s32p->retval;
    509 }
    510 #endif
    511 
    512 static inline void
    513 netbsd32_to_ksyms_gsymbol(const struct netbsd32_ksyms_gsymbol *s32p,
    514     struct ksyms_gsymbol *p, u_long cmd)
    515 {
    516 
    517 	p->kg_name = NETBSD32PTR64(s32p->kg_name);
    518 }
    519 
    520 static inline void
    521 netbsd32_to_ksyms_gvalue(const struct netbsd32_ksyms_gvalue *s32p,
    522     struct ksyms_gvalue *p, u_long cmd)
    523 {
    524 
    525 	p->kv_name = NETBSD32PTR64(s32p->kv_name);
    526 }
    527 
    528 static inline void
    529 netbsd32_to_devlistargs(const struct netbsd32_devlistargs *s32p,
    530     struct devlistargs *p, u_long cmd)
    531 {
    532 
    533 	memcpy(p->l_devname, s32p->l_devname, sizeof(p->l_devname));
    534 	p->l_children = s32p->l_children;
    535 	p->l_childname = NETBSD32PTR64(s32p->l_childname);
    536 }
    537 
    538 static inline void
    539 netbsd32_to_devrescanargs(const struct netbsd32_devrescanargs *s32p,
    540     struct devrescanargs *p, u_long cmd)
    541 {
    542 
    543 	memcpy(p->busname, s32p->busname, sizeof(p->busname));
    544 	memcpy(p->ifattr, s32p->ifattr, sizeof(p->ifattr));
    545 	p->numlocators = s32p->numlocators;
    546 	p->locators = NETBSD32PTR64(s32p->locators);
    547 }
    548 
    549 static inline void
    550 netbsd32_to_disk_strategy(const struct netbsd32_disk_strategy *s32p,
    551     struct disk_strategy *p, u_long cmd)
    552 {
    553 
    554 	memcpy(p->dks_name, s32p->dks_name, sizeof(p->dks_name));
    555 	p->dks_param = NETBSD32PTR64(s32p->dks_param);
    556 	p->dks_paramlen = s32p->dks_paramlen;
    557 }
    558 
    559 static inline void
    560 netbsd32_to_dkwedge_list(const struct netbsd32_dkwedge_list *s32p,
    561     struct dkwedge_list *p, u_long cmd)
    562 {
    563 
    564 	p->dkwl_buf = NETBSD32PTR64(s32p->dkwl_buf);
    565 	p->dkwl_bufsize = s32p->dkwl_bufsize;
    566 	p->dkwl_nwedges = s32p->dkwl_nwedges;
    567 	p->dkwl_ncopied = s32p->dkwl_ncopied;
    568 }
    569 
    570 /*
    571  * handle ioctl conversions from 64-bit kernel -> netbsd32
    572  */
    573 
    574 #if 0
    575 static inline void
    576 netbsd32_from_format_op(struct format_op *p,
    577     struct netbsd32_format_op *s32p, u_long cmd)
    578 {
    579 
    580 /* filled in */
    581 #if 0
    582 	s32p->df_buf = (netbsd32_charp)p->df_buf;
    583 #endif
    584 	s32p->df_count = p->df_count;
    585 	s32p->df_startblk = p->df_startblk;
    586 	memcpy(s32p->df_reg, p->df_reg, sizeof(p->df_reg));
    587 }
    588 #endif
    589 
    590 static inline void
    591 netbsd32_from_ifreq(struct ifreq *p, struct netbsd32_ifreq *s32p, u_long cmd)
    592 {
    593 
    594 	/*
    595 	 * XXX
    596 	 * struct ifreq says the same, but sometimes the ifr_data
    597 	 * union member needs to be converted to 64 bits... this
    598 	 * is very driver specific and so we ignore it for now..
    599 	 */
    600 	memcpy(s32p, p, sizeof *s32p);
    601 	switch (cmd) {
    602 	case SIOCGIFDATA:
    603 	case SIOCZIFDATA:
    604 	case SIOCGIFGENERIC:
    605 	case SIOCSIFGENERIC:
    606 		NETBSD32PTR32(s32p->ifr_data, p->ifr_data);
    607 		break;
    608 	}
    609 }
    610 
    611 static inline void
    612 netbsd32_from_oifreq(struct oifreq *p,
    613     struct netbsd32_oifreq *s32p, u_long cmd)
    614 {
    615 
    616 	/*
    617 	 * XXX
    618 	 * struct ifreq says the same, but sometimes the ifr_data
    619 	 * union member needs to be converted to 64 bits... this
    620 	 * is very driver specific and so we ignore it for now..
    621 	 */
    622 	memcpy(s32p, p, sizeof *s32p);
    623 	if (cmd == SIOCGIFDATA || cmd == SIOCZIFDATA)
    624 		NETBSD32PTR32(s32p->ifr_data, p->ifr_data);
    625 }
    626 
    627 static inline void
    628 netbsd32_from_if_addrprefreq(const struct if_addrprefreq *ifap,
    629     struct netbsd32_if_addrprefreq *ifap32, u_long cmd)
    630 {
    631 
    632 	strlcpy(ifap32->ifap_name, ifap->ifap_name, sizeof(ifap32->ifap_name));
    633 	ifap32->ifap_preference = ifap->ifap_preference;
    634 	memcpy(&ifap32->ifap_addr, &ifap->ifap_addr,
    635 	    uimin(ifap->ifap_addr.ss_len, _SS_MAXSIZE));
    636 }
    637 
    638 static inline void
    639 netbsd32_from_ifconf(struct ifconf *p,
    640     struct netbsd32_ifconf *s32p, u_long cmd)
    641 {
    642 
    643 	s32p->ifc_len = p->ifc_len;
    644 	/* ifc_buf & ifc_req are the same size so this works */
    645 	NETBSD32PTR32(s32p->ifc_buf, p->ifc_buf);
    646 }
    647 
    648 static inline void
    649 netbsd32_from_ifmediareq(struct ifmediareq *p,
    650     struct netbsd32_ifmediareq *s32p, u_long cmd)
    651 {
    652 
    653 	memcpy(s32p, p, sizeof *p);
    654 /* filled in? */
    655 #if 0
    656 	s32p->ifm_ulist = (netbsd32_intp_t)p->ifm_ulist;
    657 #endif
    658 }
    659 
    660 static inline void
    661 netbsd32_from_pppoediscparms(struct pppoediscparms *p,
    662     struct netbsd32_pppoediscparms *s32p, u_long cmd)
    663 {
    664 
    665 	memcpy(s32p->ifname, p->ifname, sizeof s32p->ifname);
    666 	memcpy(s32p->eth_ifname, p->eth_ifname, sizeof s32p->eth_ifname);
    667 	NETBSD32PTR32(s32p->ac_name, p->ac_name);
    668 	s32p->ac_name_len = p->ac_name_len;
    669 	NETBSD32PTR32(s32p->service_name, p->service_name);
    670 	s32p->service_name_len = p->service_name_len;
    671 }
    672 
    673 static inline void
    674 netbsd32_from_spppauthcfg(struct spppauthcfg *p,
    675     struct netbsd32_spppauthcfg *s32p, u_long cmd)
    676 {
    677 
    678 	memcpy(s32p->ifname, p->ifname, sizeof s32p->ifname);
    679 	s32p->hisauth = p->hisauth;
    680 	s32p->myauth = p->myauth;
    681 	s32p->myname_length = p->myname_length;
    682 	s32p->mysecret_length = p->mysecret_length;
    683 	s32p->hisname_length = p->hisname_length;
    684 	s32p->hissecret_length = p->hissecret_length;
    685 	s32p->myauthflags = p->myauthflags;
    686 	s32p->hisauthflags = p->hisauthflags;
    687 	NETBSD32PTR32(s32p->myname, p->myname);
    688 	NETBSD32PTR32(s32p->mysecret, p->mysecret);
    689 	NETBSD32PTR32(s32p->hisname, p->hisname);
    690 	NETBSD32PTR32(s32p->hissecret, p->hissecret);
    691 }
    692 
    693 static inline void
    694 netbsd32_from_ifdrv(struct ifdrv *p, struct netbsd32_ifdrv *s32p, u_long cmd)
    695 {
    696 
    697 	memcpy(s32p->ifd_name, p->ifd_name, sizeof s32p->ifd_name);
    698 	s32p->ifd_cmd = p->ifd_cmd;
    699 	s32p->ifd_len = p->ifd_len;
    700 	NETBSD32PTR32(s32p->ifd_data, p->ifd_data);
    701 }
    702 
    703 static inline void
    704 netbsd32_from_sioc_vif_req(struct sioc_vif_req *p,
    705     struct netbsd32_sioc_vif_req *s32p, u_long cmd)
    706 {
    707 
    708 	s32p->vifi = p->vifi;
    709 	s32p->icount = (netbsd32_u_long)p->icount;
    710 	s32p->ocount = (netbsd32_u_long)p->ocount;
    711 	s32p->ibytes = (netbsd32_u_long)p->ibytes;
    712 	s32p->obytes = (netbsd32_u_long)p->obytes;
    713 }
    714 
    715 static inline void
    716 netbsd32_from_sioc_sg_req(struct sioc_sg_req *p,
    717     struct netbsd32_sioc_sg_req *s32p, u_long cmd)
    718 {
    719 
    720 	s32p->src = p->src;
    721 	s32p->grp = p->grp;
    722 	s32p->pktcnt = (netbsd32_u_long)p->pktcnt;
    723 	s32p->bytecnt = (netbsd32_u_long)p->bytecnt;
    724 	s32p->wrong_if = (netbsd32_u_long)p->wrong_if;
    725 }
    726 
    727 static inline void
    728 netbsd32_from_atareq(struct atareq *p,
    729     struct netbsd32_atareq *s32p, u_long cmd)
    730 {
    731 
    732 	s32p->flags = (netbsd32_u_long)p->flags;
    733 	s32p->command = p->command;
    734 	s32p->features = p->features;
    735 	s32p->sec_count = p->sec_count;
    736 	s32p->sec_num = p->sec_num;
    737 	s32p->head = p->head;
    738 	s32p->cylinder = p->cylinder;
    739 	NETBSD32PTR32(s32p->databuf, p->databuf);
    740 	s32p->datalen = (netbsd32_u_long)p->datalen;
    741 	s32p->timeout = p->timeout;
    742 	s32p->retsts = p->retsts;
    743 	s32p->error = p->error;
    744 }
    745 
    746 static inline void
    747 netbsd32_from_vnd_ioctl(struct vnd_ioctl *p,
    748     struct netbsd32_vnd_ioctl *s32p, u_long cmd)
    749 {
    750 
    751 	s32p->vnd_flags = p->vnd_flags;
    752 	s32p->vnd_geom = p->vnd_geom;
    753 	s32p->vnd_osize = p->vnd_osize;
    754 	s32p->vnd_size = p->vnd_size;
    755 }
    756 
    757 static inline void
    758 netbsd32_from_vnd_user(struct vnd_user *p,
    759     struct netbsd32_vnd_user *s32p, u_long cmd)
    760 {
    761 
    762 	s32p->vnu_unit = p->vnu_unit;
    763 	s32p->vnu_dev = p->vnu_dev;
    764 	s32p->vnu_ino = p->vnu_ino;
    765 }
    766 
    767 static inline void
    768 netbsd32_from_vnd_ioctl50(struct vnd_ioctl50 *p,
    769     struct netbsd32_vnd_ioctl50 *s32p, u_long cmd)
    770 {
    771 
    772 	s32p->vnd_flags = p->vnd_flags;
    773 	s32p->vnd_geom = p->vnd_geom;
    774 	s32p->vnd_size = p->vnd_size;
    775 }
    776 
    777 static inline void
    778 netbsd32_from_plistref(struct plistref *p,
    779     struct netbsd32_plistref *s32p, u_long cmd)
    780 {
    781 
    782 	NETBSD32PTR32(s32p->pref_plist, p->pref_plist);
    783 	s32p->pref_len = p->pref_len;
    784 }
    785 
    786 static inline void
    787 netbsd32_from_nvlist_ref_t(nvlist_ref_t *p,
    788     netbsd32_nvlist_ref_t *s32p, u_long cmd)
    789 {
    790 
    791 	NETBSD32PTR32(s32p->buf, p->buf);
    792 	s32p->len = p->len;
    793 	s32p->flags = p->flags;
    794 }
    795 
    796 static inline void
    797 netbsd32_from_wdog_conf(struct wdog_conf *p,
    798     struct netbsd32_wdog_conf *s32p, u_long cmd)
    799 {
    800 
    801 	NETBSD32PTR32(s32p->wc_names, p->wc_names);
    802 	s32p->wc_count = p->wc_count;
    803 }
    804 
    805 /* wsdisplay stuff */
    806 static inline void
    807 netbsd32_from_wsdisplay_addscreendata(struct wsdisplay_addscreendata *asd,
    808     struct netbsd32_wsdisplay_addscreendata *asd32, u_long cmd)
    809 {
    810 
    811 	NETBSD32PTR32(asd32->screentype, asd->screentype);
    812 	NETBSD32PTR32(asd32->emul, asd->emul);
    813 	asd32->idx = asd->idx;
    814 }
    815 
    816 static inline void
    817 netbsd32_from_wsdisplay_cursor(struct wsdisplay_cursor *c,
    818     struct netbsd32_wsdisplay_cursor *c32, u_long cmd)
    819 {
    820 
    821 	c32->which = c->which;
    822 	c32->enable = c->enable;
    823 	c32->pos.x = c->pos.x;
    824 	c32->pos.y = c->pos.y;
    825 	c32->hot.x = c->hot.x;
    826 	c32->hot.y = c->hot.y;
    827 	c32->size.x = c->size.x;
    828 	c32->size.y = c->size.y;
    829 	c32->cmap.index = c->cmap.index;
    830 	c32->cmap.count = c->cmap.count;
    831 	NETBSD32PTR32(c32->cmap.red, c->cmap.red);
    832 	NETBSD32PTR32(c32->cmap.green, c->cmap.green);
    833 	NETBSD32PTR32(c32->cmap.blue, c->cmap.blue);
    834 	NETBSD32PTR32(c32->image, c->image);
    835 	NETBSD32PTR32(c32->mask, c->mask);
    836 }
    837 
    838 static inline void
    839 netbsd32_from_wsdisplay_cmap(struct wsdisplay_cmap *c,
    840     struct netbsd32_wsdisplay_cmap *c32, u_long cmd)
    841 {
    842 
    843 	c32->index = c->index;
    844 	c32->count = c->count;
    845 	NETBSD32PTR32(c32->red, c->red);
    846 	NETBSD32PTR32(c32->green, c->green);
    847 	NETBSD32PTR32(c32->blue, c->blue);
    848 }
    849 
    850 static inline void
    851 netbsd32_from_wsdisplay_font(struct wsdisplay_font *f,
    852     struct netbsd32_wsdisplay_font *f32, u_long cmd)
    853 {
    854 }
    855 
    856 static inline void
    857 netbsd32_from_wsdisplay_usefontdata(struct wsdisplay_usefontdata *f,
    858     struct netbsd32_wsdisplay_usefontdata *f32, u_long cmd)
    859 {
    860 }
    861 
    862 static inline void
    863 netbsd32_from_ieee80211req(struct ieee80211req *ireq,
    864     struct netbsd32_ieee80211req *ireq32, u_long cmd)
    865 {
    866 
    867 	strlcpy(ireq32->i_name, ireq->i_name, IFNAMSIZ);
    868 	ireq32->i_type = ireq->i_type;
    869 	ireq32->i_val = ireq->i_val;
    870 	ireq32->i_len = ireq->i_len;
    871 	NETBSD32PTR32(ireq32->i_data, ireq->i_data);
    872 }
    873 
    874 static inline void
    875 netbsd32_from_ieee80211_nwkey(struct ieee80211_nwkey *nwk,
    876     struct netbsd32_ieee80211_nwkey *nwk32, u_long cmd)
    877 {
    878 	int i;
    879 
    880 	strlcpy(nwk32->i_name, nwk->i_name, IFNAMSIZ);
    881 	nwk32->i_wepon = nwk->i_wepon;
    882 	nwk32->i_defkid = nwk->i_defkid;
    883 	for (i = 0; i < IEEE80211_WEP_NKID; i++) {
    884 		nwk32->i_key[i].i_keylen = nwk->i_key[i].i_keylen;
    885 		NETBSD32PTR32(nwk32->i_key[i].i_keydat,
    886 				nwk->i_key[i].i_keydat);
    887 	}
    888 }
    889 
    890 static inline void
    891 netbsd32_from_bpf_program(struct bpf_program *p,
    892     struct netbsd32_bpf_program *s32p, u_long cmd)
    893 {
    894 
    895 	NETBSD32PTR32(s32p->bf_insns, p->bf_insns);
    896 	s32p->bf_len = p->bf_len;
    897 }
    898 
    899 static inline void
    900 netbsd32_from_bpf_dltlist(struct bpf_dltlist *p,
    901     struct netbsd32_bpf_dltlist *s32p, u_long cmd)
    902 {
    903 
    904 	NETBSD32PTR32(s32p->bfl_list, p->bfl_list);
    905 	s32p->bfl_len = p->bfl_len;
    906 }
    907 
    908 static inline void
    909 netbsd32_from_u_long(u_long *p, netbsd32_u_long *s32p, u_long cmd)
    910 {
    911 
    912 	*s32p = (netbsd32_u_long)*p;
    913 }
    914 
    915 static inline void
    916 netbsd32_from_voidp(voidp *p, netbsd32_voidp *s32p, u_long cmd)
    917 {
    918 
    919 	NETBSD32PTR32(*s32p, *p);
    920 }
    921 
    922 static inline void
    923 netbsd32_from_clockctl_settimeofday(const struct clockctl_settimeofday *p,
    924     struct netbsd32_clockctl_settimeofday *s32p, u_long cmd)
    925 {
    926 
    927 	NETBSD32PTR32(s32p->tv, p->tv);
    928 	NETBSD32PTR32(s32p->tzp, p->tzp);
    929 }
    930 
    931 static inline void
    932 netbsd32_from_clockctl_adjtime(const struct clockctl_adjtime *p,
    933     struct netbsd32_clockctl_adjtime *s32p, u_long cmd)
    934 {
    935 
    936 	NETBSD32PTR32(s32p->delta, p->delta);
    937 	NETBSD32PTR32(s32p->olddelta, p->olddelta);
    938 }
    939 
    940 static inline void
    941 netbsd32_from_clockctl_clock_settime(const struct clockctl_clock_settime *p,
    942     struct netbsd32_clockctl_clock_settime *s32p, u_long cmd)
    943 {
    944 
    945 	s32p->clock_id = p->clock_id;
    946 	NETBSD32PTR32(s32p->tp, p->tp);
    947 }
    948 
    949 #ifdef NTP
    950 static inline void
    951 netbsd32_from_clockctl_ntp_adjtime(const struct clockctl_ntp_adjtime *p,
    952     struct netbsd32_clockctl_ntp_adjtime *s32p, u_long cmd)
    953 {
    954 
    955 	NETBSD32PTR32(s32p->tp, p->tp);
    956 	s32p->retval = p->retval;
    957 }
    958 #endif
    959 
    960 static inline void
    961 netbsd32_from_ksyms_gsymbol( const struct ksyms_gsymbol *p,
    962     struct netbsd32_ksyms_gsymbol *s32p, u_long cmd)
    963 {
    964 
    965 	NETBSD32PTR32(s32p->kg_name, p->kg_name);
    966 	s32p->kg_sym = p->kg_sym;
    967 }
    968 
    969 static inline void
    970 netbsd32_from_ksyms_gvalue(
    971     const struct ksyms_gvalue *p,
    972     struct netbsd32_ksyms_gvalue *s32p, u_long cmd)
    973 {
    974 
    975 	NETBSD32PTR32(s32p->kv_name, p->kv_name);
    976 	s32p->kv_value = p->kv_value;
    977 }
    978 
    979 static inline void
    980 netbsd32_from_npf_ioctl_table(const struct npf_ioctl_table *p,
    981     struct netbsd32_npf_ioctl_table *s32p, u_long cmd)
    982 {
    983 
    984        s32p->nct_cmd = p->nct_cmd;
    985        NETBSD32PTR32(s32p->nct_name, p->nct_name);
    986        switch (p->nct_cmd) {
    987        case NPF_CMD_TABLE_LOOKUP:
    988        case NPF_CMD_TABLE_ADD:
    989        case NPF_CMD_TABLE_REMOVE:
    990                s32p->nct_data.ent = p->nct_data.ent;
    991                break;
    992        case NPF_CMD_TABLE_LIST:
    993                NETBSD32PTR32(s32p->nct_data.buf.buf, p->nct_data.buf.buf);
    994                s32p->nct_data.buf.len = p->nct_data.buf.len;
    995                break;
    996        }
    997 }
    998 
    999 static inline void
   1000 netbsd32_from_devlistargs(const struct devlistargs *p,
   1001     struct netbsd32_devlistargs *s32p, u_long cmd)
   1002 {
   1003 
   1004 	memcpy(s32p->l_devname, p->l_devname, sizeof(s32p->l_devname));
   1005 	s32p->l_children = p->l_children;
   1006 	NETBSD32PTR32(s32p->l_childname, p->l_childname);
   1007 }
   1008 
   1009 static inline void
   1010 netbsd32_from_devrescanargs(const struct devrescanargs *p,
   1011     struct netbsd32_devrescanargs *s32p, u_long cmd)
   1012 {
   1013 
   1014 	memcpy(s32p->busname, p->busname, sizeof(s32p->busname));
   1015 	memcpy(s32p->ifattr, p->ifattr, sizeof(s32p->ifattr));
   1016 	s32p->numlocators = p->numlocators;
   1017 	NETBSD32PTR32(s32p->locators, p->locators);
   1018 }
   1019 
   1020 static inline void
   1021 netbsd32_from_disk_strategy(const struct disk_strategy *p,
   1022     struct netbsd32_disk_strategy *s32p, u_long cmd)
   1023 {
   1024 
   1025 	memcpy(s32p->dks_name, p->dks_name, sizeof(p->dks_name));
   1026 	NETBSD32PTR32(s32p->dks_param, p->dks_param);
   1027 	s32p->dks_paramlen = p->dks_paramlen;
   1028 }
   1029 
   1030 static inline void
   1031 netbsd32_from_dkwedge_list(const struct dkwedge_list *p,
   1032     struct netbsd32_dkwedge_list *s32p, u_long cmd)
   1033 {
   1034 
   1035 	NETBSD32PTR32(s32p->dkwl_buf, p->dkwl_buf);
   1036 	s32p->dkwl_bufsize = p->dkwl_bufsize;
   1037 	s32p->dkwl_nwedges = p->dkwl_nwedges;
   1038 	s32p->dkwl_ncopied = p->dkwl_ncopied;
   1039 }
   1040 
   1041 #ifdef NTP
   1042 static int
   1043 netbsd32_do_clockctl_ntp_adjtime(struct clockctl_ntp_adjtime *args)
   1044 {
   1045 
   1046 	struct netbsd32_timex ntv32;
   1047 	struct timex ntv;
   1048 	int error;
   1049 
   1050 	if (vec_ntp_adjtime1 == NULL)
   1051 		return EINVAL;
   1052 
   1053 	error = copyin(args->tp, &ntv32, sizeof(ntv32));
   1054 	if (error)
   1055 		return error;
   1056 
   1057 	netbsd32_to_timex(&ntv32, &ntv);
   1058 	(*vec_ntp_adjtime1)(&ntv);
   1059 	netbsd32_from_timex(&ntv, &ntv32);
   1060 
   1061 	error = copyout(&ntv32, args->tp, sizeof(ntv));
   1062 	if (error == 0)
   1063 		args->retval = ntp_timestatus();
   1064 
   1065 	return error;
   1066 }
   1067 #endif
   1068 
   1069 #ifdef COMPAT_50
   1070 static void
   1071 netbsd32_ioctl_to_timeval50(
   1072     const struct netbsd32_timeval50 *s32p,
   1073     struct timeval50 *p,
   1074     u_long cmd)
   1075 {
   1076 
   1077 	p->tv_sec = s32p->tv_sec;
   1078 	p->tv_usec = s32p->tv_usec;
   1079 }
   1080 
   1081 static void
   1082 netbsd32_ioctl_from_timeval50(
   1083     const struct timeval50 *p,
   1084     struct netbsd32_timeval50 *s32p,
   1085     u_long cmd)
   1086 {
   1087 
   1088 	s32p->tv_sec = (netbsd32_long)p->tv_sec;
   1089 	s32p->tv_usec = (netbsd32_long)p->tv_usec;
   1090 }
   1091 #endif
   1092 
   1093 /*
   1094  * main ioctl syscall.
   1095  *
   1096  * ok, here we are in the biggy.  we have to do fix ups depending
   1097  * on the ioctl command before and afterwards.
   1098  */
   1099 int
   1100 netbsd32_ioctl(struct lwp *l,
   1101     const struct netbsd32_ioctl_args *uap, register_t *retval)
   1102 {
   1103 	/* {
   1104 		syscallarg(int) fd;
   1105 		syscallarg(netbsd32_u_long) com;
   1106 		syscallarg(netbsd32_voidp) data;
   1107 	} */
   1108 	struct proc *p = l->l_proc;
   1109 	struct file *fp;
   1110 	struct filedesc *fdp;
   1111 	u_long com;
   1112 	int error = 0;
   1113 	size_t size;
   1114 	size_t alloc_size32, size32;
   1115 	void *data, *memp = NULL;
   1116 	void *data32, *memp32 = NULL;
   1117 	unsigned int fd;
   1118 	fdfile_t *ff;
   1119 	int tmp;
   1120 #define STK_PARAMS	128
   1121 	uint64_t stkbuf[STK_PARAMS/sizeof(uint64_t)];
   1122 	uint64_t stkbuf32[STK_PARAMS/sizeof(uint64_t)];
   1123 
   1124 	/*
   1125 	 * we need to translate some commands (_IOW) before calling sys_ioctl,
   1126 	 * some after (_IOR), and some both (_IOWR).
   1127 	 */
   1128 #if 0
   1129 	{
   1130 		const char * const dirs[8] = {
   1131 		    "NONE!", "VOID", "OUT", "VOID|OUT!", "IN", "VOID|IN!",
   1132 		    "INOUT", "VOID|IN|OUT!"
   1133 		};
   1134 
   1135 		printf("netbsd32_ioctl(%d, %x, %x): "
   1136 		    "%s group %c base %d len %d\n",
   1137 		    SCARG(uap, fd), SCARG(uap, com), SCARG(uap, data).i32,
   1138 		    dirs[((SCARG(uap, com) & IOC_DIRMASK)>>29)],
   1139 		    IOCGROUP(SCARG(uap, com)), IOCBASECMD(SCARG(uap, com)),
   1140 		    IOCPARM_LEN(SCARG(uap, com)));
   1141 	}
   1142 #endif
   1143 
   1144 	memp = NULL;
   1145 	memp32 = NULL;
   1146 	alloc_size32 = 0;
   1147 	size32 = 0;
   1148 	size = 0;
   1149 
   1150 	fdp = p->p_fd;
   1151 	fd = SCARG(uap, fd);
   1152 	if ((fp = fd_getfile(fd)) == NULL)
   1153 		return EBADF;
   1154 	if ((fp->f_flag & (FREAD | FWRITE)) == 0) {
   1155 		error = EBADF;
   1156 		goto out;
   1157 	}
   1158 
   1159 	ff = fdp->fd_dt->dt_ff[SCARG(uap, fd)];
   1160 	switch (com = SCARG(uap, com)) {
   1161 	case FIOCLEX:
   1162 		ff->ff_exclose = true;
   1163 		fdp->fd_exclose = true;
   1164 		goto out;
   1165 
   1166 	case FIONCLEX:
   1167 		ff->ff_exclose = false;
   1168 		goto out;
   1169 	}
   1170 
   1171 	/*
   1172 	 * Interpret high order word to find amount of data to be
   1173 	 * copied to/from the user's address space.
   1174 	 */
   1175 	size32 = IOCPARM_LEN(com);
   1176 	alloc_size32 = size32;
   1177 
   1178 	/*
   1179 	 * The disklabel is now padded to a multiple of 8 bytes however the old
   1180 	 * disklabel on 32bit platforms wasn't.  This leaves a difference in
   1181 	 * size of 4 bytes between the two but are otherwise identical.
   1182 	 * To deal with this, we allocate enough space for the new disklabel
   1183 	 * but only copyin/out the smaller amount.
   1184 	 */
   1185 	if (IOCGROUP(com) == 'd') {
   1186 		u_long ncom = com ^ (DIOCGDINFO ^ DIOCGDINFO32);
   1187 		switch (ncom) {
   1188 		case DIOCGDINFO:
   1189 		case DIOCWDINFO:
   1190 		case DIOCSDINFO:
   1191 		case DIOCGDEFLABEL:
   1192 			com = ncom;
   1193 			if (IOCPARM_LEN(DIOCGDINFO32) < IOCPARM_LEN(DIOCGDINFO))
   1194 				alloc_size32 = IOCPARM_LEN(DIOCGDINFO);
   1195 			break;
   1196 		}
   1197 	}
   1198 	if (alloc_size32 > IOCPARM_MAX) {
   1199 		error = ENOTTY;
   1200 		goto out;
   1201 	}
   1202 	if (alloc_size32 > sizeof(stkbuf)) {
   1203 		memp32 = kmem_alloc(alloc_size32, KM_SLEEP);
   1204 		data32 = memp32;
   1205 	} else
   1206 		data32 = (void *)stkbuf32;
   1207 	if ((com >> IOCPARM_SHIFT) == 0)  {
   1208 		/* UNIX-style ioctl. */
   1209 		data32 = SCARG_P32(uap, data);
   1210 	} else {
   1211 		if (com&IOC_IN) {
   1212 			if (size32) {
   1213 				error = copyin(SCARG_P32(uap, data), data32,
   1214 				    size32);
   1215 				if (error) {
   1216 					goto out;
   1217 				}
   1218 				/*
   1219 				 * The data between size and alloc_size has
   1220 				 * not been overwritten.  It shouldn't matter
   1221 				 * but let's clear that anyway.
   1222 				 */
   1223 				if (__predict_false(size32 < alloc_size32)) {
   1224 					memset((char *)data32+size32, 0,
   1225 					    alloc_size32 - size32);
   1226 				}
   1227 				ktrgenio(fd, UIO_WRITE, SCARG_P32(uap, data),
   1228 				    size32, 0);
   1229 			} else
   1230 				*(void **)data32 = SCARG_P32(uap, data);
   1231 		} else if ((com&IOC_OUT) && size32) {
   1232 			/*
   1233 			 * Zero the buffer so the user always
   1234 			 * gets back something deterministic.
   1235 			 */
   1236 			memset(data32, 0, alloc_size32);
   1237 		} else if (com&IOC_VOID) {
   1238 			*(void **)data32 = SCARG_P32(uap, data);
   1239 		}
   1240 	}
   1241 
   1242 	/*
   1243 	 * convert various structures, pointers, and other objects that
   1244 	 * change size from 32 bit -> 64 bit, for all ioctl commands.
   1245 	 */
   1246 	switch (SCARG(uap, com)) {
   1247 	case FIONBIO:
   1248 		mutex_enter(&fp->f_lock);
   1249 		if ((tmp = *(int *)data32) != 0)
   1250 			fp->f_flag |= FNONBLOCK;
   1251 		else
   1252 			fp->f_flag &= ~FNONBLOCK;
   1253 		mutex_exit(&fp->f_lock);
   1254 		error = (*fp->f_ops->fo_ioctl)(fp, FIONBIO, (void *)&tmp);
   1255 		break;
   1256 
   1257 	case FIOASYNC:
   1258 		mutex_enter(&fp->f_lock);
   1259 		if ((tmp = *(int *)data32) != 0)
   1260 			fp->f_flag |= FASYNC;
   1261 		else
   1262 			fp->f_flag &= ~FASYNC;
   1263 		mutex_exit(&fp->f_lock);
   1264 		error = (*fp->f_ops->fo_ioctl)(fp, FIOASYNC, (void *)&tmp);
   1265 		break;
   1266 
   1267 	case AUDIO_WSEEK32:
   1268 		IOCTL_CONV_TO(AUDIO_WSEEK, u_long);
   1269 
   1270 #if 0	/* not implemented by anything */
   1271 	case DIOCRFORMAT32:
   1272 		IOCTL_STRUCT_CONV_TO(DIOCRFORMAT, format_op);
   1273 	case DIOCWFORMAT32:
   1274 		IOCTL_STRUCT_CONV_TO(DIOCWFORMAT, format_op);
   1275 #endif
   1276 
   1277 	case ATAIOCCOMMAND32:
   1278 		IOCTL_STRUCT_CONV_TO(ATAIOCCOMMAND, atareq);
   1279 
   1280 	case SIOCIFGCLONERS32:
   1281 		{
   1282 			struct netbsd32_if_clonereq *req =
   1283 			    (struct netbsd32_if_clonereq *)data32;
   1284 			char *buf = NETBSD32PTR64(req->ifcr_buffer);
   1285 
   1286 			error = if_clone_list(req->ifcr_count,
   1287 			    buf, &req->ifcr_total);
   1288 			break;
   1289 		}
   1290 
   1291 /*
   1292  * only a few ifreq syscalls need conversion and those are
   1293  * all driver specific... XXX
   1294  */
   1295 #if 0
   1296 	case SIOCGADDRROM3232:
   1297 		IOCTL_STRUCT_CONV_TO(SIOCGADDRROM32, ifreq);
   1298 	case SIOCGCHIPID32:
   1299 		IOCTL_STRUCT_CONV_TO(SIOCGCHIPID, ifreq);
   1300 	case SIOCSIFADDR32:
   1301 		IOCTL_STRUCT_CONV_TO(SIOCSIFADDR, ifreq);
   1302 	case OSIOCGIFADDR32:
   1303 		IOCTL_STRUCT_CONV_TO(OSIOCGIFADDR, ifreq);
   1304 	case SIOCGIFADDR32:
   1305 		IOCTL_STRUCT_CONV_TO(SIOCGIFADDR, ifreq);
   1306 	case SIOCSIFDSTADDR32:
   1307 		IOCTL_STRUCT_CONV_TO(SIOCSIFDSTADDR, ifreq);
   1308 	case OSIOCGIFDSTADDR32:
   1309 		IOCTL_STRUCT_CONV_TO(OSIOCGIFDSTADDR, ifreq);
   1310 	case SIOCGIFDSTADDR32:
   1311 		IOCTL_STRUCT_CONV_TO(SIOCGIFDSTADDR, ifreq);
   1312 	case OSIOCGIFBRDADDR32:
   1313 		IOCTL_STRUCT_CONV_TO(OSIOCGIFBRDADDR, ifreq);
   1314 	case SIOCGIFBRDADDR32:
   1315 		IOCTL_STRUCT_CONV_TO(SIOCGIFBRDADDR, ifreq);
   1316 	case SIOCSIFBRDADDR32:
   1317 		IOCTL_STRUCT_CONV_TO(SIOCSIFBRDADDR, ifreq);
   1318 	case OSIOCGIFNETMASK32:
   1319 		IOCTL_STRUCT_CONV_TO(OSIOCGIFNETMASK, ifreq);
   1320 	case SIOCGIFNETMASK32:
   1321 		IOCTL_STRUCT_CONV_TO(SIOCGIFNETMASK, ifreq);
   1322 	case SIOCSIFNETMASK32:
   1323 		IOCTL_STRUCT_CONV_TO(SIOCSIFNETMASK, ifreq);
   1324 	case SIOCGIFMETRIC32:
   1325 		IOCTL_STRUCT_CONV_TO(SIOCGIFMETRIC, ifreq);
   1326 	case SIOCSIFMETRIC32:
   1327 		IOCTL_STRUCT_CONV_TO(SIOCSIFMETRIC, ifreq);
   1328 	case SIOCDIFADDR32:
   1329 		IOCTL_STRUCT_CONV_TO(SIOCDIFADDR, ifreq);
   1330 	case SIOCADDMULTI32:
   1331 		IOCTL_STRUCT_CONV_TO(SIOCADDMULTI, ifreq);
   1332 	case SIOCDELMULTI32:
   1333 		IOCTL_STRUCT_CONV_TO(SIOCDELMULTI, ifreq);
   1334 	case SIOCSIFMEDIA32:
   1335 		IOCTL_STRUCT_CONV_TO(SIOCSIFMEDIA, ifreq);
   1336 	case SIOCSIFMTU32:
   1337 		IOCTL_STRUCT_CONV_TO(SIOCSIFMTU, ifreq);
   1338 	case SIOCGIFMTU32:
   1339 		IOCTL_STRUCT_CONV_TO(SIOCGIFMTU, ifreq);
   1340 	case BIOCGETIF32:
   1341 		IOCTL_STRUCT_CONV_TO(BIOCGETIF, ifreq);
   1342 	case BIOCSETIF32:
   1343 		IOCTL_STRUCT_CONV_TO(BIOCSETIF, ifreq);
   1344 	case SIOCPHASE132:
   1345 		IOCTL_STRUCT_CONV_TO(SIOCPHASE1, ifreq);
   1346 	case SIOCPHASE232:
   1347 		IOCTL_STRUCT_CONV_TO(SIOCPHASE2, ifreq);
   1348 #endif
   1349 
   1350 	case OOSIOCGIFCONF32:
   1351 		IOCTL_STRUCT_CONV_TO(OOSIOCGIFCONF, ifconf);
   1352 	case OSIOCGIFCONF32:
   1353 		IOCTL_STRUCT_CONV_TO(OSIOCGIFCONF, ifconf);
   1354 	case SIOCGIFCONF32:
   1355 		IOCTL_STRUCT_CONV_TO(SIOCGIFCONF, ifconf);
   1356 
   1357 	case SIOCGIFFLAGS32:
   1358 		IOCTL_STRUCT_CONV_TO(SIOCGIFFLAGS, ifreq);
   1359 	case SIOCSIFFLAGS32:
   1360 		IOCTL_STRUCT_CONV_TO(SIOCSIFFLAGS, ifreq);
   1361 
   1362 	case SIOCGIFADDRPREF32:
   1363 		IOCTL_STRUCT_CONV_TO(SIOCGIFADDRPREF, if_addrprefreq);
   1364 	case SIOCSIFADDRPREF32:
   1365 		IOCTL_STRUCT_CONV_TO(SIOCSIFADDRPREF, if_addrprefreq);
   1366 
   1367 
   1368 	case OSIOCGIFFLAGS32:
   1369 		IOCTL_STRUCT_CONV_TO(OSIOCGIFFLAGS, oifreq);
   1370 	case OSIOCSIFFLAGS32:
   1371 		IOCTL_STRUCT_CONV_TO(OSIOCSIFFLAGS, oifreq);
   1372 
   1373 	case SIOCGIFMEDIA32_80:
   1374 		IOCTL_STRUCT_CONV_TO(SIOCGIFMEDIA_80, ifmediareq);
   1375 	case SIOCGIFMEDIA32:
   1376 		IOCTL_STRUCT_CONV_TO(SIOCGIFMEDIA, ifmediareq);
   1377 
   1378 	case SIOCGIFGENERIC32:
   1379 		IOCTL_STRUCT_CONV_TO(SIOCGIFGENERIC, ifreq);
   1380 	case SIOCSIFGENERIC32:
   1381 		IOCTL_STRUCT_CONV_TO(SIOCSIFGENERIC, ifreq);
   1382 
   1383 	case PPPOESETPARMS32:
   1384 		IOCTL_STRUCT_CONV_TO(PPPOESETPARMS, pppoediscparms);
   1385 	case PPPOEGETPARMS32:
   1386 		IOCTL_STRUCT_CONV_TO(PPPOEGETPARMS, pppoediscparms);
   1387 	case SPPPGETAUTHCFG32:
   1388 		IOCTL_STRUCT_CONV_TO(SPPPGETAUTHCFG, spppauthcfg);
   1389 	case SPPPSETAUTHCFG32:
   1390 		IOCTL_STRUCT_CONV_TO(SPPPSETAUTHCFG, spppauthcfg);
   1391 
   1392 	case SIOCSDRVSPEC32:
   1393 		IOCTL_STRUCT_CONV_TO(SIOCSDRVSPEC, ifdrv);
   1394 	case SIOCGDRVSPEC32:
   1395 		IOCTL_STRUCT_CONV_TO(SIOCGDRVSPEC, ifdrv);
   1396 
   1397 	case SIOCGETVIFCNT32:
   1398 		IOCTL_STRUCT_CONV_TO(SIOCGETVIFCNT, sioc_vif_req);
   1399 
   1400 	case SIOCGETSGCNT32:
   1401 		IOCTL_STRUCT_CONV_TO(SIOCGETSGCNT, sioc_sg_req);
   1402 
   1403 	case VNDIOCSET32:
   1404 		IOCTL_STRUCT_CONV_TO(VNDIOCSET, vnd_ioctl);
   1405 
   1406 	case VNDIOCCLR32:
   1407 		IOCTL_STRUCT_CONV_TO(VNDIOCCLR, vnd_ioctl);
   1408 
   1409 	case VNDIOCGET32:
   1410 		IOCTL_STRUCT_CONV_TO(VNDIOCGET, vnd_user);
   1411 
   1412 	case VNDIOCSET5032:
   1413 		IOCTL_STRUCT_CONV_TO(VNDIOCSET50, vnd_ioctl50);
   1414 
   1415 	case VNDIOCCLR5032:
   1416 		IOCTL_STRUCT_CONV_TO(VNDIOCCLR50, vnd_ioctl50);
   1417 
   1418 	case ENVSYS_GETDICTIONARY32:
   1419 		IOCTL_STRUCT_CONV_TO(ENVSYS_GETDICTIONARY, plistref);
   1420 	case ENVSYS_SETDICTIONARY32:
   1421 		IOCTL_STRUCT_CONV_TO(ENVSYS_SETDICTIONARY, plistref);
   1422 	case ENVSYS_REMOVEPROPS32:
   1423 		IOCTL_STRUCT_CONV_TO(ENVSYS_REMOVEPROPS, plistref);
   1424 
   1425 	case WDOGIOC_GWDOGS32:
   1426 		IOCTL_STRUCT_CONV_TO(WDOGIOC_GWDOGS, wdog_conf);
   1427 
   1428 	case BIOCSETF32:
   1429 		IOCTL_STRUCT_CONV_TO(BIOCSETF, bpf_program);
   1430 #ifdef COMPAT_50
   1431 #define netbsd32_to_timeval50 netbsd32_ioctl_to_timeval50
   1432 #define netbsd32_from_timeval50 netbsd32_ioctl_from_timeval50
   1433 	case BIOCSORTIMEOUT32:
   1434 		IOCTL_STRUCT_CONV_TO(BIOCSORTIMEOUT, timeval50);
   1435 	case BIOCGORTIMEOUT32:
   1436 		IOCTL_STRUCT_CONV_TO(BIOCGORTIMEOUT, timeval50);
   1437 #undef netbsd32_to_timeval50
   1438 #undef netbsd32_from_timeval50
   1439 #endif
   1440 	case BIOCSTCPF32:
   1441 		IOCTL_STRUCT_CONV_TO(BIOCSTCPF, bpf_program);
   1442 	case BIOCSUDPF32:
   1443 		IOCTL_STRUCT_CONV_TO(BIOCSUDPF, bpf_program);
   1444 	case BIOCGDLTLIST32:
   1445 		IOCTL_STRUCT_CONV_TO(BIOCGDLTLIST, bpf_dltlist);
   1446 #define netbsd32_to_timeval(s32p, p, cmd) netbsd32_to_timeval(s32p, p)
   1447 #define netbsd32_from_timeval(p, s32p, cmd) netbsd32_from_timeval(p, s32p)
   1448 	case BIOCSRTIMEOUT32:
   1449 		IOCTL_STRUCT_CONV_TO(BIOCSRTIMEOUT, timeval);
   1450 	case BIOCGRTIMEOUT32:
   1451 		IOCTL_STRUCT_CONV_TO(BIOCGRTIMEOUT, timeval);
   1452 #undef netbsd32_to_timeval
   1453 #undef netbsd32_from_timeval
   1454 
   1455 	case WSDISPLAYIO_ADDSCREEN32:
   1456 		IOCTL_STRUCT_CONV_TO(WSDISPLAYIO_ADDSCREEN,
   1457 		    wsdisplay_addscreendata);
   1458 
   1459 	case WSDISPLAYIO_GCURSOR32:
   1460 		IOCTL_STRUCT_CONV_TO(WSDISPLAYIO_GCURSOR, wsdisplay_cursor);
   1461 	case WSDISPLAYIO_SCURSOR32:
   1462 		IOCTL_STRUCT_CONV_TO(WSDISPLAYIO_SCURSOR, wsdisplay_cursor);
   1463 
   1464 	case WSDISPLAYIO_GETCMAP32:
   1465 		IOCTL_STRUCT_CONV_TO(WSDISPLAYIO_GETCMAP, wsdisplay_cmap);
   1466 	case WSDISPLAYIO_PUTCMAP32:
   1467 		IOCTL_STRUCT_CONV_TO(WSDISPLAYIO_PUTCMAP, wsdisplay_cmap);
   1468 
   1469 	case WSDISPLAYIO_LDFONT32:
   1470 		IOCTL_STRUCT_CONV_TO(WSDISPLAYIO_LDFONT, wsdisplay_font);
   1471 	case WSDISPLAYIO_SFONT32:
   1472 		IOCTL_STRUCT_CONV_TO(WSDISPLAYIO_SFONT, wsdisplay_usefontdata);
   1473 
   1474 	case SIOCS8021132:
   1475 		IOCTL_STRUCT_CONV_TO(SIOCS80211, ieee80211req);
   1476 	case SIOCG8021132:
   1477 		IOCTL_STRUCT_CONV_TO(SIOCG80211, ieee80211req);
   1478 	case SIOCS80211NWKEY32:
   1479 		IOCTL_STRUCT_CONV_TO(SIOCS80211NWKEY, ieee80211_nwkey);
   1480 	case SIOCG80211NWKEY32:
   1481 		IOCTL_STRUCT_CONV_TO(SIOCG80211NWKEY, ieee80211_nwkey);
   1482 
   1483 	case POWER_EVENT_RECVDICT32:
   1484 		IOCTL_STRUCT_CONV_TO(POWER_EVENT_RECVDICT, plistref);
   1485 
   1486 	case CLOCKCTL_SETTIMEOFDAY32:
   1487 		IOCTL_STRUCT_CONV_TO(CLOCKCTL_SETTIMEOFDAY,
   1488 		    clockctl_settimeofday);
   1489 	case CLOCKCTL_ADJTIME32:
   1490 		IOCTL_STRUCT_CONV_TO(CLOCKCTL_ADJTIME, clockctl_adjtime);
   1491 	case CLOCKCTL_CLOCK_SETTIME32:
   1492 		IOCTL_STRUCT_CONV_TO(CLOCKCTL_CLOCK_SETTIME,
   1493 		    clockctl_clock_settime);
   1494 	case CLOCKCTL_NTP_ADJTIME32:
   1495 #ifdef NTP
   1496 		{
   1497 			size = IOCPARM_LEN(CLOCKCTL_NTP_ADJTIME);
   1498 			if (size > sizeof(stkbuf))
   1499 				data = memp = kmem_alloc(size, KM_SLEEP);
   1500 			else
   1501 				data = (void *)stkbuf;
   1502 
   1503 			netbsd32_to_clockctl_ntp_adjtime(
   1504 				(const struct netbsd32_clockctl_ntp_adjtime *)data32,
   1505 				(struct clockctl_ntp_adjtime *)data,
   1506 				CLOCKCTL_NTP_ADJTIME);
   1507 			error = netbsd32_do_clockctl_ntp_adjtime(
   1508 				(struct clockctl_ntp_adjtime *)data);
   1509 			netbsd32_from_clockctl_ntp_adjtime(
   1510 				(const struct clockctl_ntp_adjtime *)data,
   1511 				(struct netbsd32_clockctl_ntp_adjtime *)data32,
   1512 				CLOCKCTL_NTP_ADJTIME);
   1513 
   1514 			break;
   1515 		}
   1516 #else
   1517 		error = ENOTTY;
   1518 		break;
   1519 #endif /* NTP */
   1520 
   1521 	case KIOCGSYMBOL32:
   1522 		IOCTL_STRUCT_CONV_TO(KIOCGSYMBOL, ksyms_gsymbol);
   1523 	case KIOCGVALUE32:
   1524 		IOCTL_STRUCT_CONV_TO(KIOCGVALUE, ksyms_gvalue);
   1525 
   1526         case IOC_NPF_LOAD32:
   1527                 IOCTL_CONV_TO(IOC_NPF_LOAD, nvlist_ref_t);
   1528         case IOC_NPF_TABLE32:
   1529                 IOCTL_STRUCT_CONV_TO(IOC_NPF_TABLE, npf_ioctl_table);
   1530         case IOC_NPF_STATS32:
   1531                 IOCTL_CONV_TO(IOC_NPF_STATS, voidp);
   1532         case IOC_NPF_SAVE32:
   1533                 IOCTL_CONV_TO(IOC_NPF_SAVE, nvlist_ref_t);
   1534         case IOC_NPF_RULE32:
   1535                 IOCTL_CONV_TO(IOC_NPF_RULE, nvlist_ref_t);
   1536         case IOC_NPF_CONN_LOOKUP32:
   1537                 IOCTL_CONV_TO(IOC_NPF_CONN_LOOKUP, nvlist_ref_t);
   1538 
   1539 	case DRVRESCANBUS32:
   1540 		IOCTL_STRUCT_CONV_TO(DRVRESCANBUS, devrescanargs);
   1541 	case DRVLISTDEV32:
   1542 		IOCTL_STRUCT_CONV_TO(DRVLISTDEV, devlistargs);
   1543 	case DRVCTLCOMMAND32:
   1544 		IOCTL_STRUCT_CONV_TO(DRVCTLCOMMAND, plistref);
   1545 	case DRVGETEVENT32:
   1546 		IOCTL_STRUCT_CONV_TO(DRVGETEVENT, plistref);
   1547 
   1548 	case DIOCGSTRATEGY32:
   1549 		IOCTL_STRUCT_CONV_TO(DIOCGSTRATEGY, disk_strategy);
   1550 	case DIOCSSTRATEGY32:
   1551 		IOCTL_STRUCT_CONV_TO(DIOCSSTRATEGY, disk_strategy);
   1552 	case DIOCLWEDGES32:
   1553 		IOCTL_STRUCT_CONV_TO(DIOCLWEDGES, dkwedge_list);
   1554 
   1555 	default:
   1556 #ifdef NETBSD32_DRMKMS
   1557 		if (IOCGROUP(com) == 'd') {
   1558 			error = netbsd32_drm_ioctl(fp, com, data32, l);
   1559 			break;
   1560 		}
   1561 #endif
   1562 #ifdef NETBSD32_MD_IOCTL
   1563 		error = netbsd32_md_ioctl(fp, com, data32, l);
   1564 #else
   1565 		error = (*fp->f_ops->fo_ioctl)(fp, com, data32);
   1566 #endif
   1567 		break;
   1568 	}
   1569 
   1570 	if (error == EPASSTHROUGH)
   1571 		error = ENOTTY;
   1572 
   1573 	/*
   1574 	 * Copy any data to user, size was
   1575 	 * already set and checked above.
   1576 	 */
   1577 	if (error == 0 && (com&IOC_OUT) && size32) {
   1578 		error = copyout(data32, SCARG_P32(uap, data), size32);
   1579 		ktrgenio(fd, UIO_READ, SCARG_P32(uap, data),
   1580 		    size32, error);
   1581 	}
   1582 
   1583  out:
   1584 	/* If we allocated data, free it here. */
   1585 	if (memp32)
   1586 		kmem_free(memp32, alloc_size32);
   1587 	if (memp)
   1588 		kmem_free(memp, size);
   1589 	fd_putfile(fd);
   1590 	return error;
   1591 }
   1592