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