Also at:

        http://people.freebsd.org/~nox/dvb/linux_dvbwrapper-kmod.shar

 If anyone can test it, even the better! :)  (Still seems to be
working here with the Linux w_scan on dvb-s2.)

 Thanx!
        Juergen

PS: If anyone is wondering why this is a port now, one of the
header contains lgpl'd parts out of the Linux dvb headers and
I got no reply from the author of those parts... :(

# This is a shell archive.  Save it in a file, remove anything before
# this line, and then unpack it by entering "sh file".  Note, it may
# create directories; files and directories will be owned by you and
# have default permissions.
#
# This archive contains:
#
#       linux_dvbwrapper-kmod/
#       linux_dvbwrapper-kmod/Makefile
#       linux_dvbwrapper-kmod/pkg-descr
#       linux_dvbwrapper-kmod/files/
#       linux_dvbwrapper-kmod/files/Makefile
#       linux_dvbwrapper-kmod/files/linux_dvb.h
#       linux_dvbwrapper-kmod/files/linux_dvb_compat.h
#       linux_dvbwrapper-kmod/files/linux_dvb_ioctl.h
#       linux_dvbwrapper-kmod/files/linux_dvbwrapper.c
#
echo c - linux_dvbwrapper-kmod/
mkdir -p linux_dvbwrapper-kmod/ > /dev/null 2>&1
echo x - linux_dvbwrapper-kmod/Makefile
sed 's/^X//' >linux_dvbwrapper-kmod/Makefile << 
'66b9bcdcacf08b242d7eaa0e47aae7b9'
X# New ports collection makefile for:   linux_dvbwrapper-kmod
X# Date created:                                Thu Apr 21 17:34:08 CEST 2011
X# Whom:                                        n...@freebsd.org
X#
X# $FreeBSD: $
X#
X
XPORTNAME=      linux_dvbwrapper-kmod
XPORTVERSION=   1.0
XCATEGORIES=    multimedia kld
XDISTFILES=     # none
X
XMAINTAINER=    n...@freebsd.org
XCOMMENT=       Linux compatibility layer - DVB ioctl handler
X
XONLY_FOR_ARCHS=        i386 amd64
X
X.include <bsd.port.pre.mk>
X
XPLIST_FILES+=  "@cwd /"
XPLIST_FILES+=  ${KMODDIR:C,^/,,}/linux_dvbwrapper.ko
XPLIST_FILES+=  "@exec kldxref ${KMODDIR}"
XPLIST_FILES+=  "@unexec kldxref ${KMODDIR}"
X
X# install where x11/nvidia-driver does also:
XKMODDIR=       /boot/modules
X
XMAKE_ENV+=     KMODDIR="${KMODDIR}"
X
XSYSDIR?=       ${SRC_BASE}/sys
XMAKE_ENV+=     SYSDIR="${SYSDIR}"
X
XCFLAGS+=       ${DEBUG_FLAGS}
X
X.if !exists(${SYSDIR}/Makefile)
XIGNORE=                requires kernel source to be installed
X.endif
X
Xdo-extract:
X       ${MKDIR} ${WRKSRC}
X       ${CP} ${FILESDIR}/Makefile ${FILESDIR}/*.[ch] ${WRKSRC}
X
X.include <bsd.port.post.mk>
66b9bcdcacf08b242d7eaa0e47aae7b9
echo x - linux_dvbwrapper-kmod/pkg-descr
sed 's/^X//' >linux_dvbwrapper-kmod/pkg-descr << 
'51aa72c06ddc530c5f43cce2137dd05f'
XThis kld adds DVB ioctl handling to the Linux compatibility layer
Xso that Linux apps can talk to DVB/ATSC tuners via /dev/dvb/adapterX.
X
XNote this port does not contain actual DVB drivers, those are
Xprovided by e.g. the multimedia/webcamd port.
X
XWWW: http://people.freebsd.org/~nox/dvb/
51aa72c06ddc530c5f43cce2137dd05f
echo c - linux_dvbwrapper-kmod/files/
mkdir -p linux_dvbwrapper-kmod/files/ > /dev/null 2>&1
echo x - linux_dvbwrapper-kmod/files/Makefile
sed 's/^X//' >linux_dvbwrapper-kmod/files/Makefile << 
'ff39e52f2dfa811e700ef33bcb10ae95'
X# $FreeBSD: $
X
X.if ${MACHINE_ARCH} == "amd64"
XSFX= 32
XCFLAGS+=-DCOMPAT_FREEBSD32 -DCOMPAT_LINUX32
X.endif
X
XCWARNFLAGS+=-Wno-missing-prototypes
X
XKMOD=  linux_dvbwrapper
XSRCS=  linux_dvbwrapper.c
X
X.include <bsd.kmod.mk>
ff39e52f2dfa811e700ef33bcb10ae95
echo x - linux_dvbwrapper-kmod/files/linux_dvb.h
sed 's/^X//' >linux_dvbwrapper-kmod/files/linux_dvb.h << 
'6677d8bf6fe9a16f05c826d0c116c855'
X/*
X * Extracted from <linux/dvb/frontend.h>, which is:
X *
X * Copyright (C) 2000 Marcus Metzler <mar...@convergence.de>
X *                 Ralph  Metzler <ra...@convergence.de>
X *                 Holger Waechtler <hol...@convergence.de>
X *                 Andre Draszik <a...@convergence.de>
X *                 for convergence integrated media GmbH
X *
X * This program is free software; you can redistribute it and/or
X * modify it under the terms of the GNU Lesser General Public License
X * as published by the Free Software Foundation; either version 2.1
X * of the License, or (at your option) any later version.
X *
X * This program is distributed in the hope that it will be useful,
X * but WITHOUT ANY WARRANTY; without even the implied warranty of
X * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
X * GNU General Public License for more details.
X *
X * You should have received a copy of the GNU Lesser General Public License
X * along with this program; if not, write to the Free Software
X * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
X *
X */
X
X#ifndef __LINUX_DVB_H
X#define __LINUX_DVB_H
X
X#include <sys/types.h>
X
Xstruct dtv_property {
X       uint32_t cmd;
X       uint32_t reserved[3];
X       union {
X               uint32_t data;
X               struct {
X                       uint8_t data[32];
X                       uint32_t len;
X                       uint32_t reserved1[3];
X                       void *reserved2;
X               } buffer;
X       } u;
X       int result;
X} __attribute__ ((packed));
X
X/* num of properties cannot exceed DTV_IOCTL_MAX_MSGS per ioctl */
X#define DTV_IOCTL_MAX_MSGS 64
X
Xstruct dtv_properties {
X       uint32_t num;
X       struct dtv_property *props;
X};
X
X#define FE_SET_PROPERTY                   _IOW('o', 82, struct dtv_properties)
X/* 
X * This is broken on linux as well but they workaround it in the driver.
X * Since this is impossible to do on FreeBSD fix the header instead.
X * Detailed and discussion :
X * http://lists.freebsd.org/pipermail/freebsd-multimedia/2010-April/010958.html
X */
X#define FE_GET_PROPERTY                   _IOW('o', 83, struct dtv_properties)
X
X#endif /*__LINUX_DVB_H*/
6677d8bf6fe9a16f05c826d0c116c855
echo x - linux_dvbwrapper-kmod/files/linux_dvb_compat.h
sed 's/^X//' >linux_dvbwrapper-kmod/files/linux_dvb_compat.h << 
'827c22870bae42a8ffb3d63ad3e605d6'
X#ifndef __LINUX_DVB_COMPAT_H
X#define __LINUX_DVB_COMPAT_H
X
X#include <sys/types.h>
X
Xstruct l_dtv_property {
X       uint32_t cmd;
X       uint32_t reserved[3];
X       union {
X               uint32_t data;
X               struct {
X                       uint8_t data[32];
X                       uint32_t len;
X                       uint32_t reserved1[3];
X                       l_uintptr_t reserved2;
X               } buffer;
X       } u;
X       l_int result;
X} __attribute__ ((packed));
X
Xstruct l_dtv_properties {
X       uint32_t num;
X       l_uintptr_t props;
X};
X
X#endif /*__LINUX_DVB_H*/
827c22870bae42a8ffb3d63ad3e605d6
echo x - linux_dvbwrapper-kmod/files/linux_dvb_ioctl.h
sed 's/^X//' >linux_dvbwrapper-kmod/files/linux_dvb_ioctl.h << 
'0599fcbdb1e16725afdc6cae52772454'
X/*-
X * Copyright (c) 2011 Juergen Lock
X * All rights reserved.
X *
X * Redistribution and use in source and binary forms, with or without
X * modification, are permitted provided that the following conditions
X * are met:
X * 1. Redistributions of source code must retain the above copyright
X *    notice, this list of conditions and the following disclaimer 
X *    in this position and unchanged.
X * 2. Redistributions in binary form must reproduce the above copyright
X *    notice, this list of conditions and the following disclaimer in the
X *    documentation and/or other materials provided with the distribution.
X * 3. The name of the author may not be used to endorse or promote products
X *    derived from this software without specific prior written permission.
X *
X * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
X * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
X * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
X * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
X * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
X * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
X * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
X * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
X * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
X * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
X *
X * $FreeBSD: $
X */
X
X#ifndef _LINUX_DVB_IOCTL_H_
X#define        _LINUX_DVB_IOCTL_H_
X
X/*
X * ioctl
X *
X * XXX comments in Linux' <asm-generic/ioctl.h> indicate these
X * could be arch-dependant...
X */
X#define LINUX_IOC_VOID         0
X#define LINUX_IOC_IN           0x40000000
X#define LINUX_IOC_OUT          0x80000000
X#define LINUX_IOC_INOUT                (LINUX_IOC_IN|LINUX_IOC_OUT)
X
X/*
X * DVB (osd.h and video.h not handled)
X */
X#define LINUX_AUDIO_STOP                       0x6f01 /* 0x00006f01 */
X#define LINUX_AUDIO_PLAY                       0x6f02 /* 0x00006f02 */
X#define LINUX_AUDIO_PAUSE                      0x6f03 /* 0x00006f03 */
X#define LINUX_AUDIO_CONTINUE                   0x6f04 /* 0x00006f04 */
X#define LINUX_AUDIO_SELECT_SOURCE              0x6f05 /* 0x00006f05 */
X#define LINUX_AUDIO_SET_MUTE                   0x6f06 /* 0x00006f06 */
X#define LINUX_AUDIO_SET_AV_SYNC                        0x6f07 /* 0x00006f07 */
X#define LINUX_AUDIO_SET_BYPASS_MODE            0x6f08 /* 0x00006f08 */
X#define LINUX_AUDIO_CHANNEL_SELECT             0x6f09 /* 0x00006f09 */
X#define LINUX_AUDIO_GET_STATUS                 0x6f0a /* 0x80206f0a */
X#define LINUX_AUDIO_GET_CAPABILITIES           0x6f0b /* 0x80046f0b */
X#define LINUX_AUDIO_CLEAR_BUFFER               0x6f0c /* 0x00006f0c */
X#define LINUX_AUDIO_SET_ID                     0x6f0d /* 0x00006f0d */
X#define LINUX_AUDIO_SET_MIXER                  0x6f0e /* 0x40086f0e */
X#define LINUX_AUDIO_SET_STREAMTYPE             0x6f0f /* 0x00006f0f */
X#define LINUX_AUDIO_SET_EXT_ID                 0x6f10 /* 0x00006f10 */
X#define LINUX_AUDIO_SET_ATTRIBUTES             0x6f11 /* 0x40026f11 */
X#define LINUX_AUDIO_SET_KARAOKE                        0x6f12 /* 0x400c6f12 */
X#define LINUX_AUDIO_GET_PTS                    0x6f13 /* 0x80086f13 */
X#define LINUX_AUDIO_BILINGUAL_CHANNEL_SELECT   0x6f14 /* 0x00006f14 */
X#define LINUX_DMX_START                                0x6f29 /* 0x00006f29 */
X#define LINUX_DMX_STOP                         0x6f2a /* 0x00006f2a */
X#define LINUX_DMX_SET_FILTER                   0x6f2b /* 0x403c6f2b */
X#define LINUX_DMX_SET_PES_FILTER               0x6f2c /* 0x40146f2c */
X#define LINUX_DMX_SET_BUFFER_SIZE              0x6f2d /* 0x00006f2d */
X#define LINUX_DMX_GET_PES_PIDS                 0x6f2f /* 0x800a6f2f */
X#define LINUX_DMX_GET_CAPS                     0x6f30 /* 0x80086f30 */
X#define LINUX_DMX_SET_SOURCE                   0x6f31 /* 0x40046f31 */
X#define LINUX_DMX_GET_STC                      0x6f32 /* 0xc0106f32 */
X#define LINUX_DMX_ADD_PID                      0x6f33 /* 0x40026f33 */
X#define LINUX_DMX_REMOVE_PID                   0x6f34 /* 0x40026f34 */
X#define LINUX_FE_GET_INFO                      0x6f3d /* 0x80a86f3d */
X#define LINUX_FE_DISEQC_RESET_OVERLOAD         0x6f3e /* 0x00006f3e */
X#define LINUX_FE_DISEQC_SEND_MASTER_CMD                0x6f3f /* 0x40076f3f */
X#define LINUX_FE_DISEQC_RECV_SLAVE_REPLY       0x6f40 /* 0x800c6f40 */
X#define LINUX_FE_DISEQC_SEND_BURST             0x6f41 /* 0x00006f41 */
X#define LINUX_FE_SET_TONE                      0x6f42 /* 0x00006f42 */
X#define LINUX_FE_SET_VOLTAGE                   0x6f43 /* 0x00006f43 */
X#define LINUX_FE_ENABLE_HIGH_LNB_VOLTAGE       0x6f44 /* 0x00006f44 */
X#define LINUX_FE_READ_STATUS                   0x6f45 /* 0x80046f45 */
X#define LINUX_FE_READ_BER                      0x6f46 /* 0x80046f46 */
X#define LINUX_FE_READ_SIGNAL_STRENGTH          0x6f47 /* 0x80026f47 */
X#define LINUX_FE_READ_SNR                      0x6f48 /* 0x80026f48 */
X#define LINUX_FE_READ_UNCORRECTED_BLOCKS       0x6f49 /* 0x80046f49 */
X#define LINUX_FE_SET_FRONTEND                  0x6f4c /* 0x40246f4c */
X#define LINUX_FE_GET_FRONTEND                  0x6f4d /* 0x80246f4d */
X#define LINUX_FE_GET_EVENT                     0x6f4e /* 0x80286f4e */
X#define LINUX_FE_DISHNETWORK_SEND_LEGACY_CMD   0x6f50 /* 0x00006f50 */
X#define LINUX_FE_SET_FRONTEND_TUNE_MODE                0x6f51 /* 0x00006f51 */
X#define LINUX_FE_SET_PROPERTY                  0x6f52 /* 0x40086f52 */
X#define LINUX_FE_GET_PROPERTY                  0x6f53 /* 0x80086f53 */
X#define LINUX_CA_RESET                         0x6f80 /* 0x00006f80 */
X#define LINUX_CA_GET_CAP                       0x6f81 /* 0x80106f81 */
X#define LINUX_CA_GET_SLOT_INFO                 0x6f82 /* 0x800c6f82 */
X#define LINUX_CA_GET_DESCR_INFO                        0x6f83 /* 0x80086f83 */
X#define LINUX_CA_GET_MSG                       0x6f84 /* 0x810c6f84 */
X#define LINUX_CA_SEND_MSG                      0x6f85 /* 0x410c6f85 */
X#define LINUX_CA_SET_DESCR                     0x6f86 /* 0x40106f86 */
X#define LINUX_CA_SET_PID                       0x6f87 /* 0x40086f87 */
X
X/*
X * DVB net.h
X * (LINUX_NET_ADD_IF and LINUX___NET_ADD_IF_OLD overlap with
X *  LINUX_DMX_REMOVE_PID)
X */
X#define LINUX_NET_ADD_IF                       0x6f34 /* 0xc0066f34 */
X#define LINUX_NET_REMOVE_IF                    0x6f35 /* 0x00006f35 */
X#define LINUX_NET_GET_IF                       0x6f36 /* 0xc0066f36 */
X#define LINUX___NET_ADD_IF_OLD                 0x6f34 /* 0xc0046f34 */
X#define LINUX___NET_GET_IF_OLD                 0x6f36 /* 0xc0046f36 */
X
X#define LINUX_IOCTL_DVB_MIN    LINUX_AUDIO_STOP
X#define LINUX_IOCTL_DVB_MAX    LINUX_CA_SET_PID
X
X#endif /* !_LINUX_DVB_IOCTL_H_ */
0599fcbdb1e16725afdc6cae52772454
echo x - linux_dvbwrapper-kmod/files/linux_dvbwrapper.c
sed 's/^X//' >linux_dvbwrapper-kmod/files/linux_dvbwrapper.c << 
'62000c07502c575e896a5f7ba0f4c3e5'
X/*-
X * Copyright (c) 2011 Juergen Lock
X * All rights reserved.
X *
X * Redistribution and use in source and binary forms, with or without
X * modification, are permitted provided that the following conditions
X * are met:
X * 1. Redistributions of source code must retain the above copyright
X *    notice, this list of conditions and the following disclaimer.
X * 2. Redistributions in binary form must reproduce the above copyright
X *    notice, this list of conditions and the following disclaimer in the
X *    documentation and/or other materials provided with the distribution.
X *
X * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
X * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
X * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
X * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
X * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
X * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
X * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
X * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
X * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
X * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
X * SUCH DAMAGE.
X */
X
X#include <sys/cdefs.h>
X__FBSDID("$FreeBSD: $");
X
X#include <sys/param.h>
X#include <sys/systm.h>
X#include <sys/conf.h>
X#include <sys/kernel.h>
X#include <sys/module.h>
X#include <sys/file.h>
X#include <sys/proc.h>
X#include <sys/ioccom.h>
X#include <sys/sysproto.h>
X#include <sys/mman.h>
X#include <sys/resourcevar.h>
X
X#include <vm/vm.h>
X#include <vm/pmap.h>
X#include <vm/vm_extern.h>
X#include <vm/vm_map.h>
X
X#ifdef COMPAT_LINUX32
X#include <machine/../linux32/linux.h>
X#include <machine/../linux32/linux32_proto.h>
X#else
X#include <machine/../linux/linux.h>
X#include <machine/../linux/linux_proto.h>
X#endif
X#include <compat/linux/linux_ioctl.h>
X#include <compat/linux/linux_util.h>
X
X#include "linux_dvb_ioctl.h"
X#include "linux_dvb.h"
X#include "linux_dvb_compat.h"
X
Xstatic linux_ioctl_function_t linux_ioctl_dvb;
Xstatic struct linux_ioctl_handler dvb_handler =
X{ linux_ioctl_dvb, LINUX_IOCTL_DVB_MIN, LINUX_IOCTL_DVB_MAX };
X
XSYSINIT  (dvbwrapper_register,   SI_SUB_KLD, SI_ORDER_MIDDLE,
X         linux_ioctl_register_handler, &dvb_handler);
XSYSUNINIT(dvbwrapper_unregister, SI_SUB_KLD, SI_ORDER_MIDDLE,
X         linux_ioctl_unregister_handler, &dvb_handler);
X
Xstatic MALLOC_DEFINE(M_LINUX_DVB, "linux_dvbwrapper", "Linux DVB wrapper");
X
Xstatic int
Xlinux_dvbwrapper_modevent(module_t mod, int cmd, void *data)
X{
X       return (0);
X}
X
XDEV_MODULE(linux_dvbwrapper, linux_dvbwrapper_modevent, NULL);
XMODULE_DEPEND(linux_dvbwrapper, linux, 1, 1, 1);
X
X#if ((__FreeBSD_version >= 900000) && (__FreeBSD_version < 900035)) || \
X    (__FreeBSD_version < 802503)
X/*
X * Map some anonymous memory in user space of size sz, rounded up to the page
X * boundary.
X */
Xint
Xcopyout_map(struct thread *td, vm_offset_t *addr, size_t sz)
X{
X       struct vmspace *vms;
X       int error;
X       vm_size_t size;
X
X       vms = td->td_proc->p_vmspace;
X
X       /*
X        * Map somewhere after heap in process memory.
X        */
X       PROC_LOCK(td->td_proc);
X       *addr = round_page((vm_offset_t)vms->vm_daddr +
X           lim_max(td->td_proc, RLIMIT_DATA));
X       PROC_UNLOCK(td->td_proc);
X
X       /* round size up to page boundry */
X       size = (vm_size_t)round_page(sz);
X
X       error = vm_mmap(&vms->vm_map, addr, size, PROT_READ | PROT_WRITE,
X           VM_PROT_ALL, MAP_PRIVATE | MAP_ANON, OBJT_DEFAULT, NULL, 0);
X
X       return (error);
X}
X
X/*
X * Unmap memory in user space.
X */
Xint
Xcopyout_unmap(struct thread *td, vm_offset_t addr, size_t sz)
X{
X       vm_map_t map;
X       vm_size_t size;
X
X       if (sz == 0)
X               return (0);
X
X       map = &td->td_proc->p_vmspace->vm_map;
X       size = (vm_size_t)round_page(sz);
X
X       if (vm_map_remove(map, addr, addr + size) != KERN_SUCCESS)
X               return (EINVAL);
X
X       return (0);
X}
X#endif
X
Xstatic int
Xlinux_to_bsd_dtv_properties(struct l_dtv_properties *lvps, struct 
dtv_properties *vps)
X{
X
X       vps->num = lvps->num;
X       vps->props = PTRIN(lvps->props);        /* possible pointer size 
conversion */
X       return (0);
X}
X
Xstatic int
Xlinux_to_bsd_dtv_property(struct l_dtv_property *lvp, struct dtv_property *vp)
X{
X
X       /*
X        * Everything until u.buffer.reserved2 is fixed size so
X        * just memcpy it.
X        */
X       memcpy(vp, lvp, offsetof(struct l_dtv_property, u.buffer.reserved2));
X       /*
X        * The pointer may be garbage since it's part of a union,
X        * currently no Linux code uses it so just set it to NULL.
X        */
X       vp->u.buffer.reserved2 = NULL;
X       vp->result = lvp->result;
X       return (0);
X}
X
Xstatic int
Xbsd_to_linux_dtv_property(struct dtv_property *vp, struct l_dtv_property *lvp)
X{
X
X       /*
X        * Everything until u.buffer.reserved2 is fixed size so
X        * just memcpy it.
X        */
X       memcpy(lvp, vp, offsetof(struct l_dtv_property, u.buffer.reserved2));
X       /*
X        * The pointer may be garbage since it's part of a union,
X        * currently no Linux code uses it so just set it to NULL.
X        */
X       lvp->u.buffer.reserved2 = PTROUT(NULL);
X       lvp->result = vp->result;
X       return (0);
X}
X
Xstatic int
Xlinux_ioctl_dvb(struct thread *td, struct linux_ioctl_args *args)
X{
X       struct file *fp;
X       int error, i;
X       struct l_dtv_properties l_vps;
X       struct dtv_properties vps;
X       struct l_dtv_property *l_vp, *l_p;
X       struct dtv_property *vp, *p;
X       size_t l_propsiz, propsiz;
X       vm_offset_t uvp;
X
X       l_vp = NULL;
X       vp = NULL;
X
X       switch (args->cmd & 0xffff) {
X       case LINUX_AUDIO_STOP:
X       case LINUX_AUDIO_PLAY:
X       case LINUX_AUDIO_PAUSE:
X       case LINUX_AUDIO_CONTINUE:
X       case LINUX_AUDIO_SELECT_SOURCE:
X       case LINUX_AUDIO_SET_MUTE:
X       case LINUX_AUDIO_SET_AV_SYNC:
X       case LINUX_AUDIO_SET_BYPASS_MODE:
X       case LINUX_AUDIO_CHANNEL_SELECT:
X       case LINUX_AUDIO_CLEAR_BUFFER:
X       case LINUX_AUDIO_SET_ID:
X       case LINUX_AUDIO_SET_STREAMTYPE:
X       case LINUX_AUDIO_SET_EXT_ID:
X       case LINUX_AUDIO_BILINGUAL_CHANNEL_SELECT:
X       case LINUX_DMX_START:
X       case LINUX_DMX_STOP:
X       case LINUX_DMX_SET_BUFFER_SIZE:
X       case LINUX_NET_REMOVE_IF:
X       case LINUX_FE_DISEQC_RESET_OVERLOAD:
X       case LINUX_FE_DISEQC_SEND_BURST:
X       case LINUX_FE_SET_TONE:
X       case LINUX_FE_SET_VOLTAGE:
X       case LINUX_FE_ENABLE_HIGH_LNB_VOLTAGE:
X       case LINUX_FE_DISHNETWORK_SEND_LEGACY_CMD:
X       case LINUX_FE_SET_FRONTEND_TUNE_MODE:
X       case LINUX_CA_RESET:
X               if ((args->cmd & IOC_DIRMASK) != LINUX_IOC_VOID)
X                       return ENOIOCTL;
X               args->cmd = (args->cmd & 0xffff) | IOC_VOID;
X               break;
X
X       case LINUX_DMX_REMOVE_PID:
X               /* overlaps with LINUX_NET_ADD_IF */
X               if ((args->cmd & IOC_DIRMASK) == LINUX_IOC_INOUT)
X                       goto net_add_if;
X               /* FALLTHRU */
X       case LINUX_AUDIO_SET_MIXER:
X       case LINUX_AUDIO_SET_ATTRIBUTES:
X       case LINUX_AUDIO_SET_KARAOKE:
X       case LINUX_DMX_SET_FILTER:
X       case LINUX_DMX_SET_PES_FILTER:
X       case LINUX_DMX_SET_SOURCE:
X       case LINUX_DMX_ADD_PID:
X       case LINUX_FE_DISEQC_SEND_MASTER_CMD:
X       case LINUX_FE_SET_FRONTEND:
X       case LINUX_CA_SEND_MSG:
X       case LINUX_CA_SET_DESCR:
X       case LINUX_CA_SET_PID:
X               args->cmd = (args->cmd & ~IOC_DIRMASK) | IOC_IN;
X               break;
X
X       case LINUX_AUDIO_GET_STATUS:
X       case LINUX_AUDIO_GET_CAPABILITIES:
X       case LINUX_AUDIO_GET_PTS:
X       case LINUX_DMX_GET_PES_PIDS:
X       case LINUX_DMX_GET_CAPS:
X       case LINUX_FE_GET_INFO:
X       case LINUX_FE_DISEQC_RECV_SLAVE_REPLY:
X       case LINUX_FE_READ_STATUS:
X       case LINUX_FE_READ_BER:
X       case LINUX_FE_READ_SIGNAL_STRENGTH:
X       case LINUX_FE_READ_SNR:
X       case LINUX_FE_READ_UNCORRECTED_BLOCKS:
X       case LINUX_FE_GET_FRONTEND:
X       case LINUX_FE_GET_EVENT:
X       case LINUX_CA_GET_CAP:
X       case LINUX_CA_GET_SLOT_INFO:
X       case LINUX_CA_GET_DESCR_INFO:
X       case LINUX_CA_GET_MSG:
X               args->cmd = (args->cmd & ~IOC_DIRMASK) | IOC_OUT;
X               break;
X
X       case LINUX_DMX_GET_STC:
X       case LINUX_NET_GET_IF:
X       net_add_if:
X               args->cmd = (args->cmd & ~IOC_DIRMASK) | IOC_INOUT;
X               break;
X
X       case LINUX_FE_SET_PROPERTY:
X       case LINUX_FE_GET_PROPERTY:
X               error = copyin((void *)args->arg, &l_vps, sizeof(l_vps));
X               if (error)
X                       return (error);
X               linux_to_bsd_dtv_properties(&l_vps, &vps);
X               if ((vps.num == 0) || vps.num > DTV_IOCTL_MAX_MSGS)
X                       return EINVAL;
X
X               l_propsiz = vps.num * sizeof(*l_vp);
X               propsiz = vps.num * sizeof(*vp);
X               l_vp = malloc(l_propsiz, M_LINUX_DVB, M_WAITOK);
X               vp = malloc(propsiz, M_LINUX_DVB, M_WAITOK);
X               error = copyin((void *)vps.props, l_vp, l_propsiz);
X               if (error)
X                       goto out2;
X               for (i = vps.num, l_p = l_vp, p = vp; i--; ++l_p, ++p)
X                       linux_to_bsd_dtv_property(l_p, p);
X
X               error = copyout_map(td, &uvp, propsiz);
X               if (error)
X                       goto out2;
X               copyout(vp, (void *)uvp, propsiz);
X
X               if ((error = fget(td, args->fd, &fp)) != 0) {
X                       (void)copyout_unmap(td, uvp, propsiz);
X                       goto out2;
X               }
X               vps.props = (void *)uvp;
X               if ((args->cmd & 0xffff) == LINUX_FE_SET_PROPERTY)
X                       error = fo_ioctl(fp, FE_SET_PROPERTY, &vps, 
td->td_ucred, td);
X               else
X                       error = fo_ioctl(fp, FE_GET_PROPERTY, &vps, 
td->td_ucred, td);
X               if (error) {
X                       (void)copyout_unmap(td, uvp, propsiz);
X                       goto out;
X               }
X               error = copyin((void *)uvp, vp, propsiz);
X               (void)copyout_unmap(td, uvp, propsiz);
X               if (error)
X                       goto out;
X               for (i = vps.num, l_p = l_vp, p = vp; i--; ++l_p, ++p)
X                       bsd_to_linux_dtv_property(p, l_p);
X               linux_to_bsd_dtv_properties(&l_vps, &vps);
X               copyout(l_vp, (void *)vps.props, l_propsiz);
X
X       out:
X               fdrop(fp, td);
X       out2:
X               if (l_vp)
X                       free(l_vp, M_LINUX_DVB);
X               if (vp)
X                       free(vp, M_LINUX_DVB);
X               return (error);
X
X       default:                        return (ENOIOCTL);
X       }
X
X       error = ioctl(td, (struct ioctl_args *)args);
X       return (error);
X}
62000c07502c575e896a5f7ba0f4c3e5
exit

_______________________________________________
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "freebsd-hackers-unsubscr...@freebsd.org"

Reply via email to