LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 09-02-2014, 12:08 PM   #1
kajv
LQ Newbie
 
Registered: Sep 2014
Posts: 4

Rep: Reputation: Disabled
Question Understanding the source code - 'fs' directory


As a newbie to Linux, I want to understand the source code line by line as I will be working on a small project.
I am going through fs/open.c for file systems and there are many variables and functions that I do not understand.

1. How does build_open_flags() work and what does it return?

2. There are various error checks in each function, and they are not commented. How do I know what error is being checked?

For eg. within open_check_o_direct():

if (f->f_flags & O_DIRECT) {
if (!f->f_mapping->a_ops ||
((!f->f_mapping->a_ops->direct_IO) &&
(!f->f_mapping->a_ops->get_xip_mem))) {
return -EINVAL;
}
}

3. Is there a highly commented version of the source code that I can download?

Thank you!
 
Old 09-02-2014, 03:55 PM   #2
John VV
LQ Muse
 
Registered: Aug 2005
Location: A2 area Mi.
Posts: 17,623

Rep: Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651
please do not post your homework
we will not do it for you


we can point you to reference sources
but what dose your Textbook have to say on this ?
 
Old 09-07-2014, 09:59 AM   #3
kajv
LQ Newbie
 
Registered: Sep 2014
Posts: 4

Original Poster
Rep: Reputation: Disabled
This is not homework. Nor do I have any textbook on this.

I'm trying to understand the Linux source code and am looking for guidance. If you have answers to my questions, please post.
 
Old 09-07-2014, 11:25 AM   #4
HarrisCreekCentral
Member
 
Registered: Mar 2014
Location: Kelowna, BC Canada.
Distribution: Linux Mint16. / 17 mate.
Posts: 43

Rep: Reputation: Disabled
Quote:
Originally Posted by John VV View Post
please do not post your homework
we will not do it for you


we can point you to reference sources
but what dose your Textbook have to say on this ?
I have no interest in this thread. I do not understand "Codes" period. However, I have found this forum to be very interesting, but I am very dissapointed with a "Catty Sarcastic" reply like this. We have been asked to be kind and considerate of "especially" those who aree new to the system. I feel John VV owes kajv an appology for every making such a comment.
 
Old 09-07-2014, 03:55 PM   #5
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,912

Rep: Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513
I would suggest looking at a Linux kernel text book - such as listed by:

https://www.google.com/search?q=Linu...-US:unofficial

The problem is that it requires a very detailed answer that depends on what kernel version you are running, and even what filesystem you are using for the "open".

Your specific code group is dealing with the VFS layer (the virtual filesystem) that passes the actual handling to the filesystem specific functions in the mapping structure.

Your specific question is referring to a C idiom, the use of any value as a logical test where a 0 (null pointer or 0) is counted as false - the 'if (!f->f_mapping->a_ops' is just checking to see if the a_ops function is not defined. If it is not defined then there is no need to look for direct_IO or get_xip_mem, if it is defined then '((!f->f_mapping->a_ops->direct_IO)' is checked to see if there is a direct_IO function and it checks that the '(!f->f_mapping->a_ops->get_xip_mem))' function exists. One of the two alternatives must exist, or there is an error.

If any of these tests fail (the "&& (!f->" then an error return code is given.

This would be easier to see if your post had used the code blocks to preserve indentation. I believe the original code was:
Code:
if (f->f_flags & O_DIRECT) {
        if (!f->f_mapping->a_ops ||
               ((!f->f_mapping->a_ops->direct_IO) &&
               (!f->f_mapping->a_ops->get_xip_mem))) {
                       return -EINVAL;
         }
}
But I could be off a bit.

Last edited by jpollard; 09-07-2014 at 03:59 PM.
 
Old 09-23-2014, 04:51 AM   #6
kajv
LQ Newbie
 
Registered: Sep 2014
Posts: 4

Original Poster
Rep: Reputation: Disabled
Smile Resources?

Thank you, HarrisCreekCentral.

Thanks for your reply jpollard. Yes, that was how it was indented - I should have preserved it while copying.
I have a couple of books on Linux kernel development but I find them very vast. I am taking quite a lot of time to go through them.

Is there any place where the various C idioms used are explained? What I mean is, the comments in the code do not really explain the working. My challenge is to be able to read and understand the code. Are there any sources for this, such as a good documentation or a highly commented version of the code?
 
Old 09-23-2014, 05:18 AM   #7
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,804

Rep: Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306
Usually there are no several different versions of the same code (especially there are no both a highly commented and a non-commented version).
There are no general "various C idioms", but there are developers with their own idioms. Usually the kernel contains a lot of tricky parts, you will hardly find a book with detailed explanations on those techniques.
But if you want to understand a specific part of the code you can come here, to LQ and discuss it.
In this case you need to understand not only the code copied but the structs used. Usually you need to find their headers to get some additional information about the members. Sometimes you can find general information even on wiki (for example about inode structures)
 
Old 10-08-2014, 02:32 PM   #8
kajv
LQ Newbie
 
Registered: Sep 2014
Posts: 4

Original Poster
Rep: Reputation: Disabled
Thanks for your reply.
Doesn't this make it very difficult to understand the Linux source code? How do people learn it, then? I mean what are the main steps one must follow to learn such things?
As of now, I just browse the code on Linux Free Electrons, and try to understand it myself. I am sure this is not very efficient.
 
Old 10-08-2014, 08:06 PM   #9
frankbell
LQ Guru
 
Registered: Jan 2006
Location: Virginia, USA
Distribution: Slackware, Ubuntu MATE, Mageia, and whatever VMs I happen to be playing with
Posts: 19,311
Blog Entries: 28

Rep: Reputation: 6137Reputation: 6137Reputation: 6137Reputation: 6137Reputation: 6137Reputation: 6137Reputation: 6137Reputation: 6137Reputation: 6137Reputation: 6137Reputation: 6137
This page links to a wealth of programming resources.

http://www.linuxtopia.org/online_boo...ing_index.html
 
Old 10-08-2014, 08:15 PM   #10
John VV
LQ Muse
 
Registered: Aug 2005
Location: A2 area Mi.
Posts: 17,623

Rep: Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651
to learn ...
start with learning Python then ruby and c then c++
and while you are at it toss in some FORTRAN and COBAL

you do NOT learn linux source code

you learn PROGRAMING
and
programing for Linux
programing for Windows
programing for Apple
 
  


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
source code for cd (change directory) Spyes Programming 14 02-10-2010 10:45 AM
Understanding source code Ashkan_s Linux - Software 3 07-20-2008 08:39 AM
understanding linux source code pankaj99 Programming 10 03-19-2006 04:54 PM
understanding linux source code iqbal Linux - General 2 09-16-2004 11:22 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 02:28 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
Open Source Consulting | Domain Registration