Welcome to Linux Forums!

With a comprehensive Linux Forum, information on various types of Linux software and many Linux Reviews articles, we have all the knowledge you need a click away, or accessible via our knowledgeable members.

Linux Forum ArticlesLinux ForumsLinux Forum DownloadsLinux Hosts
Home|Register|FAQ|Member List|Calendar|Unanswered Posts|Forum Rules|Today's Posts|Advanced Search|
SEARCH FOR IN
Go Back   Linux Forums > GNU Linux Zone > The Linux Kernel
Reload this Page got struck with device driver calculations ..in orelly book
Linux Forums
Linux Forums
Welcome To The Linux Forums!
Welcome to Linux Forums. We pride ourselves in being one of the largest Linux communities on the web, we encourage you to REGISTER on our forums and participate in the community. There are over 150,000 members ready to answer your questions. JOINING US today will allow you to make new posts, get support, send messages to other members and submit downloads to our downloads directory and many other great features!

The Linux Kernel Compiling, theory, programming or other discussion about the linux kernel

Reply
 
Thread Tools Display Modes
Old 06-02-2008   #1 (permalink)
brahma
Just Joined!
 
Join Date: May 2008
Posts: 4
got struck with device driver calculations ..in orelly book

Hi in the below code can anybody explain why this calculation is required heilighted in red colour,please dont hesitate to explain i will be happy and thankful to your answer .when i am getting cursor position as argument why this is required again ,i got struck at this position.

ssize_t scull_read(struct file *filp, char *buf, size_t count,
loff_t *f_pos)
{
Scull_Dev *dev = filp->private_data; /* the first listitem */
Scull_Dev *dptr;
int quantum = dev->quantum;
int qset = dev->qset;
int itemsize = quantum * qset; /* how many bytes in the listitem */
int item, s_pos, q_pos, rest;
ssize_t ret = 0;
if (down_interruptible(&dev->sem))
return -ERESTARTSYS;
if (*f_pos >= dev->size)
goto out;
if (*f_pos + count > dev->size)
count = dev->size - *f_pos;
/* find listitem, qset index, and offset in the quantum */
item = (long)*f_pos / itemsize;
rest = (long)*f_pos % itemsize;
s_pos = rest / quantum; q_pos = rest % quantum;


/* follow the list up to the right position (defined elsewhere) */
dptr = scull_follow(dev, item);

if (!dptr->data)
goto out; /* don't fill holes */
if (!dptr->data[s_pos])
goto out;

/* read only up to the end of this quantum */
if (count > quantum - q_pos)
count = quantum - q_pos;

if (copy_to_user(buf, dptr->data[s_pos]+q_pos, count)) {
ret = -EFAULT;
goto out;
}
*f_pos += count;
ret = count;

out:
up(&dev->sem);
return ret;
}
brahma is offline   Reply With Quote
Old 06-02-2008   #2 (permalink)
digvijay.gahlot
Just Joined!
 
Join Date: Mar 2008
Location: Hyderabad
Posts: 88
scull is a linked list of nodes. Each node has an list of small quantums. Number of quantum is defined in the program.

So item is just used to calculate the node number, Then quantum number is calculated for the node(item) , and then the position inside the quantum as q_pos.

The user applicaton will open the device and give the position, but you have actually reach the position inside the device to perform the activity(read/write) requested.
digvijay.gahlot is offline   Reply With Quote
Old 06-02-2008   #3 (permalink)
brahma
Just Joined!
 
Join Date: May 2008
Posts: 4
please confirm me wether i understood or not

Initially i will have pointer to first quantum and first quantum size and current array size right.and then i will get f_pos of unknown quantum,based on these things i need to find the node and current position of cursor of that particular node right for read or write is this correct,please correct me if i am wrong
brahma is offline   Reply With Quote
Old 06-03-2008   #4 (permalink)
digvijay.gahlot
Just Joined!
 
Join Date: Mar 2008
Location: Hyderabad
Posts: 88
The user can start writing anywhere within the file. ok so you can get any position of file to work with. So in your driver you have to file that position as you are implementing the device.
You are havinf pointer void **data. Which is a pointer to list of pointers (each pointer points to a quantum).
digvijay.gahlot is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




All times are GMT. The time now is 09:19 PM.




© 2000 - 2008 - All Rights Reserved - Property of  MAS Media

Content Relevant URLs by vBSEO 3.0.0