Whamcloud - gitweb
libext2fs: translate internal ext4 acl to Posix ACL in ext2fs_xattr_[sg]et()
[tools/e2fsprogs.git] / debugfs / debugfs.c
index 40ec05f..165f924 100644 (file)
@@ -35,12 +35,16 @@ extern char *optarg;
 
 #include "../version.h"
 #include "jfs_user.h"
-#include "../misc/plausible.h"
+#include "support/plausible.h"
 
 #ifndef BUFSIZ
 #define BUFSIZ 8192
 #endif
 
+#ifdef CONFIG_JBD_DEBUG                /* Enabled by configure --enable-jbd-debug */
+int journal_enable_debug = -1;
+#endif
+
 ss_request_table *extra_cmds;
 const char *debug_prog_name;
 int sci_idx;
@@ -76,7 +80,7 @@ static int debugfs_setup_tdb(const char *device_name, char *undo_file,
         * Configuration via a conf file would be
         * nice
         */
-       tdb_dir = getenv("E2FSPROGS_UNDO_DIR");
+       tdb_dir = ss_safe_getenv("E2FSPROGS_UNDO_DIR");
        if (!tdb_dir)
                tdb_dir = "/var/lib/e2fsprogs";
 
@@ -436,8 +440,7 @@ void do_show_super_stats(int argc, char *argv[])
                return;
        out = open_pager();
 
-       if (EXT2_HAS_RO_COMPAT_FEATURE(current_fs->super,
-                                      EXT4_FEATURE_RO_COMPAT_BIGALLOC))
+       if (ext2fs_has_feature_bigalloc(current_fs->super))
                units = "cluster";
 
        list_super2(current_fs->super, out);
@@ -782,11 +785,11 @@ static void dump_fast_link(FILE *out, ext2_ino_t inode_num,
                if (retval)
                        goto out;
        } else {
-               int sz = EXT2_I_SIZE(inode);
+               size_t sz = EXT2_I_SIZE(inode);
 
                if (sz > sizeof(inode->i_block))
                        sz = sizeof(inode->i_block);
-               fprintf(out, "%sFast link dest: \"%.*s\"\n", prefix, sz,
+               fprintf(out, "%sFast link dest: \"%.*s\"\n", prefix, (int) sz,
                        (char *)inode->i_block);
        }
 out:
@@ -827,8 +830,11 @@ void internal_dump_inode(FILE *out, const char *prefix,
                fprintf(out, "%sGeneration: %u    Version: 0x%08x\n", prefix,
                        inode->i_generation, inode->osd1.linux1.l_i_version);
        }
-       fprintf(out, "%sUser: %5d   Group: %5d   Size: ",
+       fprintf(out, "%sUser: %5d   Group: %5d",
                prefix, inode_uid(*inode), inode_gid(*inode));
+       if (is_large_inode && large_inode->i_extra_isize >= 32)
+               fprintf(out, "   Project: %5d", large_inode->i_projid);
+       fputs("   Size: ", out);
        if (LINUX_S_ISREG(inode->i_mode))
                fprintf(out, "%llu\n", EXT2_I_SIZE(inode));
        else
@@ -845,7 +851,7 @@ void internal_dump_inode(FILE *out, const char *prefix,
                        inode->i_file_acl | ((long long)
                                (inode->osd2.linux2.l_i_file_acl_high) << 32),
                        LINUX_S_ISDIR(inode->i_mode) ? inode->i_dir_acl : 0);
-       if (os == EXT2_OS_LINUX)
+       if (os != EXT2_OS_HURD)
                fprintf(out, "%sLinks: %d   Blockcount: %llu\n",
                        prefix, inode->i_links_count,
                        (((unsigned long long)
@@ -867,34 +873,42 @@ void internal_dump_inode(FILE *out, const char *prefix,
        if (is_large_inode && large_inode->i_extra_isize >= 24) {
                fprintf(out, "%s ctime: 0x%08x:%08x -- %s", prefix,
                        inode->i_ctime, large_inode->i_ctime_extra,
-                       time_to_string(inode->i_ctime));
+                       inode_time_to_string(inode->i_ctime,
+                                            large_inode->i_ctime_extra));
                fprintf(out, "%s atime: 0x%08x:%08x -- %s", prefix,
                        inode->i_atime, large_inode->i_atime_extra,
-                       time_to_string(inode->i_atime));
+                       inode_time_to_string(inode->i_atime,
+                                            large_inode->i_atime_extra));
                fprintf(out, "%s mtime: 0x%08x:%08x -- %s", prefix,
                        inode->i_mtime, large_inode->i_mtime_extra,
-                       time_to_string(inode->i_mtime));
+                       inode_time_to_string(inode->i_mtime,
+                                            large_inode->i_mtime_extra));
                fprintf(out, "%scrtime: 0x%08x:%08x -- %s", prefix,
                        large_inode->i_crtime, large_inode->i_crtime_extra,
-                       time_to_string(large_inode->i_crtime));
+                       inode_time_to_string(large_inode->i_crtime,
+                                            large_inode->i_crtime_extra));
+               if (inode->i_dtime)
+                       fprintf(out, "%s dtime: 0x%08x:(%08x) -- %s", prefix,
+                               large_inode->i_dtime, large_inode->i_ctime_extra,
+                               inode_time_to_string(inode->i_dtime,
+                                                    large_inode->i_ctime_extra));
        } else {
                fprintf(out, "%sctime: 0x%08x -- %s", prefix, inode->i_ctime,
-                       time_to_string(inode->i_ctime));
+                       time_to_string((__s32) inode->i_ctime));
                fprintf(out, "%satime: 0x%08x -- %s", prefix, inode->i_atime,
-                       time_to_string(inode->i_atime));
+                       time_to_string((__s32) inode->i_atime));
                fprintf(out, "%smtime: 0x%08x -- %s", prefix, inode->i_mtime,
-                       time_to_string(inode->i_mtime));
+                       time_to_string((__s32) inode->i_mtime));
+               if (inode->i_dtime)
+                       fprintf(out, "%sdtime: 0x%08x -- %s", prefix,
+                               inode->i_dtime,
+                               time_to_string((__s32) inode->i_dtime));
        }
-       if (inode->i_dtime)
-         fprintf(out, "%sdtime: 0x%08x -- %s", prefix, inode->i_dtime,
-                 time_to_string(inode->i_dtime));
        if (EXT2_INODE_SIZE(current_fs->super) > EXT2_GOOD_OLD_INODE_SIZE)
                internal_dump_inode_extra(out, prefix, inode_num,
                                          (struct ext2_inode_large *) inode);
        dump_inode_attributes(out, inode_num);
-       if (current_fs->super->s_creator_os == EXT2_OS_LINUX &&
-           current_fs->super->s_feature_ro_compat &
-               EXT4_FEATURE_RO_COMPAT_METADATA_CSUM) {
+       if (ext2fs_has_feature_metadata_csum(current_fs->super)) {
                __u32 crc = inode->i_checksum_lo;
                if (is_large_inode &&
                    large_inode->i_extra_isize >=
@@ -1570,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[])
@@ -1734,7 +1777,7 @@ void do_mkdir(int argc, char *argv[])
                                "<filename>", CHECK_FS_RW))
                return;
 
-       retval = do_mkdir_internal(current_fs, cwd, argv[1], NULL, root);
+       retval = do_mkdir_internal(current_fs, cwd, argv[1], root);
        if (retval)
                com_err(argv[0], retval, 0);
 
@@ -2076,14 +2119,14 @@ err:
 #ifndef READ_ONLY
 void do_set_current_time(int argc, char *argv[])
 {
-       time_t now;
+       __s64 now;
 
        if (common_args_process(argc, argv, 2, 2, argv[0],
                                "<time>", 0))
                return;
 
        now = string_to_time(argv[1]);
-       if (now == ((time_t) -1)) {
+       if (now == -1) {
                com_err(argv[0], 0, "Couldn't parse argument as a time: %s\n",
                        argv[1]);
                return;
@@ -2247,16 +2290,35 @@ void do_symlink(int argc, char *argv[])
 
 }
 
+#if CONFIG_MMP
 void do_dump_mmp(int argc EXT2FS_ATTR((unused)), char *argv[])
 {
-#if CONFIG_MMP
        struct mmp_struct *mmp_s;
+       unsigned long long mmp_block;
        time_t t;
        errcode_t retval = 0;
 
        if (check_fs_open(argv[0]))
                return;
 
+       if (argc > 1) {
+               char *end = NULL;
+               mmp_block = strtoull(argv[1], &end, 0);
+               if (end == argv[0] || mmp_block == 0) {
+                       fprintf(stderr, "%s: invalid MMP block '%s' given\n",
+                               argv[0], argv[1]);
+                       return;
+               }
+       } else {
+               mmp_block = current_fs->super->s_mmp_block;
+       }
+
+       if (mmp_block == 0) {
+               fprintf(stderr, "%s: MMP: not active on this filesystem.\n",
+                       argv[0]);
+               return;
+       }
+
        if (current_fs->mmp_buf == NULL) {
                retval = ext2fs_get_mem(current_fs->blocksize,
                                        &current_fs->mmp_buf);
@@ -2268,10 +2330,10 @@ void do_dump_mmp(int argc EXT2FS_ATTR((unused)), char *argv[])
 
        mmp_s = current_fs->mmp_buf;
 
-       retval = ext2fs_mmp_read(current_fs, current_fs->super->s_mmp_block,
-                                current_fs->mmp_buf);
+       retval = ext2fs_mmp_read(current_fs, mmp_block, current_fs->mmp_buf);
        if (retval) {
-               com_err(argv[0], retval, "reading MMP block.\n");
+               com_err(argv[0], retval, "reading MMP block %llu.\n",
+                       mmp_block);
                return;
        }
 
@@ -2286,11 +2348,17 @@ void do_dump_mmp(int argc EXT2FS_ATTR((unused)), char *argv[])
        fprintf(stdout, "device_name: %s\n", mmp_s->mmp_bdevname);
        fprintf(stdout, "magic: 0x%x\n", mmp_s->mmp_magic);
        fprintf(stdout, "checksum: 0x%08x\n", mmp_s->mmp_checksum);
+       fprintf(stdout, "MMP is unsupported, please recompile with "
+                       "--enable-mmp\n");
+}
 #else
+void do_dump_mmp(int argc EXT2FS_ATTR((unused)),
+                char *argv[] EXT2FS_ATTR((unused)))
+{
        fprintf(stdout, "MMP is unsupported, please recompile with "
                        "--enable-mmp\n");
-#endif
 }
+#endif
 
 static int source_file(const char *cmd_file, int ss_idx)
 {
@@ -2359,6 +2427,9 @@ int main(int argc, char **argv)
        const char      *opt_string = "niwcR:f:b:s:Vd:Dz:";
        char            *undo_file = NULL;
 #endif
+#ifdef CONFIG_JBD_DEBUG
+       char            *jbd_debug;
+#endif
 
        if (debug_prog_name == 0)
 #ifdef READ_ONLY
@@ -2370,6 +2441,19 @@ int main(int argc, char **argv)
        fprintf (stderr, "%s %s (%s)\n", debug_prog_name,
                 E2FSPROGS_VERSION, E2FSPROGS_DATE);
 
+#ifdef CONFIG_JBD_DEBUG
+       jbd_debug = ss_safe_getenv("DEBUGFS_JBD_DEBUG");
+       if (jbd_debug) {
+               int res = sscanf(jbd_debug, "%d", &journal_enable_debug);
+
+               if (res != 1) {
+                       fprintf(stderr,
+                               "DEBUGFS_JBD_DEBUG \"%s\" not an integer\n\n",
+                               jbd_debug);
+                       exit(1);
+               }
+       }
+#endif
        while ((c = getopt (argc, argv, opt_string)) != EOF) {
                switch (c) {
                case 'R':