Changeset 2725 in MondoRescue for branches/2.2.9/mindi-busybox/e2fsprogs/old_e2fsprogs/e2fsck.c
- Timestamp:
- Feb 25, 2011, 9:26:54 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2.2.9/mindi-busybox/e2fsprogs/old_e2fsprogs/e2fsck.c
r1765 r2725 27 27 * part of the ext2fs journaling system. 28 28 * 29 * Licensed under GPLv2 or later, see file License in this tarball for details. 30 */ 31 32 #ifndef _GNU_SOURCE 33 #define _GNU_SOURCE 1 /* get strnlen() */ 34 #endif 29 * Licensed under GPLv2 or later, see file LICENSE in this source tree. 30 */ 35 31 36 32 #include "e2fsck.h" /*Put all of our defines here to clean things up*/ … … 90 86 struct problem_context { 91 87 errcode_t errcode; 92 ext2_ino_t ino, ino2, dir;88 ext2_ino_t ino, ino2, dir; 93 89 struct ext2_inode *inode; 94 90 struct ext2_dir_entry *dirent; 95 blk_t blk, blk2;91 blk_t blk, blk2; 96 92 e2_blkcnt_t blkcount; 97 93 int group; 98 __u64 num;99 const char *str;94 __u64 num; 95 const char *str; 100 96 }; 101 97 … … 134 130 135 131 typedef struct dnode_t { 136 137 138 139 140 141 132 struct dnode_t *dict_left; 133 struct dnode_t *dict_right; 134 struct dnode_t *dict_parent; 135 dnode_color_t dict_color; 136 const void *dict_key; 137 void *dict_data; 142 138 } dnode_t; 143 139 … … 146 142 147 143 typedef struct dict_t { 148 149 150 151 152 153 144 dnode_t dict_nilnode; 145 dictcount_t dict_nodecount; 146 dictcount_t dict_maxcount; 147 dict_comp_t dict_compare; 148 dnode_free_t dict_freenode; 149 int dict_dupes; 154 150 } dict_t; 155 151 … … 157 153 158 154 typedef struct dict_load_t { 159 160 155 dict_t *dict_dictptr; 156 dnode_t dict_nilnode; 161 157 } dict_load_t; 162 158 … … 193 189 #define K_DEV_JOURNAL 2 194 190 195 #define lock_buffer(bh) do {} while (0)196 #define unlock_buffer(bh) do {} while (0)191 #define lock_buffer(bh) do {} while (0) 192 #define unlock_buffer(bh) do {} while (0) 197 193 #define buffer_req(bh) 1 198 #define do_readahead(journal, start) do {} while (0)194 #define do_readahead(journal, start) do {} while (0) 199 195 200 196 static e2fsck_t e2fsck_global_ctx; /* Try your very best not to use this! */ … … 215 211 kmem_cache_t *new_cache; 216 212 217 new_cache = malloc(sizeof(*new_cache)); 218 if (new_cache) 219 new_cache->object_length = len; 213 new_cache = xmalloc(sizeof(*new_cache)); 214 new_cache->object_length = len; 220 215 return new_cache; 221 216 } … … 270 265 static void rotate_left(dnode_t *upper) 271 266 { 272 273 274 275 276 277 278 279 280 281 282 283 284 upparent->left = lower;285 286 assert (upper == upparent->right);287 upparent->right = lower;288 289 290 291 267 dnode_t *lower, *lowleft, *upparent; 268 269 lower = upper->right; 270 upper->right = lowleft = lower->left; 271 lowleft->parent = upper; 272 273 lower->parent = upparent = upper->parent; 274 275 /* don't need to check for root node here because root->parent is 276 the sentinel nil node, and root->parent->left points back to root */ 277 278 if (upper == upparent->left) { 279 upparent->left = lower; 280 } else { 281 assert (upper == upparent->right); 282 upparent->right = lower; 283 } 284 285 lower->left = upper; 286 upper->parent = lower; 292 287 } 293 288 … … 299 294 static void rotate_right(dnode_t *upper) 300 295 { 301 302 303 304 305 306 307 308 309 310 upparent->right = lower;311 312 assert (upper == upparent->left);313 upparent->left = lower;314 315 316 317 296 dnode_t *lower, *lowright, *upparent; 297 298 lower = upper->left; 299 upper->left = lowright = lower->right; 300 lowright->parent = upper; 301 302 lower->parent = upparent = upper->parent; 303 304 if (upper == upparent->right) { 305 upparent->right = lower; 306 } else { 307 assert (upper == upparent->left); 308 upparent->left = lower; 309 } 310 311 lower->right = upper; 312 upper->parent = lower; 318 313 } 319 314 … … 325 320 static void free_nodes(dict_t *dict, dnode_t *node, dnode_t *nil) 326 321 { 327 328 return;329 330 331 322 if (node == nil) 323 return; 324 free_nodes(dict, node->left, nil); 325 free_nodes(dict, node->right, nil); 326 dict->dict_freenode(node); 332 327 } 333 328 … … 341 336 static int verify_dict_has_node(dnode_t *nil, dnode_t *root, dnode_t *node) 342 337 { 343 344 return root == node345 || verify_dict_has_node(nil, root->left, node)346 || verify_dict_has_node(nil, root->right, node);347 348 338 if (root != nil) { 339 return root == node 340 || verify_dict_has_node(nil, root->left, node) 341 || verify_dict_has_node(nil, root->right, node); 342 } 343 return 0; 349 344 } 350 345 … … 356 351 static void dict_set_allocator(dict_t *dict, dnode_free_t fr) 357 352 { 358 assert(dict_count(dict) == 0);359 353 assert(dict_count(dict) == 0); 354 dict->dict_freenode = fr; 360 355 } 361 356 … … 367 362 static void dict_free_nodes(dict_t *dict) 368 363 { 369 370 371 372 373 364 dnode_t *nil = dict_nil(dict), *root = dict_root(dict); 365 free_nodes(dict, root, nil); 366 dict->dict_nodecount = 0; 367 dict->nilnode.left = &dict->nilnode; 368 dict->nilnode.right = &dict->nilnode; 374 369 } 375 370 … … 380 375 static dict_t *dict_init(dict_t *dict, dictcount_t maxcount, dict_comp_t comp) 381 376 { 382 383 384 385 386 387 388 389 390 391 377 dict->compare = comp; 378 dict->dict_freenode = dnode_free; 379 dict->dict_nodecount = 0; 380 dict->maxcount = maxcount; 381 dict->nilnode.left = &dict->nilnode; 382 dict->nilnode.right = &dict->nilnode; 383 dict->nilnode.parent = &dict->nilnode; 384 dict->nilnode.color = dnode_black; 385 dict->dupes = 0; 386 return dict; 392 387 } 393 388 … … 401 396 static dnode_t *dict_lookup(dict_t *dict, const void *key) 402 397 { 403 dnode_t *root = dict_root(dict); 404 dnode_t *nil = dict_nil(dict); 405 dnode_t *saved; 406 int result; 407 408 /* simple binary search adapted for trees that contain duplicate keys */ 409 410 while (root != nil) { 411 result = dict->compare(key, root->key); 412 if (result < 0) 413 root = root->left; 414 else if (result > 0) 415 root = root->right; 416 else { 417 if (!dict->dupes) { /* no duplicates, return match */ 418 return root; 419 } else { /* could be dupes, find leftmost one */ 420 do { 421 saved = root; 422 root = root->left; 423 while (root != nil && dict->compare(key, root->key)) 398 dnode_t *root = dict_root(dict); 399 dnode_t *nil = dict_nil(dict); 400 dnode_t *saved; 401 int result; 402 403 /* simple binary search adapted for trees that contain duplicate keys */ 404 405 while (root != nil) { 406 result = dict->compare(key, root->key); 407 if (result < 0) 408 root = root->left; 409 else if (result > 0) 424 410 root = root->right; 425 } while (root != nil); 426 return saved; 427 } 428 } 429 } 430 431 return NULL; 411 else { 412 if (!dict->dupes) { /* no duplicates, return match */ 413 return root; 414 } else { /* could be dupes, find leftmost one */ 415 do { 416 saved = root; 417 root = root->left; 418 while (root != nil && dict->compare(key, root->key)) 419 root = root->right; 420 } while (root != nil); 421 return saved; 422 } 423 } 424 } 425 426 return NULL; 432 427 } 433 428 … … 442 437 static void dict_insert(dict_t *dict, dnode_t *node, const void *key) 443 438 { 444 dnode_t *where = dict_root(dict), *nil = dict_nil(dict); 445 dnode_t *parent = nil, *uncle, *grandpa; 446 int result = -1; 447 448 node->key = key; 449 450 /* basic binary tree insert */ 451 452 while (where != nil) { 453 parent = where; 454 result = dict->compare(key, where->key); 455 /* trap attempts at duplicate key insertion unless it's explicitly allowed */ 456 assert (dict->dupes || result != 0); 439 dnode_t *where = dict_root(dict), *nil = dict_nil(dict); 440 dnode_t *parent = nil, *uncle, *grandpa; 441 int result = -1; 442 443 node->key = key; 444 445 /* basic binary tree insert */ 446 447 while (where != nil) { 448 parent = where; 449 result = dict->compare(key, where->key); 450 /* trap attempts at duplicate key insertion unless it's explicitly allowed */ 451 assert(dict->dupes || result != 0); 452 if (result < 0) 453 where = where->left; 454 else 455 where = where->right; 456 } 457 458 assert(where == nil); 459 457 460 if (result < 0) 458 where = where->left;461 parent->left = node; 459 462 else 460 where = where->right; 461 } 462 463 assert (where == nil); 464 465 if (result < 0) 466 parent->left = node; 467 else 468 parent->right = node; 469 470 node->parent = parent; 471 node->left = nil; 472 node->right = nil; 473 474 dict->dict_nodecount++; 475 476 /* red black adjustments */ 477 478 node->color = dnode_red; 479 480 while (parent->color == dnode_red) { 481 grandpa = parent->parent; 482 if (parent == grandpa->left) { 483 uncle = grandpa->right; 484 if (uncle->color == dnode_red) { /* red parent, red uncle */ 485 parent->color = dnode_black; 486 uncle->color = dnode_black; 487 grandpa->color = dnode_red; 488 node = grandpa; 489 parent = grandpa->parent; 490 } else { /* red parent, black uncle */ 491 if (node == parent->right) { 492 rotate_left(parent); 493 parent = node; 494 assert (grandpa == parent->parent); 495 /* rotation between parent and child preserves grandpa */ 496 } 497 parent->color = dnode_black; 498 grandpa->color = dnode_red; 499 rotate_right(grandpa); 500 break; 501 } 502 } else { /* symmetric cases: parent == parent->parent->right */ 503 uncle = grandpa->left; 504 if (uncle->color == dnode_red) { 505 parent->color = dnode_black; 506 uncle->color = dnode_black; 507 grandpa->color = dnode_red; 508 node = grandpa; 509 parent = grandpa->parent; 510 } else { 511 if (node == parent->left) { 512 rotate_right(parent); 513 parent = node; 514 assert (grandpa == parent->parent); 515 } 516 parent->color = dnode_black; 517 grandpa->color = dnode_red; 518 rotate_left(grandpa); 519 break; 520 } 521 } 522 } 523 524 dict_root(dict)->color = dnode_black; 525 463 parent->right = node; 464 465 node->parent = parent; 466 node->left = nil; 467 node->right = nil; 468 469 dict->dict_nodecount++; 470 471 /* red black adjustments */ 472 473 node->color = dnode_red; 474 475 while (parent->color == dnode_red) { 476 grandpa = parent->parent; 477 if (parent == grandpa->left) { 478 uncle = grandpa->right; 479 if (uncle->color == dnode_red) { /* red parent, red uncle */ 480 parent->color = dnode_black; 481 uncle->color = dnode_black; 482 grandpa->color = dnode_red; 483 node = grandpa; 484 parent = grandpa->parent; 485 } else { /* red parent, black uncle */ 486 if (node == parent->right) { 487 rotate_left(parent); 488 parent = node; 489 assert (grandpa == parent->parent); 490 /* rotation between parent and child preserves grandpa */ 491 } 492 parent->color = dnode_black; 493 grandpa->color = dnode_red; 494 rotate_right(grandpa); 495 break; 496 } 497 } else { /* symmetric cases: parent == parent->parent->right */ 498 uncle = grandpa->left; 499 if (uncle->color == dnode_red) { 500 parent->color = dnode_black; 501 uncle->color = dnode_black; 502 grandpa->color = dnode_red; 503 node = grandpa; 504 parent = grandpa->parent; 505 } else { 506 if (node == parent->left) { 507 rotate_right(parent); 508 parent = node; 509 assert (grandpa == parent->parent); 510 } 511 parent->color = dnode_black; 512 grandpa->color = dnode_red; 513 rotate_left(grandpa); 514 break; 515 } 516 } 517 } 518 519 dict_root(dict)->color = dnode_black; 526 520 } 527 521 … … 533 527 static dnode_t *dnode_init(dnode_t *dnode, void *data) 534 528 { 535 536 537 538 539 529 dnode->data = data; 530 dnode->parent = NULL; 531 dnode->left = NULL; 532 dnode->right = NULL; 533 return dnode; 540 534 } 541 535 542 536 static int dict_alloc_insert(dict_t *dict, const void *key, void *data) 543 537 { 544 dnode_t *node = malloc(sizeof(dnode_t)); 545 546 if (node) { 538 dnode_t *node = xmalloc(sizeof(dnode_t)); 539 547 540 dnode_init(node, data); 548 541 dict_insert(dict, node, key); 549 542 return 1; 550 }551 return 0;552 543 } 553 544 … … 559 550 static dnode_t *dict_first(dict_t *dict) 560 551 { 561 562 563 564 while ((left = root->left) != nil)565 566 567 552 dnode_t *nil = dict_nil(dict), *root = dict_root(dict), *left; 553 554 if (root != nil) 555 while ((left = root->left) != nil) 556 root = left; 557 558 return (root == nil) ? NULL : root; 568 559 } 569 560 … … 577 568 static dnode_t *dict_next(dict_t *dict, dnode_t *curr) 578 569 { 579 dnode_t *nil = dict_nil(dict), *parent, *left; 580 581 if (curr->right != nil) { 582 curr = curr->right; 583 while ((left = curr->left) != nil) 584 curr = left; 585 return curr; 586 } 587 588 parent = curr->parent; 589 590 while (parent != nil && curr == parent->right) { 591 curr = parent; 570 dnode_t *nil = dict_nil(dict), *parent, *left; 571 572 if (curr->right != nil) { 573 curr = curr->right; 574 while ((left = curr->left) != nil) 575 curr = left; 576 return curr; 577 } 578 592 579 parent = curr->parent; 593 } 594 595 return (parent == nil) ? NULL : parent; 580 581 while (parent != nil && curr == parent->right) { 582 curr = parent; 583 parent = curr->parent; 584 } 585 586 return (parent == nil) ? NULL : parent; 596 587 } 597 588 … … 599 590 static void dnode_free(dnode_t *node) 600 591 { 601 592 free(node); 602 593 } 603 594 … … 810 801 * sizeof (struct dx_dirblock_info), 811 802 "dx_block info array"); 812 813 803 } 814 804 … … 1544 1534 struct inode *j_inode = NULL; 1545 1535 struct kdev_s *dev_fs = NULL, *dev_journal; 1546 const char *journal_name = 0;1536 const char *journal_name = NULL; 1547 1537 journal_t *journal = NULL; 1548 1538 errcode_t retval = 0; … … 1733 1723 ext2fs_free_mem(&journal); 1734 1724 return retval; 1735 1736 1725 } 1737 1726 … … 1887 1876 1888 1877 /* Leave a valid existing V1 superblock signature alone. 1889 * Anything unrecogni sable we overwrite with a new V21878 * Anything unrecognizable we overwrite with a new V2 1890 1879 * signature. */ 1891 1880 … … 2271 2260 fs->flags &= ~EXT2_FLAG_MASTER_SB_ONLY; 2272 2261 inode.i_links_count = 0; 2273 inode.i_dtime = time( 0);2262 inode.i_dtime = time(NULL); 2274 2263 if ((retval = ext2fs_write_inode(fs, ino, &inode)) != 0) 2275 2264 goto err_out; … … 2393 2382 N_("llost+found"), 2394 2383 N_("Lis a link"), 2395 2396 2384 N_("mmultiply-claimed"), 2385 N_("ninvalid"), 2397 2386 N_("oorphaned"), 2398 2387 N_("pproblem in"), … … 2444 2433 } 2445 2434 if ((ch < 32) || (ch == 0x7f)) { 2446 fputc('^', stdout);2435 bb_putchar('^'); 2447 2436 ch ^= 0x40; /* ^@, ^A, ^B; ^? for DEL */ 2448 2437 } 2449 fputc(ch, stdout);2438 bb_putchar(ch); 2450 2439 } 2451 2440 } … … 2498 2487 if (*first && islower(*str)) { 2499 2488 *first = 0; 2500 fputc(toupper(*str++), stdout);2489 bb_putchar(toupper(*str++)); 2501 2490 } 2502 2491 print_e2fsck_message(ctx, str, pctx, *first); … … 2631 2620 switch (ch) { 2632 2621 case '%': 2633 fputc('%', stdout);2622 bb_putchar('%'); 2634 2623 break; 2635 2624 case 'b': … … 2655 2644 break; 2656 2645 case 'm': 2657 printf("%s", error_message(ctx->errcode));2646 fputs(error_message(ctx->errcode), stdout); 2658 2647 break; 2659 2648 case 'N': … … 2677 2666 break; 2678 2667 case 's': 2679 printf("%s", ctx->str ? ctx->str : "NULL");2668 fputs((ctx->str ? ctx->str : "NULL"), stdout); 2680 2669 break; 2681 2670 case 'X': … … 2743 2732 region_t region; 2744 2733 2745 region = malloc(sizeof(struct region_struct)); 2746 if (!region) 2747 return NULL; 2748 memset(region, 0, sizeof(struct region_struct)); 2734 region = xzalloc(sizeof(struct region_struct)); 2749 2735 region->min = min; 2750 2736 region->max = max; … … 2811 2797 * Insert a new region element structure into the linked list 2812 2798 */ 2813 new_region = malloc(sizeof(struct region_el)); 2814 if (!new_region) 2815 return -1; 2799 new_region = xmalloc(sizeof(struct region_el)); 2816 2800 new_region->start = start; 2817 2801 new_region->end = start + n; … … 3382 3366 if (!LINUX_S_ISDIR(inode->i_mode)) { 3383 3367 if (fix_problem(ctx, PR_1_ROOT_NO_DIR, &pctx)) { 3384 inode->i_dtime = time( 0);3368 inode->i_dtime = time(NULL); 3385 3369 inode->i_links_count = 0; 3386 3370 ext2fs_icount_store(ctx->inode_link_info, … … 3389 3373 "pass1"); 3390 3374 } 3391 3392 3375 } 3393 3376 /* … … 3476 3459 if (fix_problem(ctx, PR_1_LOW_DTIME, &pctx)) { 3477 3460 inode->i_dtime = inode->i_links_count ? 3478 0 : time( 0);3461 0 : time(NULL); 3479 3462 e2fsck_write_inode(ctx, ino, inode, 3480 3463 "pass1"); … … 3490 3473 if (fix_problem(ctx, 3491 3474 PR_1_ZERO_DTIME, &pctx)) { 3492 inode->i_dtime = time( 0);3475 inode->i_dtime = time(NULL); 3493 3476 e2fsck_write_inode(ctx, ino, inode, 3494 3477 "pass1"); … … 3660 3643 e2fsck_read_inode(ctx, EXT2_RESIZE_INO, inode, 3661 3644 "recreate inode"); 3662 inode->i_mtime = time( 0);3645 inode->i_mtime = time(NULL); 3663 3646 e2fsck_write_inode(ctx, EXT2_RESIZE_INO, inode, 3664 3647 "recreate inode"); … … 3692 3675 ext2fs_free_mem(&block_buf); 3693 3676 ext2fs_free_mem(&inode); 3694 3695 3677 } 3696 3678 … … 4170 4152 inode->i_links_count = 0; 4171 4153 ext2fs_icount_store(ctx->inode_link_info, ino, 0); 4172 inode->i_dtime = time( 0);4154 inode->i_dtime = time(NULL); 4173 4155 dirty_inode++; 4174 4156 ext2fs_unmark_inode_bitmap(ctx->inode_dir_map, ino); … … 4203 4185 inode->i_links_count = 0; 4204 4186 ext2fs_icount_store(ctx->inode_link_info, ino, 0); 4205 inode->i_dtime = time( 0);4187 inode->i_dtime = time(NULL); 4206 4188 dirty_inode++; 4207 4189 ext2fs_unmark_inode_bitmap(ctx->inode_dir_map, ino); … … 4465 4447 } 4466 4448 } else { 4467 ext2fs_mark_block_bitmap(ctx->block_found_map, 4468 b); 4449 ext2fs_mark_block_bitmap(ctx->block_found_map, b); 4469 4450 } 4470 4451 } … … 4483 4464 } 4484 4465 } else { 4485 ext2fs_mark_block_bitmap(ctx->block_found_map, 4486 fs->group_desc[i].bg_block_bitmap); 4487 } 4488 4466 ext2fs_mark_block_bitmap(ctx->block_found_map, 4467 fs->group_desc[i].bg_block_bitmap); 4468 } 4489 4469 } 4490 4470 /* … … 4500 4480 } 4501 4481 } else { 4502 4503 4482 ext2fs_mark_block_bitmap(ctx->block_found_map, 4483 fs->group_desc[i].bg_inode_bitmap); 4504 4484 } 4505 4485 } … … 5148 5128 e2fsck_read_inode(ctx, ino, &inode, "delete_file"); 5149 5129 inode.i_links_count = 0; 5150 inode.i_dtime = time( 0);5130 inode.i_dtime = time(NULL); 5151 5131 if (inode.i_file_acl && 5152 5132 (fs->super->s_feature_compat & EXT2_FEATURE_COMPAT_EXT_ATTR)) { … … 5602 5582 } 5603 5583 } 5604 5605 5584 } 5606 5585 … … 6019 5998 struct dx_dir_info *dx_dir; 6020 5999 #ifdef ENABLE_HTREE 6021 struct dx_dirblock_info *dx_db = 0;6000 struct dx_dirblock_info *dx_db = NULL; 6022 6001 #endif /* ENABLE_HTREE */ 6023 6002 struct ext2_dir_entry *dirent, *prev; … … 6394 6373 e2fsck_read_inode(ctx, ino, &inode, "deallocate_inode"); 6395 6374 inode.i_links_count = 0; 6396 inode.i_dtime = time( 0);6375 inode.i_dtime = time(NULL); 6397 6376 e2fsck_write_inode(ctx, ino, &inode, "deallocate_inode"); 6398 6377 clear_problem_context(&pctx); … … 6891 6870 inode.i_mode = 040755; 6892 6871 inode.i_size = fs->blocksize; 6893 inode.i_atime = inode.i_ctime = inode.i_mtime = time( 0);6872 inode.i_atime = inode.i_ctime = inode.i_mtime = time(NULL); 6894 6873 inode.i_links_count = 2; 6895 6874 inode.i_blocks = fs->blocksize / 512; … … 7139 7118 inode.i_mode = 040700; 7140 7119 inode.i_size = fs->blocksize; 7141 inode.i_atime = inode.i_ctime = inode.i_mtime = time( 0);7120 inode.i_atime = inode.i_ctime = inode.i_mtime = time(NULL); 7142 7121 inode.i_links_count = 2; 7143 7122 inode.i_blocks = fs->blocksize / 512; … … 7493 7472 ext2fs_icount_store(ctx->inode_link_info, i, 0); 7494 7473 inode.i_links_count = 0; 7495 inode.i_dtime = time( 0);7474 inode.i_dtime = time(NULL); 7496 7475 e2fsck_write_inode(ctx, i, &inode, 7497 7476 "disconnect_inode"); … … 7534 7513 struct problem_context pctx; 7535 7514 __u16 link_count, link_counted; 7536 char *buf = 0;7515 char *buf = NULL; 7537 7516 int group, maxgroup; 7538 7517 … … 9401 9380 /* Cannot proceed without a root inode. */ 9402 9381 { PR_3_NO_ROOT_INODE_ABORT, 9403 N_(" Cannot proceed without a @r.\n"),9382 N_("can't proceed without a @r.\n"), 9404 9383 PROMPT_NONE, PR_FATAL }, 9405 9384 … … 9680 9659 ext2_filsys fs = ctx->fs; 9681 9660 const struct e2fsck_problem *ptr; 9682 struct latch_descr *ldesc = 0;9661 struct latch_descr *ldesc = NULL; 9683 9662 const char *message; 9684 9663 int def_yn, answer, ans; … … 9762 9741 printf("%s.\n", answer ? 9763 9742 _(preen_msg[(int) ptr->prompt]) : _("IGNORED")); 9764 9765 9743 } 9766 9744 … … 10015 9993 * to do with it? That depends on the pass... */ 10016 9994 10017 switch (blocktype) {9995 switch (blocktype) { 10018 9996 case JFS_DESCRIPTOR_BLOCK: 10019 9997 /* If it is a valid descriptor block, replay it … … 10312 10290 } 10313 10291 if (fd->num_array >= fd->max_array) { 10314 new_array = realloc(fd->harray,10292 new_array = xrealloc(fd->harray, 10315 10293 sizeof(struct hash_entry) * (fd->max_array+500)); 10316 if (!new_array) {10317 fd->err = ENOMEM;10318 return BLOCK_ABORT;10319 }10320 10294 fd->harray = new_array; 10321 10295 fd->max_array += 500; … … 10392 10366 10393 10367 if (outdir->max) { 10394 new_mem = realloc(outdir->buf, blocks * fs->blocksize); 10395 if (!new_mem) 10396 return ENOMEM; 10368 new_mem = xrealloc(outdir->buf, blocks * fs->blocksize); 10397 10369 outdir->buf = new_mem; 10398 new_mem = realloc(outdir->hashes,10370 new_mem = xrealloc(outdir->hashes, 10399 10371 blocks * sizeof(ext2_dirhash_t)); 10400 if (!new_mem)10401 return ENOMEM;10402 10372 outdir->hashes = new_mem; 10403 10373 } else { 10404 outdir->buf = malloc(blocks * fs->blocksize);10405 outdir->hashes = malloc(blocks * sizeof(ext2_dirhash_t));10374 outdir->buf = xmalloc(blocks * fs->blocksize); 10375 outdir->hashes = xmalloc(blocks * sizeof(ext2_dirhash_t)); 10406 10376 outdir->num = 0; 10407 10377 } … … 10687 10657 { 10688 10658 struct ext2_dx_root_info *root_info; 10689 struct ext2_dx_entry *root, *dx_ent = 0;10659 struct ext2_dx_entry *root, *dx_ent = NULL; 10690 10660 struct ext2_dx_countlimit *root_limit, *limit; 10691 10661 errcode_t retval; … … 10839 10809 errcode_t retval; 10840 10810 struct ext2_inode inode; 10841 char *dir_buf = 0;10811 char *dir_buf = NULL; 10842 10812 struct fill_dir_struct fd; 10843 10813 struct out_dir outdir; … … 10850 10820 retval = ENOMEM; 10851 10821 fd.harray = 0; 10852 dir_buf = malloc(inode.i_size); 10853 if (!dir_buf) 10854 goto errout; 10822 dir_buf = xmalloc(inode.i_size); 10855 10823 10856 10824 fd.max_array = inode.i_size / 32; 10857 10825 fd.num_array = 0; 10858 fd.harray = malloc(fd.max_array * sizeof(struct hash_entry)); 10859 if (!fd.harray) 10860 goto errout; 10826 fd.harray = xmalloc(fd.max_array * sizeof(struct hash_entry)); 10861 10827 10862 10828 fd.ctx = ctx; … … 11159 11125 shift = 0; 11160 11126 tmp = hash_size; 11161 while ((tmp >>= 1UL) != 0UL)11127 while ((tmp >>= 1UL) != 0UL) 11162 11128 shift++; 11163 11129 journal->j_revoke->hash_shift = shift; 11164 11130 11165 journal->j_revoke->hash_table = malloc(hash_size * sizeof(struct list_head)); 11166 if (!journal->j_revoke->hash_table) { 11167 free(journal->j_revoke); 11168 journal->j_revoke = NULL; 11169 return -ENOMEM; 11170 } 11131 journal->j_revoke->hash_table = xmalloc(hash_size * sizeof(struct list_head)); 11171 11132 11172 11133 for (tmp = 0; tmp < hash_size; tmp++) … … 11355 11316 (blk >= fs->super->s_blocks_count)) { 11356 11317 fix_problem(ctx, PR_0_ORPHAN_ILLEGAL_BLOCK_NUM, pctx); 11357 11318 return_abort: 11358 11319 pb->abort = 1; 11359 11320 return BLOCK_ABORT; … … 11559 11520 ext2fs_inode_alloc_stats2(fs, ino, -1, 11560 11521 LINUX_S_ISDIR(inode.i_mode)); 11561 inode.i_dtime = time( 0);11522 inode.i_dtime = time(NULL); 11562 11523 } else { 11563 11524 inode.i_dtime = 0; … … 11568 11529 ext2fs_free_mem(&block_buf); 11569 11530 return 0; 11570 return_abort:11531 return_abort: 11571 11532 ext2fs_free_mem(&block_buf); 11572 11533 return 1; … … 11586 11547 int i, j, gdt_off, ind_off; 11587 11548 blk_t blk, pblk, expect; 11588 __u32 *dind_buf = 0, *ind_buf;11549 __u32 *dind_buf = NULL, *ind_buf; 11589 11550 errcode_t retval; 11590 11551 … … 11649 11610 (blk < fs->super->s_first_data_block || 11650 11611 blk >= fs->super->s_blocks_count)) { 11651 11612 resize_inode_invalid: 11652 11613 if (fix_problem(ctx, PR_0_RESIZE_INODE_INVALID, &pctx)) { 11653 11614 memset(&inode, 0, sizeof(inode)); … … 11691 11652 } 11692 11653 11693 cleanup:11654 cleanup: 11694 11655 ext2fs_free_mem(&dind_buf); 11695 11696 } 11656 } 11697 11657 11698 11658 static void check_super_block(e2fsck_t ctx) … … 11873 11833 (gd->bg_used_dirs_count > sb->s_inodes_per_group)) 11874 11834 ext2fs_unmark_valid(fs); 11875 11876 11835 } 11877 11836 … … 11933 11892 ~EXT2_FEATURE_INCOMPAT_FILETYPE; 11934 11893 ext2fs_mark_super_dirty(fs); 11935 11936 11894 } 11937 11895 } … … 12220 12178 char buf[256]; 12221 12179 12222 ret = malloc(size); 12223 if (!ret) { 12224 sprintf(buf, "Can't allocate %s\n", description); 12225 bb_error_msg_and_die(buf); 12226 } 12227 memset(ret, 0, size); 12180 ret = xzalloc(size); 12228 12181 return ret; 12229 12182 } … … 12237 12190 if (!len) 12238 12191 len = strlen(str); 12239 ret = malloc(len+1); 12240 if (ret) { 12241 strncpy(ret, str, len); 12242 ret[len] = 0; 12243 } 12192 ret = xmalloc(len+1); 12193 strncpy(ret, str, len); 12194 ret[len] = 0; 12244 12195 return ret; 12245 12196 } … … 12252 12203 int fail = 0; 12253 12204 12254 while (1) {12205 while (1) { 12255 12206 if (e2fsck_global_ctx && 12256 12207 (e2fsck_global_ctx->flags & E2F_FLAG_CANCEL)) { … … 12282 12233 tmp.c_cc[VMIN] = 1; 12283 12234 tmp.c_cc[VTIME] = 0; 12284 tcsetattr (0, TCSANOW,&tmp);12235 tcsetattr_stdin_TCSANOW(&tmp); 12285 12236 #endif 12286 12237 … … 12298 12249 if (c == 3) { 12299 12250 #ifdef HAVE_TERMIOS_H 12300 tcsetattr (0, TCSANOW,&termios);12251 tcsetattr_stdin_TCSANOW(&termios); 12301 12252 #endif 12302 12253 if (e2fsck_global_ctx && … … 12324 12275 puts ("no\n"); 12325 12276 #ifdef HAVE_TERMIOS_H 12326 tcsetattr (0, TCSANOW,&termios);12277 tcsetattr_stdin_TCSANOW(&termios); 12327 12278 #endif 12328 12279 return def; … … 12633 12584 &ctx->mount_flags); 12634 12585 if (retval) { 12635 bb_error_msg(_("while determining whether %s is mounted ."),12586 bb_error_msg(_("while determining whether %s is mounted"), 12636 12587 ctx->filesystem_name); 12637 12588 return; … … 12654 12605 printf(_("%s is mounted. "), ctx->filesystem_name); 12655 12606 if (!ctx->interactive) 12656 bb_error_msg_and_die(_(" Cannot continue, aborting."));12607 bb_error_msg_and_die(_("can't continue, aborting")); 12657 12608 printf(_("\n\n\007\007\007\007WARNING!!! " 12658 12609 "Running e2fsck on a mounted filesystem may cause\n" … … 12673 12624 struct dirent* de; 12674 12625 12675 f = fopen ("/proc/apm", "r");12626 f = fopen_for_read("/proc/apm"); 12676 12627 if (f) { 12677 12628 if (fscanf(f, "%s %s %s %x", tmp, tmp, tmp, &acflag) != 4) … … 12687 12638 snprintf(fname, 80, "/proc/acpi/ac_adapter/%s/state", 12688 12639 de->d_name); 12689 f = fopen (fname, "r");12640 f = fopen_for_read(fname); 12690 12641 if (!f) 12691 12642 continue; … … 12715 12666 long next_check; 12716 12667 int batt = is_on_batt(); 12717 time_t now = time( 0);12668 time_t now = time(NULL); 12718 12669 12719 12670 if ((ctx->options & E2F_OPT_FORCE) || cflag || swapfs) … … 12768 12719 printf(_(" (check in %ld mounts)"), next_check); 12769 12720 } 12770 fputc('\n', stdout);12721 bb_putchar('\n'); 12771 12722 ext2fs_close(fs); 12772 12723 ctx->fs = NULL; … … 12865 12816 spaces + (sizeof(spaces) - (dpywidth - i + 1))); 12866 12817 if (fixed_percent == 1000) 12867 fputc('|', stdout);12818 bb_putchar('|'); 12868 12819 else 12869 fputc(spinner[ctx->progress_pos & 3], stdout);12820 bb_putchar(spinner[ctx->progress_pos & 3]); 12870 12821 printf(" %4.1f%% ", percent); 12871 12822 if (dpynum) … … 12893 12844 if (ctx->progress_fd) { 12894 12845 sprintf(buf, "%d %lu %lu\n", pass, cur, max); 12895 write(ctx->progress_fd, buf, strlen(buf));12846 xwrite_str(ctx->progress_fd, buf); 12896 12847 } else { 12897 12848 percent = calc_percent(&e2fsck_tbl, pass, cur, max); … … 13009 12960 errcode_t retval; 13010 12961 struct sigaction sa; 13011 char *extended_opts = 0;12962 char *extended_opts = NULL; 13012 12963 13013 12964 retval = e2fsck_allocate_context(&ctx); … … 13061 13012 if (ctx->options & (E2F_OPT_YES|E2F_OPT_NO)) { 13062 13013 conflict_opt: 13063 bb_error_msg_and_die(_(" Only one the options -p/-a, -n or -y may be specified."));13014 bb_error_msg_and_die(_("only one the options -p/-a, -n or -y may be specified")); 13064 13015 } 13065 13016 ctx->options |= E2F_OPT_PREEN; … … 13374 13325 * device driver is being bogus. 13375 13326 */ 13376 bb_error_msg(_("can not set superblock flags on %s"), ctx->device_name);13327 bb_error_msg(_("can't set superblock flags on %s"), ctx->device_name); 13377 13328 bb_error_msg_and_die(0); 13378 13329 } … … 13406 13357 /* FIXME - do we support this at all? */ 13407 13358 if (sb->s_feature_incompat & EXT2_FEATURE_INCOMPAT_COMPRESSION) 13408 bb_error_msg(_(" Warning: compression support is experimental."));13359 bb_error_msg(_("warning: compression support is experimental")); 13409 13360 #endif 13410 13361 #ifndef ENABLE_HTREE
Note:
See TracChangeset
for help on using the changeset viewer.