How to read and move inodes

I opened the descriptor of the superblock and group in the EXT2 file system, but I don’t know how to read, for example, the root directory or files in it ...

Here are some of what I got

fd=open("/dev/sdb2", O_RDONLY); lseek(fd, SuperSize, SEEK_SET); read(fd, &super_block, SuperSize); lseek(fd, 4096, SEEK_SET); read(fd, &groupDesc, DescriptSize); 

but this next part does not work ...

 lseek(fd, super_block.s_log_block_size*groupDesc.bg_inode_table, SEEK_SET); lseek(fd, InodeSize*(EXT2_ROOT_INO-1), SEEK_CUR); read(fd, &root, InodeSize); 
+6
source share
2 answers

I do not quite understand what you are asking, but here goes:

To read the contents of a directory, you basically need to look inside the block of pointers, look at the corresponding blocks on the disk indicated by the pointers, and read the contents found there to get file descriptions in the directory.

This offer is of a rather high level, but everything else really comes down to deceiving the details of the system structures themselves.

I would recommend looking at chapter 4 of this: http://www.nongnu.org/ext2-doc/ext2.html

and also make sure that you clearly understand the specific structures in your case, which should be provided to you somewhere in the task ...

+2
source

A block group descriptor is all you need to traverse the ext file system. The superblock gives you general information about the file system, as well as the location of the block group descriptor (BGD). Inside BGD, you have information about each block group inside the file system.

To find the root directory, you need to look into the group of FIRST blocks and check the second inode; otherwise known as inode number 2. This can be achieved from the location of the first inode + sizeof (inode). In turn, the location of the first inode can be found inside the BGD record for the first group of blocks.

Let me know if you need more information.

+1
source

Source: https://habr.com/ru/post/890110/


All Articles