[COLUG] Re: Linux Kernel Modules
Travis Sidelinger
travis at ilive4code.net
Sun Oct 1 22:09:55 EDT 2006
Another follow-up from last Wednesday.
I figured out why my example with sysfs tree entries did not compile.
class_simple has been moved from the kernel at version >= 2.6.13
Below is what's needed to create a simple sysfs class entry. With a
class entry, udev will receive a hotplug event and automatically create
the /dev/chardev device node file.
...
// Create sysfs entry for udev
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,13))
chardev_class = class_create(THIS_MODULE,module_name);
if(IS_ERR(chardev_class))
{
printk(KERN_ALERT "%s: failed to create sysfs entry\n",
module_name);
return(result);
}
class_device_create(chardev_class, NULL, devnum, NULL, module_name);
#else
chardev_class = class_simple_create(THIS_MODULE,module_name);
if(IS_ERR(chardev_class))
{
printk(KERN_ALERT "%s: failed to create sysfs entry\n",
module_name);
return(result);
}
class_simple_device_add(chardev_class, devnum, NULL, module_name);
#endif
...
// Remove sysfs entry
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,13))
class_device_destroy(chardev_class,devnum);
class_destroy(chardev_class);
#else
class_simple_device_remove(devnum);
class_simple_destroy(chardev_class);
#endif
Here is the full program:
http://www.ilive4unix.net/doku.php/code/linux#character_device
> Thanks everyone for your attention tonight. Hopefully I didn't put
> too many people to sleep.
>
> Here are my wiki notes this lecture was based on:
> http://www.ilive4unix.net/doku.php/notes/unix/linux/device-drivers
>
> The open doc presentation file is posted on the wiki.
>
> My examples are posted here:
> http://www.ilive4unix.net/doku.php/code/linux
>
> Errata:
> - My sysfs example failed because the class_simple interface has been
> removed from new kernel versions. I will try to get an example posted
> once I get some working code. This example does work under CentOS
> (kernel 2.6.9)
> - I update my wiki notes for coping data to and from kernel space.
> - Added /etc/modprobe.conf info
>
> Travis Sidelinger
>
More information about the colug432
mailing list