Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 1 | /* vi: set sw=4 ts=4: */ |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 2 | /* |
| 3 | * fsck.c - a file system consistency checker for Linux. |
| 4 | * |
| 5 | * (C) 1991, 1992 Linus Torvalds. This file may be redistributed |
| 6 | * as per the GNU copyleft. |
| 7 | */ |
| 8 | |
| 9 | /* |
| 10 | * 09.11.91 - made the first rudimetary functions |
| 11 | * |
| 12 | * 10.11.91 - updated, does checking, no repairs yet. |
| 13 | * Sent out to the mailing-list for testing. |
| 14 | * |
| 15 | * 14.11.91 - Testing seems to have gone well. Added some |
| 16 | * correction-code, and changed some functions. |
| 17 | * |
| 18 | * 15.11.91 - More correction code. Hopefully it notices most |
| 19 | * cases now, and tries to do something about them. |
| 20 | * |
| 21 | * 16.11.91 - More corrections (thanks to Mika Jalava). Most |
| 22 | * things seem to work now. Yeah, sure. |
| 23 | * |
| 24 | * |
| 25 | * 19.04.92 - Had to start over again from this old version, as a |
| 26 | * kernel bug ate my enhanced fsck in february. |
| 27 | * |
| 28 | * 28.02.93 - added support for different directory entry sizes.. |
| 29 | * |
| 30 | * Sat Mar 6 18:59:42 1993, faith@cs.unc.edu: Output namelen with |
| 31 | * super-block information |
| 32 | * |
| 33 | * Sat Oct 9 11:17:11 1993, faith@cs.unc.edu: make exit status conform |
| 34 | * to that required by fsutil |
| 35 | * |
| 36 | * Mon Jan 3 11:06:52 1994 - Dr. Wettstein (greg%wind.uucp@plains.nodak.edu) |
| 37 | * Added support for file system valid flag. Also |
| 38 | * added program_version variable and output of |
| 39 | * program name and version number when program |
| 40 | * is executed. |
| 41 | * |
| 42 | * 30.10.94 - added support for v2 filesystem |
| 43 | * (Andreas Schwab, schwab@issan.informatik.uni-dortmund.de) |
| 44 | * |
| 45 | * 10.12.94 - added test to prevent checking of mounted fs adapted |
| 46 | * from Theodore Ts'o's (tytso@athena.mit.edu) e2fsck |
| 47 | * program. (Daniel Quinlan, quinlan@yggdrasil.com) |
| 48 | * |
| 49 | * 01.07.96 - Fixed the v2 fs stuff to use the right #defines and such |
| 50 | * for modern libcs (janl@math.uio.no, Nicolai Langfeldt) |
| 51 | * |
| 52 | * 02.07.96 - Added C bit fiddling routines from rmk@ecs.soton.ac.uk |
| 53 | * (Russell King). He made them for ARM. It would seem |
| 54 | * that the ARM is powerful enough to do this in C whereas |
| 55 | * i386 and m64k must use assembly to get it fast >:-) |
| 56 | * This should make minix fsck systemindependent. |
| 57 | * (janl@math.uio.no, Nicolai Langfeldt) |
| 58 | * |
| 59 | * 04.11.96 - Added minor fixes from Andreas Schwab to avoid compiler |
| 60 | * warnings. Added mc68k bitops from |
| 61 | * Joerg Dorchain <dorchain@mpi-sb.mpg.de>. |
| 62 | * |
| 63 | * 06.11.96 - Added v2 code submitted by Joerg Dorchain, but written by |
| 64 | * Andreas Schwab. |
| 65 | * |
| 66 | * 1999-02-22 Arkadiusz Mi¶kiewicz <misiek@misiek.eu.org> |
| 67 | * - added Native Language Support |
| 68 | * |
| 69 | * |
| 70 | * I've had no time to add comments - hopefully the function names |
| 71 | * are comments enough. As with all file system checkers, this assumes |
| 72 | * the file system is quiescent - don't use it on a mounted device |
| 73 | * unless you can be sure nobody is writing to it (and remember that the |
| 74 | * kernel can write to it when it searches for files). |
| 75 | * |
| 76 | * Usuage: fsck [-larvsm] device |
| 77 | * -l for a listing of all the filenames |
| 78 | * -a for automatic repairs (not implemented) |
| 79 | * -r for repairs (interactive) (not implemented) |
| 80 | * -v for verbose (tells how many files) |
| 81 | * -s for super-block info |
| 82 | * -m for minix-like "mode not cleared" warnings |
| 83 | * -f force filesystem check even if filesystem marked as valid |
| 84 | * |
| 85 | * The device may be a block device or a image of one, but this isn't |
| 86 | * enforced (but it's not much fun on a character device :-). |
| 87 | */ |
| 88 | |
Eric Andersen | e674eb7 | 1999-10-19 20:52:57 +0000 | [diff] [blame] | 89 | #include "internal.h" |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 90 | #include <stdio.h> |
| 91 | #include <errno.h> |
| 92 | #include <unistd.h> |
| 93 | #include <string.h> |
| 94 | #include <fcntl.h> |
| 95 | #include <ctype.h> |
| 96 | #include <stdlib.h> |
| 97 | #include <termios.h> |
| 98 | #include <mntent.h> |
Erik Andersen | 8ea7d8c | 2000-05-20 00:40:08 +0000 | [diff] [blame] | 99 | #include <sys/param.h> |
Eric Andersen | 85c5520 | 2000-07-10 22:46:55 +0000 | [diff] [blame] | 100 | |
| 101 | |
| 102 | typedef unsigned char u8; |
| 103 | typedef unsigned short u16; |
| 104 | typedef unsigned int u32; |
| 105 | |
| 106 | |
| 107 | #define MINIX_ROOT_INO 1 |
| 108 | #define MINIX_LINK_MAX 250 |
| 109 | #define MINIX2_LINK_MAX 65530 |
| 110 | |
| 111 | #define MINIX_I_MAP_SLOTS 8 |
| 112 | #define MINIX_Z_MAP_SLOTS 64 |
| 113 | #define MINIX_SUPER_MAGIC 0x137F /* original minix fs */ |
| 114 | #define MINIX_SUPER_MAGIC2 0x138F /* minix fs, 30 char names */ |
| 115 | #define MINIX2_SUPER_MAGIC 0x2468 /* minix V2 fs */ |
| 116 | #define MINIX2_SUPER_MAGIC2 0x2478 /* minix V2 fs, 30 char names */ |
| 117 | #define MINIX_VALID_FS 0x0001 /* Clean fs. */ |
| 118 | #define MINIX_ERROR_FS 0x0002 /* fs has errors. */ |
| 119 | |
| 120 | #define MINIX_INODES_PER_BLOCK ((BLOCK_SIZE)/(sizeof (struct minix_inode))) |
| 121 | #define MINIX2_INODES_PER_BLOCK ((BLOCK_SIZE)/(sizeof (struct minix2_inode))) |
| 122 | |
| 123 | #define MINIX_V1 0x0001 /* original minix fs */ |
| 124 | #define MINIX_V2 0x0002 /* minix V2 fs */ |
| 125 | |
| 126 | #define INODE_VERSION(inode) inode->i_sb->u.minix_sb.s_version |
| 127 | |
| 128 | /* |
| 129 | * This is the original minix inode layout on disk. |
| 130 | * Note the 8-bit gid and atime and ctime. |
| 131 | */ |
| 132 | struct minix_inode { |
| 133 | u16 i_mode; |
| 134 | u16 i_uid; |
| 135 | u32 i_size; |
| 136 | u32 i_time; |
| 137 | u8 i_gid; |
| 138 | u8 i_nlinks; |
| 139 | u16 i_zone[9]; |
| 140 | }; |
| 141 | |
| 142 | /* |
| 143 | * The new minix inode has all the time entries, as well as |
| 144 | * long block numbers and a third indirect block (7+1+1+1 |
| 145 | * instead of 7+1+1). Also, some previously 8-bit values are |
| 146 | * now 16-bit. The inode is now 64 bytes instead of 32. |
| 147 | */ |
| 148 | struct minix2_inode { |
| 149 | u16 i_mode; |
| 150 | u16 i_nlinks; |
| 151 | u16 i_uid; |
| 152 | u16 i_gid; |
| 153 | u32 i_size; |
| 154 | u32 i_atime; |
| 155 | u32 i_mtime; |
| 156 | u32 i_ctime; |
| 157 | u32 i_zone[10]; |
| 158 | }; |
| 159 | |
| 160 | /* |
| 161 | * minix super-block data on disk |
| 162 | */ |
| 163 | struct minix_super_block { |
| 164 | u16 s_ninodes; |
| 165 | u16 s_nzones; |
| 166 | u16 s_imap_blocks; |
| 167 | u16 s_zmap_blocks; |
| 168 | u16 s_firstdatazone; |
| 169 | u16 s_log_zone_size; |
| 170 | u32 s_max_size; |
| 171 | u16 s_magic; |
| 172 | u16 s_state; |
| 173 | u32 s_zones; |
| 174 | }; |
| 175 | |
| 176 | struct minix_dir_entry { |
| 177 | u16 inode; |
| 178 | char name[0]; |
| 179 | }; |
| 180 | |
| 181 | #define BLOCK_SIZE_BITS 10 |
| 182 | #define BLOCK_SIZE (1<<BLOCK_SIZE_BITS) |
| 183 | |
| 184 | #define NAME_MAX 255 /* # chars in a file name */ |
| 185 | |
| 186 | #define MINIX_INODES_PER_BLOCK ((BLOCK_SIZE)/(sizeof (struct minix_inode))) |
| 187 | |
| 188 | #define MINIX_VALID_FS 0x0001 /* Clean fs. */ |
| 189 | #define MINIX_ERROR_FS 0x0002 /* fs has errors. */ |
| 190 | |
| 191 | #define MINIX_SUPER_MAGIC 0x137F /* original minix fs */ |
| 192 | #define MINIX_SUPER_MAGIC2 0x138F /* minix fs, 30 char names */ |
| 193 | |
| 194 | #ifndef BLKGETSIZE |
| 195 | #define BLKGETSIZE _IO(0x12,96) /* return device size */ |
| 196 | #endif |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 197 | |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 198 | #ifndef __linux__ |
| 199 | #define volatile |
| 200 | #endif |
| 201 | |
| 202 | #define ROOT_INO 1 |
| 203 | |
| 204 | #define UPPER(size,n) ((size+((n)-1))/(n)) |
| 205 | #define INODE_SIZE (sizeof(struct minix_inode)) |
Pavel Roskin | bc0aed7 | 2000-07-17 17:52:00 +0000 | [diff] [blame] | 206 | #ifdef BB_FEATURE_MINIX2 |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 207 | #define INODE_SIZE2 (sizeof(struct minix2_inode)) |
| 208 | #define INODE_BLOCKS UPPER(INODES, (version2 ? MINIX2_INODES_PER_BLOCK \ |
| 209 | : MINIX_INODES_PER_BLOCK)) |
| 210 | #else |
| 211 | #define INODE_BLOCKS UPPER(INODES, (MINIX_INODES_PER_BLOCK)) |
| 212 | #endif |
| 213 | #define INODE_BUFFER_SIZE (INODE_BLOCKS * BLOCK_SIZE) |
| 214 | |
| 215 | #define BITS_PER_BLOCK (BLOCK_SIZE<<3) |
| 216 | |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 217 | static char *program_version = "1.2 - 11/11/96"; |
| 218 | static char *device_name = NULL; |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 219 | static int IN; |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 220 | static int repair = 0, automatic = 0, verbose = 0, list = 0, show = |
| 221 | 0, warn_mode = 0, force = 0; |
| 222 | static int directory = 0, regular = 0, blockdev = 0, chardev = 0, links = |
| 223 | 0, symlinks = 0, total = 0; |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 224 | |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 225 | static int changed = 0; /* flags if the filesystem has been changed */ |
| 226 | static int errors_uncorrected = 0; /* flag if some error was not corrected */ |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 227 | static int dirsize = 16; |
| 228 | static int namelen = 14; |
| 229 | static int version2 = 0; |
| 230 | static struct termios termios; |
| 231 | static int termios_set = 0; |
| 232 | |
| 233 | /* File-name data */ |
John Beppu | c1dc5d9 | 2000-02-11 12:43:20 +0000 | [diff] [blame] | 234 | #define MAX_DEPTH 32 |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 235 | static int name_depth = 0; |
Erik Andersen | 4f3f757 | 2000-04-28 00:18:56 +0000 | [diff] [blame] | 236 | // static char name_list[MAX_DEPTH][BUFSIZ + 1]; |
John Beppu | 5e1b2ca | 2000-02-11 12:52:55 +0000 | [diff] [blame] | 237 | static char **name_list = NULL; |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 238 | |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 239 | static char *inode_buffer = NULL; |
| 240 | |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 241 | #define Inode (((struct minix_inode *) inode_buffer)-1) |
| 242 | #define Inode2 (((struct minix2_inode *) inode_buffer)-1) |
| 243 | static char super_block_buffer[BLOCK_SIZE]; |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 244 | |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 245 | #define Super (*(struct minix_super_block *)super_block_buffer) |
| 246 | #define INODES ((unsigned long)Super.s_ninodes) |
Pavel Roskin | bc0aed7 | 2000-07-17 17:52:00 +0000 | [diff] [blame] | 247 | #ifdef BB_FEATURE_MINIX2 |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 248 | #define ZONES ((unsigned long)(version2 ? Super.s_zones : Super.s_nzones)) |
| 249 | #else |
| 250 | #define ZONES ((unsigned long)(Super.s_nzones)) |
| 251 | #endif |
| 252 | #define IMAPS ((unsigned long)Super.s_imap_blocks) |
| 253 | #define ZMAPS ((unsigned long)Super.s_zmap_blocks) |
| 254 | #define FIRSTZONE ((unsigned long)Super.s_firstdatazone) |
| 255 | #define ZONESIZE ((unsigned long)Super.s_log_zone_size) |
| 256 | #define MAXSIZE ((unsigned long)Super.s_max_size) |
| 257 | #define MAGIC (Super.s_magic) |
| 258 | #define NORM_FIRSTZONE (2+IMAPS+ZMAPS+INODE_BLOCKS) |
| 259 | |
| 260 | static char *inode_map; |
| 261 | static char *zone_map; |
| 262 | |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 263 | static unsigned char *inode_count = NULL; |
| 264 | static unsigned char *zone_count = NULL; |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 265 | |
Eric Andersen | e674eb7 | 1999-10-19 20:52:57 +0000 | [diff] [blame] | 266 | static void recursive_check(unsigned int ino); |
Pavel Roskin | bc0aed7 | 2000-07-17 17:52:00 +0000 | [diff] [blame] | 267 | #ifdef BB_FEATURE_MINIX2 |
Eric Andersen | e674eb7 | 1999-10-19 20:52:57 +0000 | [diff] [blame] | 268 | static void recursive_check2(unsigned int ino); |
Pavel Roskin | bc0aed7 | 2000-07-17 17:52:00 +0000 | [diff] [blame] | 269 | #endif |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 270 | |
Eric Andersen | 56f3e35 | 2000-09-19 21:13:55 +0000 | [diff] [blame^] | 271 | static inline int bit(char * a,unsigned int i) |
| 272 | { |
| 273 | return (a[i >> 3] & (1<<(i & 7))) != 0; |
| 274 | } |
| 275 | #define inode_in_use(x) (bit(inode_map,(x))) |
| 276 | #define zone_in_use(x) (bit(zone_map,(x)-FIRSTZONE+1)) |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 277 | |
| 278 | #define mark_inode(x) (setbit(inode_map,(x)),changed=1) |
| 279 | #define unmark_inode(x) (clrbit(inode_map,(x)),changed=1) |
| 280 | |
| 281 | #define mark_zone(x) (setbit(zone_map,(x)-FIRSTZONE+1),changed=1) |
| 282 | #define unmark_zone(x) (clrbit(zone_map,(x)-FIRSTZONE+1),changed=1) |
| 283 | |
Eric Andersen | e674eb7 | 1999-10-19 20:52:57 +0000 | [diff] [blame] | 284 | static void leave(int) __attribute__ ((noreturn)); |
| 285 | static void leave(int status) |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 286 | { |
| 287 | if (termios_set) |
| 288 | tcsetattr(0, TCSANOW, &termios); |
| 289 | exit(status); |
| 290 | } |
| 291 | |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 292 | static void show_usage(void) |
| 293 | { |
Matt Kraai | 3bd8bd8 | 2000-07-14 23:28:47 +0000 | [diff] [blame] | 294 | usage(fsck_minix_usage); |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 295 | } |
| 296 | |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 297 | static void die(const char *str) |
| 298 | { |
Matt Kraai | d537a95 | 2000-07-14 01:51:25 +0000 | [diff] [blame] | 299 | errorMsg("%s\n", str); |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 300 | leave(8); |
| 301 | } |
| 302 | |
| 303 | /* |
| 304 | * This simply goes through the file-name data and prints out the |
| 305 | * current file. |
| 306 | */ |
Eric Andersen | e674eb7 | 1999-10-19 20:52:57 +0000 | [diff] [blame] | 307 | static void print_current_name(void) |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 308 | { |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 309 | int i = 0; |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 310 | |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 311 | while (i < name_depth) |
| 312 | printf("/%.*s", namelen, name_list[i++]); |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 313 | if (i == 0) |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 314 | printf("/"); |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 315 | } |
| 316 | |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 317 | static int ask(const char *string, int def) |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 318 | { |
| 319 | int c; |
| 320 | |
| 321 | if (!repair) { |
| 322 | printf("\n"); |
| 323 | errors_uncorrected = 1; |
| 324 | return 0; |
| 325 | } |
| 326 | if (automatic) { |
| 327 | printf("\n"); |
| 328 | if (!def) |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 329 | errors_uncorrected = 1; |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 330 | return def; |
| 331 | } |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 332 | printf(def ? "%s (y/n)? " : "%s (n/y)? ", string); |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 333 | for (;;) { |
| 334 | fflush(stdout); |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 335 | if ((c = getchar()) == EOF) { |
| 336 | if (!def) |
| 337 | errors_uncorrected = 1; |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 338 | return def; |
| 339 | } |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 340 | c = toupper(c); |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 341 | if (c == 'Y') { |
| 342 | def = 1; |
| 343 | break; |
| 344 | } else if (c == 'N') { |
| 345 | def = 0; |
| 346 | break; |
| 347 | } else if (c == ' ' || c == '\n') |
| 348 | break; |
| 349 | } |
| 350 | if (def) |
| 351 | printf("y\n"); |
| 352 | else { |
| 353 | printf("n\n"); |
| 354 | errors_uncorrected = 1; |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 355 | } |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 356 | return def; |
| 357 | } |
| 358 | |
| 359 | /* |
| 360 | * Make certain that we aren't checking a filesystem that is on a |
| 361 | * mounted partition. Code adapted from e2fsck, Copyright (C) 1993, |
| 362 | * 1994 Theodore Ts'o. Also licensed under GPL. |
| 363 | */ |
| 364 | static void check_mount(void) |
| 365 | { |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 366 | FILE *f; |
| 367 | struct mntent *mnt; |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 368 | int cont; |
| 369 | int fd; |
| 370 | |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 371 | if ((f = setmntent(MOUNTED, "r")) == NULL) |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 372 | return; |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 373 | while ((mnt = getmntent(f)) != NULL) |
| 374 | if (strcmp(device_name, mnt->mnt_fsname) == 0) |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 375 | break; |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 376 | endmntent(f); |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 377 | if (!mnt) |
| 378 | return; |
| 379 | |
| 380 | /* |
| 381 | * If the root is mounted read-only, then /etc/mtab is |
| 382 | * probably not correct; so we won't issue a warning based on |
| 383 | * it. |
| 384 | */ |
| 385 | fd = open(MOUNTED, O_RDWR); |
| 386 | if (fd < 0 && errno == EROFS) |
| 387 | return; |
| 388 | else |
| 389 | close(fd); |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 390 | |
| 391 | printf("%s is mounted. ", device_name); |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 392 | if (isatty(0) && isatty(1)) |
Eric Andersen | e674eb7 | 1999-10-19 20:52:57 +0000 | [diff] [blame] | 393 | cont = ask("Do you really want to continue", 0); |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 394 | else |
| 395 | cont = 0; |
| 396 | if (!cont) { |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 397 | printf("check aborted.\n"); |
| 398 | exit(0); |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 399 | } |
| 400 | return; |
| 401 | } |
| 402 | |
| 403 | /* |
| 404 | * check_zone_nr checks to see that *nr is a valid zone nr. If it |
| 405 | * isn't, it will possibly be repaired. Check_zone_nr sets *corrected |
| 406 | * if an error was corrected, and returns the zone (0 for no zone |
| 407 | * or a bad zone-number). |
| 408 | */ |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 409 | static int check_zone_nr(unsigned short *nr, int *corrected) |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 410 | { |
| 411 | if (!*nr) |
| 412 | return 0; |
| 413 | if (*nr < FIRSTZONE) |
Eric Andersen | e674eb7 | 1999-10-19 20:52:57 +0000 | [diff] [blame] | 414 | printf("Zone nr < FIRSTZONE in file `"); |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 415 | else if (*nr >= ZONES) |
Eric Andersen | e674eb7 | 1999-10-19 20:52:57 +0000 | [diff] [blame] | 416 | printf("Zone nr >= ZONES in file `"); |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 417 | else |
| 418 | return *nr; |
| 419 | print_current_name(); |
| 420 | printf("'."); |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 421 | if (ask("Remove block", 1)) { |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 422 | *nr = 0; |
| 423 | *corrected = 1; |
| 424 | } |
| 425 | return 0; |
| 426 | } |
| 427 | |
Pavel Roskin | bc0aed7 | 2000-07-17 17:52:00 +0000 | [diff] [blame] | 428 | #ifdef BB_FEATURE_MINIX2 |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 429 | static int check_zone_nr2(unsigned int *nr, int *corrected) |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 430 | { |
| 431 | if (!*nr) |
| 432 | return 0; |
| 433 | if (*nr < FIRSTZONE) |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 434 | printf("Zone nr < FIRSTZONE in file `"); |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 435 | else if (*nr >= ZONES) |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 436 | printf("Zone nr >= ZONES in file `"); |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 437 | else |
| 438 | return *nr; |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 439 | print_current_name(); |
| 440 | printf("'."); |
| 441 | if (ask("Remove block", 1)) { |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 442 | *nr = 0; |
| 443 | *corrected = 1; |
| 444 | } |
| 445 | return 0; |
| 446 | } |
| 447 | #endif |
| 448 | |
| 449 | /* |
| 450 | * read-block reads block nr into the buffer at addr. |
| 451 | */ |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 452 | static void read_block(unsigned int nr, char *addr) |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 453 | { |
| 454 | if (!nr) { |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 455 | memset(addr, 0, BLOCK_SIZE); |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 456 | return; |
| 457 | } |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 458 | if (BLOCK_SIZE * nr != lseek(IN, BLOCK_SIZE * nr, SEEK_SET)) { |
Eric Andersen | e674eb7 | 1999-10-19 20:52:57 +0000 | [diff] [blame] | 459 | printf("Read error: unable to seek to block in file '"); |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 460 | print_current_name(); |
| 461 | printf("'\n"); |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 462 | memset(addr, 0, BLOCK_SIZE); |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 463 | errors_uncorrected = 1; |
| 464 | } else if (BLOCK_SIZE != read(IN, addr, BLOCK_SIZE)) { |
Eric Andersen | e674eb7 | 1999-10-19 20:52:57 +0000 | [diff] [blame] | 465 | printf("Read error: bad block in file '"); |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 466 | print_current_name(); |
| 467 | printf("'\n"); |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 468 | memset(addr, 0, BLOCK_SIZE); |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 469 | errors_uncorrected = 1; |
| 470 | } |
| 471 | } |
| 472 | |
| 473 | /* |
| 474 | * write_block writes block nr to disk. |
| 475 | */ |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 476 | static void write_block(unsigned int nr, char *addr) |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 477 | { |
| 478 | if (!nr) |
| 479 | return; |
| 480 | if (nr < FIRSTZONE || nr >= ZONES) { |
Eric Andersen | e674eb7 | 1999-10-19 20:52:57 +0000 | [diff] [blame] | 481 | printf("Internal error: trying to write bad block\n" |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 482 | "Write request ignored\n"); |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 483 | errors_uncorrected = 1; |
| 484 | return; |
| 485 | } |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 486 | if (BLOCK_SIZE * nr != lseek(IN, BLOCK_SIZE * nr, SEEK_SET)) |
Eric Andersen | e674eb7 | 1999-10-19 20:52:57 +0000 | [diff] [blame] | 487 | die("seek failed in write_block"); |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 488 | if (BLOCK_SIZE != write(IN, addr, BLOCK_SIZE)) { |
Eric Andersen | e674eb7 | 1999-10-19 20:52:57 +0000 | [diff] [blame] | 489 | printf("Write error: bad block in file '"); |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 490 | print_current_name(); |
| 491 | printf("'\n"); |
| 492 | errors_uncorrected = 1; |
| 493 | } |
| 494 | } |
| 495 | |
| 496 | /* |
| 497 | * map-block calculates the absolute block nr of a block in a file. |
| 498 | * It sets 'changed' if the inode has needed changing, and re-writes |
| 499 | * any indirect blocks with errors. |
| 500 | */ |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 501 | static int map_block(struct minix_inode *inode, unsigned int blknr) |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 502 | { |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 503 | unsigned short ind[BLOCK_SIZE >> 1]; |
| 504 | unsigned short dind[BLOCK_SIZE >> 1]; |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 505 | int blk_chg, block, result; |
| 506 | |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 507 | if (blknr < 7) |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 508 | return check_zone_nr(inode->i_zone + blknr, &changed); |
| 509 | blknr -= 7; |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 510 | if (blknr < 512) { |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 511 | block = check_zone_nr(inode->i_zone + 7, &changed); |
| 512 | read_block(block, (char *) ind); |
| 513 | blk_chg = 0; |
| 514 | result = check_zone_nr(blknr + ind, &blk_chg); |
| 515 | if (blk_chg) |
| 516 | write_block(block, (char *) ind); |
| 517 | return result; |
| 518 | } |
| 519 | blknr -= 512; |
| 520 | block = check_zone_nr(inode->i_zone + 8, &changed); |
| 521 | read_block(block, (char *) dind); |
| 522 | blk_chg = 0; |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 523 | result = check_zone_nr(dind + (blknr / 512), &blk_chg); |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 524 | if (blk_chg) |
| 525 | write_block(block, (char *) dind); |
| 526 | block = result; |
| 527 | read_block(block, (char *) ind); |
| 528 | blk_chg = 0; |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 529 | result = check_zone_nr(ind + (blknr % 512), &blk_chg); |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 530 | if (blk_chg) |
| 531 | write_block(block, (char *) ind); |
| 532 | return result; |
| 533 | } |
| 534 | |
Pavel Roskin | bc0aed7 | 2000-07-17 17:52:00 +0000 | [diff] [blame] | 535 | #ifdef BB_FEATURE_MINIX2 |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 536 | static int map_block2(struct minix2_inode *inode, unsigned int blknr) |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 537 | { |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 538 | unsigned int ind[BLOCK_SIZE >> 2]; |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 539 | unsigned int dind[BLOCK_SIZE >> 2]; |
| 540 | unsigned int tind[BLOCK_SIZE >> 2]; |
| 541 | int blk_chg, block, result; |
| 542 | |
| 543 | if (blknr < 7) |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 544 | return check_zone_nr2(inode->i_zone + blknr, &changed); |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 545 | blknr -= 7; |
| 546 | if (blknr < 256) { |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 547 | block = check_zone_nr2(inode->i_zone + 7, &changed); |
| 548 | read_block(block, (char *) ind); |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 549 | blk_chg = 0; |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 550 | result = check_zone_nr2(blknr + ind, &blk_chg); |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 551 | if (blk_chg) |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 552 | write_block(block, (char *) ind); |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 553 | return result; |
| 554 | } |
| 555 | blknr -= 256; |
| 556 | if (blknr >= 256 * 256) { |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 557 | block = check_zone_nr2(inode->i_zone + 8, &changed); |
| 558 | read_block(block, (char *) dind); |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 559 | blk_chg = 0; |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 560 | result = check_zone_nr2(dind + blknr / 256, &blk_chg); |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 561 | if (blk_chg) |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 562 | write_block(block, (char *) dind); |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 563 | block = result; |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 564 | read_block(block, (char *) ind); |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 565 | blk_chg = 0; |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 566 | result = check_zone_nr2(ind + blknr % 256, &blk_chg); |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 567 | if (blk_chg) |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 568 | write_block(block, (char *) ind); |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 569 | return result; |
| 570 | } |
| 571 | blknr -= 256 * 256; |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 572 | block = check_zone_nr2(inode->i_zone + 9, &changed); |
| 573 | read_block(block, (char *) tind); |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 574 | blk_chg = 0; |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 575 | result = check_zone_nr2(tind + blknr / (256 * 256), &blk_chg); |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 576 | if (blk_chg) |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 577 | write_block(block, (char *) tind); |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 578 | block = result; |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 579 | read_block(block, (char *) dind); |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 580 | blk_chg = 0; |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 581 | result = check_zone_nr2(dind + (blknr / 256) % 256, &blk_chg); |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 582 | if (blk_chg) |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 583 | write_block(block, (char *) dind); |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 584 | block = result; |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 585 | read_block(block, (char *) ind); |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 586 | blk_chg = 0; |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 587 | result = check_zone_nr2(ind + blknr % 256, &blk_chg); |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 588 | if (blk_chg) |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 589 | write_block(block, (char *) ind); |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 590 | return result; |
| 591 | } |
| 592 | #endif |
| 593 | |
Eric Andersen | e674eb7 | 1999-10-19 20:52:57 +0000 | [diff] [blame] | 594 | static void write_super_block(void) |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 595 | { |
| 596 | /* |
| 597 | * Set the state of the filesystem based on whether or not there |
| 598 | * are uncorrected errors. The filesystem valid flag is |
| 599 | * unconditionally set if we get this far. |
| 600 | */ |
| 601 | Super.s_state |= MINIX_VALID_FS; |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 602 | if (errors_uncorrected) |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 603 | Super.s_state |= MINIX_ERROR_FS; |
| 604 | else |
| 605 | Super.s_state &= ~MINIX_ERROR_FS; |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 606 | |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 607 | if (BLOCK_SIZE != lseek(IN, BLOCK_SIZE, SEEK_SET)) |
Eric Andersen | e674eb7 | 1999-10-19 20:52:57 +0000 | [diff] [blame] | 608 | die("seek failed in write_super_block"); |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 609 | if (BLOCK_SIZE != write(IN, super_block_buffer, BLOCK_SIZE)) |
Eric Andersen | e674eb7 | 1999-10-19 20:52:57 +0000 | [diff] [blame] | 610 | die("unable to write super-block"); |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 611 | |
| 612 | return; |
| 613 | } |
| 614 | |
Eric Andersen | e674eb7 | 1999-10-19 20:52:57 +0000 | [diff] [blame] | 615 | static void write_tables(void) |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 616 | { |
| 617 | write_super_block(); |
| 618 | |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 619 | if (IMAPS * BLOCK_SIZE != write(IN, inode_map, IMAPS * BLOCK_SIZE)) |
Eric Andersen | e674eb7 | 1999-10-19 20:52:57 +0000 | [diff] [blame] | 620 | die("Unable to write inode map"); |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 621 | if (ZMAPS * BLOCK_SIZE != write(IN, zone_map, ZMAPS * BLOCK_SIZE)) |
Eric Andersen | e674eb7 | 1999-10-19 20:52:57 +0000 | [diff] [blame] | 622 | die("Unable to write zone map"); |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 623 | if (INODE_BUFFER_SIZE != write(IN, inode_buffer, INODE_BUFFER_SIZE)) |
Eric Andersen | e674eb7 | 1999-10-19 20:52:57 +0000 | [diff] [blame] | 624 | die("Unable to write inodes"); |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 625 | } |
| 626 | |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 627 | static void get_dirsize(void) |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 628 | { |
| 629 | int block; |
| 630 | char blk[BLOCK_SIZE]; |
| 631 | int size; |
| 632 | |
Pavel Roskin | bc0aed7 | 2000-07-17 17:52:00 +0000 | [diff] [blame] | 633 | #ifdef BB_FEATURE_MINIX2 |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 634 | if (version2) |
| 635 | block = Inode2[ROOT_INO].i_zone[0]; |
| 636 | else |
| 637 | #endif |
| 638 | block = Inode[ROOT_INO].i_zone[0]; |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 639 | read_block(block, blk); |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 640 | for (size = 16; size < BLOCK_SIZE; size <<= 1) { |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 641 | if (strcmp(blk + size + 2, "..") == 0) { |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 642 | dirsize = size; |
| 643 | namelen = size - 2; |
| 644 | return; |
| 645 | } |
| 646 | } |
| 647 | /* use defaults */ |
| 648 | } |
| 649 | |
Eric Andersen | e674eb7 | 1999-10-19 20:52:57 +0000 | [diff] [blame] | 650 | static void read_superblock(void) |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 651 | { |
| 652 | if (BLOCK_SIZE != lseek(IN, BLOCK_SIZE, SEEK_SET)) |
Eric Andersen | e674eb7 | 1999-10-19 20:52:57 +0000 | [diff] [blame] | 653 | die("seek failed"); |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 654 | if (BLOCK_SIZE != read(IN, super_block_buffer, BLOCK_SIZE)) |
Eric Andersen | e674eb7 | 1999-10-19 20:52:57 +0000 | [diff] [blame] | 655 | die("unable to read super block"); |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 656 | if (MAGIC == MINIX_SUPER_MAGIC) { |
| 657 | namelen = 14; |
| 658 | dirsize = 16; |
| 659 | version2 = 0; |
| 660 | } else if (MAGIC == MINIX_SUPER_MAGIC2) { |
| 661 | namelen = 30; |
| 662 | dirsize = 32; |
| 663 | version2 = 0; |
Pavel Roskin | bc0aed7 | 2000-07-17 17:52:00 +0000 | [diff] [blame] | 664 | #ifdef BB_FEATURE_MINIX2 |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 665 | } else if (MAGIC == MINIX2_SUPER_MAGIC) { |
| 666 | namelen = 14; |
| 667 | dirsize = 16; |
| 668 | version2 = 1; |
| 669 | } else if (MAGIC == MINIX2_SUPER_MAGIC2) { |
| 670 | namelen = 30; |
| 671 | dirsize = 32; |
| 672 | version2 = 1; |
| 673 | #endif |
| 674 | } else |
Eric Andersen | e674eb7 | 1999-10-19 20:52:57 +0000 | [diff] [blame] | 675 | die("bad magic number in super-block"); |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 676 | if (ZONESIZE != 0 || BLOCK_SIZE != 1024) |
Eric Andersen | e674eb7 | 1999-10-19 20:52:57 +0000 | [diff] [blame] | 677 | die("Only 1k blocks/zones supported"); |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 678 | if (IMAPS * BLOCK_SIZE * 8 < INODES + 1) |
Eric Andersen | e674eb7 | 1999-10-19 20:52:57 +0000 | [diff] [blame] | 679 | die("bad s_imap_blocks field in super-block"); |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 680 | if (ZMAPS * BLOCK_SIZE * 8 < ZONES - FIRSTZONE + 1) |
Eric Andersen | e674eb7 | 1999-10-19 20:52:57 +0000 | [diff] [blame] | 681 | die("bad s_zmap_blocks field in super-block"); |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 682 | } |
| 683 | |
Eric Andersen | e674eb7 | 1999-10-19 20:52:57 +0000 | [diff] [blame] | 684 | static void read_tables(void) |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 685 | { |
Erik Andersen | 0d068a2 | 2000-03-21 22:32:57 +0000 | [diff] [blame] | 686 | inode_map = xmalloc(IMAPS * BLOCK_SIZE); |
| 687 | zone_map = xmalloc(ZMAPS * BLOCK_SIZE); |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 688 | memset(inode_map, 0, sizeof(inode_map)); |
| 689 | memset(zone_map, 0, sizeof(zone_map)); |
Erik Andersen | 0d068a2 | 2000-03-21 22:32:57 +0000 | [diff] [blame] | 690 | inode_buffer = xmalloc(INODE_BUFFER_SIZE); |
| 691 | inode_count = xmalloc(INODES + 1); |
| 692 | zone_count = xmalloc(ZONES); |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 693 | if (IMAPS * BLOCK_SIZE != read(IN, inode_map, IMAPS * BLOCK_SIZE)) |
Eric Andersen | e674eb7 | 1999-10-19 20:52:57 +0000 | [diff] [blame] | 694 | die("Unable to read inode map"); |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 695 | if (ZMAPS * BLOCK_SIZE != read(IN, zone_map, ZMAPS * BLOCK_SIZE)) |
Eric Andersen | e674eb7 | 1999-10-19 20:52:57 +0000 | [diff] [blame] | 696 | die("Unable to read zone map"); |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 697 | if (INODE_BUFFER_SIZE != read(IN, inode_buffer, INODE_BUFFER_SIZE)) |
Eric Andersen | e674eb7 | 1999-10-19 20:52:57 +0000 | [diff] [blame] | 698 | die("Unable to read inodes"); |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 699 | if (NORM_FIRSTZONE != FIRSTZONE) { |
Eric Andersen | e674eb7 | 1999-10-19 20:52:57 +0000 | [diff] [blame] | 700 | printf("Warning: Firstzone != Norm_firstzone\n"); |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 701 | errors_uncorrected = 1; |
| 702 | } |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 703 | get_dirsize(); |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 704 | if (show) { |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 705 | printf("%ld inodes\n", INODES); |
| 706 | printf("%ld blocks\n", ZONES); |
| 707 | printf("Firstdatazone=%ld (%ld)\n", FIRSTZONE, NORM_FIRSTZONE); |
| 708 | printf("Zonesize=%d\n", BLOCK_SIZE << ZONESIZE); |
| 709 | printf("Maxsize=%ld\n", MAXSIZE); |
Eric Andersen | e674eb7 | 1999-10-19 20:52:57 +0000 | [diff] [blame] | 710 | printf("Filesystem state=%d\n", Super.s_state); |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 711 | printf("namelen=%d\n\n", namelen); |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 712 | } |
| 713 | } |
| 714 | |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 715 | struct minix_inode *get_inode(unsigned int nr) |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 716 | { |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 717 | struct minix_inode *inode; |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 718 | |
| 719 | if (!nr || nr > INODES) |
| 720 | return NULL; |
| 721 | total++; |
| 722 | inode = Inode + nr; |
| 723 | if (!inode_count[nr]) { |
| 724 | if (!inode_in_use(nr)) { |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 725 | printf("Inode %d marked not used, but used for file '", nr); |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 726 | print_current_name(); |
| 727 | printf("'\n"); |
| 728 | if (repair) { |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 729 | if (ask("Mark in use", 1)) |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 730 | mark_inode(nr); |
| 731 | } else { |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 732 | errors_uncorrected = 1; |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 733 | } |
| 734 | } |
| 735 | if (S_ISDIR(inode->i_mode)) |
| 736 | directory++; |
| 737 | else if (S_ISREG(inode->i_mode)) |
| 738 | regular++; |
| 739 | else if (S_ISCHR(inode->i_mode)) |
| 740 | chardev++; |
| 741 | else if (S_ISBLK(inode->i_mode)) |
| 742 | blockdev++; |
| 743 | else if (S_ISLNK(inode->i_mode)) |
| 744 | symlinks++; |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 745 | else if (S_ISSOCK(inode->i_mode)); |
| 746 | else if (S_ISFIFO(inode->i_mode)); |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 747 | else { |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 748 | print_current_name(); |
| 749 | printf(" has mode %05o\n", inode->i_mode); |
| 750 | } |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 751 | |
| 752 | } else |
| 753 | links++; |
| 754 | if (!++inode_count[nr]) { |
Eric Andersen | e674eb7 | 1999-10-19 20:52:57 +0000 | [diff] [blame] | 755 | printf("Warning: inode count too big.\n"); |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 756 | inode_count[nr]--; |
| 757 | errors_uncorrected = 1; |
| 758 | } |
| 759 | return inode; |
| 760 | } |
| 761 | |
Pavel Roskin | bc0aed7 | 2000-07-17 17:52:00 +0000 | [diff] [blame] | 762 | #ifdef BB_FEATURE_MINIX2 |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 763 | struct minix2_inode *get_inode2(unsigned int nr) |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 764 | { |
| 765 | struct minix2_inode *inode; |
| 766 | |
| 767 | if (!nr || nr > INODES) |
| 768 | return NULL; |
| 769 | total++; |
| 770 | inode = Inode2 + nr; |
| 771 | if (!inode_count[nr]) { |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 772 | if (!inode_in_use(nr)) { |
| 773 | printf("Inode %d marked not used, but used for file '", nr); |
| 774 | print_current_name(); |
| 775 | printf("'\n"); |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 776 | if (repair) { |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 777 | if (ask("Mark in use", 1)) |
| 778 | mark_inode(nr); |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 779 | else |
| 780 | errors_uncorrected = 1; |
| 781 | } |
| 782 | } |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 783 | if (S_ISDIR(inode->i_mode)) |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 784 | directory++; |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 785 | else if (S_ISREG(inode->i_mode)) |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 786 | regular++; |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 787 | else if (S_ISCHR(inode->i_mode)) |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 788 | chardev++; |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 789 | else if (S_ISBLK(inode->i_mode)) |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 790 | blockdev++; |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 791 | else if (S_ISLNK(inode->i_mode)) |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 792 | symlinks++; |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 793 | else if (S_ISSOCK(inode->i_mode)); |
| 794 | else if (S_ISFIFO(inode->i_mode)); |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 795 | else { |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 796 | print_current_name(); |
| 797 | printf(" has mode %05o\n", inode->i_mode); |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 798 | } |
| 799 | } else |
| 800 | links++; |
| 801 | if (!++inode_count[nr]) { |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 802 | printf("Warning: inode count too big.\n"); |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 803 | inode_count[nr]--; |
| 804 | errors_uncorrected = 1; |
| 805 | } |
| 806 | return inode; |
| 807 | } |
| 808 | #endif |
| 809 | |
Eric Andersen | e674eb7 | 1999-10-19 20:52:57 +0000 | [diff] [blame] | 810 | static void check_root(void) |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 811 | { |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 812 | struct minix_inode *inode = Inode + ROOT_INO; |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 813 | |
| 814 | if (!inode || !S_ISDIR(inode->i_mode)) |
Eric Andersen | e674eb7 | 1999-10-19 20:52:57 +0000 | [diff] [blame] | 815 | die("root inode isn't a directory"); |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 816 | } |
| 817 | |
Pavel Roskin | bc0aed7 | 2000-07-17 17:52:00 +0000 | [diff] [blame] | 818 | #ifdef BB_FEATURE_MINIX2 |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 819 | static void check_root2(void) |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 820 | { |
| 821 | struct minix2_inode *inode = Inode2 + ROOT_INO; |
| 822 | |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 823 | if (!inode || !S_ISDIR(inode->i_mode)) |
| 824 | die("root inode isn't a directory"); |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 825 | } |
| 826 | #endif |
| 827 | |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 828 | static int add_zone(unsigned short *znr, int *corrected) |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 829 | { |
| 830 | int result; |
| 831 | int block; |
| 832 | |
| 833 | result = 0; |
| 834 | block = check_zone_nr(znr, corrected); |
| 835 | if (!block) |
| 836 | return 0; |
| 837 | if (zone_count[block]) { |
Eric Andersen | e674eb7 | 1999-10-19 20:52:57 +0000 | [diff] [blame] | 838 | printf("Block has been used before. Now in file `"); |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 839 | print_current_name(); |
| 840 | printf("'."); |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 841 | if (ask("Clear", 1)) { |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 842 | *znr = 0; |
| 843 | block = 0; |
| 844 | *corrected = 1; |
| 845 | } |
| 846 | } |
| 847 | if (!block) |
| 848 | return 0; |
| 849 | if (!zone_in_use(block)) { |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 850 | printf("Block %d in file `", block); |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 851 | print_current_name(); |
Eric Andersen | e674eb7 | 1999-10-19 20:52:57 +0000 | [diff] [blame] | 852 | printf("' is marked not in use."); |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 853 | if (ask("Correct", 1)) |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 854 | mark_zone(block); |
| 855 | } |
| 856 | if (!++zone_count[block]) |
| 857 | zone_count[block]--; |
| 858 | return block; |
| 859 | } |
| 860 | |
Pavel Roskin | bc0aed7 | 2000-07-17 17:52:00 +0000 | [diff] [blame] | 861 | #ifdef BB_FEATURE_MINIX2 |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 862 | static int add_zone2(unsigned int *znr, int *corrected) |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 863 | { |
| 864 | int result; |
| 865 | int block; |
| 866 | |
| 867 | result = 0; |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 868 | block = check_zone_nr2(znr, corrected); |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 869 | if (!block) |
| 870 | return 0; |
| 871 | if (zone_count[block]) { |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 872 | printf("Block has been used before. Now in file `"); |
| 873 | print_current_name(); |
| 874 | printf("'."); |
| 875 | if (ask("Clear", 1)) { |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 876 | *znr = 0; |
| 877 | block = 0; |
| 878 | *corrected = 1; |
| 879 | } |
| 880 | } |
| 881 | if (!block) |
| 882 | return 0; |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 883 | if (!zone_in_use(block)) { |
| 884 | printf("Block %d in file `", block); |
| 885 | print_current_name(); |
| 886 | printf("' is marked not in use."); |
| 887 | if (ask("Correct", 1)) |
| 888 | mark_zone(block); |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 889 | } |
| 890 | if (!++zone_count[block]) |
| 891 | zone_count[block]--; |
| 892 | return block; |
| 893 | } |
| 894 | #endif |
| 895 | |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 896 | static void add_zone_ind(unsigned short *znr, int *corrected) |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 897 | { |
| 898 | static char blk[BLOCK_SIZE]; |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 899 | int i, chg_blk = 0; |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 900 | int block; |
| 901 | |
| 902 | block = add_zone(znr, corrected); |
| 903 | if (!block) |
| 904 | return; |
| 905 | read_block(block, blk); |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 906 | for (i = 0; i < (BLOCK_SIZE >> 1); i++) |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 907 | add_zone(i + (unsigned short *) blk, &chg_blk); |
| 908 | if (chg_blk) |
| 909 | write_block(block, blk); |
| 910 | } |
| 911 | |
Pavel Roskin | bc0aed7 | 2000-07-17 17:52:00 +0000 | [diff] [blame] | 912 | #ifdef BB_FEATURE_MINIX2 |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 913 | static void add_zone_ind2(unsigned int *znr, int *corrected) |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 914 | { |
| 915 | static char blk[BLOCK_SIZE]; |
| 916 | int i, chg_blk = 0; |
| 917 | int block; |
| 918 | |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 919 | block = add_zone2(znr, corrected); |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 920 | if (!block) |
| 921 | return; |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 922 | read_block(block, blk); |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 923 | for (i = 0; i < BLOCK_SIZE >> 2; i++) |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 924 | add_zone2(i + (unsigned int *) blk, &chg_blk); |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 925 | if (chg_blk) |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 926 | write_block(block, blk); |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 927 | } |
| 928 | #endif |
| 929 | |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 930 | static void add_zone_dind(unsigned short *znr, int *corrected) |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 931 | { |
| 932 | static char blk[BLOCK_SIZE]; |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 933 | int i, blk_chg = 0; |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 934 | int block; |
| 935 | |
| 936 | block = add_zone(znr, corrected); |
| 937 | if (!block) |
| 938 | return; |
| 939 | read_block(block, blk); |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 940 | for (i = 0; i < (BLOCK_SIZE >> 1); i++) |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 941 | add_zone_ind(i + (unsigned short *) blk, &blk_chg); |
| 942 | if (blk_chg) |
| 943 | write_block(block, blk); |
| 944 | } |
| 945 | |
Pavel Roskin | bc0aed7 | 2000-07-17 17:52:00 +0000 | [diff] [blame] | 946 | #ifdef BB_FEATURE_MINIX2 |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 947 | static void add_zone_dind2(unsigned int *znr, int *corrected) |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 948 | { |
| 949 | static char blk[BLOCK_SIZE]; |
| 950 | int i, blk_chg = 0; |
| 951 | int block; |
| 952 | |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 953 | block = add_zone2(znr, corrected); |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 954 | if (!block) |
| 955 | return; |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 956 | read_block(block, blk); |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 957 | for (i = 0; i < BLOCK_SIZE >> 2; i++) |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 958 | add_zone_ind2(i + (unsigned int *) blk, &blk_chg); |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 959 | if (blk_chg) |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 960 | write_block(block, blk); |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 961 | } |
| 962 | |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 963 | static void add_zone_tind2(unsigned int *znr, int *corrected) |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 964 | { |
| 965 | static char blk[BLOCK_SIZE]; |
| 966 | int i, blk_chg = 0; |
| 967 | int block; |
| 968 | |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 969 | block = add_zone2(znr, corrected); |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 970 | if (!block) |
| 971 | return; |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 972 | read_block(block, blk); |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 973 | for (i = 0; i < BLOCK_SIZE >> 2; i++) |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 974 | add_zone_dind2(i + (unsigned int *) blk, &blk_chg); |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 975 | if (blk_chg) |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 976 | write_block(block, blk); |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 977 | } |
| 978 | #endif |
| 979 | |
Eric Andersen | e674eb7 | 1999-10-19 20:52:57 +0000 | [diff] [blame] | 980 | static void check_zones(unsigned int i) |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 981 | { |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 982 | struct minix_inode *inode; |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 983 | |
| 984 | if (!i || i > INODES) |
| 985 | return; |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 986 | if (inode_count[i] > 1) /* have we counted this file already? */ |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 987 | return; |
| 988 | inode = Inode + i; |
| 989 | if (!S_ISDIR(inode->i_mode) && !S_ISREG(inode->i_mode) && |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 990 | !S_ISLNK(inode->i_mode)) return; |
| 991 | for (i = 0; i < 7; i++) |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 992 | add_zone(i + inode->i_zone, &changed); |
| 993 | add_zone_ind(7 + inode->i_zone, &changed); |
| 994 | add_zone_dind(8 + inode->i_zone, &changed); |
| 995 | } |
| 996 | |
Pavel Roskin | bc0aed7 | 2000-07-17 17:52:00 +0000 | [diff] [blame] | 997 | #ifdef BB_FEATURE_MINIX2 |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 998 | static void check_zones2(unsigned int i) |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 999 | { |
| 1000 | struct minix2_inode *inode; |
| 1001 | |
| 1002 | if (!i || i > INODES) |
| 1003 | return; |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 1004 | if (inode_count[i] > 1) /* have we counted this file already? */ |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 1005 | return; |
| 1006 | inode = Inode2 + i; |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 1007 | if (!S_ISDIR(inode->i_mode) && !S_ISREG(inode->i_mode) |
| 1008 | && !S_ISLNK(inode->i_mode)) |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 1009 | return; |
| 1010 | for (i = 0; i < 7; i++) |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 1011 | add_zone2(i + inode->i_zone, &changed); |
| 1012 | add_zone_ind2(7 + inode->i_zone, &changed); |
| 1013 | add_zone_dind2(8 + inode->i_zone, &changed); |
| 1014 | add_zone_tind2(9 + inode->i_zone, &changed); |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 1015 | } |
| 1016 | #endif |
| 1017 | |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 1018 | static void check_file(struct minix_inode *dir, unsigned int offset) |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 1019 | { |
| 1020 | static char blk[BLOCK_SIZE]; |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 1021 | struct minix_inode *inode; |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 1022 | int ino; |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 1023 | char *name; |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 1024 | int block; |
| 1025 | |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 1026 | block = map_block(dir, offset / BLOCK_SIZE); |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 1027 | read_block(block, blk); |
| 1028 | name = blk + (offset % BLOCK_SIZE) + 2; |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 1029 | ino = *(unsigned short *) (name - 2); |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 1030 | if (ino > INODES) { |
| 1031 | print_current_name(); |
Eric Andersen | e674eb7 | 1999-10-19 20:52:57 +0000 | [diff] [blame] | 1032 | printf(" contains a bad inode number for file '"); |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 1033 | printf("%.*s'.", namelen, name); |
| 1034 | if (ask(" Remove", 1)) { |
| 1035 | *(unsigned short *) (name - 2) = 0; |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 1036 | write_block(block, blk); |
| 1037 | } |
| 1038 | ino = 0; |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 1039 | } |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 1040 | if (name_depth < MAX_DEPTH) |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 1041 | strncpy(name_list[name_depth], name, namelen); |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 1042 | name_depth++; |
| 1043 | inode = get_inode(ino); |
| 1044 | name_depth--; |
| 1045 | if (!offset) { |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 1046 | if (!inode || strcmp(".", name)) { |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 1047 | print_current_name(); |
Eric Andersen | e674eb7 | 1999-10-19 20:52:57 +0000 | [diff] [blame] | 1048 | printf(": bad directory: '.' isn't first\n"); |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 1049 | errors_uncorrected = 1; |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 1050 | } else |
| 1051 | return; |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 1052 | } |
| 1053 | if (offset == dirsize) { |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 1054 | if (!inode || strcmp("..", name)) { |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 1055 | print_current_name(); |
Eric Andersen | e674eb7 | 1999-10-19 20:52:57 +0000 | [diff] [blame] | 1056 | printf(": bad directory: '..' isn't second\n"); |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 1057 | errors_uncorrected = 1; |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 1058 | } else |
| 1059 | return; |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 1060 | } |
| 1061 | if (!inode) |
| 1062 | return; |
| 1063 | if (name_depth < MAX_DEPTH) |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 1064 | strncpy(name_list[name_depth], name, namelen); |
| 1065 | name_depth++; |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 1066 | if (list) { |
| 1067 | if (verbose) |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 1068 | printf("%6d %07o %3d ", ino, inode->i_mode, inode->i_nlinks); |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 1069 | print_current_name(); |
| 1070 | if (S_ISDIR(inode->i_mode)) |
| 1071 | printf(":\n"); |
| 1072 | else |
| 1073 | printf("\n"); |
| 1074 | } |
| 1075 | check_zones(ino); |
| 1076 | if (inode && S_ISDIR(inode->i_mode)) |
| 1077 | recursive_check(ino); |
| 1078 | name_depth--; |
| 1079 | return; |
| 1080 | } |
| 1081 | |
Pavel Roskin | bc0aed7 | 2000-07-17 17:52:00 +0000 | [diff] [blame] | 1082 | #ifdef BB_FEATURE_MINIX2 |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 1083 | static void check_file2(struct minix2_inode *dir, unsigned int offset) |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 1084 | { |
| 1085 | static char blk[BLOCK_SIZE]; |
| 1086 | struct minix2_inode *inode; |
| 1087 | int ino; |
| 1088 | char *name; |
| 1089 | int block; |
| 1090 | |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 1091 | block = map_block2(dir, offset / BLOCK_SIZE); |
| 1092 | read_block(block, blk); |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 1093 | name = blk + (offset % BLOCK_SIZE) + 2; |
| 1094 | ino = *(unsigned short *) (name - 2); |
| 1095 | if (ino > INODES) { |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 1096 | print_current_name(); |
| 1097 | printf(" contains a bad inode number for file '"); |
| 1098 | printf("%.*s'.", namelen, name); |
| 1099 | if (ask(" Remove", 1)) { |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 1100 | *(unsigned short *) (name - 2) = 0; |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 1101 | write_block(block, blk); |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 1102 | } |
| 1103 | ino = 0; |
| 1104 | } |
| 1105 | if (name_depth < MAX_DEPTH) |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 1106 | strncpy(name_list[name_depth], name, namelen); |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 1107 | name_depth++; |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 1108 | inode = get_inode2(ino); |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 1109 | name_depth--; |
| 1110 | if (!offset) { |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 1111 | if (!inode || strcmp(".", name)) { |
| 1112 | print_current_name(); |
| 1113 | printf(": bad directory: '.' isn't first\n"); |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 1114 | errors_uncorrected = 1; |
| 1115 | } else |
| 1116 | return; |
| 1117 | } |
| 1118 | if (offset == dirsize) { |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 1119 | if (!inode || strcmp("..", name)) { |
| 1120 | print_current_name(); |
| 1121 | printf(": bad directory: '..' isn't second\n"); |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 1122 | errors_uncorrected = 1; |
| 1123 | } else |
| 1124 | return; |
| 1125 | } |
| 1126 | if (!inode) |
| 1127 | return; |
| 1128 | name_depth++; |
| 1129 | if (list) { |
| 1130 | if (verbose) |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 1131 | printf("%6d %07o %3d ", ino, inode->i_mode, inode->i_nlinks); |
| 1132 | print_current_name(); |
| 1133 | if (S_ISDIR(inode->i_mode)) |
| 1134 | printf(":\n"); |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 1135 | else |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 1136 | printf("\n"); |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 1137 | } |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 1138 | check_zones2(ino); |
| 1139 | if (inode && S_ISDIR(inode->i_mode)) |
| 1140 | recursive_check2(ino); |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 1141 | name_depth--; |
| 1142 | return; |
| 1143 | } |
| 1144 | #endif |
| 1145 | |
Eric Andersen | e674eb7 | 1999-10-19 20:52:57 +0000 | [diff] [blame] | 1146 | static void recursive_check(unsigned int ino) |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 1147 | { |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 1148 | struct minix_inode *dir; |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 1149 | unsigned int offset; |
| 1150 | |
| 1151 | dir = Inode + ino; |
| 1152 | if (!S_ISDIR(dir->i_mode)) |
Eric Andersen | e674eb7 | 1999-10-19 20:52:57 +0000 | [diff] [blame] | 1153 | die("internal error"); |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 1154 | if (dir->i_size < 2 * dirsize) { |
| 1155 | print_current_name(); |
Eric Andersen | e674eb7 | 1999-10-19 20:52:57 +0000 | [diff] [blame] | 1156 | printf(": bad directory: size<32"); |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 1157 | errors_uncorrected = 1; |
| 1158 | } |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 1159 | for (offset = 0; offset < dir->i_size; offset += dirsize) |
| 1160 | check_file(dir, offset); |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 1161 | } |
| 1162 | |
Pavel Roskin | bc0aed7 | 2000-07-17 17:52:00 +0000 | [diff] [blame] | 1163 | #ifdef BB_FEATURE_MINIX2 |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 1164 | static void recursive_check2(unsigned int ino) |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 1165 | { |
| 1166 | struct minix2_inode *dir; |
| 1167 | unsigned int offset; |
| 1168 | |
| 1169 | dir = Inode2 + ino; |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 1170 | if (!S_ISDIR(dir->i_mode)) |
| 1171 | die("internal error"); |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 1172 | if (dir->i_size < 2 * dirsize) { |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 1173 | print_current_name(); |
| 1174 | printf(": bad directory: size < 32"); |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 1175 | errors_uncorrected = 1; |
| 1176 | } |
| 1177 | for (offset = 0; offset < dir->i_size; offset += dirsize) |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 1178 | check_file2(dir, offset); |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 1179 | } |
| 1180 | #endif |
| 1181 | |
Eric Andersen | e674eb7 | 1999-10-19 20:52:57 +0000 | [diff] [blame] | 1182 | static int bad_zone(int i) |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 1183 | { |
| 1184 | char buffer[1024]; |
| 1185 | |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 1186 | if (BLOCK_SIZE * i != lseek(IN, BLOCK_SIZE * i, SEEK_SET)) |
Eric Andersen | e674eb7 | 1999-10-19 20:52:57 +0000 | [diff] [blame] | 1187 | die("seek failed in bad_zone"); |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 1188 | return (BLOCK_SIZE != read(IN, buffer, BLOCK_SIZE)); |
| 1189 | } |
| 1190 | |
Eric Andersen | e674eb7 | 1999-10-19 20:52:57 +0000 | [diff] [blame] | 1191 | static void check_counts(void) |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 1192 | { |
| 1193 | int i; |
| 1194 | |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 1195 | for (i = 1; i <= INODES; i++) { |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 1196 | if (!inode_in_use(i) && Inode[i].i_mode && warn_mode) { |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 1197 | printf("Inode %d mode not cleared.", i); |
| 1198 | if (ask("Clear", 1)) { |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 1199 | Inode[i].i_mode = 0; |
| 1200 | changed = 1; |
| 1201 | } |
| 1202 | } |
| 1203 | if (!inode_count[i]) { |
| 1204 | if (!inode_in_use(i)) |
| 1205 | continue; |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 1206 | printf("Inode %d not used, marked used in the bitmap.", i); |
| 1207 | if (ask("Clear", 1)) |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 1208 | unmark_inode(i); |
| 1209 | continue; |
| 1210 | } |
| 1211 | if (!inode_in_use(i)) { |
Eric Andersen | e674eb7 | 1999-10-19 20:52:57 +0000 | [diff] [blame] | 1212 | printf("Inode %d used, marked unused in the bitmap.", i); |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 1213 | if (ask("Set", 1)) |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 1214 | mark_inode(i); |
| 1215 | } |
| 1216 | if (Inode[i].i_nlinks != inode_count[i]) { |
Eric Andersen | e674eb7 | 1999-10-19 20:52:57 +0000 | [diff] [blame] | 1217 | printf("Inode %d (mode = %07o), i_nlinks=%d, counted=%d.", |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 1218 | i, Inode[i].i_mode, Inode[i].i_nlinks, inode_count[i]); |
| 1219 | if (ask("Set i_nlinks to count", 1)) { |
| 1220 | Inode[i].i_nlinks = inode_count[i]; |
| 1221 | changed = 1; |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 1222 | } |
| 1223 | } |
| 1224 | } |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 1225 | for (i = FIRSTZONE; i < ZONES; i++) { |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 1226 | if (zone_in_use(i) == zone_count[i]) |
| 1227 | continue; |
| 1228 | if (!zone_count[i]) { |
| 1229 | if (bad_zone(i)) |
| 1230 | continue; |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 1231 | printf("Zone %d: marked in use, no file uses it.", i); |
| 1232 | if (ask("Unmark", 1)) |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 1233 | unmark_zone(i); |
| 1234 | continue; |
| 1235 | } |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 1236 | printf("Zone %d: %sin use, counted=%d\n", |
| 1237 | i, zone_in_use(i) ? "" : "not ", zone_count[i]); |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 1238 | } |
| 1239 | } |
| 1240 | |
Pavel Roskin | bc0aed7 | 2000-07-17 17:52:00 +0000 | [diff] [blame] | 1241 | #ifdef BB_FEATURE_MINIX2 |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 1242 | static void check_counts2(void) |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 1243 | { |
| 1244 | int i; |
| 1245 | |
| 1246 | for (i = 1; i <= INODES; i++) { |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 1247 | if (!inode_in_use(i) && Inode2[i].i_mode && warn_mode) { |
| 1248 | printf("Inode %d mode not cleared.", i); |
| 1249 | if (ask("Clear", 1)) { |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 1250 | Inode2[i].i_mode = 0; |
| 1251 | changed = 1; |
| 1252 | } |
| 1253 | } |
| 1254 | if (!inode_count[i]) { |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 1255 | if (!inode_in_use(i)) |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 1256 | continue; |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 1257 | printf("Inode %d not used, marked used in the bitmap.", i); |
| 1258 | if (ask("Clear", 1)) |
| 1259 | unmark_inode(i); |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 1260 | continue; |
| 1261 | } |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 1262 | if (!inode_in_use(i)) { |
| 1263 | printf("Inode %d used, marked unused in the bitmap.", i); |
| 1264 | if (ask("Set", 1)) |
| 1265 | mark_inode(i); |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 1266 | } |
| 1267 | if (Inode2[i].i_nlinks != inode_count[i]) { |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 1268 | printf("Inode %d (mode = %07o), i_nlinks=%d, counted=%d.", |
| 1269 | i, Inode2[i].i_mode, Inode2[i].i_nlinks, |
| 1270 | inode_count[i]); |
| 1271 | if (ask("Set i_nlinks to count", 1)) { |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 1272 | Inode2[i].i_nlinks = inode_count[i]; |
| 1273 | changed = 1; |
| 1274 | } |
| 1275 | } |
| 1276 | } |
| 1277 | for (i = FIRSTZONE; i < ZONES; i++) { |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 1278 | if (zone_in_use(i) == zone_count[i]) |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 1279 | continue; |
| 1280 | if (!zone_count[i]) { |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 1281 | if (bad_zone(i)) |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 1282 | continue; |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 1283 | printf("Zone %d: marked in use, no file uses it.", i); |
| 1284 | if (ask("Unmark", 1)) |
| 1285 | unmark_zone(i); |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 1286 | continue; |
| 1287 | } |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 1288 | printf("Zone %d: %sin use, counted=%d\n", |
| 1289 | i, zone_in_use(i) ? "" : "not ", zone_count[i]); |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 1290 | } |
| 1291 | } |
| 1292 | #endif |
| 1293 | |
Eric Andersen | e674eb7 | 1999-10-19 20:52:57 +0000 | [diff] [blame] | 1294 | static void check(void) |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 1295 | { |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 1296 | memset(inode_count, 0, (INODES + 1) * sizeof(*inode_count)); |
| 1297 | memset(zone_count, 0, ZONES * sizeof(*zone_count)); |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 1298 | check_zones(ROOT_INO); |
| 1299 | recursive_check(ROOT_INO); |
| 1300 | check_counts(); |
| 1301 | } |
| 1302 | |
Pavel Roskin | bc0aed7 | 2000-07-17 17:52:00 +0000 | [diff] [blame] | 1303 | #ifdef BB_FEATURE_MINIX2 |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 1304 | static void check2(void) |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 1305 | { |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 1306 | memset(inode_count, 0, (INODES + 1) * sizeof(*inode_count)); |
| 1307 | memset(zone_count, 0, ZONES * sizeof(*zone_count)); |
| 1308 | check_zones2(ROOT_INO); |
| 1309 | recursive_check2(ROOT_INO); |
| 1310 | check_counts2(); |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 1311 | } |
| 1312 | #endif |
| 1313 | |
John Beppu | c1dc5d9 | 2000-02-11 12:43:20 +0000 | [diff] [blame] | 1314 | /* Wed Feb 9 15:17:06 MST 2000 */ |
| 1315 | /* dynamically allocate name_list (instead of making it static) */ |
| 1316 | static void alloc_name_list(void) |
| 1317 | { |
| 1318 | int i; |
| 1319 | |
Erik Andersen | 0d068a2 | 2000-03-21 22:32:57 +0000 | [diff] [blame] | 1320 | name_list = xmalloc(sizeof(char *) * MAX_DEPTH); |
| 1321 | for (i = 0; i < MAX_DEPTH; i++) |
Erik Andersen | 4f3f757 | 2000-04-28 00:18:56 +0000 | [diff] [blame] | 1322 | name_list[i] = xmalloc(sizeof(char) * BUFSIZ + 1); |
John Beppu | c1dc5d9 | 2000-02-11 12:43:20 +0000 | [diff] [blame] | 1323 | } |
| 1324 | |
Eric Andersen | b040d4f | 2000-07-25 18:01:20 +0000 | [diff] [blame] | 1325 | #ifdef BB_FEATURE_CLEAN_UP |
John Beppu | 5e1b2ca | 2000-02-11 12:52:55 +0000 | [diff] [blame] | 1326 | /* execute this atexit() to deallocate name_list[] */ |
| 1327 | /* piptigger was here */ |
John Beppu | c1dc5d9 | 2000-02-11 12:43:20 +0000 | [diff] [blame] | 1328 | static void free_name_list(void) |
| 1329 | { |
John Beppu | 5e1b2ca | 2000-02-11 12:52:55 +0000 | [diff] [blame] | 1330 | int i; |
| 1331 | |
| 1332 | if (name_list) { |
| 1333 | for (i = 0; i < MAX_DEPTH; i++) { |
| 1334 | if (name_list[i]) { |
| 1335 | free(name_list[i]); |
| 1336 | } |
| 1337 | } |
| 1338 | free(name_list); |
| 1339 | } |
John Beppu | c1dc5d9 | 2000-02-11 12:43:20 +0000 | [diff] [blame] | 1340 | } |
Erik Andersen | 298854f | 2000-03-23 01:09:18 +0000 | [diff] [blame] | 1341 | #endif |
John Beppu | c1dc5d9 | 2000-02-11 12:43:20 +0000 | [diff] [blame] | 1342 | |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 1343 | extern int fsck_minix_main(int argc, char **argv) |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 1344 | { |
| 1345 | struct termios tmp; |
| 1346 | int count; |
| 1347 | int retcode = 0; |
| 1348 | |
John Beppu | c1dc5d9 | 2000-02-11 12:43:20 +0000 | [diff] [blame] | 1349 | alloc_name_list(); |
Eric Andersen | b040d4f | 2000-07-25 18:01:20 +0000 | [diff] [blame] | 1350 | #ifdef BB_FEATURE_CLEAN_UP |
Erik Andersen | 298854f | 2000-03-23 01:09:18 +0000 | [diff] [blame] | 1351 | /* Don't bother to free memory. Exit does |
| 1352 | * that automagically, so we can save a few bytes */ |
Eric Andersen | b040d4f | 2000-07-25 18:01:20 +0000 | [diff] [blame] | 1353 | atexit(free_name_list); |
| 1354 | #endif |
John Beppu | c1dc5d9 | 2000-02-11 12:43:20 +0000 | [diff] [blame] | 1355 | |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 1356 | if (INODE_SIZE * MINIX_INODES_PER_BLOCK != BLOCK_SIZE) |
Eric Andersen | e674eb7 | 1999-10-19 20:52:57 +0000 | [diff] [blame] | 1357 | die("bad inode size"); |
Pavel Roskin | bc0aed7 | 2000-07-17 17:52:00 +0000 | [diff] [blame] | 1358 | #ifdef BB_FEATURE_MINIX2 |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 1359 | if (INODE_SIZE2 * MINIX2_INODES_PER_BLOCK != BLOCK_SIZE) |
Eric Andersen | e674eb7 | 1999-10-19 20:52:57 +0000 | [diff] [blame] | 1360 | die("bad v2 inode size"); |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 1361 | #endif |
| 1362 | while (argc-- > 1) { |
| 1363 | argv++; |
| 1364 | if (argv[0][0] != '-') { |
| 1365 | if (device_name) |
Eric Andersen | e674eb7 | 1999-10-19 20:52:57 +0000 | [diff] [blame] | 1366 | show_usage(); |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 1367 | else |
| 1368 | device_name = argv[0]; |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 1369 | } else |
| 1370 | while (*++argv[0]) |
| 1371 | switch (argv[0][0]) { |
| 1372 | case 'l': |
| 1373 | list = 1; |
| 1374 | break; |
| 1375 | case 'a': |
| 1376 | automatic = 1; |
| 1377 | repair = 1; |
| 1378 | break; |
| 1379 | case 'r': |
| 1380 | automatic = 0; |
| 1381 | repair = 1; |
| 1382 | break; |
| 1383 | case 'v': |
| 1384 | verbose = 1; |
| 1385 | break; |
| 1386 | case 's': |
| 1387 | show = 1; |
| 1388 | break; |
| 1389 | case 'm': |
| 1390 | warn_mode = 1; |
| 1391 | break; |
| 1392 | case 'f': |
| 1393 | force = 1; |
| 1394 | break; |
| 1395 | default: |
| 1396 | show_usage(); |
| 1397 | } |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 1398 | } |
| 1399 | if (!device_name) |
Eric Andersen | e674eb7 | 1999-10-19 20:52:57 +0000 | [diff] [blame] | 1400 | show_usage(); |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 1401 | check_mount(); /* trying to check a mounted filesystem? */ |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 1402 | if (repair && !automatic) { |
| 1403 | if (!isatty(0) || !isatty(1)) |
Eric Andersen | e674eb7 | 1999-10-19 20:52:57 +0000 | [diff] [blame] | 1404 | die("need terminal for interactive repairs"); |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 1405 | } |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 1406 | IN = open(device_name, repair ? O_RDWR : O_RDONLY); |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 1407 | if (IN < 0) |
Eric Andersen | e674eb7 | 1999-10-19 20:52:57 +0000 | [diff] [blame] | 1408 | die("unable to open '%s'"); |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 1409 | for (count = 0; count < 3; count++) |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 1410 | sync(); |
| 1411 | read_superblock(); |
| 1412 | |
| 1413 | /* |
| 1414 | * Determine whether or not we should continue with the checking. |
| 1415 | * This is based on the status of the filesystem valid and error |
| 1416 | * flags and whether or not the -f switch was specified on the |
| 1417 | * command line. |
| 1418 | */ |
Matt Kraai | e58771e | 2000-07-12 15:38:49 +0000 | [diff] [blame] | 1419 | printf("%s, %s\n", applet_name, program_version); |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 1420 | if (!(Super.s_state & MINIX_ERROR_FS) && |
| 1421 | (Super.s_state & MINIX_VALID_FS) && !force) { |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 1422 | if (repair) |
Eric Andersen | e674eb7 | 1999-10-19 20:52:57 +0000 | [diff] [blame] | 1423 | printf("%s is clean, no check.\n", device_name); |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 1424 | return retcode; |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 1425 | } else if (force) |
Eric Andersen | e674eb7 | 1999-10-19 20:52:57 +0000 | [diff] [blame] | 1426 | printf("Forcing filesystem check on %s.\n", device_name); |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 1427 | else if (repair) |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 1428 | printf("Filesystem on %s is dirty, needs checking.\n", |
| 1429 | device_name); |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 1430 | |
| 1431 | read_tables(); |
| 1432 | |
| 1433 | if (repair && !automatic) { |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 1434 | tcgetattr(0, &termios); |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 1435 | tmp = termios; |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 1436 | tmp.c_lflag &= ~(ICANON | ECHO); |
| 1437 | tcsetattr(0, TCSANOW, &tmp); |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 1438 | termios_set = 1; |
| 1439 | } |
Pavel Roskin | bc0aed7 | 2000-07-17 17:52:00 +0000 | [diff] [blame] | 1440 | #ifdef BB_FEATURE_MINIX2 |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 1441 | if (version2) { |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 1442 | check_root2(); |
| 1443 | check2(); |
| 1444 | } else |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 1445 | #endif |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 1446 | { |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 1447 | check_root(); |
| 1448 | check(); |
| 1449 | } |
| 1450 | if (verbose) { |
| 1451 | int i, free; |
| 1452 | |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 1453 | for (i = 1, free = 0; i <= INODES; i++) |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 1454 | if (!inode_in_use(i)) |
| 1455 | free++; |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 1456 | printf("\n%6ld inodes used (%ld%%)\n", (INODES - free), |
| 1457 | 100 * (INODES - free) / INODES); |
| 1458 | for (i = FIRSTZONE, free = 0; i < ZONES; i++) |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 1459 | if (!zone_in_use(i)) |
| 1460 | free++; |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 1461 | printf("%6ld zones used (%ld%%)\n", (ZONES - free), |
| 1462 | 100 * (ZONES - free) / ZONES); |
Eric Andersen | e674eb7 | 1999-10-19 20:52:57 +0000 | [diff] [blame] | 1463 | printf("\n%6d regular files\n" |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 1464 | "%6d directories\n" |
| 1465 | "%6d character device files\n" |
| 1466 | "%6d block device files\n" |
| 1467 | "%6d links\n" |
| 1468 | "%6d symbolic links\n" |
| 1469 | "------\n" |
| 1470 | "%6d files\n", |
| 1471 | regular, directory, chardev, blockdev, |
| 1472 | links - 2 * directory + 1, symlinks, |
| 1473 | total - 2 * directory + 1); |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 1474 | } |
| 1475 | if (changed) { |
| 1476 | write_tables(); |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 1477 | printf("----------------------------\n" |
| 1478 | "FILE SYSTEM HAS BEEN CHANGED\n" |
| 1479 | "----------------------------\n"); |
| 1480 | for (count = 0; count < 3; count++) |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 1481 | sync(); |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 1482 | } else if (repair) |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 1483 | write_super_block(); |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 1484 | |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 1485 | if (repair && !automatic) |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 1486 | tcsetattr(0, TCSANOW, &termios); |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 1487 | |
| 1488 | if (changed) |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 1489 | retcode += 3; |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 1490 | if (errors_uncorrected) |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 1491 | retcode += 4; |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 1492 | return retcode; |
| 1493 | } |