| Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 1 | /* |
| 2 | * unix.c - The unix-specific code for e2fsck |
| 3 | * |
| 4 | * Copyright (C) 1993, 1994, 1995, 1996, 1997 Theodore Ts'o. |
| 5 | * |
| 6 | * %Begin-Header% |
| 7 | * This file may be redistributed under the terms of the GNU Public |
| 8 | * License. |
| 9 | * %End-Header% |
| 10 | */ |
| 11 | |
| 12 | #include <stdio.h> |
| 13 | #ifdef HAVE_STDLIB_H |
| 14 | #include <stdlib.h> |
| 15 | #endif |
| 16 | #include <string.h> |
| 17 | #include <fcntl.h> |
| 18 | #include <ctype.h> |
| Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 19 | #include <time.h> |
| Theodore Ts'o | 9ecd8be | 1999-10-20 18:24:31 +0000 | [diff] [blame] | 20 | #ifdef HAVE_SIGNAL_H |
| Theodore Ts'o | 5596def | 1999-07-19 15:27:37 +0000 | [diff] [blame] | 21 | #include <signal.h> |
| Theodore Ts'o | 9ecd8be | 1999-10-20 18:24:31 +0000 | [diff] [blame] | 22 | #endif |
| Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 23 | #ifdef HAVE_GETOPT_H |
| 24 | #include <getopt.h> |
| Theodore Ts'o | 373b833 | 2000-04-03 16:22:35 +0000 | [diff] [blame] | 25 | #else |
| 26 | extern char *optarg; |
| 27 | extern int optind; |
| Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 28 | #endif |
| 29 | #include <unistd.h> |
| 30 | #ifdef HAVE_ERRNO_H |
| 31 | #include <errno.h> |
| 32 | #endif |
| 33 | #ifdef HAVE_MNTENT_H |
| 34 | #include <mntent.h> |
| 35 | #endif |
| Theodore Ts'o | fff4548 | 2003-04-13 00:44:19 -0400 | [diff] [blame] | 36 | #ifdef HAVE_SYS_IOCTL_H |
| Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 37 | #include <sys/ioctl.h> |
| Theodore Ts'o | fff4548 | 2003-04-13 00:44:19 -0400 | [diff] [blame] | 38 | #endif |
| Theodore Ts'o | e71d873 | 2003-03-14 02:13:48 -0500 | [diff] [blame] | 39 | #ifdef HAVE_MALLOC_H |
| Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 40 | #include <malloc.h> |
| Theodore Ts'o | e71d873 | 2003-03-14 02:13:48 -0500 | [diff] [blame] | 41 | #endif |
| Theodore Ts'o | c07f9f2 | 2004-04-12 00:16:44 -0400 | [diff] [blame] | 42 | #ifdef HAVE_SYS_TYPES_H |
| 43 | #include <sys/types.h> |
| 44 | #endif |
| 45 | #ifdef HAVE_DIRENT_H |
| 46 | #include <dirent.h> |
| 47 | #endif |
| Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 48 | |
| 49 | #include "et/com_err.h" |
| 50 | #include "e2fsck.h" |
| 51 | #include "problem.h" |
| 52 | #include "../version.h" |
| 53 | |
| Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 54 | /* Command line options */ |
| Theodore Ts'o | 54a31a3 | 2003-08-19 10:08:34 -0400 | [diff] [blame] | 55 | static int swapfs; |
| 56 | static int normalize_swapfs; |
| 57 | static int cflag; /* check disk */ |
| 58 | static int show_version_only; |
| 59 | static int verbose; |
| Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 60 | |
| Theodore Ts'o | 54a31a3 | 2003-08-19 10:08:34 -0400 | [diff] [blame] | 61 | static int replace_bad_blocks; |
| Theodore Ts'o | 4fb9d52 | 2004-02-24 00:16:09 -0500 | [diff] [blame] | 62 | static int keep_bad_blocks; |
| Theodore Ts'o | 54a31a3 | 2003-08-19 10:08:34 -0400 | [diff] [blame] | 63 | static char *bad_blocks_file; |
| Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 64 | |
| Theodore Ts'o | 243dc31 | 2000-08-22 21:37:47 +0000 | [diff] [blame] | 65 | e2fsck_t e2fsck_global_ctx; /* Try your very best not to use this! */ |
| 66 | |
| Theodore Ts'o | 5e72cdb | 2002-11-08 15:35:13 -0500 | [diff] [blame] | 67 | #ifdef CONFIG_JBD_DEBUG /* Enabled by configure --enable-jfs-debug */ |
| 68 | int journal_enable_debug = -1; |
| 69 | #endif |
| 70 | |
| Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 71 | static void usage(e2fsck_t ctx) |
| 72 | { |
| 73 | fprintf(stderr, |
| Theodore Ts'o | 4fd6834 | 2002-10-31 19:39:03 -0500 | [diff] [blame] | 74 | _("Usage: %s [-panyrcdfvstDFSV] [-b superblock] [-B blocksize]\n" |
| Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 75 | "\t\t[-I inode_buffer_blocks] [-P process_inode_size]\n" |
| Theodore Ts'o | 0684a4f | 2002-08-17 10:19:44 -0400 | [diff] [blame] | 76 | "\t\t[-l|-L bad_blocks_file] [-C fd] [-j ext-journal]\n" |
| 77 | "\t\t[-E extended-options] device\n"), |
| Theodore Ts'o | 5596def | 1999-07-19 15:27:37 +0000 | [diff] [blame] | 78 | ctx->program_name); |
| Theodore Ts'o | b55199e | 1999-07-19 15:37:46 +0000 | [diff] [blame] | 79 | |
| Theodore Ts'o | 0c4a072 | 2000-02-07 03:11:03 +0000 | [diff] [blame] | 80 | fprintf(stderr, _("\nEmergency help:\n" |
| Theodore Ts'o | b55199e | 1999-07-19 15:37:46 +0000 | [diff] [blame] | 81 | " -p Automatic repair (no questions)\n" |
| 82 | " -n Make no changes to the filesystem\n" |
| 83 | " -y Assume \"yes\" to all questions\n" |
| Theodore Ts'o | 19445ef | 2003-01-29 21:04:52 -0500 | [diff] [blame] | 84 | " -c Check for bad blocks and add them to the badblock list\n" |
| Theodore Ts'o | 53ef44c | 2001-01-06 05:55:58 +0000 | [diff] [blame] | 85 | " -f Force checking even if filesystem is marked clean\n")); |
| 86 | fprintf(stderr, _("" |
| Theodore Ts'o | b55199e | 1999-07-19 15:37:46 +0000 | [diff] [blame] | 87 | " -v Be verbose\n" |
| 88 | " -b superblock Use alternative superblock\n" |
| 89 | " -B blocksize Force blocksize when looking for superblock\n" |
| Theodore Ts'o | adee8d7 | 2001-07-23 00:17:49 -0400 | [diff] [blame] | 90 | " -j external-journal Set location of the external journal\n" |
| Theodore Ts'o | b55199e | 1999-07-19 15:37:46 +0000 | [diff] [blame] | 91 | " -l bad_blocks_file Add to badblocks list\n" |
| 92 | " -L bad_blocks_file Set badblocks list\n" |
| Theodore Ts'o | 0c4a072 | 2000-02-07 03:11:03 +0000 | [diff] [blame] | 93 | )); |
| Theodore Ts'o | b55199e | 1999-07-19 15:37:46 +0000 | [diff] [blame] | 94 | |
| Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 95 | exit(FSCK_USAGE); |
| 96 | } |
| 97 | |
| 98 | static void show_stats(e2fsck_t ctx) |
| 99 | { |
| 100 | ext2_filsys fs = ctx->fs; |
| 101 | int inodes, inodes_used, blocks, blocks_used; |
| 102 | int dir_links; |
| 103 | int num_files, num_links; |
| 104 | int frag_percent; |
| 105 | |
| 106 | dir_links = 2 * ctx->fs_directory_count - 1; |
| 107 | num_files = ctx->fs_total_count - dir_links; |
| 108 | num_links = ctx->fs_links_count - dir_links; |
| 109 | inodes = fs->super->s_inodes_count; |
| 110 | inodes_used = (fs->super->s_inodes_count - |
| 111 | fs->super->s_free_inodes_count); |
| 112 | blocks = fs->super->s_blocks_count; |
| 113 | blocks_used = (fs->super->s_blocks_count - |
| 114 | fs->super->s_free_blocks_count); |
| 115 | |
| 116 | frag_percent = (10000 * ctx->fs_fragmented) / inodes_used; |
| 117 | frag_percent = (frag_percent + 5) / 10; |
| 118 | |
| 119 | if (!verbose) { |
| Theodore Ts'o | 0c4a072 | 2000-02-07 03:11:03 +0000 | [diff] [blame] | 120 | printf(_("%s: %d/%d files (%0d.%d%% non-contiguous), %d/%d blocks\n"), |
| Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 121 | ctx->device_name, inodes_used, inodes, |
| 122 | frag_percent / 10, frag_percent % 10, |
| 123 | blocks_used, blocks); |
| 124 | return; |
| 125 | } |
| Theodore Ts'o | 113e405 | 2003-05-17 21:00:46 -0400 | [diff] [blame] | 126 | printf (P_("\n%8d inode used (%d%%)\n", "\n%8d inodes used (%d%%)\n", |
| 127 | inodes_used), inodes_used, 100 * inodes_used / inodes); |
| 128 | printf (P_("%8d non-contiguous inode (%0d.%d%%)\n", |
| 129 | "%8d non-contiguous inodes (%0d.%d%%)\n", |
| 130 | ctx->fs_fragmented), |
| Theodore Ts'o | 0c4a072 | 2000-02-07 03:11:03 +0000 | [diff] [blame] | 131 | ctx->fs_fragmented, frag_percent / 10, frag_percent % 10); |
| 132 | printf (_(" # of inodes with ind/dind/tind blocks: %d/%d/%d\n"), |
| 133 | ctx->fs_ind_count, ctx->fs_dind_count, ctx->fs_tind_count); |
| Theodore Ts'o | 113e405 | 2003-05-17 21:00:46 -0400 | [diff] [blame] | 134 | printf (P_("%8d block used (%d%%)\n", "%8d blocks used (%d%%)\n", |
| 135 | blocks_used), |
| 136 | blocks_used, (int) ((long long) 100 * blocks_used / blocks)); |
| 137 | printf (P_("%8d bad block\n", "%8d bad blocks\n", |
| 138 | ctx->fs_badblocks_count), ctx->fs_badblocks_count); |
| 139 | printf (P_("%8d large file\n", "%8d large files\n", |
| 140 | ctx->large_files), ctx->large_files); |
| 141 | printf (P_("\n%8d regular file\n", "\n%8d regular files\n", |
| 142 | ctx->fs_regular_count), ctx->fs_regular_count); |
| 143 | printf (P_("%8d directory\n", "%8d directories\n", |
| 144 | ctx->fs_directory_count), ctx->fs_directory_count); |
| 145 | printf (P_("%8d character device file\n", |
| 146 | "%8d character device files\n", ctx->fs_chardev_count), |
| 147 | ctx->fs_chardev_count); |
| 148 | printf (P_("%8d block device file\n", "%8d block device files\n", |
| 149 | ctx->fs_blockdev_count), ctx->fs_blockdev_count); |
| 150 | printf (P_("%8d fifo\n", "%8d fifos\n", ctx->fs_fifo_count), |
| 151 | ctx->fs_fifo_count); |
| 152 | printf (P_("%8d link\n", "%8d links\n", |
| 153 | ctx->fs_links_count - dir_links), |
| 154 | ctx->fs_links_count - dir_links); |
| 155 | printf (P_("%8d symbolic link", "%8d symbolic links", |
| 156 | ctx->fs_symlinks_count), ctx->fs_symlinks_count); |
| 157 | printf (P_(" (%d fast symbolic link)\n", " (%d fast symbolic links)\n", |
| 158 | ctx->fs_fast_symlinks_count), ctx->fs_fast_symlinks_count); |
| 159 | printf (P_("%8d socket\n", "%8d sockets\n", ctx->fs_sockets_count), |
| 160 | ctx->fs_sockets_count); |
| 161 | printf ("--------\n"); |
| 162 | printf (P_("%8d file\n", "%8d files\n", |
| 163 | ctx->fs_total_count - dir_links), |
| Theodore Ts'o | 0c4a072 | 2000-02-07 03:11:03 +0000 | [diff] [blame] | 164 | ctx->fs_total_count - dir_links); |
| Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 165 | } |
| 166 | |
| 167 | static void check_mount(e2fsck_t ctx) |
| 168 | { |
| 169 | errcode_t retval; |
| Theodore Ts'o | ee89513 | 2002-11-07 16:16:55 -0500 | [diff] [blame] | 170 | int cont; |
| Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 171 | |
| Theodore Ts'o | ee89513 | 2002-11-07 16:16:55 -0500 | [diff] [blame] | 172 | retval = ext2fs_check_if_mounted(ctx->filesystem_name, |
| 173 | &ctx->mount_flags); |
| Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 174 | if (retval) { |
| 175 | com_err("ext2fs_check_if_mount", retval, |
| Theodore Ts'o | 0c4a072 | 2000-02-07 03:11:03 +0000 | [diff] [blame] | 176 | _("while determining whether %s is mounted."), |
| Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 177 | ctx->filesystem_name); |
| 178 | return; |
| 179 | } |
| Theodore Ts'o | 83e6ac8 | 2001-07-30 16:29:52 -0400 | [diff] [blame] | 180 | |
| 181 | /* |
| 182 | * If the filesystem isn't mounted, or it's the root filesystem |
| 183 | * and it's mounted read-only, then everything's fine. |
| 184 | */ |
| Theodore Ts'o | ee89513 | 2002-11-07 16:16:55 -0500 | [diff] [blame] | 185 | if ((!(ctx->mount_flags & EXT2_MF_MOUNTED)) || |
| 186 | ((ctx->mount_flags & EXT2_MF_ISROOT) && |
| 187 | (ctx->mount_flags & EXT2_MF_READONLY))) |
| Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 188 | return; |
| 189 | |
| Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 190 | if (ctx->options & E2F_OPT_READONLY) { |
| Theodore Ts'o | 0c4a072 | 2000-02-07 03:11:03 +0000 | [diff] [blame] | 191 | printf(_("Warning! %s is mounted.\n"), ctx->filesystem_name); |
| Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 192 | return; |
| 193 | } |
| 194 | |
| Theodore Ts'o | 0c4a072 | 2000-02-07 03:11:03 +0000 | [diff] [blame] | 195 | printf(_("%s is mounted. "), ctx->filesystem_name); |
| Theodore Ts'o | 54a31a3 | 2003-08-19 10:08:34 -0400 | [diff] [blame] | 196 | if (!ctx->interactive) |
| Theodore Ts'o | 243dc31 | 2000-08-22 21:37:47 +0000 | [diff] [blame] | 197 | fatal_error(ctx, _("Cannot continue, aborting.\n\n")); |
| Theodore Ts'o | 0c4a072 | 2000-02-07 03:11:03 +0000 | [diff] [blame] | 198 | printf(_("\n\n\007\007\007\007WARNING!!! " |
| Theodore Ts'o | 7403335 | 1999-07-01 03:00:47 +0000 | [diff] [blame] | 199 | "Running e2fsck on a mounted filesystem may cause\n" |
| Theodore Ts'o | 0c4a072 | 2000-02-07 03:11:03 +0000 | [diff] [blame] | 200 | "SEVERE filesystem damage.\007\007\007\n\n")); |
| 201 | cont = ask_yn(_("Do you really want to continue"), -1); |
| Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 202 | if (!cont) { |
| Theodore Ts'o | 0c4a072 | 2000-02-07 03:11:03 +0000 | [diff] [blame] | 203 | printf (_("check aborted.\n")); |
| Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 204 | exit (0); |
| 205 | } |
| 206 | return; |
| 207 | } |
| 208 | |
| Theodore Ts'o | 5443492 | 2003-12-07 01:28:50 -0500 | [diff] [blame] | 209 | static int is_on_batt(void) |
| Theodore Ts'o | 015b03d | 2003-11-21 11:02:22 -0500 | [diff] [blame] | 210 | { |
| 211 | FILE *f; |
| Theodore Ts'o | c07f9f2 | 2004-04-12 00:16:44 -0400 | [diff] [blame] | 212 | DIR *d; |
| 213 | char tmp[80], tmp2[80], fname[80]; |
| Theodore Ts'o | 015b03d | 2003-11-21 11:02:22 -0500 | [diff] [blame] | 214 | unsigned int acflag; |
| Theodore Ts'o | c07f9f2 | 2004-04-12 00:16:44 -0400 | [diff] [blame] | 215 | struct dirent* de; |
| Theodore Ts'o | 015b03d | 2003-11-21 11:02:22 -0500 | [diff] [blame] | 216 | |
| 217 | f = fopen("/proc/apm", "r"); |
| 218 | if (f) { |
| 219 | if (fscanf(f, "%s %s %s %x", tmp, tmp, tmp, &acflag) != 4) |
| 220 | acflag = 1; |
| 221 | fclose(f); |
| 222 | return (acflag != 1); |
| 223 | } |
| Theodore Ts'o | c07f9f2 | 2004-04-12 00:16:44 -0400 | [diff] [blame] | 224 | d = opendir("/proc/acpi/ac_adapter"); |
| 225 | while (d && (de=readdir(d))) { |
| 226 | if (!strncmp(".", de->d_name, 1)) |
| 227 | continue; |
| 228 | snprintf(fname, 80, "/proc/acpi/ac_adapter/%s/state", |
| 229 | de->d_name); |
| 230 | f = fopen(fname, "r"); |
| 231 | if (!f) |
| 232 | continue; |
| Theodore Ts'o | 015b03d | 2003-11-21 11:02:22 -0500 | [diff] [blame] | 233 | if (fscanf(f, "%s %s", tmp2, tmp) != 2) |
| 234 | tmp[0] = 0; |
| 235 | fclose(f); |
| Theodore Ts'o | c07f9f2 | 2004-04-12 00:16:44 -0400 | [diff] [blame] | 236 | if (strncmp(tmp, "off-line", 8) == 0) { |
| 237 | closedir(d); |
| Theodore Ts'o | 015b03d | 2003-11-21 11:02:22 -0500 | [diff] [blame] | 238 | return 1; |
| Theodore Ts'o | c07f9f2 | 2004-04-12 00:16:44 -0400 | [diff] [blame] | 239 | } |
| Theodore Ts'o | 015b03d | 2003-11-21 11:02:22 -0500 | [diff] [blame] | 240 | } |
| Theodore Ts'o | c07f9f2 | 2004-04-12 00:16:44 -0400 | [diff] [blame] | 241 | closedir(d); |
| Theodore Ts'o | 015b03d | 2003-11-21 11:02:22 -0500 | [diff] [blame] | 242 | return 0; |
| 243 | } |
| 244 | |
| Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 245 | /* |
| 246 | * This routine checks to see if a filesystem can be skipped; if so, |
| 247 | * it will exit with E2FSCK_OK. Under some conditions it will print a |
| 248 | * message explaining why a check is being forced. |
| 249 | */ |
| 250 | static void check_if_skip(e2fsck_t ctx) |
| 251 | { |
| 252 | ext2_filsys fs = ctx->fs; |
| 253 | const char *reason = NULL; |
| Theodore Ts'o | b6a0807 | 2001-06-14 01:16:17 +0000 | [diff] [blame] | 254 | unsigned int reason_arg = 0; |
| Theodore Ts'o | 6de289c | 2003-11-21 10:54:54 -0500 | [diff] [blame] | 255 | long next_check; |
| Theodore Ts'o | 015b03d | 2003-11-21 11:02:22 -0500 | [diff] [blame] | 256 | int batt = is_on_batt(); |
| Theodore Ts'o | 6de289c | 2003-11-21 10:54:54 -0500 | [diff] [blame] | 257 | time_t now = time(0); |
| Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 258 | |
| Theodore Ts'o | d37066a | 2001-12-21 23:28:54 -0500 | [diff] [blame] | 259 | if ((ctx->options & E2F_OPT_FORCE) || bad_blocks_file || |
| 260 | cflag || swapfs) |
| Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 261 | return; |
| 262 | |
| 263 | if (fs->super->s_state & EXT2_ERROR_FS) |
| Theodore Ts'o | b6a0807 | 2001-06-14 01:16:17 +0000 | [diff] [blame] | 264 | reason = _(" contains a file system with errors"); |
| Theodore Ts'o | 24fc503 | 1998-08-26 15:23:31 +0000 | [diff] [blame] | 265 | else if ((fs->super->s_state & EXT2_VALID_FS) == 0) |
| Theodore Ts'o | b6a0807 | 2001-06-14 01:16:17 +0000 | [diff] [blame] | 266 | reason = _(" was not cleanly unmounted"); |
| Theodore Ts'o | bc57f15 | 2001-04-26 04:11:46 +0000 | [diff] [blame] | 267 | else if ((fs->super->s_max_mnt_count > 0) && |
| Theodore Ts'o | 17390c0 | 2000-07-07 04:13:21 +0000 | [diff] [blame] | 268 | (fs->super->s_mnt_count >= |
| Theodore Ts'o | b6a0807 | 2001-06-14 01:16:17 +0000 | [diff] [blame] | 269 | (unsigned) fs->super->s_max_mnt_count)) { |
| 270 | reason = _(" has been mounted %u times without being checked"); |
| 271 | reason_arg = fs->super->s_mnt_count; |
| Theodore Ts'o | 015b03d | 2003-11-21 11:02:22 -0500 | [diff] [blame] | 272 | if (batt && (fs->super->s_mnt_count < |
| 273 | (unsigned) fs->super->s_max_mnt_count*2)) |
| 274 | reason = 0; |
| Theodore Ts'o | b6a0807 | 2001-06-14 01:16:17 +0000 | [diff] [blame] | 275 | } else if (fs->super->s_checkinterval && |
| Theodore Ts'o | 5443492 | 2003-12-07 01:28:50 -0500 | [diff] [blame] | 276 | ((now - fs->super->s_lastcheck) >= |
| 277 | fs->super->s_checkinterval)) { |
| Theodore Ts'o | b6a0807 | 2001-06-14 01:16:17 +0000 | [diff] [blame] | 278 | reason = _(" has gone %u days without being checked"); |
| Theodore Ts'o | 6de289c | 2003-11-21 10:54:54 -0500 | [diff] [blame] | 279 | reason_arg = (now - fs->super->s_lastcheck)/(3600*24); |
| Theodore Ts'o | 5443492 | 2003-12-07 01:28:50 -0500 | [diff] [blame] | 280 | if (batt && ((now - fs->super->s_lastcheck) < |
| 281 | fs->super->s_checkinterval*2)) |
| Theodore Ts'o | 015b03d | 2003-11-21 11:02:22 -0500 | [diff] [blame] | 282 | reason = 0; |
| Theodore Ts'o | b6a0807 | 2001-06-14 01:16:17 +0000 | [diff] [blame] | 283 | } |
| Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 284 | if (reason) { |
| Theodore Ts'o | b6a0807 | 2001-06-14 01:16:17 +0000 | [diff] [blame] | 285 | fputs(ctx->device_name, stdout); |
| 286 | printf(reason, reason_arg); |
| 287 | fputs(_(", check forced.\n"), stdout); |
| Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 288 | return; |
| 289 | } |
| Theodore Ts'o | 6de289c | 2003-11-21 10:54:54 -0500 | [diff] [blame] | 290 | printf(_("%s: clean, %d/%d files, %d/%d blocks"), ctx->device_name, |
| Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 291 | fs->super->s_inodes_count - fs->super->s_free_inodes_count, |
| 292 | fs->super->s_inodes_count, |
| 293 | fs->super->s_blocks_count - fs->super->s_free_blocks_count, |
| 294 | fs->super->s_blocks_count); |
| Theodore Ts'o | 6de289c | 2003-11-21 10:54:54 -0500 | [diff] [blame] | 295 | next_check = 100000; |
| 296 | if (fs->super->s_max_mnt_count > 0) { |
| 297 | next_check = fs->super->s_max_mnt_count - fs->super->s_mnt_count; |
| 298 | if (next_check <= 0) |
| 299 | next_check = 1; |
| 300 | } |
| Theodore Ts'o | 5443492 | 2003-12-07 01:28:50 -0500 | [diff] [blame] | 301 | if ((now - fs->super->s_lastcheck) >= fs->super->s_checkinterval) |
| Theodore Ts'o | 6de289c | 2003-11-21 10:54:54 -0500 | [diff] [blame] | 302 | next_check = 1; |
| 303 | if (next_check <= 5) { |
| 304 | if (next_check == 1) |
| 305 | fputs(_(" (check after next mount)"), stdout); |
| 306 | else |
| Theodore Ts'o | 5443492 | 2003-12-07 01:28:50 -0500 | [diff] [blame] | 307 | printf(_(" (check in %ld mounts)"), next_check); |
| Theodore Ts'o | 6de289c | 2003-11-21 10:54:54 -0500 | [diff] [blame] | 308 | } |
| 309 | fputc('\n', stdout); |
| Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 310 | ext2fs_close(fs); |
| Theodore Ts'o | 6d222f3 | 2001-07-29 12:06:58 -0400 | [diff] [blame] | 311 | ctx->fs = NULL; |
| 312 | e2fsck_free_context(ctx); |
| Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 313 | exit(FSCK_OK); |
| 314 | } |
| 315 | |
| Theodore Ts'o | efac9a1 | 1998-05-07 05:02:00 +0000 | [diff] [blame] | 316 | /* |
| 317 | * For completion notice |
| 318 | */ |
| Theodore Ts'o | 5596def | 1999-07-19 15:27:37 +0000 | [diff] [blame] | 319 | struct percent_tbl { |
| 320 | int max_pass; |
| 321 | int table[32]; |
| 322 | }; |
| 323 | struct percent_tbl e2fsck_tbl = { |
| 324 | 5, { 0, 70, 90, 92, 95, 100 } |
| 325 | }; |
| Theodore Ts'o | 54a31a3 | 2003-08-19 10:08:34 -0400 | [diff] [blame] | 326 | static char bar[128], spaces[128]; |
| Theodore Ts'o | 5596def | 1999-07-19 15:27:37 +0000 | [diff] [blame] | 327 | |
| 328 | static float calc_percent(struct percent_tbl *tbl, int pass, int curr, |
| 329 | int max) |
| 330 | { |
| 331 | float percent; |
| 332 | |
| 333 | if (pass <= 0) |
| 334 | return 0.0; |
| Theodore Ts'o | b8d164c | 2000-08-08 03:17:04 +0000 | [diff] [blame] | 335 | if (pass > tbl->max_pass || max == 0) |
| Theodore Ts'o | 5596def | 1999-07-19 15:27:37 +0000 | [diff] [blame] | 336 | return 100.0; |
| 337 | percent = ((float) curr) / ((float) max); |
| 338 | return ((percent * (tbl->table[pass] - tbl->table[pass-1])) |
| 339 | + tbl->table[pass-1]); |
| 340 | } |
| 341 | |
| 342 | extern void e2fsck_clear_progbar(e2fsck_t ctx) |
| 343 | { |
| 344 | if (!(ctx->flags & E2F_FLAG_PROG_BAR)) |
| 345 | return; |
| 346 | |
| Theodore Ts'o | 54a31a3 | 2003-08-19 10:08:34 -0400 | [diff] [blame] | 347 | printf("%s%s\r%s", ctx->start_meta, spaces + (sizeof(spaces) - 80), |
| 348 | ctx->stop_meta); |
| Theodore Ts'o | bc34d6b | 2003-04-16 14:05:06 -0400 | [diff] [blame] | 349 | fflush(stdout); |
| Theodore Ts'o | 5596def | 1999-07-19 15:27:37 +0000 | [diff] [blame] | 350 | ctx->flags &= ~E2F_FLAG_PROG_BAR; |
| 351 | } |
| 352 | |
| Theodore Ts'o | 520ead3 | 2003-04-19 13:48:27 -0400 | [diff] [blame] | 353 | int e2fsck_simple_progress(e2fsck_t ctx, const char *label, float percent, |
| Theodore Ts'o | b0700a1 | 2003-03-14 01:43:56 -0500 | [diff] [blame] | 354 | unsigned int dpynum) |
| 355 | { |
| 356 | static const char spinner[] = "\\|/-"; |
| Theodore Ts'o | b0700a1 | 2003-03-14 01:43:56 -0500 | [diff] [blame] | 357 | int i; |
| Theodore Ts'o | 5443492 | 2003-12-07 01:28:50 -0500 | [diff] [blame] | 358 | unsigned int tick; |
| Theodore Ts'o | b0700a1 | 2003-03-14 01:43:56 -0500 | [diff] [blame] | 359 | struct timeval tv; |
| 360 | int dpywidth; |
| 361 | |
| 362 | if (ctx->flags & E2F_FLAG_PROG_SUPPRESS) |
| 363 | return 0; |
| 364 | |
| 365 | /* |
| 366 | * Calculate the new progress position. If the |
| 367 | * percentage hasn't changed, then we skip out right |
| 368 | * away. |
| 369 | */ |
| 370 | if (ctx->progress_last_percent == (int) 10 * percent) |
| 371 | return 0; |
| 372 | ctx->progress_last_percent = (int) 10 * percent; |
| 373 | |
| 374 | /* |
| 375 | * If we've already updated the spinner once within |
| 376 | * the last 1/8th of a second, no point doing it |
| 377 | * again. |
| 378 | */ |
| 379 | gettimeofday(&tv, NULL); |
| 380 | tick = (tv.tv_sec << 3) + (tv.tv_usec / (1000000 / 8)); |
| 381 | if ((tick == ctx->progress_last_time) && |
| 382 | (percent != 0.0) && (percent != 100.0)) |
| 383 | return 0; |
| 384 | ctx->progress_last_time = tick; |
| 385 | |
| 386 | /* |
| 387 | * Advance the spinner, and note that the progress bar |
| 388 | * will be on the screen |
| 389 | */ |
| 390 | ctx->progress_pos = (ctx->progress_pos+1) & 3; |
| 391 | ctx->flags |= E2F_FLAG_PROG_BAR; |
| 392 | |
| 393 | dpywidth = 66 - strlen(label); |
| 394 | dpywidth = 8 * (dpywidth / 8); |
| 395 | if (dpynum) |
| 396 | dpywidth -= 8; |
| 397 | |
| 398 | i = ((percent * dpywidth) + 50) / 100; |
| Theodore Ts'o | 54a31a3 | 2003-08-19 10:08:34 -0400 | [diff] [blame] | 399 | printf("%s%s: |%s%s", ctx->start_meta, label, |
| 400 | bar + (sizeof(bar) - (i+1)), |
| Theodore Ts'o | b0700a1 | 2003-03-14 01:43:56 -0500 | [diff] [blame] | 401 | spaces + (sizeof(spaces) - (dpywidth - i + 1))); |
| 402 | if (percent == 100.0) |
| 403 | fputc('|', stdout); |
| 404 | else |
| 405 | fputc(spinner[ctx->progress_pos & 3], stdout); |
| 406 | if (dpynum) |
| Theodore Ts'o | 54a31a3 | 2003-08-19 10:08:34 -0400 | [diff] [blame] | 407 | printf(" %4.1f%% %u\r%s", percent, dpynum, ctx->stop_meta); |
| Theodore Ts'o | b0700a1 | 2003-03-14 01:43:56 -0500 | [diff] [blame] | 408 | else |
| Theodore Ts'o | 54a31a3 | 2003-08-19 10:08:34 -0400 | [diff] [blame] | 409 | printf(" %4.1f%% \r%s", percent, ctx->stop_meta); |
| Theodore Ts'o | b0700a1 | 2003-03-14 01:43:56 -0500 | [diff] [blame] | 410 | |
| 411 | if (percent == 100.0) |
| 412 | e2fsck_clear_progbar(ctx); |
| 413 | fflush(stdout); |
| 414 | |
| 415 | return 0; |
| 416 | } |
| 417 | |
| Theodore Ts'o | efac9a1 | 1998-05-07 05:02:00 +0000 | [diff] [blame] | 418 | static int e2fsck_update_progress(e2fsck_t ctx, int pass, |
| 419 | unsigned long cur, unsigned long max) |
| 420 | { |
| Theodore Ts'o | efac9a1 | 1998-05-07 05:02:00 +0000 | [diff] [blame] | 421 | char buf[80]; |
| Theodore Ts'o | 5596def | 1999-07-19 15:27:37 +0000 | [diff] [blame] | 422 | float percent; |
| Theodore Ts'o | f75c28d | 1998-08-01 04:18:06 +0000 | [diff] [blame] | 423 | |
| 424 | if (pass == 0) |
| 425 | return 0; |
| Theodore Ts'o | efac9a1 | 1998-05-07 05:02:00 +0000 | [diff] [blame] | 426 | |
| 427 | if (ctx->progress_fd) { |
| 428 | sprintf(buf, "%d %lu %lu\n", pass, cur, max); |
| 429 | write(ctx->progress_fd, buf, strlen(buf)); |
| 430 | } else { |
| Theodore Ts'o | e4c8e88 | 2000-07-05 23:54:46 +0000 | [diff] [blame] | 431 | percent = calc_percent(&e2fsck_tbl, pass, cur, max); |
| Theodore Ts'o | b0700a1 | 2003-03-14 01:43:56 -0500 | [diff] [blame] | 432 | e2fsck_simple_progress(ctx, ctx->device_name, |
| 433 | percent, 0); |
| Theodore Ts'o | efac9a1 | 1998-05-07 05:02:00 +0000 | [diff] [blame] | 434 | } |
| 435 | return 0; |
| 436 | } |
| Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 437 | |
| 438 | #define PATH_SET "PATH=/sbin" |
| 439 | |
| Theodore Ts'o | 5ba23cb | 2001-01-11 19:15:02 +0000 | [diff] [blame] | 440 | static void reserve_stdio_fds(void) |
| Theodore Ts'o | 24fc503 | 1998-08-26 15:23:31 +0000 | [diff] [blame] | 441 | { |
| 442 | int fd; |
| 443 | |
| 444 | while (1) { |
| 445 | fd = open("/dev/null", O_RDWR); |
| 446 | if (fd > 2) |
| 447 | break; |
| Theodore Ts'o | 75d83be | 1999-05-18 03:16:36 +0000 | [diff] [blame] | 448 | if (fd < 0) { |
| Theodore Ts'o | 0c4a072 | 2000-02-07 03:11:03 +0000 | [diff] [blame] | 449 | fprintf(stderr, _("ERROR: Couldn't open " |
| 450 | "/dev/null (%s)\n"), |
| Theodore Ts'o | 75d83be | 1999-05-18 03:16:36 +0000 | [diff] [blame] | 451 | strerror(errno)); |
| 452 | break; |
| 453 | } |
| Theodore Ts'o | 24fc503 | 1998-08-26 15:23:31 +0000 | [diff] [blame] | 454 | } |
| 455 | close(fd); |
| 456 | } |
| 457 | |
| Theodore Ts'o | 9ecd8be | 1999-10-20 18:24:31 +0000 | [diff] [blame] | 458 | #ifdef HAVE_SIGNAL_H |
| Theodore Ts'o | 5443492 | 2003-12-07 01:28:50 -0500 | [diff] [blame] | 459 | static void signal_progress_on(int sig EXT2FS_ATTR((unused))) |
| Theodore Ts'o | 5596def | 1999-07-19 15:27:37 +0000 | [diff] [blame] | 460 | { |
| Theodore Ts'o | 243dc31 | 2000-08-22 21:37:47 +0000 | [diff] [blame] | 461 | e2fsck_t ctx = e2fsck_global_ctx; |
| Theodore Ts'o | 5596def | 1999-07-19 15:27:37 +0000 | [diff] [blame] | 462 | |
| 463 | if (!ctx) |
| 464 | return; |
| 465 | |
| 466 | ctx->progress = e2fsck_update_progress; |
| 467 | ctx->progress_fd = 0; |
| 468 | } |
| 469 | |
| Theodore Ts'o | 5443492 | 2003-12-07 01:28:50 -0500 | [diff] [blame] | 470 | static void signal_progress_off(int sig EXT2FS_ATTR((unused))) |
| Theodore Ts'o | 5596def | 1999-07-19 15:27:37 +0000 | [diff] [blame] | 471 | { |
| Theodore Ts'o | 243dc31 | 2000-08-22 21:37:47 +0000 | [diff] [blame] | 472 | e2fsck_t ctx = e2fsck_global_ctx; |
| Theodore Ts'o | 5596def | 1999-07-19 15:27:37 +0000 | [diff] [blame] | 473 | |
| 474 | if (!ctx) |
| 475 | return; |
| 476 | |
| 477 | e2fsck_clear_progbar(ctx); |
| 478 | ctx->progress = 0; |
| 479 | } |
| Theodore Ts'o | 4cae045 | 2002-07-21 14:14:03 -0400 | [diff] [blame] | 480 | |
| Theodore Ts'o | 5443492 | 2003-12-07 01:28:50 -0500 | [diff] [blame] | 481 | static void signal_cancel(int sig EXT2FS_ATTR((unused))) |
| Theodore Ts'o | 4cae045 | 2002-07-21 14:14:03 -0400 | [diff] [blame] | 482 | { |
| 483 | e2fsck_t ctx = e2fsck_global_ctx; |
| 484 | |
| 485 | if (!ctx) |
| 486 | exit(FSCK_CANCELED); |
| 487 | |
| 488 | ctx->flags |= E2F_FLAG_CANCEL; |
| 489 | } |
| Theodore Ts'o | 9ecd8be | 1999-10-20 18:24:31 +0000 | [diff] [blame] | 490 | #endif |
| Theodore Ts'o | 5596def | 1999-07-19 15:27:37 +0000 | [diff] [blame] | 491 | |
| Theodore Ts'o | 0684a4f | 2002-08-17 10:19:44 -0400 | [diff] [blame] | 492 | static void parse_extended_opts(e2fsck_t ctx, const char *opts) |
| 493 | { |
| 494 | char *buf, *token, *next, *p, *arg; |
| Theodore Ts'o | f364093 | 2003-03-01 19:47:44 -0500 | [diff] [blame] | 495 | int ea_ver; |
| Theodore Ts'o | 0684a4f | 2002-08-17 10:19:44 -0400 | [diff] [blame] | 496 | int extended_usage = 0; |
| 497 | |
| Theodore Ts'o | f364093 | 2003-03-01 19:47:44 -0500 | [diff] [blame] | 498 | buf = string_copy(ctx, opts, 0); |
| Theodore Ts'o | 0684a4f | 2002-08-17 10:19:44 -0400 | [diff] [blame] | 499 | for (token = buf; token && *token; token = next) { |
| 500 | p = strchr(token, ','); |
| 501 | next = 0; |
| 502 | if (p) { |
| 503 | *p = 0; |
| 504 | next = p+1; |
| 505 | } |
| 506 | arg = strchr(token, '='); |
| 507 | if (arg) { |
| 508 | *arg = 0; |
| 509 | arg++; |
| 510 | } |
| 511 | if (strcmp(token, "ea_ver") == 0) { |
| 512 | if (!arg) { |
| 513 | extended_usage++; |
| 514 | continue; |
| 515 | } |
| 516 | ea_ver = strtoul(arg, &p, 0); |
| 517 | if (*p || |
| 518 | ((ea_ver != 1) && (ea_ver != 2))) { |
| 519 | fprintf(stderr, |
| 520 | _("Invalid EA version.\n")); |
| 521 | extended_usage++; |
| 522 | continue; |
| 523 | } |
| 524 | ctx->ext_attr_ver = ea_ver; |
| 525 | } else |
| 526 | extended_usage++; |
| 527 | } |
| 528 | if (extended_usage) { |
| 529 | fprintf(stderr, _("Extended options are separated by commas, " |
| 530 | "and may take an argument which\n" |
| 531 | "is set off by an equals ('=') sign. " |
| 532 | "Valid raid options are:\n" |
| 533 | "\tea_ver=<ea_version (1 or 2)\n\n")); |
| 534 | exit(1); |
| 535 | } |
| 536 | } |
| 537 | |
| 538 | |
| Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 539 | static errcode_t PRS(int argc, char *argv[], e2fsck_t *ret_ctx) |
| 540 | { |
| 541 | int flush = 0; |
| Theodore Ts'o | ae8160e | 2001-05-01 21:13:37 +0000 | [diff] [blame] | 542 | int c, fd; |
| Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 543 | #ifdef MTRACE |
| 544 | extern void *mallwatch; |
| 545 | #endif |
| Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 546 | e2fsck_t ctx; |
| 547 | errcode_t retval; |
| Theodore Ts'o | 9ecd8be | 1999-10-20 18:24:31 +0000 | [diff] [blame] | 548 | #ifdef HAVE_SIGNAL_H |
| Theodore Ts'o | 5596def | 1999-07-19 15:27:37 +0000 | [diff] [blame] | 549 | struct sigaction sa; |
| Theodore Ts'o | 9ecd8be | 1999-10-20 18:24:31 +0000 | [diff] [blame] | 550 | #endif |
| Theodore Ts'o | 0684a4f | 2002-08-17 10:19:44 -0400 | [diff] [blame] | 551 | char *extended_opts = 0; |
| Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 552 | |
| 553 | retval = e2fsck_allocate_context(&ctx); |
| 554 | if (retval) |
| 555 | return retval; |
| 556 | |
| 557 | *ret_ctx = ctx; |
| 558 | |
| Theodore Ts'o | 908b785 | 2003-04-16 15:20:13 -0400 | [diff] [blame] | 559 | setvbuf(stdout, NULL, _IONBF, BUFSIZ); |
| 560 | setvbuf(stderr, NULL, _IONBF, BUFSIZ); |
| Theodore Ts'o | 54a31a3 | 2003-08-19 10:08:34 -0400 | [diff] [blame] | 561 | if (isatty(0) && isatty(1)) { |
| 562 | ctx->interactive = 1; |
| 563 | } else { |
| 564 | ctx->start_meta[0] = '\001'; |
| 565 | ctx->stop_meta[0] = '\002'; |
| 566 | } |
| 567 | memset(bar, '=', sizeof(bar)-1); |
| 568 | memset(spaces, ' ', sizeof(spaces)-1); |
| Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 569 | initialize_ext2_error_table(); |
| Theodore Ts'o | f364093 | 2003-03-01 19:47:44 -0500 | [diff] [blame] | 570 | blkid_get_cache(&ctx->blkid, NULL); |
| Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 571 | |
| 572 | if (argc && *argv) |
| 573 | ctx->program_name = *argv; |
| 574 | else |
| 575 | ctx->program_name = "e2fsck"; |
| Theodore Ts'o | 4fb9d52 | 2004-02-24 00:16:09 -0500 | [diff] [blame] | 576 | while ((c = getopt (argc, argv, "panyrcC:B:dE:fvtFVM:b:I:j:P:l:L:N:SsDk")) != EOF) |
| Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 577 | switch (c) { |
| Theodore Ts'o | efac9a1 | 1998-05-07 05:02:00 +0000 | [diff] [blame] | 578 | case 'C': |
| 579 | ctx->progress = e2fsck_update_progress; |
| 580 | ctx->progress_fd = atoi(optarg); |
| Theodore Ts'o | fc9a69c | 2001-05-12 13:43:46 +0000 | [diff] [blame] | 581 | if (!ctx->progress_fd) |
| 582 | break; |
| Theodore Ts'o | ae8160e | 2001-05-01 21:13:37 +0000 | [diff] [blame] | 583 | /* Validate the file descriptor to avoid disasters */ |
| 584 | fd = dup(ctx->progress_fd); |
| 585 | if (fd < 0) { |
| 586 | fprintf(stderr, |
| 587 | _("Error validating file descriptor %d: %s\n"), |
| 588 | ctx->progress_fd, |
| 589 | error_message(errno)); |
| 590 | fatal_error(ctx, |
| 591 | _("Invalid completion information file descriptor")); |
| 592 | } else |
| 593 | close(fd); |
| Theodore Ts'o | efac9a1 | 1998-05-07 05:02:00 +0000 | [diff] [blame] | 594 | break; |
| Theodore Ts'o | 850d05e | 2002-07-25 00:00:08 -0400 | [diff] [blame] | 595 | case 'D': |
| 596 | ctx->options |= E2F_OPT_COMPRESS_DIRS; |
| 597 | break; |
| Theodore Ts'o | 0684a4f | 2002-08-17 10:19:44 -0400 | [diff] [blame] | 598 | case 'E': |
| 599 | extended_opts = optarg; |
| 600 | break; |
| Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 601 | case 'p': |
| 602 | case 'a': |
| Theodore Ts'o | 8161a74 | 2003-01-02 16:36:44 -0500 | [diff] [blame] | 603 | if (ctx->options & (E2F_OPT_YES|E2F_OPT_NO)) { |
| 604 | conflict_opt: |
| 605 | fatal_error(ctx, |
| 606 | _("Only one the options -p/-a, -n or -y may be specified.")); |
| 607 | } |
| Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 608 | ctx->options |= E2F_OPT_PREEN; |
| Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 609 | break; |
| 610 | case 'n': |
| Theodore Ts'o | 8161a74 | 2003-01-02 16:36:44 -0500 | [diff] [blame] | 611 | if (ctx->options & (E2F_OPT_YES|E2F_OPT_PREEN)) |
| 612 | goto conflict_opt; |
| Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 613 | ctx->options |= E2F_OPT_NO; |
| Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 614 | break; |
| 615 | case 'y': |
| Theodore Ts'o | 8161a74 | 2003-01-02 16:36:44 -0500 | [diff] [blame] | 616 | if (ctx->options & (E2F_OPT_PREEN|E2F_OPT_NO)) |
| 617 | goto conflict_opt; |
| Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 618 | ctx->options |= E2F_OPT_YES; |
| Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 619 | break; |
| 620 | case 't': |
| Theodore Ts'o | 8bf191e | 1997-10-20 01:38:32 +0000 | [diff] [blame] | 621 | #ifdef RESOURCE_TRACK |
| Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 622 | if (ctx->options & E2F_OPT_TIME) |
| 623 | ctx->options |= E2F_OPT_TIME2; |
| 624 | else |
| 625 | ctx->options |= E2F_OPT_TIME; |
| Theodore Ts'o | 8bf191e | 1997-10-20 01:38:32 +0000 | [diff] [blame] | 626 | #else |
| Theodore Ts'o | 0c4a072 | 2000-02-07 03:11:03 +0000 | [diff] [blame] | 627 | fprintf(stderr, _("The -t option is not " |
| 628 | "supported on this version of e2fsck.\n")); |
| Theodore Ts'o | 8bf191e | 1997-10-20 01:38:32 +0000 | [diff] [blame] | 629 | #endif |
| Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 630 | break; |
| 631 | case 'c': |
| Theodore Ts'o | 3ed57c2 | 2001-12-24 15:01:59 -0500 | [diff] [blame] | 632 | if (cflag++) |
| 633 | ctx->options |= E2F_OPT_WRITECHECK; |
| Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 634 | ctx->options |= E2F_OPT_CHECKBLOCKS; |
| 635 | break; |
| 636 | case 'r': |
| 637 | /* What we do by default, anyway! */ |
| 638 | break; |
| 639 | case 'b': |
| 640 | ctx->use_superblock = atoi(optarg); |
| Theodore Ts'o | ae6cdcf | 2001-09-19 15:17:25 -0400 | [diff] [blame] | 641 | ctx->flags |= E2F_FLAG_SB_SPECIFIED; |
| Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 642 | break; |
| 643 | case 'B': |
| Theodore Ts'o | f1a1761 | 2001-12-23 22:27:52 -0500 | [diff] [blame] | 644 | ctx->blocksize = atoi(optarg); |
| Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 645 | break; |
| 646 | case 'I': |
| 647 | ctx->inode_buffer_blocks = atoi(optarg); |
| 648 | break; |
| Theodore Ts'o | adee8d7 | 2001-07-23 00:17:49 -0400 | [diff] [blame] | 649 | case 'j': |
| Theodore Ts'o | f364093 | 2003-03-01 19:47:44 -0500 | [diff] [blame] | 650 | ctx->journal_name = string_copy(ctx, optarg, 0); |
| Theodore Ts'o | adee8d7 | 2001-07-23 00:17:49 -0400 | [diff] [blame] | 651 | break; |
| Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 652 | case 'P': |
| 653 | ctx->process_inode_size = atoi(optarg); |
| 654 | break; |
| 655 | case 'L': |
| 656 | replace_bad_blocks++; |
| 657 | case 'l': |
| Theodore Ts'o | f364093 | 2003-03-01 19:47:44 -0500 | [diff] [blame] | 658 | bad_blocks_file = string_copy(ctx, optarg, 0); |
| Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 659 | break; |
| 660 | case 'd': |
| 661 | ctx->options |= E2F_OPT_DEBUG; |
| 662 | break; |
| 663 | case 'f': |
| Theodore Ts'o | d37066a | 2001-12-21 23:28:54 -0500 | [diff] [blame] | 664 | ctx->options |= E2F_OPT_FORCE; |
| Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 665 | break; |
| 666 | case 'F': |
| Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 667 | flush = 1; |
| Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 668 | break; |
| 669 | case 'v': |
| 670 | verbose = 1; |
| 671 | break; |
| 672 | case 'V': |
| 673 | show_version_only = 1; |
| 674 | break; |
| 675 | #ifdef MTRACE |
| 676 | case 'M': |
| 677 | mallwatch = (void *) strtol(optarg, NULL, 0); |
| 678 | break; |
| 679 | #endif |
| 680 | case 'N': |
| 681 | ctx->device_name = optarg; |
| 682 | break; |
| Theodore Ts'o | 5df55d7 | 2001-06-11 07:00:04 +0000 | [diff] [blame] | 683 | #ifdef ENABLE_SWAPFS |
| Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 684 | case 's': |
| 685 | normalize_swapfs = 1; |
| 686 | case 'S': |
| 687 | swapfs = 1; |
| 688 | break; |
| Theodore Ts'o | 5df55d7 | 2001-06-11 07:00:04 +0000 | [diff] [blame] | 689 | #else |
| 690 | case 's': |
| 691 | case 'S': |
| 692 | fprintf(stderr, _("Byte-swapping filesystems " |
| 693 | "not compiled in this version " |
| 694 | "of e2fsck\n")); |
| 695 | exit(1); |
| 696 | #endif |
| Theodore Ts'o | 4fb9d52 | 2004-02-24 00:16:09 -0500 | [diff] [blame] | 697 | case 'k': |
| 698 | keep_bad_blocks++; |
| Theodore Ts'o | bc69f82 | 2004-02-27 10:39:27 -0500 | [diff] [blame] | 699 | break; |
| Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 700 | default: |
| 701 | usage(ctx); |
| 702 | } |
| 703 | if (show_version_only) |
| 704 | return 0; |
| 705 | if (optind != argc - 1) |
| 706 | usage(ctx); |
| 707 | if ((ctx->options & E2F_OPT_NO) && !bad_blocks_file && |
| Theodore Ts'o | 850d05e | 2002-07-25 00:00:08 -0400 | [diff] [blame] | 708 | !cflag && !swapfs && !(ctx->options & E2F_OPT_COMPRESS_DIRS)) |
| Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 709 | ctx->options |= E2F_OPT_READONLY; |
| Theodore Ts'o | f364093 | 2003-03-01 19:47:44 -0500 | [diff] [blame] | 710 | ctx->filesystem_name = blkid_get_devname(ctx->blkid, argv[optind], 0); |
| Theodore Ts'o | 817e49e | 2003-11-21 09:10:29 -0500 | [diff] [blame] | 711 | if (!ctx->filesystem_name) { |
| 712 | com_err(ctx->program_name, 0, _("Unable to resolve '%s'"), |
| 713 | argv[optind]); |
| 714 | fatal_error(ctx, 0); |
| 715 | } |
| Theodore Ts'o | 0684a4f | 2002-08-17 10:19:44 -0400 | [diff] [blame] | 716 | if (extended_opts) |
| 717 | parse_extended_opts(ctx, extended_opts); |
| 718 | |
| Theodore Ts'o | 28ffafb | 2000-02-08 19:14:02 +0000 | [diff] [blame] | 719 | if (flush) { |
| Theodore Ts'o | 4ea7bd0 | 2001-12-16 23:23:37 -0500 | [diff] [blame] | 720 | fd = open(ctx->filesystem_name, O_RDONLY, 0); |
| Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 721 | if (fd < 0) { |
| Theodore Ts'o | 0c4a072 | 2000-02-07 03:11:03 +0000 | [diff] [blame] | 722 | com_err("open", errno, |
| 723 | _("while opening %s for flushing"), |
| Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 724 | ctx->filesystem_name); |
| Theodore Ts'o | 243dc31 | 2000-08-22 21:37:47 +0000 | [diff] [blame] | 725 | fatal_error(ctx, 0); |
| Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 726 | } |
| Theodore Ts'o | 5df55d7 | 2001-06-11 07:00:04 +0000 | [diff] [blame] | 727 | if ((retval = ext2fs_sync_device(fd, 1))) { |
| Theodore Ts'o | 5ba23cb | 2001-01-11 19:15:02 +0000 | [diff] [blame] | 728 | com_err("ext2fs_sync_device", retval, |
| Theodore Ts'o | 0c4a072 | 2000-02-07 03:11:03 +0000 | [diff] [blame] | 729 | _("while trying to flush %s"), |
| Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 730 | ctx->filesystem_name); |
| Theodore Ts'o | 243dc31 | 2000-08-22 21:37:47 +0000 | [diff] [blame] | 731 | fatal_error(ctx, 0); |
| Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 732 | } |
| 733 | close(fd); |
| Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 734 | } |
| Theodore Ts'o | 5df55d7 | 2001-06-11 07:00:04 +0000 | [diff] [blame] | 735 | #ifdef ENABLE_SWAPFS |
| Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 736 | if (swapfs) { |
| 737 | if (cflag || bad_blocks_file) { |
| Theodore Ts'o | 0c4a072 | 2000-02-07 03:11:03 +0000 | [diff] [blame] | 738 | fprintf(stderr, _("Incompatible options not " |
| Theodore Ts'o | 3ed57c2 | 2001-12-24 15:01:59 -0500 | [diff] [blame] | 739 | "allowed when byte-swapping.\n")); |
| Theodore Ts'o | 243dc31 | 2000-08-22 21:37:47 +0000 | [diff] [blame] | 740 | exit(FSCK_USAGE); |
| Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 741 | } |
| 742 | } |
| Theodore Ts'o | 5df55d7 | 2001-06-11 07:00:04 +0000 | [diff] [blame] | 743 | #endif |
| Theodore Ts'o | 3ed57c2 | 2001-12-24 15:01:59 -0500 | [diff] [blame] | 744 | if (cflag && bad_blocks_file) { |
| 745 | fprintf(stderr, _("The -c and the -l/-L options may " |
| 746 | "not be both used at the same time.\n")); |
| 747 | exit(FSCK_USAGE); |
| 748 | } |
| Theodore Ts'o | 9ecd8be | 1999-10-20 18:24:31 +0000 | [diff] [blame] | 749 | #ifdef HAVE_SIGNAL_H |
| Theodore Ts'o | 5596def | 1999-07-19 15:27:37 +0000 | [diff] [blame] | 750 | /* |
| 751 | * Set up signal action |
| 752 | */ |
| 753 | memset(&sa, 0, sizeof(struct sigaction)); |
| Theodore Ts'o | 850d05e | 2002-07-25 00:00:08 -0400 | [diff] [blame] | 754 | sa.sa_handler = signal_cancel; |
| 755 | sigaction(SIGINT, &sa, 0); |
| 756 | sigaction(SIGTERM, &sa, 0); |
| Theodore Ts'o | 5596def | 1999-07-19 15:27:37 +0000 | [diff] [blame] | 757 | #ifdef SA_RESTART |
| 758 | sa.sa_flags = SA_RESTART; |
| 759 | #endif |
| Theodore Ts'o | 243dc31 | 2000-08-22 21:37:47 +0000 | [diff] [blame] | 760 | e2fsck_global_ctx = ctx; |
| Theodore Ts'o | 5596def | 1999-07-19 15:27:37 +0000 | [diff] [blame] | 761 | sa.sa_handler = signal_progress_on; |
| 762 | sigaction(SIGUSR1, &sa, 0); |
| 763 | sa.sa_handler = signal_progress_off; |
| 764 | sigaction(SIGUSR2, &sa, 0); |
| Theodore Ts'o | 9ecd8be | 1999-10-20 18:24:31 +0000 | [diff] [blame] | 765 | #endif |
| Theodore Ts'o | 6d222f3 | 2001-07-29 12:06:58 -0400 | [diff] [blame] | 766 | |
| 767 | /* Update our PATH to include /sbin if we need to run badblocks */ |
| 768 | if (cflag) { |
| 769 | char *oldpath = getenv("PATH"); |
| 770 | if (oldpath) { |
| 771 | char *newpath; |
| 772 | |
| 773 | newpath = (char *) malloc(sizeof (PATH_SET) + 1 + |
| 774 | strlen (oldpath)); |
| 775 | if (!newpath) |
| 776 | fatal_error(ctx, "Couldn't malloc() newpath"); |
| 777 | strcpy (newpath, PATH_SET); |
| 778 | strcat (newpath, ":"); |
| 779 | strcat (newpath, oldpath); |
| 780 | putenv (newpath); |
| 781 | } else |
| 782 | putenv (PATH_SET); |
| 783 | } |
| Theodore Ts'o | 5e72cdb | 2002-11-08 15:35:13 -0500 | [diff] [blame] | 784 | #ifdef CONFIG_JBD_DEBUG |
| 785 | if (getenv("E2FSCK_JBD_DEBUG")) |
| 786 | journal_enable_debug = atoi(getenv("E2FSCK_JBD_DEBUG")); |
| 787 | #endif |
| Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 788 | return 0; |
| 789 | } |
| 790 | |
| 791 | static const char *my_ver_string = E2FSPROGS_VERSION; |
| 792 | static const char *my_ver_date = E2FSPROGS_DATE; |
| 793 | |
| 794 | int main (int argc, char *argv[]) |
| 795 | { |
| 796 | errcode_t retval = 0; |
| 797 | int exit_value = FSCK_OK; |
| Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 798 | ext2_filsys fs = 0; |
| 799 | io_manager io_ptr; |
| Theodore Ts'o | 5dd8f96 | 2001-01-01 15:51:50 +0000 | [diff] [blame] | 800 | struct ext2_super_block *sb; |
| Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 801 | const char *lib_ver_date; |
| 802 | int my_ver, lib_ver; |
| 803 | e2fsck_t ctx; |
| 804 | struct problem_context pctx; |
| Theodore Ts'o | 08b2130 | 1997-11-03 19:42:40 +0000 | [diff] [blame] | 805 | int flags, run_result; |
| Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 806 | |
| 807 | clear_problem_context(&pctx); |
| 808 | #ifdef MTRACE |
| 809 | mtrace(); |
| 810 | #endif |
| 811 | #ifdef MCHECK |
| 812 | mcheck(0); |
| 813 | #endif |
| Theodore Ts'o | 0c4a072 | 2000-02-07 03:11:03 +0000 | [diff] [blame] | 814 | #ifdef ENABLE_NLS |
| 815 | setlocale(LC_MESSAGES, ""); |
| Theodore Ts'o | 14308a5 | 2002-03-05 03:26:52 -0500 | [diff] [blame] | 816 | setlocale(LC_CTYPE, ""); |
| Theodore Ts'o | 0c4a072 | 2000-02-07 03:11:03 +0000 | [diff] [blame] | 817 | bindtextdomain(NLS_CAT_NAME, LOCALEDIR); |
| 818 | textdomain(NLS_CAT_NAME); |
| 819 | #endif |
| Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 820 | my_ver = ext2fs_parse_version_string(my_ver_string); |
| 821 | lib_ver = ext2fs_get_library_version(0, &lib_ver_date); |
| 822 | if (my_ver > lib_ver) { |
| Theodore Ts'o | 0c4a072 | 2000-02-07 03:11:03 +0000 | [diff] [blame] | 823 | fprintf( stderr, _("Error: ext2fs library version " |
| 824 | "out of date!\n")); |
| Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 825 | show_version_only++; |
| 826 | } |
| 827 | |
| 828 | retval = PRS(argc, argv, &ctx); |
| 829 | if (retval) { |
| 830 | com_err("e2fsck", retval, |
| Theodore Ts'o | 0c4a072 | 2000-02-07 03:11:03 +0000 | [diff] [blame] | 831 | _("while trying to initialize program")); |
| Theodore Ts'o | 243dc31 | 2000-08-22 21:37:47 +0000 | [diff] [blame] | 832 | exit(FSCK_ERROR); |
| Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 833 | } |
| Theodore Ts'o | 24fc503 | 1998-08-26 15:23:31 +0000 | [diff] [blame] | 834 | reserve_stdio_fds(); |
| 835 | |
| Theodore Ts'o | 8bf191e | 1997-10-20 01:38:32 +0000 | [diff] [blame] | 836 | #ifdef RESOURCE_TRACK |
| Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 837 | init_resource_track(&ctx->global_rtrack); |
| Theodore Ts'o | 8bf191e | 1997-10-20 01:38:32 +0000 | [diff] [blame] | 838 | #endif |
| Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 839 | |
| 840 | if (!(ctx->options & E2F_OPT_PREEN) || show_version_only) |
| Theodore Ts'o | 908b785 | 2003-04-16 15:20:13 -0400 | [diff] [blame] | 841 | fprintf(stderr, "e2fsck %s (%s)\n", my_ver_string, |
| Theodore Ts'o | 0f8973f | 2001-08-27 12:44:23 -0400 | [diff] [blame] | 842 | my_ver_date); |
| Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 843 | |
| 844 | if (show_version_only) { |
| Theodore Ts'o | 0c4a072 | 2000-02-07 03:11:03 +0000 | [diff] [blame] | 845 | fprintf(stderr, _("\tUsing %s, %s\n"), |
| Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 846 | error_message(EXT2_ET_BASE), lib_ver_date); |
| Theodore Ts'o | 243dc31 | 2000-08-22 21:37:47 +0000 | [diff] [blame] | 847 | exit(FSCK_OK); |
| Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 848 | } |
| 849 | |
| 850 | check_mount(ctx); |
| 851 | |
| 852 | if (!(ctx->options & E2F_OPT_PREEN) && |
| 853 | !(ctx->options & E2F_OPT_NO) && |
| 854 | !(ctx->options & E2F_OPT_YES)) { |
| Theodore Ts'o | 54a31a3 | 2003-08-19 10:08:34 -0400 | [diff] [blame] | 855 | if (!ctx->interactive) |
| Theodore Ts'o | f8188ff | 1997-11-14 05:23:04 +0000 | [diff] [blame] | 856 | fatal_error(ctx, |
| Theodore Ts'o | 0c4a072 | 2000-02-07 03:11:03 +0000 | [diff] [blame] | 857 | _("need terminal for interactive repairs")); |
| Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 858 | } |
| 859 | ctx->superblock = ctx->use_superblock; |
| 860 | restart: |
| Theodore Ts'o | 2a29f13 | 2003-05-05 12:08:47 -0400 | [diff] [blame] | 861 | #ifdef CONFIG_TESTIO_DEBUG |
| Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 862 | io_ptr = test_io_manager; |
| 863 | test_io_backing_manager = unix_io_manager; |
| Theodore Ts'o | 2a29f13 | 2003-05-05 12:08:47 -0400 | [diff] [blame] | 864 | #else |
| 865 | io_ptr = unix_io_manager; |
| Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 866 | #endif |
| Theodore Ts'o | 17390c0 | 2000-07-07 04:13:21 +0000 | [diff] [blame] | 867 | flags = 0; |
| 868 | if ((ctx->options & E2F_OPT_READONLY) == 0) |
| 869 | flags |= EXT2_FLAG_RW; |
| 870 | |
| Theodore Ts'o | f1a1761 | 2001-12-23 22:27:52 -0500 | [diff] [blame] | 871 | if (ctx->superblock && ctx->blocksize) { |
| Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 872 | retval = ext2fs_open(ctx->filesystem_name, flags, |
| Theodore Ts'o | f1a1761 | 2001-12-23 22:27:52 -0500 | [diff] [blame] | 873 | ctx->superblock, ctx->blocksize, |
| 874 | io_ptr, &fs); |
| Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 875 | } else if (ctx->superblock) { |
| Andreas Dilger | 932a489 | 2002-05-16 03:20:07 -0600 | [diff] [blame] | 876 | int blocksize; |
| 877 | for (blocksize = EXT2_MIN_BLOCK_SIZE; |
| 878 | blocksize <= EXT2_MAX_BLOCK_SIZE; blocksize *= 2) { |
| Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 879 | retval = ext2fs_open(ctx->filesystem_name, flags, |
| Andreas Dilger | 932a489 | 2002-05-16 03:20:07 -0600 | [diff] [blame] | 880 | ctx->superblock, blocksize, |
| Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 881 | io_ptr, &fs); |
| 882 | if (!retval) |
| 883 | break; |
| 884 | } |
| 885 | } else |
| 886 | retval = ext2fs_open(ctx->filesystem_name, flags, |
| 887 | 0, 0, io_ptr, &fs); |
| Theodore Ts'o | ae6cdcf | 2001-09-19 15:17:25 -0400 | [diff] [blame] | 888 | if (!ctx->superblock && !(ctx->options & E2F_OPT_PREEN) && |
| 889 | !(ctx->flags & E2F_FLAG_SB_SPECIFIED) && |
| Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 890 | ((retval == EXT2_ET_BAD_MAGIC) || |
| 891 | ((retval == 0) && ext2fs_check_desc(fs)))) { |
| 892 | if (!fs || (fs->group_desc_count > 1)) { |
| Theodore Ts'o | 0c4a072 | 2000-02-07 03:11:03 +0000 | [diff] [blame] | 893 | printf(_("%s trying backup blocks...\n"), |
| 894 | retval ? _("Couldn't find ext2 superblock,") : |
| 895 | _("Group descriptors look bad...")); |
| Theodore Ts'o | f1a1761 | 2001-12-23 22:27:52 -0500 | [diff] [blame] | 896 | get_backup_sb(ctx, fs, ctx->filesystem_name, io_ptr); |
| Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 897 | if (fs) |
| 898 | ext2fs_close(fs); |
| 899 | goto restart; |
| 900 | } |
| 901 | } |
| 902 | if (retval) { |
| Theodore Ts'o | 0c4a072 | 2000-02-07 03:11:03 +0000 | [diff] [blame] | 903 | com_err(ctx->program_name, retval, _("while trying to open %s"), |
| Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 904 | ctx->filesystem_name); |
| Theodore Ts'o | 24dd402 | 1998-02-01 00:16:40 +0000 | [diff] [blame] | 905 | if (retval == EXT2_ET_REV_TOO_HIGH) { |
| Theodore Ts'o | 0c4a072 | 2000-02-07 03:11:03 +0000 | [diff] [blame] | 906 | printf(_("The filesystem revision is apparently " |
| Theodore Ts'o | 24dd402 | 1998-02-01 00:16:40 +0000 | [diff] [blame] | 907 | "too high for this version of e2fsck.\n" |
| 908 | "(Or the filesystem superblock " |
| Theodore Ts'o | 0c4a072 | 2000-02-07 03:11:03 +0000 | [diff] [blame] | 909 | "is corrupt)\n\n")); |
| Theodore Ts'o | 24dd402 | 1998-02-01 00:16:40 +0000 | [diff] [blame] | 910 | fix_problem(ctx, PR_0_SB_CORRUPT, &pctx); |
| 911 | } else if (retval == EXT2_ET_SHORT_READ) |
| Theodore Ts'o | 0c4a072 | 2000-02-07 03:11:03 +0000 | [diff] [blame] | 912 | printf(_("Could this be a zero-length partition?\n")); |
| Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 913 | else if ((retval == EPERM) || (retval == EACCES)) |
| Theodore Ts'o | 0c4a072 | 2000-02-07 03:11:03 +0000 | [diff] [blame] | 914 | printf(_("You must have %s access to the " |
| 915 | "filesystem or be root\n"), |
| Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 916 | (ctx->options & E2F_OPT_READONLY) ? |
| 917 | "r/o" : "r/w"); |
| 918 | else if (retval == ENXIO) |
| Theodore Ts'o | 0c4a072 | 2000-02-07 03:11:03 +0000 | [diff] [blame] | 919 | printf(_("Possibly non-existent or swap device?\n")); |
| Theodore Ts'o | 6822754 | 1997-11-04 04:25:22 +0000 | [diff] [blame] | 920 | #ifdef EROFS |
| 921 | else if (retval == EROFS) |
| Theodore Ts'o | 0c4a072 | 2000-02-07 03:11:03 +0000 | [diff] [blame] | 922 | printf(_("Disk write-protected; use the -n option " |
| Theodore Ts'o | 6822754 | 1997-11-04 04:25:22 +0000 | [diff] [blame] | 923 | "to do a read-only\n" |
| Theodore Ts'o | 0c4a072 | 2000-02-07 03:11:03 +0000 | [diff] [blame] | 924 | "check of the device.\n")); |
| Theodore Ts'o | 6822754 | 1997-11-04 04:25:22 +0000 | [diff] [blame] | 925 | #endif |
| Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 926 | else |
| 927 | fix_problem(ctx, PR_0_SB_CORRUPT, &pctx); |
| Theodore Ts'o | 243dc31 | 2000-08-22 21:37:47 +0000 | [diff] [blame] | 928 | fatal_error(ctx, 0); |
| Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 929 | } |
| 930 | ctx->fs = fs; |
| Theodore Ts'o | 54dc7ca | 1998-01-19 14:50:49 +0000 | [diff] [blame] | 931 | fs->priv_data = ctx; |
| Theodore Ts'o | 5dd8f96 | 2001-01-01 15:51:50 +0000 | [diff] [blame] | 932 | sb = fs->super; |
| 933 | if (sb->s_rev_level > E2FSCK_CURRENT_REV) { |
| Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 934 | com_err(ctx->program_name, EXT2_ET_REV_TOO_HIGH, |
| Theodore Ts'o | 0c4a072 | 2000-02-07 03:11:03 +0000 | [diff] [blame] | 935 | _("while trying to open %s"), |
| Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 936 | ctx->filesystem_name); |
| Theodore Ts'o | f8188ff | 1997-11-14 05:23:04 +0000 | [diff] [blame] | 937 | get_newer: |
| Theodore Ts'o | 0c4a072 | 2000-02-07 03:11:03 +0000 | [diff] [blame] | 938 | fatal_error(ctx, _("Get a newer version of e2fsck!")); |
| Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 939 | } |
| Theodore Ts'o | 3b5386d | 2000-08-14 14:25:19 +0000 | [diff] [blame] | 940 | |
| Theodore Ts'o | 17390c0 | 2000-07-07 04:13:21 +0000 | [diff] [blame] | 941 | /* |
| Theodore Ts'o | 3b5386d | 2000-08-14 14:25:19 +0000 | [diff] [blame] | 942 | * Set the device name, which is used whenever we print error |
| 943 | * or informational messages to the user. |
| Theodore Ts'o | 17390c0 | 2000-07-07 04:13:21 +0000 | [diff] [blame] | 944 | */ |
| Theodore Ts'o | 5596def | 1999-07-19 15:27:37 +0000 | [diff] [blame] | 945 | if (ctx->device_name == 0 && |
| Theodore Ts'o | 5dd8f96 | 2001-01-01 15:51:50 +0000 | [diff] [blame] | 946 | (sb->s_volume_name[0] != 0)) { |
| Theodore Ts'o | f364093 | 2003-03-01 19:47:44 -0500 | [diff] [blame] | 947 | ctx->device_name = string_copy(ctx, sb->s_volume_name, |
| 948 | sizeof(sb->s_volume_name)); |
| Theodore Ts'o | 5596def | 1999-07-19 15:27:37 +0000 | [diff] [blame] | 949 | } |
| 950 | if (ctx->device_name == 0) |
| 951 | ctx->device_name = ctx->filesystem_name; |
| Theodore Ts'o | 3b5386d | 2000-08-14 14:25:19 +0000 | [diff] [blame] | 952 | |
| 953 | /* |
| Theodore Ts'o | 9b56575 | 2000-12-13 18:50:22 +0000 | [diff] [blame] | 954 | * Make sure the ext3 superblock fields are consistent. |
| Theodore Ts'o | 3b5386d | 2000-08-14 14:25:19 +0000 | [diff] [blame] | 955 | */ |
| 956 | retval = e2fsck_check_ext3_journal(ctx); |
| 957 | if (retval) { |
| 958 | com_err(ctx->program_name, retval, |
| 959 | _("while checking ext3 journal for %s"), |
| 960 | ctx->device_name); |
| Theodore Ts'o | 243dc31 | 2000-08-22 21:37:47 +0000 | [diff] [blame] | 961 | fatal_error(ctx, 0); |
| Theodore Ts'o | 3b5386d | 2000-08-14 14:25:19 +0000 | [diff] [blame] | 962 | } |
| 963 | |
| Theodore Ts'o | 9b56575 | 2000-12-13 18:50:22 +0000 | [diff] [blame] | 964 | /* |
| 965 | * Check to see if we need to do ext3-style recovery. If so, |
| 966 | * do it, and then restart the fsck. |
| 967 | */ |
| Theodore Ts'o | 5dd8f96 | 2001-01-01 15:51:50 +0000 | [diff] [blame] | 968 | if (sb->s_feature_incompat & EXT3_FEATURE_INCOMPAT_RECOVER) { |
| Theodore Ts'o | 2575fb0 | 2000-08-22 21:50:04 +0000 | [diff] [blame] | 969 | if (ctx->options & E2F_OPT_READONLY) { |
| 970 | printf(_("Warning: skipping journal recovery " |
| 971 | "because doing a read-only filesystem " |
| 972 | "check.\n")); |
| 973 | io_channel_flush(ctx->fs->io); |
| 974 | } else { |
| Theodore Ts'o | b92ae15 | 2003-01-02 16:53:54 -0500 | [diff] [blame] | 975 | if (ctx->flags & E2F_FLAG_RESTARTED) { |
| 976 | /* |
| 977 | * Whoops, we attempted to run the |
| 978 | * journal twice. This should never |
| 979 | * happen, unless the hardware or |
| 980 | * device driver is being bogus. |
| 981 | */ |
| 982 | com_err(ctx->program_name, 0, |
| 983 | _("unable to set superblock flags on %s\n"), ctx->device_name); |
| 984 | fatal_error(ctx, 0); |
| 985 | } |
| Theodore Ts'o | 2575fb0 | 2000-08-22 21:50:04 +0000 | [diff] [blame] | 986 | retval = e2fsck_run_ext3_journal(ctx); |
| 987 | if (retval) { |
| 988 | com_err(ctx->program_name, retval, |
| Theodore Ts'o | 3b5386d | 2000-08-14 14:25:19 +0000 | [diff] [blame] | 989 | _("while recovering ext3 journal of %s"), |
| Theodore Ts'o | 2575fb0 | 2000-08-22 21:50:04 +0000 | [diff] [blame] | 990 | ctx->device_name); |
| 991 | fatal_error(ctx, 0); |
| 992 | } |
| 993 | ext2fs_close(ctx->fs); |
| 994 | ctx->fs = 0; |
| Theodore Ts'o | b92ae15 | 2003-01-02 16:53:54 -0500 | [diff] [blame] | 995 | ctx->flags |= E2F_FLAG_RESTARTED; |
| Theodore Ts'o | 2575fb0 | 2000-08-22 21:50:04 +0000 | [diff] [blame] | 996 | goto restart; |
| Theodore Ts'o | 3b5386d | 2000-08-14 14:25:19 +0000 | [diff] [blame] | 997 | } |
| Theodore Ts'o | 3b5386d | 2000-08-14 14:25:19 +0000 | [diff] [blame] | 998 | } |
| 999 | |
| 1000 | /* |
| 1001 | * Check for compatibility with the feature sets. We need to |
| 1002 | * be more stringent than ext2fs_open(). |
| 1003 | */ |
| Theodore Ts'o | 5dd8f96 | 2001-01-01 15:51:50 +0000 | [diff] [blame] | 1004 | if ((sb->s_feature_compat & ~EXT2_LIB_FEATURE_COMPAT_SUPP) || |
| 1005 | (sb->s_feature_incompat & ~EXT2_LIB_FEATURE_INCOMPAT_SUPP)) { |
| Theodore Ts'o | 3b5386d | 2000-08-14 14:25:19 +0000 | [diff] [blame] | 1006 | com_err(ctx->program_name, EXT2_ET_UNSUPP_FEATURE, |
| 1007 | "(%s)", ctx->device_name); |
| 1008 | goto get_newer; |
| 1009 | } |
| Theodore Ts'o | 5dd8f96 | 2001-01-01 15:51:50 +0000 | [diff] [blame] | 1010 | if (sb->s_feature_ro_compat & ~EXT2_LIB_FEATURE_RO_COMPAT_SUPP) { |
| Theodore Ts'o | 3b5386d | 2000-08-14 14:25:19 +0000 | [diff] [blame] | 1011 | com_err(ctx->program_name, EXT2_ET_RO_UNSUPP_FEATURE, |
| 1012 | "(%s)", ctx->device_name); |
| 1013 | goto get_newer; |
| 1014 | } |
| 1015 | #ifdef ENABLE_COMPRESSION |
| Theodore Ts'o | 5dd8f96 | 2001-01-01 15:51:50 +0000 | [diff] [blame] | 1016 | if (sb->s_feature_incompat & EXT2_FEATURE_INCOMPAT_COMPRESSION) |
| Theodore Ts'o | 3b5386d | 2000-08-14 14:25:19 +0000 | [diff] [blame] | 1017 | com_err(ctx->program_name, 0, |
| 1018 | _("Warning: compression support is experimental.\n")); |
| 1019 | #endif |
| Theodore Ts'o | 8fdc998 | 2002-06-25 23:26:34 -0400 | [diff] [blame] | 1020 | #ifndef ENABLE_HTREE |
| 1021 | if (sb->s_feature_compat & EXT2_FEATURE_COMPAT_DIR_INDEX) { |
| 1022 | com_err(ctx->program_name, 0, |
| 1023 | _("E2fsck not compiled with HTREE support,\n\t" |
| 1024 | "but filesystem %s has HTREE directories.\n"), |
| 1025 | ctx->device_name); |
| 1026 | goto get_newer; |
| 1027 | } |
| 1028 | #endif |
| 1029 | |
| Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 1030 | /* |
| 1031 | * If the user specified a specific superblock, presumably the |
| 1032 | * master superblock has been trashed. So we mark the |
| 1033 | * superblock as dirty, so it can be written out. |
| 1034 | */ |
| 1035 | if (ctx->superblock && |
| 1036 | !(ctx->options & E2F_OPT_READONLY)) |
| 1037 | ext2fs_mark_super_dirty(fs); |
| 1038 | |
| 1039 | /* |
| Theodore Ts'o | e70ae99 | 2002-09-28 09:16:28 -0400 | [diff] [blame] | 1040 | * We only update the master superblock because (a) paranoia; |
| 1041 | * we don't want to corrupt the backup superblocks, and (b) we |
| 1042 | * don't need to update the mount count and last checked |
| 1043 | * fields in the backup superblock (the kernel doesn't |
| 1044 | * update the backup superblocks anyway). |
| Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 1045 | */ |
| 1046 | fs->flags |= EXT2_FLAG_MASTER_SB_ONLY; |
| 1047 | |
| 1048 | ehandler_init(fs->io); |
| 1049 | |
| 1050 | if (ctx->superblock) |
| 1051 | set_latch_flags(PR_LATCH_RELOC, PRL_LATCHED, 0); |
| 1052 | check_super_block(ctx); |
| Theodore Ts'o | a02ce9d | 1998-02-24 20:22:23 +0000 | [diff] [blame] | 1053 | if (ctx->flags & E2F_FLAG_SIGNAL_MASK) |
| Theodore Ts'o | 243dc31 | 2000-08-22 21:37:47 +0000 | [diff] [blame] | 1054 | fatal_error(ctx, 0); |
| Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 1055 | check_if_skip(ctx); |
| 1056 | if (bad_blocks_file) |
| 1057 | read_bad_blocks_file(ctx, bad_blocks_file, replace_bad_blocks); |
| 1058 | else if (cflag) |
| Theodore Ts'o | 4fb9d52 | 2004-02-24 00:16:09 -0500 | [diff] [blame] | 1059 | read_bad_blocks_file(ctx, 0, !keep_bad_blocks); /* Test disk */ |
| Theodore Ts'o | a02ce9d | 1998-02-24 20:22:23 +0000 | [diff] [blame] | 1060 | if (ctx->flags & E2F_FLAG_SIGNAL_MASK) |
| Theodore Ts'o | 243dc31 | 2000-08-22 21:37:47 +0000 | [diff] [blame] | 1061 | fatal_error(ctx, 0); |
| Theodore Ts'o | 5df55d7 | 2001-06-11 07:00:04 +0000 | [diff] [blame] | 1062 | #ifdef ENABLE_SWAPFS |
| Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 1063 | if (normalize_swapfs) { |
| 1064 | if ((fs->flags & EXT2_FLAG_SWAP_BYTES) == |
| 1065 | ext2fs_native_flag()) { |
| Theodore Ts'o | 0c4a072 | 2000-02-07 03:11:03 +0000 | [diff] [blame] | 1066 | fprintf(stderr, _("%s: Filesystem byte order " |
| 1067 | "already normalized.\n"), ctx->device_name); |
| Theodore Ts'o | 243dc31 | 2000-08-22 21:37:47 +0000 | [diff] [blame] | 1068 | fatal_error(ctx, 0); |
| Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 1069 | } |
| 1070 | } |
| Theodore Ts'o | f8188ff | 1997-11-14 05:23:04 +0000 | [diff] [blame] | 1071 | if (swapfs) { |
| Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 1072 | swap_filesys(ctx); |
| Theodore Ts'o | a02ce9d | 1998-02-24 20:22:23 +0000 | [diff] [blame] | 1073 | if (ctx->flags & E2F_FLAG_SIGNAL_MASK) |
| Theodore Ts'o | 243dc31 | 2000-08-22 21:37:47 +0000 | [diff] [blame] | 1074 | fatal_error(ctx, 0); |
| Theodore Ts'o | f8188ff | 1997-11-14 05:23:04 +0000 | [diff] [blame] | 1075 | } |
| Theodore Ts'o | 5df55d7 | 2001-06-11 07:00:04 +0000 | [diff] [blame] | 1076 | #endif |
| Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 1077 | |
| 1078 | /* |
| 1079 | * Mark the system as valid, 'til proven otherwise |
| 1080 | */ |
| 1081 | ext2fs_mark_valid(fs); |
| 1082 | |
| 1083 | retval = ext2fs_read_bb_inode(fs, &fs->badblocks); |
| 1084 | if (retval) { |
| 1085 | com_err(ctx->program_name, retval, |
| Theodore Ts'o | 0c4a072 | 2000-02-07 03:11:03 +0000 | [diff] [blame] | 1086 | _("while reading bad blocks inode")); |
| Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 1087 | preenhalt(ctx); |
| Theodore Ts'o | 0c4a072 | 2000-02-07 03:11:03 +0000 | [diff] [blame] | 1088 | printf(_("This doesn't bode well," |
| 1089 | " but we'll try to go on...\n")); |
| Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 1090 | } |
| Theodore Ts'o | 08b2130 | 1997-11-03 19:42:40 +0000 | [diff] [blame] | 1091 | |
| 1092 | run_result = e2fsck_run(ctx); |
| Theodore Ts'o | 5596def | 1999-07-19 15:27:37 +0000 | [diff] [blame] | 1093 | e2fsck_clear_progbar(ctx); |
| Theodore Ts'o | 08b2130 | 1997-11-03 19:42:40 +0000 | [diff] [blame] | 1094 | if (run_result == E2F_FLAG_RESTART) { |
| Theodore Ts'o | 0c4a072 | 2000-02-07 03:11:03 +0000 | [diff] [blame] | 1095 | printf(_("Restarting e2fsck from the beginning...\n")); |
| Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 1096 | retval = e2fsck_reset_context(ctx); |
| 1097 | if (retval) { |
| 1098 | com_err(ctx->program_name, retval, |
| Theodore Ts'o | 0c4a072 | 2000-02-07 03:11:03 +0000 | [diff] [blame] | 1099 | _("while resetting context")); |
| Theodore Ts'o | 243dc31 | 2000-08-22 21:37:47 +0000 | [diff] [blame] | 1100 | fatal_error(ctx, 0); |
| Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 1101 | } |
| Theodore Ts'o | 73f17cf | 1999-01-04 07:35:45 +0000 | [diff] [blame] | 1102 | ext2fs_close(fs); |
| Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 1103 | goto restart; |
| 1104 | } |
| Theodore Ts'o | 4cae045 | 2002-07-21 14:14:03 -0400 | [diff] [blame] | 1105 | if (run_result & E2F_FLAG_CANCEL) { |
| 1106 | printf(_("%s: e2fsck canceled.\n"), ctx->device_name ? |
| 1107 | ctx->device_name : ctx->filesystem_name); |
| 1108 | exit_value |= FSCK_CANCELED; |
| 1109 | } |
| 1110 | if (run_result & E2F_FLAG_ABORT) |
| 1111 | fatal_error(ctx, _("aborted")); |
| Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 1112 | |
| 1113 | #ifdef MTRACE |
| 1114 | mtrace_print("Cleanup"); |
| 1115 | #endif |
| 1116 | if (ext2fs_test_changed(fs)) { |
| Theodore Ts'o | 4cae045 | 2002-07-21 14:14:03 -0400 | [diff] [blame] | 1117 | exit_value |= FSCK_NONDESTRUCT; |
| Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 1118 | if (!(ctx->options & E2F_OPT_PREEN)) |
| Theodore Ts'o | 0c4a072 | 2000-02-07 03:11:03 +0000 | [diff] [blame] | 1119 | printf(_("\n%s: ***** FILE SYSTEM WAS MODIFIED *****\n"), |
| Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 1120 | ctx->device_name); |
| Theodore Ts'o | ee89513 | 2002-11-07 16:16:55 -0500 | [diff] [blame] | 1121 | if (ctx->mount_flags & EXT2_MF_ISROOT) { |
| Theodore Ts'o | 0c4a072 | 2000-02-07 03:11:03 +0000 | [diff] [blame] | 1122 | printf(_("%s: ***** REBOOT LINUX *****\n"), |
| Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 1123 | ctx->device_name); |
| Theodore Ts'o | 4cae045 | 2002-07-21 14:14:03 -0400 | [diff] [blame] | 1124 | exit_value |= FSCK_REBOOT; |
| Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 1125 | } |
| 1126 | } |
| Theodore Ts'o | e70ae99 | 2002-09-28 09:16:28 -0400 | [diff] [blame] | 1127 | if (!ext2fs_test_valid(fs)) { |
| Theodore Ts'o | d312401 | 2001-07-20 14:13:49 -0400 | [diff] [blame] | 1128 | printf(_("\n%s: ********** WARNING: Filesystem still has " |
| 1129 | "errors **********\n\n"), ctx->device_name); |
| Theodore Ts'o | 4cae045 | 2002-07-21 14:14:03 -0400 | [diff] [blame] | 1130 | exit_value |= FSCK_UNCORRECTED; |
| 1131 | exit_value &= ~FSCK_NONDESTRUCT; |
| Theodore Ts'o | d312401 | 2001-07-20 14:13:49 -0400 | [diff] [blame] | 1132 | } |
| Theodore Ts'o | 4cae045 | 2002-07-21 14:14:03 -0400 | [diff] [blame] | 1133 | if (exit_value & FSCK_CANCELED) |
| 1134 | exit_value &= ~FSCK_NONDESTRUCT; |
| Theodore Ts'o | c1637bd | 2002-11-08 15:55:17 -0500 | [diff] [blame] | 1135 | else { |
| Theodore Ts'o | 4cae045 | 2002-07-21 14:14:03 -0400 | [diff] [blame] | 1136 | show_stats(ctx); |
| Theodore Ts'o | c1637bd | 2002-11-08 15:55:17 -0500 | [diff] [blame] | 1137 | if (!(ctx->options & E2F_OPT_READONLY)) { |
| 1138 | if (ext2fs_test_valid(fs)) { |
| 1139 | if (!(sb->s_state & EXT2_VALID_FS)) |
| 1140 | exit_value |= FSCK_NONDESTRUCT; |
| 1141 | sb->s_state = EXT2_VALID_FS; |
| 1142 | } else |
| 1143 | sb->s_state &= ~EXT2_VALID_FS; |
| 1144 | sb->s_mnt_count = 0; |
| 1145 | sb->s_lastcheck = time(NULL); |
| 1146 | ext2fs_mark_super_dirty(fs); |
| 1147 | } |
| 1148 | } |
| Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 1149 | |
| Theodore Ts'o | f8188ff | 1997-11-14 05:23:04 +0000 | [diff] [blame] | 1150 | e2fsck_write_bitmaps(ctx); |
| Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 1151 | |
| Theodore Ts'o | 0628ae3 | 2001-07-29 12:26:46 -0400 | [diff] [blame] | 1152 | ext2fs_close(fs); |
| 1153 | ctx->fs = NULL; |
| Theodore Ts'o | f364093 | 2003-03-01 19:47:44 -0500 | [diff] [blame] | 1154 | free(ctx->filesystem_name); |
| 1155 | free(ctx->journal_name); |
| Theodore Ts'o | 0628ae3 | 2001-07-29 12:26:46 -0400 | [diff] [blame] | 1156 | e2fsck_free_context(ctx); |
| 1157 | |
| Theodore Ts'o | 8bf191e | 1997-10-20 01:38:32 +0000 | [diff] [blame] | 1158 | #ifdef RESOURCE_TRACK |
| Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 1159 | if (ctx->options & E2F_OPT_TIME) |
| 1160 | print_resource_track(NULL, &ctx->global_rtrack); |
| Theodore Ts'o | 8bf191e | 1997-10-20 01:38:32 +0000 | [diff] [blame] | 1161 | #endif |
| Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 1162 | |
| Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 1163 | return exit_value; |
| 1164 | } |