问题
In the read
function prototype,
ssize_t read(struct file *filp, char __user *buff,size_t count, loff_t *offp);
where does the parameter offp
point to?
What I understand from the below write
function is that the parameter ppos
points to the top of the data available in deviceBuffer[]
, which is a global buffer in kernel space. Correct me if I am wrong.
How does this apply to read
function ?
static ssize_t mcspi_write(struct file *filp, const char *buff, size_t length, loff_t *ppos)
{
int maxbytes; /* maximum bytes that can be written */
int bytes_to_write;
int bytes_written = 0;
//int i;
maxbytes = BUFFER_SIZE - *ppos;
if(maxbytes < length)
bytes_to_write = maxbytes;
else
bytes_to_write = length;
bytes_written = bytes_to_write - copy_from_user(deviceBuffer + *ppos, buff, bytes_to_write);
/*
for(i = 0; i < 1024; i++)
{
printk(KERN_INFO "deviceBuffer[%d] = %x\n", i, deviceBuffer[i]);
}
*/
printk(KERN_INFO "%s: %d bytes copied from user space\n", DEVICE_NAME, bytes_written);
*ppos += bytes_written;
return bytes_written;
}
来源:https://stackoverflow.com/questions/23289181/where-does-the-last-parameter-of-the-read-function-in-linux-kernel-code-point