diff options
Diffstat (limited to 'fsck_minix.c')
-rw-r--r-- | fsck_minix.c | 716 |
1 files changed, 364 insertions, 352 deletions
diff --git a/fsck_minix.c b/fsck_minix.c index 09111c5dc..084c76d36 100644 --- a/fsck_minix.c +++ b/fsck_minix.c | |||
@@ -1,3 +1,4 @@ | |||
1 | /* vi: set sw=4 ts=4: */ | ||
1 | /* | 2 | /* |
2 | * fsck.c - a file system consistency checker for Linux. | 3 | * fsck.c - a file system consistency checker for Linux. |
3 | * | 4 | * |
@@ -96,7 +97,7 @@ | |||
96 | #include <termios.h> | 97 | #include <termios.h> |
97 | #include <mntent.h> | 98 | #include <mntent.h> |
98 | #include <sys/stat.h> | 99 | #include <sys/stat.h> |
99 | #include <sys/param.h> /* for PATH_MAX */ | 100 | #include <sys/param.h> /* for PATH_MAX */ |
100 | 101 | ||
101 | #include <linux/fs.h> | 102 | #include <linux/fs.h> |
102 | #include <linux/minix_fs.h> | 103 | #include <linux/minix_fs.h> |
@@ -124,17 +125,17 @@ | |||
124 | 125 | ||
125 | #define BITS_PER_BLOCK (BLOCK_SIZE<<3) | 126 | #define BITS_PER_BLOCK (BLOCK_SIZE<<3) |
126 | 127 | ||
127 | static char * program_name = "fsck.minix"; | 128 | static char *program_name = "fsck.minix"; |
128 | static char * program_version = "1.2 - 11/11/96"; | 129 | static char *program_version = "1.2 - 11/11/96"; |
129 | static char * device_name = NULL; | 130 | static char *device_name = NULL; |
130 | static int IN; | 131 | static int IN; |
131 | static int repair=0, automatic=0, verbose=0, list=0, show=0, warn_mode=0, | 132 | static int repair = 0, automatic = 0, verbose = 0, list = 0, show = |
132 | force=0; | 133 | 0, warn_mode = 0, force = 0; |
133 | static int directory=0, regular=0, blockdev=0, chardev=0, links=0, | 134 | static int directory = 0, regular = 0, blockdev = 0, chardev = 0, links = |
134 | symlinks=0, total=0; | 135 | 0, symlinks = 0, total = 0; |
135 | 136 | ||
136 | static int changed = 0; /* flags if the filesystem has been changed */ | 137 | static int changed = 0; /* flags if the filesystem has been changed */ |
137 | static int errors_uncorrected = 0; /* flag if some error was not corrected */ | 138 | static int errors_uncorrected = 0; /* flag if some error was not corrected */ |
138 | static int dirsize = 16; | 139 | static int dirsize = 16; |
139 | static int namelen = 14; | 140 | static int namelen = 14; |
140 | static int version2 = 0; | 141 | static int version2 = 0; |
@@ -146,10 +147,12 @@ static int termios_set = 0; | |||
146 | static int name_depth = 0; | 147 | static int name_depth = 0; |
147 | static char name_list[MAX_DEPTH][PATH_MAX + 1]; | 148 | static char name_list[MAX_DEPTH][PATH_MAX + 1]; |
148 | 149 | ||
149 | static char * inode_buffer = NULL; | 150 | static char *inode_buffer = NULL; |
151 | |||
150 | #define Inode (((struct minix_inode *) inode_buffer)-1) | 152 | #define Inode (((struct minix_inode *) inode_buffer)-1) |
151 | #define Inode2 (((struct minix2_inode *) inode_buffer)-1) | 153 | #define Inode2 (((struct minix2_inode *) inode_buffer)-1) |
152 | static char super_block_buffer[BLOCK_SIZE]; | 154 | static char super_block_buffer[BLOCK_SIZE]; |
155 | |||
153 | #define Super (*(struct minix_super_block *)super_block_buffer) | 156 | #define Super (*(struct minix_super_block *)super_block_buffer) |
154 | #define INODES ((unsigned long)Super.s_ninodes) | 157 | #define INODES ((unsigned long)Super.s_ninodes) |
155 | #ifdef HAVE_MINIX2 | 158 | #ifdef HAVE_MINIX2 |
@@ -168,8 +171,8 @@ static char super_block_buffer[BLOCK_SIZE]; | |||
168 | static char *inode_map; | 171 | static char *inode_map; |
169 | static char *zone_map; | 172 | static char *zone_map; |
170 | 173 | ||
171 | static unsigned char * inode_count = NULL; | 174 | static unsigned char *inode_count = NULL; |
172 | static unsigned char * zone_count = NULL; | 175 | static unsigned char *zone_count = NULL; |
173 | 176 | ||
174 | static void recursive_check(unsigned int ino); | 177 | static void recursive_check(unsigned int ino); |
175 | static void recursive_check2(unsigned int ino); | 178 | static void recursive_check2(unsigned int ino); |
@@ -191,22 +194,27 @@ static void leave(int status) | |||
191 | exit(status); | 194 | exit(status); |
192 | } | 195 | } |
193 | 196 | ||
194 | static void show_usage(void) { | 197 | static void show_usage(void) |
195 | fprintf(stderr, "BusyBox v%s (%s) multi-call binary -- GPL2\n\n", BB_VER, BB_BT); | 198 | { |
199 | fprintf(stderr, "BusyBox v%s (%s) multi-call binary -- GPL2\n\n", | ||
200 | BB_VER, BB_BT); | ||
196 | fprintf(stderr, "Usage: %s [-larvsmf] /dev/name\n\n", program_name); | 201 | fprintf(stderr, "Usage: %s [-larvsmf] /dev/name\n\n", program_name); |
197 | fprintf(stderr, "Performs a consistency check for MINIX filesystems.\n\n"); | 202 | fprintf(stderr, |
203 | "Performs a consistency check for MINIX filesystems.\n\n"); | ||
198 | fprintf(stderr, "OPTIONS:\n"); | 204 | fprintf(stderr, "OPTIONS:\n"); |
199 | fprintf(stderr, "\t-l\tLists all filenames\n"); | 205 | fprintf(stderr, "\t-l\tLists all filenames\n"); |
200 | fprintf(stderr, "\t-r\tPerform interactive repairs\n"); | 206 | fprintf(stderr, "\t-r\tPerform interactive repairs\n"); |
201 | fprintf(stderr, "\t-a\tPerform automatic repairs\n"); | 207 | fprintf(stderr, "\t-a\tPerform automatic repairs\n"); |
202 | fprintf(stderr, "\t-v\tverbose\n"); | 208 | fprintf(stderr, "\t-v\tverbose\n"); |
203 | fprintf(stderr, "\t-s\tOutputs super-block information\n"); | 209 | fprintf(stderr, "\t-s\tOutputs super-block information\n"); |
204 | fprintf(stderr, "\t-m\tActivates MINIX-like \"mode not cleared\" warnings\n"); | 210 | fprintf(stderr, |
211 | "\t-m\tActivates MINIX-like \"mode not cleared\" warnings\n"); | ||
205 | fprintf(stderr, "\t-f\tForce file system check.\n\n"); | 212 | fprintf(stderr, "\t-f\tForce file system check.\n\n"); |
206 | leave(16); | 213 | leave(16); |
207 | } | 214 | } |
208 | 215 | ||
209 | static void die(const char *str) { | 216 | static void die(const char *str) |
217 | { | ||
210 | fprintf(stderr, "%s: %s\n", program_name, str); | 218 | fprintf(stderr, "%s: %s\n", program_name, str); |
211 | leave(8); | 219 | leave(8); |
212 | } | 220 | } |
@@ -217,15 +225,15 @@ static void die(const char *str) { | |||
217 | */ | 225 | */ |
218 | static void print_current_name(void) | 226 | static void print_current_name(void) |
219 | { | 227 | { |
220 | int i=0; | 228 | int i = 0; |
221 | 229 | ||
222 | while (i<name_depth) | 230 | while (i < name_depth) |
223 | printf("/%.*s",namelen,name_list[i++]); | 231 | printf("/%.*s", namelen, name_list[i++]); |
224 | if (i == 0) | 232 | if (i == 0) |
225 | printf ("/"); | 233 | printf("/"); |
226 | } | 234 | } |
227 | 235 | ||
228 | static int ask(const char * string, int def) | 236 | static int ask(const char *string, int def) |
229 | { | 237 | { |
230 | int c; | 238 | int c; |
231 | 239 | ||
@@ -237,18 +245,18 @@ static int ask(const char * string, int def) | |||
237 | if (automatic) { | 245 | if (automatic) { |
238 | printf("\n"); | 246 | printf("\n"); |
239 | if (!def) | 247 | if (!def) |
240 | errors_uncorrected = 1; | 248 | errors_uncorrected = 1; |
241 | return def; | 249 | return def; |
242 | } | 250 | } |
243 | printf(def?"%s (y/n)? ":"%s (n/y)? ",string); | 251 | printf(def ? "%s (y/n)? " : "%s (n/y)? ", string); |
244 | for (;;) { | 252 | for (;;) { |
245 | fflush(stdout); | 253 | fflush(stdout); |
246 | if ((c=getchar())==EOF) { | 254 | if ((c = getchar()) == EOF) { |
247 | if (!def) | 255 | if (!def) |
248 | errors_uncorrected = 1; | 256 | errors_uncorrected = 1; |
249 | return def; | 257 | return def; |
250 | } | 258 | } |
251 | c=toupper(c); | 259 | c = toupper(c); |
252 | if (c == 'Y') { | 260 | if (c == 'Y') { |
253 | def = 1; | 261 | def = 1; |
254 | break; | 262 | break; |
@@ -263,7 +271,7 @@ static int ask(const char * string, int def) | |||
263 | else { | 271 | else { |
264 | printf("n\n"); | 272 | printf("n\n"); |
265 | errors_uncorrected = 1; | 273 | errors_uncorrected = 1; |
266 | } | 274 | } |
267 | return def; | 275 | return def; |
268 | } | 276 | } |
269 | 277 | ||
@@ -274,17 +282,17 @@ static int ask(const char * string, int def) | |||
274 | */ | 282 | */ |
275 | static void check_mount(void) | 283 | static void check_mount(void) |
276 | { | 284 | { |
277 | FILE * f; | 285 | FILE *f; |
278 | struct mntent * mnt; | 286 | struct mntent *mnt; |
279 | int cont; | 287 | int cont; |
280 | int fd; | 288 | int fd; |
281 | 289 | ||
282 | if ((f = setmntent (MOUNTED, "r")) == NULL) | 290 | if ((f = setmntent(MOUNTED, "r")) == NULL) |
283 | return; | 291 | return; |
284 | while ((mnt = getmntent (f)) != NULL) | 292 | while ((mnt = getmntent(f)) != NULL) |
285 | if (strcmp (device_name, mnt->mnt_fsname) == 0) | 293 | if (strcmp(device_name, mnt->mnt_fsname) == 0) |
286 | break; | 294 | break; |
287 | endmntent (f); | 295 | endmntent(f); |
288 | if (!mnt) | 296 | if (!mnt) |
289 | return; | 297 | return; |
290 | 298 | ||
@@ -298,15 +306,15 @@ static void check_mount(void) | |||
298 | return; | 306 | return; |
299 | else | 307 | else |
300 | close(fd); | 308 | close(fd); |
301 | 309 | ||
302 | printf ("%s is mounted. ", device_name); | 310 | printf("%s is mounted. ", device_name); |
303 | if (isatty(0) && isatty(1)) | 311 | if (isatty(0) && isatty(1)) |
304 | cont = ask("Do you really want to continue", 0); | 312 | cont = ask("Do you really want to continue", 0); |
305 | else | 313 | else |
306 | cont = 0; | 314 | cont = 0; |
307 | if (!cont) { | 315 | if (!cont) { |
308 | printf ("check aborted.\n"); | 316 | printf("check aborted.\n"); |
309 | exit (0); | 317 | exit(0); |
310 | } | 318 | } |
311 | return; | 319 | return; |
312 | } | 320 | } |
@@ -317,7 +325,7 @@ static void check_mount(void) | |||
317 | * if an error was corrected, and returns the zone (0 for no zone | 325 | * if an error was corrected, and returns the zone (0 for no zone |
318 | * or a bad zone-number). | 326 | * or a bad zone-number). |
319 | */ | 327 | */ |
320 | static int check_zone_nr(unsigned short * nr, int * corrected) | 328 | static int check_zone_nr(unsigned short *nr, int *corrected) |
321 | { | 329 | { |
322 | if (!*nr) | 330 | if (!*nr) |
323 | return 0; | 331 | return 0; |
@@ -329,7 +337,7 @@ static int check_zone_nr(unsigned short * nr, int * corrected) | |||
329 | return *nr; | 337 | return *nr; |
330 | print_current_name(); | 338 | print_current_name(); |
331 | printf("'."); | 339 | printf("'."); |
332 | if (ask("Remove block",1)) { | 340 | if (ask("Remove block", 1)) { |
333 | *nr = 0; | 341 | *nr = 0; |
334 | *corrected = 1; | 342 | *corrected = 1; |
335 | } | 343 | } |
@@ -337,19 +345,19 @@ static int check_zone_nr(unsigned short * nr, int * corrected) | |||
337 | } | 345 | } |
338 | 346 | ||
339 | #ifdef HAVE_MINIX2 | 347 | #ifdef HAVE_MINIX2 |
340 | static int check_zone_nr2 (unsigned int *nr, int *corrected) | 348 | static int check_zone_nr2(unsigned int *nr, int *corrected) |
341 | { | 349 | { |
342 | if (!*nr) | 350 | if (!*nr) |
343 | return 0; | 351 | return 0; |
344 | if (*nr < FIRSTZONE) | 352 | if (*nr < FIRSTZONE) |
345 | printf ("Zone nr < FIRSTZONE in file `"); | 353 | printf("Zone nr < FIRSTZONE in file `"); |
346 | else if (*nr >= ZONES) | 354 | else if (*nr >= ZONES) |
347 | printf ("Zone nr >= ZONES in file `"); | 355 | printf("Zone nr >= ZONES in file `"); |
348 | else | 356 | else |
349 | return *nr; | 357 | return *nr; |
350 | print_current_name (); | 358 | print_current_name(); |
351 | printf ("'."); | 359 | printf("'."); |
352 | if (ask ("Remove block", 1)) { | 360 | if (ask("Remove block", 1)) { |
353 | *nr = 0; | 361 | *nr = 0; |
354 | *corrected = 1; | 362 | *corrected = 1; |
355 | } | 363 | } |
@@ -360,23 +368,23 @@ static int check_zone_nr2 (unsigned int *nr, int *corrected) | |||
360 | /* | 368 | /* |
361 | * read-block reads block nr into the buffer at addr. | 369 | * read-block reads block nr into the buffer at addr. |
362 | */ | 370 | */ |
363 | static void read_block(unsigned int nr, char * addr) | 371 | static void read_block(unsigned int nr, char *addr) |
364 | { | 372 | { |
365 | if (!nr) { | 373 | if (!nr) { |
366 | memset(addr,0,BLOCK_SIZE); | 374 | memset(addr, 0, BLOCK_SIZE); |
367 | return; | 375 | return; |
368 | } | 376 | } |
369 | if (BLOCK_SIZE*nr != lseek(IN, BLOCK_SIZE*nr, SEEK_SET)) { | 377 | if (BLOCK_SIZE * nr != lseek(IN, BLOCK_SIZE * nr, SEEK_SET)) { |
370 | printf("Read error: unable to seek to block in file '"); | 378 | printf("Read error: unable to seek to block in file '"); |
371 | print_current_name(); | 379 | print_current_name(); |
372 | printf("'\n"); | 380 | printf("'\n"); |
373 | memset(addr,0,BLOCK_SIZE); | 381 | memset(addr, 0, BLOCK_SIZE); |
374 | errors_uncorrected = 1; | 382 | errors_uncorrected = 1; |
375 | } else if (BLOCK_SIZE != read(IN, addr, BLOCK_SIZE)) { | 383 | } else if (BLOCK_SIZE != read(IN, addr, BLOCK_SIZE)) { |
376 | printf("Read error: bad block in file '"); | 384 | printf("Read error: bad block in file '"); |
377 | print_current_name(); | 385 | print_current_name(); |
378 | printf("'\n"); | 386 | printf("'\n"); |
379 | memset(addr,0,BLOCK_SIZE); | 387 | memset(addr, 0, BLOCK_SIZE); |
380 | errors_uncorrected = 1; | 388 | errors_uncorrected = 1; |
381 | } | 389 | } |
382 | } | 390 | } |
@@ -384,17 +392,17 @@ static void read_block(unsigned int nr, char * addr) | |||
384 | /* | 392 | /* |
385 | * write_block writes block nr to disk. | 393 | * write_block writes block nr to disk. |
386 | */ | 394 | */ |
387 | static void write_block(unsigned int nr, char * addr) | 395 | static void write_block(unsigned int nr, char *addr) |
388 | { | 396 | { |
389 | if (!nr) | 397 | if (!nr) |
390 | return; | 398 | return; |
391 | if (nr < FIRSTZONE || nr >= ZONES) { | 399 | if (nr < FIRSTZONE || nr >= ZONES) { |
392 | printf("Internal error: trying to write bad block\n" | 400 | printf("Internal error: trying to write bad block\n" |
393 | "Write request ignored\n"); | 401 | "Write request ignored\n"); |
394 | errors_uncorrected = 1; | 402 | errors_uncorrected = 1; |
395 | return; | 403 | return; |
396 | } | 404 | } |
397 | if (BLOCK_SIZE*nr != lseek(IN, BLOCK_SIZE*nr, SEEK_SET)) | 405 | if (BLOCK_SIZE * nr != lseek(IN, BLOCK_SIZE * nr, SEEK_SET)) |
398 | die("seek failed in write_block"); | 406 | die("seek failed in write_block"); |
399 | if (BLOCK_SIZE != write(IN, addr, BLOCK_SIZE)) { | 407 | if (BLOCK_SIZE != write(IN, addr, BLOCK_SIZE)) { |
400 | printf("Write error: bad block in file '"); | 408 | printf("Write error: bad block in file '"); |
@@ -409,16 +417,16 @@ static void write_block(unsigned int nr, char * addr) | |||
409 | * It sets 'changed' if the inode has needed changing, and re-writes | 417 | * It sets 'changed' if the inode has needed changing, and re-writes |
410 | * any indirect blocks with errors. | 418 | * any indirect blocks with errors. |
411 | */ | 419 | */ |
412 | static int map_block(struct minix_inode * inode, unsigned int blknr) | 420 | static int map_block(struct minix_inode *inode, unsigned int blknr) |
413 | { | 421 | { |
414 | unsigned short ind[BLOCK_SIZE>>1]; | 422 | unsigned short ind[BLOCK_SIZE >> 1]; |
415 | unsigned short dind[BLOCK_SIZE>>1]; | 423 | unsigned short dind[BLOCK_SIZE >> 1]; |
416 | int blk_chg, block, result; | 424 | int blk_chg, block, result; |
417 | 425 | ||
418 | if (blknr<7) | 426 | if (blknr < 7) |
419 | return check_zone_nr(inode->i_zone + blknr, &changed); | 427 | return check_zone_nr(inode->i_zone + blknr, &changed); |
420 | blknr -= 7; | 428 | blknr -= 7; |
421 | if (blknr<512) { | 429 | if (blknr < 512) { |
422 | block = check_zone_nr(inode->i_zone + 7, &changed); | 430 | block = check_zone_nr(inode->i_zone + 7, &changed); |
423 | read_block(block, (char *) ind); | 431 | read_block(block, (char *) ind); |
424 | blk_chg = 0; | 432 | blk_chg = 0; |
@@ -431,73 +439,73 @@ static int map_block(struct minix_inode * inode, unsigned int blknr) | |||
431 | block = check_zone_nr(inode->i_zone + 8, &changed); | 439 | block = check_zone_nr(inode->i_zone + 8, &changed); |
432 | read_block(block, (char *) dind); | 440 | read_block(block, (char *) dind); |
433 | blk_chg = 0; | 441 | blk_chg = 0; |
434 | result = check_zone_nr(dind + (blknr/512), &blk_chg); | 442 | result = check_zone_nr(dind + (blknr / 512), &blk_chg); |
435 | if (blk_chg) | 443 | if (blk_chg) |
436 | write_block(block, (char *) dind); | 444 | write_block(block, (char *) dind); |
437 | block = result; | 445 | block = result; |
438 | read_block(block, (char *) ind); | 446 | read_block(block, (char *) ind); |
439 | blk_chg = 0; | 447 | blk_chg = 0; |
440 | result = check_zone_nr(ind + (blknr%512), &blk_chg); | 448 | result = check_zone_nr(ind + (blknr % 512), &blk_chg); |
441 | if (blk_chg) | 449 | if (blk_chg) |
442 | write_block(block, (char *) ind); | 450 | write_block(block, (char *) ind); |
443 | return result; | 451 | return result; |
444 | } | 452 | } |
445 | 453 | ||
446 | #ifdef HAVE_MINIX2 | 454 | #ifdef HAVE_MINIX2 |
447 | static int map_block2 (struct minix2_inode *inode, unsigned int blknr) | 455 | static int map_block2(struct minix2_inode *inode, unsigned int blknr) |
448 | { | 456 | { |
449 | unsigned int ind[BLOCK_SIZE >> 2]; | 457 | unsigned int ind[BLOCK_SIZE >> 2]; |
450 | unsigned int dind[BLOCK_SIZE >> 2]; | 458 | unsigned int dind[BLOCK_SIZE >> 2]; |
451 | unsigned int tind[BLOCK_SIZE >> 2]; | 459 | unsigned int tind[BLOCK_SIZE >> 2]; |
452 | int blk_chg, block, result; | 460 | int blk_chg, block, result; |
453 | 461 | ||
454 | if (blknr < 7) | 462 | if (blknr < 7) |
455 | return check_zone_nr2 (inode->i_zone + blknr, &changed); | 463 | return check_zone_nr2(inode->i_zone + blknr, &changed); |
456 | blknr -= 7; | 464 | blknr -= 7; |
457 | if (blknr < 256) { | 465 | if (blknr < 256) { |
458 | block = check_zone_nr2 (inode->i_zone + 7, &changed); | 466 | block = check_zone_nr2(inode->i_zone + 7, &changed); |
459 | read_block (block, (char *) ind); | 467 | read_block(block, (char *) ind); |
460 | blk_chg = 0; | 468 | blk_chg = 0; |
461 | result = check_zone_nr2 (blknr + ind, &blk_chg); | 469 | result = check_zone_nr2(blknr + ind, &blk_chg); |
462 | if (blk_chg) | 470 | if (blk_chg) |
463 | write_block (block, (char *) ind); | 471 | write_block(block, (char *) ind); |
464 | return result; | 472 | return result; |
465 | } | 473 | } |
466 | blknr -= 256; | 474 | blknr -= 256; |
467 | if (blknr >= 256 * 256) { | 475 | if (blknr >= 256 * 256) { |
468 | block = check_zone_nr2 (inode->i_zone + 8, &changed); | 476 | block = check_zone_nr2(inode->i_zone + 8, &changed); |
469 | read_block (block, (char *) dind); | 477 | read_block(block, (char *) dind); |
470 | blk_chg = 0; | 478 | blk_chg = 0; |
471 | result = check_zone_nr2 (dind + blknr / 256, &blk_chg); | 479 | result = check_zone_nr2(dind + blknr / 256, &blk_chg); |
472 | if (blk_chg) | 480 | if (blk_chg) |
473 | write_block (block, (char *) dind); | 481 | write_block(block, (char *) dind); |
474 | block = result; | 482 | block = result; |
475 | read_block (block, (char *) ind); | 483 | read_block(block, (char *) ind); |
476 | blk_chg = 0; | 484 | blk_chg = 0; |
477 | result = check_zone_nr2 (ind + blknr % 256, &blk_chg); | 485 | result = check_zone_nr2(ind + blknr % 256, &blk_chg); |
478 | if (blk_chg) | 486 | if (blk_chg) |
479 | write_block (block, (char *) ind); | 487 | write_block(block, (char *) ind); |
480 | return result; | 488 | return result; |
481 | } | 489 | } |
482 | blknr -= 256 * 256; | 490 | blknr -= 256 * 256; |
483 | block = check_zone_nr2 (inode->i_zone + 9, &changed); | 491 | block = check_zone_nr2(inode->i_zone + 9, &changed); |
484 | read_block (block, (char *) tind); | 492 | read_block(block, (char *) tind); |
485 | blk_chg = 0; | 493 | blk_chg = 0; |
486 | result = check_zone_nr2 (tind + blknr / (256 * 256), &blk_chg); | 494 | result = check_zone_nr2(tind + blknr / (256 * 256), &blk_chg); |
487 | if (blk_chg) | 495 | if (blk_chg) |
488 | write_block (block, (char *) tind); | 496 | write_block(block, (char *) tind); |
489 | block = result; | 497 | block = result; |
490 | read_block (block, (char *) dind); | 498 | read_block(block, (char *) dind); |
491 | blk_chg = 0; | 499 | blk_chg = 0; |
492 | result = check_zone_nr2 (dind + (blknr / 256) % 256, &blk_chg); | 500 | result = check_zone_nr2(dind + (blknr / 256) % 256, &blk_chg); |
493 | if (blk_chg) | 501 | if (blk_chg) |
494 | write_block (block, (char *) dind); | 502 | write_block(block, (char *) dind); |
495 | block = result; | 503 | block = result; |
496 | read_block (block, (char *) ind); | 504 | read_block(block, (char *) ind); |
497 | blk_chg = 0; | 505 | blk_chg = 0; |
498 | result = check_zone_nr2 (ind + blknr % 256, &blk_chg); | 506 | result = check_zone_nr2(ind + blknr % 256, &blk_chg); |
499 | if (blk_chg) | 507 | if (blk_chg) |
500 | write_block (block, (char *) ind); | 508 | write_block(block, (char *) ind); |
501 | return result; | 509 | return result; |
502 | } | 510 | } |
503 | #endif | 511 | #endif |
@@ -510,11 +518,11 @@ static void write_super_block(void) | |||
510 | * unconditionally set if we get this far. | 518 | * unconditionally set if we get this far. |
511 | */ | 519 | */ |
512 | Super.s_state |= MINIX_VALID_FS; | 520 | Super.s_state |= MINIX_VALID_FS; |
513 | if ( errors_uncorrected ) | 521 | if (errors_uncorrected) |
514 | Super.s_state |= MINIX_ERROR_FS; | 522 | Super.s_state |= MINIX_ERROR_FS; |
515 | else | 523 | else |
516 | Super.s_state &= ~MINIX_ERROR_FS; | 524 | Super.s_state &= ~MINIX_ERROR_FS; |
517 | 525 | ||
518 | if (BLOCK_SIZE != lseek(IN, BLOCK_SIZE, SEEK_SET)) | 526 | if (BLOCK_SIZE != lseek(IN, BLOCK_SIZE, SEEK_SET)) |
519 | die("seek failed in write_super_block"); | 527 | die("seek failed in write_super_block"); |
520 | if (BLOCK_SIZE != write(IN, super_block_buffer, BLOCK_SIZE)) | 528 | if (BLOCK_SIZE != write(IN, super_block_buffer, BLOCK_SIZE)) |
@@ -527,15 +535,15 @@ static void write_tables(void) | |||
527 | { | 535 | { |
528 | write_super_block(); | 536 | write_super_block(); |
529 | 537 | ||
530 | if (IMAPS*BLOCK_SIZE != write(IN,inode_map,IMAPS*BLOCK_SIZE)) | 538 | if (IMAPS * BLOCK_SIZE != write(IN, inode_map, IMAPS * BLOCK_SIZE)) |
531 | die("Unable to write inode map"); | 539 | die("Unable to write inode map"); |
532 | if (ZMAPS*BLOCK_SIZE != write(IN,zone_map,ZMAPS*BLOCK_SIZE)) | 540 | if (ZMAPS * BLOCK_SIZE != write(IN, zone_map, ZMAPS * BLOCK_SIZE)) |
533 | die("Unable to write zone map"); | 541 | die("Unable to write zone map"); |
534 | if (INODE_BUFFER_SIZE != write(IN,inode_buffer,INODE_BUFFER_SIZE)) | 542 | if (INODE_BUFFER_SIZE != write(IN, inode_buffer, INODE_BUFFER_SIZE)) |
535 | die("Unable to write inodes"); | 543 | die("Unable to write inodes"); |
536 | } | 544 | } |
537 | 545 | ||
538 | static void get_dirsize (void) | 546 | static void get_dirsize(void) |
539 | { | 547 | { |
540 | int block; | 548 | int block; |
541 | char blk[BLOCK_SIZE]; | 549 | char blk[BLOCK_SIZE]; |
@@ -547,9 +555,9 @@ static void get_dirsize (void) | |||
547 | else | 555 | else |
548 | #endif | 556 | #endif |
549 | block = Inode[ROOT_INO].i_zone[0]; | 557 | block = Inode[ROOT_INO].i_zone[0]; |
550 | read_block (block, blk); | 558 | read_block(block, blk); |
551 | for (size = 16; size < BLOCK_SIZE; size <<= 1) { | 559 | for (size = 16; size < BLOCK_SIZE; size <<= 1) { |
552 | if (strcmp (blk + size + 2, "..") == 0) { | 560 | if (strcmp(blk + size + 2, "..") == 0) { |
553 | dirsize = size; | 561 | dirsize = size; |
554 | namelen = size - 2; | 562 | namelen = size - 2; |
555 | return; | 563 | return; |
@@ -600,8 +608,8 @@ static void read_tables(void) | |||
600 | zone_map = malloc(ZMAPS * BLOCK_SIZE); | 608 | zone_map = malloc(ZMAPS * BLOCK_SIZE); |
601 | if (!inode_map) | 609 | if (!inode_map) |
602 | die("Unable to allocate buffer for zone map"); | 610 | die("Unable to allocate buffer for zone map"); |
603 | memset(inode_map,0,sizeof(inode_map)); | 611 | memset(inode_map, 0, sizeof(inode_map)); |
604 | memset(zone_map,0,sizeof(zone_map)); | 612 | memset(zone_map, 0, sizeof(zone_map)); |
605 | inode_buffer = malloc(INODE_BUFFER_SIZE); | 613 | inode_buffer = malloc(INODE_BUFFER_SIZE); |
606 | if (!inode_buffer) | 614 | if (!inode_buffer) |
607 | die("Unable to allocate buffer for inodes"); | 615 | die("Unable to allocate buffer for inodes"); |
@@ -611,31 +619,31 @@ static void read_tables(void) | |||
611 | zone_count = malloc(ZONES); | 619 | zone_count = malloc(ZONES); |
612 | if (!zone_count) | 620 | if (!zone_count) |
613 | die("Unable to allocate buffer for zone count"); | 621 | die("Unable to allocate buffer for zone count"); |
614 | if (IMAPS*BLOCK_SIZE != read(IN,inode_map,IMAPS*BLOCK_SIZE)) | 622 | if (IMAPS * BLOCK_SIZE != read(IN, inode_map, IMAPS * BLOCK_SIZE)) |
615 | die("Unable to read inode map"); | 623 | die("Unable to read inode map"); |
616 | if (ZMAPS*BLOCK_SIZE != read(IN,zone_map,ZMAPS*BLOCK_SIZE)) | 624 | if (ZMAPS * BLOCK_SIZE != read(IN, zone_map, ZMAPS * BLOCK_SIZE)) |
617 | die("Unable to read zone map"); | 625 | die("Unable to read zone map"); |
618 | if (INODE_BUFFER_SIZE != read(IN,inode_buffer,INODE_BUFFER_SIZE)) | 626 | if (INODE_BUFFER_SIZE != read(IN, inode_buffer, INODE_BUFFER_SIZE)) |
619 | die("Unable to read inodes"); | 627 | die("Unable to read inodes"); |
620 | if (NORM_FIRSTZONE != FIRSTZONE) { | 628 | if (NORM_FIRSTZONE != FIRSTZONE) { |
621 | printf("Warning: Firstzone != Norm_firstzone\n"); | 629 | printf("Warning: Firstzone != Norm_firstzone\n"); |
622 | errors_uncorrected = 1; | 630 | errors_uncorrected = 1; |
623 | } | 631 | } |
624 | get_dirsize (); | 632 | get_dirsize(); |
625 | if (show) { | 633 | if (show) { |
626 | printf("%ld inodes\n",INODES); | 634 | printf("%ld inodes\n", INODES); |
627 | printf("%ld blocks\n",ZONES); | 635 | printf("%ld blocks\n", ZONES); |
628 | printf("Firstdatazone=%ld (%ld)\n",FIRSTZONE,NORM_FIRSTZONE); | 636 | printf("Firstdatazone=%ld (%ld)\n", FIRSTZONE, NORM_FIRSTZONE); |
629 | printf("Zonesize=%d\n",BLOCK_SIZE<<ZONESIZE); | 637 | printf("Zonesize=%d\n", BLOCK_SIZE << ZONESIZE); |
630 | printf("Maxsize=%ld\n",MAXSIZE); | 638 | printf("Maxsize=%ld\n", MAXSIZE); |
631 | printf("Filesystem state=%d\n", Super.s_state); | 639 | printf("Filesystem state=%d\n", Super.s_state); |
632 | printf("namelen=%d\n\n",namelen); | 640 | printf("namelen=%d\n\n", namelen); |
633 | } | 641 | } |
634 | } | 642 | } |
635 | 643 | ||
636 | struct minix_inode * get_inode(unsigned int nr) | 644 | struct minix_inode *get_inode(unsigned int nr) |
637 | { | 645 | { |
638 | struct minix_inode * inode; | 646 | struct minix_inode *inode; |
639 | 647 | ||
640 | if (!nr || nr > INODES) | 648 | if (!nr || nr > INODES) |
641 | return NULL; | 649 | return NULL; |
@@ -643,15 +651,14 @@ struct minix_inode * get_inode(unsigned int nr) | |||
643 | inode = Inode + nr; | 651 | inode = Inode + nr; |
644 | if (!inode_count[nr]) { | 652 | if (!inode_count[nr]) { |
645 | if (!inode_in_use(nr)) { | 653 | if (!inode_in_use(nr)) { |
646 | printf("Inode %d marked not used, but used for file '", | 654 | printf("Inode %d marked not used, but used for file '", nr); |
647 | nr); | ||
648 | print_current_name(); | 655 | print_current_name(); |
649 | printf("'\n"); | 656 | printf("'\n"); |
650 | if (repair) { | 657 | if (repair) { |
651 | if (ask("Mark in use",1)) | 658 | if (ask("Mark in use", 1)) |
652 | mark_inode(nr); | 659 | mark_inode(nr); |
653 | } else { | 660 | } else { |
654 | errors_uncorrected = 1; | 661 | errors_uncorrected = 1; |
655 | } | 662 | } |
656 | } | 663 | } |
657 | if (S_ISDIR(inode->i_mode)) | 664 | if (S_ISDIR(inode->i_mode)) |
@@ -664,14 +671,12 @@ struct minix_inode * get_inode(unsigned int nr) | |||
664 | blockdev++; | 671 | blockdev++; |
665 | else if (S_ISLNK(inode->i_mode)) | 672 | else if (S_ISLNK(inode->i_mode)) |
666 | symlinks++; | 673 | symlinks++; |
667 | else if (S_ISSOCK(inode->i_mode)) | 674 | else if (S_ISSOCK(inode->i_mode)); |
668 | ; | 675 | else if (S_ISFIFO(inode->i_mode)); |
669 | else if (S_ISFIFO(inode->i_mode)) | ||
670 | ; | ||
671 | else { | 676 | else { |
672 | print_current_name(); | 677 | print_current_name(); |
673 | printf(" has mode %05o\n",inode->i_mode); | 678 | printf(" has mode %05o\n", inode->i_mode); |
674 | } | 679 | } |
675 | 680 | ||
676 | } else | 681 | } else |
677 | links++; | 682 | links++; |
@@ -684,8 +689,7 @@ struct minix_inode * get_inode(unsigned int nr) | |||
684 | } | 689 | } |
685 | 690 | ||
686 | #ifdef HAVE_MINIX2 | 691 | #ifdef HAVE_MINIX2 |
687 | struct minix2_inode * | 692 | struct minix2_inode *get_inode2(unsigned int nr) |
688 | get_inode2 (unsigned int nr) | ||
689 | { | 693 | { |
690 | struct minix2_inode *inode; | 694 | struct minix2_inode *inode; |
691 | 695 | ||
@@ -694,37 +698,37 @@ get_inode2 (unsigned int nr) | |||
694 | total++; | 698 | total++; |
695 | inode = Inode2 + nr; | 699 | inode = Inode2 + nr; |
696 | if (!inode_count[nr]) { | 700 | if (!inode_count[nr]) { |
697 | if (!inode_in_use (nr)) { | 701 | if (!inode_in_use(nr)) { |
698 | printf ("Inode %d marked not used, but used for file '", nr); | 702 | printf("Inode %d marked not used, but used for file '", nr); |
699 | print_current_name (); | 703 | print_current_name(); |
700 | printf ("'\n"); | 704 | printf("'\n"); |
701 | if (repair) { | 705 | if (repair) { |
702 | if (ask ("Mark in use", 1)) | 706 | if (ask("Mark in use", 1)) |
703 | mark_inode (nr); | 707 | mark_inode(nr); |
704 | else | 708 | else |
705 | errors_uncorrected = 1; | 709 | errors_uncorrected = 1; |
706 | } | 710 | } |
707 | } | 711 | } |
708 | if (S_ISDIR (inode->i_mode)) | 712 | if (S_ISDIR(inode->i_mode)) |
709 | directory++; | 713 | directory++; |
710 | else if (S_ISREG (inode->i_mode)) | 714 | else if (S_ISREG(inode->i_mode)) |
711 | regular++; | 715 | regular++; |
712 | else if (S_ISCHR (inode->i_mode)) | 716 | else if (S_ISCHR(inode->i_mode)) |
713 | chardev++; | 717 | chardev++; |
714 | else if (S_ISBLK (inode->i_mode)) | 718 | else if (S_ISBLK(inode->i_mode)) |
715 | blockdev++; | 719 | blockdev++; |
716 | else if (S_ISLNK (inode->i_mode)) | 720 | else if (S_ISLNK(inode->i_mode)) |
717 | symlinks++; | 721 | symlinks++; |
718 | else if (S_ISSOCK (inode->i_mode)); | 722 | else if (S_ISSOCK(inode->i_mode)); |
719 | else if (S_ISFIFO (inode->i_mode)); | 723 | else if (S_ISFIFO(inode->i_mode)); |
720 | else { | 724 | else { |
721 | print_current_name (); | 725 | print_current_name(); |
722 | printf (" has mode %05o\n", inode->i_mode); | 726 | printf(" has mode %05o\n", inode->i_mode); |
723 | } | 727 | } |
724 | } else | 728 | } else |
725 | links++; | 729 | links++; |
726 | if (!++inode_count[nr]) { | 730 | if (!++inode_count[nr]) { |
727 | printf ("Warning: inode count too big.\n"); | 731 | printf("Warning: inode count too big.\n"); |
728 | inode_count[nr]--; | 732 | inode_count[nr]--; |
729 | errors_uncorrected = 1; | 733 | errors_uncorrected = 1; |
730 | } | 734 | } |
@@ -734,23 +738,23 @@ get_inode2 (unsigned int nr) | |||
734 | 738 | ||
735 | static void check_root(void) | 739 | static void check_root(void) |
736 | { | 740 | { |
737 | struct minix_inode * inode = Inode + ROOT_INO; | 741 | struct minix_inode *inode = Inode + ROOT_INO; |
738 | 742 | ||
739 | if (!inode || !S_ISDIR(inode->i_mode)) | 743 | if (!inode || !S_ISDIR(inode->i_mode)) |
740 | die("root inode isn't a directory"); | 744 | die("root inode isn't a directory"); |
741 | } | 745 | } |
742 | 746 | ||
743 | #ifdef HAVE_MINIX2 | 747 | #ifdef HAVE_MINIX2 |
744 | static void check_root2 (void) | 748 | static void check_root2(void) |
745 | { | 749 | { |
746 | struct minix2_inode *inode = Inode2 + ROOT_INO; | 750 | struct minix2_inode *inode = Inode2 + ROOT_INO; |
747 | 751 | ||
748 | if (!inode || !S_ISDIR (inode->i_mode)) | 752 | if (!inode || !S_ISDIR(inode->i_mode)) |
749 | die ("root inode isn't a directory"); | 753 | die("root inode isn't a directory"); |
750 | } | 754 | } |
751 | #endif | 755 | #endif |
752 | 756 | ||
753 | static int add_zone(unsigned short * znr, int * corrected) | 757 | static int add_zone(unsigned short *znr, int *corrected) |
754 | { | 758 | { |
755 | int result; | 759 | int result; |
756 | int block; | 760 | int block; |
@@ -763,7 +767,7 @@ static int add_zone(unsigned short * znr, int * corrected) | |||
763 | printf("Block has been used before. Now in file `"); | 767 | printf("Block has been used before. Now in file `"); |
764 | print_current_name(); | 768 | print_current_name(); |
765 | printf("'."); | 769 | printf("'."); |
766 | if (ask("Clear",1)) { | 770 | if (ask("Clear", 1)) { |
767 | *znr = 0; | 771 | *znr = 0; |
768 | block = 0; | 772 | block = 0; |
769 | *corrected = 1; | 773 | *corrected = 1; |
@@ -772,10 +776,10 @@ static int add_zone(unsigned short * znr, int * corrected) | |||
772 | if (!block) | 776 | if (!block) |
773 | return 0; | 777 | return 0; |
774 | if (!zone_in_use(block)) { | 778 | if (!zone_in_use(block)) { |
775 | printf("Block %d in file `",block); | 779 | printf("Block %d in file `", block); |
776 | print_current_name(); | 780 | print_current_name(); |
777 | printf("' is marked not in use."); | 781 | printf("' is marked not in use."); |
778 | if (ask("Correct",1)) | 782 | if (ask("Correct", 1)) |
779 | mark_zone(block); | 783 | mark_zone(block); |
780 | } | 784 | } |
781 | if (!++zone_count[block]) | 785 | if (!++zone_count[block]) |
@@ -784,20 +788,20 @@ static int add_zone(unsigned short * znr, int * corrected) | |||
784 | } | 788 | } |
785 | 789 | ||
786 | #ifdef HAVE_MINIX2 | 790 | #ifdef HAVE_MINIX2 |
787 | static int add_zone2 (unsigned int *znr, int *corrected) | 791 | static int add_zone2(unsigned int *znr, int *corrected) |
788 | { | 792 | { |
789 | int result; | 793 | int result; |
790 | int block; | 794 | int block; |
791 | 795 | ||
792 | result = 0; | 796 | result = 0; |
793 | block = check_zone_nr2 (znr, corrected); | 797 | block = check_zone_nr2(znr, corrected); |
794 | if (!block) | 798 | if (!block) |
795 | return 0; | 799 | return 0; |
796 | if (zone_count[block]) { | 800 | if (zone_count[block]) { |
797 | printf ("Block has been used before. Now in file `"); | 801 | printf("Block has been used before. Now in file `"); |
798 | print_current_name (); | 802 | print_current_name(); |
799 | printf ("'."); | 803 | printf("'."); |
800 | if (ask ("Clear", 1)) { | 804 | if (ask("Clear", 1)) { |
801 | *znr = 0; | 805 | *znr = 0; |
802 | block = 0; | 806 | block = 0; |
803 | *corrected = 1; | 807 | *corrected = 1; |
@@ -805,12 +809,12 @@ static int add_zone2 (unsigned int *znr, int *corrected) | |||
805 | } | 809 | } |
806 | if (!block) | 810 | if (!block) |
807 | return 0; | 811 | return 0; |
808 | if (!zone_in_use (block)) { | 812 | if (!zone_in_use(block)) { |
809 | printf ("Block %d in file `", block); | 813 | printf("Block %d in file `", block); |
810 | print_current_name (); | 814 | print_current_name(); |
811 | printf ("' is marked not in use."); | 815 | printf("' is marked not in use."); |
812 | if (ask ("Correct", 1)) | 816 | if (ask("Correct", 1)) |
813 | mark_zone (block); | 817 | mark_zone(block); |
814 | } | 818 | } |
815 | if (!++zone_count[block]) | 819 | if (!++zone_count[block]) |
816 | zone_count[block]--; | 820 | zone_count[block]--; |
@@ -818,182 +822,179 @@ static int add_zone2 (unsigned int *znr, int *corrected) | |||
818 | } | 822 | } |
819 | #endif | 823 | #endif |
820 | 824 | ||
821 | static void add_zone_ind(unsigned short * znr, int * corrected) | 825 | static void add_zone_ind(unsigned short *znr, int *corrected) |
822 | { | 826 | { |
823 | static char blk[BLOCK_SIZE]; | 827 | static char blk[BLOCK_SIZE]; |
824 | int i, chg_blk=0; | 828 | int i, chg_blk = 0; |
825 | int block; | 829 | int block; |
826 | 830 | ||
827 | block = add_zone(znr, corrected); | 831 | block = add_zone(znr, corrected); |
828 | if (!block) | 832 | if (!block) |
829 | return; | 833 | return; |
830 | read_block(block, blk); | 834 | read_block(block, blk); |
831 | for (i=0 ; i < (BLOCK_SIZE>>1) ; i++) | 835 | for (i = 0; i < (BLOCK_SIZE >> 1); i++) |
832 | add_zone(i + (unsigned short *) blk, &chg_blk); | 836 | add_zone(i + (unsigned short *) blk, &chg_blk); |
833 | if (chg_blk) | 837 | if (chg_blk) |
834 | write_block(block, blk); | 838 | write_block(block, blk); |
835 | } | 839 | } |
836 | 840 | ||
837 | #ifdef HAVE_MINIX2 | 841 | #ifdef HAVE_MINIX2 |
838 | static void | 842 | static void add_zone_ind2(unsigned int *znr, int *corrected) |
839 | add_zone_ind2 (unsigned int *znr, int *corrected) | ||
840 | { | 843 | { |
841 | static char blk[BLOCK_SIZE]; | 844 | static char blk[BLOCK_SIZE]; |
842 | int i, chg_blk = 0; | 845 | int i, chg_blk = 0; |
843 | int block; | 846 | int block; |
844 | 847 | ||
845 | block = add_zone2 (znr, corrected); | 848 | block = add_zone2(znr, corrected); |
846 | if (!block) | 849 | if (!block) |
847 | return; | 850 | return; |
848 | read_block (block, blk); | 851 | read_block(block, blk); |
849 | for (i = 0; i < BLOCK_SIZE >> 2; i++) | 852 | for (i = 0; i < BLOCK_SIZE >> 2; i++) |
850 | add_zone2 (i + (unsigned int *) blk, &chg_blk); | 853 | add_zone2(i + (unsigned int *) blk, &chg_blk); |
851 | if (chg_blk) | 854 | if (chg_blk) |
852 | write_block (block, blk); | 855 | write_block(block, blk); |
853 | } | 856 | } |
854 | #endif | 857 | #endif |
855 | 858 | ||
856 | static void add_zone_dind(unsigned short * znr, int * corrected) | 859 | static void add_zone_dind(unsigned short *znr, int *corrected) |
857 | { | 860 | { |
858 | static char blk[BLOCK_SIZE]; | 861 | static char blk[BLOCK_SIZE]; |
859 | int i, blk_chg=0; | 862 | int i, blk_chg = 0; |
860 | int block; | 863 | int block; |
861 | 864 | ||
862 | block = add_zone(znr, corrected); | 865 | block = add_zone(znr, corrected); |
863 | if (!block) | 866 | if (!block) |
864 | return; | 867 | return; |
865 | read_block(block, blk); | 868 | read_block(block, blk); |
866 | for (i=0 ; i < (BLOCK_SIZE>>1) ; i++) | 869 | for (i = 0; i < (BLOCK_SIZE >> 1); i++) |
867 | add_zone_ind(i + (unsigned short *) blk, &blk_chg); | 870 | add_zone_ind(i + (unsigned short *) blk, &blk_chg); |
868 | if (blk_chg) | 871 | if (blk_chg) |
869 | write_block(block, blk); | 872 | write_block(block, blk); |
870 | } | 873 | } |
871 | 874 | ||
872 | #ifdef HAVE_MINIX2 | 875 | #ifdef HAVE_MINIX2 |
873 | static void | 876 | static void add_zone_dind2(unsigned int *znr, int *corrected) |
874 | add_zone_dind2 (unsigned int *znr, int *corrected) | ||
875 | { | 877 | { |
876 | static char blk[BLOCK_SIZE]; | 878 | static char blk[BLOCK_SIZE]; |
877 | int i, blk_chg = 0; | 879 | int i, blk_chg = 0; |
878 | int block; | 880 | int block; |
879 | 881 | ||
880 | block = add_zone2 (znr, corrected); | 882 | block = add_zone2(znr, corrected); |
881 | if (!block) | 883 | if (!block) |
882 | return; | 884 | return; |
883 | read_block (block, blk); | 885 | read_block(block, blk); |
884 | for (i = 0; i < BLOCK_SIZE >> 2; i++) | 886 | for (i = 0; i < BLOCK_SIZE >> 2; i++) |
885 | add_zone_ind2 (i + (unsigned int *) blk, &blk_chg); | 887 | add_zone_ind2(i + (unsigned int *) blk, &blk_chg); |
886 | if (blk_chg) | 888 | if (blk_chg) |
887 | write_block (block, blk); | 889 | write_block(block, blk); |
888 | } | 890 | } |
889 | 891 | ||
890 | static void | 892 | static void add_zone_tind2(unsigned int *znr, int *corrected) |
891 | add_zone_tind2 (unsigned int *znr, int *corrected) | ||
892 | { | 893 | { |
893 | static char blk[BLOCK_SIZE]; | 894 | static char blk[BLOCK_SIZE]; |
894 | int i, blk_chg = 0; | 895 | int i, blk_chg = 0; |
895 | int block; | 896 | int block; |
896 | 897 | ||
897 | block = add_zone2 (znr, corrected); | 898 | block = add_zone2(znr, corrected); |
898 | if (!block) | 899 | if (!block) |
899 | return; | 900 | return; |
900 | read_block (block, blk); | 901 | read_block(block, blk); |
901 | for (i = 0; i < BLOCK_SIZE >> 2; i++) | 902 | for (i = 0; i < BLOCK_SIZE >> 2; i++) |
902 | add_zone_dind2 (i + (unsigned int *) blk, &blk_chg); | 903 | add_zone_dind2(i + (unsigned int *) blk, &blk_chg); |
903 | if (blk_chg) | 904 | if (blk_chg) |
904 | write_block (block, blk); | 905 | write_block(block, blk); |
905 | } | 906 | } |
906 | #endif | 907 | #endif |
907 | 908 | ||
908 | static void check_zones(unsigned int i) | 909 | static void check_zones(unsigned int i) |
909 | { | 910 | { |
910 | struct minix_inode * inode; | 911 | struct minix_inode *inode; |
911 | 912 | ||
912 | if (!i || i > INODES) | 913 | if (!i || i > INODES) |
913 | return; | 914 | return; |
914 | if (inode_count[i] > 1) /* have we counted this file already? */ | 915 | if (inode_count[i] > 1) /* have we counted this file already? */ |
915 | return; | 916 | return; |
916 | inode = Inode + i; | 917 | inode = Inode + i; |
917 | if (!S_ISDIR(inode->i_mode) && !S_ISREG(inode->i_mode) && | 918 | if (!S_ISDIR(inode->i_mode) && !S_ISREG(inode->i_mode) && |
918 | !S_ISLNK(inode->i_mode)) | 919 | !S_ISLNK(inode->i_mode)) return; |
919 | return; | 920 | for (i = 0; i < 7; i++) |
920 | for (i=0 ; i<7 ; i++) | ||
921 | add_zone(i + inode->i_zone, &changed); | 921 | add_zone(i + inode->i_zone, &changed); |
922 | add_zone_ind(7 + inode->i_zone, &changed); | 922 | add_zone_ind(7 + inode->i_zone, &changed); |
923 | add_zone_dind(8 + inode->i_zone, &changed); | 923 | add_zone_dind(8 + inode->i_zone, &changed); |
924 | } | 924 | } |
925 | 925 | ||
926 | #ifdef HAVE_MINIX2 | 926 | #ifdef HAVE_MINIX2 |
927 | static void | 927 | static void check_zones2(unsigned int i) |
928 | check_zones2 (unsigned int i) | ||
929 | { | 928 | { |
930 | struct minix2_inode *inode; | 929 | struct minix2_inode *inode; |
931 | 930 | ||
932 | if (!i || i > INODES) | 931 | if (!i || i > INODES) |
933 | return; | 932 | return; |
934 | if (inode_count[i] > 1) /* have we counted this file already? */ | 933 | if (inode_count[i] > 1) /* have we counted this file already? */ |
935 | return; | 934 | return; |
936 | inode = Inode2 + i; | 935 | inode = Inode2 + i; |
937 | if (!S_ISDIR (inode->i_mode) && !S_ISREG (inode->i_mode) | 936 | if (!S_ISDIR(inode->i_mode) && !S_ISREG(inode->i_mode) |
938 | && !S_ISLNK (inode->i_mode)) | 937 | && !S_ISLNK(inode->i_mode)) |
939 | return; | 938 | return; |
940 | for (i = 0; i < 7; i++) | 939 | for (i = 0; i < 7; i++) |
941 | add_zone2 (i + inode->i_zone, &changed); | 940 | add_zone2(i + inode->i_zone, &changed); |
942 | add_zone_ind2 (7 + inode->i_zone, &changed); | 941 | add_zone_ind2(7 + inode->i_zone, &changed); |
943 | add_zone_dind2 (8 + inode->i_zone, &changed); | 942 | add_zone_dind2(8 + inode->i_zone, &changed); |
944 | add_zone_tind2 (9 + inode->i_zone, &changed); | 943 | add_zone_tind2(9 + inode->i_zone, &changed); |
945 | } | 944 | } |
946 | #endif | 945 | #endif |
947 | 946 | ||
948 | static void check_file(struct minix_inode * dir, unsigned int offset) | 947 | static void check_file(struct minix_inode *dir, unsigned int offset) |
949 | { | 948 | { |
950 | static char blk[BLOCK_SIZE]; | 949 | static char blk[BLOCK_SIZE]; |
951 | struct minix_inode * inode; | 950 | struct minix_inode *inode; |
952 | int ino; | 951 | int ino; |
953 | char * name; | 952 | char *name; |
954 | int block; | 953 | int block; |
955 | 954 | ||
956 | block = map_block(dir,offset/BLOCK_SIZE); | 955 | block = map_block(dir, offset / BLOCK_SIZE); |
957 | read_block(block, blk); | 956 | read_block(block, blk); |
958 | name = blk + (offset % BLOCK_SIZE) + 2; | 957 | name = blk + (offset % BLOCK_SIZE) + 2; |
959 | ino = * (unsigned short *) (name-2); | 958 | ino = *(unsigned short *) (name - 2); |
960 | if (ino > INODES) { | 959 | if (ino > INODES) { |
961 | print_current_name(); | 960 | print_current_name(); |
962 | printf(" contains a bad inode number for file '"); | 961 | printf(" contains a bad inode number for file '"); |
963 | printf("%.*s'.",namelen,name); | 962 | printf("%.*s'.", namelen, name); |
964 | if (ask(" Remove",1)) { | 963 | if (ask(" Remove", 1)) { |
965 | *(unsigned short *)(name-2) = 0; | 964 | *(unsigned short *) (name - 2) = 0; |
966 | write_block(block, blk); | 965 | write_block(block, blk); |
967 | } | 966 | } |
968 | ino = 0; | 967 | ino = 0; |
969 | } | 968 | } |
970 | if (name_depth < MAX_DEPTH) | 969 | if (name_depth < MAX_DEPTH) |
971 | strncpy (name_list[name_depth], name, namelen); | 970 | strncpy(name_list[name_depth], name, namelen); |
972 | name_depth++; | 971 | name_depth++; |
973 | inode = get_inode(ino); | 972 | inode = get_inode(ino); |
974 | name_depth--; | 973 | name_depth--; |
975 | if (!offset) { | 974 | if (!offset) { |
976 | if (!inode || strcmp(".",name)) { | 975 | if (!inode || strcmp(".", name)) { |
977 | print_current_name(); | 976 | print_current_name(); |
978 | printf(": bad directory: '.' isn't first\n"); | 977 | printf(": bad directory: '.' isn't first\n"); |
979 | errors_uncorrected = 1; | 978 | errors_uncorrected = 1; |
980 | } else return; | 979 | } else |
980 | return; | ||
981 | } | 981 | } |
982 | if (offset == dirsize) { | 982 | if (offset == dirsize) { |
983 | if (!inode || strcmp("..",name)) { | 983 | if (!inode || strcmp("..", name)) { |
984 | print_current_name(); | 984 | print_current_name(); |
985 | printf(": bad directory: '..' isn't second\n"); | 985 | printf(": bad directory: '..' isn't second\n"); |
986 | errors_uncorrected = 1; | 986 | errors_uncorrected = 1; |
987 | } else return; | 987 | } else |
988 | return; | ||
988 | } | 989 | } |
989 | if (!inode) | 990 | if (!inode) |
990 | return; | 991 | return; |
991 | if (name_depth < MAX_DEPTH) | 992 | if (name_depth < MAX_DEPTH) |
992 | strncpy(name_list[name_depth],name,namelen); | 993 | strncpy(name_list[name_depth], name, namelen); |
993 | name_depth++; | 994 | name_depth++; |
994 | if (list) { | 995 | if (list) { |
995 | if (verbose) | 996 | if (verbose) |
996 | printf("%6d %07o %3d ",ino,inode->i_mode,inode->i_nlinks); | 997 | printf("%6d %07o %3d ", ino, inode->i_mode, inode->i_nlinks); |
997 | print_current_name(); | 998 | print_current_name(); |
998 | if (S_ISDIR(inode->i_mode)) | 999 | if (S_ISDIR(inode->i_mode)) |
999 | printf(":\n"); | 1000 | printf(":\n"); |
@@ -1008,8 +1009,7 @@ static void check_file(struct minix_inode * dir, unsigned int offset) | |||
1008 | } | 1009 | } |
1009 | 1010 | ||
1010 | #ifdef HAVE_MINIX2 | 1011 | #ifdef HAVE_MINIX2 |
1011 | static void | 1012 | static void check_file2(struct minix2_inode *dir, unsigned int offset) |
1012 | check_file2 (struct minix2_inode *dir, unsigned int offset) | ||
1013 | { | 1013 | { |
1014 | static char blk[BLOCK_SIZE]; | 1014 | static char blk[BLOCK_SIZE]; |
1015 | struct minix2_inode *inode; | 1015 | struct minix2_inode *inode; |
@@ -1017,37 +1017,37 @@ check_file2 (struct minix2_inode *dir, unsigned int offset) | |||
1017 | char *name; | 1017 | char *name; |
1018 | int block; | 1018 | int block; |
1019 | 1019 | ||
1020 | block = map_block2 (dir, offset / BLOCK_SIZE); | 1020 | block = map_block2(dir, offset / BLOCK_SIZE); |
1021 | read_block (block, blk); | 1021 | read_block(block, blk); |
1022 | name = blk + (offset % BLOCK_SIZE) + 2; | 1022 | name = blk + (offset % BLOCK_SIZE) + 2; |
1023 | ino = *(unsigned short *) (name - 2); | 1023 | ino = *(unsigned short *) (name - 2); |
1024 | if (ino > INODES) { | 1024 | if (ino > INODES) { |
1025 | print_current_name (); | 1025 | print_current_name(); |
1026 | printf (" contains a bad inode number for file '"); | 1026 | printf(" contains a bad inode number for file '"); |
1027 | printf ("%.*s'.", namelen, name); | 1027 | printf("%.*s'.", namelen, name); |
1028 | if (ask (" Remove", 1)) { | 1028 | if (ask(" Remove", 1)) { |
1029 | *(unsigned short *) (name - 2) = 0; | 1029 | *(unsigned short *) (name - 2) = 0; |
1030 | write_block (block, blk); | 1030 | write_block(block, blk); |
1031 | } | 1031 | } |
1032 | ino = 0; | 1032 | ino = 0; |
1033 | } | 1033 | } |
1034 | if (name_depth < MAX_DEPTH) | 1034 | if (name_depth < MAX_DEPTH) |
1035 | strncpy (name_list[name_depth], name, namelen); | 1035 | strncpy(name_list[name_depth], name, namelen); |
1036 | name_depth++; | 1036 | name_depth++; |
1037 | inode = get_inode2 (ino); | 1037 | inode = get_inode2(ino); |
1038 | name_depth--; | 1038 | name_depth--; |
1039 | if (!offset) { | 1039 | if (!offset) { |
1040 | if (!inode || strcmp (".", name)) { | 1040 | if (!inode || strcmp(".", name)) { |
1041 | print_current_name (); | 1041 | print_current_name(); |
1042 | printf (": bad directory: '.' isn't first\n"); | 1042 | printf(": bad directory: '.' isn't first\n"); |
1043 | errors_uncorrected = 1; | 1043 | errors_uncorrected = 1; |
1044 | } else | 1044 | } else |
1045 | return; | 1045 | return; |
1046 | } | 1046 | } |
1047 | if (offset == dirsize) { | 1047 | if (offset == dirsize) { |
1048 | if (!inode || strcmp ("..", name)) { | 1048 | if (!inode || strcmp("..", name)) { |
1049 | print_current_name (); | 1049 | print_current_name(); |
1050 | printf (": bad directory: '..' isn't second\n"); | 1050 | printf(": bad directory: '..' isn't second\n"); |
1051 | errors_uncorrected = 1; | 1051 | errors_uncorrected = 1; |
1052 | } else | 1052 | } else |
1053 | return; | 1053 | return; |
@@ -1057,16 +1057,16 @@ check_file2 (struct minix2_inode *dir, unsigned int offset) | |||
1057 | name_depth++; | 1057 | name_depth++; |
1058 | if (list) { | 1058 | if (list) { |
1059 | if (verbose) | 1059 | if (verbose) |
1060 | printf ("%6d %07o %3d ", ino, inode->i_mode, inode->i_nlinks); | 1060 | printf("%6d %07o %3d ", ino, inode->i_mode, inode->i_nlinks); |
1061 | print_current_name (); | 1061 | print_current_name(); |
1062 | if (S_ISDIR (inode->i_mode)) | 1062 | if (S_ISDIR(inode->i_mode)) |
1063 | printf (":\n"); | 1063 | printf(":\n"); |
1064 | else | 1064 | else |
1065 | printf ("\n"); | 1065 | printf("\n"); |
1066 | } | 1066 | } |
1067 | check_zones2 (ino); | 1067 | check_zones2(ino); |
1068 | if (inode && S_ISDIR (inode->i_mode)) | 1068 | if (inode && S_ISDIR(inode->i_mode)) |
1069 | recursive_check2 (ino); | 1069 | recursive_check2(ino); |
1070 | name_depth--; | 1070 | name_depth--; |
1071 | return; | 1071 | return; |
1072 | } | 1072 | } |
@@ -1074,7 +1074,7 @@ check_file2 (struct minix2_inode *dir, unsigned int offset) | |||
1074 | 1074 | ||
1075 | static void recursive_check(unsigned int ino) | 1075 | static void recursive_check(unsigned int ino) |
1076 | { | 1076 | { |
1077 | struct minix_inode * dir; | 1077 | struct minix_inode *dir; |
1078 | unsigned int offset; | 1078 | unsigned int offset; |
1079 | 1079 | ||
1080 | dir = Inode + ino; | 1080 | dir = Inode + ino; |
@@ -1085,27 +1085,26 @@ static void recursive_check(unsigned int ino) | |||
1085 | printf(": bad directory: size<32"); | 1085 | printf(": bad directory: size<32"); |
1086 | errors_uncorrected = 1; | 1086 | errors_uncorrected = 1; |
1087 | } | 1087 | } |
1088 | for (offset = 0 ; offset < dir->i_size ; offset += dirsize) | 1088 | for (offset = 0; offset < dir->i_size; offset += dirsize) |
1089 | check_file(dir,offset); | 1089 | check_file(dir, offset); |
1090 | } | 1090 | } |
1091 | 1091 | ||
1092 | #ifdef HAVE_MINIX2 | 1092 | #ifdef HAVE_MINIX2 |
1093 | static void | 1093 | static void recursive_check2(unsigned int ino) |
1094 | recursive_check2 (unsigned int ino) | ||
1095 | { | 1094 | { |
1096 | struct minix2_inode *dir; | 1095 | struct minix2_inode *dir; |
1097 | unsigned int offset; | 1096 | unsigned int offset; |
1098 | 1097 | ||
1099 | dir = Inode2 + ino; | 1098 | dir = Inode2 + ino; |
1100 | if (!S_ISDIR (dir->i_mode)) | 1099 | if (!S_ISDIR(dir->i_mode)) |
1101 | die ("internal error"); | 1100 | die("internal error"); |
1102 | if (dir->i_size < 2 * dirsize) { | 1101 | if (dir->i_size < 2 * dirsize) { |
1103 | print_current_name (); | 1102 | print_current_name(); |
1104 | printf (": bad directory: size < 32"); | 1103 | printf(": bad directory: size < 32"); |
1105 | errors_uncorrected = 1; | 1104 | errors_uncorrected = 1; |
1106 | } | 1105 | } |
1107 | for (offset = 0; offset < dir->i_size; offset += dirsize) | 1106 | for (offset = 0; offset < dir->i_size; offset += dirsize) |
1108 | check_file2 (dir, offset); | 1107 | check_file2(dir, offset); |
1109 | } | 1108 | } |
1110 | #endif | 1109 | #endif |
1111 | 1110 | ||
@@ -1113,7 +1112,7 @@ static int bad_zone(int i) | |||
1113 | { | 1112 | { |
1114 | char buffer[1024]; | 1113 | char buffer[1024]; |
1115 | 1114 | ||
1116 | if (BLOCK_SIZE*i != lseek(IN, BLOCK_SIZE*i, SEEK_SET)) | 1115 | if (BLOCK_SIZE * i != lseek(IN, BLOCK_SIZE * i, SEEK_SET)) |
1117 | die("seek failed in bad_zone"); | 1116 | die("seek failed in bad_zone"); |
1118 | return (BLOCK_SIZE != read(IN, buffer, BLOCK_SIZE)); | 1117 | return (BLOCK_SIZE != read(IN, buffer, BLOCK_SIZE)); |
1119 | } | 1118 | } |
@@ -1122,10 +1121,10 @@ static void check_counts(void) | |||
1122 | { | 1121 | { |
1123 | int i; | 1122 | int i; |
1124 | 1123 | ||
1125 | for (i=1 ; i <= INODES ; i++) { | 1124 | for (i = 1; i <= INODES; i++) { |
1126 | if (!inode_in_use(i) && Inode[i].i_mode && warn_mode) { | 1125 | if (!inode_in_use(i) && Inode[i].i_mode && warn_mode) { |
1127 | printf("Inode %d mode not cleared.",i); | 1126 | printf("Inode %d mode not cleared.", i); |
1128 | if (ask("Clear",1)) { | 1127 | if (ask("Clear", 1)) { |
1129 | Inode[i].i_mode = 0; | 1128 | Inode[i].i_mode = 0; |
1130 | changed = 1; | 1129 | changed = 1; |
1131 | } | 1130 | } |
@@ -1133,117 +1132,115 @@ static void check_counts(void) | |||
1133 | if (!inode_count[i]) { | 1132 | if (!inode_count[i]) { |
1134 | if (!inode_in_use(i)) | 1133 | if (!inode_in_use(i)) |
1135 | continue; | 1134 | continue; |
1136 | printf("Inode %d not used, marked used in the bitmap.",i); | 1135 | printf("Inode %d not used, marked used in the bitmap.", i); |
1137 | if (ask("Clear",1)) | 1136 | if (ask("Clear", 1)) |
1138 | unmark_inode(i); | 1137 | unmark_inode(i); |
1139 | continue; | 1138 | continue; |
1140 | } | 1139 | } |
1141 | if (!inode_in_use(i)) { | 1140 | if (!inode_in_use(i)) { |
1142 | printf("Inode %d used, marked unused in the bitmap.", i); | 1141 | printf("Inode %d used, marked unused in the bitmap.", i); |
1143 | if (ask("Set",1)) | 1142 | if (ask("Set", 1)) |
1144 | mark_inode(i); | 1143 | mark_inode(i); |
1145 | } | 1144 | } |
1146 | if (Inode[i].i_nlinks != inode_count[i]) { | 1145 | if (Inode[i].i_nlinks != inode_count[i]) { |
1147 | printf("Inode %d (mode = %07o), i_nlinks=%d, counted=%d.", | 1146 | printf("Inode %d (mode = %07o), i_nlinks=%d, counted=%d.", |
1148 | i,Inode[i].i_mode,Inode[i].i_nlinks,inode_count[i]); | 1147 | i, Inode[i].i_mode, Inode[i].i_nlinks, inode_count[i]); |
1149 | if (ask("Set i_nlinks to count",1)) { | 1148 | if (ask("Set i_nlinks to count", 1)) { |
1150 | Inode[i].i_nlinks=inode_count[i]; | 1149 | Inode[i].i_nlinks = inode_count[i]; |
1151 | changed=1; | 1150 | changed = 1; |
1152 | } | 1151 | } |
1153 | } | 1152 | } |
1154 | } | 1153 | } |
1155 | for (i=FIRSTZONE ; i < ZONES ; i++) { | 1154 | for (i = FIRSTZONE; i < ZONES; i++) { |
1156 | if (zone_in_use(i) == zone_count[i]) | 1155 | if (zone_in_use(i) == zone_count[i]) |
1157 | continue; | 1156 | continue; |
1158 | if (!zone_count[i]) { | 1157 | if (!zone_count[i]) { |
1159 | if (bad_zone(i)) | 1158 | if (bad_zone(i)) |
1160 | continue; | 1159 | continue; |
1161 | printf("Zone %d: marked in use, no file uses it.",i); | 1160 | printf("Zone %d: marked in use, no file uses it.", i); |
1162 | if (ask("Unmark",1)) | 1161 | if (ask("Unmark", 1)) |
1163 | unmark_zone(i); | 1162 | unmark_zone(i); |
1164 | continue; | 1163 | continue; |
1165 | } | 1164 | } |
1166 | printf("Zone %d: %sin use, counted=%d\n", | 1165 | printf("Zone %d: %sin use, counted=%d\n", |
1167 | i,zone_in_use(i)?"":"not ",zone_count[i]); | 1166 | i, zone_in_use(i) ? "" : "not ", zone_count[i]); |
1168 | } | 1167 | } |
1169 | } | 1168 | } |
1170 | 1169 | ||
1171 | #ifdef HAVE_MINIX2 | 1170 | #ifdef HAVE_MINIX2 |
1172 | static void | 1171 | static void check_counts2(void) |
1173 | check_counts2 (void) | ||
1174 | { | 1172 | { |
1175 | int i; | 1173 | int i; |
1176 | 1174 | ||
1177 | for (i = 1; i <= INODES; i++) { | 1175 | for (i = 1; i <= INODES; i++) { |
1178 | if (!inode_in_use (i) && Inode2[i].i_mode && warn_mode) { | 1176 | if (!inode_in_use(i) && Inode2[i].i_mode && warn_mode) { |
1179 | printf ("Inode %d mode not cleared.", i); | 1177 | printf("Inode %d mode not cleared.", i); |
1180 | if (ask ("Clear", 1)) { | 1178 | if (ask("Clear", 1)) { |
1181 | Inode2[i].i_mode = 0; | 1179 | Inode2[i].i_mode = 0; |
1182 | changed = 1; | 1180 | changed = 1; |
1183 | } | 1181 | } |
1184 | } | 1182 | } |
1185 | if (!inode_count[i]) { | 1183 | if (!inode_count[i]) { |
1186 | if (!inode_in_use (i)) | 1184 | if (!inode_in_use(i)) |
1187 | continue; | 1185 | continue; |
1188 | printf ("Inode %d not used, marked used in the bitmap.", i); | 1186 | printf("Inode %d not used, marked used in the bitmap.", i); |
1189 | if (ask ("Clear", 1)) | 1187 | if (ask("Clear", 1)) |
1190 | unmark_inode (i); | 1188 | unmark_inode(i); |
1191 | continue; | 1189 | continue; |
1192 | } | 1190 | } |
1193 | if (!inode_in_use (i)) { | 1191 | if (!inode_in_use(i)) { |
1194 | printf ("Inode %d used, marked unused in the bitmap.", i); | 1192 | printf("Inode %d used, marked unused in the bitmap.", i); |
1195 | if (ask ("Set", 1)) | 1193 | if (ask("Set", 1)) |
1196 | mark_inode (i); | 1194 | mark_inode(i); |
1197 | } | 1195 | } |
1198 | if (Inode2[i].i_nlinks != inode_count[i]) { | 1196 | if (Inode2[i].i_nlinks != inode_count[i]) { |
1199 | printf ("Inode %d (mode = %07o), i_nlinks=%d, counted=%d.", | 1197 | printf("Inode %d (mode = %07o), i_nlinks=%d, counted=%d.", |
1200 | i, Inode2[i].i_mode, Inode2[i].i_nlinks, inode_count[i]); | 1198 | i, Inode2[i].i_mode, Inode2[i].i_nlinks, |
1201 | if (ask ("Set i_nlinks to count", 1)) { | 1199 | inode_count[i]); |
1200 | if (ask("Set i_nlinks to count", 1)) { | ||
1202 | Inode2[i].i_nlinks = inode_count[i]; | 1201 | Inode2[i].i_nlinks = inode_count[i]; |
1203 | changed = 1; | 1202 | changed = 1; |
1204 | } | 1203 | } |
1205 | } | 1204 | } |
1206 | } | 1205 | } |
1207 | for (i = FIRSTZONE; i < ZONES; i++) { | 1206 | for (i = FIRSTZONE; i < ZONES; i++) { |
1208 | if (zone_in_use (i) == zone_count[i]) | 1207 | if (zone_in_use(i) == zone_count[i]) |
1209 | continue; | 1208 | continue; |
1210 | if (!zone_count[i]) { | 1209 | if (!zone_count[i]) { |
1211 | if (bad_zone (i)) | 1210 | if (bad_zone(i)) |
1212 | continue; | 1211 | continue; |
1213 | printf ("Zone %d: marked in use, no file uses it.", i); | 1212 | printf("Zone %d: marked in use, no file uses it.", i); |
1214 | if (ask ("Unmark", 1)) | 1213 | if (ask("Unmark", 1)) |
1215 | unmark_zone (i); | 1214 | unmark_zone(i); |
1216 | continue; | 1215 | continue; |
1217 | } | 1216 | } |
1218 | printf ("Zone %d: %sin use, counted=%d\n", | 1217 | printf("Zone %d: %sin use, counted=%d\n", |
1219 | i, zone_in_use (i) ? "" : "not ", zone_count[i]); | 1218 | i, zone_in_use(i) ? "" : "not ", zone_count[i]); |
1220 | } | 1219 | } |
1221 | } | 1220 | } |
1222 | #endif | 1221 | #endif |
1223 | 1222 | ||
1224 | static void check(void) | 1223 | static void check(void) |
1225 | { | 1224 | { |
1226 | memset(inode_count,0,(INODES + 1) * sizeof(*inode_count)); | 1225 | memset(inode_count, 0, (INODES + 1) * sizeof(*inode_count)); |
1227 | memset(zone_count,0,ZONES*sizeof(*zone_count)); | 1226 | memset(zone_count, 0, ZONES * sizeof(*zone_count)); |
1228 | check_zones(ROOT_INO); | 1227 | check_zones(ROOT_INO); |
1229 | recursive_check(ROOT_INO); | 1228 | recursive_check(ROOT_INO); |
1230 | check_counts(); | 1229 | check_counts(); |
1231 | } | 1230 | } |
1232 | 1231 | ||
1233 | #ifdef HAVE_MINIX2 | 1232 | #ifdef HAVE_MINIX2 |
1234 | static void | 1233 | static void check2(void) |
1235 | check2 (void) | ||
1236 | { | 1234 | { |
1237 | memset (inode_count, 0, (INODES + 1) * sizeof (*inode_count)); | 1235 | memset(inode_count, 0, (INODES + 1) * sizeof(*inode_count)); |
1238 | memset (zone_count, 0, ZONES * sizeof (*zone_count)); | 1236 | memset(zone_count, 0, ZONES * sizeof(*zone_count)); |
1239 | check_zones2 (ROOT_INO); | 1237 | check_zones2(ROOT_INO); |
1240 | recursive_check2 (ROOT_INO); | 1238 | recursive_check2(ROOT_INO); |
1241 | check_counts2 (); | 1239 | check_counts2(); |
1242 | } | 1240 | } |
1243 | #endif | 1241 | #endif |
1244 | 1242 | ||
1245 | extern int | 1243 | extern int fsck_minix_main(int argc, char **argv) |
1246 | fsck_minix_main(int argc, char ** argv) | ||
1247 | { | 1244 | { |
1248 | struct termios tmp; | 1245 | struct termios tmp; |
1249 | int count; | 1246 | int count; |
@@ -1264,29 +1261,47 @@ fsck_minix_main(int argc, char ** argv) | |||
1264 | show_usage(); | 1261 | show_usage(); |
1265 | else | 1262 | else |
1266 | device_name = argv[0]; | 1263 | device_name = argv[0]; |
1267 | } else while (*++argv[0]) | 1264 | } else |
1268 | switch (argv[0][0]) { | 1265 | while (*++argv[0]) |
1269 | case 'l': list=1; break; | 1266 | switch (argv[0][0]) { |
1270 | case 'a': automatic=1; repair=1; break; | 1267 | case 'l': |
1271 | case 'r': automatic=0; repair=1; break; | 1268 | list = 1; |
1272 | case 'v': verbose=1; break; | 1269 | break; |
1273 | case 's': show=1; break; | 1270 | case 'a': |
1274 | case 'm': warn_mode=1; break; | 1271 | automatic = 1; |
1275 | case 'f': force=1; break; | 1272 | repair = 1; |
1276 | default: show_usage(); | 1273 | break; |
1277 | } | 1274 | case 'r': |
1275 | automatic = 0; | ||
1276 | repair = 1; | ||
1277 | break; | ||
1278 | case 'v': | ||
1279 | verbose = 1; | ||
1280 | break; | ||
1281 | case 's': | ||
1282 | show = 1; | ||
1283 | break; | ||
1284 | case 'm': | ||
1285 | warn_mode = 1; | ||
1286 | break; | ||
1287 | case 'f': | ||
1288 | force = 1; | ||
1289 | break; | ||
1290 | default: | ||
1291 | show_usage(); | ||
1292 | } | ||
1278 | } | 1293 | } |
1279 | if (!device_name) | 1294 | if (!device_name) |
1280 | show_usage(); | 1295 | show_usage(); |
1281 | check_mount(); /* trying to check a mounted filesystem? */ | 1296 | check_mount(); /* trying to check a mounted filesystem? */ |
1282 | if (repair && !automatic) { | 1297 | if (repair && !automatic) { |
1283 | if (!isatty(0) || !isatty(1)) | 1298 | if (!isatty(0) || !isatty(1)) |
1284 | die("need terminal for interactive repairs"); | 1299 | die("need terminal for interactive repairs"); |
1285 | } | 1300 | } |
1286 | IN = open(device_name,repair?O_RDWR:O_RDONLY); | 1301 | IN = open(device_name, repair ? O_RDWR : O_RDONLY); |
1287 | if (IN < 0) | 1302 | if (IN < 0) |
1288 | die("unable to open '%s'"); | 1303 | die("unable to open '%s'"); |
1289 | for (count=0 ; count<3 ; count++) | 1304 | for (count = 0; count < 3; count++) |
1290 | sync(); | 1305 | sync(); |
1291 | read_superblock(); | 1306 | read_superblock(); |
1292 | 1307 | ||
@@ -1297,80 +1312,77 @@ fsck_minix_main(int argc, char ** argv) | |||
1297 | * command line. | 1312 | * command line. |
1298 | */ | 1313 | */ |
1299 | printf("%s, %s\n", program_name, program_version); | 1314 | printf("%s, %s\n", program_name, program_version); |
1300 | if ( !(Super.s_state & MINIX_ERROR_FS) && | 1315 | if (!(Super.s_state & MINIX_ERROR_FS) && |
1301 | (Super.s_state & MINIX_VALID_FS) && | 1316 | (Super.s_state & MINIX_VALID_FS) && !force) { |
1302 | !force ) { | ||
1303 | if (repair) | 1317 | if (repair) |
1304 | printf("%s is clean, no check.\n", device_name); | 1318 | printf("%s is clean, no check.\n", device_name); |
1305 | return retcode; | 1319 | return retcode; |
1306 | } | 1320 | } else if (force) |
1307 | else if (force) | ||
1308 | printf("Forcing filesystem check on %s.\n", device_name); | 1321 | printf("Forcing filesystem check on %s.\n", device_name); |
1309 | else if (repair) | 1322 | else if (repair) |
1310 | printf("Filesystem on %s is dirty, needs checking.\n",\ | 1323 | printf("Filesystem on %s is dirty, needs checking.\n", |
1311 | device_name); | 1324 | device_name); |
1312 | 1325 | ||
1313 | read_tables(); | 1326 | read_tables(); |
1314 | 1327 | ||
1315 | if (repair && !automatic) { | 1328 | if (repair && !automatic) { |
1316 | tcgetattr(0,&termios); | 1329 | tcgetattr(0, &termios); |
1317 | tmp = termios; | 1330 | tmp = termios; |
1318 | tmp.c_lflag &= ~(ICANON|ECHO); | 1331 | tmp.c_lflag &= ~(ICANON | ECHO); |
1319 | tcsetattr(0,TCSANOW,&tmp); | 1332 | tcsetattr(0, TCSANOW, &tmp); |
1320 | termios_set = 1; | 1333 | termios_set = 1; |
1321 | } | 1334 | } |
1322 | |||
1323 | #if HAVE_MINIX2 | 1335 | #if HAVE_MINIX2 |
1324 | if (version2) { | 1336 | if (version2) { |
1325 | check_root2 (); | 1337 | check_root2(); |
1326 | check2 (); | 1338 | check2(); |
1327 | } else | 1339 | } else |
1328 | #endif | 1340 | #endif |
1329 | { | 1341 | { |
1330 | check_root(); | 1342 | check_root(); |
1331 | check(); | 1343 | check(); |
1332 | } | 1344 | } |
1333 | if (verbose) { | 1345 | if (verbose) { |
1334 | int i, free; | 1346 | int i, free; |
1335 | 1347 | ||
1336 | for (i=1,free=0 ; i <= INODES ; i++) | 1348 | for (i = 1, free = 0; i <= INODES; i++) |
1337 | if (!inode_in_use(i)) | 1349 | if (!inode_in_use(i)) |
1338 | free++; | 1350 | free++; |
1339 | printf("\n%6ld inodes used (%ld%%)\n",(INODES-free), | 1351 | printf("\n%6ld inodes used (%ld%%)\n", (INODES - free), |
1340 | 100*(INODES-free)/INODES); | 1352 | 100 * (INODES - free) / INODES); |
1341 | for (i=FIRSTZONE,free=0 ; i < ZONES ; i++) | 1353 | for (i = FIRSTZONE, free = 0; i < ZONES; i++) |
1342 | if (!zone_in_use(i)) | 1354 | if (!zone_in_use(i)) |
1343 | free++; | 1355 | free++; |
1344 | printf("%6ld zones used (%ld%%)\n",(ZONES-free), | 1356 | printf("%6ld zones used (%ld%%)\n", (ZONES - free), |
1345 | 100*(ZONES-free)/ZONES); | 1357 | 100 * (ZONES - free) / ZONES); |
1346 | printf("\n%6d regular files\n" | 1358 | printf("\n%6d regular files\n" |
1347 | "%6d directories\n" | 1359 | "%6d directories\n" |
1348 | "%6d character device files\n" | 1360 | "%6d character device files\n" |
1349 | "%6d block device files\n" | 1361 | "%6d block device files\n" |
1350 | "%6d links\n" | 1362 | "%6d links\n" |
1351 | "%6d symbolic links\n" | 1363 | "%6d symbolic links\n" |
1352 | "------\n" | 1364 | "------\n" |
1353 | "%6d files\n", | 1365 | "%6d files\n", |
1354 | regular,directory,chardev,blockdev, | 1366 | regular, directory, chardev, blockdev, |
1355 | links-2*directory+1,symlinks,total-2*directory+1); | 1367 | links - 2 * directory + 1, symlinks, |
1368 | total - 2 * directory + 1); | ||
1356 | } | 1369 | } |
1357 | if (changed) { | 1370 | if (changed) { |
1358 | write_tables(); | 1371 | write_tables(); |
1359 | printf( "----------------------------\n" | 1372 | printf("----------------------------\n" |
1360 | "FILE SYSTEM HAS BEEN CHANGED\n" | 1373 | "FILE SYSTEM HAS BEEN CHANGED\n" |
1361 | "----------------------------\n"); | 1374 | "----------------------------\n"); |
1362 | for (count=0 ; count<3 ; count++) | 1375 | for (count = 0; count < 3; count++) |
1363 | sync(); | 1376 | sync(); |
1364 | } | 1377 | } else if (repair) |
1365 | else if ( repair ) | ||
1366 | write_super_block(); | 1378 | write_super_block(); |
1367 | 1379 | ||
1368 | if (repair && !automatic) | 1380 | if (repair && !automatic) |
1369 | tcsetattr(0,TCSANOW,&termios); | 1381 | tcsetattr(0, TCSANOW, &termios); |
1370 | 1382 | ||
1371 | if (changed) | 1383 | if (changed) |
1372 | retcode += 3; | 1384 | retcode += 3; |
1373 | if (errors_uncorrected) | 1385 | if (errors_uncorrected) |
1374 | retcode += 4; | 1386 | retcode += 4; |
1375 | return retcode; | 1387 | return retcode; |
1376 | } | 1388 | } |