diff mbox

UBI: add ioctl compatibility

Message ID 1232036381.25068.10.camel@localhost.localdomain
State New, archived
Headers show

Commit Message

Artem Bityutskiy Jan. 15, 2009, 4:19 p.m. UTC
Hi Arnd,

would you please glance if this patch all-right?



From: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
Subject: [PATCH] UBI: add ioctl compatibility

UBI ioctl's do not work when running 64-bit kernel and 32-bit
user-land. Fix this by adding ioctl translation etries to
fs/compat_ioctl.c

Reported-by: Geert Uytterhoeven <Geert.Uytterhoeven@sonycom.com>
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
---
 fs/compat_ioctl.c |   14 ++++++++++++++
 1 files changed, 14 insertions(+), 0 deletions(-)

Comments

Arnd Bergmann Jan. 15, 2009, 4:34 p.m. UTC | #1
On Thursday 15 January 2009, Artem Bityutskiy wrote:

> would you please glance if this patch all-right?

No, it's not. New ioctl numbers should not be added to fs/compat_ioctl.c
but rather to the file that implements the file operations (ubi/cdev.c).

The best way to do it would be to add functions that do

static long compat_vol_cdev_ioctl(struct file *file,
		unsigned int cmd, unsigned long arg)
{
	int ret;

	arg = (unsigned long)compat_ptr(arg);

	lock_kernel();
	ret = vol_cdev_locked_ioctl(file->f_inode, file, cmd, arg);
	unlock_kernel();

	return ret;
}

static long vol_cdev_ioctl(struct file *file,
		unsigned int cmd, unsigned long arg)
{
	int ret;

	lock_kernel();
	ret = vol_cdev_locked_ioctl(file->f_inode, file, cmd, arg);
	unlock_kernel();

	return ret;
}

and then use these two functions as your unlocked_ioctl and compat_ioctl
methods in file_operations.

If you can prove that you don't rely on the BKL, you can also drop the
{un,}lock_kernel() calls.


>  COMPATIBLE_IOCTL(MEMGETREGIONINFO)
>  COMPATIBLE_IOCTL(MEMGETBADBLOCK)
>  COMPATIBLE_IOCTL(MEMSETBADBLOCK)
> +/* UBI */
> +COMPATIBLE_IOCTL(UBI_IOCMKVOL)
> +ULONG_IOCTL(UBI_IOCRMVOL)
> +COMPATIBLE_IOCTL(UBI_IOCRSVOL)
> +COMPATIBLE_IOCTL(UBI_IOCRNVOL)
> +COMPATIBLE_IOCTL(UBI_IOCATT)
> +ULONG_IOCTL(UBI_IOCDET)
> +ULONG_IOCTL(UBI_IOCVOLUP)
> +ULONG_IOCTL(UBI_IOCEBER)
> +ULONG_IOCTL(UBI_IOCEBCH)
> +ULONG_IOCTL(UBI_IOCEBMAP)
> +ULONG_IOCTL(UBI_IOCEBUNMAP)
> +ULONG_IOCTL(UBI_IOCEBISMAP)

ULONG_IOCTL() would be wrong here, all your ioctl handlers expect
a pointer, not an unsigned long

	Arnd <><
diff mbox

Patch

diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
index 5235c67..f1e00e1 100644
--- a/fs/compat_ioctl.c
+++ b/fs/compat_ioctl.c
@@ -95,6 +95,7 @@ 
 #include <linux/sonet.h>
 #include <linux/atm_suni.h>
 #include <linux/mtd/mtd.h>
+#include <mtd/ubi-user.h>
 
 #include <linux/usb.h>
 #include <linux/usbdevice_fs.h>
@@ -2423,6 +2424,19 @@  COMPATIBLE_IOCTL(MEMGETREGIONCOUNT)
 COMPATIBLE_IOCTL(MEMGETREGIONINFO)
 COMPATIBLE_IOCTL(MEMGETBADBLOCK)
 COMPATIBLE_IOCTL(MEMSETBADBLOCK)
+/* UBI */
+COMPATIBLE_IOCTL(UBI_IOCMKVOL)
+ULONG_IOCTL(UBI_IOCRMVOL)
+COMPATIBLE_IOCTL(UBI_IOCRSVOL)
+COMPATIBLE_IOCTL(UBI_IOCRNVOL)
+COMPATIBLE_IOCTL(UBI_IOCATT)
+ULONG_IOCTL(UBI_IOCDET)
+ULONG_IOCTL(UBI_IOCVOLUP)
+ULONG_IOCTL(UBI_IOCEBER)
+ULONG_IOCTL(UBI_IOCEBCH)
+ULONG_IOCTL(UBI_IOCEBMAP)
+ULONG_IOCTL(UBI_IOCEBUNMAP)
+ULONG_IOCTL(UBI_IOCEBISMAP)
 /* NBD */
 ULONG_IOCTL(NBD_SET_SOCK)
 ULONG_IOCTL(NBD_SET_BLKSIZE)