Lines Matching refs:ctx
75 static void usage(e2fsck_t ctx)
82 ctx->program_name);
102 static void show_stats(e2fsck_t ctx)
104 ext2_filsys fs = ctx->fs;
111 dir_links = 2 * ctx->fs_directory_count - 1;
112 num_files = ctx->fs_total_count - dir_links;
113 num_links = ctx->fs_links_count - dir_links;
121 frag_percent = (10000 * ctx->fs_fragmented) / inodes_used;
126 ctx->device_name, inodes_used, inodes,
135 ctx->fs_fragmented),
136 ctx->fs_fragmented, frag_percent / 10, frag_percent % 10);
138 ctx->fs_ind_count, ctx->fs_dind_count, ctx->fs_tind_count);
142 ctx->fs_badblocks_count), ctx->fs_badblocks_count);
144 ctx->large_files), ctx->large_files);
146 ctx->fs_regular_count), ctx->fs_regular_count);
148 ctx->fs_directory_count), ctx->fs_directory_count);
150 "%8u character device files\n", ctx->fs_chardev_count),
151 ctx->fs_chardev_count);
153 ctx->fs_blockdev_count), ctx->fs_blockdev_count);
154 printf (P_("%8u fifo\n", "%8u fifos\n", ctx->fs_fifo_count),
155 ctx->fs_fifo_count);
157 ctx->fs_links_count - dir_links),
158 ctx->fs_links_count - dir_links);
160 ctx->fs_symlinks_count), ctx->fs_symlinks_count);
162 ctx->fs_fast_symlinks_count), ctx->fs_fast_symlinks_count);
163 printf (P_("%8u socket\n", "%8u sockets\n", ctx->fs_sockets_count),
164 ctx->fs_sockets_count);
167 ctx->fs_total_count - dir_links),
168 ctx->fs_total_count - dir_links);
171 static void check_mount(e2fsck_t ctx)
176 retval = ext2fs_check_if_mounted(ctx->filesystem_name,
177 &ctx->mount_flags);
181 ctx->filesystem_name);
190 if ((!(ctx->mount_flags & EXT2_MF_MOUNTED)) ||
191 ((ctx->mount_flags & EXT2_MF_ISROOT) &&
192 (ctx->mount_flags & EXT2_MF_READONLY) &&
193 !(ctx->options & E2F_OPT_WRITECHECK)))
196 if ((ctx->options & E2F_OPT_READONLY) &&
197 !(ctx->options & E2F_OPT_WRITECHECK)) {
198 printf(_("Warning! %s is mounted.\n"), ctx->filesystem_name);
202 printf(_("%s is mounted. "), ctx->filesystem_name);
203 if (!ctx->interactive)
204 fatal_error(ctx, _("Cannot continue, aborting.\n\n"));
259 static void check_if_skip(e2fsck_t ctx)
261 ext2_filsys fs = ctx->fs;
269 profile_get_boolean(ctx->profile, "options",
275 if ((ctx->options & E2F_OPT_FORCE) || bad_blocks_file ||
280 if (lastcheck > ctx->now)
281 lastcheck -= ctx->time_fudge;
287 else if (check_backup_super_block(ctx))
298 ((ctx->now - lastcheck) >= fs->super->s_checkinterval)) {
300 reason_arg = (ctx->now - fs->super->s_lastcheck)/(3600*24);
301 if (batt && ((ctx->now - fs->super->s_lastcheck) <
306 fputs(ctx->device_name, stdout);
311 printf(_("%s: clean, %u/%u files, %u/%u blocks"), ctx->device_name,
323 ((ctx->now - fs->super->s_lastcheck) >= fs->super->s_checkinterval))
337 ctx->fs = NULL;
338 e2fsck_free_context(ctx);
368 extern void e2fsck_clear_progbar(e2fsck_t ctx)
370 if (!(ctx->flags & E2F_FLAG_PROG_BAR))
373 printf("%s%s\r%s", ctx->start_meta, spaces + (sizeof(spaces) - 80),
374 ctx->stop_meta);
376 ctx->flags &= ~E2F_FLAG_PROG_BAR;
379 int e2fsck_simple_progress(e2fsck_t ctx, const char *label, float percent,
389 if (ctx->flags & E2F_FLAG_PROG_SUPPRESS)
398 if (ctx->progress_last_percent == fixed_percent)
400 ctx->progress_last_percent = fixed_percent;
409 if ((tick == ctx->progress_last_time) &&
412 ctx->progress_last_time = tick;
418 ctx->progress_pos = (ctx->progress_pos+1) & 3;
419 ctx->flags |= E2F_FLAG_PROG_BAR;
427 printf("%s%s: |%s%s", ctx->start_meta, label,
433 fputc(spinner[ctx->progress_pos & 3], stdout);
439 fputs(ctx->stop_meta, stdout);
442 e2fsck_clear_progbar(ctx);
448 static int e2fsck_update_progress(e2fsck_t ctx, int pass,
457 if (ctx->progress_fd) {
459 write(ctx->progress_fd, buf, strlen(buf));
462 e2fsck_simple_progress(ctx, ctx->device_name,
491 e2fsck_t ctx = e2fsck_global_ctx;
493 if (!ctx)
496 ctx->progress = e2fsck_update_progress;
497 ctx->progress_fd = 0;
502 e2fsck_t ctx = e2fsck_global_ctx;
504 if (!ctx)
507 e2fsck_clear_progbar(ctx);
508 ctx->progress = 0;
513 e2fsck_t ctx = e2fsck_global_ctx;
515 if (!ctx)
518 ctx->flags |= E2F_FLAG_CANCEL;
522 static void parse_extended_opts(e2fsck_t ctx, const char *opts)
528 buf = string_copy(ctx, opts, 0);
554 ctx->ext_attr_ver = ea_ver;
590 e2fsck_t ctx;
602 retval = e2fsck_allocate_context(&ctx);
606 *ret_ctx = ctx;
611 ctx->interactive = 1;
613 ctx->start_meta[0] = '\001';
614 ctx->stop_meta[0] = '\002';
620 blkid_get_cache(&ctx->blkid, NULL);
623 ctx->program_name = *argv;
625 ctx->program_name = "e2fsck";
629 ctx
630 res = sscanf(optarg, "%d", &ctx->progress_fd);
634 if (!ctx->progress_fd)
637 fd = dup(ctx->progress_fd);
641 ctx->progress_fd,
643 fatal_error(ctx,
649 ctx->options |= E2F_OPT_COMPRESS_DIRS;
656 if (ctx->options & (E2F_OPT_YES|E2F_OPT_NO)) {
658 fatal_error(ctx,
661 ctx->options |= E2F_OPT_PREEN;
664 if (ctx->options & (E2F_OPT_YES|E2F_OPT_PREEN))
666 ctx->options |= E2F_OPT_NO;
669 if (ctx->options & (E2F_OPT_PREEN|E2F_OPT_NO))
671 ctx->options |= E2F_OPT_YES;
675 if (ctx->options & E2F_OPT_TIME)
676 ctx->options |= E2F_OPT_TIME2;
678 ctx->options |= E2F_OPT_TIME;
686 ctx->options |= E2F_OPT_WRITECHECK;
687 ctx->options |= E2F_OPT_CHECKBLOCKS;
693 res = sscanf(optarg, "%d", &ctx->use_superblock);
696 ctx->flags |= E2F_FLAG_SB_SPECIFIED;
699 ctx->blocksize = atoi(optarg);
702 res = sscanf(optarg, "%d", &ctx->inode_buffer_blocks);
707 ctx->journal_name = string_copy(ctx, optarg, 0);
710 res = sscanf(optarg, "%d", &ctx->process_inode_size);
717 bad_blocks_file = string_copy(ctx, optarg, 0);
720 ctx->options |= E2F_OPT_DEBUG;
723 ctx->options |= E2F_OPT_FORCE;
740 ctx->device_name = optarg;
760 usage(ctx);
765 usage(ctx);
766 if ((ctx->options & E2F_OPT_NO) && !bad_blocks_file &&
767 !cflag && !swapfs && !(ctx->options & E2F_OPT_COMPRESS_DIRS))
768 ctx->options |= E2F_OPT_READONLY;
769 ctx->io_options = strchr(argv[optind], '?');
770 if (ctx->io_options)
771 *ctx->io_options++ = 0;
772 ctx->filesystem_name = blkid_get_devname(ctx->blkid, argv[optind], 0);
773 if (!ctx->filesystem_name) {
774 com_err(ctx->program_name, 0, _("Unable to resolve '%s'"),
776 fatal_error(ctx, 0);
779 parse_extended_opts(ctx, extended_opts);
784 profile_init(config_fn, &ctx->profile);
787 fd = open(ctx->filesystem_name, O_RDONLY, 0);
791 ctx->filesystem_name);
792 fatal_error(ctx, 0);
797 ctx->filesystem_name);
798 fatal_error(ctx, 0);
827 e2fsck_global_ctx = ctx;
845 fatal_error(ctx, "Couldn't malloc() newpath");
886 e2fsck_t ctx;
914 retval = PRS(argc, argv, &ctx);
923 init_resource_track(&ctx->global_rtrack);
926 if (!(ctx->options & E2F_OPT_PREEN) || show_version_only)
936 check_mount(ctx);
938 if (!(ctx->options & E2F_OPT_PREEN) &&
939 !(ctx->options & E2F_OPT_NO) &&
940 !(ctx->options & E2F_OPT_YES)) {
941 if (!ctx->interactive)
942 fatal_error(ctx,
945 ctx->superblock = ctx->use_superblock;
954 if ((ctx->options & E2F_OPT_READONLY) == 0)
956 if ((ctx->mount_flags & EXT2_MF_MOUNTED) == 0)
959 if (ctx->superblock && ctx->blocksize) {
960 retval = ext2fs_open2(ctx->filesystem_name, ctx->io_options,
961 flags, ctx->superblock, ctx->blocksize,
963 } else if (ctx->superblock) {
967 retval = ext2fs_open2(ctx->filesystem_name,
968 ctx->io_options, flags,
969 ctx->superblock, blocksize,
975 retval = ext2fs_open2(ctx->filesystem_name, ctx->io_options,
977 if (!ctx->superblock && !(ctx->options & E2F_OPT_PREEN) &&
978 !(ctx->flags & E2F_FLAG_SB_SPECIFIED) &&
988 ctx->program_name,
991 get_backup_sb(ctx, fs, ctx->filesystem_name, io_ptr);
1014 com_err(ctx->program_name, retval, _("while trying to open %s"),
1015 ctx->filesystem_name);
1021 fix_problem(ctx, PR_0_SB_CORRUPT, &pctx);
1027 (ctx->options & E2F_OPT_READONLY) ?
1041 fix_problem(ctx, PR_0_SB_CORRUPT, &pctx);
1042 fatal_error(ctx, 0);
1057 if (!(ctx->flags & E2F_FLAG_GOT_DEVSIZE)) {
1061 pctx.errcode = ext2fs_get_device_size(ctx->filesystem_name,
1063 &ctx->num_blocks);
1075 ext2fs_get_device_size(ctx->filesystem_name,
1077 &ctx->num_blocks);
1080 ctx->num_blocks = 0;
1082 fix_problem(ctx, PR_0_GETSIZE_ERROR, &pctx);
1083 ctx->flags |= E2F_FLAG_ABORT;
1084 fatal_error(ctx, 0);
1086 ctx->flags |= E2F_FLAG_GOT_DEVSIZE;
1091 ctx->fs = fs;
1092 fs->priv_data = ctx;
1093 fs->now = ctx->now;
1096 com_err(ctx->program_name, EXT2_ET_REV_TOO_HIGH,
1098 ctx->filesystem_name);
1100 fatal_error(ctx, _("Get a newer version of e2fsck!"));
1107 if (ctx->device_name == 0 &&
1109 ctx->device_name = string_copy(ctx, sb->s_volume_name,
1112 if (ctx->device_name == 0)
1113 ctx->device_name = ctx->filesystem_name;
1118 retval = e2fsck_check_ext3_journal(ctx);
1120 com_err(ctx->program_name, retval,
1122 ctx->device_name);
1123 fatal_error(ctx, 0);
1131 if (ctx->options & E2F_OPT_READONLY) {
1135 io_channel_flush(ctx->fs->io);
1137 if (ctx->flags & E2F_FLAG_RESTARTED) {
1144 com_err(ctx->program_name, 0,
1145 _("unable to set superblock flags on %s\n"), ctx->device_name);
1146 fatal_error(ctx, 0);
1148 retval = e2fsck_run_ext3_journal(ctx);
1150 com_err(ctx->program_name, retval,
1152 ctx->device_name);
1153 fatal_error(ctx, 0);
1155 ext2fs_close(ctx->fs);
1156 ctx->fs = 0;
1157 ctx->flags |= E2F_FLAG_RESTARTED;
1176 ctx->filesystem_name);
1190 com_err(ctx->program_name, 0,
1195 com_err(ctx->program_name, 0,
1198 ctx->device_name);
1208 if (ctx->superblock &&
1209 !(ctx->options & E2F_OPT_READONLY))
1222 ctx->blocks_per_page = sys_page_size / fs->blocksize;
1223 if (ctx->blocks_per_page == 0)
1224 ctx->blocks_per_page = 1;
1228 if (ctx->superblock)
1231 check_super_block(ctx);
1232 if (ctx->flags & E2F_FLAG_SIGNAL_MASK)
1233 fatal_error(ctx, 0);
1234 check_if_skip(ctx);
1236 read_bad_blocks_file(ctx
1238 read_bad_blocks_file(ctx, 0, !keep_bad_blocks); /* Test disk */
1239 if (ctx->flags & E2F_FLAG_SIGNAL_MASK)
1240 fatal_error(ctx, 0);
1246 "already normalized.\n"), ctx->device_name);
1247 fatal_error(ctx, 0);
1251 swap_filesys(ctx);
1252 if (ctx->flags & E2F_FLAG_SIGNAL_MASK)
1253 fatal_error(ctx, 0);
1264 com_err(ctx->program_name, retval,
1266 preenhalt(ctx);
1281 run_result = e2fsck_run(ctx);
1282 e2fsck_clear_progbar(ctx);
1284 if (ctx->flags & E2F_FLAG_JOURNAL_INODE) {
1285 if (fix_problem(ctx, PR_6_RECREATE_JOURNAL, &pctx)) {
1292 com_err(ctx->program_name, 0,
1315 retval = e2fsck_reset_context(ctx);
1317 com_err(ctx->program_name, retval,
1319 fatal_error(ctx, 0);
1325 printf(_("%s: e2fsck canceled.\n"), ctx->device_name ?
1326 ctx->device_name : ctx->filesystem_name);
1330 fatal_error(ctx, _("aborted"));
1331 if (check_backup_super_block(ctx)) {
1341 if (!(ctx->options & E2F_OPT_PREEN))
1343 ctx->device_name);
1344 if (ctx->mount_flags & EXT2_MF_ISROOT) {
1346 ctx->device_name);
1354 "errors **********\n\n"), ctx->device_name);
1361 profile_get_boolean(ctx->profile, "options",
1370 show_stats(ctx);
1371 if (!(ctx->options & E2F_OPT_READONLY)) {
1379 sb->s_lastcheck = ctx->now;
1384 e2fsck_write_bitmaps(ctx);
1387 ctx->fs = NULL;
1388 free(ctx->filesystem_name);
1389 free(ctx->journal_name);
1392 if (ctx->options & E2F_OPT_TIME)
1393 print_resource_track(NULL, &ctx->global_rtrack);
1395 e2fsck_free_context(ctx);