I looked through the relevant code in pass2.c::check_dir_block():
/*
* Offer to clear unused inodes; if we are going to be
* restarting the scan due to bg_itable_unused being
* wrong, then don't clear any inodes to avoid zapping
* inodes that were skipped during pass1 due to an
* incorrect bg_itable_unused; we'll get any real
* problems after we restart.
*/
if (!(ctx->flags & E2F_FLAG_RESTART_LATER) &&
!(ext2fs_test_inode_bitmap2(ctx->inode_used_map,
dirent->inode)))
problem = PR_2_UNUSED_INODE;
if (problem) {
if (fix_problem(ctx, problem, &cd->pctx)) {
dirent->inode = 0;
dir_modified++;
goto next;
It is easy to trigger the PR_2_UNUSED_INODE problem by setting nlink = 0 in the inode(s) via debugfs. However, when I run e2fsck against such a filesystem (whether with small directories or large htree directories) e2fsck fixes the problem by clearing the dirent (setting inode = 0 above, and later writing out the directory block) and a second check shows it is fixed.
To capture a filesystem that has a persistent case of this problem (after "e2fsck -fy" didn't fix it) so that it can be debugged and fixed, please use e2image to dump the filesystem metadata. The dense image format can be efficiently compressed and transported, unlike the sparse variant of e2image:
Hopefully the OSTnnnn.qcow.bz2 image size is small enough for transport. It is possible to reconstitute the (uncompressed) qcow file into a raw ext4 image file that can be tested with e2fsck, debugfs, or mounted via loopback.
It seems like this doesn't actually produce a valid raw image:
e2image -r OSTnnnn.qcow OSTnnnn.raw
I had to do:
qemu-img convert -p -O raw /scratch/ost000b.qcow ost000b.raw
to get something that worked.