RE: using sys_mknod in init_module

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



>   Hi all,
> 
>      How to use sys_mknod function call in the driver init_module.
> Currently my init_module function looks like as follows. I am trying
> to create a device file in my init_module itself.
> 
> static int __init init_my_module(void)
> {
>         char device_name[15] = {'\0'};
>         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\n");
>         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");
> 
>         sys_mknod = sys_call_table[ __NR_mknod];
>         sprintf(device_name, "/dev/%s", DEVICE_NAME);
>         set_fs( get_ds() );
>         sys_mknod(device_name, S_IFCHR|0666, MKDEV(Major,1));
>         return SUCCESS;
> }
> 
>    I am getting following warning....
> 
>     *** Warning: "sys_call_table"
> [/home/NTEK-APPL/MODULE_PG/CHP4/chardev.ko] undefined!
> 
>      It looks like to me "sys_call_table" is not exported to kernel.
> If it is true  then how to export it else how to solve this problem.
> 
>    Currently I am manually creating the device file using mknod in
shell.
> 
> Thanks
> Manjunath Naik

Dear Manjunath,

You can create the nodes in the init modules using the following way.

static struct class_simple *dev_class;

	dev_class = class_simple_create(THIS_MODULE, "dev_name");
	if(IS_ERR(dev_class))
		printk("Error creating device class\n");

	for (i=0; i<3; i++)
	{	
		class_simple_device_add(dev_class,
MKDEV(device_major,i), 
					NULL, "dev_name%d",i);
	}

You can also remove the created node in the cleanup module by the
following way.

	for(i=0; i<3; i++)
	{
		class_simple_device_remove(MKDEV(device_major,i));
	}
	class_simple_destroy(dev_class);
		
This was tested using the 2.6.9-1.667 kernel version. I think it may
work with other 2.6.x kernels.

For more information you can go through the following link.
http://lwn.net/images/pdf/LDD3/ch14.pdf

You can find the information from the 42nd page of the chapter and
headed by UDEV.

I think this solves your problem. If not let us know.

Thanks and Regards,
Srinivas G

--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/



[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux