Ignore:
Timestamp:
Feb 25, 2011, 9:26:54 PM (13 years ago)
Author:
Bruno Cornec
Message:
  • Update mindi-busybox to 1.18.3 to avoid problems with the tar command which is now failing on recent versions with busybox 1.7.3
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2.2.9/mindi-busybox/e2fsprogs/old_e2fsprogs/e2fsck.c

    r1765 r2725  
    2727 * part of the ext2fs journaling system.
    2828 *
    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 */
    3531
    3632#include "e2fsck.h" /*Put all of our defines here to clean things up*/
     
    9086struct problem_context {
    9187    errcode_t       errcode;
    92     ext2_ino_t ino, ino2, dir;
     88    ext2_ino_t      ino, ino2, dir;
    9389    struct ext2_inode *inode;
    9490    struct ext2_dir_entry *dirent;
    95     blk_t   blk, blk2;
     91    blk_t           blk, blk2;
    9692    e2_blkcnt_t     blkcount;
    9793    int             group;
    98     __u64   num;
    99     const char *str;
     94    __u64           num;
     95    const char      *str;
    10096};
    10197
     
    134130
    135131typedef struct dnode_t {
    136     struct dnode_t *dict_left;
    137     struct dnode_t *dict_right;
    138     struct dnode_t *dict_parent;
    139     dnode_color_t dict_color;
    140     const void *dict_key;
    141     void *dict_data;
     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;
    142138} dnode_t;
    143139
     
    146142
    147143typedef struct dict_t {
    148     dnode_t dict_nilnode;
    149     dictcount_t dict_nodecount;
    150     dictcount_t dict_maxcount;
    151     dict_comp_t dict_compare;
    152     dnode_free_t dict_freenode;
    153     int dict_dupes;
     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;
    154150} dict_t;
    155151
     
    157153
    158154typedef struct dict_load_t {
    159     dict_t *dict_dictptr;
    160     dnode_t dict_nilnode;
     155    dict_t *dict_dictptr;
     156    dnode_t dict_nilnode;
    161157} dict_load_t;
    162158
     
    193189#define K_DEV_JOURNAL   2
    194190
    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)
    197193#define buffer_req(bh) 1
    198 #define do_readahead(journal, start) do {} while(0)
     194#define do_readahead(journal, start) do {} while (0)
    199195
    200196static e2fsck_t e2fsck_global_ctx;  /* Try your very best not to use this! */
     
    215211    kmem_cache_t *new_cache;
    216212
    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;
    220215    return new_cache;
    221216}
     
    270265static void rotate_left(dnode_t *upper)
    271266{
    272     dnode_t *lower, *lowleft, *upparent;
    273 
    274     lower = upper->right;
    275     upper->right = lowleft = lower->left;
    276     lowleft->parent = upper;
    277 
    278     lower->parent = upparent = upper->parent;
    279 
    280     /* don't need to check for root node here because root->parent is
    281        the sentinel nil node, and root->parent->left points back to root */
    282 
    283     if (upper == upparent->left) {
    284     upparent->left = lower;
    285     } else {
    286     assert (upper == upparent->right);
    287     upparent->right = lower;
    288     }
    289 
    290     lower->left = upper;
    291     upper->parent = lower;
     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;
    292287}
    293288
     
    299294static void rotate_right(dnode_t *upper)
    300295{
    301     dnode_t *lower, *lowright, *upparent;
    302 
    303     lower = upper->left;
    304     upper->left = lowright = lower->right;
    305     lowright->parent = upper;
    306 
    307     lower->parent = upparent = upper->parent;
    308 
    309     if (upper == upparent->right) {
    310     upparent->right = lower;
    311     } else {
    312     assert (upper == upparent->left);
    313     upparent->left = lower;
    314     }
    315 
    316     lower->right = upper;
    317     upper->parent = lower;
     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;
    318313}
    319314
     
    325320static void free_nodes(dict_t *dict, dnode_t *node, dnode_t *nil)
    326321{
    327     if (node == nil)
    328     return;
    329     free_nodes(dict, node->left, nil);
    330     free_nodes(dict, node->right, nil);
    331     dict->dict_freenode(node);
     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);
    332327}
    333328
     
    341336static int verify_dict_has_node(dnode_t *nil, dnode_t *root, dnode_t *node)
    342337{
    343     if (root != nil) {
    344     return root == node
    345         || verify_dict_has_node(nil, root->left, node)
    346         || verify_dict_has_node(nil, root->right, node);
    347     }
    348     return 0;
     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;
    349344}
    350345
     
    356351static void dict_set_allocator(dict_t *dict, dnode_free_t fr)
    357352{
    358     assert (dict_count(dict) == 0);
    359     dict->dict_freenode = fr;
     353    assert(dict_count(dict) == 0);
     354    dict->dict_freenode = fr;
    360355}
    361356
     
    367362static void dict_free_nodes(dict_t *dict)
    368363{
    369     dnode_t *nil = dict_nil(dict), *root = dict_root(dict);
    370     free_nodes(dict, root, nil);
    371     dict->dict_nodecount = 0;
    372     dict->nilnode.left = &dict->nilnode;
    373     dict->nilnode.right = &dict->nilnode;
     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;
    374369}
    375370
     
    380375static dict_t *dict_init(dict_t *dict, dictcount_t maxcount, dict_comp_t comp)
    381376{
    382     dict->compare = comp;
    383     dict->dict_freenode = dnode_free;
    384     dict->dict_nodecount = 0;
    385     dict->maxcount = maxcount;
    386     dict->nilnode.left = &dict->nilnode;
    387     dict->nilnode.right = &dict->nilnode;
    388     dict->nilnode.parent = &dict->nilnode;
    389     dict->nilnode.color = dnode_black;
    390     dict->dupes = 0;
    391     return dict;
     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;
    392387}
    393388
     
    401396static dnode_t *dict_lookup(dict_t *dict, const void *key)
    402397{
    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)
    424410            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;
    432427}
    433428
     
    442437static void dict_insert(dict_t *dict, dnode_t *node, const void *key)
    443438{
    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
    457460    if (result < 0)
    458         where = where->left;
     461        parent->left = node;
    459462    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;
    526520}
    527521
     
    533527static dnode_t *dnode_init(dnode_t *dnode, void *data)
    534528{
    535     dnode->data = data;
    536     dnode->parent = NULL;
    537     dnode->left = NULL;
    538     dnode->right = NULL;
    539     return dnode;
     529    dnode->data = data;
     530    dnode->parent = NULL;
     531    dnode->left = NULL;
     532    dnode->right = NULL;
     533    return dnode;
    540534}
    541535
    542536static int dict_alloc_insert(dict_t *dict, const void *key, void *data)
    543537{
    544     dnode_t *node = malloc(sizeof(dnode_t));
    545 
    546     if (node) {
     538    dnode_t *node = xmalloc(sizeof(dnode_t));
     539
    547540    dnode_init(node, data);
    548541    dict_insert(dict, node, key);
    549542    return 1;
    550     }
    551     return 0;
    552543}
    553544
     
    559550static dnode_t *dict_first(dict_t *dict)
    560551{
    561     dnode_t *nil = dict_nil(dict), *root = dict_root(dict), *left;
    562 
    563     if (root != nil)
    564     while ((left = root->left) != nil)
    565         root = left;
    566 
    567     return (root == nil) ? NULL : root;
     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;
    568559}
    569560
     
    577568static dnode_t *dict_next(dict_t *dict, dnode_t *curr)
    578569{
    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
    592579    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;
    596587}
    597588
     
    599590static void dnode_free(dnode_t *node)
    600591{
    601     free(node);
     592    free(node);
    602593}
    603594
     
    810801                       * sizeof (struct dx_dirblock_info),
    811802                       "dx_block info array");
    812 
    813803}
    814804
     
    15441534    struct inode            *j_inode = NULL;
    15451535    struct kdev_s           *dev_fs = NULL, *dev_journal;
    1546     const char              *journal_name = 0;
     1536    const char              *journal_name = NULL;
    15471537    journal_t               *journal = NULL;
    15481538    errcode_t               retval = 0;
     
    17331723    ext2fs_free_mem(&journal);
    17341724    return retval;
    1735 
    17361725}
    17371726
     
    18871876
    18881877    /* Leave a valid existing V1 superblock signature alone.
    1889      * Anything unrecognisable we overwrite with a new V2
     1878     * Anything unrecognizable we overwrite with a new V2
    18901879     * signature. */
    18911880
     
    22712260    fs->flags &= ~EXT2_FLAG_MASTER_SB_ONLY;
    22722261    inode.i_links_count = 0;
    2273     inode.i_dtime = time(0);
     2262    inode.i_dtime = time(NULL);
    22742263    if ((retval = ext2fs_write_inode(fs, ino, &inode)) != 0)
    22752264        goto err_out;
     
    23932382    N_("llost+found"),
    23942383    N_("Lis a link"),
    2395     N_("mmultiply-claimed"),
    2396     N_("ninvalid"),
     2384    N_("mmultiply-claimed"),
     2385    N_("ninvalid"),
    23972386    N_("oorphaned"),
    23982387    N_("pproblem in"),
     
    24442433        }
    24452434        if ((ch < 32) || (ch == 0x7f)) {
    2446             fputc('^', stdout);
     2435            bb_putchar('^');
    24472436            ch ^= 0x40; /* ^@, ^A, ^B; ^? for DEL */
    24482437        }
    2449         fputc(ch, stdout);
     2438        bb_putchar(ch);
    24502439    }
    24512440}
     
    24982487        if (*first && islower(*str)) {
    24992488            *first = 0;
    2500             fputc(toupper(*str++), stdout);
     2489            bb_putchar(toupper(*str++));
    25012490        }
    25022491        print_e2fsck_message(ctx, str, pctx, *first);
     
    26312620    switch (ch) {
    26322621    case '%':
    2633         fputc('%', stdout);
     2622        bb_putchar('%');
    26342623        break;
    26352624    case 'b':
     
    26552644        break;
    26562645    case 'm':
    2657         printf("%s", error_message(ctx->errcode));
     2646        fputs(error_message(ctx->errcode), stdout);
    26582647        break;
    26592648    case 'N':
     
    26772666        break;
    26782667    case 's':
    2679         printf("%s", ctx->str ? ctx->str : "NULL");
     2668        fputs((ctx->str ? ctx->str : "NULL"), stdout);
    26802669        break;
    26812670    case 'X':
     
    27432732    region_t        region;
    27442733
    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));
    27492735    region->min = min;
    27502736    region->max = max;
     
    28112797     * Insert a new region element structure into the linked list
    28122798     */
    2813     new_region = malloc(sizeof(struct region_el));
    2814     if (!new_region)
    2815         return -1;
     2799    new_region = xmalloc(sizeof(struct region_el));
    28162800    new_region->start = start;
    28172801    new_region->end = start + n;
     
    33823366            if (!LINUX_S_ISDIR(inode->i_mode)) {
    33833367                if (fix_problem(ctx, PR_1_ROOT_NO_DIR, &pctx)) {
    3384                     inode->i_dtime = time(0);
     3368                    inode->i_dtime = time(NULL);
    33853369                    inode->i_links_count = 0;
    33863370                    ext2fs_icount_store(ctx->inode_link_info,
     
    33893373                               "pass1");
    33903374                }
    3391 
    33923375            }
    33933376            /*
     
    34763459            if (fix_problem(ctx, PR_1_LOW_DTIME, &pctx)) {
    34773460                inode->i_dtime = inode->i_links_count ?
    3478                     0 : time(0);
     3461                    0 : time(NULL);
    34793462                e2fsck_write_inode(ctx, ino, inode,
    34803463                           "pass1");
     
    34903473                if (fix_problem(ctx,
    34913474                        PR_1_ZERO_DTIME, &pctx)) {
    3492                     inode->i_dtime = time(0);
     3475                    inode->i_dtime = time(NULL);
    34933476                    e2fsck_write_inode(ctx, ino, inode,
    34943477                               "pass1");
     
    36603643        e2fsck_read_inode(ctx, EXT2_RESIZE_INO, inode,
    36613644                  "recreate inode");
    3662         inode->i_mtime = time(0);
     3645        inode->i_mtime = time(NULL);
    36633646        e2fsck_write_inode(ctx, EXT2_RESIZE_INO, inode,
    36643647                  "recreate inode");
     
    36923675    ext2fs_free_mem(&block_buf);
    36933676    ext2fs_free_mem(&inode);
    3694 
    36953677}
    36963678
     
    41704152        inode->i_links_count = 0;
    41714153        ext2fs_icount_store(ctx->inode_link_info, ino, 0);
    4172         inode->i_dtime = time(0);
     4154        inode->i_dtime = time(NULL);
    41734155        dirty_inode++;
    41744156        ext2fs_unmark_inode_bitmap(ctx->inode_dir_map, ino);
     
    42034185            inode->i_links_count = 0;
    42044186            ext2fs_icount_store(ctx->inode_link_info, ino, 0);
    4205             inode->i_dtime = time(0);
     4187            inode->i_dtime = time(NULL);
    42064188            dirty_inode++;
    42074189            ext2fs_unmark_inode_bitmap(ctx->inode_dir_map, ino);
     
    44654447                    }
    44664448                } else {
    4467                     ext2fs_mark_block_bitmap(ctx->block_found_map,
    4468                                  b);
     4449                    ext2fs_mark_block_bitmap(ctx->block_found_map, b);
    44694450                }
    44704451            }
     
    44834464                }
    44844465            } 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            }
    44894469        }
    44904470        /*
     
    45004480                }
    45014481            } else {
    4502                 ext2fs_mark_block_bitmap(ctx->block_found_map,
    4503                      fs->group_desc[i].bg_inode_bitmap);
     4482                ext2fs_mark_block_bitmap(ctx->block_found_map,
     4483                    fs->group_desc[i].bg_inode_bitmap);
    45044484            }
    45054485        }
     
    51485128    e2fsck_read_inode(ctx, ino, &inode, "delete_file");
    51495129    inode.i_links_count = 0;
    5150     inode.i_dtime = time(0);
     5130    inode.i_dtime = time(NULL);
    51515131    if (inode.i_file_acl &&
    51525132        (fs->super->s_feature_compat & EXT2_FEATURE_COMPAT_EXT_ATTR)) {
     
    56025582        }
    56035583    }
    5604 
    56055584}
    56065585
     
    60195998    struct dx_dir_info      *dx_dir;
    60205999#ifdef ENABLE_HTREE
    6021     struct dx_dirblock_info *dx_db = 0;
     6000    struct dx_dirblock_info *dx_db = NULL;
    60226001#endif /* ENABLE_HTREE */
    60236002    struct ext2_dir_entry   *dirent, *prev;
     
    63946373    e2fsck_read_inode(ctx, ino, &inode, "deallocate_inode");
    63956374    inode.i_links_count = 0;
    6396     inode.i_dtime = time(0);
     6375    inode.i_dtime = time(NULL);
    63976376    e2fsck_write_inode(ctx, ino, &inode, "deallocate_inode");
    63986377    clear_problem_context(&pctx);
     
    68916870    inode.i_mode = 040755;
    68926871    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);
    68946873    inode.i_links_count = 2;
    68956874    inode.i_blocks = fs->blocksize / 512;
     
    71397118    inode.i_mode = 040700;
    71407119    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);
    71427121    inode.i_links_count = 2;
    71437122    inode.i_blocks = fs->blocksize / 512;
     
    74937472            ext2fs_icount_store(ctx->inode_link_info, i, 0);
    74947473            inode.i_links_count = 0;
    7495             inode.i_dtime = time(0);
     7474            inode.i_dtime = time(NULL);
    74967475            e2fsck_write_inode(ctx, i, &inode,
    74977476                       "disconnect_inode");
     
    75347513    struct problem_context  pctx;
    75357514    __u16   link_count, link_counted;
    7536     char    *buf = 0;
     7515    char    *buf = NULL;
    75377516    int     group, maxgroup;
    75387517
     
    94019380    /* Cannot proceed without a root inode. */
    94029381    { PR_3_NO_ROOT_INODE_ABORT,
    9403       N_("Cannot proceed without a @r.\n"),
     9382      N_("can't proceed without a @r.\n"),
    94049383      PROMPT_NONE, PR_FATAL },
    94059384
     
    96809659    ext2_filsys fs = ctx->fs;
    96819660    const struct e2fsck_problem *ptr;
    9682     struct latch_descr *ldesc = 0;
     9661    struct latch_descr *ldesc = NULL;
    96839662    const char *message;
    96849663    int             def_yn, answer, ans;
     
    97629741            printf("%s.\n", answer ?
    97639742                   _(preen_msg[(int) ptr->prompt]) : _("IGNORED"));
    9764 
    97659743    }
    97669744
     
    100159993         * to do with it?  That depends on the pass... */
    100169994
    10017         switch(blocktype) {
     9995        switch (blocktype) {
    100189996        case JFS_DESCRIPTOR_BLOCK:
    100199997            /* If it is a valid descriptor block, replay it
     
    1031210290        }
    1031310291        if (fd->num_array >= fd->max_array) {
    10314             new_array = realloc(fd->harray,
     10292            new_array = xrealloc(fd->harray,
    1031510293                sizeof(struct hash_entry) * (fd->max_array+500));
    10316             if (!new_array) {
    10317                 fd->err = ENOMEM;
    10318                 return BLOCK_ABORT;
    10319             }
    1032010294            fd->harray = new_array;
    1032110295            fd->max_array += 500;
     
    1039210366
    1039310367    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);
    1039710369        outdir->buf = new_mem;
    10398         new_mem = realloc(outdir->hashes,
     10370        new_mem = xrealloc(outdir->hashes,
    1039910371                  blocks * sizeof(ext2_dirhash_t));
    10400         if (!new_mem)
    10401             return ENOMEM;
    1040210372        outdir->hashes = new_mem;
    1040310373    } 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));
    1040610376        outdir->num = 0;
    1040710377    }
     
    1068710657{
    1068810658    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;
    1069010660    struct ext2_dx_countlimit       *root_limit, *limit;
    1069110661    errcode_t                       retval;
     
    1083910809    errcode_t               retval;
    1084010810    struct ext2_inode       inode;
    10841     char                    *dir_buf = 0;
     10811    char                    *dir_buf = NULL;
    1084210812    struct fill_dir_struct  fd;
    1084310813    struct out_dir          outdir;
     
    1085010820    retval = ENOMEM;
    1085110821    fd.harray = 0;
    10852     dir_buf = malloc(inode.i_size);
    10853     if (!dir_buf)
    10854         goto errout;
     10822    dir_buf = xmalloc(inode.i_size);
    1085510823
    1085610824    fd.max_array = inode.i_size / 32;
    1085710825    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));
    1086110827
    1086210828    fd.ctx = ctx;
     
    1115911125    shift = 0;
    1116011126    tmp = hash_size;
    11161     while((tmp >>= 1UL) != 0UL)
     11127    while ((tmp >>= 1UL) != 0UL)
    1116211128        shift++;
    1116311129    journal->j_revoke->hash_shift = shift;
    1116411130
    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));
    1117111132
    1117211133    for (tmp = 0; tmp < hash_size; tmp++)
     
    1135511316        (blk >= fs->super->s_blocks_count)) {
    1135611317        fix_problem(ctx, PR_0_ORPHAN_ILLEGAL_BLOCK_NUM, pctx);
    11357     return_abort:
     11318 return_abort:
    1135811319        pb->abort = 1;
    1135911320        return BLOCK_ABORT;
     
    1155911520            ext2fs_inode_alloc_stats2(fs, ino, -1,
    1156011521                          LINUX_S_ISDIR(inode.i_mode));
    11561             inode.i_dtime = time(0);
     11522            inode.i_dtime = time(NULL);
    1156211523        } else {
    1156311524            inode.i_dtime = 0;
     
    1156811529    ext2fs_free_mem(&block_buf);
    1156911530    return 0;
    11570 return_abort:
     11531 return_abort:
    1157111532    ext2fs_free_mem(&block_buf);
    1157211533    return 1;
     
    1158611547    int             i, j, gdt_off, ind_off;
    1158711548    blk_t           blk, pblk, expect;
    11588     __u32           *dind_buf = 0, *ind_buf;
     11549    __u32           *dind_buf = NULL, *ind_buf;
    1158911550    errcode_t       retval;
    1159011551
     
    1164911610        (blk < fs->super->s_first_data_block ||
    1165011611         blk >= fs->super->s_blocks_count)) {
    11651     resize_inode_invalid:
     11612 resize_inode_invalid:
    1165211613        if (fix_problem(ctx, PR_0_RESIZE_INODE_INVALID, &pctx)) {
    1165311614            memset(&inode, 0, sizeof(inode));
     
    1169111652    }
    1169211653
    11693 cleanup:
     11654 cleanup:
    1169411655    ext2fs_free_mem(&dind_buf);
    11695 
    11696  }
     11656}
    1169711657
    1169811658static void check_super_block(e2fsck_t ctx)
     
    1187311833            (gd->bg_used_dirs_count > sb->s_inodes_per_group))
    1187411834            ext2fs_unmark_valid(fs);
    11875 
    1187611835    }
    1187711836
     
    1193311892                ~EXT2_FEATURE_INCOMPAT_FILETYPE;
    1193411893            ext2fs_mark_super_dirty(fs);
    11935 
    1193611894        }
    1193711895    }
     
    1222012178    char buf[256];
    1222112179
    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);
    1222812181    return ret;
    1222912182}
     
    1223712190    if (!len)
    1223812191        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;
    1224412195    return ret;
    1224512196}
     
    1225212203    int     fail = 0;
    1225312204
    12254     while(1) {
     12205    while (1) {
    1225512206        if (e2fsck_global_ctx &&
    1225612207            (e2fsck_global_ctx->flags & E2F_FLAG_CANCEL)) {
     
    1228212233    tmp.c_cc[VMIN] = 1;
    1228312234    tmp.c_cc[VTIME] = 0;
    12284     tcsetattr (0, TCSANOW, &tmp);
     12235    tcsetattr_stdin_TCSANOW(&tmp);
    1228512236#endif
    1228612237
     
    1229812249        if (c == 3) {
    1229912250#ifdef HAVE_TERMIOS_H
    12300             tcsetattr (0, TCSANOW, &termios);
     12251            tcsetattr_stdin_TCSANOW(&termios);
    1230112252#endif
    1230212253            if (e2fsck_global_ctx &&
     
    1232412275        puts ("no\n");
    1232512276#ifdef HAVE_TERMIOS_H
    12326     tcsetattr (0, TCSANOW, &termios);
     12277    tcsetattr_stdin_TCSANOW(&termios);
    1232712278#endif
    1232812279    return def;
     
    1263312584                     &ctx->mount_flags);
    1263412585    if (retval) {
    12635         bb_error_msg(_("while determining whether %s is mounted."),
     12586        bb_error_msg(_("while determining whether %s is mounted"),
    1263612587            ctx->filesystem_name);
    1263712588        return;
     
    1265412605    printf(_("%s is mounted.  "), ctx->filesystem_name);
    1265512606    if (!ctx->interactive)
    12656         bb_error_msg_and_die(_("Cannot continue, aborting."));
     12607        bb_error_msg_and_die(_("can't continue, aborting"));
    1265712608    printf(_("\n\n\007\007\007\007WARNING!!!  "
    1265812609           "Running e2fsck on a mounted filesystem may cause\n"
     
    1267312624    struct dirent*  de;
    1267412625
    12675     f = fopen("/proc/apm", "r");
     12626    f = fopen_for_read("/proc/apm");
    1267612627    if (f) {
    1267712628        if (fscanf(f, "%s %s %s %x", tmp, tmp, tmp, &acflag) != 4)
     
    1268712638            snprintf(fname, 80, "/proc/acpi/ac_adapter/%s/state",
    1268812639                 de->d_name);
    12689             f = fopen(fname, "r");
     12640            f = fopen_for_read(fname);
    1269012641            if (!f)
    1269112642                continue;
     
    1271512666    long next_check;
    1271612667    int batt = is_on_batt();
    12717     time_t now = time(0);
     12668    time_t now = time(NULL);
    1271812669
    1271912670    if ((ctx->options & E2F_OPT_FORCE) || cflag || swapfs)
     
    1276812719            printf(_(" (check in %ld mounts)"), next_check);
    1276912720    }
    12770     fputc('\n', stdout);
     12721    bb_putchar('\n');
    1277112722    ext2fs_close(fs);
    1277212723    ctx->fs = NULL;
     
    1286512816           spaces + (sizeof(spaces) - (dpywidth - i + 1)));
    1286612817    if (fixed_percent == 1000)
    12867         fputc('|', stdout);
     12818        bb_putchar('|');
    1286812819    else
    12869         fputc(spinner[ctx->progress_pos & 3], stdout);
     12820        bb_putchar(spinner[ctx->progress_pos & 3]);
    1287012821    printf(" %4.1f%%  ", percent);
    1287112822    if (dpynum)
     
    1289312844    if (ctx->progress_fd) {
    1289412845        sprintf(buf, "%d %lu %lu\n", pass, cur, max);
    12895         write(ctx->progress_fd, buf, strlen(buf));
     12846        xwrite_str(ctx->progress_fd, buf);
    1289612847    } else {
    1289712848        percent = calc_percent(&e2fsck_tbl, pass, cur, max);
     
    1300912960    errcode_t       retval;
    1301012961    struct sigaction        sa;
    13011     char            *extended_opts = 0;
     12962    char            *extended_opts = NULL;
    1301212963
    1301312964    retval = e2fsck_allocate_context(&ctx);
     
    1306113012            if (ctx->options & (E2F_OPT_YES|E2F_OPT_NO)) {
    1306213013            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"));
    1306413015            }
    1306513016            ctx->options |= E2F_OPT_PREEN;
     
    1337413325                 * device driver is being bogus.
    1337513326                 */
    13376                 bb_error_msg(_("cannot set superblock flags on %s"), ctx->device_name);
     13327                bb_error_msg(_("can't set superblock flags on %s"), ctx->device_name);
    1337713328                bb_error_msg_and_die(0);
    1337813329            }
     
    1340613357    /* FIXME - do we support this at all? */
    1340713358    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"));
    1340913360#endif
    1341013361#ifndef ENABLE_HTREE
Note: See TracChangeset for help on using the changeset viewer.