Linux – Does the inode data structure contains the actual address of the file on disk

filesystemslinux

I am currently learning about the Linux file system. I have learned the following so far:

  • A directory is just a file that contains the following information:
    the file names, and their inode numbers.
  • There is an inode table that contains a data structure for each inode
    number. This data structure contains information such as Owner ID,
    Group ID, Size of file, etc.

Now does the inode data structure also contains the actual address of the file on disk, or does it only contain the address of some other data structure that knows the actual address of the file on disk?

Best Answer

This is dependent of the filesystem type. However, in most filesystems, the inode (or dinode) will contain the addresses of the first couple of data blocks (called "direct block") and then, for larger files, the addresses of the "indirect blocks" which themselves store pointers to additional data blocks.

See Inode_pointer_structure wikipedia's page for more details.

For learning purposes, I would recommend looking at UFS filesystem which has a relatively simple structure. See UFS diode struct, specifically di_db and di_ib for pointers to direct and indirect blocks.

Related Question