Recover Berkeley DB File

Panayotis Tsiamis ptsiamis at fg.internet.gr
Fri Mar 31 13:06:20 EEST 2006


Idou 3 apo ta functions ta opia elpizo na bgaleis kapio nohma
giati ego de to katexo. An epithimeis olo to arxio pesmou na sto stilo
mono sto diko sou e-mail meso attachment.

/* add dns */
static void dns_db_put(DNODEPTR dnode)
{ 
   DBT k, v;
   struct dnsRecord *recPtr = NULL;
   int nameLen, recSize, dberror;
               
   if(dnode == NULL || dnode->name == NULL)
      return;
       
   nameLen = strlen(dnode->name) + 1;
  
   /* Align to multiple of eight bytes */
   recSize = (sizeof(struct dnsRecord)+nameLen+7) & ~0x7;
       
   /* make sure we have a db ;) */
   if(dns_db == NULL)
                return;

        memset(&k, 0, sizeof(k));
        memset(&v, 0, sizeof(v));

   if((recPtr = (dnsRecord*) calloc(1, recSize))) {
      recPtr->timeStamp = dnode->resolved;
      memcpy(&recPtr->hostName, dnode->name, nameLen);

      k.data = dnode->ipaddr;
      k.size = strlen(dnode->ipaddr);

      v.data = recPtr;
      v.size = recSize;

      mutex_lock(db_mutex);
      if((dberror = dns_db->put(dns_db, NULL, &k, &v, 0)) < 0) {
         if (verbose>1)
            fprintf(stderr,"dns_db_put failed (%04x - %s)!\n", dberror, 
db_strerror(dberror));
      }
      mutex_unlock(db_mutex);

      free(recPtr);
   }
}
/*********************************************/
/* OPEN_CACHE - open our cache file RDONLY   */
/*********************************************/

static bool dns_db_open(void)
{
   struct stat  dbStat;
        int major, minor, patch;

   /* double check filename was specified */
   if(!dns_cache) { dns_db=NULL; return 0; }

        db_version(&major, &minor, &patch);

        if(major < 4 && minor < 3) {
                fprintf(stderr, "Error: The Berkeley DB library must be 
v4.3 or newer (found v%d.%d.%d).\n", major, minor, patch);
                return false;
        }

   /* minimal sanity check on it */
   if(stat(dns_cache, &dbStat) < 0)
   {
      if(errno != ENOENT) return false;
   }
   else
   {
      if(!dbStat.st_size)  /* bogus file, probably from a crash */
      {
         unlink(dns_cache);  /* remove it so we can recreate... */
      }
   }

   if(db_create(&dns_db, NULL, 0)) {
      if (verbose) fprintf(stderr,"%s %s\n",msg_dns_nodb, dns_cache);
      return false;                  /* disable cache */
   }

   /* open cache file */
   if(dns_db->open(dns_db, NULL, dns_cache, NULL, DB_HASH, DB_CREATE | 
DB_THREAD, 0664))
   {
      /* Error: Unable to open DNS cache file <filename> */
      if (verbose) fprintf(stderr,"%s %s\n",msg_dns_nodb,dns_cache);
      return false;                  /* disable cache */
   }

   db_mutex = mutex_create();

   return true;
}


/*********************************************/
/* CLOSE_CACHE - close our RDONLY cache      */
/*********************************************/

static bool dns_db_close(void)
{
        if(dns_db)
                dns_db->close(dns_db, 0);

   if(db_mutex)
      mutex_destroy(db_mutex);
   db_mutex = NULL;

   return true;
}

telos oi metablites :

struct dnsRecord { time_t    timeStamp; /* Timestamp of resolv data  */
                   char      hostName[1]; }; /* Hostname (var length)*/

static DB *dns_db   = NULL;/* DNS cache database */
static time_t runtime;
static mutex_t dnode_mutex;
static mutex_t db_mutex;
static thread_t *dnode_threads;
static bool dns_thread_stop = false;
static event_t dns_done_event;

static DNODEPTR dnode_list;     
static DNODEPTR dnode_start, dnode_end, dnode_cur;
static int dns_live_workers = 0; /* total number of DNS threads */
static DNODEPTR host_table[MAXHASH]; /* DNS hash table */
static u_long dnode_count = 0;/* total number of dnodes  */
static u_long dns_unresolved = 0; /* number of addresses to resolve   */

struct dnode {
          char *name;/* DNS node hash table struct */
          char *ipaddr;
          size_t resolved; /* when the name was resolved   */
          struct in_addr  addr;
          struct dnode    *llist;
          struct dnode    *next;
          dnode(void);
};

O/H Giorgos Keramidas έγραψε:
[... /kodika/ ...]

ps: thanx gia to endiaferon





More information about the Linux-greek-users mailing list