LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
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 05-04-2011, 05:18 PM   #1
eantoranz
Senior Member
 
Registered: Apr 2003
Location: Colombia
Distribution: Kubuntu, Debian, Knoppix
Posts: 1,982
Blog Entries: 1

Rep: Reputation: 83
Why does the value of ret change out of nowhere in do_sync_read?


Hi!

I'm having some fun creating a linux block device driver. This device driver will have to read from files and so I've been trying to solve all the problems involved. While doing my research I've hit a very weird behavior in a function defined in fs/read_write.c. It's do_sync_read. I have added some debug messages to it on my UML kernel (the one I'm developing my device driver on) to check all vaules involved while running the function cause I was getting a -EFAULT when I ran vfs_read. Following the functions involved I arrived at do_sync_read.

If you take a look at the function, you will see that there is one _seemingly_ endless for, then a check, then change of the ppos variable and finally a return of ret.

I have found that there is only one cycle of the for run, because there is a break that is hit if everything is OK inside the for.

First, ret is assigned like this:

Code:
ret = filp->f_op->aio_read(&kiocb, &iov, 1, kiocb.ki_pos);
After this point, the value of the variable ret is set to 0 meaning the operation ran normally (or so I like to think).

Then there is a check that is evaluated to true which means that ret != -EIOCBRETRY, great... but before I call break I print again the value of ret and now the value has been changed to -14 (-EFAULT). Why is that happening? Cause I dont see anything that could be going on that could be changing the value of ret from 0 to -14 between those two points.

Code:
for (;;) {
	ret = filp->f_op->aio_read(&kiocb, &iov, 1, kiocb.ki_pos);
	if (filp == debugFile) printk (KERN_NOTICE "Con la posicion %d resultado fue %d\n", kiocb.ki_pos, ret);
	if (ret != -EIOCBRETRY) {
		if (filp == debugFile) printk (KERN_NOTICE "Saliendo del ciclo con ret valiendo %d\n", ret);
		break;
	}
	wait_on_retry_sync_kiocb(&kiocb);
}
Output:
Code:
Con la posicion 2000 resultado fue 0
Saliendo del ciclo con ret valiendo -14
 
  


Reply

Tags
do_sync_read, kernel, programming, uml


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
lame mp3 ret hat fedora 5 cyberfruits Linux - Server 9 08-25-2008 10:09 AM
emacs ctrl-m is RET. how to change ? Horos23 Linux - Software 1 11-13-2007 12:53 AM
Assembly - little problem with ret cdog Programming 6 05-11-2007 04:35 PM
assembly language: ret>>=10 ashlesha Programming 2 09-13-2006 05:11 AM


All times are GMT -5. The time now is 09:38 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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration