Hi, i am new to Linux C Programing (Just used to Windows). I am developing a PCI Card and the driver for Linux but i got a problem. I got no idea how to call a driver function i defined on my driver (read and write basicaly) inside my C program. How can i do that? I am using 2.6 Kernel. I used to do that o windows, and is quitte simple (althought it is not simple to make the driver itself on windows, linux is much less complicated)
In UNIX and Linux, devices are accessed from user space in exactly the same way as files are accessed. These device files are normally subdirectories of the /dev directory.
To link normal files with a kernel module two numbers are used: major number and minor number. The major number is the one the kernel uses to link a file with its driver. The minor number is for internal use of the device and for simplicity it won’t be covered in this article.
To achieve this, a file (which will be used to access the device driver) must be created, by typing the following command as root:
# mknod /dev/memory c 60 0
In the above, c means that a char device is to be created, 60 is the major number and 0 is the minor number.
Within the driver, in order to link it with its corresponding /dev file in kernel space, the register_chrdev function is used. It is called with three arguments: major number, a string of characters showing the module name, and a file_operations structure which links the call with the file functions it defines.
Device drivers in Linux are treated like files in the /dev tree