#!/bin/sh

echo "This tool attempts to dump inodes from a corrupted disc"
echo "using debugfs. Use the namem.sh and filem.sh tools to"
echo "make recovery easier."
echo ""
echo "THIS IS OPEN SOURCE SOFTWARE."
echo ""
echo "Philip J. Mucci (mucci@cs.utk.edu)"
echo "http://www.cs.utk.edu/~mucci"
echo ""

# touch me
startinode=1;
endinode=1;
sizelimit=10000
device=/dev/hda5
month=""
# don't touch
i=$startinode
size=0;
output="";

while [ $i -lt $endinode ]; 
echo -n "Inode $i: "
do
# filter on time
if [ $month ]; then
toutput=`echo "stat <$i>" | debugfs -c $device 2> /dev/null | grep mtime`
echo $toutput | grep -e $month > /dev/null
fi
if [ $? -eq 0 ]; then
output=`echo "stat <$i>" | debugfs -c $device 2> /dev/null | grep User`
size=`echo $output | cut -d: -f4 | xargs`
# filter on size
if [ $size -gt $sizelimit ]; then
	echo "dump <$i> /mnt/temp4/$i" | debugfs -c $device 2> /dev/null
	echo "inode $i saved $size bytes"
else
	echo "inode $i skipped $size bytes"
fi
else
echo "Old/invalid file skipped"
fi
(( i=$i+1 ));
done


