LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Understanding the source code - 'fs' directory (https://www.linuxquestions.org/questions/linux-newbie-8/understanding-the-source-code-fs-directory-4175517173/)

kajv 09-02-2014 12:08 PM

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!

John VV 09-02-2014 03:55 PM

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 ?

kajv 09-07-2014 09:59 AM

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.

HarrisCreekCentral 09-07-2014 11:25 AM

Quote:

Originally Posted by John VV (Post 5231393)
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.

jpollard 09-07-2014 03:55 PM

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.

kajv 09-23-2014 04:51 AM

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?

pan64 09-23-2014 05:18 AM

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)

kajv 10-08-2014 02:32 PM

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.

frankbell 10-08-2014 08:06 PM

This page links to a wealth of programming resources.

http://www.linuxtopia.org/online_boo...ing_index.html

John VV 10-08-2014 08:15 PM

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


All times are GMT -5. The time now is 05:40 AM.