]> git.ipfire.org Git - thirdparty/e2fsprogs.git/commitdiff
debugfs: add the debugfs copy_inode subcommand
authorTheodore Ts'o <tytso@mit.edu>
Wed, 31 Aug 2016 22:13:16 +0000 (18:13 -0400)
committerTheodore Ts'o <tytso@mit.edu>
Wed, 31 Aug 2016 22:13:16 +0000 (18:13 -0400)
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
debugfs/debug_cmds.ct
debugfs/debugfs.8.in
debugfs/debugfs.c

index 34dad9e6f731eba91f07dbd137884429d3bccec0..1ff6c9dcd6b53aa6ac570946f201a21b320372c5 100644 (file)
@@ -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;
 
index e85034ab1cacaa5ed5d8ce29a2fd89b0e8464320..e151d43aa64dd6b161f4fc2f85581f4fb0717a0f 100644 (file)
@@ -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
index b2b06fe666e2143ac1ab737d5f3797fa73d66c2f..f25ab1e445be6971be7c26015b482979aa428fb3 100644 (file)
@@ -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",
+                               "<source file> <dest_name>", 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[])