/*
* ioctl32.c: Conversion between 32bit and 64bit native ioctls.
* Separated from fs stuff by Arnd Bergmann <arnd@arndb.de>
*
* Copyright (C) 1997-2000 Jakub Jelinek (jakub@redhat.com)
* Copyright (C) 1998 Eddie C. Dost (ecd@skynet.be)
* Copyright (C) 2001,2002 Andi Kleen, SuSE Labs
* Copyright (C) 2003 Pavel Machek (pavel@suse.cz)
* Copyright (C) 2005 Philippe De Muyter (phdm@macqel.be)
*
* These routines maintain argument size conversion between 32bit and 64bit
* ioctls.
*/
#include <linux/compat.h>
#include <linux/videodev.h>
#include <linux/videodev2.h>
#include <linux/module.h>
#include <linux/smp_lock.h>
#include <media/v4l2-common.h>
#ifdef CONFIG_COMPAT
#ifdef CONFIG_VIDEO_V4L1_COMPAT
struct video_tuner32 {
compat_int_t tuner;
char name[32];
compat_ulong_t rangelow, rangehigh;
u32 flags; /* It is really u32 in videodev.h */
u16 mode, signal;
};
static int get_video_tuner32(struct video_tuner *kp, struct video_tuner32 __user *up)
{
if(!access_ok(VERIFY_READ, up, sizeof(struct video_tuner32)) ||
get_user(kp->tuner, &up->tuner) ||
copy_from_user(kp->name, up->name, 32) ||
get_user(kp->rangelow, &up->rangelow) ||
get_user(kp->rangehigh, &up->rangehigh) ||
get_user(kp->flags, &up->flags) ||
get_user(kp->mode, &up->mode) ||
get_user(kp->signal, &up->signal))
return -EFAULT;
return 0;
}
static int put_video_tuner32(struct video_tuner *kp, struct video_tuner32 __user *up)
{
if(!access_ok(VERIFY_WRITE, up, sizeof(struct video_tuner32)) ||
put_user(kp->tuner, &up->tuner) ||
copy_to_user(up->name, kp->name, 32) ||
put_user(kp->rangelow, &up->rangelow) ||
put_user(kp->rangehigh, &up->rangehigh) ||
put_user(kp->flags, &up->flags) ||
put_user(kp->mode, &up->mode) ||
put_user(kp->signal, &up->signal))
return -EFAULT;
return 0;
}
struct video_buffer32 {
compat_caddr_t base;
compat_int_t height, width, depth, bytesperline;
};
static int get_video_buffer32(struct video_buffer *kp, struct video_buffer32 __user *up)
{
u32 tmp;
if (!access_ok(VERIFY_READ, up, sizeof(struct video_buffer32)) ||
get_user(tmp, &up->base) ||
get_user(kp->height, &up->height) ||
get_user(kp->width, &up->width) ||
get_user(kp->depth, &up->depth) ||
get_user(kp->bytesperline, &up->bytesperline))
return -EFAULT;
/* This is actually a physical address stored
* as a void pointer.
*/
kp->base = (void *)(unsigned long) tmp;
return 0;
}
static int put_video_buffer32(struct video_buffer *kp, struct video_buffer32 __user *up)
{
u32 tmp = (u32)((unsigned long)kp->base);
if(!access_ok(VERIFY_WRITE, up, sizeof(struct video_buffer32)) ||
put_user(tmp, &up->base) ||
put_user(kp->height, &up->height) ||
put_user(kp->width, &up->width) ||
put_user(kp->depth, &up->depth) ||
put_user(kp->bytesperline, &up->bytesperline))
return -EFAULT;
return 0;
}
struct video_clip32 {
s32 x, y, width, height; /* Its really s32 in videodev.h */
compat_caddr_t next;
};
struct video_window32 {
u32 x, y, width, height, chromakey, flags;
compat_caddr_t clips;
compat_int_t clipcount;
};
#endif
static int native_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
{
int ret = -ENOIOCTLCMD;
if (file->f_op->unlocked_ioctl)
ret = file->f_op->unlocked_ioctl(file, cmd, arg);
else if (file->f_op->ioctl) {
lock_kernel();
ret = file->f_op->ioctl(file->f_path.dentry->d_inode, file, cmd, arg);
unlock_kernel();
}
return ret;
}
#ifdef CONFIG_VIDEO_V4L1_COMPAT
/* You get back everything except the clips... */
static int put_video_window32(struct video_window *kp, struct video_window32 __user *up)