LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel
User Name
Password
Linux - Kernel This forum is for all discussion relating to the Linux kernel.

Notices

Reply
 
Search this Thread
Old 07-03-2013, 07:00 PM   #1
eduardosufan
LQ Newbie
 
Registered: Jul 2013
Posts: 4

Rep: Reputation: Disabled
Why not get the offset to the read-write functions of my driver?


hi all! I'm programming a device driver that performs reads and writes to memory locations that have been mapped (in driver open)

according to my reading function in the code of my device driver:
Code:
static ssize_t device_read(struct file *filp, char *buffer,size_t length, loff_t * offset)
and my file operations:
Code:
static struct file_operations fops = {
    .read    = device_read,
    .write   = device_write,
    .open    = device_open,
    .release = device_release
};
from my program in c, I use a function from my library with:
Code:
read (fd,buffer,199, offset_read);
Where fd is the file descriptor obtained in open, buffer and 199 is for the reading data.
And offset_read is:
Code:
loff_t offset = 16;
loff_t * offset_read = &offset;
The problem is that the offset never comes to my reading function in the driver

I print with:
Code:
 printk(KERN_ALERT "Offset: %lld\n", *offset);
and offset is always 0....

any ideas? thank you very much!
 
Old 07-04-2013, 04:05 PM   #2
eduardosufan
LQ Newbie
 
Registered: Jul 2013
Posts: 4

Original Poster
Rep: Reputation: Disabled
How is the correct way to call de function device_read/write from user space???
 
Old 07-04-2013, 08:03 PM   #3
sundialsvcs
Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 5,422

Rep: Reputation: 1158Reputation: 1158Reputation: 1158Reputation: 1158Reputation: 1158Reputation: 1158Reputation: 1158Reputation: 1158Reputation: 1158
The only way to invoke kernel-level code from user space is through a system call, such as the ones which 'stdio' and other libraries provide for you.
 
Old 07-05-2013, 08:38 AM   #4
eduardosufan
LQ Newbie
 
Registered: Jul 2013
Posts: 4

Original Poster
Rep: Reputation: Disabled
read is the system call, is mapped into the structure file_operations
when i call "read" in user space, according to file_operations, runs device_read into the kernel space
 
Old 07-11-2013, 04:31 PM   #5
eduardosufan
LQ Newbie
 
Registered: Jul 2013
Posts: 4

Original Poster
Rep: Reputation: Disabled
[SOLVED]

i have to call pread (file_descriptor, buffer, size, offset (just an int)) with 4 paramethers and the file operations:

struct file_operations{
.read=device_read
}

call device_read in the kernel and with *offset i have the value in the code function.

static ssize_t device_read(struct file *filp, char *buffer,size_t length, loff_t * offset)
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
[SOLVED] Device driver read/write functions not running for address 0x80000000 shade963 Linux - Kernel 0 09-10-2012 11:27 AM
read/write in block device driver zali Programming 4 05-05-2012 04:14 AM
USB Driver Read and Write for PC biswajit.2k3 Linux - Kernel 8 04-04-2012 09:29 AM
How to write a keyboard driver read and interrupt functions? sunr2007 Programming 1 01-13-2009 09:38 AM
how i can list directory by using read() & write() kernll functions ashamry Programming 2 05-10-2004 02:44 PM


All times are GMT -5. The time now is 05:45 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration