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