Call Driver Function

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)

Thank you
Thank you thats helps a bit. Just a question, at page 11 it uses: fwrite(&byte,1,1,PARLELPORT); to write to the port.

How does he associate that with the functions parlelport_write? Was it done when he defined the fops structure?

Thank you!
That was done by creating a node in /dev using mknod after the module was loaded:

http://www.freesoftwaremagazine.com/articles/drivers_linux?page=0,3

FSM wrote:

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
Last edited on
Hmm thats makes sense, but is there a file function for each file_operations option? As example how would i call llseek or ioctl?
I'm really not an expert on this. But I don't see why you wouldn't simply fill out further entries in struct file_operations.
http://www.freesoftwaremagazine.com/articles/drivers_linux?page=0,8
Maybe something like this:
1
2
3
4
5
6
7
8
struct file_operations parlelport_fops = { 
  read: parlelport_read,
  write: parlelport_write,
  open: parlelport_open,
  release: parlelport_release,

  llseek: parlelport_llseek
};


Thank you, but i mean, how would i call it as i cal write with fwrite. Thank you!!
Topic archived. No new replies allowed.