If you're trying to recovery files from ext2/ext3 filesystems, you might be duplicating work that has already been done. The Coroner's Toolkit
contains the programs unrm
(unremove) and lazarus
which can be used together to attempt
to undelete files. The authors point out that it is not for the faint of heart. I know the book Knoppix Hacks
contains instructions for this. You may be able to find other instructions around. If you don't want to use these tools as is, perhaps reading their source can answer some of the questions you have.