LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel
User Name
Password
Linux - Kernel This forum is for all discussion relating to the Linux kernel.

Notices



Reply
 
Search this Thread
Old 11-30-2012, 07:24 AM   #1
AnkurTank
LQ Newbie
 
Registered: Oct 2012
Posts: 13

Rep: Reputation: Disabled
Question 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 ?
 
Old 11-30-2012, 09:22 AM   #2
linuxxer
Member
 
Registered: Apr 2011
Location: I have my own planet
Distribution: SlackwareŽ
Posts: 72
Blog Entries: 1

Rep: Reputation: Disabled
Quote:
Originally Posted by AnkurTank View Post
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 View Post
I also want same device to be accessed through alias device
Create symlink using udev rules.

Last edited by linuxxer; 11-30-2012 at 09:24 AM.
 
Old 03-25-2013, 10:04 AM   #3
AnkurTank
LQ Newbie
 
Registered: Oct 2012
Posts: 13

Original Poster
Rep: Reputation: Disabled
Smile 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
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
find file and create a symbolic link dragos19 Linux - Newbie 4 03-25-2008 01:41 AM
How to create symbolic link to html file and avoid page link problem? haxpor Linux - General 2 01-29-2008 08:40 AM
How do I create a symbolic link? Arenba Linux - Newbie 4 09-29-2003 11:40 AM
How to create a Symbolic Link? sikandar Linux - Software 6 09-09-2003 12:41 PM
how do I create a symbolic link? rdaves@earthlink.net Linux - Newbie 2 05-23-2001 02:28 PM


All times are GMT -5. The time now is 08:57 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration