Link to home
Start Free TrialLog in
Avatar of Maarten Bruins
Maarten Bruins

asked on

What is the purpose of the inode table?

For this question, let's forget about v-nodes/vnodes. So let's say the contents of a file are located in data block(s) on a real physical disc.

See for example: https://www.usna.edu/Users/cs/aviv/classes/ic221/s16/lec/21/lec.html#orgheadline4

2.3 V-node and I-node Tables

There they explain the inode-table. Actually the inode-table just leads you to the contents of a file. But I think they forgot to mention something important. Let's say I'm requesting a regular file in a filesystem. In such a case, for what I need the inode-table? I just see it like this:

dentry (possibly more than 1) -> inode -> data block(s)

The inode contains the pointers to the data block(s). So why we need an inode-table? Or is this inode from above actually just an entry in the inode-table? If that's true, then it's weird because the inode-table is stored in memory, so when restarting the computer all the inodes are gone. Furthermore, probably the inode-table only contains information about open files.

Or are the inodes of open files just cached in memory (in the inode-table) to speed things up? Then the purpose of the inode-table is i.a. caching?

Anyway I'm surprised that they don't say anything about this. I think understanding the inode-table starts with the question why there is an inode-table.
Avatar of David Favor
David Favor
Flag of United States of America image

https://linoxide.com/linux-command/linux-inode/ - clear description with examples, including effects of symlinks + hardlinks.
Avatar of Maarten Bruins
Maarten Bruins

ASKER

And where on that page you see the answer to my question? I already understand symlinks, hardlinks et cetera. That's not what the question is about.
From my reading, the inode contains more information than just a link to the data blocks. The inode table is where all inodes are stored and its size and location will depend on the file system. Does this article help explain further for you? https://www.slashroot.in/inode-and-its-structure-linux

Edit: Apparently, some file systems omit the inode table, for example ReiserFS but need to provide the same data via an alternative method.

Edit 2: In David's defence, there is a section in the link he provides (https://linoxide.com/linux-command/linux-inode/) that states the following:
An inode is an entry in inode table, containing information ( the metadata ) about a regular file and directory. An inode is a data structure on a traditional Unix-style file system such as ext3 or ext4. Linux extended filesystems such as ext2 or ext3 maintain an array of these inodes: the inode table. This table contains list of all files in that filesystem. The individual inodes in inode table have a unique number (unique to that filesystem), the inode number. Diving deep into the inode, an inode stores:

   
  •    File type: regular file, directory, pipe etc.
  •    Permissions to that file: read, write, execute
  •    Link count: The number of hard link relative to an inode
  •    User ID: owner of file
  •    Group ID: group owner
  •    Size of file: or major/minor number in case of some special files
  •    Time stamp: access time, modification time and (inode) change time
  •    Attributes: immutable' for example
  •    Access control list: permissions for special users/groups
  •    Link to location of file
  •    Other metadata about the file

It does directly answer your question as to why inodes are required - they don't just store information about file blocks.

Edit 3: Its clear from the above, and the links, that the inode table is not just stored in an OS cache. The OS may choose to cache it, but it is also stored on the file system, where the filesystem uses one.
My link is about the INCORE-inode table. This is located in kernel space. A user can not even access this data.

P.S. I have to read more about it, because again different websites are saying different things. So first I have to find out if there are different types of inode-tables? And then we know if we're talking about the same table.

P.S. Websites are talking about an in-memory inode table. This means that if you restart the computer, then the inodes are gone. So the data must also be stored somewhere else.

P.S. So is there an "inode table" AND an "incore inode table"? What's the difference?

P.S. Just see:
https://www.google.nl/search?q=open+file+table+inode+table&source=lnms&tbm=isch&sa=X&ved=0ahUKEwiUjL_20-rdAhUSL1AKHdQcAjEQ_AUICigB&biw=1920&bih=979#imgrc=0fewyj9A-gClfM:
https://www.google.nl/search?q=open+file+table+inode+table&source=lnms&tbm=isch&sa=X&ved=0ahUKEwiUjL_20-rdAhUSL1AKHdQcAjEQ_AUICigB&biw=1920&bih=979#imgrc=3XZ4-jpFA5KdWM:
https://www.google.nl/search?q=open+file+table+inode+table&source=lnms&tbm=isch&sa=X&ved=0ahUKEwiUjL_20-rdAhUSL1AKHdQcAjEQ_AUICigB&biw=1920&bih=979#imgrc=vB-5_iokMPUeMM:
Three different pictures, three different "space". Which one is correct? Anyway the "file descriptor table" must be in user space.
From reading your link further, it appears to me that the vnode and inode references are about how the kernel stores information for open files. The vnode information is an abstraction that the kernel uses and is consistent irrespective of the file system type, where as the inode information appears to relate to actual data stored in the file system and access information.

An OS needs to track information about files that are in use so it looks as though open file tables are managed (vnode and inode tables) by the kernel and this is made up of vnodes and inodes. it appears to me that a vnode is an abstraction of any device as a file whereas the inode records how (as in the method by which) the file should be accessed.

Unfortunately, it was not clear to me from your question what exactly you needed to know, but my interpretation was that you wanted to know why inodes existed because you were referring to directory entries and by my understanding these only exist in the file system. The kernel may well maintain a reference to a directory as an inode and vnode in the open file table, certainly if the directory is being read or modified, but that's not clear from my limited reading.

Maybe someone with better kernel understanding will find this question and clarify any of the points we have discussed.
Just read this:

https://books.google.nl/books?id=tdsZHyH9bQEC&pg=PA120&lpg=PA120&dq=difference+in+memory+inode+table+and+inode+table&source=bl&ots=rvYk83k_p6&sig=nEoL8qZKQ3wGHtiPwiLH-55py6Y&hl=nl&sa=X&ved=2ahUKEwjS9f3s2erdAhWEKVAKHY2FCVI4ChDoATAFegQIBhAB#v=onepage&q=difference%20in%20memory%20inode%20table%20and%20inode%20table&f=false

The in-memory inode table contains an entry for each active file in the system.

So what my question is about is apparently about a different inode table then you guys are talking about.

P.S. I didn't read your last post yet, but I will do this now.
ASKER CERTIFIED SOLUTION
Avatar of Martyn Spencer
Martyn Spencer
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I think I have answered the main points. Naturally there will be reading that you can do to flesh out your understanding, but I think I have covered the main points. I'll stop writing now to give you a chance to catch up with what I have written. If I have not made myself clear, just ask.
Thanks a lot! First I'll read some more about it, but it's already helpful. Then it's actually what I already thought as a possibility:

Or are the inodes of open files just cached in memory (in the inode-table) to speed things up? Then the purpose of the inode-table is i.a. caching?

And about:

Unfortunately, it was not clear to me from your question what exactly you needed to know, but my interpretation was that you wanted to know why inodes existed because you were referring to directory entries and by my understanding these only exist in the file system. The kernel may well maintain a reference to a directory as an inode and vnode in the open file table, certainly if the directory is being read or modified, but that's not clear from my limited reading.

Maybe see: https://www.kernel.org/doc/Documentation/filesystems/vfs.txt

The dentry cache is meant to be a view into your entire filespace. As
most computers cannot fit all dentries in the RAM at the same time,
some bits of the cache are missing. In order to resolve your pathname
into a dentry, the VFS may have to resort to creating dentries along
the way, and then loading the inode. This is done by looking up the
inode.

But my question was indeed more about:

fd table -> open file table -> inode/vnode table

I mentioned:

dentry -> inode -> data block(s)

I did this, because for this you don't need an in-core inode-table, so that's why I was wondering why such a table exists.

But let's say a system opens /dir-1/dir-2/dir-3/file.txt. If this file wouldn't be in the in-core inode-table, then probably every time the system has to check:

dentry /
dentry dir-1
dentry dir-2
dentry file.txt

Then in the end, the system can access the file's inode (from the NON-in-core inode table). Maybe the in-core inode table speeds up this process by storing the inode information in the in-core inode table too. But this is just guessing. Coming days I'll try to find/read more about it, Then maybe I can determine whether or not it's the correct answer.

Anyway it does make sence what you (Martyn) are saying, so probably it is the right answer.