LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
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 04-15-2011, 12:26 AM   #1
linuxaddected
LQ Newbie
 
Registered: Apr 2011
Posts: 2

Rep: Reputation: 0
Unhappy scull_read and scull_write functions are not called


hi..
i designed the scull driver according to the LDD3 book. But when i execute it, it doesn't make use of the scull_read(copying data to user space) and scull_write(copying data to kernel space) functions. So how can i check these two functions or make them work? I am very confused.
Please help.
Thanks
 
Old 04-18-2011, 12:41 AM   #2
TheIndependentAquarius
Senior Member
 
Registered: Dec 2008
Posts: 4,680
Blog Entries: 29

Rep: Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918
Quote:
Originally Posted by linuxaddected View Post
it doesn't make use of the scull_read(copying data to user space)
The Linux kernel API has a function titled "copy_to_user" to copy data from kernel space to user space. See how this function fits in your driver code. http://www.gnugeneration.com/books/l...api/re262.html
 
Old 04-18-2011, 07:29 AM   #3
linuxaddected
LQ Newbie
 
Registered: Apr 2011
Posts: 2

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by Anisha Kaul View Post
The Linux kernel API has a function titled "copy_to_user" to copy data from kernel space to user space. See how this function fits in your driver code. http://www.gnugeneration.com/books/l...api/re262.html
Thanks a lot for reply.. I have used this function and the code is below:

ssize_t scull_read(struct file *filp, char __user *buf, size_t count,loff_t *f_pos){

printk("SCULL_READ is called............");
// dev was stored in filp during the open call.
struct scull_dev *dev = filp->private_data;
struct scull_qset *dptr; // Pointer to the beginning of the data
int quantum = dev->quantum; // Size of a quantum
int qset = dev->qset; // Number of quantums
int itemsize = quantum * qset; // number of bytes in the listitem
int item, s_pos, q_pos, rest;
ssize_t retval = 0; // Will contain the result

// Request unique access
if(down_interruptible(&dev->sem)){
return -ERESTARTSYS;
}


// If the offset is larger than the data stored
if(*f_pos >= dev->size){
goto out;
}
// If more data is requested than available
if(*f_pos+count > dev->size){
count = dev->size - *f_pos;
}

// item = which listnode
item = (long) *f_pos / itemsize;
// rest = the offset in the listnode
rest = (long) *f_pos % itemsize;

// s_pos = which quantum
s_pos = rest / quantum;
// q_pos = the offset in the quantum
q_pos = rest % quantum;


dptr = scull_follow(dev,item);

if(dptr == NULL || !dptr->data || !dptr->data[s_pos]){
goto out;
}

/* Read only up to the end of this qunatum */
if(count > quantum - q_pos){
count = quantum - q_pos;
}

// Copy this quantum (from the offset, to the end of this quantum)
// to userspace
if(copy_to_user(buf, dptr->data[s_pos] + q_pos, count)){
retval = -EFAULT;
goto out;
}

// Update the file offset
*f_pos += count;
retval = count;
out:
up(&dev->sem);
return retval;
}



This function is never called during the program run(scull_write also which uses copy_from_user). So can you please suggest how can i use these functions at the program run?
Thanks.
Akshay
 
Old 04-18-2011, 11:47 AM   #4
TheIndependentAquarius
Senior Member
 
Registered: Dec 2008
Posts: 4,680
Blog Entries: 29

Rep: Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918
Have you included properly scull_read in the file_operations struct?
 
  


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
USB kernel module, how functions get called by kernel falmdavis Linux - Kernel 1 01-18-2011 02:58 PM
OSE system call functions to Linux Sytem Call functions required roshantraj30 Linux - General 0 06-08-2009 03:06 AM
Functions in .so file not called. priyeshwadhwa Linux - Newbie 2 02-22-2008 05:05 AM
LXer: OpenOffice.org Calc functions, part 1: Understanding functions LXer Syndicated Linux News 0 03-31-2007 01:01 PM
pointers to functions/member functions champ Programming 2 03-28-2003 07:22 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel

All times are GMT -5. The time now is 01:37 PM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration