--- kqemu/kmod.c 2005-02-10 23:09:09.000000000 +0100 +++ kqemu/kmod-sysfs.c 2005-02-22 19:46:44.000000000 +0100 @@ -15,7 +15,10 @@ #include #include #include - +#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,0) +#include +#endif +#include #include "kqemu.h" #if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,19) @@ -34,6 +37,10 @@ int page_alloc_count; #endif +#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,0) +static struct class_simple *kqemu_class; +#endif + /* lock the page at virtual address 'user_addr' and return its page index. Return -1 if error */ unsigned long CDECL kqemu_lock_user_page(unsigned long user_addr) @@ -296,17 +303,51 @@ max_locked_pages = 32768; ret = register_chrdev(KQEMU_MAJOR, "kqemu", &kqemu_fops); + if (ret < 0) { printk("kqemu: could not get major %d\n", KQEMU_MAJOR); return ret; } + +#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,0) + kqemu_class = class_simple_create(THIS_MODULE, "kqemu"); + + if (IS_ERR(kqemu_class)) { + unregister_chrdev(KQEMU_MAJOR, "kqemu"); + ret = PTR_ERR(kqemu_class); + goto out_chrdev; + } + + class_simple_device_add(kqemu_class, MKDEV(KQEMU_MAJOR, 0), NULL, "kqemu"); +#endif + + ret = devfs_mk_cdev(MKDEV(KQEMU_MAJOR, 0), + S_IFCHR|S_IRUSR|S_IWUSR, "kqemu"); + if (ret) + goto out_class; + printk("KQEMU installed, max_instances=%d max_locked_mem=%dkB.\n", KQEMU_MAX_INSTANCES, max_locked_pages * 4); return 0; + +out_class: +#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,0) + class_simple_device_remove(MKDEV(KQEMU_MAJOR,0)); + class_simple_destroy(kqemu_class); +#endif +out_chrdev: + unregister_chrdev(KQEMU_MAJOR, "kqemu"); + + return ret; } void cleanup_module(void) { unregister_chrdev(KQEMU_MAJOR, "kqemu"); + devfs_remove("kqemu"); +#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,0) + class_simple_device_remove(MKDEV(KQEMU_MAJOR, 0)); + class_simple_destroy(kqemu_class); +#endif }