0

In c, how would I find a directory in a virtual disk? I can easily recurse the absolute path and tun that into just the name of the directory I am looking for (i.e. turning /x/y/z into just z). I know that the root is inode 2, and I know how to get to some parts of the file system (superblock, block descriptor, inode table, bg_block/inode bitmap) but I have no clue how to traverse all the data in the image.

This image only has one block group, for what it's worth. Inode size and block size are set to their own predefined variables in the header (EXT2_BLOCK_SIZE and s_inode_size in superblock).

Jeffrey
  • 13
  • 3
  • You can use [guestfs_lstatns from libguestfs](http://libguestfs.org/guestfs.3.html#guestfs_lstatns). Or did you want something lower level? – Mark Plotnick Dec 04 '15 at 21:05
  • You could mount the file system and then do a `stat` on the file to find its inode, but I believe this is not what you desire. – fuz Dec 04 '15 at 21:06

1 Answers1

0

You have to implement the namei algorithm for ext[234] filesystem to get to the correct place. Just follow the kernel source code for the implementation of the ext[234] filesystem and look for the namei routine.

Luis Colorado
  • 10,974
  • 1
  • 16
  • 31