How to undelete (Re: PATCH to pre-patch-2.1.45: clean_inode needs to reset i_writecount)

Andrea Arcangeli (arcangeli@mbox.queen.it)
Mon, 11 Aug 1997 02:25:58 +0200 (CEST)


I want to know how undelete a directory or a file from ext2fs because I
deleted some files (not very important :) from my hd.

I remember an not very old mail of Linus about this, but I can' t
reproduce it myself.

On Thu, 10 Jul 1997, Linus Torvalds wrote:

>Actually, because the minixfs didn't bother to write out the inodes after
>it deleted them, it was _very_ simple to recover from "rm -rf". I've
>actually done this once when I removed my linux source directory by
>mistake once:
>
> - find the inode that was the "linux" directory inode (not very hard:
> because the inode was never written out when it was deleted, all the
> information was still up-to-date)

I can find it using debugfs with lsdel command.

> - create a new directory entry pointing to the "linux" inode

????? How can I do it ????? Using debugfs ?????

> - run fsck

Easy :).

>
>Voila, the _whole_ tree came back. NOTHING was lost. Because the inode
>wasn't actually written out to disk when it was deleted, all the
>information was still there: including the full directory tree (because
>the data blocks were also marked clean when they were deleted, so all the
>directory entry zeroing that had happened recursively never hit the disk
>at all).

Can somebody explain me how can I create a new directory entry pointing to
the old "directory_deleted" inode?

If I run mkdir inside debugfs the inode number is selected by debugfs.
Using the mi command inside debugfs I can' t change the inode number.

Thanks in advance for any help...

Andrea Arcangeli