From b026d539e67ca4bd1a7ef3743888c594fad7bfff Mon Sep 17 00:00:00 2001 From: Theodore Ts'o Date: Tue, 1 Jan 2008 11:37:20 -0500 Subject: [PATCH] debugfs: allow the undel command reallocate without linking the inode When recovering a large number of deleted files, linking the undeleted inodes to directories may require a directory to be expanded. This could allocate a block that that had been used by one of the yet-to-be-undeleted files. So the 'undel' command been enhanced to allow the destination pathname to be optional. This will allow the cautious user to undelete all of the inodes without specifying a destination pathname, and then either use debugfs's link command to add hard links, or use e2fsck to link all of the recovered files to the lost+found directory. Addresses-Sourceforge-Feature-Request: #967141 Signed-off-by: "Theodore Ts'o" --- debugfs/debugfs.8.in | 21 +++++++++++++++++++++ debugfs/debugfs.c | 7 ++++--- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/debugfs/debugfs.8.in b/debugfs/debugfs.8.in index a4d9670..b9de234 100644 --- a/debugfs/debugfs.8.in +++ b/debugfs/debugfs.8.in @@ -446,6 +446,27 @@ Test if the inode .I filespec is marked as allocated in the inode bitmap. .TP +.I undel [pathname] +Undelete the specified inode number (which must be surrounded by angle +brackets) so that it and its blocks are marked in use, and optionally +link the recovered inode to the specified pathname. The +.B e2fsck +command should always be run after using the +.B undel +command to recover deleted files. +.IP +Note that if you are recovering a large number of deleted files, linking +the inode to a directory may require the directory to be expanded, which +could allocate a block that had been used by one of the +yet-to-be-undeleted files. So it is safer to undelete all of the +inodes without specifying a destination pathname, and then in a separate +pass, use the debugfs +.B link +command to link the inode to the destination pathname, or use +.B e2fsck +to check the filesystem and link all of the recovered inodes to the +lost+found dirctory. +.TP .I unlink pathname Remove the link specified by .I pathname diff --git a/debugfs/debugfs.c b/debugfs/debugfs.c index 6635471..2d24825 100644 --- a/debugfs/debugfs.c +++ b/debugfs/debugfs.c @@ -1084,8 +1084,8 @@ void do_undel(int argc, char *argv[]) ext2_ino_t ino; struct ext2_inode inode; - if (common_args_process(argc, argv, 3, 3, "undelete", - " ", + if (common_args_process(argc, argv, 2, 3, "undelete", + " [dest_name]", CHECK_FS_RW | CHECK_FS_BITMAPS)) return; @@ -1116,7 +1116,8 @@ void do_undel(int argc, char *argv[]) ext2fs_inode_alloc_stats2(current_fs, ino, +1, 0); - make_link(argv[1], argv[2]); + if (argc > 2) + make_link(argv[1], argv[2]); } static void unlink_file_by_name(char *filename) -- 1.8.3.1