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 = kmalloc(sizeof(*data), GFP_KERNEL);
  45. if (!data)
  46. return -ENOMEM;
  47. if (copy_from_user(data, data32, sizeof(*data32)) ||
  48. get_user(data->flags, &data32->flags) ||
  49. get_user(data->time_queue, &data32->time_queue))
  50. goto error;
  51. data->kernel = NULL;
  52. fs = snd_enter_user();
  53. err = snd_seq_do_ioctl(client, cmd, data);
  54. snd_leave_user(fs);
  55. if (err < 0)
  56. goto error;
  57. if (copy_to_user(data32, data, sizeof(*data32)) ||
  58. put_user(data->flags, &data32->flags) ||
  59. put_user(data->time_queue, &data32->time_queue))
  60. err = -EFAULT;
  61. error:
  62. kfree(data);
  63. return err;
  64. }
  65. /*
  66. */
  67. enum {
  68. SNDRV_SEQ_IOCTL_CREATE_PORT32 = _IOWR('S', 0x20, struct snd_seq_port_info32),
  69. SNDRV_SEQ_IOCTL_DELETE_PORT32 = _IOW ('S', 0x21, struct snd_seq_port_info32),
  70. SNDRV_SEQ_IOCTL_GET_PORT_INFO32 = _IOWR('S', 0x22, struct snd_seq_port_info32),
  71. SNDRV_SEQ_IOCTL_SET_PORT_INFO32 = _IOW ('S', 0x23, struct snd_seq_port_info32),
  72. SNDRV_SEQ_IOCTL_QUERY_NEXT_PORT32 = _IOWR('S', 0x52, struct snd_seq_port_info32),
  73. };
  74. static long snd_seq_ioctl_compat(struct file *file, unsigned int cmd, unsigned long arg)
  75. {
  76. struct snd_seq_client *client = file->private_data;
  77. void __user *argp = compat_ptr(arg);
  78. if (snd_BUG_ON(!client))
  79. return -ENXIO;
  80. switch (cmd) {
  81. case SNDRV_SEQ_IOCTL_PVERSION:
  82. case SNDRV_SEQ_IOCTL_CLIENT_ID:
  83. case SNDRV_SEQ_IOCTL_SYSTEM_INFO:
  84. case SNDRV_SEQ_IOCTL_GET_CLIENT_INFO:
  85. case SNDRV_SEQ_IOCTL_SET_CLIENT_INFO:
  86. case SNDRV_SEQ_IOCTL_SUBSCRIBE_PORT:
  87. case SNDRV_SEQ_IOCTL_UNSUBSCRIBE_PORT:
  88. case SNDRV_SEQ_IOCTL_CREATE_QUEUE:
  89. case SNDRV_SEQ_IOCTL_DELETE_QUEUE:
  90. case SNDRV_SEQ_IOCTL_GET_QUEUE_INFO:
  91. case SNDRV_SEQ_IOCTL_SET_QUEUE_INFO:
  92. case SNDRV_SEQ_IOCTL_GET_NAMED_QUEUE:
  93. case SNDRV_SEQ_IOCTL_GET_QUEUE_STATUS:
  94. case SNDRV_SEQ_IOCTL_GET_QUEUE_TEMPO:
  95. case SNDRV_SEQ_IOCTL_SET_QUEUE_TEMPO:
  96. case SNDRV_SEQ_IOCTL_GET_QUEUE_TIMER:
  97. case SNDRV_SEQ_IOCTL_SET_QUEUE_TIMER:
  98. case SNDRV_SEQ_IOCTL_GET_QUEUE_CLIENT:
  99. case SNDRV_SEQ_IOCTL_SET_QUEUE_CLIENT:
  100. case SNDRV_SEQ_IOCTL_GET_CLIENT_POOL:
  101. case SNDRV_SEQ_IOCTL_SET_CLIENT_POOL:
  102. case SNDRV_SEQ_IOCTL_REMOVE_EVENTS:
  103. case SNDRV_SEQ_IOCTL_QUERY_SUBS:
  104. case SNDRV_SEQ_IOCTL_GET_SUBSCRIPTION:
  105. case SNDRV_SEQ_IOCTL_QUERY_NEXT_CLIENT:
  106. case SNDRV_SEQ_IOCTL_RUNNING_MODE:
  107. return snd_seq_do_ioctl(client, cmd, argp);
  108. case SNDRV_SEQ_IOCTL_CREATE_PORT32:
  109. return snd_seq_call_port_info_ioctl(client, SNDRV_SEQ_IOCTL_CREATE_PORT, argp);
  110. case SNDRV_SEQ_IOCTL_DELETE_PORT32:
  111. return snd_seq_call_port_info_ioctl(client, SNDRV_SEQ_IOCTL_DELETE_PORT, argp);
  112. case SNDRV_SEQ_IOCTL_GET_PORT_INFO32:
  113. return snd_seq_call_port_info_ioctl(client, SNDRV_SEQ_IOCTL_GET_PORT_INFO, argp);
  114. case SNDRV_SEQ_IOCTL_SET_PORT_INFO32:
  115. return snd_seq_call_port_info_ioctl(client, SNDRV_SEQ_IOCTL_SET_PORT_INFO, argp);
  116. case SNDRV_SEQ_IOCTL_QUERY_NEXT_PORT32:
  117. return snd_seq_call_port_info_ioctl(client, SNDRV_SEQ_IOCTL_QUERY_NEXT_PORT, argp);
  118. }
  119. return -ENOIOCTLCMD;
  120. }