From b199291909e5951b74c9ad43163b5022a329dc26 Mon Sep 17 00:00:00 2001 From: Theodore Ts'o Date: Wed, 31 Aug 2016 18:13:16 -0400 Subject: [PATCH] debugfs: add the debugfs copy_inode subcommand Signed-off-by: Theodore Ts'o --- debugfs/debug_cmds.ct | 3 +++ debugfs/debugfs.8.in | 6 ++++++ debugfs/debugfs.c | 29 +++++++++++++++++++++++++++++ 3 files changed, 38 insertions(+) diff --git a/debugfs/debug_cmds.ct b/debugfs/debug_cmds.ct index 34dad9e6..1ff6c9dc 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 e85034ab..e151d43a 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 b2b06fe6..f25ab1e4 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[])