The HyperNews Linux KHG Discussion Pages

Hurray! Use special device files!

Forum: Supporting Functions
Re: Question File access within a device driver? (Paul Osborn)
Keywords: file access device driver
Date: Wed, 11 Feb 1998 11:47:50 GMT
From: Rubens Nogueira <mytsplick@hotmail.com>

Itīs simple: create an object file like a loadable module using the skeleton from  Michael Johnsonīs "Writing Linux device drivers"(http://www.redhat.com/~johnsonm/devices.html).
Load this file to obtain the major number (put a printk(major) within the function init_module()). Then type the shell command :
       mknod -m 666 /dev/device c mj 0
This command creates a special device file that is useful to transmit information between executable file and loaded module. Create an executable file with the function open("/dev/device", ...) to open the special device file. When you need to write bytes to the device, use write(); to read bytes, use read(); this commands fills a module buffer. The module buffer will hold your information for use by device. Do you understand? I suffer very much time to comprehend this, but now I can smile again ! I CAN WRITE TO AND READ FROM A DEVICE! I GET ACCESS TO HARDWARE THROUGH AN EXECUTABLE FILE! 

I hope all you understand my English...

Rubens - University of Sao Paulo - Brazil