rawmidi_compat.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /*
  2. * 32bit -> 64bit ioctl wrapper for raw MIDI API
  3. * Copyright (c) by Takashi Iwai <tiwai@suse.de>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  18. *
  19. */
  20. /* This file included from rawmidi.c */
  21. #include <linux/compat.h>
  22. struct snd_rawmidi_params32 {
  23. s32 stream;
  24. u32 buffer_size;
  25. u32 avail_min;
  26. unsigned int no_active_sensing; /* avoid bit-field */
  27. unsigned char reserved[16];
  28. } __attribute__((packed));
  29. static int snd_rawmidi_ioctl_params_compat(struct snd_rawmidi_file *rfile,
  30. struct snd_rawmidi_params32 __user *src)
  31. {
  32. struct snd_rawmidi_params params;
  33. unsigned int val;
  34. if (rfile->output == NULL)
  35. return -EINVAL;
  36. if (get_user(params.stream, &src->stream) ||
  37. get_user(params.buffer_size, &src->buffer_size) ||
  38. get_user(params.avail_min, &src->avail_min) ||
  39. get_user(val, &src->no_active_sensing))
  40. return -EFAULT;
  41. params.no_active_sensing = val;
  42. switch (params.stream) {
  43. case SNDRV_RAWMIDI_STREAM_OUTPUT:
  44. return snd_rawmidi_output_params(rfile->output, &params);
  45. case SNDRV_RAWMIDI_STREAM_INPUT:
  46. return snd_rawmidi_input_params(rfile->input, &params);
  47. }
  48. return -EINVAL;
  49. }
  50. struct snd_rawmidi_status32 {
  51. s32 stream;
  52. struct compat_timespec tstamp;
  53. u32 avail;
  54. u32 xruns;
  55. unsigned char reserved[16];
  56. } __attribute__((packed));
  57. static int snd_rawmidi_ioctl_status_compat(struct snd_rawmidi_file *rfile,
  58. struct snd_rawmidi_status32 __user *src)
  59. {
  60. int err;
  61. struct snd_rawmidi_status status;
  62. if (rfile->output == NULL)
  63. return -EINVAL;
  64. if (get_user(status.stream, &src->stream))
  65. return -EFAULT;
  66. switch (status.stream) {
  67. case SNDRV_RAWMIDI_STREAM_OUTPUT:
  68. err = snd_rawmidi_output_status(rfile->output, &status);
  69. break;
  70. case SNDRV_RAWMIDI_STREAM_INPUT:
  71. err = snd_rawmidi_input_status(rfile->input, &status);
  72. break;
  73. default:
  74. return -EINVAL;
  75. }
  76. if (err < 0)
  77. return err;
  78. if (put_user(status.tstamp.tv_sec, &src->tstamp.tv_sec) ||
  79. put_user(status.tstamp.tv_nsec, &src->tstamp.tv_nsec) ||
  80. put_user(status.avail, &src->avail) ||
  81. put_user(status.xruns, &src->xruns))
  82. return -EFAULT;
  83. return 0;
  84. }
  85. enum {
  86. SNDRV_RAWMIDI_IOCTL_PARAMS32 = _IOWR('W', 0x10, struct snd_rawmidi_params32),
  87. SNDRV_RAWMIDI_IOCTL_STATUS32 = _IOWR('W', 0x20, struct snd_rawmidi_status32),
  88. };
  89. static long snd_rawmidi_ioctl_compat(struct file *file, unsigned int cmd, unsigned long arg)
  90. {
  91. struct snd_rawmidi_file *rfile;
  92. void __user *argp = compat_ptr(arg);
  93. rfile = file->private_data;
  94. switch (cmd) {
  95. case SNDRV_RAWMIDI_IOCTL_PVERSION:
  96. case SNDRV_RAWMIDI_IOCTL_INFO:
  97. case SNDRV_RAWMIDI_IOCTL_DROP:
  98. case SNDRV_RAWMIDI_IOCTL_DRAIN:
  99. return snd_rawmidi_ioctl(file, cmd, (unsigned long)argp);
  100. case SNDRV_RAWMIDI_IOCTL_PARAMS32:
  101. return snd_rawmidi_ioctl_params_compat(rfile, argp);
  102. case SNDRV_RAWMIDI_IOCTL_STATUS32:
  103. return snd_rawmidi_ioctl_status_compat(rfile, argp);
  104. }
  105. return -ENOIOCTLCMD;
  106. }