linux_ioctl.c (197176) | linux_ioctl.c (200110) |
---|---|
1/*- 2 * Copyright (c) 1994-1995 S�ren Schmidt 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 15 unchanged lines hidden (view full) --- 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 */ 28 29#include "opt_compat.h" 30 31#include <sys/cdefs.h> | 1/*- 2 * Copyright (c) 1994-1995 S�ren Schmidt 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 15 unchanged lines hidden (view full) --- 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 */ 28 29#include "opt_compat.h" 30 31#include <sys/cdefs.h> |
32__FBSDID("$FreeBSD: head/sys/compat/linux/linux_ioctl.c 197176 2009-09-13 21:30:18Z zec $"); | 32__FBSDID("$FreeBSD: head/sys/compat/linux/linux_ioctl.c 200110 2009-12-04 21:06:54Z netchild $"); |
33 34#include <sys/param.h> 35#include <sys/systm.h> 36#include <sys/sysproto.h> 37#include <sys/cdio.h> 38#include <sys/dvdio.h> 39#include <sys/conf.h> 40#include <sys/disk.h> --- 32 unchanged lines hidden (view full) --- 73#include <machine/../linux/linux_proto.h> 74#endif 75 76#include <compat/linux/linux_ioctl.h> 77#include <compat/linux/linux_mib.h> 78#include <compat/linux/linux_socket.h> 79#include <compat/linux/linux_util.h> 80 | 33 34#include <sys/param.h> 35#include <sys/systm.h> 36#include <sys/sysproto.h> 37#include <sys/cdio.h> 38#include <sys/dvdio.h> 39#include <sys/conf.h> 40#include <sys/disk.h> --- 32 unchanged lines hidden (view full) --- 73#include <machine/../linux/linux_proto.h> 74#endif 75 76#include <compat/linux/linux_ioctl.h> 77#include <compat/linux/linux_mib.h> 78#include <compat/linux/linux_socket.h> 79#include <compat/linux/linux_util.h> 80 |
81#include <compat/linux/linux_videodev.h> 82#include <compat/linux/linux_videodev_compat.h> 83 |
|
81CTASSERT(LINUX_IFNAMSIZ == IFNAMSIZ); 82 83static linux_ioctl_function_t linux_ioctl_cdrom; 84static linux_ioctl_function_t linux_ioctl_vfat; 85static linux_ioctl_function_t linux_ioctl_console; 86static linux_ioctl_function_t linux_ioctl_hdio; 87static linux_ioctl_function_t linux_ioctl_disk; 88static linux_ioctl_function_t linux_ioctl_socket; 89static linux_ioctl_function_t linux_ioctl_sound; 90static linux_ioctl_function_t linux_ioctl_termio; 91static linux_ioctl_function_t linux_ioctl_private; 92static linux_ioctl_function_t linux_ioctl_drm; 93static linux_ioctl_function_t linux_ioctl_sg; | 84CTASSERT(LINUX_IFNAMSIZ == IFNAMSIZ); 85 86static linux_ioctl_function_t linux_ioctl_cdrom; 87static linux_ioctl_function_t linux_ioctl_vfat; 88static linux_ioctl_function_t linux_ioctl_console; 89static linux_ioctl_function_t linux_ioctl_hdio; 90static linux_ioctl_function_t linux_ioctl_disk; 91static linux_ioctl_function_t linux_ioctl_socket; 92static linux_ioctl_function_t linux_ioctl_sound; 93static linux_ioctl_function_t linux_ioctl_termio; 94static linux_ioctl_function_t linux_ioctl_private; 95static linux_ioctl_function_t linux_ioctl_drm; 96static linux_ioctl_function_t linux_ioctl_sg; |
97static linux_ioctl_function_t linux_ioctl_v4l; |
|
94static linux_ioctl_function_t linux_ioctl_special; 95 96static struct linux_ioctl_handler cdrom_handler = 97{ linux_ioctl_cdrom, LINUX_IOCTL_CDROM_MIN, LINUX_IOCTL_CDROM_MAX }; 98static struct linux_ioctl_handler vfat_handler = 99{ linux_ioctl_vfat, LINUX_IOCTL_VFAT_MIN, LINUX_IOCTL_VFAT_MAX }; 100static struct linux_ioctl_handler console_handler = 101{ linux_ioctl_console, LINUX_IOCTL_CONSOLE_MIN, LINUX_IOCTL_CONSOLE_MAX }; --- 8 unchanged lines hidden (view full) --- 110static struct linux_ioctl_handler termio_handler = 111{ linux_ioctl_termio, LINUX_IOCTL_TERMIO_MIN, LINUX_IOCTL_TERMIO_MAX }; 112static struct linux_ioctl_handler private_handler = 113{ linux_ioctl_private, LINUX_IOCTL_PRIVATE_MIN, LINUX_IOCTL_PRIVATE_MAX }; 114static struct linux_ioctl_handler drm_handler = 115{ linux_ioctl_drm, LINUX_IOCTL_DRM_MIN, LINUX_IOCTL_DRM_MAX }; 116static struct linux_ioctl_handler sg_handler = 117{ linux_ioctl_sg, LINUX_IOCTL_SG_MIN, LINUX_IOCTL_SG_MAX }; | 98static linux_ioctl_function_t linux_ioctl_special; 99 100static struct linux_ioctl_handler cdrom_handler = 101{ linux_ioctl_cdrom, LINUX_IOCTL_CDROM_MIN, LINUX_IOCTL_CDROM_MAX }; 102static struct linux_ioctl_handler vfat_handler = 103{ linux_ioctl_vfat, LINUX_IOCTL_VFAT_MIN, LINUX_IOCTL_VFAT_MAX }; 104static struct linux_ioctl_handler console_handler = 105{ linux_ioctl_console, LINUX_IOCTL_CONSOLE_MIN, LINUX_IOCTL_CONSOLE_MAX }; --- 8 unchanged lines hidden (view full) --- 114static struct linux_ioctl_handler termio_handler = 115{ linux_ioctl_termio, LINUX_IOCTL_TERMIO_MIN, LINUX_IOCTL_TERMIO_MAX }; 116static struct linux_ioctl_handler private_handler = 117{ linux_ioctl_private, LINUX_IOCTL_PRIVATE_MIN, LINUX_IOCTL_PRIVATE_MAX }; 118static struct linux_ioctl_handler drm_handler = 119{ linux_ioctl_drm, LINUX_IOCTL_DRM_MIN, LINUX_IOCTL_DRM_MAX }; 120static struct linux_ioctl_handler sg_handler = 121{ linux_ioctl_sg, LINUX_IOCTL_SG_MIN, LINUX_IOCTL_SG_MAX }; |
122static struct linux_ioctl_handler video_handler = 123{ linux_ioctl_v4l, LINUX_IOCTL_VIDEO_MIN, LINUX_IOCTL_VIDEO_MAX }; |
|
118 119DATA_SET(linux_ioctl_handler_set, cdrom_handler); 120DATA_SET(linux_ioctl_handler_set, vfat_handler); 121DATA_SET(linux_ioctl_handler_set, console_handler); 122DATA_SET(linux_ioctl_handler_set, hdio_handler); 123DATA_SET(linux_ioctl_handler_set, disk_handler); 124DATA_SET(linux_ioctl_handler_set, socket_handler); 125DATA_SET(linux_ioctl_handler_set, sound_handler); 126DATA_SET(linux_ioctl_handler_set, termio_handler); 127DATA_SET(linux_ioctl_handler_set, private_handler); 128DATA_SET(linux_ioctl_handler_set, drm_handler); 129DATA_SET(linux_ioctl_handler_set, sg_handler); | 124 125DATA_SET(linux_ioctl_handler_set, cdrom_handler); 126DATA_SET(linux_ioctl_handler_set, vfat_handler); 127DATA_SET(linux_ioctl_handler_set, console_handler); 128DATA_SET(linux_ioctl_handler_set, hdio_handler); 129DATA_SET(linux_ioctl_handler_set, disk_handler); 130DATA_SET(linux_ioctl_handler_set, socket_handler); 131DATA_SET(linux_ioctl_handler_set, sound_handler); 132DATA_SET(linux_ioctl_handler_set, termio_handler); 133DATA_SET(linux_ioctl_handler_set, private_handler); 134DATA_SET(linux_ioctl_handler_set, drm_handler); 135DATA_SET(linux_ioctl_handler_set, sg_handler); |
136DATA_SET(linux_ioctl_handler_set, video_handler); |
|
130 131struct handler_element 132{ 133 TAILQ_ENTRY(handler_element) list; 134 int (*func)(struct thread *, struct linux_ioctl_args *); 135 int low, high, span; 136}; 137 --- 2446 unchanged lines hidden (view full) --- 2584 cmd = args->cmd; 2585 2586 error = (fo_ioctl(fp, cmd, (caddr_t)args->arg, td->td_ucred, td)); 2587 fdrop(fp, td); 2588 return (error); 2589} 2590 2591/* | 137 138struct handler_element 139{ 140 TAILQ_ENTRY(handler_element) list; 141 int (*func)(struct thread *, struct linux_ioctl_args *); 142 int low, high, span; 143}; 144 --- 2446 unchanged lines hidden (view full) --- 2591 cmd = args->cmd; 2592 2593 error = (fo_ioctl(fp, cmd, (caddr_t)args->arg, td->td_ucred, td)); 2594 fdrop(fp, td); 2595 return (error); 2596} 2597 2598/* |
2599 * Video4Linux (V4L) ioctl handler 2600 */ 2601static int 2602linux_to_bsd_v4l_tuner(struct l_video_tuner *lvt, struct video_tuner *vt) 2603{ 2604 vt->tuner = lvt->tuner; 2605 strlcpy(vt->name, lvt->name, LINUX_VIDEO_TUNER_NAME_SIZE); 2606 vt->rangelow = lvt->rangelow; /* possible long size conversion */ 2607 vt->rangehigh = lvt->rangehigh; /* possible long size conversion */ 2608 vt->flags = lvt->flags; 2609 vt->mode = lvt->mode; 2610 vt->signal = lvt->signal; 2611 return (0); 2612} 2613 2614static int 2615bsd_to_linux_v4l_tuner(struct video_tuner *vt, struct l_video_tuner *lvt) 2616{ 2617 lvt->tuner = vt->tuner; 2618 strlcpy(lvt->name, vt->name, LINUX_VIDEO_TUNER_NAME_SIZE); 2619 lvt->rangelow = vt->rangelow; /* possible long size conversion */ 2620 lvt->rangehigh = vt->rangehigh; /* possible long size conversion */ 2621 lvt->flags = vt->flags; 2622 lvt->mode = vt->mode; 2623 lvt->signal = vt->signal; 2624 return (0); 2625} 2626 2627#if 0 2628static int 2629linux_to_bsd_v4l_clip(struct l_video_clip *lvc, struct video_clip *vc) 2630{ 2631 vc->x = lvc->x; 2632 vc->y = lvc->y; 2633 vc->width = lvc->width; 2634 vc->height = lvc->height; 2635 vc->next = PTRIN(lvc->next); /* possible pointer size conversion */ 2636 return (0); 2637} 2638#endif 2639 2640static int 2641linux_to_bsd_v4l_window(struct l_video_window *lvw, struct video_window *vw) 2642{ 2643 vw->x = lvw->x; 2644 vw->y = lvw->y; 2645 vw->width = lvw->width; 2646 vw->height = lvw->height; 2647 vw->chromakey = lvw->chromakey; 2648 vw->flags = lvw->flags; 2649 vw->clips = PTRIN(lvw->clips); /* possible pointer size conversion */ 2650 vw->clipcount = lvw->clipcount; 2651 return (0); 2652} 2653 2654static int 2655bsd_to_linux_v4l_window(struct video_window *vw, struct l_video_window *lvw) 2656{ 2657 lvw->x = vw->x; 2658 lvw->y = vw->y; 2659 lvw->width = vw->width; 2660 lvw->height = vw->height; 2661 lvw->chromakey = vw->chromakey; 2662 lvw->flags = vw->flags; 2663 lvw->clips = PTROUT(vw->clips); /* possible pointer size conversion */ 2664 lvw->clipcount = vw->clipcount; 2665 return (0); 2666} 2667 2668static int 2669linux_to_bsd_v4l_buffer(struct l_video_buffer *lvb, struct video_buffer *vb) 2670{ 2671 vb->base = PTRIN(lvb->base); /* possible pointer size conversion */ 2672 vb->height = lvb->height; 2673 vb->width = lvb->width; 2674 vb->depth = lvb->depth; 2675 vb->bytesperline = lvb->bytesperline; 2676 return (0); 2677} 2678 2679static int 2680bsd_to_linux_v4l_buffer(struct video_buffer *vb, struct l_video_buffer *lvb) 2681{ 2682 lvb->base = PTROUT(vb->base); /* possible pointer size conversion */ 2683 lvb->height = vb->height; 2684 lvb->width = vb->width; 2685 lvb->depth = vb->depth; 2686 lvb->bytesperline = vb->bytesperline; 2687 return (0); 2688} 2689 2690static int 2691linux_to_bsd_v4l_code(struct l_video_code *lvc, struct video_code *vc) 2692{ 2693 strlcpy(vc->loadwhat, lvc->loadwhat, LINUX_VIDEO_CODE_LOADWHAT_SIZE); 2694 vc->datasize = lvc->datasize; 2695 vc->data = PTRIN(lvc->data); /* possible pointer size conversion */ 2696 return (0); 2697} 2698 2699#if 0 2700static int 2701linux_v4l_cliplist_copy(struct l_video_window *lvw, struct video_window *vw) 2702{ 2703 struct video_clip vclip; 2704 struct l_video_clip l_vclip; 2705 struct video_clip **ppvc; 2706 struct l_video_clip *plvc; 2707 int error; 2708 2709 ppvc = &(vw->clips); 2710 for (plvc = (struct l_video_clip *) PTRIN(lvw->clips); 2711 plvc != NULL; 2712 plvc = (struct l_video_clip *) PTRIN(plvc->next)) { 2713 error = copyin((void *) plvc, &l_vclip, sizeof(l_vclip)); 2714 if (error) return (error); 2715 linux_to_bsd_v4l_clip(&l_vclip, &vclip); 2716 /* XXX: If there can be no concurrency: s/M_NOWAIT/M_WAITOK/ */ 2717 if ((*ppvc = malloc(sizeof(**ppvc), M_LINUX, M_NOWAIT)) == NULL) 2718 return (ENOMEM); /* XXX: linux has no ENOMEM here */ 2719 memcpy(&vclip, *ppvc, sizeof(vclip)); 2720 ppvc = &((*ppvc)->next); 2721 } 2722 return (0); 2723} 2724 2725static int 2726linux_v4l_cliplist_free(struct video_window *vw) 2727{ 2728 struct video_clip **ppvc; 2729 struct video_clip **ppvc_next; 2730 2731 for (ppvc = &(vw->clips); *ppvc != NULL; ppvc = ppvc_next) { 2732 ppvc_next = &((*ppvc)->next); 2733 free(*ppvc, M_LINUX); 2734 } 2735 return (0); 2736} 2737#endif 2738 2739static int 2740linux_ioctl_v4l(struct thread *td, struct linux_ioctl_args *args) 2741{ 2742 struct file *fp; 2743 int error; 2744 struct video_tuner vtun; 2745 struct video_window vwin; 2746 struct video_buffer vbuf; 2747 struct video_code vcode; 2748 struct l_video_tuner l_vtun; 2749 struct l_video_window l_vwin; 2750 struct l_video_buffer l_vbuf; 2751 struct l_video_code l_vcode; 2752 2753 switch (args->cmd & 0xffff) { 2754 case LINUX_VIDIOCGCAP: args->cmd = VIDIOCGCAP; break; 2755 case LINUX_VIDIOCGCHAN: args->cmd = VIDIOCGCHAN; break; 2756 case LINUX_VIDIOCSCHAN: args->cmd = VIDIOCSCHAN; break; 2757 2758 case LINUX_VIDIOCGTUNER: 2759 if ((error = fget(td, args->fd, &fp)) != 0) 2760 return (error); 2761 error = fo_ioctl(fp, VIDIOCGTUNER, &vtun, td->td_ucred, td); 2762 if (!error) { 2763 bsd_to_linux_v4l_tuner(&vtun, &l_vtun); 2764 error = copyout(&l_vtun, (void *) args->arg, 2765 sizeof(l_vtun)); 2766 } 2767 fdrop(fp, td); 2768 return (error); 2769 2770 case LINUX_VIDIOCSTUNER: 2771 if ((error = fget(td, args->fd, &fp)) != 0) 2772 return (error); 2773 error = copyin((void *) args->arg, &l_vtun, sizeof(l_vtun)); 2774 if (error) { 2775 fdrop(fp, td); 2776 return (error); 2777 } 2778 linux_to_bsd_v4l_tuner(&l_vtun, &vtun); 2779 error = fo_ioctl(fp, VIDIOCSMICROCODE, &vtun, td->td_ucred, td); 2780 fdrop(fp, td); 2781 return (error); 2782 2783 case LINUX_VIDIOCGPICT: args->cmd = VIDIOCGPICT; break; 2784 case LINUX_VIDIOCSPICT: args->cmd = VIDIOCSPICT; break; 2785 case LINUX_VIDIOCCAPTURE: args->cmd = VIDIOCCAPTURE; break; 2786 2787 case LINUX_VIDIOCGWIN: 2788 if ((error = fget(td, args->fd, &fp)) != 0) 2789 return (error); 2790 error = fo_ioctl(fp, VIDIOCGWIN, &vwin, td->td_ucred, td); 2791 if (!error) { 2792 bsd_to_linux_v4l_window(&vwin, &l_vwin); 2793 error = copyout(&l_vwin, (void *) args->arg, 2794 sizeof(l_vwin)); 2795 } 2796 fdrop(fp, td); 2797 return (error); 2798 2799 case LINUX_VIDIOCSWIN: 2800 if ((error = fget(td, args->fd, &fp)) != 0) 2801 return (error); 2802 error = copyin((void *) args->arg, &l_vwin, sizeof(l_vwin)); 2803 if (error) { 2804 fdrop(fp, td); 2805 return (error); 2806 } 2807 linux_to_bsd_v4l_window(&l_vwin, &vwin); 2808#if 0 2809 /* 2810 * XXX: some Linux apps call SWIN but do not store valid 2811 * values in clipcount or in the clips pointer. Until 2812 * we have someone calling to support this, the code 2813 * to handle the list of video_clip structures is removed. 2814 */ 2815 error = linux_v4l_cliplist_copy(&l_vwin, &vwin); 2816#endif 2817 if (!error) 2818 error = fo_ioctl(fp, VIDIOCSWIN, &vwin, td->td_ucred, td); 2819 fdrop(fp, td); 2820#if 0 2821 linux_v4l_cliplist_free(&vwin); 2822#endif 2823 return (error); 2824 2825 case LINUX_VIDIOCGFBUF: 2826 if ((error = fget(td, args->fd, &fp)) != 0) 2827 return (error); 2828 error = fo_ioctl(fp, VIDIOCGFBUF, &vbuf, td->td_ucred, td); 2829 if (!error) { 2830 bsd_to_linux_v4l_buffer(&vbuf, &l_vbuf); 2831 error = copyout(&l_vbuf, (void *) args->arg, 2832 sizeof(l_vbuf)); 2833 } 2834 fdrop(fp, td); 2835 return (error); 2836 2837 case LINUX_VIDIOCSFBUF: 2838 if ((error = fget(td, args->fd, &fp)) != 0) 2839 return (error); 2840 error = copyin((void *) args->arg, &l_vbuf, sizeof(l_vbuf)); 2841 if (error) { 2842 fdrop(fp, td); 2843 return (error); 2844 } 2845 linux_to_bsd_v4l_buffer(&l_vbuf, &vbuf); 2846 error = fo_ioctl(fp, VIDIOCSFBUF, &vbuf, td->td_ucred, td); 2847 fdrop(fp, td); 2848 return (error); 2849 2850 case LINUX_VIDIOCKEY: args->cmd = VIDIOCKEY; break; 2851 case LINUX_VIDIOCGFREQ: args->cmd = VIDIOCGFREQ; break; 2852 case LINUX_VIDIOCSFREQ: args->cmd = VIDIOCSFREQ; break; 2853 case LINUX_VIDIOCGAUDIO: args->cmd = VIDIOCGAUDIO; break; 2854 case LINUX_VIDIOCSAUDIO: args->cmd = VIDIOCSAUDIO; break; 2855 case LINUX_VIDIOCSYNC: args->cmd = VIDIOCSYNC; break; 2856 case LINUX_VIDIOCMCAPTURE: args->cmd = VIDIOCMCAPTURE; break; 2857 case LINUX_VIDIOCGMBUF: args->cmd = VIDIOCGMBUF; break; 2858 case LINUX_VIDIOCGUNIT: args->cmd = VIDIOCGUNIT; break; 2859 case LINUX_VIDIOCGCAPTURE: args->cmd = VIDIOCGCAPTURE; break; 2860 case LINUX_VIDIOCSCAPTURE: args->cmd = VIDIOCSCAPTURE; break; 2861 case LINUX_VIDIOCSPLAYMODE: args->cmd = VIDIOCSPLAYMODE; break; 2862 case LINUX_VIDIOCSWRITEMODE: args->cmd = VIDIOCSWRITEMODE; break; 2863 case LINUX_VIDIOCGPLAYINFO: args->cmd = VIDIOCGPLAYINFO; break; 2864 2865 case LINUX_VIDIOCSMICROCODE: 2866 if ((error = fget(td, args->fd, &fp)) != 0) 2867 return (error); 2868 error = copyin((void *) args->arg, &l_vcode, sizeof(l_vcode)); 2869 if (error) { 2870 fdrop(fp, td); 2871 return (error); 2872 } 2873 linux_to_bsd_v4l_code(&l_vcode, &vcode); 2874 error = fo_ioctl(fp, VIDIOCSTUNER, &vcode, td->td_ucred, td); 2875 fdrop(fp, td); 2876 return (error); 2877 2878 case LINUX_VIDIOCGVBIFMT: args->cmd = VIDIOCGVBIFMT; break; 2879 case LINUX_VIDIOCSVBIFMT: args->cmd = VIDIOCSVBIFMT; break; 2880 default: return (ENOIOCTL); 2881 } 2882 2883 error = ioctl(td, (struct ioctl_args *)args); 2884 return (error); 2885} 2886 2887/* |
|
2592 * Special ioctl handler 2593 */ 2594static int 2595linux_ioctl_special(struct thread *td, struct linux_ioctl_args *args) 2596{ 2597 int error; 2598 2599 switch (args->cmd) { --- 133 unchanged lines hidden --- | 2888 * Special ioctl handler 2889 */ 2890static int 2891linux_ioctl_special(struct thread *td, struct linux_ioctl_args *args) 2892{ 2893 int error; 2894 2895 switch (args->cmd) { --- 133 unchanged lines hidden --- |