linux_mtio.c revision 1.4 1 /* $NetBSD: linux_mtio.c,v 1.4 2007/03/04 06:01:24 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.4 2007/03/04 06:01:24 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/syscallargs.h>
42
43 #include <compat/linux/common/linux_types.h>
44 #include <compat/linux/common/linux_ioctl.h>
45 #include <compat/linux/common/linux_signal.h>
46 #include <compat/linux/common/linux_mtio.h>
47
48 #include <compat/linux/linux_syscallargs.h>
49
50 static const struct mtop_mapping {
51 short lop;
52 short op;
53 } mtop_map[] = {
54 { LINUX_MTFSF, MTFSF },
55 { LINUX_MTBSF, MTBSF },
56 { LINUX_MTFSR, MTFSR },
57 { LINUX_MTBSR, MTBSR },
58 { LINUX_MTWEOF, MTWEOF },
59 { LINUX_MTREW, MTREW },
60 { LINUX_MTOFFL, MTOFFL },
61 { LINUX_MTNOP, MTNOP },
62 { LINUX_MTRETEN, MTRETEN },
63 { LINUX_MTEOM, MTEOM },
64 { LINUX_MTERASE, MTERASE },
65 { LINUX_MTSETBLK, MTSETBSIZ },
66 { LINUX_MTSETDENSITY, MTSETDNSTY },
67 { LINUX_MTCOMPRESSION, MTCMPRESS },
68 { -1, -1 }
69 };
70
71 int
72 linux_ioctl_mtio(struct lwp *l, struct linux_sys_ioctl_args *uap,
73 register_t *retval)
74 {
75 struct file *fp;
76 struct filedesc *fdp;
77 u_long com = SCARG(uap, com);
78 int i, error = 0;
79 int (*ioctlf)(struct file *, u_long, void *, struct lwp *);
80 struct linux_mtop lmtop;
81 struct linux_mtget lmtget;
82 struct mtop mt;
83
84 fdp = l->l_proc->p_fd;
85 if ((fp = fd_getfile(fdp, SCARG(uap, fd))) == NULL)
86 return EBADF;
87
88 FILE_USE(fp);
89 ioctlf = fp->f_ops->fo_ioctl;
90
91 *retval = 0;
92 switch (com) {
93 case LINUX_MTIOCTOP:
94 error = copyin(SCARG(uap, data), &lmtop, sizeof lmtop);
95 for (i = 0; mtop_map[i].lop >= 0; i++) {
96 if (mtop_map[i].lop == lmtop.mt_op)
97 break;
98 }
99
100 if (mtop_map[i].lop == -1) {
101 error = EINVAL;
102 break;
103 }
104
105 mt.mt_op = mtop_map[i].op;
106 mt.mt_count = lmtop.mt_count;
107 error = ioctlf(fp, MTIOCTOP, (void *)&mt, l);
108 break;
109 case LINUX_MTIOCGET:
110 lmtget.mt_type = LINUX_MT_ISUNKNOWN;
111 lmtget.mt_resid = 0;
112 lmtget.mt_dsreg = 0;
113 lmtget.mt_gstat = 0;
114 lmtget.mt_erreg = 0;
115 lmtget.mt_fileno = 0;
116 lmtget.mt_blkno = 0;
117 error = copyout(&lmtget, SCARG(uap, data), sizeof lmtget);
118 break;
119 case LINUX_MTIOCPOS:
120 default:
121 printf("linux_mtio unsupported ioctl 0x%lx\n", com);
122 error = ENODEV;
123 break;
124 }
125
126 FILE_UNUSE(fp, l);
127
128 return error;
129 }
130