By user12625760 on Jun 05, 2006
Ever since Solaris 2.0 people have been asking for a way to map from a block on a disk back to the file which contains that block. In SunOS 4 and earlier used to have icheck(8) but that was never available in Solaris 2.0.
The answer that is usually given is short: “Use fsdb”. However fsdb is slightly less than friendly and in fact doing an exhaustive search of a file system for a particular block would be close to impossible to do by hand.
I was left thinking this must be able to be scripted. Since my particular issue was on Solaris 8 I had the added constraint that it would have to be a shell script from the choice of shells on Solaris 8.
As an example of things you can do I have written a script that will drive fsdb and can be used to:
Copy files out of unmounted file systems (with the caveat that they get padded to be whole number of blocks). I used this to test the script then compare the source file and target. I have left it in more amusement.
Find which inode and offset contains a particular disk block (blocks get specified in hex):
# icheck -d /dev/rdsk/c0d0s6 007e1590 007dd2a0 008bb6c0 inode 5c94: file block: 16#80b device block: 16#007e1590 inode 5c94: file block: 16#1ffff device block: 16#007dd2a0 inode 5c94: file block: 16#7ffffff device block: 16#008bb6c0 #
This search can be directly limited to a single inode using the -i option and an inode number (in hex).
Print the extents of a file. Again this is just mildly amusing but shows how well or badly UFS is doing laying out your files.
# icheck -d /dev/rdsk/c0t0d0s0 -x -i 186e file off 0 dev off 6684 len 1279 file off 1279 dev off 6683 len 1 #
The user interface could live with being tidied up but my original goal has been satisfied.
The script itself is not for those with a weak stomach as it works around some bugs and features in fsdb. The script is here if you wish to see the full horror.