linux_mtio.c revision 1.4 1 1.4 christos /* $NetBSD: linux_mtio.c,v 1.4 2007/03/04 06:01:24 christos 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.4 christos __KERNEL_RCSID(0, "$NetBSD: linux_mtio.c,v 1.4 2007/03/04 06:01:24 christos 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.1 soren
48 1.1 soren #include <compat/linux/linux_syscallargs.h>
49 1.1 soren
50 1.1 soren static const struct mtop_mapping {
51 1.1 soren short lop;
52 1.1 soren short op;
53 1.1 soren } mtop_map[] = {
54 1.1 soren { LINUX_MTFSF, MTFSF },
55 1.1 soren { LINUX_MTBSF, MTBSF },
56 1.1 soren { LINUX_MTFSR, MTFSR },
57 1.1 soren { LINUX_MTBSR, MTBSR },
58 1.1 soren { LINUX_MTWEOF, MTWEOF },
59 1.1 soren { LINUX_MTREW, MTREW },
60 1.1 soren { LINUX_MTOFFL, MTOFFL },
61 1.1 soren { LINUX_MTNOP, MTNOP },
62 1.1 soren { LINUX_MTRETEN, MTRETEN },
63 1.1 soren { LINUX_MTEOM, MTEOM },
64 1.1 soren { LINUX_MTERASE, MTERASE },
65 1.1 soren { LINUX_MTSETBLK, MTSETBSIZ },
66 1.1 soren { LINUX_MTSETDENSITY, MTSETDNSTY },
67 1.1 soren { LINUX_MTCOMPRESSION, MTCMPRESS },
68 1.1 soren { -1, -1 }
69 1.1 soren };
70 1.1 soren
71 1.1 soren int
72 1.2 christos linux_ioctl_mtio(struct lwp *l, struct linux_sys_ioctl_args *uap,
73 1.1 soren register_t *retval)
74 1.1 soren {
75 1.1 soren struct file *fp;
76 1.1 soren struct filedesc *fdp;
77 1.1 soren u_long com = SCARG(uap, com);
78 1.1 soren int i, error = 0;
79 1.2 christos int (*ioctlf)(struct file *, u_long, void *, struct lwp *);
80 1.1 soren struct linux_mtop lmtop;
81 1.1 soren struct linux_mtget lmtget;
82 1.1 soren struct mtop mt;
83 1.1 soren
84 1.2 christos fdp = l->l_proc->p_fd;
85 1.1 soren if ((fp = fd_getfile(fdp, SCARG(uap, fd))) == NULL)
86 1.1 soren return EBADF;
87 1.1 soren
88 1.1 soren FILE_USE(fp);
89 1.1 soren ioctlf = fp->f_ops->fo_ioctl;
90 1.1 soren
91 1.1 soren *retval = 0;
92 1.1 soren switch (com) {
93 1.1 soren case LINUX_MTIOCTOP:
94 1.1 soren error = copyin(SCARG(uap, data), &lmtop, sizeof lmtop);
95 1.1 soren for (i = 0; mtop_map[i].lop >= 0; i++) {
96 1.1 soren if (mtop_map[i].lop == lmtop.mt_op)
97 1.1 soren break;
98 1.1 soren }
99 1.1 soren
100 1.1 soren if (mtop_map[i].lop == -1) {
101 1.1 soren error = EINVAL;
102 1.1 soren break;
103 1.1 soren }
104 1.1 soren
105 1.1 soren mt.mt_op = mtop_map[i].op;
106 1.1 soren mt.mt_count = lmtop.mt_count;
107 1.4 christos error = ioctlf(fp, MTIOCTOP, (void *)&mt, l);
108 1.1 soren break;
109 1.1 soren case LINUX_MTIOCGET:
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.2 christos FILE_UNUSE(fp, l);
127 1.1 soren
128 1.1 soren return error;
129 1.1 soren }
130