6

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?

user228197
  • 61
  • 2

1 Answers1

5

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.

steve
  • 21,892
sfk
  • 151
  • 1
    Also see "How does Linux know the Location of File Data on Disk" https://unix.stackexchange.com/questions/74319/how-does-linux-know-the-location-of-file-data-on-disk – steve Apr 22 '17 at 21:56
  • Modern file systems, like Ext4 or Btrfs use extents, which are ranges of continuous blocks on the disk. Extents are referred to using a starting block, length pair. Of course, when the disk gets fragmented, you may have to use several extents for a larger file. This happens when a single long enough sequence of consecutive disk blocks is not available. – Johan Myréen Apr 22 '17 at 23:12