static int freebsd32_ioctl_ioc_read_toc(struct thread *td, struct freebsd32_ioctl_args *uap, struct file *fp) { struct ioc_read_toc_entry toce; struct ioc_read_toc_entry32 toce32; int error; if ((error = copyin(uap->data, &toce32, sizeof(toce32)))) return (error); CP(toce32, toce, address_format); CP(toce32, toce, starting_track); CP(toce32, toce, data_len); PTRIN_CP(toce32, toce, data); if ((error = fo_ioctl(fp, CDIOREADTOCENTRYS, (caddr_t)&toce, td->td_ucred, td))) { CP(toce, toce32, address_format); CP(toce, toce32, starting_track); CP(toce, toce32, data_len); PTROUT_CP(toce, toce32, data); error = copyout(&toce32, uap->data, sizeof(toce32)); } return error; }
int freebsd32_ioctl(struct thread *td, struct freebsd32_ioctl_args *uap) { struct ioctl_args ap /*{ int fd; u_long com; caddr_t data; }*/ ; struct file *fp; cap_rights_t rights; int error; error = fget(td, uap->fd, cap_rights_init(&rights, CAP_IOCTL), &fp); if (error != 0) return (error); if ((fp->f_flag & (FREAD | FWRITE)) == 0) { fdrop(fp, td); return (EBADF); } switch (uap->com) { case MDIOCATTACH_32: /* FALLTHROUGH */ case MDIOCDETACH_32: /* FALLTHROUGH */ case MDIOCQUERY_32: /* FALLTHROUGH */ case MDIOCLIST_32: error = freebsd32_ioctl_md(td, uap, fp); break; case CDIOREADTOCENTRYS_32: error = freebsd32_ioctl_ioc_read_toc(td, uap, fp); break; case FIODGNAME_32: error = freebsd32_ioctl_fiodgname(td, uap, fp); break; case MEMRANGE_GET32: /* FALLTHROUGH */ case MEMRANGE_SET32: error = freebsd32_ioctl_memrange(td, uap, fp); break; case PCIOCGETCONF_32: error = freebsd32_ioctl_pciocgetconf(td, uap, fp); break; case SG_IO_32: error = freebsd32_ioctl_sg(td, uap, fp); break; default: fdrop(fp, td); ap.fd = uap->fd; ap.com = uap->com; PTRIN_CP(*uap, ap, data); return sys_ioctl(td, &ap); } fdrop(fp, td); return error; }
static int freebsd32_ioctl_fiodgname(struct thread *td, struct freebsd32_ioctl_args *uap, struct file *fp) { struct fiodgname_arg fgn; struct fiodgname_arg32 fgn32; int error; if ((error = copyin(uap->data, &fgn32, sizeof fgn32)) != 0) return (error); CP(fgn32, fgn, len); PTRIN_CP(fgn32, fgn, buf); error = fo_ioctl(fp, FIODGNAME, (caddr_t)&fgn, td->td_ucred, td); return (error); }
static int freebsd32_ioctl_memrange(struct thread *td, struct freebsd32_ioctl_args *uap, struct file *fp) { struct mem_range_op mro; struct mem_range_op32 mro32; int error; u_long com; if ((error = copyin(uap->data, &mro32, sizeof(mro32))) != 0) return (error); PTRIN_CP(mro32, mro, mo_desc); CP(mro32, mro, mo_arg[0]); CP(mro32, mro, mo_arg[1]); com = 0; switch (uap->com) { case MEMRANGE_GET32: com = MEMRANGE_GET; break; case MEMRANGE_SET32: com = MEMRANGE_SET; break; default: panic("%s: unknown MEMRANGE %#x", __func__, uap->com); } if ((error = fo_ioctl(fp, com, (caddr_t)&mro, td->td_ucred, td)) != 0) return (error); if ( (com & IOC_OUT) ) { CP(mro, mro32, mo_arg[0]); CP(mro, mro32, mo_arg[1]); error = copyout(&mro32, uap->data, sizeof(mro32)); } return (error); }
static int freebsd32_ioctl_md(struct thread *td, struct freebsd32_ioctl_args *uap, struct file *fp) { struct md_ioctl mdv; struct md_ioctl32 md32; u_long com = 0; int i, error; if (uap->com & IOC_IN) { if ((error = copyin(uap->data, &md32, sizeof(md32)))) { return (error); } CP(md32, mdv, md_version); CP(md32, mdv, md_unit); CP(md32, mdv, md_type); PTRIN_CP(md32, mdv, md_file); CP(md32, mdv, md_mediasize); CP(md32, mdv, md_sectorsize); CP(md32, mdv, md_options); CP(md32, mdv, md_base); CP(md32, mdv, md_fwheads); CP(md32, mdv, md_fwsectors); } else if (uap->com & IOC_OUT) { /* * Zero the buffer so the user always * gets back something deterministic. */ bzero(&mdv, sizeof mdv); } switch (uap->com) { case MDIOCATTACH_32: com = MDIOCATTACH; break; case MDIOCDETACH_32: com = MDIOCDETACH; break; case MDIOCQUERY_32: com = MDIOCQUERY; break; case MDIOCLIST_32: com = MDIOCLIST; break; default: panic("%s: unknown MDIOC %#x", __func__, uap->com); } error = fo_ioctl(fp, com, (caddr_t)&mdv, td->td_ucred, td); if (error == 0 && (com & IOC_OUT)) { CP(mdv, md32, md_version); CP(mdv, md32, md_unit); CP(mdv, md32, md_type); PTROUT_CP(mdv, md32, md_file); CP(mdv, md32, md_mediasize); CP(mdv, md32, md_sectorsize); CP(mdv, md32, md_options); CP(mdv, md32, md_base); CP(mdv, md32, md_fwheads); CP(mdv, md32, md_fwsectors); if (com == MDIOCLIST) { /* * Use MDNPAD, and not MDNPAD32. Padding is * allocated and used by compat32 ABI. */ for (i = 0; i < MDNPAD; i++) CP(mdv, md32, md_pad[i]); } error = copyout(&md32, uap->data, sizeof(md32)); } return error; }
static int freebsd32_ioctl_sg(struct thread *td, struct freebsd32_ioctl_args *uap, struct file *fp) { struct sg_io_hdr io; struct sg_io_hdr32 io32; int error; if ((error = copyin(uap->data, &io32, sizeof(io32))) != 0) return (error); CP(io32, io, interface_id); CP(io32, io, dxfer_direction); CP(io32, io, cmd_len); CP(io32, io, mx_sb_len); CP(io32, io, iovec_count); CP(io32, io, dxfer_len); PTRIN_CP(io32, io, dxferp); PTRIN_CP(io32, io, cmdp); PTRIN_CP(io32, io, sbp); CP(io32, io, timeout); CP(io32, io, flags); CP(io32, io, pack_id); PTRIN_CP(io32, io, usr_ptr); CP(io32, io, status); CP(io32, io, masked_status); CP(io32, io, msg_status); CP(io32, io, sb_len_wr); CP(io32, io, host_status); CP(io32, io, driver_status); CP(io32, io, resid); CP(io32, io, duration); CP(io32, io, info); if ((error = fo_ioctl(fp, SG_IO, (caddr_t)&io, td->td_ucred, td)) != 0) return (error); CP(io, io32, interface_id); CP(io, io32, dxfer_direction); CP(io, io32, cmd_len); CP(io, io32, mx_sb_len); CP(io, io32, iovec_count); CP(io, io32, dxfer_len); PTROUT_CP(io, io32, dxferp); PTROUT_CP(io, io32, cmdp); PTROUT_CP(io, io32, sbp); CP(io, io32, timeout); CP(io, io32, flags); CP(io, io32, pack_id); PTROUT_CP(io, io32, usr_ptr); CP(io, io32, status); CP(io, io32, masked_status); CP(io, io32, msg_status); CP(io, io32, sb_len_wr); CP(io, io32, host_status); CP(io, io32, driver_status); CP(io, io32, resid); CP(io, io32, duration); CP(io, io32, info); error = copyout(&io32, uap->data, sizeof(io32)); return (error); }
static int mps_ioctl32(struct cdev *dev, u_long cmd32, void *_arg, int flag, struct thread *td) { struct mps_cfg_page_req32 *page32 = _arg; struct mps_ext_cfg_page_req32 *ext32 = _arg; struct mps_raid_action32 *raid32 = _arg; struct mps_usr_command32 *user32 = _arg; union { struct mps_cfg_page_req page; struct mps_ext_cfg_page_req ext; struct mps_raid_action raid; struct mps_usr_command user; } arg; u_long cmd; int error; switch (cmd32) { case MPSIO_READ_CFG_HEADER32: case MPSIO_READ_CFG_PAGE32: case MPSIO_WRITE_CFG_PAGE32: if (cmd32 == MPSIO_READ_CFG_HEADER32) cmd = MPSIO_READ_CFG_HEADER; else if (cmd32 == MPSIO_READ_CFG_PAGE32) cmd = MPSIO_READ_CFG_PAGE; else cmd = MPSIO_WRITE_CFG_PAGE; CP(*page32, arg.page, header); CP(*page32, arg.page, page_address); PTRIN_CP(*page32, arg.page, buf); CP(*page32, arg.page, len); CP(*page32, arg.page, ioc_status); break; case MPSIO_READ_EXT_CFG_HEADER32: case MPSIO_READ_EXT_CFG_PAGE32: if (cmd32 == MPSIO_READ_EXT_CFG_HEADER32) cmd = MPSIO_READ_EXT_CFG_HEADER; else cmd = MPSIO_READ_EXT_CFG_PAGE; CP(*ext32, arg.ext, header); CP(*ext32, arg.ext, page_address); PTRIN_CP(*ext32, arg.ext, buf); CP(*ext32, arg.ext, len); CP(*ext32, arg.ext, ioc_status); break; case MPSIO_RAID_ACTION32: cmd = MPSIO_RAID_ACTION; CP(*raid32, arg.raid, action); CP(*raid32, arg.raid, volume_bus); CP(*raid32, arg.raid, volume_id); CP(*raid32, arg.raid, phys_disk_num); CP(*raid32, arg.raid, action_data_word); PTRIN_CP(*raid32, arg.raid, buf); CP(*raid32, arg.raid, len); CP(*raid32, arg.raid, volume_status); bcopy(raid32->action_data, arg.raid.action_data, sizeof arg.raid.action_data); CP(*raid32, arg.raid, ioc_status); CP(*raid32, arg.raid, write); break; case MPSIO_MPS_COMMAND32: cmd = MPSIO_MPS_COMMAND; PTRIN_CP(*user32, arg.user, req); CP(*user32, arg.user, req_len); PTRIN_CP(*user32, arg.user, rpl); CP(*user32, arg.user, rpl_len); PTRIN_CP(*user32, arg.user, buf); CP(*user32, arg.user, len); CP(*user32, arg.user, flags); break; default: return (ENOIOCTL); } error = mps_ioctl(dev, cmd, &arg, flag, td); if (error == 0 && (cmd32 & IOC_OUT) != 0) { switch (cmd32) { case MPSIO_READ_CFG_HEADER32: case MPSIO_READ_CFG_PAGE32: case MPSIO_WRITE_CFG_PAGE32: CP(arg.page, *page32, header); CP(arg.page, *page32, page_address); PTROUT_CP(arg.page, *page32, buf); CP(arg.page, *page32, len); CP(arg.page, *page32, ioc_status); break; case MPSIO_READ_EXT_CFG_HEADER32: case MPSIO_READ_EXT_CFG_PAGE32: CP(arg.ext, *ext32, header); CP(arg.ext, *ext32, page_address); PTROUT_CP(arg.ext, *ext32, buf); CP(arg.ext, *ext32, len); CP(arg.ext, *ext32, ioc_status); break; case MPSIO_RAID_ACTION32: CP(arg.raid, *raid32, action); CP(arg.raid, *raid32, volume_bus); CP(arg.raid, *raid32, volume_id); CP(arg.raid, *raid32, phys_disk_num); CP(arg.raid, *raid32, action_data_word); PTROUT_CP(arg.raid, *raid32, buf); CP(arg.raid, *raid32, len); CP(arg.raid, *raid32, volume_status); bcopy(arg.raid.action_data, raid32->action_data, sizeof arg.raid.action_data); CP(arg.raid, *raid32, ioc_status); CP(arg.raid, *raid32, write); break; case MPSIO_MPS_COMMAND32: PTROUT_CP(arg.user, *user32, req); CP(arg.user, *user32, req_len); PTROUT_CP(arg.user, *user32, rpl); CP(arg.user, *user32, rpl_len); PTROUT_CP(arg.user, *user32, buf); CP(arg.user, *user32, len); CP(arg.user, *user32, flags); break; } } return (error); }