void make_journal_device(char *journal_device, ext2_filsys fs, int quiet, int force) { errcode_t retval; ext2_filsys jfs; io_manager io_ptr; check_plausibility(journal_device, force); check_mount(journal_device, force, "journal"); io_ptr = unix_io_manager; retval = ext2fs_open(journal_device, EXT2_FLAG_RW| EXT2_FLAG_JOURNAL_DEV_OK, 0, fs->blocksize, io_ptr, &jfs); if (retval) bb_error_msg_and_die("can't journal device %s", journal_device); if (!quiet) printf("Adding journal to device %s: ", journal_device); fflush(stdout); retval = ext2fs_add_journal_device(fs, jfs); if (retval) bb_error_msg_and_die("\nFailed to add journal to device %s", journal_device); if (!quiet) puts("done"); ext2fs_close(jfs); }
int main (int argc, char ** argv) { errcode_t retval; ext2_filsys fs; int print_badblocks = 0; blk64_t use_superblock = 0; int use_blocksize = 0; int image_dump = 0; int force = 0; int flags; int header_only = 0; int c; int grp_only = 0; #ifdef ENABLE_NLS setlocale(LC_MESSAGES, ""); setlocale(LC_CTYPE, ""); bindtextdomain(NLS_CAT_NAME, LOCALEDIR); textdomain(NLS_CAT_NAME); set_com_err_gettext(gettext); #endif add_error_table(&et_ext2_error_table); fprintf (stderr, "dumpe2fs %s (%s)\n", E2FSPROGS_VERSION, E2FSPROGS_DATE); if (argc && *argv) program_name = *argv; while ((c = getopt(argc, argv, "bfghixVo:")) != EOF) { switch (c) { case 'b': print_badblocks++; break; case 'f': force++; break; case 'g': grp_only++; break; case 'h': header_only++; break; case 'i': image_dump++; break; case 'o': parse_extended_opts(optarg, &use_superblock, &use_blocksize); break; case 'V': /* Print version number and exit */ fprintf(stderr, _("\tUsing %s\n"), error_message(EXT2_ET_BASE)); exit(0); case 'x': hex_format++; break; default: usage(); } } if (optind != argc - 1) { usage(); exit(1); } device_name = argv[optind++]; flags = EXT2_FLAG_JOURNAL_DEV_OK | EXT2_FLAG_SOFTSUPP_FEATURES | EXT2_FLAG_64BITS; if (force) flags |= EXT2_FLAG_FORCE; if (image_dump) flags |= EXT2_FLAG_IMAGE_FILE; try_open_again: if (use_superblock && !use_blocksize) { for (use_blocksize = EXT2_MIN_BLOCK_SIZE; use_blocksize <= EXT2_MAX_BLOCK_SIZE; use_blocksize *= 2) { retval = ext2fs_open (device_name, flags, use_superblock, use_blocksize, unix_io_manager, &fs); if (!retval) break; } } else retval = ext2fs_open (device_name, flags, use_superblock, use_blocksize, unix_io_manager, &fs); if (retval && !(flags & EXT2_FLAG_IGNORE_CSUM_ERRORS)) { flags |= EXT2_FLAG_IGNORE_CSUM_ERRORS; goto try_open_again; } if (!retval && (fs->flags & EXT2_FLAG_IGNORE_CSUM_ERRORS)) printf("%s", _("\n*** Checksum errors detected in filesystem! Run e2fsck now!\n\n")); flags |= EXT2_FLAG_IGNORE_CSUM_ERRORS; if (retval) { com_err (program_name, retval, _("while trying to open %s"), device_name); printf("%s", _("Couldn't find valid filesystem superblock.\n")); if (retval == EXT2_ET_BAD_MAGIC) check_plausibility(device_name, CHECK_FS_EXIST, NULL); exit (1); } fs->default_bitmap_type = EXT2FS_BMAP64_RBTREE; if (fs->super->s_feature_incompat & EXT4_FEATURE_INCOMPAT_64BIT) blocks64 = 1; if (print_badblocks) { list_bad_blocks(fs, 1); } else { if (grp_only) goto just_descriptors; list_super (fs->super); if (fs->super->s_feature_incompat & EXT3_FEATURE_INCOMPAT_JOURNAL_DEV) { print_journal_information(fs); ext2fs_close_free(&fs); exit(0); } if ((fs->super->s_feature_compat & EXT3_FEATURE_COMPAT_HAS_JOURNAL) && (fs->super->s_journal_inum != 0)) print_inline_journal_information(fs); list_bad_blocks(fs, 0); if (header_only) { ext2fs_close_free(&fs); exit (0); } fs->flags &= ~EXT2_FLAG_IGNORE_CSUM_ERRORS; try_bitmaps_again: retval = ext2fs_read_bitmaps (fs); if (retval && !(fs->flags & EXT2_FLAG_IGNORE_CSUM_ERRORS)) { fs->flags |= EXT2_FLAG_IGNORE_CSUM_ERRORS; goto try_bitmaps_again; } if (!retval && (fs->flags & EXT2_FLAG_IGNORE_CSUM_ERRORS)) printf("%s", _("\n*** Checksum errors detected in bitmaps! Run e2fsck now!\n\n")); just_descriptors: list_desc(fs, grp_only); if (retval) { printf(_("\n%s: %s: error reading bitmaps: %s\n"), program_name, device_name, error_message(retval)); } } ext2fs_close_free(&fs); remove_error_table(&et_ext2_error_table); exit (0); }