seq_compat.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /*
  2. * 32bit -> 64bit ioctl wrapper for sequencer 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 seq.c */
  21. #include <linux/compat.h>
  22. struct snd_seq_port_info32 {
  23. struct snd_seq_addr addr; /* client/port numbers */
  24. char name[64]; /* port name */
  25. u32 capability; /* port capability bits */
  26. u32 type; /* port type bits */
  27. s32 midi_channels; /* channels per MIDI port */
  28. s32 midi_voices; /* voices per MIDI port */
  29. s32 synth_voices; /* voices per SYNTH port */
  30. s32 read_use; /* R/O: subscribers for output (from this port) */
  31. s32 write_use; /* R/O: subscribers for input (to this port) */
  32. u32 kernel; /* reserved for kernel use (must be NULL) */
  33. u32 flags; /* misc. conditioning */
  34. unsigned char time_queue; /* queue # for timestamping */
  35. char reserved[59]; /* for future use */
  36. };
  37. static int snd_seq_call_port_info_ioctl(struct snd_seq_client *client, unsigned int cmd,
  38. struct snd_seq_port_info32 __user *data32)
  39. {
  40. int err = -EFAULT;
  41. struct snd_seq_port_info *data;
  42. mm_segment_t fs;
  43. data = memdup_user(data32, sizeof(*data32));
  44. if (IS_ERR(data))
  45. return PTR_ERR(data);
  46. if (get_user(data->flags, &data32->flags) ||
  47. get_user(data->time_queue, &data32->time_queue))
  48. goto error;
  49. data->kernel = NULL;
  50. fs = snd_enter_user();
  51. err = snd_seq_do_ioctl(client, cmd, data);
  52. snd_leave_user(fs);
  53. if (err < 0)
  54. goto error;
  55. if (copy_to_user(data32, data, sizeof(*data32)) ||
  56. put_user(data->flags, &data32->flags) ||
  57. put_user(data->time_queue, &data32->time_queue))
  58. err = -EFAULT;
  59. error:
  60. kfree(data);
  61. return err;
  62. }
  63. /*
  64. */
  65. enum {
  66. SNDRV_SEQ_IOCTL_CREATE_PORT32 = _IOWR('S', 0x20, struct snd_seq_port_info32),
  67. SNDRV_SEQ_IOCTL_DELETE_PORT32 = _IOW ('S', 0x21, struct snd_seq_port_info32),
  68. SNDRV_SEQ_IOCTL_GET_PORT_INFO32 = _IOWR('S', 0x22, struct snd_seq_port_info32),
  69. SNDRV_SEQ_IOCTL_SET_PORT_INFO32 = _IOW ('S', 0x23, struct snd_seq_port_info32),
  70. SNDRV_SEQ_IOCTL_QUERY_NEXT_PORT32 = _IOWR('S', 0x52, struct snd_seq_port_info32),
  71. };
  72. static long snd_seq_ioctl_compat(struct file *file, unsigned int cmd, unsigned long arg)
  73. {
  74. struct snd_seq_client *client = file->private_data;
  75. void __user *argp = compat_ptr(arg);
  76. if (snd_BUG_ON(!client))
  77. return -ENXIO;
  78. switch (cmd) {
  79. case SNDRV_SEQ_IOCTL_PVERSION:
  80. case SNDRV_SEQ_IOCTL_CLIENT_ID:
  81. case SNDRV_SEQ_IOCTL_SYSTEM_INFO:
  82. case SNDRV_SEQ_IOCTL_GET_CLIENT_INFO:
  83. case SNDRV_SEQ_IOCTL_SET_CLIENT_INFO:
  84. case SNDRV_SEQ_IOCTL_SUBSCRIBE_PORT:
  85. case SNDRV_SEQ_IOCTL_UNSUBSCRIBE_PORT:
  86. case SNDRV_SEQ_IOCTL_CREATE_QUEUE:
  87. case SNDRV_SEQ_IOCTL_DELETE_QUEUE:
  88. case SNDRV_SEQ_IOCTL_GET_QUEUE_INFO:
  89. case SNDRV_SEQ_IOCTL_SET_QUEUE_INFO:
  90. case SNDRV_SEQ_IOCTL_GET_NAMED_QUEUE:
  91. case SNDRV_SEQ_IOCTL_GET_QUEUE_STATUS:
  92. case SNDRV_SEQ_IOCTL_GET_QUEUE_TEMPO:
  93. case SNDRV_SEQ_IOCTL_SET_QUEUE_TEMPO:
  94. case SNDRV_SEQ_IOCTL_GET_QUEUE_TIMER:
  95. case SNDRV_SEQ_IOCTL_SET_QUEUE_TIMER:
  96. case SNDRV_SEQ_IOCTL_GET_QUEUE_CLIENT:
  97. case SNDRV_SEQ_IOCTL_SET_QUEUE_CLIENT:
  98. case SNDRV_SEQ_IOCTL_GET_CLIENT_POOL:
  99. case SNDRV_SEQ_IOCTL_SET_CLIENT_POOL:
  100. case SNDRV_SEQ_IOCTL_REMOVE_EVENTS:
  101. case SNDRV_SEQ_IOCTL_QUERY_SUBS:
  102. case SNDRV_SEQ_IOCTL_GET_SUBSCRIPTION:
  103. case SNDRV_SEQ_IOCTL_QUERY_NEXT_CLIENT:
  104. case SNDRV_SEQ_IOCTL_RUNNING_MODE:
  105. return snd_seq_do_ioctl(client, cmd, argp);
  106. case SNDRV_SEQ_IOCTL_CREATE_PORT32:
  107. return snd_seq_call_port_info_ioctl(client, SNDRV_SEQ_IOCTL_CREATE_PORT, argp);
  108. case SNDRV_SEQ_IOCTL_DELETE_PORT32:
  109. return snd_seq_call_port_info_ioctl(client, SNDRV_SEQ_IOCTL_DELETE_PORT, argp);
  110. case SNDRV_SEQ_IOCTL_GET_PORT_INFO32:
  111. return snd_seq_call_port_info_ioctl(client, SNDRV_SEQ_IOCTL_GET_PORT_INFO, argp);
  112. case SNDRV_SEQ_IOCTL_SET_PORT_INFO32:
  113. return snd_seq_call_port_info_ioctl(client, SNDRV_SEQ_IOCTL_SET_PORT_INFO, argp);
  114. case SNDRV_SEQ_IOCTL_QUERY_NEXT_PORT32:
  115. return snd_seq_call_port_info_ioctl(client, SNDRV_SEQ_IOCTL_QUERY_NEXT_PORT, argp);
  116. }
  117. return -ENOIOCTLCMD;
  118. }