ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
If you can do something (execute a command) by hand, you can do it from a script, can't you ?
Is it the only way , to write additional script ?
Is there any way to do it without writing additional script?
What i want is to do it by only single C code.
How can i execute mknod command in my module code ?
Is it the only way , to write additional script ?
Is there any way to do it without writing additional script?
What i want is to do it by only single C code.
How can i execute mknod command in my module code ?
I don't think you correctly understand how a driver works. Driver is a piece of code called by some other piece of code.
Why do you want the single piece of "C" code ? What's the ultimate goal ?
Well, it isn't in English ,making tranlastion might lead misunderstanding the problem.
So i found this; http://www.faqs.org/docs/kernel/x571.html#AEN692
In this web site , where i took character device driver example code , it says ;
Quote:
If you pass a major number of 0 to register_chrdev, the return value will be the dynamically allocated major number. The downside is that you can't make a device file in advance, since you don't know what the major number will be. There are a couple of ways to do this. First, the driver itself can print the newly assigned number and we can make the device file by hand. Second, the newly registered device will have an entry in /proc/devices, and we can either make the device file by hand or write a shell script to read the file in and make the device file. The third method is we can have our driver make the the device file using the mknod system call after a successful registration and rm during the call to cleanup_module.
First mentioned way , the way i did , our driver prints assigned number and we made device file with mknod command and it works.
Second way , is using shell script which shall read entry from /proc/devices/ , which isn't wanted.
Third way , is the wanted way , "our driver make the the device file using the mknod system call after a successful registration."
How can we achieve this third way ?
Well, it isn't in English ,making tranlastion might lead misunderstanding the problem.
So i found this; http://www.faqs.org/docs/kernel/x571.html#AEN692
In this web site , where i took character device driver example code , it says ;
First mentioned way , the way i did , our driver prints assigned number and we made device file with mknod command and it works.
Second way , is using shell script which shall read entry from /proc/devices/ , which isn't wanted.
Third way , is the wanted way , "our driver make the the device file using the mknod system call after a successful registration."
How can we achieve this third way ?
The problem is solved .
Thanks for help , Sergei Steshenko,
It's solved without executing shell command.It also sounds nonsense that executing shell commands in a module.
I'll copy-paste solution here, maybe later, it'll help people
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.