From: Artem Blagodarenko Add a helper that lists a directory with the -lD flags and checks whether any dirdata fields exist. This helper will be used by subsequent dirdata-related patches. Signed-off-by: Artem Blagodarenko --- common/ext4 | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/common/ext4 b/common/ext4 index a2ce456d..47c31db9 100644 --- a/common/ext4 +++ b/common/ext4 @@ -242,3 +242,37 @@ _ext4_get_inum_iflags() { debugfs -R "stat <${inumber}>" "${dev}" 2> /dev/null | \ sed -n 's/^.*Flags: \([0-9a-fx]*\).*$/\1/p' } + +# Helper to dump directory structure with hash info (requires dirdata feature) +# This is useful for verifying that dirdata is storing hash information +_dump_dir_structure() +{ + local dir=$1 + local dir_name=$(basename $dir) + local expected=$3 + + local debugfs_output=$({ + echo "cd $dir_name" + echo "ls -lD ." + echo "quit" + } | debugfs $SCRATCH_DEV 2>/dev/null) + + # DEBUG: uncomment to see full debugfs output + # echo " [DEBUG] debugfs output for $dir_name:" + # echo "$debugfs_output" | grep -v "^debugfs:" | sed 's/^/ /' + + # Check if hash data is present (encryption+casefold+dirdata case) + # or if fid data is present (dirdata+encryption or dirdata only case) + if echo "$debugfs_output" | grep -q "fid="; then + local fid_value=$(echo "$debugfs_output" | grep -o "fid=[^ ]*" | head -1 | sed 's/^fid=//') + if [ "$fid_value" = "$expected" ]; then + echo " Directory structure of $dir_name: OK (dirdata verified)" + else + echo " Directory structure of $dir_name: FAILED (fid mismatch: got '$fid_value', expected '$expected')" + fi + elif echo "$debugfs_output" | grep -q "hash="; then + echo " Directory structure of $dir_name: OK (dirdata verified)" + else + echo " Directory structure of $dir_name: FAILED (no dirdata)" + fi +} -- 2.43.7