#!/bin/bash # suppress output from debugfs exec 2> /dev/null if [[ $# -eq 0 ]]; then echo "Usage: $0 filename" exit fi INODE=`stat $1 | grep "Inode: " | awk '{print $4}'` PARTITION=`df -h $1 | tail -1 | awk '{print $1}'` BLOCK=`debugfs -R "imap <$INODE>" $PARTITION | grep "located" | cut -d" " -f4 | cut -d"," -f1` OFFSET=`debugfs -R "imap <$INODE>" $PARTITION | grep "offset" | awk '{print $6}'` echo "inode: $INODE, block: $BLOCK, offset: $OFFSET, partition: $PARTITION" # inodes are always 256 bytes (for now, at least) readblock $PARTITION $BLOCK $OFFSET 256 | dumpit | grep -v "stdin:"