Read image with libext2

  • Is there a way to read a disk image created by mke2fs using libext2? (Open a file system using the image file as the device?)


    Parker Abercrombie

    • Theodore Ts'o
      Theodore Ts'o

      Yes, it is possible.   Take a look at the code in the e2fsprogs sources, in debugfs/dump.c and debugfs/util.c.   You first have to translate the filename to an inode number (see debugfs/util.c, in the string_to_inode function), using the function ext2_namei().  You can then use ext2fs_file_open(), ext2fs_file_read(), and ext2fs_file_close().  There is an example of how to use these functions in the dump_file() subroutine in debugfs/dump.c.   Note that writing a file via libext2fs is a bit more complicated, but reading from an image file is relatively straight forward.