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
36 #include <sys/ioctl.h>
39 #include "et/com_err.h"
42 #include "../version.h"
44 /* Command line options */
45 static int swapfs = 0;
46 static int normalize_swapfs = 0;
47 static int cflag = 0; /* check disk */
48 static int show_version_only = 0;
49 static int verbose = 0;
51 static int replace_bad_blocks = 0;
52 static char *bad_blocks_file = 0;
54 e2fsck_t e2fsck_global_ctx; /* Try your very best not to use this! */
56 #ifdef CONFIG_JBD_DEBUG /* Enabled by configure --enable-jfs-debug */
57 int journal_enable_debug = -1;
60 static void usage(e2fsck_t ctx)
63 _("Usage: %s [-panyrcdfvstDFSV] [-b superblock] [-B blocksize]\n"
64 "\t\t[-I inode_buffer_blocks] [-P process_inode_size]\n"
65 "\t\t[-l|-L bad_blocks_file] [-C fd] [-j ext-journal]\n"
66 "\t\t[-E extended-options] device\n"),
69 fprintf(stderr, _("\nEmergency help:\n"
70 " -p Automatic repair (no questions)\n"
71 " -n Make no changes to the filesystem\n"
72 " -y Assume \"yes\" to all questions\n"
73 " -c Check for bad blocks\n"
74 " -f Force checking even if filesystem is marked clean\n"));
77 " -b superblock Use alternative superblock\n"
78 " -B blocksize Force blocksize when looking for superblock\n"
79 " -j external-journal Set location of the external journal\n"
80 " -l bad_blocks_file Add to badblocks list\n"
81 " -L bad_blocks_file Set badblocks list\n"
87 static void show_stats(e2fsck_t ctx)
89 ext2_filsys fs = ctx->fs;
90 int inodes, inodes_used, blocks, blocks_used;
92 int num_files, num_links;
95 dir_links = 2 * ctx->fs_directory_count - 1;
96 num_files = ctx->fs_total_count - dir_links;
97 num_links = ctx->fs_links_count - dir_links;
98 inodes = fs->super->s_inodes_count;
99 inodes_used = (fs->super->s_inodes_count -
100 fs->super->s_free_inodes_count);
101 blocks = fs->super->s_blocks_count;
102 blocks_used = (fs->super->s_blocks_count -
103 fs->super->s_free_blocks_count);
105 frag_percent = (10000 * ctx->fs_fragmented) / inodes_used;
106 frag_percent = (frag_percent + 5) / 10;
109 printf(_("%s: %d/%d files (%0d.%d%% non-contiguous), %d/%d blocks\n"),
110 ctx->device_name, inodes_used, inodes,
111 frag_percent / 10, frag_percent % 10,
112 blocks_used, blocks);
116 * This is a bit ugly. But I think there will nearly always be more
117 * than one "thing" to report about, so I won't try writing complex
118 * code to handle one/two/many forms of all words.
119 * Some languages (Italian, at least) never uses the plural form
120 * of foreign words, so in real life this could not be a problem.
121 * md@linux.it - 2000-1-15
124 printf (_("\n%8d inodes used (%d%%)\n"), inodes_used,
125 100 * inodes_used / inodes);
126 printf (_("%8d non-contiguous inodes (%0d.%d%%)\n"),
127 ctx->fs_fragmented, frag_percent / 10, frag_percent % 10);
128 printf (_(" # of inodes with ind/dind/tind blocks: %d/%d/%d\n"),
129 ctx->fs_ind_count, ctx->fs_dind_count, ctx->fs_tind_count);
130 printf (_("%8d blocks used (%d%%)\n"
131 "%8d bad blocks\n"), blocks_used,
132 (int) ((long long) 100 * blocks_used / blocks),
133 ctx->fs_badblocks_count);
134 printf(_("%8d large files\n"), ctx->large_files);
135 printf (_("\n%8d regular files\n"
137 "%8d character device files\n"
138 "%8d block device files\n"
141 "%8d symbolic links (%d fast symbolic links)\n"
145 ctx->fs_regular_count,
146 ctx->fs_directory_count,
147 ctx->fs_chardev_count,
148 ctx->fs_blockdev_count,
150 ctx->fs_links_count - dir_links,
151 ctx->fs_symlinks_count,
152 ctx->fs_fast_symlinks_count,
153 ctx->fs_sockets_count,
154 ctx->fs_total_count - dir_links);
156 printf ("\n%8d inode%s used (%d%%)\n", inodes_used,
157 (inodes_used != 1) ? "s" : "",
158 100 * inodes_used / inodes);
159 printf ("%8d non-contiguous inodes (%0d.%d%%)\n",
160 ctx->fs_fragmented, frag_percent / 10, frag_percent % 10);
161 printf (" # of inodes with ind/dind/tind blocks: %d/%d/%d\n",
162 ctx->fs_ind_count, ctx->fs_dind_count, ctx->fs_tind_count);
163 printf ("%8d block%s used (%d%%)\n"
164 "%8d bad block%s\n", blocks_used,
165 (blocks_used != 1) ? "s" : "",
166 100 * blocks_used / blocks, ctx->fs_badblocks_count,
167 ctx->fs_badblocks_count != 1 ? "s" : "");
168 printf(_("%8d large file%s\n"), ctx->large_files,
169 (ctx->large_files != 1) ? "s" : "");
170 printf ("\n%8d regular file%s\n"
172 "%8d character device file%s\n"
173 "%8d block device file%s\n"
176 "%8d symbolic link%s (%d fast symbolic link%s)\n"
180 ctx->fs_regular_count,
181 (ctx->fs_regular_count != 1) ? "s" : "",
182 ctx->fs_directory_count,
183 (ctx->fs_directory_count != 1) ? "ies" : "y",
184 ctx->fs_chardev_count,
185 (ctx->fs_chardev_count != 1) ? "s" : "",
186 ctx->fs_blockdev_count,
187 (ctx->fs_blockdev_count != 1) ? "s" : "",
189 (ctx->fs_fifo_count != 1) ? "s" : "",
190 ctx->fs_links_count - dir_links,
191 ((ctx->fs_links_count - dir_links) != 1) ? "s" : "",
192 ctx->fs_symlinks_count,
193 (ctx->fs_symlinks_count != 1) ? "s" : "",
194 ctx->fs_fast_symlinks_count,
195 (ctx->fs_fast_symlinks_count != 1) ? "s" : "",
196 ctx->fs_sockets_count, (ctx->fs_sockets_count != 1) ? "s" : "",
197 ctx->fs_total_count - dir_links,
198 ((ctx->fs_total_count - dir_links) != 1) ? "s" : "");
202 static void check_mount(e2fsck_t ctx)
207 retval = ext2fs_check_if_mounted(ctx->filesystem_name,
210 com_err("ext2fs_check_if_mount", retval,
211 _("while determining whether %s is mounted."),
212 ctx->filesystem_name);
217 * If the filesystem isn't mounted, or it's the root filesystem
218 * and it's mounted read-only, then everything's fine.
220 if ((!(ctx->mount_flags & EXT2_MF_MOUNTED)) ||
221 ((ctx->mount_flags & EXT2_MF_ISROOT) &&
222 (ctx->mount_flags & EXT2_MF_READONLY)))
225 if (ctx->options & E2F_OPT_READONLY) {
226 printf(_("Warning! %s is mounted.\n"), ctx->filesystem_name);
230 printf(_("%s is mounted. "), ctx->filesystem_name);
231 if (!isatty(0) || !isatty(1))
232 fatal_error(ctx, _("Cannot continue, aborting.\n\n"));
233 printf(_("\n\n\007\007\007\007WARNING!!! "
234 "Running e2fsck on a mounted filesystem may cause\n"
235 "SEVERE filesystem damage.\007\007\007\n\n"));
236 cont = ask_yn(_("Do you really want to continue"), -1);
238 printf (_("check aborted.\n"));
245 * This routine checks to see if a filesystem can be skipped; if so,
246 * it will exit with E2FSCK_OK. Under some conditions it will print a
247 * message explaining why a check is being forced.
249 static void check_if_skip(e2fsck_t ctx)
251 ext2_filsys fs = ctx->fs;
252 const char *reason = NULL;
253 unsigned int reason_arg = 0;
255 if ((ctx->options & E2F_OPT_FORCE) || bad_blocks_file ||
259 if (fs->super->s_state & EXT2_ERROR_FS)
260 reason = _(" contains a file system with errors");
261 else if ((fs->super->s_state & EXT2_VALID_FS) == 0)
262 reason = _(" was not cleanly unmounted");
263 else if ((fs->super->s_max_mnt_count > 0) &&
264 (fs->super->s_mnt_count >=
265 (unsigned) fs->super->s_max_mnt_count)) {
266 reason = _(" has been mounted %u times without being checked");
267 reason_arg = fs->super->s_mnt_count;
268 } else if (fs->super->s_checkinterval &&
269 time(0) >= (fs->super->s_lastcheck +
270 fs->super->s_checkinterval)) {
271 reason = _(" has gone %u days without being checked");
272 reason_arg = (time(0) - fs->super->s_lastcheck)/(3600*24);
275 fputs(ctx->device_name, stdout);
276 printf(reason, reason_arg);
277 fputs(_(", check forced.\n"), stdout);
280 printf(_("%s: clean, %d/%d files, %d/%d blocks\n"), ctx->device_name,
281 fs->super->s_inodes_count - fs->super->s_free_inodes_count,
282 fs->super->s_inodes_count,
283 fs->super->s_blocks_count - fs->super->s_free_blocks_count,
284 fs->super->s_blocks_count);
287 e2fsck_free_context(ctx);
292 * For completion notice
298 struct percent_tbl e2fsck_tbl = {
299 5, { 0, 70, 90, 92, 95, 100 }
302 "==============================================================="
303 "===============================================================";
304 static char spaces[] =
308 static float calc_percent(struct percent_tbl *tbl, int pass, int curr,
315 if (pass > tbl->max_pass || max == 0)
317 percent = ((float) curr) / ((float) max);
318 return ((percent * (tbl->table[pass] - tbl->table[pass-1]))
319 + tbl->table[pass-1]);
322 extern void e2fsck_clear_progbar(e2fsck_t ctx)
324 if (!(ctx->flags & E2F_FLAG_PROG_BAR))
327 printf("%s\r", spaces + (sizeof(spaces) - 80));
328 ctx->flags &= ~E2F_FLAG_PROG_BAR;
331 static int e2fsck_update_progress(e2fsck_t ctx, int pass,
332 unsigned long cur, unsigned long max)
334 static const char spinner[] = "\\|/-";
340 static int dpywidth = 0;
345 if (ctx->progress_fd) {
346 sprintf(buf, "%d %lu %lu\n", pass, cur, max);
347 write(ctx->progress_fd, buf, strlen(buf));
349 if (ctx->flags & E2F_FLAG_PROG_SUPPRESS)
352 dpywidth = 66 - strlen(ctx->device_name);
353 dpywidth = 8 * (dpywidth / 8);
356 * Calculate the new progress position. If the
357 * percentage hasn't changed, then we skip out right
360 percent = calc_percent(&e2fsck_tbl, pass, cur, max);
361 if (ctx->progress_last_percent == (int) 10 * percent)
363 ctx->progress_last_percent = (int) 10 * percent;
366 * If we've already updated the spinner once within
367 * the last 1/8th of a second, no point doing it
370 gettimeofday(&tv, NULL);
371 tick = (tv.tv_sec << 3) + (tv.tv_usec / (1000000 / 8));
372 if ((tick == ctx->progress_last_time) &&
373 (cur != max) && (cur != 0))
375 ctx->progress_last_time = tick;
378 * Advance the spinner, and note that the progress bar
379 * will be on the screen
381 ctx->progress_pos = (ctx->progress_pos+1) & 3;
382 ctx->flags |= E2F_FLAG_PROG_BAR;
384 i = ((percent * dpywidth) + 50) / 100;
385 printf("%s: |%s%s", ctx->device_name,
386 bar + (sizeof(bar) - (i+1)),
387 spaces + (sizeof(spaces) - (dpywidth - i + 1)));
388 if (percent == 100.0)
391 fputc(spinner[ctx->progress_pos & 3], stdout);
392 printf(" %4.1f%% \r", percent);
393 if (percent == 100.0)
394 e2fsck_clear_progbar(ctx);
400 #define PATH_SET "PATH=/sbin"
402 static void reserve_stdio_fds(void)
407 fd = open("/dev/null", O_RDWR);
411 fprintf(stderr, _("ERROR: Couldn't open "
421 static void signal_progress_on(int sig)
423 e2fsck_t ctx = e2fsck_global_ctx;
428 ctx->progress = e2fsck_update_progress;
429 ctx->progress_fd = 0;
432 static void signal_progress_off(int sig)
434 e2fsck_t ctx = e2fsck_global_ctx;
439 e2fsck_clear_progbar(ctx);
443 static void signal_cancel(int sig)
445 e2fsck_t ctx = e2fsck_global_ctx;
450 ctx->flags |= E2F_FLAG_CANCEL;
454 static void parse_extended_opts(e2fsck_t ctx, const char *opts)
456 char *buf, *token, *next, *p, *arg;
458 int extended_usage = 0;
463 fprintf(stderr, _("Couldn't allocate memory to parse "
464 "extended options!\n"));
468 for (token = buf; token && *token; token = next) {
469 p = strchr(token, ',');
475 arg = strchr(token, '=');
480 if (strcmp(token, "ea_ver") == 0) {
485 ea_ver = strtoul(arg, &p, 0);
487 ((ea_ver != 1) && (ea_ver != 2))) {
489 _("Invalid EA version.\n"));
493 ctx->ext_attr_ver = ea_ver;
497 if (extended_usage) {
498 fprintf(stderr, _("Extended options are separated by commas, "
499 "and may take an argument which\n"
500 "is set off by an equals ('=') sign. "
501 "Valid raid options are:\n"
502 "\tea_ver=<ea_version (1 or 2)\n\n"));
508 static errcode_t PRS(int argc, char *argv[], e2fsck_t *ret_ctx)
513 extern void *mallwatch;
520 char *extended_opts = 0;
522 retval = e2fsck_allocate_context(&ctx);
528 setbuf(stdout, NULL);
529 setbuf(stderr, NULL);
530 initialize_ext2_error_table();
533 ctx->program_name = *argv;
535 ctx->program_name = "e2fsck";
536 while ((c = getopt (argc, argv, "panyrcC:B:dE:fvtFVM:b:I:j:P:l:L:N:SsD")) != EOF)
539 ctx->progress = e2fsck_update_progress;
540 ctx->progress_fd = atoi(optarg);
541 if (!ctx->progress_fd)
543 /* Validate the file descriptor to avoid disasters */
544 fd = dup(ctx->progress_fd);
547 _("Error validating file descriptor %d: %s\n"),
549 error_message(errno));
551 _("Invalid completion information file descriptor"));
556 ctx->options |= E2F_OPT_COMPRESS_DIRS;
559 extended_opts = optarg;
563 ctx->options |= E2F_OPT_PREEN;
564 ctx->options &= ~(E2F_OPT_YES|E2F_OPT_NO);
567 ctx->options |= E2F_OPT_NO;
568 ctx->options &= ~(E2F_OPT_YES|E2F_OPT_PREEN);
571 ctx->options |= E2F_OPT_YES;
572 ctx->options &= ~(E2F_OPT_PREEN|E2F_OPT_NO);
575 #ifdef RESOURCE_TRACK
576 if (ctx->options & E2F_OPT_TIME)
577 ctx->options |= E2F_OPT_TIME2;
579 ctx->options |= E2F_OPT_TIME;
581 fprintf(stderr, _("The -t option is not "
582 "supported on this version of e2fsck.\n"));
587 ctx->options |= E2F_OPT_WRITECHECK;
588 ctx->options |= E2F_OPT_CHECKBLOCKS;
591 /* What we do by default, anyway! */
594 ctx->use_superblock = atoi(optarg);
595 ctx->flags |= E2F_FLAG_SB_SPECIFIED;
598 ctx->blocksize = atoi(optarg);
601 ctx->inode_buffer_blocks = atoi(optarg);
604 ctx->journal_name = optarg;
607 ctx->process_inode_size = atoi(optarg);
610 replace_bad_blocks++;
612 bad_blocks_file = (char *) malloc(strlen(optarg)+1);
613 if (!bad_blocks_file)
615 "Couldn't malloc bad_blocks_file");
616 strcpy(bad_blocks_file, optarg);
619 ctx->options |= E2F_OPT_DEBUG;
622 ctx->options |= E2F_OPT_FORCE;
631 show_version_only = 1;
635 mallwatch = (void *) strtol(optarg, NULL, 0);
639 ctx->device_name = optarg;
643 normalize_swapfs = 1;
650 fprintf(stderr, _("Byte-swapping filesystems "
651 "not compiled in this version "
658 if (show_version_only)
660 if (optind != argc - 1)
662 if ((ctx->options & E2F_OPT_NO) && !bad_blocks_file &&
663 !cflag && !swapfs && !(ctx->options & E2F_OPT_COMPRESS_DIRS))
664 ctx->options |= E2F_OPT_READONLY;
665 ctx->filesystem_name = argv[optind];
667 parse_extended_opts(ctx, extended_opts);
670 fd = open(ctx->filesystem_name, O_RDONLY, 0);
672 com_err("open", errno,
673 _("while opening %s for flushing"),
674 ctx->filesystem_name);
677 if ((retval = ext2fs_sync_device(fd, 1))) {
678 com_err("ext2fs_sync_device", retval,
679 _("while trying to flush %s"),
680 ctx->filesystem_name);
687 if (cflag || bad_blocks_file) {
688 fprintf(stderr, _("Incompatible options not "
689 "allowed when byte-swapping.\n"));
694 if (cflag && bad_blocks_file) {
695 fprintf(stderr, _("The -c and the -l/-L options may "
696 "not be both used at the same time.\n"));
701 * Set up signal action
703 memset(&sa, 0, sizeof(struct sigaction));
704 sa.sa_handler = signal_cancel;
705 sigaction(SIGINT, &sa, 0);
706 sigaction(SIGTERM, &sa, 0);
708 sa.sa_flags = SA_RESTART;
710 e2fsck_global_ctx = ctx;
711 sa.sa_handler = signal_progress_on;
712 sigaction(SIGUSR1, &sa, 0);
713 sa.sa_handler = signal_progress_off;
714 sigaction(SIGUSR2, &sa, 0);
717 /* Update our PATH to include /sbin if we need to run badblocks */
719 char *oldpath = getenv("PATH");
723 newpath = (char *) malloc(sizeof (PATH_SET) + 1 +
726 fatal_error(ctx, "Couldn't malloc() newpath");
727 strcpy (newpath, PATH_SET);
728 strcat (newpath, ":");
729 strcat (newpath, oldpath);
734 #ifdef CONFIG_JBD_DEBUG
735 if (getenv("E2FSCK_JBD_DEBUG"))
736 journal_enable_debug = atoi(getenv("E2FSCK_JBD_DEBUG"));
741 static const char *my_ver_string = E2FSPROGS_VERSION;
742 static const char *my_ver_date = E2FSPROGS_DATE;
744 int main (int argc, char *argv[])
746 errcode_t retval = 0;
747 int exit_value = FSCK_OK;
750 struct ext2_super_block *sb;
751 const char *lib_ver_date;
754 struct problem_context pctx;
755 int flags, run_result;
757 clear_problem_context(&pctx);
765 setlocale(LC_MESSAGES, "");
766 setlocale(LC_CTYPE, "");
767 bindtextdomain(NLS_CAT_NAME, LOCALEDIR);
768 textdomain(NLS_CAT_NAME);
770 my_ver = ext2fs_parse_version_string(my_ver_string);
771 lib_ver = ext2fs_get_library_version(0, &lib_ver_date);
772 if (my_ver > lib_ver) {
773 fprintf( stderr, _("Error: ext2fs library version "
778 retval = PRS(argc, argv, &ctx);
780 com_err("e2fsck", retval,
781 _("while trying to initialize program"));
786 #ifdef RESOURCE_TRACK
787 init_resource_track(&ctx->global_rtrack);
790 if (!(ctx->options & E2F_OPT_PREEN) || show_version_only)
791 fprintf (stderr, "e2fsck %s (%s)\n", my_ver_string,
794 if (show_version_only) {
795 fprintf(stderr, _("\tUsing %s, %s\n"),
796 error_message(EXT2_ET_BASE), lib_ver_date);
802 if (!(ctx->options & E2F_OPT_PREEN) &&
803 !(ctx->options & E2F_OPT_NO) &&
804 !(ctx->options & E2F_OPT_YES)) {
805 if (!isatty (0) || !isatty (1))
807 _("need terminal for interactive repairs"));
809 ctx->superblock = ctx->use_superblock;
812 io_ptr = unix_io_manager;
814 io_ptr = test_io_manager;
815 test_io_backing_manager = unix_io_manager;
818 if ((ctx->options & E2F_OPT_READONLY) == 0)
819 flags |= EXT2_FLAG_RW;
821 if (ctx->superblock && ctx->blocksize) {
822 retval = ext2fs_open(ctx->filesystem_name, flags,
823 ctx->superblock, ctx->blocksize,
825 } else if (ctx->superblock) {
827 for (blocksize = EXT2_MIN_BLOCK_SIZE;
828 blocksize <= EXT2_MAX_BLOCK_SIZE; blocksize *= 2) {
829 retval = ext2fs_open(ctx->filesystem_name, flags,
830 ctx->superblock, blocksize,
836 retval = ext2fs_open(ctx->filesystem_name, flags,
838 if (!ctx->superblock && !(ctx->options & E2F_OPT_PREEN) &&
839 !(ctx->flags & E2F_FLAG_SB_SPECIFIED) &&
840 ((retval == EXT2_ET_BAD_MAGIC) ||
841 ((retval == 0) && ext2fs_check_desc(fs)))) {
842 if (!fs || (fs->group_desc_count > 1)) {
843 printf(_("%s trying backup blocks...\n"),
844 retval ? _("Couldn't find ext2 superblock,") :
845 _("Group descriptors look bad..."));
846 get_backup_sb(ctx, fs, ctx->filesystem_name, io_ptr);
853 com_err(ctx->program_name, retval, _("while trying to open %s"),
854 ctx->filesystem_name);
855 if (retval == EXT2_ET_REV_TOO_HIGH) {
856 printf(_("The filesystem revision is apparently "
857 "too high for this version of e2fsck.\n"
858 "(Or the filesystem superblock "
860 fix_problem(ctx, PR_0_SB_CORRUPT, &pctx);
861 } else if (retval == EXT2_ET_SHORT_READ)
862 printf(_("Could this be a zero-length partition?\n"));
863 else if ((retval == EPERM) || (retval == EACCES))
864 printf(_("You must have %s access to the "
865 "filesystem or be root\n"),
866 (ctx->options & E2F_OPT_READONLY) ?
868 else if (retval == ENXIO)
869 printf(_("Possibly non-existent or swap device?\n"));
871 else if (retval == EROFS)
872 printf(_("Disk write-protected; use the -n option "
873 "to do a read-only\n"
874 "check of the device.\n"));
877 fix_problem(ctx, PR_0_SB_CORRUPT, &pctx);
883 if (sb->s_rev_level > E2FSCK_CURRENT_REV) {
884 com_err(ctx->program_name, EXT2_ET_REV_TOO_HIGH,
885 _("while trying to open %s"),
886 ctx->filesystem_name);
888 fatal_error(ctx, _("Get a newer version of e2fsck!"));
892 * Set the device name, which is used whenever we print error
893 * or informational messages to the user.
895 if (ctx->device_name == 0 &&
896 (sb->s_volume_name[0] != 0)) {
897 char *cp = malloc(sizeof(sb->s_volume_name)+1);
899 strncpy(cp, sb->s_volume_name,
900 sizeof(sb->s_volume_name));
901 cp[sizeof(sb->s_volume_name)] = 0;
902 ctx->device_name = cp;
905 if (ctx->device_name == 0)
906 ctx->device_name = ctx->filesystem_name;
909 * Make sure the ext3 superblock fields are consistent.
911 retval = e2fsck_check_ext3_journal(ctx);
913 com_err(ctx->program_name, retval,
914 _("while checking ext3 journal for %s"),
920 * Check to see if we need to do ext3-style recovery. If so,
921 * do it, and then restart the fsck.
923 if (sb->s_feature_incompat & EXT3_FEATURE_INCOMPAT_RECOVER) {
924 if (ctx->options & E2F_OPT_READONLY) {
925 printf(_("Warning: skipping journal recovery "
926 "because doing a read-only filesystem "
928 io_channel_flush(ctx->fs->io);
930 retval = e2fsck_run_ext3_journal(ctx);
932 com_err(ctx->program_name, retval,
933 _("while recovering ext3 journal of %s"),
937 ext2fs_close(ctx->fs);
944 * Check for compatibility with the feature sets. We need to
945 * be more stringent than ext2fs_open().
947 if ((sb->s_feature_compat & ~EXT2_LIB_FEATURE_COMPAT_SUPP) ||
948 (sb->s_feature_incompat & ~EXT2_LIB_FEATURE_INCOMPAT_SUPP)) {
949 com_err(ctx->program_name, EXT2_ET_UNSUPP_FEATURE,
950 "(%s)", ctx->device_name);
953 if (sb->s_feature_ro_compat & ~EXT2_LIB_FEATURE_RO_COMPAT_SUPP) {
954 com_err(ctx->program_name, EXT2_ET_RO_UNSUPP_FEATURE,
955 "(%s)", ctx->device_name);
958 #ifdef ENABLE_COMPRESSION
959 if (sb->s_feature_incompat & EXT2_FEATURE_INCOMPAT_COMPRESSION)
960 com_err(ctx->program_name, 0,
961 _("Warning: compression support is experimental.\n"));
964 if (sb->s_feature_compat & EXT2_FEATURE_COMPAT_DIR_INDEX) {
965 com_err(ctx->program_name, 0,
966 _("E2fsck not compiled with HTREE support,\n\t"
967 "but filesystem %s has HTREE directories.\n"),
974 * If the user specified a specific superblock, presumably the
975 * master superblock has been trashed. So we mark the
976 * superblock as dirty, so it can be written out.
978 if (ctx->superblock &&
979 !(ctx->options & E2F_OPT_READONLY))
980 ext2fs_mark_super_dirty(fs);
983 * We only update the master superblock because (a) paranoia;
984 * we don't want to corrupt the backup superblocks, and (b) we
985 * don't need to update the mount count and last checked
986 * fields in the backup superblock (the kernel doesn't
987 * update the backup superblocks anyway).
989 fs->flags |= EXT2_FLAG_MASTER_SB_ONLY;
991 ehandler_init(fs->io);
994 set_latch_flags(PR_LATCH_RELOC, PRL_LATCHED, 0);
995 check_super_block(ctx);
996 if (ctx->flags & E2F_FLAG_SIGNAL_MASK)
1000 read_bad_blocks_file(ctx, bad_blocks_file, replace_bad_blocks);
1003 if (ctx->flags & E2F_FLAG_SIGNAL_MASK)
1004 fatal_error(ctx, 0);
1005 #ifdef ENABLE_SWAPFS
1006 if (normalize_swapfs) {
1007 if ((fs->flags & EXT2_FLAG_SWAP_BYTES) ==
1008 ext2fs_native_flag()) {
1009 fprintf(stderr, _("%s: Filesystem byte order "
1010 "already normalized.\n"), ctx->device_name);
1011 fatal_error(ctx, 0);
1016 if (ctx->flags & E2F_FLAG_SIGNAL_MASK)
1017 fatal_error(ctx, 0);
1022 * Mark the system as valid, 'til proven otherwise
1024 ext2fs_mark_valid(fs);
1026 retval = ext2fs_read_bb_inode(fs, &fs->badblocks);
1028 com_err(ctx->program_name, retval,
1029 _("while reading bad blocks inode"));
1031 printf(_("This doesn't bode well,"
1032 " but we'll try to go on...\n"));
1035 run_result = e2fsck_run(ctx);
1036 e2fsck_clear_progbar(ctx);
1037 if (run_result == E2F_FLAG_RESTART) {
1038 printf(_("Restarting e2fsck from the beginning...\n"));
1039 retval = e2fsck_reset_context(ctx);
1041 com_err(ctx->program_name, retval,
1042 _("while resetting context"));
1043 fatal_error(ctx, 0);
1048 if (run_result & E2F_FLAG_CANCEL) {
1049 printf(_("%s: e2fsck canceled.\n"), ctx->device_name ?
1050 ctx->device_name : ctx->filesystem_name);
1051 exit_value |= FSCK_CANCELED;
1053 if (run_result & E2F_FLAG_ABORT)
1054 fatal_error(ctx, _("aborted"));
1057 mtrace_print("Cleanup");
1059 if (ext2fs_test_changed(fs)) {
1060 exit_value |= FSCK_NONDESTRUCT;
1061 if (!(ctx->options & E2F_OPT_PREEN))
1062 printf(_("\n%s: ***** FILE SYSTEM WAS MODIFIED *****\n"),
1064 if (ctx->mount_flags & EXT2_MF_ISROOT) {
1065 printf(_("%s: ***** REBOOT LINUX *****\n"),
1067 exit_value |= FSCK_REBOOT;
1070 if (!ext2fs_test_valid(fs)) {
1071 printf(_("\n%s: ********** WARNING: Filesystem still has "
1072 "errors **********\n\n"), ctx->device_name);
1073 exit_value |= FSCK_UNCORRECTED;
1074 exit_value &= ~FSCK_NONDESTRUCT;
1076 if (exit_value & FSCK_CANCELED)
1077 exit_value &= ~FSCK_NONDESTRUCT;
1080 if (!(ctx->options & E2F_OPT_READONLY)) {
1081 if (ext2fs_test_valid(fs)) {
1082 if (!(sb->s_state & EXT2_VALID_FS))
1083 exit_value |= FSCK_NONDESTRUCT;
1084 sb->s_state = EXT2_VALID_FS;
1086 sb->s_state &= ~EXT2_VALID_FS;
1087 sb->s_mnt_count = 0;
1088 sb->s_lastcheck = time(NULL);
1089 ext2fs_mark_super_dirty(fs);
1093 e2fsck_write_bitmaps(ctx);
1097 e2fsck_free_context(ctx);
1099 #ifdef RESOURCE_TRACK
1100 if (ctx->options & E2F_OPT_TIME)
1101 print_resource_track(NULL, &ctx->global_rtrack);