Whamcloud - gitweb
debugfs: fix header checks in logdump
[tools/e2fsprogs.git] / debugfs / debugfs.c
index 2022f3d..b67a88b 100644 (file)
@@ -231,7 +231,8 @@ void do_open_filesys(int argc, char **argv, int sci_idx EXT2FS_ATTR((unused)),
        int     catastrophic = 0;
        blk64_t superblock = 0;
        blk64_t blocksize = 0;
-       int     open_flags = EXT2_FLAG_SOFTSUPP_FEATURES | EXT2_FLAG_64BITS; 
+       int     open_flags = EXT2_FLAG_SOFTSUPP_FEATURES | EXT2_FLAG_64BITS |
+               EXT2_FLAG_THREADS;
        char    *data_filename = 0;
        char    *undo_file = NULL;
 
@@ -276,7 +277,11 @@ void do_open_filesys(int argc, char **argv, int sci_idx EXT2FS_ATTR((unused)),
                                return;
                        break;
                case 'z':
+#ifdef READ_ONLY
+                       goto print_usage;
+#else
                        undo_file = optarg;
+#endif
                        break;
                default:
                        goto print_usage;
@@ -294,9 +299,10 @@ void do_open_filesys(int argc, char **argv, int sci_idx EXT2FS_ATTR((unused)),
 
 print_usage:
        fprintf(stderr, "%s: Usage: open [-s superblock] [-b blocksize] "
+#ifdef READ_ONLY
                "[-d image_filename] [-z undo_file] [-c] [-i] [-f] [-e] [-D] "
-#ifndef READ_ONLY
-               "[-w] "
+#else
+               "[-d image_filename] [-c] [-i] [-f] [-e] [-D] [-w] "
 #endif
                "<device>\n", argv[0]);
 }
@@ -487,11 +493,12 @@ void do_show_super_stats(int argc, char *argv[],
                        "inode table at %llu\n"
                        "           %u free %s%s, "
                        "%u free %s, "
-                       "%u used %s%s",
-                       i, ext2fs_block_bitmap_loc(current_fs, i),
-                       ext2fs_inode_bitmap_loc(current_fs, i),
-                       ext2fs_inode_table_loc(current_fs, i),
-                       ext2fs_bg_free_blocks_count(current_fs, i), units,
+                       "%u used %s%s", i,
+                       (unsigned long long) ext2fs_block_bitmap_loc(current_fs, i),
+                       (unsigned long long) ext2fs_inode_bitmap_loc(current_fs, i),
+                       (unsigned long long) ext2fs_inode_table_loc(current_fs, i),
+                       ext2fs_bg_free_blocks_count(current_fs, i),
+                       units,
                        ext2fs_bg_free_blocks_count(current_fs, i) != 1 ?
                        "s" : "",
                        ext2fs_bg_free_inodes_count(current_fs, i),
@@ -561,11 +568,13 @@ static void finish_range(struct list_blocks_struct *lb)
                fprintf(lb->f, ", ");
        if (lb->first_block == lb->last_block)
                fprintf(lb->f, "(%lld):%llu",
-                       (long long)lb->first_bcnt, lb->first_block);
+                       (long long)lb->first_bcnt,
+                       (unsigned long long) lb->first_block);
        else
                fprintf(lb->f, "(%lld-%lld):%llu-%llu",
                        (long long)lb->first_bcnt, (long long)lb->last_bcnt,
-                       lb->first_block, lb->last_block);
+                       (unsigned long long) lb->first_block,
+                       (unsigned long long) lb->last_block);
        lb->first_block = 0;
 }
 
@@ -715,18 +724,18 @@ static void dump_extents(FILE *f, const char *prefix, ext2_ino_t ino,
                                        info.curr_level, info.max_depth,
                                        info.curr_entry, info.num_entries,
                                        logical_width,
-                                       extent.e_lblk,
+                                       (unsigned long long) extent.e_lblk,
                                        logical_width,
-                                       extent.e_lblk + (extent.e_len - 1),
+                                       (unsigned long long) extent.e_lblk + (extent.e_len - 1),
                                        physical_width,
-                                       extent.e_pblk,
+                                       (unsigned long long) extent.e_pblk,
                                        physical_width+3, "", extent.e_len);
                                continue;
                        }
 
                        fprintf(f, "%s(ETB%d):%llu",
                                printed ? ", " : "", info.curr_level,
-                               extent.e_pblk);
+                               (unsigned long long) extent.e_pblk);
                        printed = 1;
                        continue;
                }
@@ -737,13 +746,13 @@ static void dump_extents(FILE *f, const char *prefix, ext2_ino_t ino,
                                info.curr_level, info.max_depth,
                                info.curr_entry, info.num_entries,
                                logical_width,
-                               extent.e_lblk,
+                               (unsigned long long) extent.e_lblk,
                                logical_width,
-                               extent.e_lblk + (extent.e_len - 1),
+                               (unsigned long long) extent.e_lblk + (extent.e_len - 1),
                                physical_width,
-                               extent.e_pblk,
+                               (unsigned long long) extent.e_pblk,
                                physical_width,
-                               extent.e_pblk + (extent.e_len - 1),
+                               (unsigned long long) extent.e_pblk + (extent.e_len - 1),
                                extent.e_len,
                                extent.e_flags & EXT2_EXTENT_FLAGS_UNINIT ?
                                        "Uninit" : "");
@@ -756,20 +765,20 @@ static void dump_extents(FILE *f, const char *prefix, ext2_ino_t ino,
                        fprintf(f,
                                "%s(%lld%s):%lld",
                                printed ? ", " : "",
-                               extent.e_lblk,
+                               (unsigned long long) extent.e_lblk,
                                extent.e_flags & EXT2_EXTENT_FLAGS_UNINIT ?
                                "[u]" : "",
-                               extent.e_pblk);
+                               (unsigned long long) extent.e_pblk);
                else
                        fprintf(f,
                                "%s(%lld-%lld%s):%lld-%lld",
                                printed ? ", " : "",
-                               extent.e_lblk,
-                               extent.e_lblk + (extent.e_len - 1),
+                               (unsigned long long) extent.e_lblk,
+                               (unsigned long long) extent.e_lblk + (extent.e_len - 1),
                                extent.e_flags & EXT2_EXTENT_FLAGS_UNINIT ?
                                        "[u]" : "",
-                               extent.e_pblk,
-                               extent.e_pblk + (extent.e_len - 1));
+                               (unsigned long long) extent.e_pblk,
+                               (unsigned long long) extent.e_pblk + (extent.e_len - 1));
                printed = 1;
        }
        if (printed)
@@ -855,7 +864,7 @@ void internal_dump_inode(FILE *out, const char *prefix,
                fprintf(out, "   Project: %5d", large_inode->i_projid);
        fputs("   Size: ", out);
        if (LINUX_S_ISREG(inode->i_mode) || LINUX_S_ISDIR(inode->i_mode))
-               fprintf(out, "%llu\n", EXT2_I_SIZE(inode));
+               fprintf(out, "%llu\n", (unsigned long long) EXT2_I_SIZE(inode));
        else
                fprintf(out, "%u\n", inode->i_size);
        if (os == EXT2_OS_HURD)
@@ -1079,7 +1088,7 @@ static int print_blocks_proc(ext2_filsys fs EXT2FS_ATTR((unused)),
                             int ref_offset EXT2FS_ATTR((unused)),
                             void *private EXT2FS_ATTR((unused)))
 {
-       printf("%llu ", *blocknr);
+       printf("%llu ", (unsigned long long) *blocknr);
        return 0;
 }
 
@@ -1226,7 +1235,7 @@ void do_freeb(int argc, char *argv[], int sci_idx EXT2FS_ATTR((unused)),
        while (count-- > 0) {
                if (!ext2fs_test_block_bitmap2(current_fs->block_map,block))
                        com_err(argv[0], 0, "Warning: block %llu already clear",
-                               block);
+                               (unsigned long long) block);
                ext2fs_unmark_block_bitmap2(current_fs->block_map,block);
                block++;
        }
@@ -1246,7 +1255,7 @@ void do_setb(int argc, char *argv[], int sci_idx EXT2FS_ATTR((unused)),
        while (count-- > 0) {
                if (ext2fs_test_block_bitmap2(current_fs->block_map,block))
                        com_err(argv[0], 0, "Warning: block %llu already set",
-                               block);
+                               (unsigned long long) block);
                ext2fs_mark_block_bitmap2(current_fs->block_map,block);
                block++;
        }
@@ -1264,9 +1273,11 @@ void do_testb(int argc, char *argv[], int sci_idx EXT2FS_ATTR((unused)),
                return;
        while (count-- > 0) {
                if (ext2fs_test_block_bitmap2(current_fs->block_map,block))
-                       printf("Block %llu marked in use\n", block);
+                       printf("Block %llu marked in use\n",
+                              (unsigned long long) block);
                else
-                       printf("Block %llu not in use\n", block);
+                       printf("Block %llu not in use\n",
+                              (unsigned long long) block);
                block++;
        }
 }
@@ -1702,7 +1713,7 @@ void do_find_free_block(int argc, char *argv[],
                        com_err("ext2fs_new_block", retval, 0);
                        return;
                } else
-                       printf("%llu ", free_blk);
+                       printf("%llu ", (unsigned long long) free_blk);
        }
        printf("\n");
 }
@@ -2104,10 +2115,11 @@ void do_bmap(int argc, char *argv[], int sci_idx EXT2FS_ATTR((unused)),
                               &ret_flags, &pblk);
        if (errcode) {
                com_err(argv[0], errcode,
-                       "while mapping logical block %llu\n", blk);
+                       "while mapping logical block %llu\n",
+                       (unsigned long long) blk);
                return;
        }
-       printf("%llu", pblk);
+       printf("%llu", (unsigned long long) pblk);
        if (ret_flags & BMAP_RET_UNINIT)
                fputs(" (uninit)", stdout);
        fputc('\n', stdout);
@@ -2379,7 +2391,6 @@ void do_fallocate(int argc, char *argv[], int sci_idx EXT2FS_ATTR((unused)),
                return;
        }
 }
-#endif /* READ_ONLY */
 
 void do_symlink(int argc, char *argv[], int sci_idx EXT2FS_ATTR((unused)),
                void *infop EXT2FS_ATTR((unused)))
@@ -2395,6 +2406,7 @@ void do_symlink(int argc, char *argv[], int sci_idx EXT2FS_ATTR((unused)),
                com_err(argv[0], retval, 0);
 
 }
+#endif /* READ_ONLY */
 
 #if CONFIG_MMP
 void do_dump_mmp(int argc EXT2FS_ATTR((unused)), char *argv[],
@@ -2441,17 +2453,19 @@ void do_dump_mmp(int argc EXT2FS_ATTR((unused)), char *argv[],
        retval = ext2fs_mmp_read(current_fs, mmp_block, current_fs->mmp_buf);
        if (retval) {
                com_err(argv[0], retval, "reading MMP block %llu.\n",
-                       mmp_block);
+                       (unsigned long long) mmp_block);
                return;
        }
 
        t = mmp_s->mmp_time;
-       fprintf(stdout, "block_number: %llu\n", current_fs->super->s_mmp_block);
+       fprintf(stdout, "block_number: %llu\n",
+               (unsigned long long) current_fs->super->s_mmp_block);
        fprintf(stdout, "update_interval: %d\n",
                current_fs->super->s_mmp_update_interval);
        fprintf(stdout, "check_interval: %d\n", mmp_s->mmp_check_interval);
        fprintf(stdout, "sequence: %08x\n", mmp_s->mmp_seq);
-       fprintf(stdout, "time: %lld -- %s", mmp_s->mmp_time, ctime(&t));
+       fprintf(stdout, "time: %llu -- %s",
+               (unsigned long long) mmp_s->mmp_time, ctime(&t));
        fprintf(stdout, "node_name: %.*s\n",
                EXT2_LEN_STR(mmp_s->mmp_nodename));
        fprintf(stdout, "device_name: %.*s\n",
@@ -2527,7 +2541,8 @@ int main(int argc, char **argv)
 #endif
                "[-c]] [device]";
        int             c;
-       int             open_flags = EXT2_FLAG_SOFTSUPP_FEATURES | EXT2_FLAG_64BITS;
+       int             open_flags = EXT2_FLAG_SOFTSUPP_FEATURES |
+                               EXT2_FLAG_64BITS | EXT2_FLAG_THREADS;
        char            *request = 0;
        int             exit_status = 0;
        char            *cmd_file = 0;
@@ -2539,8 +2554,8 @@ int main(int argc, char **argv)
        const char      *opt_string = "nicR:f:b:s:Vd:D";
 #else
        const char      *opt_string = "niwcR:f:b:s:Vd:Dz:";
-       char            *undo_file = NULL;
 #endif
+       char            *undo_file = NULL;
 #ifdef CONFIG_JBD_DEBUG
        char            *jbd_debug;
 #endif
@@ -2612,9 +2627,11 @@ int main(int argc, char **argv)
                        fprintf(stderr, "\tUsing %s\n",
                                error_message(EXT2_ET_BASE));
                        exit(0);
+#ifndef READ_ONLY
                case 'z':
                        undo_file = optarg;
                        break;
+#endif
                default:
                        com_err(argv[0], 0, usage, debug_prog_name);
                        return 1;