]> git.ipfire.org Git - thirdparty/e2fsprogs.git/blobdiff - debugfs/debugfs.c
debugfs: output large directory size
[thirdparty/e2fsprogs.git] / debugfs / debugfs.c
index a17d90825778c7413b2b1d7a3573c314f913dd99..faae12da25ecbdd1c2b0a4c1f90d09253cec03eb 100644 (file)
@@ -55,13 +55,15 @@ int sci_idx;
 ext2_filsys    current_fs;
 quota_ctx_t    current_qctx;
 ext2_ino_t     root, cwd;
+int            no_copy_xattrs;
 
 static int debugfs_setup_tdb(const char *device_name, char *undo_file,
                             io_manager *io_ptr)
 {
        errcode_t retval = ENOMEM;
-       char *tdb_dir = NULL, *tdb_file = NULL;
-       char *dev_name, *tmp_name;
+       const char      *tdb_dir = NULL;
+       char            *tdb_file = NULL;
+       char            *dev_name, *tmp_name;
 
        /* (re)open a specific undo file */
        if (undo_file && undo_file[0] != 0) {
@@ -159,13 +161,8 @@ static void open_filesystem(char *device, int open_flags, blk64_t superblock,
                }
        }
 
-       if (catastrophic && (open_flags & EXT2_FLAG_RW)) {
-               com_err(device, 0,
-                       "opening read-only because of catastrophic mode");
-               open_flags &= ~EXT2_FLAG_RW;
-       }
        if (catastrophic)
-               open_flags |= EXT2_FLAG_SKIP_MMP;
+               open_flags |= EXT2_FLAG_SKIP_MMP | EXT2_FLAG_IGNORE_SB_ERRORS;
 
        if (undo_file) {
                retval = debugfs_setup_tdb(device, undo_file, &io_ptr);
@@ -176,13 +173,15 @@ static void open_filesystem(char *device, int open_flags, blk64_t superblock,
 try_open_again:
        retval = ext2fs_open(device, open_flags, superblock, blocksize,
                             io_ptr, &current_fs);
-       if (retval && !(open_flags & EXT2_FLAG_IGNORE_CSUM_ERRORS)) {
+       if (retval && (retval == EXT2_ET_SB_CSUM_INVALID) &&
+           !(open_flags & EXT2_FLAG_IGNORE_CSUM_ERRORS)) {
                open_flags |= EXT2_FLAG_IGNORE_CSUM_ERRORS;
                printf("Checksum errors in superblock!  Retrying...\n");
                goto try_open_again;
        }
        if (retval) {
-               com_err(device, retval, "while opening filesystem");
+               com_err(debug_prog_name, retval,
+                       "while trying to open %s", device);
                if (retval == EXT2_ET_BAD_MAGIC)
                        check_plausibility(device, CHECK_FS_EXIST, NULL);
                current_fs = NULL;
@@ -193,14 +192,10 @@ try_open_again:
        if (catastrophic)
                com_err(device, 0, "catastrophic mode - not reading inode or group bitmaps");
        else {
-               retval = ext2fs_read_inode_bitmap(current_fs);
-               if (retval) {
-                       com_err(device, retval, "while reading inode bitmap");
-                       goto errout;
-               }
-               retval = ext2fs_read_block_bitmap(current_fs);
+               retval = ext2fs_read_bitmaps(current_fs);
                if (retval) {
-                       com_err(device, retval, "while reading block bitmap");
+                       com_err(device, retval,
+                               "while reading allocation bitmaps");
                        goto errout;
                }
        }
@@ -845,7 +840,7 @@ void internal_dump_inode(FILE *out, const char *prefix,
        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))
+       if (LINUX_S_ISREG(inode->i_mode) || LINUX_S_ISDIR(inode->i_mode))
                fprintf(out, "%llu\n", EXT2_I_SIZE(inode));
        else
                fprintf(out, "%d\n", inode->i_size);
@@ -1773,7 +1768,8 @@ void do_mknod(int argc, char *argv[])
                goto usage;
 
        st.st_rdev = makedev(major, minor);
-       retval = do_mknod_internal(current_fs, cwd, argv[1], &st);
+       retval = do_mknod_internal(current_fs, cwd, argv[1],
+                                  st.st_mode, st.st_rdev);
        if (retval)
                com_err(argv[0], retval, 0);
 }
@@ -1796,11 +1792,17 @@ static int release_blocks_proc(ext2_filsys fs, blk64_t *blocknr,
                               e2_blkcnt_t blockcnt EXT2FS_ATTR((unused)),
                               blk64_t ref_block EXT2FS_ATTR((unused)),
                               int ref_offset EXT2FS_ATTR((unused)),
-                              void *private EXT2FS_ATTR((unused)))
+                              void *private)
 {
-       blk64_t block;
+       blk64_t block = *blocknr;
+       blk64_t *last_cluster = (blk64_t *)private;
+       blk64_t cluster = EXT2FS_B2C(fs, block);
+
+       if (cluster == *last_cluster)
+               return 0;
+
+       *last_cluster = cluster;
 
-       block = *blocknr;
        ext2fs_block_alloc_stats2(fs, block, -1);
        return 0;
 }
@@ -1815,8 +1817,9 @@ static void kill_file_by_inode(ext2_ino_t inode)
        if (debugfs_write_inode(inode, &inode_buf, 0))
                return;
        if (ext2fs_inode_has_valid_blocks2(current_fs, &inode_buf)) {
+               blk64_t last_cluster = 0;
                ext2fs_block_iterate3(current_fs, inode, BLOCK_FLAG_READ_ONLY,
-                                     NULL, release_blocks_proc, NULL);
+                                     NULL, release_blocks_proc, &last_cluster);
        }
        printf("\n");
        ext2fs_inode_alloc_stats2(current_fs, inode, -1,
@@ -2094,15 +2097,29 @@ void do_imap(int argc, char *argv[])
 
 void do_idump(int argc, char *argv[])
 {
+       struct ext2_inode_large *inode;
        ext2_ino_t      ino;
        unsigned char   *buf;
        errcode_t       err;
-       int             isize;
+       unsigned int    isize, size, offset = 0;
+       int             c, mode = 0;
 
-       if (common_args_process(argc, argv, 2, 2, argv[0],
-                               "<file>", 0))
+       reset_getopt();
+       while ((c = getopt (argc, argv, "bex")) != EOF) {
+               if (mode || c == '?') {
+                       com_err(argv[0], 0,
+                               "Usage: inode_dump [-b]|[-e] <file>");
+                       return;
+               }
+               mode = c;
+       }
+       if (optind != argc-1)
                return;
-       ino = string_to_inode(argv[1]);
+
+       if (check_fs_open(argv[0]))
+               return;
+
+       ino = string_to_inode(argv[optind]);
        if (!ino)
                return;
 
@@ -2120,7 +2137,29 @@ void do_idump(int argc, char *argv[])
                goto err;
        }
 
-       do_byte_hexdump(stdout, buf, isize);
+       inode = (struct ext2_inode_large *) buf;
+       size = isize;
+       switch (mode) {
+       case 'b':
+               offset = ((char *) (&inode->i_block)) - ((char *) buf);
+               size = sizeof(inode->i_block);
+               break;
+       case 'x':
+       case 'e':
+               if (size <= EXT2_GOOD_OLD_INODE_SIZE) {
+                       com_err(argv[0], 0, "No extra space in inode");
+                       goto err;
+               }
+               offset = EXT2_GOOD_OLD_INODE_SIZE + inode->i_extra_isize;
+               if (offset > size)
+                       goto err;
+               size -= offset;
+               break;
+       }
+       if (mode == 'x')
+               raw_inode_xattr_dump(stdout, buf + offset, size);
+       else
+               do_byte_hexdump(stdout, buf + offset, size);
 err:
        ext2fs_free_mem(&buf);
 }
@@ -2357,8 +2396,6 @@ 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)),