troubleshooting Question

Understanding the structure of the open file table

Avatar of Maarten Bruins
Maarten Bruins asked on
LinuxSystem ProgrammingCC++Linux OS Dev
15 Comments1 Solution322 ViewsLast Modified:
I'm trying to understand the structure of the open file table. During this search I'm reading things that look like (for me) they are in contrast with each other.

In a system there is a:

File descriptor table:
This table is located in user space and is associated with a certain process (per-process).

Open file table:
This table is located in kernel space and is associated with all processes (process-wide).

Entries in the file descriptor table point to the open file table. This all is clear. Now let's go to the structure of these tables. For example, see: https://elixir.bootlin.com/linux/v3.18/source/include/linux/fdtable.h#L24

struct fdtable {
        [...]
};

And:

/*
 * Open file table structure
 */
struct files_struct {
        [...]
};

Also this is clear. But now see for example: http://www.andrew.cmu.edu/user/gkesden/ucsd/classes/sp17/cse291-a/applications/ln/lecture5.html

Per Process File Information


struct files_struct { /* kept within task_struct (PCB) */
        [...]
};

Here they are talking about files_struct when it's about "per process file information". I don't understand this, because the open file table is process-wide. This is for example what they are saying:

The count variable tracks the number of files the process has open

But imagine ... two different processes point to the same entry in the open file table. I think "count" only says semething about how many file descriptors are pointing to that entry in the open file table. This has nothing to do with a specific process or something?

This is just an example, because many websites say the same. Another example: https://books.google.nl/books?id=sKoo-cFNPYsC&pg=PA159&lpg=PA159&dq=what+is+"max_fds"

It gets a struct files_structure table for the current process

If the "files_structure" refers to structure of the open file table, then they could not say "for the current process", because the open file table is not about particular processes. Actually they are saying this:

It gets a table for the current process

However, the only table that is per-process is the "file descriptor table" and not the "open file table". So it doesn't make sence to get the open file table for the current process, because for another process it's the same table.

Am I missing something? Or these websites incorrect? And how about "count"? And "struct file" is also part of the structure of the open file table, right? See:


struct files_struct { /* kept within task_struct (PCB) */
        [...]
        struct file * fd_array[NR_OPEN_DEFAULT];
};
ASKER CERTIFIED SOLUTION
mccarl
IT Business Systems Analyst / Software Developer
Join our community to see this answer!
Unlock 1 Answer and 15 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 15 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros