2 * unix.c - The unix-specific code for e2fsck
4 * Copyright (C) 1993, 1994, 1995, 1996, 1997 Theodore Ts'o.
7 * This file may be redistributed under the terms of the GNU Public
12 #define _XOPEN_SOURCE 600 /* for inclusion of sa_handler in Solaris */
39 #ifdef HAVE_SYS_IOCTL_H
40 #include <sys/ioctl.h>
45 #ifdef HAVE_SYS_TYPES_H
46 #include <sys/types.h>
53 #include "et/com_err.h"
57 #include "../version.h"
59 /* Command line options */
60 static int cflag; /* check disk */
61 static int show_version_only;
64 static int replace_bad_blocks;
65 static int keep_bad_blocks;
66 static char *bad_blocks_file;
68 e2fsck_t e2fsck_global_ctx; /* Try your very best not to use this! */
70 #ifdef CONFIG_JBD_DEBUG /* Enabled by configure --enable-jfs-debug */
71 int journal_enable_debug = -1;
74 static void usage(e2fsck_t ctx)
77 _("Usage: %s [-panyrcdfvtDFV] [-b superblock] [-B blocksize]\n"
78 "\t\t[-I inode_buffer_blocks] [-P process_inode_size]\n"
79 "\t\t[-l|-L bad_blocks_file] [-C fd] [-j external_journal]\n"
80 "\t\t[-E extended-options] device\n"),
83 fprintf(stderr, _("\nEmergency help:\n"
84 " -p Automatic repair (no questions)\n"
85 " -n Make no changes to the filesystem\n"
86 " -y Assume \"yes\" to all questions\n"
87 " -c Check for bad blocks and add them to the badblock list\n"
88 " -f Force checking even if filesystem is marked clean\n"));
91 " -b superblock Use alternative superblock\n"
92 " -B blocksize Force blocksize when looking for superblock\n"
93 " -j external_journal Set location of the external journal\n"
94 " -l bad_blocks_file Add to badblocks list\n"
95 " -L bad_blocks_file Set badblocks list\n"
101 static void show_stats(e2fsck_t ctx)
103 ext2_filsys fs = ctx->fs;
104 ext2_ino_t inodes, inodes_used;
105 blk64_t blocks, blocks_used;
106 unsigned int dir_links;
107 unsigned int num_files, num_links;
108 int frag_percent_file, frag_percent_dir, frag_percent_total;
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;
114 inodes = fs->super->s_inodes_count;
115 inodes_used = (fs->super->s_inodes_count -
116 fs->super->s_free_inodes_count);
117 blocks = ext2fs_blocks_count(fs->super);
118 blocks_used = (ext2fs_blocks_count(fs->super) -
119 ext2fs_free_blocks_count(fs->super));
121 frag_percent_file = (10000 * ctx->fs_fragmented) / inodes_used;
122 frag_percent_file = (frag_percent_file + 5) / 10;
124 frag_percent_dir = (10000 * ctx->fs_fragmented_dir) / inodes_used;
125 frag_percent_dir = (frag_percent_dir + 5) / 10;
127 frag_percent_total = ((10000 * (ctx->fs_fragmented +
128 ctx->fs_fragmented_dir))
130 frag_percent_total = (frag_percent_total + 5) / 10;
133 printf(_("%s: %u/%u files (%0d.%d%% non-contiguous), %llu/%llu blocks\n"),
134 ctx->device_name, inodes_used, inodes,
135 frag_percent_total / 10, frag_percent_total % 10,
136 blocks_used, blocks);
139 printf (P_("\n%8u inode used (%2.2f%%)\n", "\n%8u inodes used (%2.2f%%)\n",
140 inodes_used), inodes_used, 100.0 * inodes_used / inodes);
141 printf (P_("%8u non-contiguous file (%0d.%d%%)\n",
142 "%8u non-contiguous files (%0d.%d%%)\n",
144 ctx->fs_fragmented, frag_percent_file / 10,
145 frag_percent_file % 10);
146 printf (P_("%8u non-contiguous directory (%0d.%d%%)\n",
147 "%8u non-contiguous directories (%0d.%d%%)\n",
148 ctx->fs_fragmented_dir),
149 ctx->fs_fragmented_dir, frag_percent_dir / 10,
150 frag_percent_dir % 10);
151 printf (_(" # of inodes with ind/dind/tind blocks: %u/%u/%u\n"),
152 ctx->fs_ind_count, ctx->fs_dind_count, ctx->fs_tind_count);
154 for (j=MAX_EXTENT_DEPTH_COUNT-1; j >=0; j--)
155 if (ctx->extent_depth_count[j])
158 printf (_(" Extent depth histogram: "));
159 for (i=0; i < j; i++) {
162 printf("%u", ctx->extent_depth_count[i]);
167 printf (P_("%8llu block used (%2.2f%%)\n",
168 "%8llu blocks used (%2.2f%%)\n",
169 blocks_used), blocks_used, 100.0 * blocks_used / blocks);
170 printf (P_("%8u bad block\n", "%8u bad blocks\n",
171 ctx->fs_badblocks_count), ctx->fs_badblocks_count);
172 printf (P_("%8u large file\n", "%8u large files\n",
173 ctx->large_files), ctx->large_files);
174 printf (P_("\n%8u regular file\n", "\n%8u regular files\n",
175 ctx->fs_regular_count), ctx->fs_regular_count);
176 printf (P_("%8u directory\n", "%8u directories\n",
177 ctx->fs_directory_count), ctx->fs_directory_count);
178 printf (P_("%8u character device file\n",
179 "%8u character device files\n", ctx->fs_chardev_count),
180 ctx->fs_chardev_count);
181 printf (P_("%8u block device file\n", "%8u block device files\n",
182 ctx->fs_blockdev_count), ctx->fs_blockdev_count);
183 printf (P_("%8u fifo\n", "%8u fifos\n", ctx->fs_fifo_count),
185 printf (P_("%8u link\n", "%8u links\n",
186 ctx->fs_links_count - dir_links),
187 ctx->fs_links_count - dir_links);
188 printf (P_("%8u symbolic link", "%8u symbolic links",
189 ctx->fs_symlinks_count), ctx->fs_symlinks_count);
190 printf (P_(" (%u fast symbolic link)\n", " (%u fast symbolic links)\n",
191 ctx->fs_fast_symlinks_count), ctx->fs_fast_symlinks_count);
192 printf (P_("%8u socket\n", "%8u sockets\n", ctx->fs_sockets_count),
193 ctx->fs_sockets_count);
194 printf ("--------\n");
195 printf (P_("%8u file\n", "%8u files\n",
196 ctx->fs_total_count - dir_links),
197 ctx->fs_total_count - dir_links);
200 static void check_mount(e2fsck_t ctx)
205 retval = ext2fs_check_if_mounted(ctx->filesystem_name,
208 com_err("ext2fs_check_if_mount", retval,
209 _("while determining whether %s is mounted."),
210 ctx->filesystem_name);
215 * If the filesystem isn't mounted, or it's the root
216 * filesystem and it's mounted read-only, and we're not doing
217 * a read/write check, then everything's fine.
219 if ((!(ctx->mount_flags & EXT2_MF_MOUNTED)) ||
220 ((ctx->mount_flags & EXT2_MF_ISROOT) &&
221 (ctx->mount_flags & EXT2_MF_READONLY) &&
222 !(ctx->options & E2F_OPT_WRITECHECK)))
225 if ((ctx->options & E2F_OPT_READONLY) &&
226 !(ctx->options & E2F_OPT_WRITECHECK)) {
227 printf(_("Warning! %s is mounted.\n"), ctx->filesystem_name);
231 printf(_("%s is mounted. "), ctx->filesystem_name);
232 if (!ctx->interactive)
233 fatal_error(ctx, _("Cannot continue, aborting.\n\n"));
234 printf(_("\n\n\007\007\007\007WARNING!!! "
235 "The filesystem is mounted. If you continue you ***WILL***\n"
236 "cause ***SEVERE*** filesystem damage.\007\007\007\n\n"));
237 cont = ask_yn(_("Do you really want to continue"), 0);
239 printf (_("check aborted.\n"));
245 static int is_on_batt(void)
249 char tmp[80], tmp2[80], fname[80];
253 f = fopen("/proc/apm", "r");
255 if (fscanf(f, "%s %s %s %x", tmp, tmp, tmp, &acflag) != 4)
258 return (acflag != 1);
260 d = opendir("/proc/acpi/ac_adapter");
262 while ((de=readdir(d)) != NULL) {
263 if (!strncmp(".", de->d_name, 1))
265 snprintf(fname, 80, "/proc/acpi/ac_adapter/%s/state",
267 f = fopen(fname, "r");
270 if (fscanf(f, "%s %s", tmp2, tmp) != 2)
273 if (strncmp(tmp, "off-line", 8) == 0) {
284 * This routine checks to see if a filesystem can be skipped; if so,
285 * it will exit with E2FSCK_OK. Under some conditions it will print a
286 * message explaining why a check is being forced.
288 static void check_if_skip(e2fsck_t ctx)
290 ext2_filsys fs = ctx->fs;
291 struct problem_context pctx;
292 const char *reason = NULL;
293 unsigned int reason_arg = 0;
295 int batt = is_on_batt();
296 int defer_check_on_battery;
297 int broken_system_clock;
300 profile_get_boolean(ctx->profile, "options", "broken_system_clock",
301 0, 0, &broken_system_clock);
302 if (ctx->flags & E2F_FLAG_TIME_INSANE)
303 broken_system_clock = 1;
304 profile_get_boolean(ctx->profile, "options",
305 "defer_check_on_battery", 0, 1,
306 &defer_check_on_battery);
307 if (!defer_check_on_battery)
310 if ((ctx->options & E2F_OPT_FORCE) || bad_blocks_file || cflag)
313 if (ctx->options & E2F_OPT_JOURNAL_ONLY)
316 lastcheck = fs->super->s_lastcheck;
317 if (lastcheck > ctx->now)
318 lastcheck -= ctx->time_fudge;
319 if ((fs->super->s_state & EXT2_ERROR_FS) ||
320 !ext2fs_test_valid(fs))
321 reason = _(" contains a file system with errors");
322 else if ((fs->super->s_state & EXT2_VALID_FS) == 0)
323 reason = _(" was not cleanly unmounted");
324 else if (check_backup_super_block(ctx))
325 reason = _(" primary superblock features different from backup");
326 else if ((fs->super->s_max_mnt_count > 0) &&
327 (fs->super->s_mnt_count >=
328 (unsigned) fs->super->s_max_mnt_count)) {
329 reason = _(" has been mounted %u times without being checked");
330 reason_arg = fs->super->s_mnt_count;
331 if (batt && (fs->super->s_mnt_count <
332 (unsigned) fs->super->s_max_mnt_count*2))
334 } else if (!broken_system_clock && fs->super->s_checkinterval &&
335 (ctx->now < lastcheck)) {
336 reason = _(" has filesystem last checked time in the future");
339 } else if (!broken_system_clock && fs->super->s_checkinterval &&
340 ((ctx->now - lastcheck) >=
341 ((time_t) fs->super->s_checkinterval))) {
342 reason = _(" has gone %u days without being checked");
343 reason_arg = (ctx->now - fs->super->s_lastcheck)/(3600*24);
344 if (batt && ((ctx->now - fs->super->s_lastcheck) <
345 fs->super->s_checkinterval*2))
349 fputs(ctx->device_name, stdout);
350 printf(reason, reason_arg);
351 fputs(_(", check forced.\n"), stdout);
356 * Update the global counts from the block group counts. This
357 * is needed since modern kernels don't update the global
358 * counts so as to avoid locking the entire file system. So
359 * if the filesystem is not unmounted cleanly, the global
360 * counts may not be accurate. Update them here if we can,
361 * for the benefit of users who might examine the file system
362 * using dumpe2fs. (This is for cosmetic reasons only.)
364 clear_problem_context(&pctx);
365 pctx.ino = fs->super->s_free_inodes_count;
366 pctx.ino2 = ctx->free_inodes;
367 if ((pctx.ino != pctx.ino2) &&
368 !(ctx->options & E2F_OPT_READONLY) &&
369 fix_problem(ctx, PR_0_FREE_INODE_COUNT, &pctx)) {
370 fs->super->s_free_inodes_count = ctx->free_inodes;
371 ext2fs_mark_super_dirty(fs);
373 clear_problem_context(&pctx);
374 pctx.blk = ext2fs_free_blocks_count(fs->super);
375 pctx.blk2 = ctx->free_blocks;
376 if ((pctx.blk != pctx.blk2) &&
377 !(ctx->options & E2F_OPT_READONLY) &&
378 fix_problem(ctx, PR_0_FREE_BLOCK_COUNT, &pctx)) {
379 ext2fs_free_blocks_count_set(fs->super, ctx->free_blocks);
380 ext2fs_mark_super_dirty(fs);
383 /* Print the summary message when we're skipping a full check */
384 printf(_("%s: clean, %u/%u files, %llu/%llu blocks"), ctx->device_name,
385 fs->super->s_inodes_count - fs->super->s_free_inodes_count,
386 fs->super->s_inodes_count,
387 ext2fs_blocks_count(fs->super) -
388 ext2fs_free_blocks_count(fs->super),
389 ext2fs_blocks_count(fs->super));
391 if (fs->super->s_max_mnt_count > 0) {
392 next_check = fs->super->s_max_mnt_count - fs->super->s_mnt_count;
396 if (!broken_system_clock && fs->super->s_checkinterval &&
397 ((ctx->now - fs->super->s_lastcheck) >= fs->super->s_checkinterval))
399 if (next_check <= 5) {
400 if (next_check == 1) {
402 fputs(_(" (check deferred; on battery)"),
405 fputs(_(" (check after next mount)"), stdout);
407 printf(_(" (check in %ld mounts)"), next_check);
413 e2fsck_free_context(ctx);
418 * For completion notice
424 struct percent_tbl e2fsck_tbl = {
425 5, { 0, 70, 90, 92, 95, 100 }
427 static char bar[128], spaces[128];
429 static float calc_percent(struct percent_tbl *tbl, int pass, int curr,
436 if (pass > tbl->max_pass || max == 0)
438 percent = ((float) curr) / ((float) max);
439 return ((percent * (tbl->table[pass] - tbl->table[pass-1]))
440 + tbl->table[pass-1]);
443 extern void e2fsck_clear_progbar(e2fsck_t ctx)
445 if (!(ctx->flags & E2F_FLAG_PROG_BAR))
448 printf("%s%s\r%s", ctx->start_meta, spaces + (sizeof(spaces) - 80),
451 ctx->flags &= ~E2F_FLAG_PROG_BAR;
454 int e2fsck_simple_progress(e2fsck_t ctx, const char *label, float percent,
457 static const char spinner[] = "\\|/-";
464 if (ctx->flags & E2F_FLAG_PROG_SUPPRESS)
468 * Calculate the new progress position. If the
469 * percentage hasn't changed, then we skip out right
472 fixed_percent = (int) ((10 * percent) + 0.5);
473 if (ctx->progress_last_percent == fixed_percent)
475 ctx->progress_last_percent = fixed_percent;
478 * If we've already updated the spinner once within
479 * the last 1/8th of a second, no point doing it
482 gettimeofday(&tv, NULL);
483 tick = (tv.tv_sec << 3) + (tv.tv_usec / (1000000 / 8));
484 if ((tick == ctx->progress_last_time) &&
485 (fixed_percent != 0) && (fixed_percent != 1000))
487 ctx->progress_last_time = tick;
490 * Advance the spinner, and note that the progress bar
491 * will be on the screen
493 ctx->progress_pos = (ctx->progress_pos+1) & 3;
494 ctx->flags |= E2F_FLAG_PROG_BAR;
496 dpywidth = 66 - strlen(label);
497 dpywidth = 8 * (dpywidth / 8);
501 i = ((percent * dpywidth) + 50) / 100;
502 printf("%s%s: |%s%s", ctx->start_meta, label,
503 bar + (sizeof(bar) - (i+1)),
504 spaces + (sizeof(spaces) - (dpywidth - i + 1)));
505 if (fixed_percent == 1000)
508 fputc(spinner[ctx->progress_pos & 3], stdout);
509 printf(" %4.1f%% ", percent);
511 printf("%u\r", dpynum);
513 fputs(" \r", stdout);
514 fputs(ctx->stop_meta, stdout);
516 if (fixed_percent == 1000)
517 e2fsck_clear_progbar(ctx);
523 static int e2fsck_update_progress(e2fsck_t ctx, int pass,
524 unsigned long cur, unsigned long max)
532 if (ctx->progress_fd) {
533 snprintf(buf, sizeof(buf), "%d %lu %lu %s\n",
534 pass, cur, max, ctx->device_name);
535 write_all(ctx->progress_fd, buf, strlen(buf));
537 percent = calc_percent(&e2fsck_tbl, pass, cur, max);
538 e2fsck_simple_progress(ctx, ctx->device_name,
544 #define PATH_SET "PATH=/sbin"
547 * Make sure 0,1,2 file descriptors are open, so that we don't open
548 * the filesystem using the same file descriptor as stdout or stderr.
550 static void reserve_stdio_fds(void)
555 fd = open("/dev/null", O_RDWR);
557 fprintf(stderr, _("ERROR: Couldn't open "
566 static void signal_progress_on(int sig EXT2FS_ATTR((unused)))
568 e2fsck_t ctx = e2fsck_global_ctx;
573 ctx->progress = e2fsck_update_progress;
576 static void signal_progress_off(int sig EXT2FS_ATTR((unused)))
578 e2fsck_t ctx = e2fsck_global_ctx;
583 e2fsck_clear_progbar(ctx);
587 static void signal_cancel(int sig EXT2FS_ATTR((unused)))
589 e2fsck_t ctx = e2fsck_global_ctx;
594 ctx->flags |= E2F_FLAG_CANCEL;
598 static void parse_extended_opts(e2fsck_t ctx, const char *opts)
600 char *buf, *token, *next, *p, *arg;
602 int extended_usage = 0;
604 buf = string_copy(ctx, opts, 0);
605 for (token = buf; token && *token; token = next) {
606 p = strchr(token, ',');
612 arg = strchr(token, '=');
617 if (strcmp(token, "ea_ver") == 0) {
622 ea_ver = strtoul(arg, &p, 0);
624 ((ea_ver != 1) && (ea_ver != 2))) {
626 _("Invalid EA version.\n"));
630 ctx->ext_attr_ver = ea_ver;
631 } else if (strcmp(token, "fragcheck") == 0) {
632 ctx->options |= E2F_OPT_FRAGCHECK;
634 } else if (strcmp(token, "journal_only") == 0) {
639 ctx->options |= E2F_OPT_JOURNAL_ONLY;
640 } else if (strcmp(token, "discard") == 0) {
641 ctx->options |= E2F_OPT_DISCARD;
643 } else if (strcmp(token, "nodiscard") == 0) {
644 ctx->options &= ~E2F_OPT_DISCARD;
647 fprintf(stderr, _("Unknown extended option: %s\n"),
654 if (extended_usage) {
655 fputs(("\nExtended options are separated by commas, "
656 "and may take an argument which\n"
657 "is set off by an equals ('=') sign. "
658 "Valid extended options are:\n"), stderr);
659 fputs(("\tea_ver=<ea_version (1 or 2)>\n"), stderr);
660 fputs(("\tfragcheck\n"), stderr);
661 fputs(("\tjournal_only\n"), stderr);
662 fputs(("\tdiscard\n"), stderr);
663 fputs(("\tnodiscard\n"), stderr);
669 static void syntax_err_report(const char *filename, long err, int line_num)
672 _("Syntax error in e2fsck config file (%s, line #%d)\n\t%s\n"),
673 filename, line_num, error_message(err));
677 static const char *config_fn[] = { ROOT_SYSCONFDIR "/e2fsck.conf", 0 };
679 static errcode_t PRS(int argc, char *argv[], e2fsck_t *ret_ctx)
684 extern void *mallwatch;
691 char *extended_opts = 0;
693 int res; /* result of sscanf */
694 #ifdef CONFIG_JBD_DEBUG
698 retval = e2fsck_allocate_context(&ctx);
704 setvbuf(stdout, NULL, _IONBF, BUFSIZ);
705 setvbuf(stderr, NULL, _IONBF, BUFSIZ);
706 if (isatty(0) && isatty(1)) {
707 ctx->interactive = 1;
709 ctx->start_meta[0] = '\001';
710 ctx->stop_meta[0] = '\002';
712 memset(bar, '=', sizeof(bar)-1);
713 memset(spaces, ' ', sizeof(spaces)-1);
714 add_error_table(&et_ext2_error_table);
715 add_error_table(&et_prof_error_table);
716 blkid_get_cache(&ctx->blkid, NULL);
719 ctx->program_name = *argv;
721 ctx->program_name = "e2fsck";
723 while ((c = getopt (argc, argv, "panyrcC:B:dE:fvtFVM:b:I:j:P:l:L:N:SsDk")) != EOF)
726 ctx->progress = e2fsck_update_progress;
727 res = sscanf(optarg, "%d", &ctx->progress_fd);
731 if (ctx->progress_fd < 0) {
733 ctx->progress_fd = ctx->progress_fd * -1;
735 if (!ctx->progress_fd)
737 /* Validate the file descriptor to avoid disasters */
738 fd = dup(ctx->progress_fd);
741 _("Error validating file descriptor %d: %s\n"),
743 error_message(errno));
745 _("Invalid completion information file descriptor"));
750 ctx->options |= E2F_OPT_COMPRESS_DIRS;
753 extended_opts = optarg;
757 if (ctx->options & (E2F_OPT_YES|E2F_OPT_NO)) {
760 _("Only one of the options -p/-a, -n or -y may be specified."));
762 ctx->options |= E2F_OPT_PREEN;
765 if (ctx->options & (E2F_OPT_YES|E2F_OPT_PREEN))
767 ctx->options |= E2F_OPT_NO;
770 if (ctx->options & (E2F_OPT_PREEN|E2F_OPT_NO))
772 ctx->options |= E2F_OPT_YES;
775 #ifdef RESOURCE_TRACK
776 if (ctx->options & E2F_OPT_TIME)
777 ctx->options |= E2F_OPT_TIME2;
779 ctx->options |= E2F_OPT_TIME;
781 fprintf(stderr, _("The -t option is not "
782 "supported on this version of e2fsck.\n"));
787 ctx->options |= E2F_OPT_WRITECHECK;
788 ctx->options |= E2F_OPT_CHECKBLOCKS;
791 /* What we do by default, anyway! */
794 res = sscanf(optarg, "%llu", &ctx->use_superblock);
797 ctx->flags |= E2F_FLAG_SB_SPECIFIED;
800 ctx->blocksize = atoi(optarg);
803 res = sscanf(optarg, "%d", &ctx->inode_buffer_blocks);
808 ctx->journal_name = blkid_get_devname(ctx->blkid,
810 if (!ctx->journal_name) {
811 com_err(ctx->program_name, 0,
812 _("Unable to resolve '%s'"),
818 res = sscanf(optarg, "%d", &ctx->process_inode_size);
823 replace_bad_blocks++;
825 bad_blocks_file = string_copy(ctx, optarg, 0);
828 ctx->options |= E2F_OPT_DEBUG;
831 ctx->options |= E2F_OPT_FORCE;
840 show_version_only = 1;
844 mallwatch = (void *) strtol(optarg, NULL, 0);
848 ctx->device_name = string_copy(ctx, optarg, 0);
856 if (show_version_only)
858 if (optind != argc - 1)
860 if ((ctx->options & E2F_OPT_NO) &&
861 (ctx->options & E2F_OPT_COMPRESS_DIRS)) {
862 com_err(ctx->program_name, 0,
863 _("The -n and -D options are incompatible."));
866 if ((ctx->options & E2F_OPT_NO) && cflag) {
867 com_err(ctx->program_name, 0,
868 _("The -n and -c options are incompatible."));
871 if ((ctx->options & E2F_OPT_NO) && bad_blocks_file) {
872 com_err(ctx->program_name, 0,
873 _("The -n and -l/-L options are incompatible."));
876 if (ctx->options & E2F_OPT_NO)
877 ctx->options |= E2F_OPT_READONLY;
879 ctx->io_options = strchr(argv[optind], '?');
881 *ctx->io_options++ = 0;
882 ctx->filesystem_name = blkid_get_devname(ctx->blkid, argv[optind], 0);
883 if (!ctx->filesystem_name) {
884 com_err(ctx->program_name, 0, _("Unable to resolve '%s'"),
889 parse_extended_opts(ctx, extended_opts);
891 if ((cp = getenv("E2FSCK_CONFIG")) != NULL)
893 profile_set_syntax_err_cb(syntax_err_report);
894 profile_init(config_fn, &ctx->profile);
897 fd = open(ctx->filesystem_name, O_RDONLY, 0);
899 com_err("open", errno,
900 _("while opening %s for flushing"),
901 ctx->filesystem_name);
904 if ((retval = ext2fs_sync_device(fd, 1))) {
905 com_err("ext2fs_sync_device", retval,
906 _("while trying to flush %s"),
907 ctx->filesystem_name);
912 if (cflag && bad_blocks_file) {
913 fprintf(stderr, _("The -c and the -l/-L options may "
914 "not be both used at the same time.\n"));
919 * Set up signal action
921 memset(&sa, 0, sizeof(struct sigaction));
922 sa.sa_handler = signal_cancel;
923 sigaction(SIGINT, &sa, 0);
924 sigaction(SIGTERM, &sa, 0);
926 sa.sa_flags = SA_RESTART;
928 e2fsck_global_ctx = ctx;
929 sa.sa_handler = signal_progress_on;
930 sigaction(SIGUSR1, &sa, 0);
931 sa.sa_handler = signal_progress_off;
932 sigaction(SIGUSR2, &sa, 0);
935 /* Update our PATH to include /sbin if we need to run badblocks */
937 char *oldpath = getenv("PATH");
939 int len = sizeof(PATH_SET) + 1;
942 len += strlen(oldpath);
944 newpath = malloc(len);
946 fatal_error(ctx, "Couldn't malloc() newpath");
947 strcpy(newpath, PATH_SET);
950 strcat(newpath, ":");
951 strcat(newpath, oldpath);
955 #ifdef CONFIG_JBD_DEBUG
956 jbd_debug = getenv("E2FSCK_JBD_DEBUG");
958 res = sscanf(jbd_debug, "%d", &journal_enable_debug);
961 _("E2FSCK_JBD_DEBUG \"%s\" not an integer\n\n"),
970 fprintf(stderr, _("\nInvalid non-numeric argument to -%c (\"%s\")\n\n"),
975 static errcode_t try_open_fs(e2fsck_t ctx, int flags, io_manager io_ptr,
981 if (ctx->superblock && ctx->blocksize) {
982 retval = ext2fs_open2(ctx->filesystem_name, ctx->io_options,
983 flags, ctx->superblock, ctx->blocksize,
985 } else if (ctx->superblock) {
987 for (blocksize = EXT2_MIN_BLOCK_SIZE;
988 blocksize <= EXT2_MAX_BLOCK_SIZE; blocksize *= 2) {
990 ext2fs_free(*ret_fs);
993 retval = ext2fs_open2(ctx->filesystem_name,
994 ctx->io_options, flags,
995 ctx->superblock, blocksize,
1001 retval = ext2fs_open2(ctx->filesystem_name, ctx->io_options,
1002 flags, 0, 0, io_ptr, ret_fs);
1006 static const char *my_ver_string = E2FSPROGS_VERSION;
1007 static const char *my_ver_date = E2FSPROGS_DATE;
1009 int e2fsck_check_mmp(ext2_filsys fs, e2fsck_t ctx)
1011 struct mmp_struct *mmp_s;
1012 unsigned int mmp_check_interval;
1013 errcode_t retval = 0;
1014 struct problem_context pctx;
1015 unsigned int wait_time = 0;
1017 clear_problem_context(&pctx);
1018 if (fs->mmp_buf == NULL) {
1019 retval = ext2fs_get_mem(fs->blocksize, &fs->mmp_buf);
1024 retval = ext2fs_mmp_read(fs, fs->super->s_mmp_block, fs->mmp_buf);
1028 mmp_s = fs->mmp_buf;
1030 mmp_check_interval = fs->super->s_mmp_update_interval;
1031 if (mmp_check_interval < EXT4_MMP_MIN_CHECK_INTERVAL)
1032 mmp_check_interval = EXT4_MMP_MIN_CHECK_INTERVAL;
1035 * If check_interval in MMP block is larger, use that instead of
1036 * check_interval from the superblock.
1038 if (mmp_s->mmp_check_interval > mmp_check_interval)
1039 mmp_check_interval = mmp_s->mmp_check_interval;
1041 wait_time = mmp_check_interval * 2 + 1;
1043 if (mmp_s->mmp_seq == EXT4_MMP_SEQ_CLEAN)
1045 else if (mmp_s->mmp_seq == EXT4_MMP_SEQ_FSCK)
1046 retval = EXT2_ET_MMP_FSCK_ON;
1047 else if (mmp_s->mmp_seq > EXT4_MMP_SEQ_MAX)
1048 retval = EXT2_ET_MMP_UNKNOWN_SEQ;
1053 /* Print warning if e2fck will wait for more than 20 secs. */
1054 if (verbose || wait_time > EXT4_MMP_MIN_CHECK_INTERVAL * 4) {
1055 printf("MMP interval is %u seconds and total wait time is %u "
1056 "seconds. Please wait...\n",
1057 mmp_check_interval, wait_time * 2);
1064 if (retval == EXT2_ET_MMP_BAD_BLOCK) {
1065 if (fix_problem(ctx, PR_0_MMP_INVALID_BLK, &pctx)) {
1066 fs->super->s_mmp_block = 0;
1067 ext2fs_mark_super_dirty(fs);
1070 } else if (retval == EXT2_ET_MMP_FAILED) {
1071 com_err(ctx->program_name, retval,
1072 _("while checking MMP block"));
1073 dump_mmp_msg(fs->mmp_buf, NULL);
1074 } else if (retval == EXT2_ET_MMP_FSCK_ON ||
1075 retval == EXT2_ET_MMP_UNKNOWN_SEQ) {
1076 com_err(ctx->program_name, retval,
1077 _("while checking MMP block"));
1078 dump_mmp_msg(fs->mmp_buf,
1079 _("If you are sure the filesystem is not "
1080 "in use on any node, run:\n"
1081 "'tune2fs -f -E clear_mmp {device}'\n"));
1082 } else if (retval == EXT2_ET_MMP_MAGIC_INVALID) {
1083 if (fix_problem(ctx, PR_0_MMP_INVALID_MAGIC, &pctx)) {
1084 ext2fs_mmp_clear(fs);
1091 int main (int argc, char *argv[])
1093 errcode_t retval = 0, retval2 = 0, orig_retval = 0;
1094 int exit_value = FSCK_OK;
1097 struct ext2_super_block *sb;
1098 const char *lib_ver_date;
1099 int my_ver, lib_ver;
1101 blk_t orig_superblock;
1102 struct problem_context pctx;
1103 int flags, run_result;
1105 int sysval, sys_page_size = 4096;
1110 clear_problem_context(&pctx);
1119 setlocale(LC_MESSAGES, "");
1120 setlocale(LC_CTYPE, "");
1121 bindtextdomain(NLS_CAT_NAME, LOCALEDIR);
1122 textdomain(NLS_CAT_NAME);
1124 my_ver = ext2fs_parse_version_string(my_ver_string);
1125 lib_ver = ext2fs_get_library_version(0, &lib_ver_date);
1126 if (my_ver > lib_ver) {
1127 fprintf( stderr, _("Error: ext2fs library version "
1129 show_version_only++;
1132 retval = PRS(argc, argv, &ctx);
1134 com_err("e2fsck", retval,
1135 _("while trying to initialize program"));
1138 reserve_stdio_fds();
1140 init_resource_track(&ctx->global_rtrack, NULL);
1141 if (!(ctx->options & E2F_OPT_PREEN) || show_version_only)
1142 fprintf(stderr, "e2fsck %s (%s)\n", my_ver_string,
1145 if (show_version_only) {
1146 fprintf(stderr, _("\tUsing %s, %s\n"),
1147 error_message(EXT2_ET_BASE), lib_ver_date);
1153 if (!(ctx->options & E2F_OPT_PREEN) &&
1154 !(ctx->options & E2F_OPT_NO) &&
1155 !(ctx->options & E2F_OPT_YES)) {
1156 if (!ctx->interactive)
1158 _("need terminal for interactive repairs"));
1160 ctx->superblock = ctx->use_superblock;
1162 flags = EXT2_FLAG_SKIP_MMP;
1164 #ifdef CONFIG_TESTIO_DEBUG
1165 if (getenv("TEST_IO_FLAGS") || getenv("TEST_IO_BLOCK")) {
1166 io_ptr = test_io_manager;
1167 test_io_backing_manager = unix_io_manager;
1170 io_ptr = unix_io_manager;
1171 flags |= EXT2_FLAG_NOFREE_ON_ERROR;
1172 profile_get_boolean(ctx->profile, "options", "old_bitmaps", 0, 0,
1175 flags |= EXT2_FLAG_64BITS;
1176 if ((ctx->options & E2F_OPT_READONLY) == 0)
1177 flags |= EXT2_FLAG_RW;
1178 if ((ctx->mount_flags & EXT2_MF_MOUNTED) == 0)
1179 flags |= EXT2_FLAG_EXCLUSIVE;
1181 retval = try_open_fs(ctx, flags, io_ptr, &fs);
1183 if (!ctx->superblock && !(ctx->options & E2F_OPT_PREEN) &&
1184 !(ctx->flags & E2F_FLAG_SB_SPECIFIED) &&
1185 ((retval == EXT2_ET_BAD_MAGIC) ||
1186 (retval == EXT2_ET_CORRUPT_SUPERBLOCK) ||
1187 ((retval == 0) && (retval2 = ext2fs_check_desc(fs))))) {
1188 if (retval2 == ENOMEM) {
1192 if (fs->flags & EXT2_FLAG_NOFREE_ON_ERROR) {
1196 if (!fs || (fs->group_desc_count > 1)) {
1197 printf(_("%s: %s trying backup blocks...\n"),
1199 retval ? _("Superblock invalid,") :
1200 _("Group descriptors look bad..."));
1201 orig_superblock = ctx->superblock;
1202 get_backup_sb(ctx, fs, ctx->filesystem_name, io_ptr);
1205 orig_retval = retval;
1206 retval = try_open_fs(ctx, flags, io_ptr, &fs);
1207 if ((orig_retval == 0) && retval != 0) {
1210 com_err(ctx->program_name, retval,
1211 "when using the backup blocks");
1212 printf(_("%s: going back to original "
1213 "superblock\n"), ctx->program_name);
1214 ctx->superblock = orig_superblock;
1215 retval = try_open_fs(ctx, flags, io_ptr, &fs);
1219 if (((retval == EXT2_ET_UNSUPP_FEATURE) ||
1220 (retval == EXT2_ET_RO_UNSUPP_FEATURE)) &&
1223 features[0] = (sb->s_feature_compat &
1224 ~EXT2_LIB_FEATURE_COMPAT_SUPP);
1225 features[1] = (sb->s_feature_incompat &
1226 ~EXT2_LIB_FEATURE_INCOMPAT_SUPP);
1227 features[2] = (sb->s_feature_ro_compat &
1228 ~EXT2_LIB_FEATURE_RO_COMPAT_SUPP);
1229 if (features[0] || features[1] || features[2])
1230 goto print_unsupp_features;
1235 retval = orig_retval;
1236 com_err(ctx->program_name, retval, _("while trying to open %s"),
1237 ctx->filesystem_name);
1238 if (retval == EXT2_ET_REV_TOO_HIGH) {
1239 printf(_("The filesystem revision is apparently "
1240 "too high for this version of e2fsck.\n"
1241 "(Or the filesystem superblock "
1242 "is corrupt)\n\n"));
1243 fix_problem(ctx, PR_0_SB_CORRUPT, &pctx);
1244 } else if (retval == EXT2_ET_SHORT_READ)
1245 printf(_("Could this be a zero-length partition?\n"));
1246 else if ((retval == EPERM) || (retval == EACCES))
1247 printf(_("You must have %s access to the "
1248 "filesystem or be root\n"),
1249 (ctx->options & E2F_OPT_READONLY) ?
1251 else if (retval == ENXIO)
1252 printf(_("Possibly non-existent or swap device?\n"));
1253 else if (retval == EBUSY)
1254 printf(_("Filesystem mounted or opened exclusively "
1255 "by another program?\n"));
1256 else if (retval == ENOENT)
1257 printf(_("Possibly non-existent device?\n"));
1259 else if (retval == EROFS)
1260 printf(_("Disk write-protected; use the -n option "
1261 "to do a read-only\n"
1262 "check of the device.\n"));
1265 fix_problem(ctx, PR_0_SB_CORRUPT, &pctx);
1266 fatal_error(ctx, 0);
1269 * We only update the master superblock because (a) paranoia;
1270 * we don't want to corrupt the backup superblocks, and (b) we
1271 * don't need to update the mount count and last checked
1272 * fields in the backup superblock (the kernel doesn't update
1273 * the backup superblocks anyway). With newer versions of the
1274 * library this flag is set by ext2fs_open2(), but we set this
1275 * here just to be sure. (No, we don't support e2fsck running
1276 * with some other libext2fs than the one that it was shipped
1277 * with, but just in case....)
1279 fs->flags |= EXT2_FLAG_MASTER_SB_ONLY;
1281 if (!(ctx->flags & E2F_FLAG_GOT_DEVSIZE)) {
1282 __u32 blocksize = EXT2_BLOCK_SIZE(fs->super);
1283 int need_restart = 0;
1285 pctx.errcode = ext2fs_get_device_size2(ctx->filesystem_name,
1289 * The floppy driver refuses to allow anyone else to
1290 * open the device if has been opened with O_EXCL;
1291 * this is unlike other block device drivers in Linux.
1292 * To handle this, we close the filesystem and then
1293 * reopen the filesystem after we get the device size.
1295 if (pctx.errcode == EBUSY) {
1299 ext2fs_get_device_size2(ctx->filesystem_name,
1303 if (pctx.errcode == EXT2_ET_UNIMPLEMENTED)
1304 ctx->num_blocks = 0;
1305 else if (pctx.errcode) {
1306 fix_problem(ctx, PR_0_GETSIZE_ERROR, &pctx);
1307 ctx->flags |= E2F_FLAG_ABORT;
1308 fatal_error(ctx, 0);
1310 ctx->flags |= E2F_FLAG_GOT_DEVSIZE;
1316 fs->priv_data = ctx;
1319 if (sb->s_rev_level > E2FSCK_CURRENT_REV) {
1320 com_err(ctx->program_name, EXT2_ET_REV_TOO_HIGH,
1321 _("while trying to open %s"),
1322 ctx->filesystem_name);
1324 fatal_error(ctx, _("Get a newer version of e2fsck!"));
1328 * Set the device name, which is used whenever we print error
1329 * or informational messages to the user.
1331 if (ctx->device_name == 0 &&
1332 (sb->s_volume_name[0] != 0)) {
1333 ctx->device_name = string_copy(ctx, sb->s_volume_name,
1334 sizeof(sb->s_volume_name));
1336 if (ctx->device_name == 0)
1337 ctx->device_name = string_copy(ctx, ctx->filesystem_name, 0);
1338 for (cp = ctx->device_name; *cp; cp++)
1339 if (isspace(*cp) || *cp == ':')
1342 ehandler_init(fs->io);
1344 if ((fs->super->s_feature_incompat & EXT4_FEATURE_INCOMPAT_MMP) &&
1345 (flags & EXT2_FLAG_SKIP_MMP)) {
1346 if (e2fsck_check_mmp(fs, ctx))
1347 fatal_error(ctx, 0);
1351 * Restart in order to reopen fs but this time start mmp.
1353 if (flags & EXT2_FLAG_SKIP_MMP) {
1356 flags &= ~EXT2_FLAG_SKIP_MMP;
1360 if ((ctx->mount_flags & EXT2_MF_MOUNTED) &&
1361 !(sb->s_feature_incompat & EXT3_FEATURE_INCOMPAT_RECOVER))
1365 * Make sure the ext3 superblock fields are consistent.
1367 retval = e2fsck_check_ext3_journal(ctx);
1369 com_err(ctx->program_name, retval,
1370 _("while checking ext3 journal for %s"),
1372 fatal_error(ctx, 0);
1376 * Check to see if we need to do ext3-style recovery. If so,
1377 * do it, and then restart the fsck.
1379 if (sb->s_feature_incompat & EXT3_FEATURE_INCOMPAT_RECOVER) {
1380 if (ctx->options & E2F_OPT_READONLY) {
1381 printf(_("Warning: skipping journal recovery "
1382 "because doing a read-only filesystem "
1384 io_channel_flush(ctx->fs->io);
1386 if (ctx->flags & E2F_FLAG_RESTARTED) {
1388 * Whoops, we attempted to run the
1389 * journal twice. This should never
1390 * happen, unless the hardware or
1391 * device driver is being bogus.
1393 com_err(ctx->program_name, 0,
1394 _("unable to set superblock flags on %s\n"), ctx->device_name);
1395 fatal_error(ctx, 0);
1397 retval = e2fsck_run_ext3_journal(ctx);
1399 com_err(ctx->program_name, retval,
1400 _("while recovering ext3 journal of %s"),
1402 fatal_error(ctx, 0);
1404 ext2fs_close(ctx->fs);
1406 ctx->flags |= E2F_FLAG_RESTARTED;
1413 * Check for compatibility with the feature sets. We need to
1414 * be more stringent than ext2fs_open().
1416 features[0] = sb->s_feature_compat & ~EXT2_LIB_FEATURE_COMPAT_SUPP;
1417 features[1] = sb->s_feature_incompat & ~EXT2_LIB_FEATURE_INCOMPAT_SUPP;
1418 features[2] = (sb->s_feature_ro_compat &
1419 ~EXT2_LIB_FEATURE_RO_COMPAT_SUPP);
1420 print_unsupp_features:
1421 if (features[0] || features[1] || features[2]) {
1423 __u32 *mask = features, m;
1425 fprintf(stderr, _("%s has unsupported feature(s):"),
1426 ctx->filesystem_name);
1428 for (i=0; i <3; i++,mask++) {
1429 for (j=0,m=1; j < 32; j++, m<<=1) {
1431 fprintf(stderr, " %s",
1432 e2p_feature2string(i, m));
1438 #ifdef ENABLE_COMPRESSION
1439 if (sb->s_feature_incompat & EXT2_FEATURE_INCOMPAT_COMPRESSION)
1440 com_err(ctx->program_name, 0,
1441 _("Warning: compression support is experimental.\n"));
1443 #ifndef ENABLE_HTREE
1444 if (sb->s_feature_compat & EXT2_FEATURE_COMPAT_DIR_INDEX) {
1445 com_err(ctx->program_name, 0,
1446 _("E2fsck not compiled with HTREE support,\n\t"
1447 "but filesystem %s has HTREE directories.\n"),
1454 * If the user specified a specific superblock, presumably the
1455 * master superblock has been trashed. So we mark the
1456 * superblock as dirty, so it can be written out.
1458 if (ctx->superblock &&
1459 !(ctx->options & E2F_OPT_READONLY))
1460 ext2fs_mark_super_dirty(fs);
1463 * Calculate the number of filesystem blocks per pagesize. If
1464 * fs->blocksize > page_size, set the number of blocks per
1465 * pagesize to 1 to avoid division by zero errors.
1468 sysval = sysconf(_SC_PAGESIZE);
1470 sys_page_size = sysval;
1471 #endif /* _SC_PAGESIZE */
1472 ctx->blocks_per_page = sys_page_size / fs->blocksize;
1473 if (ctx->blocks_per_page == 0)
1474 ctx->blocks_per_page = 1;
1476 if (ctx->superblock)
1477 set_latch_flags(PR_LATCH_RELOC, PRL_LATCHED, 0);
1478 ext2fs_mark_valid(fs);
1479 check_super_block(ctx);
1480 if (ctx->flags & E2F_FLAG_SIGNAL_MASK)
1481 fatal_error(ctx, 0);
1483 check_resize_inode(ctx);
1484 if (bad_blocks_file)
1485 read_bad_blocks_file(ctx, bad_blocks_file, replace_bad_blocks);
1487 read_bad_blocks_file(ctx, 0, !keep_bad_blocks); /* Test disk */
1488 if (ctx->flags & E2F_FLAG_SIGNAL_MASK)
1489 fatal_error(ctx, 0);
1492 * Mark the system as valid, 'til proven otherwise
1494 ext2fs_mark_valid(fs);
1496 retval = ext2fs_read_bb_inode(fs, &fs->badblocks);
1498 com_err(ctx->program_name, retval,
1499 _("while reading bad blocks inode"));
1501 printf(_("This doesn't bode well,"
1502 " but we'll try to go on...\n"));
1506 * Save the journal size in megabytes.
1507 * Try and use the journal size from the backup else let e2fsck
1508 * find the default journal size.
1510 if (sb->s_jnl_backup_type == EXT3_JNL_BACKUP_BLOCKS)
1511 journal_size = (sb->s_jnl_blocks[15] << (32 - 20)) |
1512 (sb->s_jnl_blocks[16] >> 20);
1516 if (sb->s_feature_ro_compat & EXT4_FEATURE_RO_COMPAT_QUOTA) {
1518 /* Quotas were enabled. Do quota accounting during fsck. */
1519 if ((sb->s_usr_quota_inum && sb->s_grp_quota_inum) ||
1520 (!sb->s_usr_quota_inum && !sb->s_grp_quota_inum))
1523 qtype = sb->s_usr_quota_inum ? USRQUOTA : GRPQUOTA;
1525 init_quota_context(&ctx->qctx, ctx->fs, qtype);
1528 run_result = e2fsck_run(ctx);
1529 e2fsck_clear_progbar(ctx);
1531 if (ctx->flags & E2F_FLAG_JOURNAL_INODE) {
1532 if (fix_problem(ctx, PR_6_RECREATE_JOURNAL, &pctx)) {
1533 if (journal_size < 1024)
1534 journal_size = ext2fs_default_journal_size(ext2fs_blocks_count(fs->super));
1535 if (journal_size < 0) {
1536 fs->super->s_feature_compat &=
1537 ~EXT3_FEATURE_COMPAT_HAS_JOURNAL;
1538 fs->flags &= ~EXT2_FLAG_MASTER_SB_ONLY;
1539 com_err(ctx->program_name, 0,
1540 _("Couldn't determine journal size"));
1543 printf(_("Creating journal (%d blocks): "),
1546 retval = ext2fs_add_journal_inode(fs,
1549 com_err("Error ", retval,
1550 _("\n\twhile trying to create journal"));
1553 printf(_(" Done.\n"));
1554 printf(_("\n*** journal has been re-created - "
1555 "filesystem is now ext3 again ***\n"));
1561 write_quota_inode(ctx->qctx, -1);
1562 release_quota_context(&ctx->qctx);
1565 if (run_result == E2F_FLAG_RESTART) {
1566 printf(_("Restarting e2fsck from the beginning...\n"));
1567 retval = e2fsck_reset_context(ctx);
1569 com_err(ctx->program_name, retval,
1570 _("while resetting context"));
1571 fatal_error(ctx, 0);
1576 if (run_result & E2F_FLAG_CANCEL) {
1577 printf(_("%s: e2fsck canceled.\n"), ctx->device_name ?
1578 ctx->device_name : ctx->filesystem_name);
1579 exit_value |= FSCK_CANCELED;
1581 if (run_result & E2F_FLAG_ABORT)
1582 fatal_error(ctx, _("aborted"));
1583 if (check_backup_super_block(ctx)) {
1584 fs->flags &= ~EXT2_FLAG_MASTER_SB_ONLY;
1585 ext2fs_mark_super_dirty(fs);
1589 mtrace_print("Cleanup");
1591 if (ext2fs_test_changed(fs)) {
1592 exit_value |= FSCK_NONDESTRUCT;
1593 if (!(ctx->options & E2F_OPT_PREEN))
1594 printf(_("\n%s: ***** FILE SYSTEM WAS MODIFIED *****\n"),
1596 if (ctx->mount_flags & EXT2_MF_ISROOT) {
1597 printf(_("%s: ***** REBOOT LINUX *****\n"),
1599 exit_value |= FSCK_REBOOT;
1602 if (!ext2fs_test_valid(fs) ||
1603 ((exit_value & FSCK_CANCELED) &&
1604 (sb->s_state & EXT2_ERROR_FS))) {
1605 printf(_("\n%s: ********** WARNING: Filesystem still has "
1606 "errors **********\n\n"), ctx->device_name);
1607 exit_value |= FSCK_UNCORRECTED;
1608 exit_value &= ~FSCK_NONDESTRUCT;
1610 if (exit_value & FSCK_CANCELED) {
1611 int allow_cancellation;
1613 profile_get_boolean(ctx->profile, "options",
1614 "allow_cancellation", 0, 0,
1615 &allow_cancellation);
1616 exit_value &= ~FSCK_NONDESTRUCT;
1617 if (allow_cancellation && ext2fs_test_valid(fs) &&
1618 (sb->s_state & EXT2_VALID_FS) &&
1619 !(sb->s_state & EXT2_ERROR_FS))
1623 if (!(ctx->options & E2F_OPT_READONLY)) {
1624 if (ext2fs_test_valid(fs)) {
1625 if (!(sb->s_state & EXT2_VALID_FS))
1626 exit_value |= FSCK_NONDESTRUCT;
1627 sb->s_state = EXT2_VALID_FS;
1629 sb->s_state &= ~EXT2_VALID_FS;
1630 sb->s_mnt_count = 0;
1631 if (!(ctx->flags & E2F_FLAG_TIME_INSANE))
1632 sb->s_lastcheck = ctx->now;
1633 memset(((char *) sb) + EXT4_S_ERR_START, 0,
1635 ext2fs_mark_super_dirty(fs);
1639 if ((run_result & E2F_FLAG_CANCEL) == 0 &&
1640 sb->s_feature_ro_compat & EXT4_FEATURE_RO_COMPAT_GDT_CSUM &&
1641 !(ctx->options & E2F_OPT_READONLY)) {
1642 retval = ext2fs_set_gdt_csum(ctx->fs);
1644 com_err(ctx->program_name, retval,
1645 _("while setting block group checksum info"));
1646 fatal_error(ctx, 0);
1650 e2fsck_write_bitmaps(ctx);
1651 io_channel_flush(ctx->fs->io);
1652 print_resource_track(ctx, NULL, &ctx->global_rtrack, ctx->fs->io);
1656 free(ctx->journal_name);
1658 e2fsck_free_context(ctx);
1659 remove_error_table(&et_ext2_error_table);
1660 remove_error_table(&et_prof_error_table);