On Fri, Dec 08, 2017 at 07:33:58PM +0300, Nikita Maslov wrote:
> Package: e2fsprogs
> Version: 1.43.7-1
> Severity: normal
> 
> I found a problem with debugfs (but it may be a problem with the whole
> e2fslibs) when trying to mark block bitmap.  It looks like group
> descriptor which is modified with 
> 
> Steps to reproduce this:
> 
>    1. Create a new ext4 filesystem image:
>       $ dd if=/dev/zero of=/tmp/testfs.img bs=1K count=4096
>       $ /sbin/mkfs.ext4 /tmp/testfs.img
>    2. Open this image with debugfs, set some free block's mark and close
>    debugfs:
>       $ /sbin/debugfs -w /tmp/testfs.img
>       debugfs: ffb
>       Free blocks found: 1204
>       debugfs: setb 1204
>       debugfs: q
>       $
>    3. Try to open this image again with debugfs:
>       $ /sbin/debugfs /tmp/testfs.img
>       /tmp/testfs.img: Block bitmap checksum does not match bitmap while 
> reading block bitmap

So this is one of these interesting philosophical questions about how
low-level debugfs is supposed to be.  The setb/clearb/seti/setb
commands are extremely low level, so they do *not* update the block
group descriptor's checksums.

You can update the block group descriptor's checksum by hand via
the set_bg command.

Yes, this is annoyingly manual.  But part of this is a question over
what the intended users of debugfs is supposed to be.  It was
originally intended to be used by ext4 developers to create corrupted
file system images, and to do low-level file system debugging.  But it
is now also used by system administrators, and in some cases by
embedded systems developers who use debugfs to populate prebuilt file
system images (say, as part of Android system image builds, for
example).

This situation has come up before, and this is why in addition to the
"unlink" (which _just_ removes the directory entry, or "link" for a
particular file), and "kill_file" (which deallocates an inode and
updates the block bitmaps -- and also updates the checksums, by the
way), and "rm" (which acts like the rm command --- removes a directory
entry, it drops the inode's link_count, and if the link_count goes to
zero, calls "kill_file").

The "rm" command is the user-friendly command intended for civilian
use cases, where as the "unlink" and "kill_file" are intended for ext4
developers who want to do something extremely targetted.

One approach would be to create a civilian-friendly version of "setb",
but it's not clear to me why civillians would be using setb directly
in the first place.  Another approach might be to create a mode which
automatically updates the block group descriptor's checksum fields
automatically.  At the very least I should add the ability to say,
"set_bg 0 block_bitmap_csum calc", which currently only works for the
"set_bg 0 checksum calc" case.

By the way, you can open a file system bad checksum values by using
the debugfs -n command.

Cheers,

                                                - Ted

Reply via email to