LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Hardware > Linux - Embedded & Single-board computer
User Name
Password
Linux - Embedded & Single-board computer This forum is for the discussion of Linux on both embedded devices and single-board computers (such as the Raspberry Pi, BeagleBoard and PandaBoard). Discussions involving Arduino, plug computers and other micro-controller like devices are also welcome.

Notices


Reply
  Search this Thread
Old 06-07-2010, 10:31 PM   #1
chxooi
LQ Newbie
 
Registered: May 2010
Posts: 24

Rep: Reputation: 0
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;
}
 
Old 06-09-2010, 03:15 PM   #2
nini09
Senior Member
 
Registered: Apr 2009
Posts: 1,850

Rep: Reputation: 161Reputation: 161
In read/write function, 'offset' parameter is your current position.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
how to make device driver built-in in initial ramdisk suo Linux - Kernel 2 08-12-2008 04:25 PM
Change network device driver code to make it default stevebeiko Programming 6 07-31-2008 04:16 AM
How to make use of a USB device driver? rockballad Programming 6 01-22-2008 06:59 PM
how can i make device driver diskette? mrship Linux - Hardware 0 06-21-2004 01:02 AM
Trouble running make to compile example scull device driver taillefer Programming 3 03-23-2004 12:53 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Hardware > Linux - Embedded & Single-board computer

All times are GMT -5. The time now is 06:41 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration