1 /* $NetBSD: linux_fdio.c,v 1.2 2001/06/14 20:32:43 thorpej Exp $ */ 2 3 /* 4 * Copyright (c) 2000 Wasabi Systems, Inc. 5 * All rights reserved. 6 * 7 * Written by Frank van der Linden for Wasabi Systems, Inc. 8 * 9 * Redistribution and use in source and binary forms, with or without 10 * modification, are permitted provided that the following conditions 11 * are met: 12 * 1. Redistributions of source code must retain the above copyright 13 * notice, this list of conditions and the following disclaimer. 14 * 2. Redistributions in binary form must reproduce the above copyright 15 * notice, this list of conditions and the following disclaimer in the 16 * documentation and/or other materials provided with the distribution. 17 * 3. All advertising materials mentioning features or use of this software 18 * must display the following acknowledgement: 19 * This product includes software developed for the NetBSD Project by 20 * Wasabi Systems, Inc. 21 * 4. The name of Wasabi Systems, Inc. may not be used to endorse 22 * or promote products derived from this software without specific prior 23 * written permission. 24 * 25 * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND 26 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 27 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 28 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC 29 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 32 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 33 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 34 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 35 * POSSIBILITY OF SUCH DAMAGE. 36 */ 37 38 #include <sys/param.h> 39 #include <sys/systm.h> 40 #include <sys/ioctl.h> 41 #include <sys/file.h> 42 #include <sys/filedesc.h> 43 #include <sys/mount.h> 44 #include <sys/proc.h> 45 #include <sys/disklabel.h> 46 47 #include <sys/fdio.h> 48 49 #include <sys/syscallargs.h> 50 51 #include <dev/isa/fdreg.h> 52 53 #include <compat/linux/common/linux_types.h> 54 #include <compat/linux/common/linux_ioctl.h> 55 #include <compat/linux/common/linux_signal.h> 56 #include <compat/linux/common/linux_util.h> 57 #include <compat/linux/common/linux_fdio.h> 58 59 #include <compat/linux/linux_syscallargs.h> 60 61 int 62 linux_ioctl_fdio(struct proc *p, struct linux_sys_ioctl_args *uap, 63 register_t *retval) 64 { 65 struct filedesc *fdp; 66 struct file *fp; 67 int error; 68 int (*ioctlf) __P((struct file *, u_long, caddr_t, struct proc *)); 69 u_long com; 70 struct fdformat_parms fparams; 71 struct linux_floppy_struct lflop; 72 struct linux_floppy_drive_struct ldrive; 73 74 com = (u_long)SCARG(uap, data); 75 76 fdp = p->p_fd; 77 if ((fp = fd_getfile(fdp, SCARG(uap, fd))) == NULL) 78 return (EBADF); 79 80 FILE_USE(fp); 81 82 com = SCARG(uap, com); 83 ioctlf = fp->f_ops->fo_ioctl; 84 85 retval[0] = error = 0; 86 87 switch (com) { 88 case LINUX_FDMSGON: 89 case LINUX_FDMSGOFF: 90 case LINUX_FDTWADDLE: 91 case LINUX_FDCLRPRM: 92 /* whatever you say */ 93 break; 94 case LINUX_FDPOLLDRVSTAT: 95 /* 96 * Just fill in some innocent defaults. 97 */ 98 memset(&ldrive, 0, sizeof ldrive); 99 ldrive.fd_ref = 1; 100 ldrive.maxblock = 2; 101 ldrive.maxtrack = ldrive.track = 1; 102 ldrive.flags = LINUX_FD_DISK_WRITABLE; 103 error = copyout(&ldrive, SCARG(uap, data), sizeof ldrive); 104 break; 105 case LINUX_FDGETPRM: 106 error = ioctlf(fp, FDIOCGETFORMAT, (caddr_t)&fparams, p); 107 if (error != 0) 108 break; 109 lflop.size = fparams.ncyl * fparams.nspt * fparams.ntrk; 110 lflop.sect = fparams.nspt; 111 lflop.head = fparams.ntrk; 112 lflop.track = fparams.ncyl; 113 lflop.stretch = fparams.stepspercyl == 2 ? 1 : 0; 114 lflop.fmt_gap = fparams.gaplen; 115 /* 116 * XXXX Use knowledge of floppy for these fields. 117 * FDIOCGETFORMAT does not provide enough information. 118 * It would be better to have FDIOCGETFORMAT return more 119 * information. 120 */ 121 switch (fparams.xfer_rate) { 122 case 500 * 1024: 123 lflop.spec1 = 0xcf; 124 lflop.gap = 0x1b; 125 lflop.rate = FDC_500KBPS; 126 break; 127 case 300 * 1024: 128 lflop.spec1 = 0xdf; 129 lflop.gap = 0x23; 130 lflop.rate = FDC_300KBPS; 131 break; 132 case 250 * 1024: 133 lflop.spec1 = 0xdf; 134 lflop.gap = 0x2a; 135 lflop.rate = FDC_250KBPS; 136 break; 137 } 138 error = copyout(&lflop, SCARG(uap, data), sizeof lflop); 139 break; 140 case LINUX_FDSETPRM: 141 /* 142 * Should use FDIOCSETFORMAT here, iff its interface 143 * is extended. 144 */ 145 case LINUX_FDDEFPRM: 146 case LINUX_FDFMTBEG: 147 case LINUX_FDFMTTRK: 148 case LINUX_FDFMTEND: 149 case LINUX_FDSETEMSGTRESH: 150 case LINUX_FDFLUSH: 151 case LINUX_FDSETMAXERRS: 152 case LINUX_FDGETMAXERRS: 153 case LINUX_FDGETDRVTYP: 154 case LINUX_FDSETDRVPRM: 155 case LINUX_FDGETDRVPRM: 156 case LINUX_FDGETDRVSTAT: 157 case LINUX_FDRESET: 158 case LINUX_FDGETFDCSTAT: 159 case LINUX_FDWERRORCLR: 160 case LINUX_FDWERRORGET: 161 case LINUX_FDRAWCMD: 162 case LINUX_FDEJECT: 163 default: 164 error = EINVAL; 165 } 166 167 FILE_UNUSE(fp, p); 168 169 return 0; 170 } 171