Lines Matching refs:ctx
77 static void usage(e2fsck_t ctx)
84 ctx->program_name);
104 static void show_stats(e2fsck_t ctx)
106 ext2_filsys fs = ctx->fs;
114 dir_links = 2 * ctx->fs_directory_count - 1;
115 num_files = ctx->fs_total_count - dir_links;
116 num_links = ctx->fs_links_count - dir_links;
124 frag_percent_file = (10000 * ctx->fs_fragmented) / inodes_used;
127 frag_percent_dir = (10000 * ctx->fs_fragmented_dir) / inodes_used;
130 frag_percent_total = ((10000 * (ctx->fs_fragmented +
131 ctx->fs_fragmented_dir))
137 ctx->device_name, inodes_used, inodes,
146 ctx->fs_fragmented),
147 ctx->fs_fragmented, frag_percent_file / 10,
151 ctx->fs_fragmented_dir),
152 ctx->fs_fragmented_dir, frag_percent_dir / 10,
155 ctx->fs_ind_count, ctx->fs_dind_count, ctx->fs_tind_count);
158 if (ctx->extent_depth_count[j])
165 printf("%u", ctx->extent_depth_count[i]);
173 ctx->fs_badblocks_count), ctx->fs_badblocks_count);
175 ctx->large_files), ctx->large_files);
177 ctx->fs_regular_count), ctx->fs_regular_count);
179 ctx->fs_directory_count), ctx->fs_directory_count);
181 "%8u character device files\n", ctx->fs_chardev_count),
182 ctx->fs_chardev_count);
184 ctx->fs_blockdev_count), ctx->fs_blockdev_count);
185 printf (P_("%8u fifo\n", "%8u fifos\n", ctx->fs_fifo_count),
186 ctx->fs_fifo_count);
188 ctx->fs_links_count - dir_links),
189 ctx->fs_links_count - dir_links);
191 ctx->fs_symlinks_count), ctx->fs_symlinks_count);
193 ctx->fs_fast_symlinks_count), ctx->fs_fast_symlinks_count);
194 printf (P_("%8u socket\n", "%8u sockets\n", ctx->fs_sockets_count),
195 ctx->fs_sockets_count);
198 ctx->fs_total_count - dir_links),
199 ctx->fs_total_count - dir_links);
202 static void check_mount(e2fsck_t ctx)
207 retval = ext2fs_check_if_mounted(ctx->filesystem_name,
208 &ctx->mount_flags);
212 ctx->filesystem_name);
221 if ((!(ctx->mount_flags & EXT2_MF_MOUNTED)) ||
222 ((ctx->mount_flags & EXT2_MF_ISROOT) &&
223 (ctx->mount_flags & EXT2_MF_READONLY) &&
224 !(ctx->options & E2F_OPT_WRITECHECK)))
227 if ((ctx->options & E2F_OPT_READONLY) &&
228 !(ctx->options & E2F_OPT_WRITECHECK)) {
229 printf(_("Warning! %s is mounted.\n"), ctx->filesystem_name);
233 printf(_("%s is mounted. "), ctx->filesystem_name);
234 if (!ctx->interactive)
235 fatal_error(ctx, _("Cannot continue, aborting.\n\n"));
290 static void check_if_skip(e2fsck_t ctx)
292 ext2_filsys fs = ctx->fs;
301 profile_get_boolean(ctx->profile, "options", "broken_system_clock",
303 if (ctx->flags & E2F_FLAG_TIME_INSANE)
305 profile_get_boolean(ctx->profile, "options",
311 if ((ctx->options & E2F_OPT_FORCE) || bad_blocks_file || cflag)
314 if (ctx->options & E2F_OPT_JOURNAL_ONLY)
318 if (lastcheck > ctx->now)
319 lastcheck -= ctx->time_fudge;
325 else if (check_backup_super_block(ctx))
336 (ctx->now < lastcheck)) {
341 ((ctx->now - lastcheck) >=
344 reason_arg = (ctx->now - fs->super->s_lastcheck)/(3600*24);
345 if (batt && ((ctx->now - fs->super->s_lastcheck) <
350 fputs(ctx->device_name, stdout);
355 printf(_("%s: clean, %u/%u files, %u/%u blocks"), ctx->device_name,
367 ((ctx->now - fs->super->s_lastcheck) >= fs->super->s_checkinterval))
382 ctx->fs = NULL;
383 e2fsck_free_context(ctx);
413 extern void e2fsck_clear_progbar(e2fsck_t ctx)
415 if (!(ctx->flags & E2F_FLAG_PROG_BAR))
418 printf("%s%s\r%s", ctx->start_meta, spaces + (sizeof(spaces) - 80),
419 ctx->stop_meta);
421 ctx->flags &= ~E2F_FLAG_PROG_BAR;
424 int e2fsck_simple_progress(e2fsck_t ctx, const char *label, float percent,
434 if (ctx->flags & E2F_FLAG_PROG_SUPPRESS)
443 if (ctx->progress_last_percent == fixed_percent)
445 ctx->progress_last_percent = fixed_percent;
454 if ((tick == ctx->progress_last_time) &&
457 ctx->progress_last_time = tick;
463 ctx->progress_pos = (ctx->progress_pos+1) & 3;
464 ctx->flags |= E2F_FLAG_PROG_BAR;
472 printf("%s%s: |%s%s", ctx->start_meta, label,
478 fputc(spinner[ctx->progress_pos & 3], stdout);
484 fputs(ctx->stop_meta, stdout);
487 e2fsck_clear_progbar(ctx);
493 static int e2fsck_update_progress(e2fsck_t ctx, int pass,
502 if (ctx->progress_fd) {
504 pass, cur, max, ctx->device_name);
505 write_all(ctx->progress_fd, buf, strlen(buf));
508 e2fsck_simple_progress(ctx, ctx->device_name,
537 e2fsck_t ctx = e2fsck_global_ctx;
539 if (!ctx)
542 ctx->progress = e2fsck_update_progress;
547 e2fsck_t ctx = e2fsck_global_ctx;
549 if (!ctx)
552 e2fsck_clear_progbar(ctx);
553 ctx->progress = 0;
558 e2fsck_t ctx = e2fsck_global_ctx;
560 if (!ctx)
563 ctx->flags |= E2F_FLAG_CANCEL;
567 static void parse_extended_opts(e2fsck_t ctx, const char *opts)
573 buf = string_copy(ctx, opts, 0);
599 ctx->ext_attr_ver = ea_ver;
601 ctx->options |= E2F_OPT_FRAGCHECK;
608 ctx->options |= E2F_OPT_JOURNAL_ONLY;
647 e2fsck_t ctx;
659 retval = e2fsck_allocate_context(&ctx);
663 *ret_ctx = ctx;
668 ctx->interactive = 1;
670 ctx->start_meta[0] = '\001';
671 ctx->stop_meta[0] = '\002';
677 blkid_get_cache(&ctx->blkid, NULL);
680 ctx->program_name = *argv;
682 ctx->program_name = "e2fsck";
686 ctx->progress = e2fsck_update_progress;
687 res = sscanf(optarg, "%d", &ctx->progress_fd);
691 if (ctx->progress_fd < 0) {
692 ctx->progress = 0;
693 ctx->progress_fd = ctx->progress_fd * -1;
695 if (!ctx->progress_fd)
698 fd = dup(ctx->progress_fd);
702 ctx->progress_fd,
704 fatal_error(ctx,
710 ctx->options |= E2F_OPT_COMPRESS_DIRS;
717 if (ctx->options & (E2F_OPT_YES|E2F_OPT_NO)) {
719 fatal_error(ctx,
722 ctx->options |= E2F_OPT_PREEN;
725 if (ctx->options & (E2F_OPT_YES|E2F_OPT_PREEN))
727 ctx->options |= E2F_OPT_NO;
730 if (ctx->options & (E2F_OPT_PREEN|E2F_OPT_NO))
732 ctx->options |= E2F_OPT_YES;
736 if (ctx->options & E2F_OPT_TIME)
737 ctx->options |= E2F_OPT_TIME2;
739 ctx->options |= E2F_OPT_TIME;
747 ctx->options |= E2F_OPT_WRITECHECK;
748 ctx->options |= E2F_OPT_CHECKBLOCKS;
754 res = sscanf(optarg, "%u", &ctx->use_superblock);
757 ctx->flags |= E2F_FLAG_SB_SPECIFIED;
760 ctx->blocksize = atoi(optarg);
763 res = sscanf(optarg, "%d", &ctx->inode_buffer_blocks);
768 ctx->journal_name = blkid_get_devname(ctx->blkid,
770 if (!ctx->journal_name) {
771 com_err(ctx->program_name, 0,
774 fatal_error(ctx, 0);
778 res = sscanf(optarg, "%d", &ctx->process_inode_size);
785 bad_blocks_file = string_copy(ctx, optarg, 0);
788 ctx->options |= E2F_OPT_DEBUG;
791 ctx->options |= E2F_OPT_FORCE;
808 ctx->device_name = string_copy(ctx, optarg, 0);
814 usage(ctx);
819 usage(ctx);
820 if ((ctx->options & E2F_OPT_NO) &&
821 (ctx->options & E2F_OPT_COMPRESS_DIRS)) {
822 com_err(ctx->program_name, 0,
824 fatal_error(ctx, 0);
826 if ((ctx->options & E2F_OPT_NO) && cflag) {
827 com_err(ctx->program_name, 0,
829 fatal_error(ctx, 0);
831 if ((ctx->options & E2F_OPT_NO) && bad_blocks_file) {
832 com_err(ctx->program_name, 0,
834 fatal_error(ctx, 0);
836 if (ctx->options & E2F_OPT_NO)
837 ctx->options |= E2F_OPT_READONLY;
839 ctx->io_options = strchr(argv[optind], '?');
840 if (ctx->io_options)
841 *ctx->io_options++ = 0;
842 ctx->filesystem_name = blkid_get_devname(ctx->blkid, argv[optind], 0);
843 if (!ctx->filesystem_name) {
844 com_err(ctx->program_name, 0, _("Unable to resolve '%s'"),
846 fatal_error(ctx, 0);
849 parse_extended_opts(ctx, extended_opts);
854 profile_init(config_fn, &ctx->profile);
857 fd = open(ctx->filesystem_name, O_RDONLY, 0);
861 ctx->filesystem_name);
862 fatal_error(ctx, 0);
867 ctx->filesystem_name);
868 fatal_error(ctx, 0);
888 e2fsck_global_ctx = ctx;
906 fatal_error(ctx, "Couldn't malloc() newpath");
935 static errcode_t try_open_fs(e2fsck_t ctx, int flags, io_manager io_ptr,
941 if (ctx->superblock && ctx->blocksize) {
942 retval = ext2fs_open2(ctx->filesystem_name, ctx->io_options,
943 flags, ctx->superblock, ctx->blocksize,
945 } else if (ctx->superblock) {
953 retval = ext2fs_open2(ctx->filesystem_name,
954 ctx->io_options, flags,
955 ctx->superblock, blocksize,
961 retval = ext2fs_open2(ctx->filesystem_name, ctx->io_options,
979 e2fsck_t ctx;
1009 retval = PRS(argc, argv, &ctx);
1017 init_resource_track(&ctx->global_rtrack, NULL);
1018 if (!(ctx->options & E2F_OPT_PREEN) || show_version_only)
1028 check_mount(ctx);
1030 if (!(ctx->options & E2F_OPT_PREEN) &&
1031 !(ctx->options & E2F_OPT_NO) &&
1032 !(ctx->options & E2F_OPT_YES)) {
1033 if (!ctx->interactive)
1034 fatal_error(ctx,
1037 ctx->superblock = ctx->use_superblock;
1047 if ((ctx->options & E2F_OPT_READONLY) == 0)
1049 if ((ctx->mount_flags & EXT2_MF_MOUNTED) == 0)
1052 retval = try_open_fs(ctx, flags, io_ptr, &fs);
1054 if (!ctx->superblock && !(ctx->options & E2F_OPT_PREEN) &&
1055 !(ctx->flags & E2F_FLAG_SB_SPECIFIED) &&
1069 ctx->program_name,
1072 orig_superblock = ctx->superblock;
1073 get_backup_sb(ctx, fs, ctx->filesystem_name, io_ptr);
1077 retval = try_open_fs(ctx, flags, io_ptr, &fs);
1081 com_err(ctx->program_name, retval,
1084 "superblock\n"), ctx->program_name);
1085 ctx->superblock = orig_superblock;
1086 retval = try_open_fs(ctx, flags, io_ptr, &fs);
1107 com_err(ctx->program_name, retval, _("while trying to open %s"),
1108 ctx->filesystem_name);
1114 fix_problem(ctx, PR_0_SB_CORRUPT, &pctx);
1120 (ctx->options & E2F_OPT_READONLY) ?
1136 fix_problem(ctx, PR_0_SB_CORRUPT, &pctx);
1137 fatal_error(ctx, 0);
1152 if (!(ctx->flags & E2F_FLAG_GOT_DEVSIZE)) {
1156 pctx.errcode = ext2fs_get_device_size2(ctx->filesystem_name,
1158 &ctx->num_blocks);
1170 ext2fs_get_device_size2(ctx->filesystem_name,
1172 &ctx->num_blocks);
1175 ctx->num_blocks = 0;
1177 fix_problem(ctx, PR_0_GETSIZE_ERROR, &pctx);
1178 ctx->flags |= E2F_FLAG_ABORT;
1179 fatal_error(ctx, 0);
1181 ctx->flags |= E2F_FLAG_GOT_DEVSIZE;
1186 ctx->fs = fs;
1187 fs->priv_data = ctx;
1188 fs->now = ctx->now;
1191 com_err(ctx->program_name, EXT2_ET_REV_TOO_HIGH,
1193 ctx->filesystem_name);
1195 fatal_error(ctx, _("Get a newer version of e2fsck!"));
1202 if (ctx->device_name == 0 &&
1204 ctx->device_name = string_copy(ctx, sb->s_volume_name,
1207 if (ctx->device_name == 0)
1208 ctx->device_name = string_copy(ctx, ctx->filesystem_name, 0);
1209 for (cp = ctx->device_name; *cp; cp++)
1215 if ((ctx->mount_flags & EXT2_MF_MOUNTED) &&
1222 retval = e2fsck_check_ext3_journal(ctx);
1224 com_err(ctx->program_name, retval,
1226 ctx->device_name);
1227 fatal_error(ctx, 0);
1235 if (ctx->options & E2F_OPT_READONLY) {
1239 io_channel_flush(ctx->fs->io);
1241 if (ctx->flags & E2F_FLAG_RESTARTED) {
1248 com_err(ctx->program_name, 0,
1249 _("unable to set superblock flags on %s\n"), ctx->device_name);
1250 fatal_error(ctx, 0);
1252 retval = e2fsck_run_ext3_journal(ctx);
1254 com_err(ctx->program_name, retval,
1256 ctx->device_name);
1257 fatal_error(ctx, 0);
1259 ext2fs_close(ctx->fs);
1260 ctx->fs = 0;
1261 ctx->flags |= E2F_FLAG_RESTARTED;
1281 ctx->filesystem_name);
1295 com_err(ctx->program_name, 0,
1300 com_err(ctx->program_name, 0,
1303 ctx->device_name);
1313 if (ctx->superblock &&
1314 !(ctx->options & E2F_OPT_READONLY))
1327 ctx->blocks_per_page = sys_page_size / fs->blocksize;
1328 if (ctx->blocks_per_page == 0)
1329 ctx->blocks_per_page = 1;
1331 if (ctx->superblock)
1334 check_super_block(ctx);
1335 if (ctx->flags & E2F_FLAG_SIGNAL_MASK)
1336 fatal_error(ctx, 0);
1337 check_if_skip(ctx);
1338 check_resize_inode(ctx);
1340 read_bad_blocks_file(ctx, bad_blocks_file, replace_bad_blocks);
1342 read_bad_blocks_file(ctx, 0, !keep_bad_blocks); /* Test disk */
1343 if (ctx->flags & E2F_FLAG_SIGNAL_MASK)
1344 fatal_error(ctx, 0);
1353 com_err(ctx->program_name, retval,
1355 preenhalt(ctx);
1370 run_result = e2fsck_run(ctx);
1371 e2fsck_clear_progbar(ctx);
1373 if (ctx->flags & E2F_FLAG_JOURNAL_INODE) {
1374 if (fix_problem(ctx, PR_6_RECREATE_JOURNAL, &pctx)) {
1381 com_err(ctx->program_name, 0,
1404 retval = e2fsck_reset_context(ctx);
1406 com_err(ctx->program_name, retval,
1408 fatal_error(ctx, 0);
1414 printf(_("%s: e2fsck canceled.\n"), ctx->device_name ?
1415 ctx->device_name : ctx->filesystem_name);
1419 fatal_error(ctx, _("aborted"));
1420 if (check_backup_super_block(ctx)) {
1430 if (!(ctx->options & E2F_OPT_PREEN))
1432 ctx->device_name);
1433 if (ctx->mount_flags & EXT2_MF_ISROOT) {
1435 ctx->device_name);
1443 "errors **********\n\n"), ctx->device_name);
1450 profile_get_boolean(ctx->profile, "options",
1459 show_stats(ctx);
1460 if (!(ctx->options & E2F_OPT_READONLY)) {
1468 if (!(ctx->flags & E2F_FLAG_TIME_INSANE))
1469 sb->s_lastcheck = ctx->now;
1478 !(ctx->options & E2F_OPT_READONLY)) {
1479 retval = ext2fs_set_gdt_csum(ctx->fs);
1481 com_err(ctx->program_name, retval,
1483 fatal_error(ctx, 0);
1487 e2fsck_write_bitmaps(ctx);
1488 io_channel_flush(ctx->fs->io);
1489 print_resource_track(ctx, NULL, &ctx->global_rtrack, ctx->fs->io);
1492 ctx->fs = NULL;
1493 free(ctx->journal_name);
1495 e2fsck_free_context(ctx);