Hi,

the attached patch makes the ltp/testcases/kernel/device-drivers/nls
testsuite compileable under Linux kernel 2.6.25.

Currently the test_nls_base() crashes with 2.6.25, but without calling that
function the module loads and unloads cleanly. This can be a base for checking
what is going wrong with nls.

Signed-off-by: Márton Németh <[email protected]>


Best regards,

        Márton Németh
diff -uprN ltp.orig/testcases/kernel/device-drivers/nls/Makefile ltp/testcases/kernel/device-drivers/nls/Makefile
--- ltp.orig/testcases/kernel/device-drivers/nls/Makefile	2003-07-08 20:24:13.000000000 +0200
+++ ltp/testcases/kernel/device-drivers/nls/Makefile	2009-01-06 21:34:52.000000000 +0100
@@ -3,7 +3,7 @@
 #
 
 #KERNELDIR := /usr/src/linux-2.5.66-gcov
-CFLAGS := $(CFLAGS) -Wall
+EXTRA_CFLAGS := -Wall -Wextra -Wno-unused-parameter
 
 ifneq ($(KERNELRELEASE),)
 
@@ -14,10 +14,19 @@ PWD	:= $(shell pwd)
 
 default:
 	$(MAKE) -C $(KDIR) SUBDIRS=$(PWD) modules
-	gcc -Wall -o userBlockNLS userBlockNLS.c
+	gcc $(EXTRA_CFLAGS) -o userBlockNLS userBlockNLS.c
 #	$(MAKE) -C $(KERNELDIR) SUBDIRS=$(PWD) modules
 endif
 
 clean:
-	rm -f nlsTest.o 2>/dev/null || true
-
+	rm -f modules.order
+	rm -f Module.symvers
+	rm -f userBlockNLS
+	rm -f nlsTest.o
+	rm -f nlsTest.ko
+	rm -f nlsTest.mod.c
+	rm -f nlsTest.mod.o
+	rm -f .nlsTest.ko.cmd
+	rm -f .nlsTest.mod.o.cmd
+	rm -f .nlsTest.o.cmd
+	rm -rf .tmp_versions
diff -uprN ltp.orig/testcases/kernel/device-drivers/nls/nlsTest.c ltp/testcases/kernel/device-drivers/nls/nlsTest.c
--- ltp.orig/testcases/kernel/device-drivers/nls/nlsTest.c	2006-01-09 20:17:16.000000000 +0100
+++ ltp/testcases/kernel/device-drivers/nls/nlsTest.c	2009-01-10 14:24:42.000000000 +0100
@@ -18,6 +18,12 @@
  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  */
 
+/*
+ * Legacy Power Management (PM) was removed from the kernel, removed it from
+ * here also. ( http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commit;h=6afe1a1fe8ff83f6ac2726b04665e76ba7b14f3e )
+ *
+ */
+
 #include <linux/types.h>
 #include <linux/kernel.h>
 #include <linux/fs.h>
@@ -28,8 +34,9 @@
 #include <linux/genhd.h>
 #include <linux/version.h>
 #include <linux/string.h>
-#include <linux/config.h>
+#include <linux/autoconf.h>
 #include <linux/nls.h>
+#include <linux/blkdev.h>
 
 #ifdef CONFIG_KMOD
 #include <linux/kmod.h>
@@ -37,149 +44,220 @@
 
 #include <linux/errno.h>
 #include <linux/spinlock.h>
-#include <asm/uaccess.h>
+#include <linux/uaccess.h>
+
 #include "nlsTest.h"
 
 MODULE_AUTHOR("David Cruz <[email protected]>");
+MODULE_AUTHOR("Márton Németh <[email protected]>");
 MODULE_DESCRIPTION(TEST_DRIVER_NAME);
 MODULE_LICENSE("GPL");
 
-static int test_ioctl (struct inode *, struct file *, unsigned int, unsigned long);
-static int test_open (struct inode *, struct file *);
-static int test_close (struct inode *, struct file *);
+/* Struct block_device_operations changed:
+ * http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commitdiff;h=d4430d62fa77208824a37fe6f85ab2831d274769
+ */
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 28)
+static int test_open(struct inode *, struct file *);
+static int test_release(struct inode *, struct file *);
+static int test_ioctl(struct inode *, struct file *,
+		      unsigned int cmd, unsigned long l);
+#else
+static int test_open(struct block_device *bdev, fmode_t mode);
+static int test_release(struct gendisk *disk, fmode_t mode);
+static int test_ioctl(struct block_device *bdev, fmode_t mode,
+		      unsigned int cmd, unsigned long l);
+#endif
+
 static void test_nls_base(void);
+static void option1(void);
+
+
+struct test_block_device {
+	spinlock_t queue_lock;
+};
+
 
 static struct block_device_operations bdops = {
-        open: test_open,
-        release: test_close,
-        ioctl: test_ioctl,
+	.open = test_open,
+	.release = test_release,
+	.ioctl = test_ioctl,
 };
 
-static char genhd_flags = 0;
-static struct gendisk * gd_ptr;
-static struct pm_dev *ltp_pm_dev = NULL;
+static struct gendisk *gd_ptr;
 
-static int test_open(struct inode *ino, struct file *f) {
-	printk("device open\n");
-        return 0;
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 28)
+static int test_open(struct inode *inode, struct file *f)
+#else
+static int test_open(struct block_device *bdev, fmode_t mode)
+#endif
+{
+	printk(KERN_DEBUG "device opened\n");
+	return 0;
 }
 
-static int test_close(struct inode *ino, struct file *f) {
-	printk("device closed\n");
-        return 0;
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 28)
+static int test_release(struct inode *ino, struct file *f)
+#else
+static int test_release(struct gendisk *disk, fmode_t mode)
+#endif
+{
+	printk(KERN_DEBUG "device released\n");
+	return 0;
 }
 
-static int test_ioctl(struct inode *ino, struct file *f, unsigned int cmd, unsigned long l) {
-
-	int rc = 0;             //return code
-        int arg;
-
-        printk("Entered the ioctl call.\n");
-
-        if (copy_from_user(&arg, (void *)l, sizeof(int)) ) {
-                //bad address
-                return(-EFAULT);
-        }
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 28)
+static int test_ioctl(struct inode *ino, struct file *f,
+		      unsigned int cmd, unsigned long l)
+#else
+static int test_ioctl(struct block_device *bdev, fmode_t mode,
+		      unsigned int cmd, unsigned long l)
+#endif
+{
+	int rc = 0;             /* return code */
+	int arg;
+
+	printk(KERN_DEBUG "Entered the ioctl call.\n");
+
+	if (copy_from_user(&arg, (void *)l, sizeof(int))) {
+		/* bad address */
+		return -EFAULT;
+	}
 
-	switch(cmd) {
-                case OPTION1: option1(); break;
-                default:
-                        printk("Mismatching ioctl command\n");
-                        break;
-        }
-        //0 by default
-        return rc;
-}
+	switch (cmd) {
+	case OPTION1:
+		option1();
+		break;
+	default:
+		printk(KERN_ERR "Mismatching ioctl command\n");
+	}
 
-static void option1(void) {
-        printk("Module option 1 chosen\n");
+	return rc;
 }
 
-static int ltp_pm_callback(struct pm_dev *dev, pm_request_t rqst, void *data) {
-        return 0;
+static void option1(void)
+{
+	printk(KERN_DEBUG "Module option 1 chosen\n");
 }
 
-static int test_init_module(void) {
+static void test_request(struct request_queue *q)
+{
+	printk(KERN_DEBUG "test_request() called\n");
+};
 
+static int test_init_module(void)
+{
+	struct test_block_device *dev;
+	struct request_queue *queue;
 	int rc;
 
-	printk("starting module\n");
+	printk(KERN_DEBUG "starting module\n");
+
+	dev = kzalloc(sizeof(*dev), GFP_KERNEL);
+	if (!dev)
+		return -ENOMEM;
 
-	ltp_pm_dev = pm_register(PM_UNKNOWN_DEV, 0, ltp_pm_callback);
 	rc = register_blkdev(NLSMAJOR, DEVICE_NAME);
 
-	printk("BLK INC - result =%d major %d\n",rc,NLSMAJOR);
+	printk(KERN_DEBUG "BLK INC - result=%d, major=%d\n", rc, NLSMAJOR);
+
+	if (rc < 0) {
+		printk(KERN_ERR "Failed to register device.\n");
+		kfree(dev);
+		return rc;
+	}
 
-        if(rc < 0) {
-                printk("Failed to register device.\n");
-                return rc;
-        }
+	spin_lock_init(&dev->queue_lock);
 
-	gd_ptr = kmalloc(sizeof(struct gendisk *),GFP_KERNEL);
+	gd_ptr = alloc_disk(1);
 	if (!gd_ptr) {
-		 printk(KERN_ALERT "ERROR getting memory !!!\n");
-		 return 0;
+		unregister_blkdev(NLSMAJOR, DEVICE_NAME);
+		kfree(dev);
+		return -ENOMEM;
+	}
+
+	printk(KERN_ALERT "gd_ptr after alloc=%p\n", gd_ptr);
+
+	queue = blk_init_queue(test_request, &dev->queue_lock);
+	if (!queue) {
+		del_gendisk(gd_ptr);
+		unregister_blkdev(NLSMAJOR, DEVICE_NAME);
+		kfree(dev);
+		return -ENOMEM;
 	}
 
-        printk("major = %d\n",NLSMAJOR);
-	gd_ptr = alloc_disk(1);
-	printk(KERN_ALERT "gd_ptr after alloc = %p \n",gd_ptr);
 	gd_ptr->major = NLSMAJOR;
 	gd_ptr->first_minor = 0;
 	gd_ptr->fops = &bdops;
-	gd_ptr->minor_shift= MINOR_SHIFT_BITS;
-	gd_ptr->driverfs_dev = NULL;
-	gd_ptr->capacity = MAX_NUM_DISKS;
-	gd_ptr->disk_de = NULL;
-	gd_ptr->flags = genhd_flags;
-
-	sprintf(gd_ptr->disk_name, DEVICE_NAME);
+	gd_ptr->queue = queue;
+	gd_ptr->private_data = dev;
+	snprintf(gd_ptr->disk_name, sizeof(gd_ptr->disk_name), DEVICE_NAME);
 	add_disk(gd_ptr);
-	
+
+	printk(KERN_DEBUG "block device %s added\n", DEVICE_NAME);
+
 	test_nls_base();
-	
+
 	return 0;
 }
 
 
-static void test_exit_module(void) {
-        
-	int rc;
-	
-        pm_unregister(ltp_pm_dev);
-        put_disk(gd_ptr);
-        del_gendisk(gd_ptr);
-	
-	rc = unregister_blkdev(NLSMAJOR, DEVICE_NAME);
-		
-        if(rc < 0) {
-                printk("unregister failed %d\n",rc);
-        }
-        else {
-                printk("unregister success\n");
-        }
-}
-
-static void test_nls_base(void) {
-
-	wchar_t p=0x20;
-	__u8 s=0x01;
-	int n=2;
+static void test_exit_module(void)
+{
+	printk(KERN_DEBUG "unloading module\n");
+
+	del_gendisk(gd_ptr);
+	unregister_blkdev(NLSMAJOR, DEVICE_NAME);
+}
+
+static void test_nls_base(void)
+{
+	wchar_t p = 0x20;
+	__u8 s = 0x01;
+	int n = 2;
 	struct nls_table nls;
-	char charset[20]="David";
-	
-	load_nls_default();
-	register_nls(&nls);
+	struct nls_table *nls_ptr;
+	int ret;
+	char charset[20] = "David";
+
+	memset(&nls, 0, sizeof(nls));
+
+	printk(KERN_DEBUG "Calling load_nls_default()\n");
+	nls_ptr = load_nls_default();
+	printk(KERN_DEBUG "load_nls_default() returns %p\n", nls_ptr);
+
+	printk(KERN_DEBUG "Calling register_nls(%p)\n", &nls);
+	ret = register_nls(&nls);
+	printk(KERN_DEBUG "register_nls() returns %i\n", ret);
+
+	printk(KERN_DEBUG "Calling unload_nls(%p)\n", &nls);
 	unload_nls(&nls);
-	load_nls(charset);
+
+	printk(KERN_DEBUG "Calling load_nls(\"%s\")\n", charset);
+	nls_ptr = load_nls(charset);
+	printk(KERN_DEBUG "load_nls() returns %p\n", nls_ptr);
+
+	printk(KERN_DEBUG "Calling unregister_nls(%p)\n", &nls);
 	unregister_nls(&nls);
-	utf8_mbtowc(&p, &s, n);
-	utf8_mbstowcs(&p, &s, n);
-	n=20;
-	utf8_wctomb(&s, p, n);
-	utf8_wcstombs(&s, &p, n);
-}
 
+	printk(KERN_DEBUG "Calling utf8_mbtowc(%p, %p, %i);\n", &p, &s, n);
+	ret = utf8_mbtowc(&p, &s, n);
+	printk(KERN_DEBUG "utf8_mbtowc() returns %i\n", ret);
+
+	printk(KERN_DEBUG "Calling utf8_mbstowcs(%p, %p, %i);\n", &p, &s, n);
+	ret = utf8_mbstowcs(&p, &s, n);
+	printk(KERN_DEBUG "utf8_mbstowcs() returns %i\n", ret);
+
+	n = 20;
+
+	printk(KERN_DEBUG "Calling utf8_wctomb(%p, 0x%X, %i);\n", &s, p, n);
+	ret = utf8_wctomb(&s, p, n);
+	printk(KERN_DEBUG "utf8_wctomb() returns %i\n", ret);
+
+	printk(KERN_DEBUG "Calling utf8_wcstombs(%p, %p, %i);\n", &s, &p, n);
+	ret = utf8_wcstombs(&s, &p, n);
+	printk(KERN_DEBUG "utf8_wcstombs() returns %i\n", ret);
+
+}
 
-module_init(test_init_module)
-module_exit(test_exit_module)
+module_init(test_init_module);
+module_exit(test_exit_module);
diff -uprN ltp.orig/testcases/kernel/device-drivers/nls/nlsTest.h ltp/testcases/kernel/device-drivers/nls/nlsTest.h
--- ltp.orig/testcases/kernel/device-drivers/nls/nlsTest.h	2006-01-09 20:17:16.000000000 +0100
+++ ltp/testcases/kernel/device-drivers/nls/nlsTest.h	2009-01-05 21:26:57.000000000 +0100
@@ -42,10 +42,3 @@ typedef enum nlsdev_ioctl_cmds_s {
 } nlsdev_ioctl_cmds_t;
 
 #define NLSDEV_CMD              _IOR(NLSMAJOR, NLS_IOCTL_NUMBER, nlsdev_cmd_t**)
-
-/*
- * function prototypes
- */
-
-static void option1(void);
-
diff -uprN ltp.orig/testcases/kernel/device-drivers/nls/README ltp/testcases/kernel/device-drivers/nls/README
--- ltp.orig/testcases/kernel/device-drivers/nls/README	1970-01-01 01:00:00.000000000 +0100
+++ ltp/testcases/kernel/device-drivers/nls/README	2009-01-05 21:42:23.000000000 +0100
@@ -0,0 +1,3 @@
+
+Depends on "nls_base" kernel module.
+Depends on CONFIG_NLS.
diff -uprN ltp.orig/testcases/kernel/device-drivers/nls/userBlockNLS.c ltp/testcases/kernel/device-drivers/nls/userBlockNLS.c
--- ltp.orig/testcases/kernel/device-drivers/nls/userBlockNLS.c	2006-01-09 20:17:16.000000000 +0100
+++ ltp/testcases/kernel/device-drivers/nls/userBlockNLS.c	2009-01-05 20:34:03.000000000 +0100
@@ -91,8 +91,8 @@ int open_block_device()
                                                     S_IROTH | S_IXOTH));
 		
             } else {
-                printf("ERROR: Problem with INC dev directory.  Error code from stat(
-			) is %d\n\n", errno);
+                printf("ERROR: Problem with INC dev directory.  Error code from stat() "
+			"is %d\n\n", errno);
             }
         } else {
 	    if (!(statbuf.st_mode & S_IFDIR)) {
diff -uprN ltp.orig/testcases/kernel/device-drivers/tbio/kernel_space/Makefile ltp/testcases/kernel/device-drivers/tbio/kernel_space/Makefile
--- ltp.orig/testcases/kernel/device-drivers/tbio/kernel_space/Makefile	2006-08-21 09:07:12.000000000 +0200
+++ ltp/testcases/kernel/device-drivers/tbio/kernel_space/Makefile	2009-01-10 08:25:46.000000000 +0100
@@ -3,7 +3,7 @@
 #
 
 #KERNELDIR := /usr/src/linux-2.5.64-gcov
-CFLAGS := $(CFLAGS) -Wall
+EXTRA_CFLAGS := -Wall
 
 ifneq ($(KERNELRELEASE),)
 
------------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It is the best place to buy or sell services for
just about anything Open Source.
http://p.sf.net/sfu/Xq1LFB
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

Reply via email to