On Tue, Nov 2, 2010 at 3:10 AM, Victor Rodriguez <vm.rod25@xxxxxxxxx> wrote: > Hi all > > I have a doubt I have checked the Char Driver from Linux Device > Drivers 3rd edition and I can not understand how does the char driver > is register in the newst way, I just have done by the Linux Kernel > Module programing guide example > > http://tldp.org/LDP/lkmpg/2.6/html/x569.html > > with the function > > > int init_module(void) > { > Major = register_chrdev(0, DEVICE_NAME, &fops); > > if (Major < 0) { > printk(KERN_ALERT "Registering char device failed with %d\n", Major); > return Major; > } > > printk(KERN_INFO "I was assigned major number %d. To talk to\n", Major); > printk(KERN_INFO "the driver, create a dev file with\n"); > printk(KERN_INFO "'mknod /dev/%s c %d 0'.\n", DEVICE_NAME, Major); > printk(KERN_INFO "Try various minor numbers. Try to cat and echo to\n"); > printk(KERN_INFO "the device file.\n"); > printk(KERN_INFO "Remove the device file and module when done.\n"); > > return SUCCESS; > } > > but the new way is with alloc_chrdev_region and > > struct cdev *my_cdev = cdev_alloc( ); > my_cdev->ops = &my_fops; > > but i can not see any good and easy example on the internet > > Does anybody has seen any one ? > > One more thing > > After insert the module on the kernel I need to run > > mknod > > in order to make the node to interact with cat and echo instructions > > Is there another automatic way to do that ? I have read a litle bit > from udev, but I wonder how does the /dev char drivers are created > when linux start ? AFAIK registering your device to a class will send an event to userspace. This event will be handled by udev and (eventually) a node will be created. You can have a look here ([1]), where the simple miscdev class is used. Also you should read chapter 14 from LDD3 ([2]). thanks, Daniel. [1] http://lxr.linux.no/#linux+v2.6.36/drivers/s390/char/vmcp.c#L172 [2] http://lwn.net/Kernel/LDD3/ -- To unsubscribe from this list: send an email with "unsubscribe kernelnewbies" to ecartis@xxxxxxxxxxxx Please read the FAQ at http://kernelnewbies.org/FAQ