Ignore:
Timestamp:
Nov 4, 2007, 3:16:40 AM (16 years ago)
Author:
Bruno Cornec
Message:

Update to busybox 1.7.2

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2.2.5/mindi-busybox/libbb/inode_hash.c

    r821 r1765  
    99 */
    1010
    11 #include <stdio.h>
    12 #include <stdlib.h>
    13 #include <string.h>
    1411#include "libbb.h"
     12
     13typedef struct ino_dev_hash_bucket_struct {
     14    struct ino_dev_hash_bucket_struct *next;
     15    ino_t ino;
     16    dev_t dev;
     17    char name[1];
     18} ino_dev_hashtable_bucket_t;
    1519
    1620#define HASH_SIZE   311     /* Should be prime */
    1721#define hash_inode(i)   ((i) % HASH_SIZE)
    1822
    19 typedef struct ino_dev_hash_bucket_struct {
    20   struct ino_dev_hash_bucket_struct *next;
    21   ino_t ino;
    22   dev_t dev;
    23   char name[1];
    24 } ino_dev_hashtable_bucket_t;
    25 
    26 static ino_dev_hashtable_bucket_t *ino_dev_hashtable[HASH_SIZE];
     23/* array of [HASH_SIZE] elements */
     24static ino_dev_hashtable_bucket_t **ino_dev_hashtable;
    2725
    2826/*
    29  * Return 1 if statbuf->st_ino && statbuf->st_dev are recorded in
    30  * `ino_dev_hashtable', else return 0
    31  *
    32  * If NAME is a non-NULL pointer to a character pointer, and there is
    33  * a match, then set *NAME to the value of the name slot in that
    34  * bucket.
     27 * Return name if statbuf->st_ino && statbuf->st_dev are recorded in
     28 * ino_dev_hashtable, else return NULL
    3529 */
    36 int is_in_ino_dev_hashtable(const struct stat *statbuf, char **name)
     30char *is_in_ino_dev_hashtable(const struct stat *statbuf)
    3731{
    3832    ino_dev_hashtable_bucket_t *bucket;
    3933
     34    if (!ino_dev_hashtable)
     35        return NULL;
     36
    4037    bucket = ino_dev_hashtable[hash_inode(statbuf->st_ino)];
    4138    while (bucket != NULL) {
    42       if ((bucket->ino == statbuf->st_ino) &&
    43           (bucket->dev == statbuf->st_dev))
    44       {
    45         if (name) *name = bucket->name;
    46         return 1;
    47       }
    48       bucket = bucket->next;
     39        if ((bucket->ino == statbuf->st_ino)
     40         && (bucket->dev == statbuf->st_dev)
     41        ) {
     42            return bucket->name;
     43        }
     44        bucket = bucket->next;
    4945    }
    50     return 0;
     46    return NULL;
    5147}
    5248
     
    5551{
    5652    int i;
    57     size_t s;
    5853    ino_dev_hashtable_bucket_t *bucket;
    5954
    6055    i = hash_inode(statbuf->st_ino);
    61     s = name ? strlen(name) : 0;
    62     bucket = xmalloc(sizeof(ino_dev_hashtable_bucket_t) + s);
     56    if (!name)
     57        name = "";
     58    bucket = xmalloc(sizeof(ino_dev_hashtable_bucket_t) + strlen(name));
    6359    bucket->ino = statbuf->st_ino;
    6460    bucket->dev = statbuf->st_dev;
    65     if (name)
    66         strcpy(bucket->name, name);
    67     else
    68         bucket->name[0] = '\0';
     61    strcpy(bucket->name, name);
     62
     63    if (!ino_dev_hashtable)
     64        ino_dev_hashtable = xzalloc(HASH_SIZE * sizeof(*ino_dev_hashtable));
     65
    6966    bucket->next = ino_dev_hashtable[i];
    7067    ino_dev_hashtable[i] = bucket;
    7168}
    7269
    73 #ifdef CONFIG_FEATURE_CLEAN_UP
     70#if ENABLE_FEATURE_CLEAN_UP
    7471/* Clear statbuf hash table */
    7572void reset_ino_dev_hashtable(void)
     
    7875    ino_dev_hashtable_bucket_t *bucket;
    7976
    80     for (i = 0; i < HASH_SIZE; i++) {
     77    for (i = 0; ino_dev_hashtable && i < HASH_SIZE; i++) {
    8178        while (ino_dev_hashtable[i] != NULL) {
    8279            bucket = ino_dev_hashtable[i]->next;
     
    8582        }
    8683    }
     84    free(ino_dev_hashtable);
     85    ino_dev_hashtable = NULL;
    8786}
     87#else
     88void reset_ino_dev_hashtable(void);
    8889#endif
Note: See TracChangeset for help on using the changeset viewer.