Looking at file descriptors and the next part. So a bit of pre-requisites first
Every process has its own task struct. And in that task struct is basically a field which is a pointer to struct called file_struct
File descriptor table lives as a filed inside this file_struct as fdtable which is a growing array of struct_file*
Dentry (directory entry) is an in-memory record that maps a name inside a directory to an inode.
So in this blog we are going to be diving deeper into the structures of these tables.

So the columns in the file descriptor table are two fold one is the list of file descriptors which as I explained in the previous blog are integers from 0 to per- RLIMIT_NOFILE per process.
Open File Description Table
Each entry in the file descriptor table maps to a struct file which is basically an open file description. This points to an entry in the open file descriptor table which is like a table consisting of all of the file entries currently. Internally it is just a collection of all of the open file descriptors that each individual file descriptor of a process points to.struct file holds the offset (f_pos), status flags (f_flags, e.g., O_APPEND, O_NONBLOCK, O_SYNC, O_DIRECT) and access mode (f_mode). I will go into what these flags are in part 3 but for now all you need to understand is that each flag has its set of status falgs that its opened with.
Inodes
Each entry in this open file descriptor table points to the underlying inode inside the file system. Each FD points to a struct file. That struct file has an f_path (mount + dentry). We will deep dive into dentries in another blog, you can look it up or ill put it in the pre-requisites up top. The dentry references the inode. The inode does not store a path; paths are names in dentries The inode holds file metadata: permissions, owner, size, timestamps, device/superblock links, etc.
In the next blog we will dive deep into how dup, dup(2) works on duplicating these file descriptor and how offsets are dealt with as well as wrap up the knowledge we need for these file descriptors.
This post was first published on Substack.
View the original