1 1.9 riastrad /* $NetBSD: linux_mtio.c,v 1.9 2024/10/01 16:41:29 riastradh Exp $ */ 2 1.1 soren 3 1.1 soren /* 4 1.1 soren * Copyright (c) 2005 Soren S. Jorvang. All rights reserved. 5 1.1 soren * 6 1.1 soren * Redistribution and use in source and binary forms, with or without 7 1.1 soren * modification, are permitted provided that the following conditions 8 1.1 soren * are met: 9 1.1 soren * 1. Redistributions of source code must retain the above copyright 10 1.1 soren * notice, this list of conditions, and the following disclaimer. 11 1.1 soren * 2. Redistributions in binary form must reproduce the above copyright 12 1.1 soren * notice, this list of conditions and the following disclaimer in the 13 1.1 soren * documentation and/or other materials provided with the distribution. 14 1.1 soren * 15 1.1 soren * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 16 1.1 soren * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 1.1 soren * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 1.1 soren * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19 1.1 soren * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 1.1 soren * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21 1.1 soren * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22 1.1 soren * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23 1.1 soren * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 1.1 soren * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25 1.1 soren * SUCH DAMAGE. 26 1.1 soren */ 27 1.1 soren 28 1.1 soren #include <sys/cdefs.h> 29 1.9 riastrad __KERNEL_RCSID(0, "$NetBSD: linux_mtio.c,v 1.9 2024/10/01 16:41:29 riastradh Exp $"); 30 1.1 soren 31 1.1 soren #include <sys/param.h> 32 1.1 soren #include <sys/systm.h> 33 1.1 soren #include <sys/ioctl.h> 34 1.1 soren #include <sys/file.h> 35 1.1 soren #include <sys/filedesc.h> 36 1.1 soren #include <sys/mount.h> 37 1.1 soren #include <sys/proc.h> 38 1.1 soren 39 1.1 soren #include <sys/mtio.h> 40 1.1 soren 41 1.1 soren #include <sys/syscallargs.h> 42 1.1 soren 43 1.1 soren #include <compat/linux/common/linux_types.h> 44 1.1 soren #include <compat/linux/common/linux_ioctl.h> 45 1.1 soren #include <compat/linux/common/linux_signal.h> 46 1.1 soren #include <compat/linux/common/linux_mtio.h> 47 1.5 njoly #include <compat/linux/common/linux_ipc.h> 48 1.5 njoly #include <compat/linux/common/linux_sem.h> 49 1.1 soren 50 1.1 soren #include <compat/linux/linux_syscallargs.h> 51 1.1 soren 52 1.1 soren static const struct mtop_mapping { 53 1.1 soren short lop; 54 1.1 soren short op; 55 1.1 soren } mtop_map[] = { 56 1.1 soren { LINUX_MTFSF, MTFSF }, 57 1.1 soren { LINUX_MTBSF, MTBSF }, 58 1.1 soren { LINUX_MTFSR, MTFSR }, 59 1.1 soren { LINUX_MTBSR, MTBSR }, 60 1.1 soren { LINUX_MTWEOF, MTWEOF }, 61 1.1 soren { LINUX_MTREW, MTREW }, 62 1.1 soren { LINUX_MTOFFL, MTOFFL }, 63 1.1 soren { LINUX_MTNOP, MTNOP }, 64 1.1 soren { LINUX_MTRETEN, MTRETEN }, 65 1.1 soren { LINUX_MTEOM, MTEOM }, 66 1.1 soren { LINUX_MTERASE, MTERASE }, 67 1.1 soren { LINUX_MTSETBLK, MTSETBSIZ }, 68 1.1 soren { LINUX_MTSETDENSITY, MTSETDNSTY }, 69 1.1 soren { LINUX_MTCOMPRESSION, MTCMPRESS }, 70 1.1 soren { -1, -1 } 71 1.1 soren }; 72 1.1 soren 73 1.1 soren int 74 1.6 dsl linux_ioctl_mtio(struct lwp *l, const struct linux_sys_ioctl_args *uap, 75 1.1 soren register_t *retval) 76 1.1 soren { 77 1.7 ad file_t *fp; 78 1.1 soren u_long com = SCARG(uap, com); 79 1.1 soren int i, error = 0; 80 1.7 ad int (*ioctlf)(file_t *, u_long, void *); 81 1.1 soren struct linux_mtop lmtop; 82 1.1 soren struct linux_mtget lmtget; 83 1.1 soren struct mtop mt; 84 1.1 soren 85 1.7 ad if ((fp = fd_getfile(SCARG(uap, fd))) == NULL) 86 1.1 soren return EBADF; 87 1.1 soren 88 1.1 soren ioctlf = fp->f_ops->fo_ioctl; 89 1.1 soren 90 1.1 soren *retval = 0; 91 1.1 soren switch (com) { 92 1.1 soren case LINUX_MTIOCTOP: 93 1.1 soren error = copyin(SCARG(uap, data), &lmtop, sizeof lmtop); 94 1.1 soren for (i = 0; mtop_map[i].lop >= 0; i++) { 95 1.1 soren if (mtop_map[i].lop == lmtop.mt_op) 96 1.1 soren break; 97 1.1 soren } 98 1.1 soren 99 1.1 soren if (mtop_map[i].lop == -1) { 100 1.1 soren error = EINVAL; 101 1.1 soren break; 102 1.1 soren } 103 1.9 riastrad 104 1.1 soren mt.mt_op = mtop_map[i].op; 105 1.1 soren mt.mt_count = lmtop.mt_count; 106 1.7 ad error = ioctlf(fp, MTIOCTOP, &mt); 107 1.1 soren break; 108 1.1 soren case LINUX_MTIOCGET: 109 1.8 riastrad memset(&lmtget, 0, sizeof(lmtget)); 110 1.1 soren lmtget.mt_type = LINUX_MT_ISUNKNOWN; 111 1.1 soren lmtget.mt_resid = 0; 112 1.1 soren lmtget.mt_dsreg = 0; 113 1.1 soren lmtget.mt_gstat = 0; 114 1.1 soren lmtget.mt_erreg = 0; 115 1.1 soren lmtget.mt_fileno = 0; 116 1.1 soren lmtget.mt_blkno = 0; 117 1.1 soren error = copyout(&lmtget, SCARG(uap, data), sizeof lmtget); 118 1.1 soren break; 119 1.1 soren case LINUX_MTIOCPOS: 120 1.1 soren default: 121 1.1 soren printf("linux_mtio unsupported ioctl 0x%lx\n", com); 122 1.1 soren error = ENODEV; 123 1.1 soren break; 124 1.1 soren } 125 1.1 soren 126 1.7 ad fd_putfile(SCARG(uap, fd)); 127 1.1 soren 128 1.1 soren return error; 129 1.1 soren } 130