Why writing files from the kernel is bad ?
Reasons
The question "how to I open/read/write files from the kernel ?" is often asked on the kernelnewbies mailing list. However, the question cannot really be answered: opening, reading and writing files from within the kernel is usually a bad idea. Generally speaking, trying to use any of the sys_*() functions from the kernel itself is a bad idea.
For several reasons:
- it is not the role of the kernel
The good ways to exchange data with user space
There are several ways to exchange informations between userspace and the kernel, and the one to use really depends on what you want to do:
- kernel module parameters are useful to set general configuration options for your modules
[http://sosdg.org/~coywolf/lxr/source/Documentation/filesystems/sysfs.txt sysfs] is useful to get/set attributes to devices
[http://lwn.net/Articles/115405/ debugfs]
[http://sosdg.org/~coywolf/lxr/source/Documentation/filesystems/relayfs.txt relayfs]
- netlink sockets
Using /proc is not anymore a good idea these days, except if you want to export information related to processes.
The good way to create device nodes
The good way is to have your device exported in sysfs and to let udev create the device node in /dev. Do not call try to call sys_mknod() from the kernel.