Hello and welcome.
In this video session we will discuss the file descriptor table.
The file table and the inode table.
We will see the relationship between all the three tables.
We have discussed previously the open system call and how the open system call works.
Now we will discuss the internals of the open system call.
The data structure used in Open system call.
When we have to open a file, we use open system call.
This open system call is being called from a process.
So every process has a file descriptor table.
Now the file descriptor table contains the FD, which is nothing but the file descriptor.
So here we can see zero, one, two or by default present, which represents a standard input, standard
output and standard error.
So now when we open a new file, we get the next least value of FD that is freely available from this
file descriptor table.
And we have one more column called as pointer to a open file table.
We will see what is open file table.
The open file table is a system wide, which means it is not limited to a process level, and this table
is visible to all the process.
The different columns of open file table are file offset.
File status flag and the pointer to the inode.
Now whenever a new file is being opened.
The file descriptor table points to the open file table.
so a entry in open file table is being created.
And the parameters that we pass in the open system call is stored here.
For example, we open the file in some required permissions such as read only, write only, read,
write, append, o_creat.
Different file status flags are stored in this column.
As we have discussed earlier in the read and write system call, there is a offset indicator.
Which indicates the current byte that is going to be read or written to the file.
So this is the file offset indicator.
The file offset is updated whenever we call the read or write or lseek system call.
For example, when we call a lseek() system call and we want to travel by 'N' number of bytes, the offset is
being updated in this field.
And lastly, the open file table contains a pointer to a inode.
So inode is also a table which contains all the information of the file.
We will see what inode table is in detail in next session.
Now we can say that.
File descriptor table points to the open file table.
And the open file table points to the final inode table, which is the representation of the file.
We will discuss on more information on the open file table.
And the file descriptor table when we start multiprocessing topics like.
Parent and the child process.
Now we will discuss inode table.
Whenever a file is created, there is an entry in the inode table.
A inode table is a collection of data structures.
In the figure, we can see the data structure of a single file.
The data structure contains different elements.
The elements are 'file type', which stores the type of the file, like whether the file is a regular file
or a Fifo, or a pipe or a directory, and then it contains information on the user, such as.
User ID.
Group ID.
User ID stores the user's identification and GID stores the group's identification to which the file belongs
to.
The size of the file will vary whenever there is a read or write operation performed on the file.
The 'time' field gives information of the time when the file was created, modified, and many information
related to the time.
Then comes the field which actually represents the content of the file.
In inode table, there are total four different addressing methods
Which points to the data block.
In Linux, there is a concept of block size.
There are different block sizes that can be used during configuration.
4KB data is the default block size in Linux system, but this can be changed or configured in other
words.
Now, considering 4 kilobytes as the default block size.
Every block contains four kilobytes of memory.
Whenever the system used the memory for the file, it allocates in terms of data blocks of four kilobytes.
So now let's see how the data is being allocated or how the blocks are being allocated to the file.
Let's say we have a file of only few bytes of data.
So this field what we see here contains the address of.
12 disk blocks.
Each address points to a data block.
So this is a data block.
Assuming we have four kilobytes of memory.
Four kilobytes of data can be stored in this one data block.
We have such 12 pointers.
Altogether here.
If we utilize all the 12 pointers, we can have 12 data blocks pointing.
So we have 12 X 4 kilobytes equal to 48kB of data.
Then we have single indirection.
Double indirection and we have triple indirection.
We will see with some more details on this, but before this we will have some more details on the inode
table.
As we discussed, the disk block size may be four kilobyte, eight kilobyte, and so on, but by default
it will be four kilobyte.
We can see the inode information of any file using the command.
Stat and followed by the file name.
Let's see one of the example of the inode table.
We can go to any of the folders and we can see the inode of a file.
We have a file called Lseek.c.
Now let's see the inode information of this file.
If you run the command stat space followed by the name of the file, we get some information of the
inode.
Now it contains different details.
Let's see some inode details.
Here we can see type of the file.
In this case, it's a regular file.
Then it has a inode number.
This is the inode number of the file.
We can see uid and the group id.
UID is the user id, whereas gid is the group id.
This also gives the information who is the user and what are the group the file belongs to.
This is the access information, like in which mode the file is being created and what are the different
access for user group and others.
Also it stores file size.
This is the current size of the file.
Then we have time in which it is modified or changed.
These are the different fields of inode.
Table of a file.
The previous video session we saw using the first 12 address, the inode can point up to 48kB of data
of a file.
If the file size crosses 48 KB of data, then the single indirection comes into picture.
In case of single indirection, this points to a memory block, which is 4 KB, and this is used
to store the pointers.
Now, since each pointer needs four bytes of memory space, that means 1024 such pointers can be stored
in this memory block, and each pointer points to the final data blocks, which is four KB.
This means using the single indirection.
The total number of data that can be stored is 4k into 1024.
that is nothing but
4MB of data.
Now.
Using the same concept.
The double indirection and triple indirection can be derived,
In case of double indirection, two levels of pointers are used, and in triple indirection three levels
of pointers are used.
Let's see this.
So as discussed, the in case of single indirection, the total memory that can be mapped is
four KB X 1 KB, that is 4 MB, and using the double indirection, the total memory that can be stored
is 4 KB x 1 KB x 1 KB that is 4 GB, and in triple indirection, the total memory that
can be stored is 4 KB x 1 KB x 1 KB x 1 KB that is 4 terabytes.
So in case of single indirection, this is a single level of pointers.
In case of double indirection, this is two level of pointers, and in case of triple indirection,
there are three level of pointers and the final pointer points to the data block.
This is the concept of single indirection, double indirection and triple indirection used in inode
table.
Thank you.