OSDN Git Service

debugfs: allow the undel command reallocate without linking the inode
authorTheodore Ts'o <tytso@mit.edu>
Tue, 1 Jan 2008 16:37:20 +0000 (11:37 -0500)
committerTheodore Ts'o <tytso@mit.edu>
Tue, 1 Jan 2008 16:43:41 +0000 (11:43 -0500)
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" <tytso@mit.edu>
debugfs/debugfs.8.in
debugfs/debugfs.c

index a4d9670..b9de234 100644 (file)
@@ -446,6 +446,27 @@ Test if the inode
 .I filespec
 is marked as allocated in the inode bitmap.
 .TP
+.I undel <inode num> [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 
index 6635471..2d24825 100644 (file)
@@ -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",
-                               "<inode_num> <dest_name>",
+       if (common_args_process(argc, argv, 2, 3, "undelete",
+                               "<inode_num> [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)