哪里有在Linux内核代码点变成“读”功能的最后一个参数?(Where does the last

2019-11-03 04:35发布

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;
}
文章来源: Where does the last parameter of the 'read' function in Linux kernel code point to?