linux_fdio.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. /* $OpenBSD: linux_fdio.c,v 1.7 2012/04/22 05:43:14 guenther Exp $ */
  2. /* $NetBSD: linux_fdio.c,v 1.1 2000/12/10 14:12:16 fvdl Exp $ */
  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. #include <sys/param.h>
  38. #include <sys/systm.h>
  39. #include <sys/ioctl.h>
  40. #include <sys/file.h>
  41. #include <sys/filedesc.h>
  42. #include <sys/mount.h>
  43. #include <sys/proc.h>
  44. #include <sys/disklabel.h>
  45. #include <sys/syscallargs.h>
  46. #include <dev/isa/fdreg.h>
  47. #include <compat/linux/linux_types.h>
  48. #include <compat/linux/linux_ioctl.h>
  49. #include <compat/linux/linux_signal.h>
  50. #include <compat/linux/linux_util.h>
  51. #include <compat/linux/linux_fdio.h>
  52. #include <machine/ioctl_fd.h>
  53. #include <compat/linux/linux_syscallargs.h>
  54. int
  55. linux_ioctl_fdio(struct proc *p, struct linux_sys_ioctl_args *uap,
  56. register_t *retval)
  57. {
  58. struct filedesc *fdp;
  59. struct file *fp;
  60. int error;
  61. int (*ioctlf)(struct file *, u_long, caddr_t, struct proc *);
  62. u_long com;
  63. struct fd_type fparams;
  64. struct linux_floppy_struct lflop;
  65. struct linux_floppy_drive_struct ldrive;
  66. com = (u_long)SCARG(uap, data);
  67. fdp = p->p_fd;
  68. if ((fp = fd_getfile(fdp, SCARG(uap, fd))) == NULL)
  69. return (EBADF);
  70. FREF(fp);
  71. com = SCARG(uap, com);
  72. ioctlf = fp->f_ops->fo_ioctl;
  73. retval[0] = error = 0;
  74. switch (com) {
  75. case LINUX_FDMSGON:
  76. case LINUX_FDMSGOFF:
  77. case LINUX_FDTWADDLE:
  78. case LINUX_FDCLRPRM:
  79. /* whatever you say */
  80. break;
  81. case LINUX_FDPOLLDRVSTAT:
  82. /*
  83. * Just fill in some innocent defaults.
  84. */
  85. memset(&ldrive, 0, sizeof ldrive);
  86. ldrive.fd_ref = 1;
  87. ldrive.maxblock = 2;
  88. ldrive.maxtrack = ldrive.track = 1;
  89. ldrive.flags = LINUX_FD_DISK_WRITABLE;
  90. error = copyout(&ldrive, SCARG(uap, data), sizeof ldrive);
  91. break;
  92. case LINUX_FDGETPRM:
  93. error = ioctlf(fp, FD_GTYPE, (caddr_t)&fparams, p);
  94. if (error != 0)
  95. break;
  96. lflop.size = fparams.heads * fparams.sectrac * fparams.tracks;
  97. lflop.sect = fparams.sectrac;
  98. lflop.head = fparams.heads;
  99. lflop.track = fparams.tracks;
  100. lflop.stretch = fparams.step == 2 ? 1 : 0;
  101. lflop.spec1 = fparams.steprate;
  102. lflop.gap = fparams.gap1;
  103. lflop.fmt_gap = fparams.gap2;
  104. lflop.rate = fparams.rate;
  105. error = copyout(&lflop, SCARG(uap, data), sizeof lflop);
  106. break;
  107. case LINUX_FDSETPRM:
  108. /*
  109. * Should use FDIOCSETFORMAT here, iff its interface
  110. * is extended.
  111. */
  112. case LINUX_FDDEFPRM:
  113. case LINUX_FDFMTBEG:
  114. case LINUX_FDFMTTRK:
  115. case LINUX_FDFMTEND:
  116. case LINUX_FDSETEMSGTRESH:
  117. case LINUX_FDFLUSH:
  118. case LINUX_FDSETMAXERRS:
  119. case LINUX_FDGETMAXERRS:
  120. case LINUX_FDGETDRVTYP:
  121. case LINUX_FDSETDRVPRM:
  122. case LINUX_FDGETDRVPRM:
  123. case LINUX_FDGETDRVSTAT:
  124. case LINUX_FDRESET:
  125. case LINUX_FDGETFDCSTAT:
  126. case LINUX_FDWERRORCLR:
  127. case LINUX_FDWERRORGET:
  128. case LINUX_FDRAWCMD:
  129. case LINUX_FDEJECT:
  130. default:
  131. error = EINVAL;
  132. }
  133. FRELE(fp, p);
  134. return 0;
  135. }