Treper
Treper

Reputation: 3653

about write function in linux device driver

I wrote a linux device driver and implemented the function device_write like this:

static int device_write(struct file* file,const char* buff,int count, loff * offp)
{
//some implementation
printk("write value %x to card\n",value);
//some implementation
}

I also implement the device_read function and have a printk to print some information in it. The problem is when I use the read(fd,buff,1) in application program the printk result is displayed but when I use the write(fd,buff,1) there is no printk's result.The device_write function may not be called.What can cause this problem? Have anyone encounter this kind of problem before? Can anybody give me some help and suggestion?

Upvotes: 2

Views: 1410

Answers (1)

nategoose
nategoose

Reputation: 12392

This is only half an answer, but it is too big for a comment.

Are other actions within your device_write function happening?

Do a very simple printk at the top of the device_write function and see if that prints. Something like

static int device_write(struct file* file,const char* buff,int count, loff * offp)
{
    printk("%s: %s\n", __FILE__, __func__);

that executes regardless of whatever else happens in the function. If that prints then you can narrow down where to go from there.

If that doesn't work then make sure you are actually setting the function pointer in the device structure. Or maybe your error is in the test application. Are you sure that you've opened up the device with write permissions? That would be an easy mistake to make if you copied code from a program initially written just to test the read functionality.

Upvotes: 3

Related Questions