在read
函数原型,
ssize_t read(struct file *filp, char __user *buff,size_t count, loff_t *offp);
该参数在哪里呢offp
点?
我从下面的理解write
功能,参数ppos
指向可用数据的顶部deviceBuffer[]
这是在内核空间的全局缓存。 纠正我,如果我错了。
请问这个适用于read
功能?
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;
}