troubleshooting Question

The structure of the file descriptor "table"?

Avatar of Maarten Bruins
Maarten Bruins asked on
LinuxCLinux OS DevUnix OSLinux Distributions
16 Comments1 Solution455 ViewsLast Modified:
Actually the file descriptor table is not a real table. It's just an array of pointers to the "open file table" (struct file). But let's say we will see it as a table. What are the columns? For example:

FD   | Pointer to "open file table"
...  | ...

In short, that's the question. I see a lot of different figures on the internet, but they are all different. For example, see:
There they have a column "fd flags" (read/write), but I would think that this column is part of the "open file table" and not part of the "file descriptor table". See for example:

       A call to open() creates a new open file description, an entry in the
       system-wide table of open files.  The open file description records
       the file offset and the file status flags (see below).  A file
       descriptor is a reference to an open file description; this reference
       is unaffected if pathname is subsequently removed or modified to
       refer to a different file.  For further details on open file
       descriptions, see NOTES.

       The argument flags must include one of the following access modes:
       O_RDONLY, O_WRONLY, or O_RDWR.  These request opening the file read-
       only, write-only, or read/write, respectively.

So this creates a file descriptor and an entry in the open file table. A file descriptor is only an integer, so then I would conclude that O_RDONLY/O_WRONLY/O_RDWR is part of the open file table and not of the file descriptor table. They also say this:

A file descriptor is a reference to an open file description; this reference is unaffected if pathname is subsequently removed or modified to refer to a different file.

If write/read would be part of the file descriptor table, then the above can not be true in my opinion.

Another example:
Here they also have a column "flags". Do they also mean read/write et cetera with "flags"? Or what exactly do they mean by flags in this case?
Here they don't have the column flags at all.

I think for the answer we have to look at

 * Open file table structure
struct files_struct {
   * read mostly part
      atomic_t count;
      struct fdtable __rcu *fdt;
      struct fdtable fdtab;
   * written part on a separate cache line in SMP
      spinlock_t file_lock ____cacheline_aligned_in_smp;
      int next_fd;
      unsigned long close_on_exec_init[1];
      unsigned long open_fds_init[1];
      struct file __rcu * fd_array[NR_OPEN_DEFAULT];

Although they write "open file table structure", probably this is what other people call the "file descriptor table". These structures are still a bit abracadabra for me, but I don't see something like read/write flags.

So how I have to see it? Which columns does the file descriptor "table" have? (if we would see it as a table)
IT Business Systems Analyst / Software Developer

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Top Expert 2015

The Distinguished Expert awards are presented to the top veteran and rookie experts to earn the most points in the top 50 topics.

Join our community to see this answer!
Unlock 1 Answer and 16 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 16 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