LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Embedded & Single-board computer (https://www.linuxquestions.org/questions/linux-embedded-and-single-board-computer-78/)
-   -   How can I make device driver for llseek. (https://www.linuxquestions.org/questions/linux-embedded-and-single-board-computer-78/how-can-i-make-device-driver-for-llseek-812781/)

chxooi 06-07-2010 10:31 PM

How can I make device driver for llseek.
 
I've made read/write function for device driver emulator like nvram or flash ram using memory buffer.(call it nvram emul driver)
Total buffer size is 1024


Total read/ total write is ok.
But, problem is llseek.

I don't know how I can use the specific positon for read/write function using llseek.
I think that offset is very important value for llseek.
But, I don't know or I don't understand how I can use it.

How can I use specific positon for llseek based on my read/write driver.

Do I need to fix ? or modify in detail?

Code:

#define  BUFF_SIZE      1024

ssize_t ram_emul_read(uint32_t partition_id, char * buf, size_t count, loff_t  offset)
{
    copy_to_user(buf,memory_buffer,count);
    return count;
}

ssize_t ram_emul_write( uint32_t partition_id, const char * buf, size_t count, loff_t offset)
{

    if (BUFF_SIZE < count)
        sz_data  = BUFF_SIZE;
    sz_data  = count;

    memcpy(memory_buffer,buf,sz_data);
    return count;
}

===============================

lseek function
-->

    switch (whence)
    {
        case 0: /* SEEK_SET */
            newpos = off;
            break;
        case 1: /* SEEK_CUR */
            newpos = filep->f_pos + off;
            break;
        case 2: /* SEEK_END */
            newpos = ram_emul_get_partition_size(device->id) + off;
            break;
        default:    /* shouldn't happen */
            // Unlock and return error
            up(&nvram_mutex);
            TRACE_END_ERR("Failed, invalid WHENCE parameter");
            return -EINVAL;
    }


int ram_emul_get_partition_size(uint32_t partition_id)
{

    return BUFF_SIZE;
}


nini09 06-09-2010 03:15 PM

In read/write function, 'offset' parameter is your current position.


All times are GMT -5. The time now is 11:29 PM.