seq_compat.c 4.6 KB

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