0

I'm getting looped printing of the written data on the character device when using the cat command to read from the device file. I'm new to this so I'm probably doing it wrong, would appreciate some help trying to figure this out`

static ssize_t device_read( struct file* file,
                        char __user* buffer,
                        size_t       length,
                        loff_t*      offset )
{
  // read doesnt really do anything (for now)
  int i;
  printk( "Invocing device_read(%p,%d) - "
      "operation not supported yet\n"
      "(last written - %s)\n",
      file, length, the_message );
  for(i = 0; i < length && i < BUF_LEN; ++i )
  {
    put_user(the_message[i],&buffer[i]);
  }
  return i;
  //invalid argument error
  return -EINVAL;
}
Santino
  • 1
  • 4
  • In short: when determine which character to put into the user buffer, you need to take into account argument 'offset'. And when 'offset' is more that size of your buffer, 0 should be returned. – Tsyvarev May 17 '18 at 22:14
  • Got it! thanks a lot;) – Santino May 18 '18 at 11:11

0 Answers0