LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Kernel (http://www.linuxquestions.org/questions/linux-kernel-70/)
-   -   How to create symbolic link to device file from driver (http://www.linuxquestions.org/questions/linux-kernel-70/how-to-create-symbolic-link-to-device-file-from-driver-4175439432/)

AnkurTank 11-30-2012 06:24 AM

How to create symbolic link to device file from driver
 
I am writing a driver in linux kernel wherein i want to create device file from driver itself using device_create() function. e.g. /dev/mydfolder/mydevice.
Now i have two questions,
1. Is there a way to create folder under /dev/ directory from driver ?
2. I also want same device to be accessed through alias device
e.g. /dev/mydfolder/mydevice should also be accessible through /dev/mydfolder/mydevice-alias
so is it possible to create symbolic link from driver ?

linuxxer 11-30-2012 08:22 AM

Quote:

Originally Posted by AnkurTank (Post 4840111)
is it possible to create symbolic link from driver ?

It is possible to create symbolic link, using udev rules
For example,

Code:

KERNEL=="mice",        SYMLINK+="mouse"
http://www.reactivated.net/writing_udev_rules.html

To create alias, write modprob configuration
For example,
Code:

$ cd /lib/modprobe.d
$ fgrep -w alias isapnp.conf
alias pnp:dPNP0F13 psmouse

Quote:

Originally Posted by AnkurTank (Post 4840111)
I also want same device to be accessed through alias device

Create symlink using udev rules.

AnkurTank 03-25-2013 09:04 AM

found exact solution
 
Thank you linuxxer,

Link you provided helped me to create udev rule for creating symlinks,
here is full solution to my question
Code:

det_t devno = MKDEV(major,minor);
static struct class *dev_class;

dev_class = class_create(THIS_MODULE,"myfolder")
device_create(dev_class,NULL,devno,NULL,"myfolder/mydevice");

above code is enough to create mydevice under /dev/myfolder. (myfolder is dynamically created)
But if symbolic link is required to be create for /dev/myfolder/mydevice then below udev rule is required to be put in one of the rules file under /etc/udev/rules.d/
[I had put this rule under local.rules]

Code:

SUBSYSTEM=="myfolder",  KERNEL=="myfolder/mydevice", SYMLINK+="myfolder/yourdevice"
Above udev rule will create symbolic link "yourdevice" to /dev/myfolder/mydevice in the same directory.

I extended rule for multiple devices with same major but different minor using udev rules from same link.
http://www.reactivated.net/writing_udev_rules.html


All times are GMT -5. The time now is 04:45 AM.