From: Theodore Ts'o Date: Wed, 31 Aug 2016 22:13:16 +0000 (-0400) Subject: debugfs: add the debugfs copy_inode subcommand X-Git-Tag: v1.43.2~17 X-Git-Url: https://git.whamcloud.com/gitweb?a=commitdiff_plain;h=b199291909e5951b74c9ad43163b5022a329dc26;p=tools%2Fe2fsprogs.git debugfs: add the debugfs copy_inode subcommand Signed-off-by: Theodore Ts'o --- diff --git a/debugfs/debug_cmds.ct b/debugfs/debug_cmds.ct index 34dad9e..1ff6c9d 100644 --- a/debugfs/debug_cmds.ct +++ b/debugfs/debug_cmds.ct @@ -73,6 +73,9 @@ request do_rm, "Remove a file (unlink and kill_file, if appropriate)", request do_kill_file, "Deallocate an inode and its blocks", kill_file; +request do_copy_inode, "Copy the inode structure", + copy_inode; + request do_clri, "Clear an inode's contents", clri; diff --git a/debugfs/debugfs.8.in b/debugfs/debugfs.8.in index e85034a..e151d43 100644 --- a/debugfs/debugfs.8.in +++ b/debugfs/debugfs.8.in @@ -225,6 +225,12 @@ master superblock. Clear the contents of the inode .IR filespec . .TP +.BI copy_inode " source_inode destination_inode" +Copy the conents of the inode structure in +.I source_inode +and use it to overwrite the inode structure at +.IR destination_inode . +.TP .BI dirsearch " filespec filename" Search the directory .I filespec diff --git a/debugfs/debugfs.c b/debugfs/debugfs.c index b2b06fe..f25ab1e 100644 --- a/debugfs/debugfs.c +++ b/debugfs/debugfs.c @@ -1584,6 +1584,35 @@ void do_unlink(int argc, char *argv[]) unlink_file_by_name(argv[1]); } + +void do_copy_inode(int argc, char *argv[]) +{ + ext2_ino_t src_ino, dest_ino; + struct ext2_inode inode; + unsigned char buf[4096]; + int retval; + + if (common_args_process(argc, argv, 3, 3, "copy_inode", + " ", CHECK_FS_RW)) + return; + + src_ino = string_to_inode(argv[1]); + if (!src_ino) + return; + + dest_ino = string_to_inode(argv[2]); + if (!dest_ino) + return; + + if (debugfs_read_inode_full(src_ino, (struct ext2_inode *) buf, + argv[0], sizeof(buf))) + return; + + if (debugfs_write_inode_full(dest_ino, (struct ext2_inode *) buf, + argv[0], sizeof(buf))) + return; +} + #endif /* READ_ONLY */ void do_find_free_block(int argc, char *argv[])