Skip to content

Instantly share code, notes, and snippets.

@windwiny
Created December 12, 2013 06:56
Show Gist options
  • Select an option

  • Save windwiny/7924120 to your computer and use it in GitHub Desktop.

Select an option

Save windwiny/7924120 to your computer and use it in GitHub Desktop.
search each cylinder , find hard disk lost filesystem
def oo(cylinder, sector)
sector *= 512
aa=<<-EOS
echo "cylinder: #{cylinder}"
losetup -o #{sector} /dev/loop1 /dev/sdb3
if [ $? -eq 0 ] ; then
mount /dev/loop1 /tmp/11 2>/dev/null
if [ $? -eq 0 ] ; then
echo "offset #{sector} byte find a file system!!"
exit 0
fi
losetup -d /dev/loop1
sleep 0.1
fi
EOS
puts aa
end
# foreach cylinder, 0/1 header, 1 sector , find a file system
#beg = 30678
beg = 0 + 3900
eng = beg + 250
(beg..eng).each do |cylinder|
sec0 = cylinder*255*63 + 0*63 + 1 - 1
sec1 = cylinder*255*63 + 1*63 + 1 - 1
oo(cylinder, sec0)
oo(cylinder, sec1)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment