libext2fs: workaround for bitmap data parsin?

2010-06-11
2012-11-28
  • Superblock records the number of inodes per disk group.  From this you can figure out how many bits at the tail end of the bitmap you should ignore.

     
  • Yann Droneaud
    Yann Droneaud
    2010-06-14

    I'm using this code (adapted from dumpe2fs):

        blk_itr = fs->super->s_first_data_block;
        for (i = 0; i < fs->group_desc_count; i++) {
            /* get bitmap data of allocated blocks in current group */
            ret = ext2fs_get_block_bitmap_range(fs->block_map,
                                                blk_itr, blocks_bitmap_len * 8,
                                                blocks_bitmap);
            first_block = ext2fs_group_first_block(fs, i);
            last_block = ext2fs_group_last_block(fs, i);
             /* set them relative to current block */
            first_block -= blk_itr;
            last_block -= blk_itr;
            /* parse blocks bitmap, from first to last (included) */
            for (j = first_block; j <= last_block; j++) {
            }
    

    See http://pulse2.mandriva.org/browser/pulse2/client/imaging/trunk/tools/revosave/image_e2fs.c

    How can I check that there's no block bitmap for a group without looking into ext2fs data structure: I wan't to use library function only ?

    Thanks.

     
  • Yann Droneaud
    Yann Droneaud
    2010-06-14

    With e2fsprogs < 1.41.9, on a empty 2G filesystem, the tool reports:

    - Total sectors : 4194304 = 2048 MiB
    - Used sectors  : 2300256 = 1123 MiB (54.84%)

    While with e2fsprogs >= 1.41.9, the tools reports:

    - Total sectors : 4194304 = 2048 MiB
    - Used sectors  : 203104 = 99 MiB (4.84%)

    I'd like to make the tool reporting  a correct results regardless to the library used. I'm currently stuck to blacklist older e2fsprogs which doesn"t make user of Debian happy, for example.

     
  • Theodore Ts'o
    Theodore Ts'o
    2010-06-14

    What program are you trying to write and what distribution are you trying to support?   There are enough bugs with the ext4 support in e2fsprogs versions older than 1.41.9 that it's really not worth it to work around it in an application program.  My recommendation is to check the library version using ext2fs_get_library_version() and then exit with an error if you see a version of e2fsprogs that old….  tell the user to upgrade, since they will be running into many other problems with ext4 support.

     
  • Yann Droneaud
    Yann Droneaud
    2010-06-14

    This a program that lists the used physical sectors of a ext2,ext3, ext4 filesystem.

    I'm ok to blacklist any e2fsprogs older than 1.41.9 regarding to ext4, it's a sane solution. Thanks for your advice.
    But it should be OK to use previous e2fsprogs for ext2 and ext3. So I must add a check on filesystem feature to detect filesystem flavor known or not to work.

    Regards.

     
  • Theodore Ts'o
    Theodore Ts'o
    2010-06-14

    I'm just curious; is this program intended to assist in data recovery after a hard drive failure?

     
  • Yann Droneaud
    Yann Droneaud
    2010-06-14

    No, it's just a tool to create another kind of disk image. This is an old tool, part of LRS (Linbox Rescue Server), which was using e2fsprogs-1.22 (statically linked !). I've made it use the system shared library instead, so it could also process ext4 filesystem.