Reputation: 988
I have created a misc driver and has made a sample read function like this
static ssize_t test_read(struct file *file, char __user *buffer,
size_t count, loff_t *ppos)
{
pr_info("Count arg : %d\n",count);
return ret;
}
I now try to read the device using a userspace code as shown below
uint64_t read_buff;
fread(&read_buff, sizeof(read_buff), 1, fp)
The dmesg log I get is
[ 1593.273163] Count arg : 4096
I was expecting it to be of the size of uint64_t. Could anybody point me why I get an unexpected value?
Upvotes: 0
Views: 139
Reputation: 3778
Seems that fread()
tries to buffer some data for userland. I found source code of one fread()
that buffers data (in __srefill()
). So, it's OK for fread()
to do so.
If you want to avoid such unexpected results, lower one level down and work with read()
function in userland.
Upvotes: 3