2

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?

2

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.

  • Also see "How does Linux know the Location of File Data on Disk" unix.stackexchange.com/questions/74319/… – 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.