Where does the last parameter of the 'read' function in Linux kernel code point to?

£可爱£侵袭症+ 提交于 2019-12-25 12:24:21

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!