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 puts("\007\007\007\007");
235 printf(_("\n\nWARNING!!! "
236 "The filesystem is mounted. If you continue you ***WILL***\n"
237 "cause ***SEVERE*** filesystem damage.\n\n"));
238 puts("\007\007\007");
239 cont = ask_yn(_("Do you really want to continue"), 0);
241 printf (_("check aborted.\n"));
247 static int is_on_batt(void)
251 char tmp[80], tmp2[80], fname[80];
255 f = fopen("/proc/apm", "r");
257 if (fscanf(f, "%s %s %s %x", tmp, tmp, tmp, &acflag) != 4)
260 return (acflag != 1);
262 d = opendir("/proc/acpi/ac_adapter");
264 while ((de=readdir(d)) != NULL) {
265 if (!strncmp(".", de->d_name, 1))
267 snprintf(fname, 80, "/proc/acpi/ac_adapter/%s/state",
269 f = fopen(fname, "r");
272 if (fscanf(f, "%s %s", tmp2, tmp) != 2)
275 if (strncmp(tmp, "off-line", 8) == 0) {
286 * This routine checks to see if a filesystem can be skipped; if so,
287 * it will exit with E2FSCK_OK. Under some conditions it will print a
288 * message explaining why a check is being forced.
290 static void check_if_skip(e2fsck_t ctx)
292 ext2_filsys fs = ctx->fs;
293 struct problem_context pctx;
294 const char *reason = NULL;
295 unsigned int reason_arg = 0;
297 int batt = is_on_batt();
298 int defer_check_on_battery;
299 int broken_system_clock;
302 profile_get_boolean(ctx->profile, "options", "broken_system_clock",
303 0, 0, &broken_system_clock);
304 if (ctx->flags & E2F_FLAG_TIME_INSANE)
305 broken_system_clock = 1;
306 profile_get_boolean(ctx->profile, "options",
307 "defer_check_on_battery", 0, 1,
308 &defer_check_on_battery);
309 if (!defer_check_on_battery)
312 if ((ctx->options & E2F_OPT_FORCE) || bad_blocks_file || cflag)
315 if (ctx->options & E2F_OPT_JOURNAL_ONLY)
318 lastcheck = fs->super->s_lastcheck;
319 if (lastcheck > ctx->now)
320 lastcheck -= ctx->time_fudge;
321 if ((fs->super->s_state & EXT2_ERROR_FS) ||
322 !ext2fs_test_valid(fs))
323 reason = _(" contains a file system with errors");
324 else if ((fs->super->s_state & EXT2_VALID_FS) == 0)
325 reason = _(" was not cleanly unmounted");
326 else if (check_backup_super_block(ctx))
327 reason = _(" primary superblock features different from backup");
328 else if ((fs->super->s_max_mnt_count > 0) &&
329 (fs->super->s_mnt_count >=
330 (unsigned) fs->super->s_max_mnt_count)) {
331 reason = _(" has been mounted %u times without being checked");
332 reason_arg = fs->super->s_mnt_count;
333 if (batt && (fs->super->s_mnt_count <
334 (unsigned) fs->super->s_max_mnt_count*2))
336 } else if (!broken_system_clock && fs->super->s_checkinterval &&
337 (ctx->now < lastcheck)) {
338 reason = _(" has filesystem last checked time in the future");
341 } else if (!broken_system_clock && fs->super->s_checkinterval &&
342 ((ctx->now - lastcheck) >=
343 ((time_t) fs->super->s_checkinterval))) {
344 reason = _(" has gone %u days without being checked");
345 reason_arg = (ctx->now - fs->super->s_lastcheck)/(3600*24);
346 if (batt && ((ctx->now - fs->super->s_lastcheck) <
347 fs->super->s_checkinterval*2))
351 fputs(ctx->device_name, stdout);
352 printf(reason, reason_arg);
353 fputs(_(", check forced.\n"), stdout);
358 * Update the global counts from the block group counts. This
359 * is needed since modern kernels don't update the global
360 * counts so as to avoid locking the entire file system. So
361 * if the filesystem is not unmounted cleanly, the global
362 * counts may not be accurate. Update them here if we can,
363 * for the benefit of users who might examine the file system
364 * using dumpe2fs. (This is for cosmetic reasons only.)
366 clear_problem_context(&pctx);
367 pctx.ino = fs->super->s_free_inodes_count;
368 pctx.ino2 = ctx->free_inodes;
369 if ((pctx.ino != pctx.ino2) &&
370 !(ctx->options & E2F_OPT_READONLY) &&
371 fix_problem(ctx, PR_0_FREE_INODE_COUNT, &pctx)) {
372 fs->super->s_free_inodes_count = ctx->free_inodes;
373 ext2fs_mark_super_dirty(fs);
375 clear_problem_context(&pctx);
376 pctx.blk = ext2fs_free_blocks_count(fs->super);
377 pctx.blk2 = ctx->free_blocks;
378 if ((pctx.blk != pctx.blk2) &&
379 !(ctx->options & E2F_OPT_READONLY) &&
380 fix_problem(ctx, PR_0_FREE_BLOCK_COUNT, &pctx)) {
381 ext2fs_free_blocks_count_set(fs->super, ctx->free_blocks);
382 ext2fs_mark_super_dirty(fs);
385 /* Print the summary message when we're skipping a full check */
386 printf(_("%s: clean, %u/%u files, %llu/%llu blocks"), ctx->device_name,
387 fs->super->s_inodes_count - fs->super->s_free_inodes_count,
388 fs->super->s_inodes_count,
389 ext2fs_blocks_count(fs->super) -
390 ext2fs_free_blocks_count(fs->super),
391 ext2fs_blocks_count(fs->super));
393 if (fs->super->s_max_mnt_count > 0) {
394 next_check = fs->super->s_max_mnt_count - fs->super->s_mnt_count;
398 if (!broken_system_clock && fs->super->s_checkinterval &&
399 ((ctx->now - fs->super->s_lastcheck) >= fs->super->s_checkinterval))
401 if (next_check <= 5) {
402 if (next_check == 1) {
404 fputs(_(" (check deferred; on battery)"),
407 fputs(_(" (check after next mount)"), stdout);
409 printf(_(" (check in %ld mounts)"), next_check);
415 e2fsck_free_context(ctx);
420 * For completion notice
426 struct percent_tbl e2fsck_tbl = {
427 5, { 0, 70, 90, 92, 95, 100 }
429 static char bar[128], spaces[128];
431 static float calc_percent(struct percent_tbl *tbl, int pass, int curr,
438 if (pass > tbl->max_pass || max == 0)
440 percent = ((float) curr) / ((float) max);
441 return ((percent * (tbl->table[pass] - tbl->table[pass-1]))
442 + tbl->table[pass-1]);
445 extern void e2fsck_clear_progbar(e2fsck_t ctx)
447 if (!(ctx->flags & E2F_FLAG_PROG_BAR))
450 printf("%s%s\r%s", ctx->start_meta, spaces + (sizeof(spaces) - 80),
453 ctx->flags &= ~E2F_FLAG_PROG_BAR;
456 int e2fsck_simple_progress(e2fsck_t ctx, const char *label, float percent,
459 static const char spinner[] = "\\|/-";
466 if (ctx->flags & E2F_FLAG_PROG_SUPPRESS)
470 * Calculate the new progress position. If the
471 * percentage hasn't changed, then we skip out right
474 fixed_percent = (int) ((10 * percent) + 0.5);
475 if (ctx->progress_last_percent == fixed_percent)
477 ctx->progress_last_percent = fixed_percent;
480 * If we've already updated the spinner once within
481 * the last 1/8th of a second, no point doing it
484 gettimeofday(&tv, NULL);
485 tick = (tv.tv_sec << 3) + (tv.tv_usec / (1000000 / 8));
486 if ((tick == ctx->progress_last_time) &&
487 (fixed_percent != 0) && (fixed_percent != 1000))
489 ctx->progress_last_time = tick;
492 * Advance the spinner, and note that the progress bar
493 * will be on the screen
495 ctx->progress_pos = (ctx->progress_pos+1) & 3;
496 ctx->flags |= E2F_FLAG_PROG_BAR;
498 dpywidth = 66 - strlen(label);
499 dpywidth = 8 * (dpywidth / 8);
503 i = ((percent * dpywidth) + 50) / 100;
504 printf("%s%s: |%s%s", ctx->start_meta, label,
505 bar + (sizeof(bar) - (i+1)),
506 spaces + (sizeof(spaces) - (dpywidth - i + 1)));
507 if (fixed_percent == 1000)
510 fputc(spinner[ctx->progress_pos & 3], stdout);
511 printf(" %4.1f%% ", percent);
513 printf("%u\r", dpynum);
515 fputs(" \r", stdout);
516 fputs(ctx->stop_meta, stdout);
518 if (fixed_percent == 1000)
519 e2fsck_clear_progbar(ctx);
525 static int e2fsck_update_progress(e2fsck_t ctx, int pass,
526 unsigned long cur, unsigned long max)
534 if (ctx->progress_fd) {
535 snprintf(buf, sizeof(buf), "%d %lu %lu %s\n",
536 pass, cur, max, ctx->device_name);
537 write_all(ctx->progress_fd, buf, strlen(buf));
539 percent = calc_percent(&e2fsck_tbl, pass, cur, max);
540 e2fsck_simple_progress(ctx, ctx->device_name,
546 #define PATH_SET "PATH=/sbin"
549 * Make sure 0,1,2 file descriptors are open, so that we don't open
550 * the filesystem using the same file descriptor as stdout or stderr.
552 static void reserve_stdio_fds(void)
557 fd = open("/dev/null", O_RDWR);
559 fprintf(stderr, _("ERROR: Couldn't open "
568 static void signal_progress_on(int sig EXT2FS_ATTR((unused)))
570 e2fsck_t ctx = e2fsck_global_ctx;
575 ctx->progress = e2fsck_update_progress;
578 static void signal_progress_off(int sig EXT2FS_ATTR((unused)))
580 e2fsck_t ctx = e2fsck_global_ctx;
585 e2fsck_clear_progbar(ctx);
589 static void signal_cancel(int sig EXT2FS_ATTR((unused)))
591 e2fsck_t ctx = e2fsck_global_ctx;
596 ctx->flags |= E2F_FLAG_CANCEL;
600 static void parse_extended_opts(e2fsck_t ctx, const char *opts)
602 char *buf, *token, *next, *p, *arg;
604 int extended_usage = 0;
606 buf = string_copy(ctx, opts, 0);
607 for (token = buf; token && *token; token = next) {
608 p = strchr(token, ',');
614 arg = strchr(token, '=');
619 if (strcmp(token, "ea_ver") == 0) {
624 ea_ver = strtoul(arg, &p, 0);
626 ((ea_ver != 1) && (ea_ver != 2))) {
628 _("Invalid EA version.\n"));
632 ctx->ext_attr_ver = ea_ver;
633 } else if (strcmp(token, "fragcheck") == 0) {
634 ctx->options |= E2F_OPT_FRAGCHECK;
636 } else if (strcmp(token, "journal_only") == 0) {
641 ctx->options |= E2F_OPT_JOURNAL_ONLY;
642 } else if (strcmp(token, "discard") == 0) {
643 ctx->options |= E2F_OPT_DISCARD;
645 } else if (strcmp(token, "nodiscard") == 0) {
646 ctx->options &= ~E2F_OPT_DISCARD;
649 fprintf(stderr, _("Unknown extended option: %s\n"),
656 if (extended_usage) {
657 fputs(("\nExtended options are separated by commas, "
658 "and may take an argument which\n"
659 "is set off by an equals ('=') sign. "
660 "Valid extended options are:\n"), stderr);
661 fputs(("\tea_ver=<ea_version (1 or 2)>\n"), stderr);
662 fputs(("\tfragcheck\n"), stderr);
663 fputs(("\tjournal_only\n"), stderr);
664 fputs(("\tdiscard\n"), stderr);
665 fputs(("\tnodiscard\n"), stderr);
671 static void syntax_err_report(const char *filename, long err, int line_num)
674 _("Syntax error in e2fsck config file (%s, line #%d)\n\t%s\n"),
675 filename, line_num, error_message(err));
679 static const char *config_fn[] = { ROOT_SYSCONFDIR "/e2fsck.conf", 0 };
681 static errcode_t PRS(int argc, char *argv[], e2fsck_t *ret_ctx)
686 extern void *mallwatch;
693 char *extended_opts = 0;
695 int res; /* result of sscanf */
696 #ifdef CONFIG_JBD_DEBUG
700 retval = e2fsck_allocate_context(&ctx);
706 setvbuf(stdout, NULL, _IONBF, BUFSIZ);
707 setvbuf(stderr, NULL, _IONBF, BUFSIZ);
708 if (isatty(0) && isatty(1)) {
709 ctx->interactive = 1;
711 ctx->start_meta[0] = '\001';
712 ctx->stop_meta[0] = '\002';
714 memset(bar, '=', sizeof(bar)-1);
715 memset(spaces, ' ', sizeof(spaces)-1);
716 add_error_table(&et_ext2_error_table);
717 add_error_table(&et_prof_error_table);
718 blkid_get_cache(&ctx->blkid, NULL);
721 ctx->program_name = *argv;
723 ctx->program_name = "e2fsck";
725 while ((c = getopt (argc, argv, "panyrcC:B:dE:fvtFVM:b:I:j:P:l:L:N:SsDk")) != EOF)
728 ctx->progress = e2fsck_update_progress;
729 res = sscanf(optarg, "%d", &ctx->progress_fd);
733 if (ctx->progress_fd < 0) {
735 ctx->progress_fd = ctx->progress_fd * -1;
737 if (!ctx->progress_fd)
739 /* Validate the file descriptor to avoid disasters */
740 fd = dup(ctx->progress_fd);
743 _("Error validating file descriptor %d: %s\n"),
745 error_message(errno));
747 _("Invalid completion information file descriptor"));
752 ctx->options |= E2F_OPT_COMPRESS_DIRS;
755 extended_opts = optarg;
759 if (ctx->options & (E2F_OPT_YES|E2F_OPT_NO)) {
762 _("Only one of the options -p/-a, -n or -y may be specified."));
764 ctx->options |= E2F_OPT_PREEN;
767 if (ctx->options & (E2F_OPT_YES|E2F_OPT_PREEN))
769 ctx->options |= E2F_OPT_NO;
772 if (ctx->options & (E2F_OPT_PREEN|E2F_OPT_NO))
774 ctx->options |= E2F_OPT_YES;
777 #ifdef RESOURCE_TRACK
778 if (ctx->options & E2F_OPT_TIME)
779 ctx->options |= E2F_OPT_TIME2;
781 ctx->options |= E2F_OPT_TIME;
783 fprintf(stderr, _("The -t option is not "
784 "supported on this version of e2fsck.\n"));
789 ctx->options |= E2F_OPT_WRITECHECK;
790 ctx->options |= E2F_OPT_CHECKBLOCKS;
793 /* What we do by default, anyway! */
796 res = sscanf(optarg, "%llu", &ctx->use_superblock);
799 ctx->flags |= E2F_FLAG_SB_SPECIFIED;
802 ctx->blocksize = atoi(optarg);
805 res = sscanf(optarg, "%d", &ctx->inode_buffer_blocks);
810 ctx->journal_name = blkid_get_devname(ctx->blkid,
812 if (!ctx->journal_name) {
813 com_err(ctx->program_name, 0,
814 _("Unable to resolve '%s'"),
820 res = sscanf(optarg, "%d", &ctx->process_inode_size);
825 replace_bad_blocks++;
827 bad_blocks_file = string_copy(ctx, optarg, 0);
830 ctx->options |= E2F_OPT_DEBUG;
833 ctx->options |= E2F_OPT_FORCE;
842 show_version_only = 1;
846 mallwatch = (void *) strtol(optarg, NULL, 0);
850 ctx->device_name = string_copy(ctx, optarg, 0);
858 if (show_version_only)
860 if (optind != argc - 1)
862 if ((ctx->options & E2F_OPT_NO) &&
863 (ctx->options & E2F_OPT_COMPRESS_DIRS)) {
864 com_err(ctx->program_name, 0,
865 _("The -n and -D options are incompatible."));
868 if ((ctx->options & E2F_OPT_NO) && cflag) {
869 com_err(ctx->program_name, 0,
870 _("The -n and -c options are incompatible."));
873 if ((ctx->options & E2F_OPT_NO) && bad_blocks_file) {
874 com_err(ctx->program_name, 0,
875 _("The -n and -l/-L options are incompatible."));
878 if (ctx->options & E2F_OPT_NO)
879 ctx->options |= E2F_OPT_READONLY;
881 ctx->io_options = strchr(argv[optind], '?');
883 *ctx->io_options++ = 0;
884 ctx->filesystem_name = blkid_get_devname(ctx->blkid, argv[optind], 0);
885 if (!ctx->filesystem_name) {
886 com_err(ctx->program_name, 0, _("Unable to resolve '%s'"),
891 parse_extended_opts(ctx, extended_opts);
893 if ((cp = getenv("E2FSCK_CONFIG")) != NULL)
895 profile_set_syntax_err_cb(syntax_err_report);
896 profile_init(config_fn, &ctx->profile);
899 fd = open(ctx->filesystem_name, O_RDONLY, 0);
901 com_err("open", errno,
902 _("while opening %s for flushing"),
903 ctx->filesystem_name);
906 if ((retval = ext2fs_sync_device(fd, 1))) {
907 com_err("ext2fs_sync_device", retval,
908 _("while trying to flush %s"),
909 ctx->filesystem_name);
914 if (cflag && bad_blocks_file) {
915 fprintf(stderr, _("The -c and the -l/-L options may "
916 "not be both used at the same time.\n"));
921 * Set up signal action
923 memset(&sa, 0, sizeof(struct sigaction));
924 sa.sa_handler = signal_cancel;
925 sigaction(SIGINT, &sa, 0);
926 sigaction(SIGTERM, &sa, 0);
928 sa.sa_flags = SA_RESTART;
930 e2fsck_global_ctx = ctx;
931 sa.sa_handler = signal_progress_on;
932 sigaction(SIGUSR1, &sa, 0);
933 sa.sa_handler = signal_progress_off;
934 sigaction(SIGUSR2, &sa, 0);
937 /* Update our PATH to include /sbin if we need to run badblocks */
939 char *oldpath = getenv("PATH");
941 int len = sizeof(PATH_SET) + 1;
944 len += strlen(oldpath);
946 newpath = malloc(len);
948 fatal_error(ctx, "Couldn't malloc() newpath");
949 strcpy(newpath, PATH_SET);
952 strcat(newpath, ":");
953 strcat(newpath, oldpath);
957 #ifdef CONFIG_JBD_DEBUG
958 jbd_debug = getenv("E2FSCK_JBD_DEBUG");
960 res = sscanf(jbd_debug, "%d", &journal_enable_debug);
963 _("E2FSCK_JBD_DEBUG \"%s\" not an integer\n\n"),
972 fprintf(stderr, _("\nInvalid non-numeric argument to -%c (\"%s\")\n\n"),
977 static errcode_t try_open_fs(e2fsck_t ctx, int flags, io_manager io_ptr,
983 if (ctx->superblock && ctx->blocksize) {
984 retval = ext2fs_open2(ctx->filesystem_name, ctx->io_options,
985 flags, ctx->superblock, ctx->blocksize,
987 } else if (ctx->superblock) {
989 for (blocksize = EXT2_MIN_BLOCK_SIZE;
990 blocksize <= EXT2_MAX_BLOCK_SIZE; blocksize *= 2) {
992 ext2fs_free(*ret_fs);
995 retval = ext2fs_open2(ctx->filesystem_name,
996 ctx->io_options, flags,
997 ctx->superblock, blocksize,
1003 retval = ext2fs_open2(ctx->filesystem_name, ctx->io_options,
1004 flags, 0, 0, io_ptr, ret_fs);
1008 static const char *my_ver_string = E2FSPROGS_VERSION;
1009 static const char *my_ver_date = E2FSPROGS_DATE;
1011 int e2fsck_check_mmp(ext2_filsys fs, e2fsck_t ctx)
1013 struct mmp_struct *mmp_s;
1014 unsigned int mmp_check_interval;
1015 errcode_t retval = 0;
1016 struct problem_context pctx;
1017 unsigned int wait_time = 0;
1019 clear_problem_context(&pctx);
1020 if (fs->mmp_buf == NULL) {
1021 retval = ext2fs_get_mem(fs->blocksize, &fs->mmp_buf);
1026 retval = ext2fs_mmp_read(fs, fs->super->s_mmp_block, fs->mmp_buf);
1030 mmp_s = fs->mmp_buf;
1032 mmp_check_interval = fs->super->s_mmp_update_interval;
1033 if (mmp_check_interval < EXT4_MMP_MIN_CHECK_INTERVAL)
1034 mmp_check_interval = EXT4_MMP_MIN_CHECK_INTERVAL;
1037 * If check_interval in MMP block is larger, use that instead of
1038 * check_interval from the superblock.
1040 if (mmp_s->mmp_check_interval > mmp_check_interval)
1041 mmp_check_interval = mmp_s->mmp_check_interval;
1043 wait_time = mmp_check_interval * 2 + 1;
1045 if (mmp_s->mmp_seq == EXT4_MMP_SEQ_CLEAN)
1047 else if (mmp_s->mmp_seq == EXT4_MMP_SEQ_FSCK)
1048 retval = EXT2_ET_MMP_FSCK_ON;
1049 else if (mmp_s->mmp_seq > EXT4_MMP_SEQ_MAX)
1050 retval = EXT2_ET_MMP_UNKNOWN_SEQ;
1055 /* Print warning if e2fck will wait for more than 20 secs. */
1056 if (verbose || wait_time > EXT4_MMP_MIN_CHECK_INTERVAL * 4) {
1057 printf("MMP interval is %u seconds and total wait time is %u "
1058 "seconds. Please wait...\n",
1059 mmp_check_interval, wait_time * 2);
1066 if (retval == EXT2_ET_MMP_BAD_BLOCK) {
1067 if (fix_problem(ctx, PR_0_MMP_INVALID_BLK, &pctx)) {
1068 fs->super->s_mmp_block = 0;
1069 ext2fs_mark_super_dirty(fs);
1072 } else if (retval == EXT2_ET_MMP_FAILED) {
1073 com_err(ctx->program_name, retval,
1074 _("while checking MMP block"));
1075 dump_mmp_msg(fs->mmp_buf, NULL);
1076 } else if (retval == EXT2_ET_MMP_FSCK_ON ||
1077 retval == EXT2_ET_MMP_UNKNOWN_SEQ) {
1078 com_err(ctx->program_name, retval,
1079 _("while checking MMP block"));
1080 dump_mmp_msg(fs->mmp_buf,
1081 _("If you are sure the filesystem is not "
1082 "in use on any node, run:\n"
1083 "'tune2fs -f -E clear_mmp {device}'\n"));
1084 } else if (retval == EXT2_ET_MMP_MAGIC_INVALID) {
1085 if (fix_problem(ctx, PR_0_MMP_INVALID_MAGIC, &pctx)) {
1086 ext2fs_mmp_clear(fs);
1093 int main (int argc, char *argv[])
1095 errcode_t retval = 0, retval2 = 0, orig_retval = 0;
1096 int exit_value = FSCK_OK;
1099 struct ext2_super_block *sb;
1100 const char *lib_ver_date;
1101 int my_ver, lib_ver;
1103 blk_t orig_superblock;
1104 struct problem_context pctx;
1105 int flags, run_result;
1107 int sysval, sys_page_size = 4096;
1112 clear_problem_context(&pctx);
1121 setlocale(LC_MESSAGES, "");
1122 setlocale(LC_CTYPE, "");
1123 bindtextdomain(NLS_CAT_NAME, LOCALEDIR);
1124 textdomain(NLS_CAT_NAME);
1125 set_com_err_gettext(gettext);
1127 my_ver = ext2fs_parse_version_string(my_ver_string);
1128 lib_ver = ext2fs_get_library_version(0, &lib_ver_date);
1129 if (my_ver > lib_ver) {
1130 fprintf( stderr, _("Error: ext2fs library version "
1132 show_version_only++;
1135 retval = PRS(argc, argv, &ctx);
1137 com_err("e2fsck", retval,
1138 _("while trying to initialize program"));
1141 reserve_stdio_fds();
1143 init_resource_track(&ctx->global_rtrack, NULL);
1144 if (!(ctx->options & E2F_OPT_PREEN) || show_version_only)
1145 fprintf(stderr, "e2fsck %s (%s)\n", my_ver_string,
1148 if (show_version_only) {
1149 fprintf(stderr, _("\tUsing %s, %s\n"),
1150 error_message(EXT2_ET_BASE), lib_ver_date);
1156 if (!(ctx->options & E2F_OPT_PREEN) &&
1157 !(ctx->options & E2F_OPT_NO) &&
1158 !(ctx->options & E2F_OPT_YES)) {
1159 if (!ctx->interactive)
1161 _("need terminal for interactive repairs"));
1163 ctx->superblock = ctx->use_superblock;
1165 flags = EXT2_FLAG_SKIP_MMP;
1167 #ifdef CONFIG_TESTIO_DEBUG
1168 if (getenv("TEST_IO_FLAGS") || getenv("TEST_IO_BLOCK")) {
1169 io_ptr = test_io_manager;
1170 test_io_backing_manager = unix_io_manager;
1173 io_ptr = unix_io_manager;
1174 flags |= EXT2_FLAG_NOFREE_ON_ERROR;
1175 profile_get_boolean(ctx->profile, "options", "old_bitmaps", 0, 0,
1178 flags |= EXT2_FLAG_64BITS;
1179 if ((ctx->options & E2F_OPT_READONLY) == 0)
1180 flags |= EXT2_FLAG_RW;
1181 if ((ctx->mount_flags & EXT2_MF_MOUNTED) == 0)
1182 flags |= EXT2_FLAG_EXCLUSIVE;
1184 retval = try_open_fs(ctx, flags, io_ptr, &fs);
1186 if (!ctx->superblock && !(ctx->options & E2F_OPT_PREEN) &&
1187 !(ctx->flags & E2F_FLAG_SB_SPECIFIED) &&
1188 ((retval == EXT2_ET_BAD_MAGIC) ||
1189 (retval == EXT2_ET_CORRUPT_SUPERBLOCK) ||
1190 ((retval == 0) && (retval2 = ext2fs_check_desc(fs))))) {
1191 if (retval2 == ENOMEM) {
1195 if (fs->flags & EXT2_FLAG_NOFREE_ON_ERROR) {
1199 if (!fs || (fs->group_desc_count > 1)) {
1200 printf(_("%s: %s trying backup blocks...\n"),
1202 retval ? _("Superblock invalid,") :
1203 _("Group descriptors look bad..."));
1204 orig_superblock = ctx->superblock;
1205 get_backup_sb(ctx, fs, ctx->filesystem_name, io_ptr);
1208 orig_retval = retval;
1209 retval = try_open_fs(ctx, flags, io_ptr, &fs);
1210 if ((orig_retval == 0) && retval != 0) {
1213 com_err(ctx->program_name, retval,
1214 "when using the backup blocks");
1215 printf(_("%s: going back to original "
1216 "superblock\n"), ctx->program_name);
1217 ctx->superblock = orig_superblock;
1218 retval = try_open_fs(ctx, flags, io_ptr, &fs);
1222 if (((retval == EXT2_ET_UNSUPP_FEATURE) ||
1223 (retval == EXT2_ET_RO_UNSUPP_FEATURE)) &&
1226 features[0] = (sb->s_feature_compat &
1227 ~EXT2_LIB_FEATURE_COMPAT_SUPP);
1228 features[1] = (sb->s_feature_incompat &
1229 ~EXT2_LIB_FEATURE_INCOMPAT_SUPP);
1230 features[2] = (sb->s_feature_ro_compat &
1231 ~EXT2_LIB_FEATURE_RO_COMPAT_SUPP);
1232 if (features[0] || features[1] || features[2])
1233 goto print_unsupp_features;
1238 retval = orig_retval;
1239 com_err(ctx->program_name, retval, _("while trying to open %s"),
1240 ctx->filesystem_name);
1241 if (retval == EXT2_ET_REV_TOO_HIGH) {
1242 printf(_("The filesystem revision is apparently "
1243 "too high for this version of e2fsck.\n"
1244 "(Or the filesystem superblock "
1245 "is corrupt)\n\n"));
1246 fix_problem(ctx, PR_0_SB_CORRUPT, &pctx);
1247 } else if (retval == EXT2_ET_SHORT_READ)
1248 printf(_("Could this be a zero-length partition?\n"));
1249 else if ((retval == EPERM) || (retval == EACCES))
1250 printf(_("You must have %s access to the "
1251 "filesystem or be root\n"),
1252 (ctx->options & E2F_OPT_READONLY) ?
1254 else if (retval == ENXIO)
1255 printf(_("Possibly non-existent or swap device?\n"));
1256 else if (retval == EBUSY)
1257 printf(_("Filesystem mounted or opened exclusively "
1258 "by another program?\n"));
1259 else if (retval == ENOENT)
1260 printf(_("Possibly non-existent device?\n"));
1262 else if (retval == EROFS)
1263 printf(_("Disk write-protected; use the -n option "
1264 "to do a read-only\n"
1265 "check of the device.\n"));
1268 fix_problem(ctx, PR_0_SB_CORRUPT, &pctx);
1269 fatal_error(ctx, 0);
1272 * We only update the master superblock because (a) paranoia;
1273 * we don't want to corrupt the backup superblocks, and (b) we
1274 * don't need to update the mount count and last checked
1275 * fields in the backup superblock (the kernel doesn't update
1276 * the backup superblocks anyway). With newer versions of the
1277 * library this flag is set by ext2fs_open2(), but we set this
1278 * here just to be sure. (No, we don't support e2fsck running
1279 * with some other libext2fs than the one that it was shipped
1280 * with, but just in case....)
1282 fs->flags |= EXT2_FLAG_MASTER_SB_ONLY;
1284 if (!(ctx->flags & E2F_FLAG_GOT_DEVSIZE)) {
1285 __u32 blocksize = EXT2_BLOCK_SIZE(fs->super);
1286 int need_restart = 0;
1288 pctx.errcode = ext2fs_get_device_size2(ctx->filesystem_name,
1292 * The floppy driver refuses to allow anyone else to
1293 * open the device if has been opened with O_EXCL;
1294 * this is unlike other block device drivers in Linux.
1295 * To handle this, we close the filesystem and then
1296 * reopen the filesystem after we get the device size.
1298 if (pctx.errcode == EBUSY) {
1302 ext2fs_get_device_size2(ctx->filesystem_name,
1306 if (pctx.errcode == EXT2_ET_UNIMPLEMENTED)
1307 ctx->num_blocks = 0;
1308 else if (pctx.errcode) {
1309 fix_problem(ctx, PR_0_GETSIZE_ERROR, &pctx);
1310 ctx->flags |= E2F_FLAG_ABORT;
1311 fatal_error(ctx, 0);
1313 ctx->flags |= E2F_FLAG_GOT_DEVSIZE;
1319 fs->priv_data = ctx;
1322 if (sb->s_rev_level > E2FSCK_CURRENT_REV) {
1323 com_err(ctx->program_name, EXT2_ET_REV_TOO_HIGH,
1324 _("while trying to open %s"),
1325 ctx->filesystem_name);
1327 fatal_error(ctx, _("Get a newer version of e2fsck!"));
1331 * Set the device name, which is used whenever we print error
1332 * or informational messages to the user.
1334 if (ctx->device_name == 0 &&
1335 (sb->s_volume_name[0] != 0)) {
1336 ctx->device_name = string_copy(ctx, sb->s_volume_name,
1337 sizeof(sb->s_volume_name));
1339 if (ctx->device_name == 0)
1340 ctx->device_name = string_copy(ctx, ctx->filesystem_name, 0);
1341 for (cp = ctx->device_name; *cp; cp++)
1342 if (isspace(*cp) || *cp == ':')
1345 ehandler_init(fs->io);
1347 if ((fs->super->s_feature_incompat & EXT4_FEATURE_INCOMPAT_MMP) &&
1348 (flags & EXT2_FLAG_SKIP_MMP)) {
1349 if (e2fsck_check_mmp(fs, ctx))
1350 fatal_error(ctx, 0);
1354 * Restart in order to reopen fs but this time start mmp.
1356 if (flags & EXT2_FLAG_SKIP_MMP) {
1359 flags &= ~EXT2_FLAG_SKIP_MMP;
1363 if ((ctx->mount_flags & EXT2_MF_MOUNTED) &&
1364 !(sb->s_feature_incompat & EXT3_FEATURE_INCOMPAT_RECOVER))
1368 * Make sure the ext3 superblock fields are consistent.
1370 retval = e2fsck_check_ext3_journal(ctx);
1372 com_err(ctx->program_name, retval,
1373 _("while checking ext3 journal for %s"),
1375 fatal_error(ctx, 0);
1379 * Check to see if we need to do ext3-style recovery. If so,
1380 * do it, and then restart the fsck.
1382 if (sb->s_feature_incompat & EXT3_FEATURE_INCOMPAT_RECOVER) {
1383 if (ctx->options & E2F_OPT_READONLY) {
1384 printf(_("Warning: skipping journal recovery "
1385 "because doing a read-only filesystem "
1387 io_channel_flush(ctx->fs->io);
1389 if (ctx->flags & E2F_FLAG_RESTARTED) {
1391 * Whoops, we attempted to run the
1392 * journal twice. This should never
1393 * happen, unless the hardware or
1394 * device driver is being bogus.
1396 com_err(ctx->program_name, 0,
1397 _("unable to set superblock flags on %s\n"), ctx->device_name);
1398 fatal_error(ctx, 0);
1400 retval = e2fsck_run_ext3_journal(ctx);
1402 com_err(ctx->program_name, retval,
1403 _("while recovering ext3 journal of %s"),
1405 fatal_error(ctx, 0);
1407 ext2fs_close(ctx->fs);
1409 ctx->flags |= E2F_FLAG_RESTARTED;
1416 * Check for compatibility with the feature sets. We need to
1417 * be more stringent than ext2fs_open().
1419 features[0] = sb->s_feature_compat & ~EXT2_LIB_FEATURE_COMPAT_SUPP;
1420 features[1] = sb->s_feature_incompat & ~EXT2_LIB_FEATURE_INCOMPAT_SUPP;
1421 features[2] = (sb->s_feature_ro_compat &
1422 ~EXT2_LIB_FEATURE_RO_COMPAT_SUPP);
1423 print_unsupp_features:
1424 if (features[0] || features[1] || features[2]) {
1426 __u32 *mask = features, m;
1428 fprintf(stderr, _("%s has unsupported feature(s):"),
1429 ctx->filesystem_name);
1431 for (i=0; i <3; i++,mask++) {
1432 for (j=0,m=1; j < 32; j++, m<<=1) {
1434 fprintf(stderr, " %s",
1435 e2p_feature2string(i, m));
1441 #ifdef ENABLE_COMPRESSION
1442 if (sb->s_feature_incompat & EXT2_FEATURE_INCOMPAT_COMPRESSION)
1443 com_err(ctx->program_name, 0,
1444 _("Warning: compression support is experimental.\n"));
1446 #ifndef ENABLE_HTREE
1447 if (sb->s_feature_compat & EXT2_FEATURE_COMPAT_DIR_INDEX) {
1448 com_err(ctx->program_name, 0,
1449 _("E2fsck not compiled with HTREE support,\n\t"
1450 "but filesystem %s has HTREE directories.\n"),
1457 * If the user specified a specific superblock, presumably the
1458 * master superblock has been trashed. So we mark the
1459 * superblock as dirty, so it can be written out.
1461 if (ctx->superblock &&
1462 !(ctx->options & E2F_OPT_READONLY))
1463 ext2fs_mark_super_dirty(fs);
1466 * Calculate the number of filesystem blocks per pagesize. If
1467 * fs->blocksize > page_size, set the number of blocks per
1468 * pagesize to 1 to avoid division by zero errors.
1471 sysval = sysconf(_SC_PAGESIZE);
1473 sys_page_size = sysval;
1474 #endif /* _SC_PAGESIZE */
1475 ctx->blocks_per_page = sys_page_size / fs->blocksize;
1476 if (ctx->blocks_per_page == 0)
1477 ctx->blocks_per_page = 1;
1479 if (ctx->superblock)
1480 set_latch_flags(PR_LATCH_RELOC, PRL_LATCHED, 0);
1481 ext2fs_mark_valid(fs);
1482 check_super_block(ctx);
1483 if (ctx->flags & E2F_FLAG_SIGNAL_MASK)
1484 fatal_error(ctx, 0);
1486 check_resize_inode(ctx);
1487 if (bad_blocks_file)
1488 read_bad_blocks_file(ctx, bad_blocks_file, replace_bad_blocks);
1490 read_bad_blocks_file(ctx, 0, !keep_bad_blocks); /* Test disk */
1491 if (ctx->flags & E2F_FLAG_SIGNAL_MASK)
1492 fatal_error(ctx, 0);
1495 * Mark the system as valid, 'til proven otherwise
1497 ext2fs_mark_valid(fs);
1499 retval = ext2fs_read_bb_inode(fs, &fs->badblocks);
1501 com_err(ctx->program_name, retval,
1502 _("while reading bad blocks inode"));
1504 printf(_("This doesn't bode well,"
1505 " but we'll try to go on...\n"));
1509 * Save the journal size in megabytes.
1510 * Try and use the journal size from the backup else let e2fsck
1511 * find the default journal size.
1513 if (sb->s_jnl_backup_type == EXT3_JNL_BACKUP_BLOCKS)
1514 journal_size = (sb->s_jnl_blocks[15] << (32 - 20)) |
1515 (sb->s_jnl_blocks[16] >> 20);
1519 if (sb->s_feature_ro_compat & EXT4_FEATURE_RO_COMPAT_QUOTA) {
1521 /* Quotas were enabled. Do quota accounting during fsck. */
1522 if ((sb->s_usr_quota_inum && sb->s_grp_quota_inum) ||
1523 (!sb->s_usr_quota_inum && !sb->s_grp_quota_inum))
1526 qtype = sb->s_usr_quota_inum ? USRQUOTA : GRPQUOTA;
1528 init_quota_context(&ctx->qctx, ctx->fs, qtype);
1531 run_result = e2fsck_run(ctx);
1532 e2fsck_clear_progbar(ctx);
1534 if (ctx->flags & E2F_FLAG_JOURNAL_INODE) {
1535 if (fix_problem(ctx, PR_6_RECREATE_JOURNAL, &pctx)) {
1536 if (journal_size < 1024)
1537 journal_size = ext2fs_default_journal_size(ext2fs_blocks_count(fs->super));
1538 if (journal_size < 0) {
1539 fs->super->s_feature_compat &=
1540 ~EXT3_FEATURE_COMPAT_HAS_JOURNAL;
1541 fs->flags &= ~EXT2_FLAG_MASTER_SB_ONLY;
1542 com_err(ctx->program_name, 0,
1543 _("Couldn't determine journal size"));
1546 printf(_("Creating journal (%d blocks): "),
1549 retval = ext2fs_add_journal_inode(fs,
1552 com_err("Error ", retval,
1553 _("\n\twhile trying to create journal"));
1556 printf(_(" Done.\n"));
1557 printf(_("\n*** journal has been re-created - "
1558 "filesystem is now ext3 again ***\n"));
1564 write_quota_inode(ctx->qctx, -1);
1565 release_quota_context(&ctx->qctx);
1568 if (run_result == E2F_FLAG_RESTART) {
1569 printf(_("Restarting e2fsck from the beginning...\n"));
1570 retval = e2fsck_reset_context(ctx);
1572 com_err(ctx->program_name, retval,
1573 _("while resetting context"));
1574 fatal_error(ctx, 0);
1579 if (run_result & E2F_FLAG_CANCEL) {
1580 printf(_("%s: e2fsck canceled.\n"), ctx->device_name ?
1581 ctx->device_name : ctx->filesystem_name);
1582 exit_value |= FSCK_CANCELED;
1584 if (run_result & E2F_FLAG_ABORT)
1585 fatal_error(ctx, _("aborted"));
1586 if (check_backup_super_block(ctx)) {
1587 fs->flags &= ~EXT2_FLAG_MASTER_SB_ONLY;
1588 ext2fs_mark_super_dirty(fs);
1592 mtrace_print("Cleanup");
1594 if (ext2fs_test_changed(fs)) {
1595 exit_value |= FSCK_NONDESTRUCT;
1596 if (!(ctx->options & E2F_OPT_PREEN))
1597 printf(_("\n%s: ***** FILE SYSTEM WAS MODIFIED *****\n"),
1599 if (ctx->mount_flags & EXT2_MF_ISROOT) {
1600 printf(_("%s: ***** REBOOT LINUX *****\n"),
1602 exit_value |= FSCK_REBOOT;
1605 if (!ext2fs_test_valid(fs) ||
1606 ((exit_value & FSCK_CANCELED) &&
1607 (sb->s_state & EXT2_ERROR_FS))) {
1608 printf(_("\n%s: ********** WARNING: Filesystem still has "
1609 "errors **********\n\n"), ctx->device_name);
1610 exit_value |= FSCK_UNCORRECTED;
1611 exit_value &= ~FSCK_NONDESTRUCT;
1613 if (exit_value & FSCK_CANCELED) {
1614 int allow_cancellation;
1616 profile_get_boolean(ctx->profile, "options",
1617 "allow_cancellation", 0, 0,
1618 &allow_cancellation);
1619 exit_value &= ~FSCK_NONDESTRUCT;
1620 if (allow_cancellation && ext2fs_test_valid(fs) &&
1621 (sb->s_state & EXT2_VALID_FS) &&
1622 !(sb->s_state & EXT2_ERROR_FS))
1626 if (!(ctx->options & E2F_OPT_READONLY)) {
1627 if (ext2fs_test_valid(fs)) {
1628 if (!(sb->s_state & EXT2_VALID_FS))
1629 exit_value |= FSCK_NONDESTRUCT;
1630 sb->s_state = EXT2_VALID_FS;
1632 sb->s_state &= ~EXT2_VALID_FS;
1633 sb->s_mnt_count = 0;
1634 if (!(ctx->flags & E2F_FLAG_TIME_INSANE))
1635 sb->s_lastcheck = ctx->now;
1636 memset(((char *) sb) + EXT4_S_ERR_START, 0,
1638 ext2fs_mark_super_dirty(fs);
1642 if ((run_result & E2F_FLAG_CANCEL) == 0 &&
1643 sb->s_feature_ro_compat & EXT4_FEATURE_RO_COMPAT_GDT_CSUM &&
1644 !(ctx->options & E2F_OPT_READONLY)) {
1645 retval = ext2fs_set_gdt_csum(ctx->fs);
1647 com_err(ctx->program_name, retval,
1648 _("while setting block group checksum info"));
1649 fatal_error(ctx, 0);
1653 e2fsck_write_bitmaps(ctx);
1654 io_channel_flush(ctx->fs->io);
1655 print_resource_track(ctx, NULL, &ctx->global_rtrack, ctx->fs->io);
1659 free(ctx->journal_name);
1661 e2fsck_free_context(ctx);
1662 remove_error_table(&et_ext2_error_table);
1663 remove_error_table(&et_prof_error_table);