Пример #1
0
/* {{{ rberkeley_db_get_type */
SEXP rberkeley_db_get_type (SEXP _dbp)
{
  DB *dbp;
  DBTYPE type;
  int ret;

  dbp = R_ExternalPtrAddr(_dbp);
  if(R_ExternalPtrTag(_dbp) != RBerkeley_DB || dbp == NULL)
    error("invalid 'db' handle");
  ret = dbp->get_type(dbp, &type);

  switch(type) {
    case DB_BTREE:
      return mkString("DB_BTREE");
      break;
    case DB_HASH:
      return mkString("DB_HASH");
      break;
    case DB_RECNO:
      return mkString("DB_RECNO");
      break;
    case DB_QUEUE:
      return mkString("DB_QUEUE");
      break;
    case DB_UNKNOWN:
      return mkString("DB_UNKNOWN");
      break;
    default:
      return R_NilValue;
      break;
  }
}
Пример #2
0
static void do_async_stat(void* arg)
{
    // Payload is: << DbRef:32, Flags:32 >>
    PortData* d = (PortData*)arg;

    // Get the database object, using the provided ref
    DB* db = bdberl_lookup_dbref(d->async_dbref);
    DBTYPE type = DB_UNKNOWN;
    int rc = db->get_type(db, &type);
    if (rc != 0)
    {
        bdberl_async_cleanup_and_send_rc(d, rc);
        return;
    }

    void *sp = NULL;
    rc = db->stat(db, d->txn, &sp, d->async_flags);
    if (rc != 0 || sp == NULL)
    {
        bdberl_async_cleanup_and_send_rc(d, rc);
    }
    else
    {
        switch(type)
        {
            case DB_BTREE: /*FALLTHRU*/
            case DB_RECNO:
                async_cleanup_and_send_btree_stats(d, type == DB_BTREE ? "btree" :"recno", sp);
                break;
            case DB_HASH:
                async_cleanup_and_send_hash_stats(d, sp);
                break;
#ifdef ENABLE_QUEUE
            case DB_QUEUE:
                async_cleanup_and_send_queue_stats(d, sp);
                break;
#endif
            default:
                bdberl_async_cleanup_and_send_rc(d, ERROR_INVALID_DB_TYPE);
                break;
        }
    }

    // Finally, clean up value buffer (driver_send_term made a copy)
    if (NULL != sp)
    {
        driver_free(sp);
    }
}
Пример #3
0
static int db3_dbiOpen(rpmdb rdb, rpmDbiTagVal rpmtag, dbiIndex * dbip, int flags)
{
    const char *dbhome = rpmdbHome(rdb);
    dbiIndex dbi = NULL;
    int rc = 0;
    int retry_open;
    int verifyonly = (flags & RPMDB_FLAG_VERIFYONLY);

    DB * db = NULL;
    DBTYPE dbtype = DB_UNKNOWN;
    uint32_t oflags;
    static int _lockdbfd = 0;

    if (dbip)
	*dbip = NULL;

    if ((dbi = dbiNew(rdb, rpmtag)) == NULL)
	return 1;

    /*
     * Parse db configuration parameters.
     */
    dbConfigure(rpmtag, rdb->db_dbenv == NULL ? &rdb->cfg : NULL, &dbi->cfg);

    /*
     * Map open mode flags onto configured database/environment flags.
     */
    oflags = dbi->cfg.dbi_oflags;
    if ((rdb->db_mode & O_ACCMODE) == O_RDONLY)
	oflags |= DB_RDONLY;

    rc = db_init(rdb, dbhome);

    retry_open = (rc == 0) ? 2 : 0;

    while (retry_open) {
	rc = db_create(&db, rdb->db_dbenv, 0);
	rc = cvtdberr(dbi, "db_create", rc, _debug);

	/* For verify we only want the handle, not an open db */
	if (verifyonly)
	    break;

	if (rc == 0 && db != NULL) {
	    int _printit;
	    char *dbfs = prDbiOpenFlags(oflags, 0);
	    rpmlog(RPMLOG_DEBUG, "opening  db index       %s/%s %s mode=0x%x\n",
		    dbhome, dbi->dbi_file, dbfs, rdb->db_mode);
	    free(dbfs);

	    rc = (db->open)(db, NULL, dbi->dbi_file, NULL,
			    dbtype, oflags, rdb->db_perms);

	    /* Attempt to create if missing, discarding DB_RDONLY (!) */
	    if (rc == ENOENT) {
		oflags |= DB_CREATE;
		oflags &= ~DB_RDONLY;
		dbtype = (rpmtag == RPMDBI_PACKAGES) ?  DB_HASH : DB_BTREE;
		retry_open--;
	    } else {
		retry_open = 0;
	    }

	    /* XXX return rc == errno without printing */
	    _printit = (rc > 0 ? 0 : _debug);
	    rc = cvtdberr(dbi, "db->open", rc, _printit);

	    /* Validate the index type is something we can support */
	    if ((rc == 0) && (dbtype == DB_UNKNOWN)) {
		db->get_type(db, &dbtype);
		if (dbtype != DB_HASH && dbtype != DB_BTREE) {
		    rpmlog(RPMLOG_ERR, _("invalid index type %x on %s/%s\n"),
				dbtype, dbhome, dbi->dbi_file);
		    rc = 1;
		}
	    }

	    if (rc != 0) {
		db->close(db, 0);
		db = NULL;
	    }
	}
    }

    dbi->dbi_db = db;

    dbi->dbi_flags = 0;
    if (oflags & DB_CREATE)
	dbi->dbi_flags |= DBI_CREATED;
    if (oflags & DB_RDONLY)
	dbi->dbi_flags |= DBI_RDONLY;

    if (!verifyonly && rc == 0 && dbi->cfg.dbi_lockdbfd && _lockdbfd++ == 0) {
	rc = dbiFlock(dbi, rdb->db_mode);
    }

    if (rc == 0 && dbi->dbi_db != NULL && dbip != NULL) {
	*dbip = dbi;
    } else {
	(void) dbiClose(dbi, 0);
    }

    return rc;
}
Пример #4
0
Файл: db3.c Проект: xrg/RPM
static int db3open(rpmdb rpmdb, rpmTag rpmtag, dbiIndex * dbip)
{
    extern const struct _dbiVec db3vec;
    const char * root;
    const char * home;
    char * dbhome;
    const char * dbfile;
    const char * dbsubfile;
    dbiIndex dbi = NULL;
    int rc = 0;
    int xx;

    DB * db = NULL;
    DB_ENV * dbenv = NULL;
    DB_TXN * txnid = NULL;
    uint32_t oflags;
    int _printit;

    if (dbip)
	*dbip = NULL;

    /*
     * Parse db configuration parameters.
     */
    if ((dbi = db3New(rpmdb, rpmtag)) == NULL)
	return 1;
    dbi->dbi_api = DB_VERSION_MAJOR;

    /*
     * Get the prefix/root component and directory path.
     */
    root = (dbi->dbi_root ? dbi->dbi_root : rpmdb->db_root);
    if ((root[0] == '/' && root[1] == '\0') || rpmdb->db_chrootDone)
	root = NULL;
    home = (dbi->dbi_home ? dbi->dbi_home : rpmdb->db_home);

    dbhome = rpmGenPath(root, home, NULL);
    if (dbi->dbi_temporary) {
	dbfile = NULL;
	dbsubfile = NULL;
    } else {
#ifdef	HACK	/* XXX necessary to support dbsubfile */
	dbfile = (dbi->dbi_file ? dbi->dbi_file : db3basename);
	dbsubfile = (dbi->dbi_subfile ? dbi->dbi_subfile : rpmTagGetName(dbi->dbi_rpmtag));
#else
	dbfile = (dbi->dbi_file ? dbi->dbi_file : rpmTagGetName(dbi->dbi_rpmtag));
	dbsubfile = NULL;
#endif
    }

    oflags = (dbi->dbi_oeflags | dbi->dbi_oflags);
    oflags &= ~DB_TRUNCATE;	/* XXX this is dangerous */

#if 0	/* XXX rpmdb: illegal flag combination specified to DB->open */
    if ( dbi->dbi_mode & O_EXCL) oflags |= DB_EXCL;
#endif

    /*
     * Map open mode flags onto configured database/environment flags.
     */
    if (dbi->dbi_temporary) {
	oflags |= DB_CREATE;
	dbi->dbi_oeflags |= DB_CREATE;
	oflags &= ~DB_RDONLY;
	dbi->dbi_oflags &= ~DB_RDONLY;
    } else {
	if ((dbi->dbi_mode & O_ACCMODE) == O_RDONLY) oflags |= DB_RDONLY;
	if (dbi->dbi_mode & O_CREAT) {
	    oflags |= DB_CREATE;
	    dbi->dbi_oeflags |= DB_CREATE;
	}
#ifdef	DANGEROUS
	if ( dbi->dbi_mode & O_TRUNC) oflags |= DB_TRUNCATE;
#endif
    }

    /*
     * Create the /var/lib/rpm directory if it doesn't exist (root only).
     */
    (void) rpmioMkpath(dbhome, 0755, getuid(), getgid());

    /*
     * Avoid incompatible DB_CREATE/DB_RDONLY flags on DBENV->open.
     */
    if (dbi->dbi_use_dbenv) {

	if (access(dbhome, W_OK) == -1) {

	    /* dbhome is unwritable, don't attempt DB_CREATE on DB->open ... */
	    oflags &= ~DB_CREATE;

	    /* ... but DBENV->open might still need DB_CREATE ... */
	    if (dbi->dbi_eflags & DB_PRIVATE) {
		dbi->dbi_eflags &= ~DB_JOINENV;
	    } else {
		dbi->dbi_eflags |= DB_JOINENV;
		dbi->dbi_oeflags &= ~DB_CREATE;
		dbi->dbi_oeflags &= ~DB_THREAD;
		/* ... but, unless DB_PRIVATE is used, skip DBENV. */
		dbi->dbi_use_dbenv = 0;
	    }

	    /* ... DB_RDONLY maps dbhome perms across files ...  */
	    if (dbi->dbi_temporary) {
		oflags |= DB_CREATE;
		dbi->dbi_oeflags |= DB_CREATE;
		oflags &= ~DB_RDONLY;
		dbi->dbi_oflags &= ~DB_RDONLY;
	    } else {
		oflags |= DB_RDONLY;
		/* ... and DB_WRITECURSOR won't be needed ...  */
		dbi->dbi_oflags |= DB_RDONLY;
	    }

	} else {	/* dbhome is writable, check for persistent dbenv. */
	    char * dbf = rpmGetPath(dbhome, "/__db.001", NULL);

	    if (access(dbf, F_OK) == -1) {
		/* ... non-existent (or unwritable) DBENV, will create ... */
		dbi->dbi_oeflags |= DB_CREATE;
		dbi->dbi_eflags &= ~DB_JOINENV;
	    } else {
		/* ... pre-existent (or bogus) DBENV, will join ... */
		if (dbi->dbi_eflags & DB_PRIVATE) {
		    dbi->dbi_eflags &= ~DB_JOINENV;
		} else {
		    dbi->dbi_eflags |= DB_JOINENV;
		    dbi->dbi_oeflags &= ~DB_CREATE;
		    dbi->dbi_oeflags &= ~DB_THREAD;
		}
	    }
	    dbf = _free(dbf);
	}
    }

    /*
     * Avoid incompatible DB_CREATE/DB_RDONLY flags on DB->open.
     */
    if ((oflags & DB_CREATE) && (oflags & DB_RDONLY)) {
	/* dbhome is writable, and DB->open flags may conflict. */
	const char * dbfn = (dbfile ? dbfile : rpmTagGetName(dbi->dbi_rpmtag));
	char * dbf = rpmGetPath(dbhome, "/", dbfn, NULL);

	if (access(dbf, F_OK) == -1) {
	    /* File does not exist, DB->open might create ... */
	    oflags &= ~DB_RDONLY;
	} else {
	    /* File exists, DB->open need not create ... */
	    oflags &= ~DB_CREATE;
	}

	/* Only writers need DB_WRITECURSOR ... */
	if (!(oflags & DB_RDONLY) && access(dbf, W_OK) == 0) {
	    dbi->dbi_oflags &= ~DB_RDONLY;
	} else {
	    dbi->dbi_oflags |= DB_RDONLY;
	}
	dbf = _free(dbf);
    }

    /*
     * Turn off verify-on-close if opening read-only.
     */
    if (oflags & DB_RDONLY)
	dbi->dbi_verify_on_close = 0;

    if (dbi->dbi_use_dbenv) {
	if (rpmdb->db_dbenv == NULL) {
	    rc = db_init(dbi, dbhome, dbfile, dbsubfile, &dbenv);
	    if (rc == 0) {
		rpmdb->db_dbenv = dbenv;
		rpmdb->db_opens = 1;
	    }
	} else {
	    dbenv = rpmdb->db_dbenv;
	    rpmdb->db_opens++;
	}
    }

    {	char *dbiflags = prDbiOpenFlags(oflags, 0);
    	rpmlog(RPMLOG_DEBUG, "opening  db index       %s/%s %s mode=0x%x\n",
		dbhome, (dbfile ? dbfile : rpmTagGetName(dbi->dbi_rpmtag)),
		dbiflags, dbi->dbi_mode);
	free(dbiflags);
    }

    if (rc == 0) {
	static int _lockdbfd = 0;

	rc = db_create(&db, dbenv, dbi->dbi_cflags);
	rc = cvtdberr(dbi, "db_create", rc, _debug);
	if (rc == 0 && db != NULL) {

	    if (rc == 0 &&
			rpmdb->db_malloc && rpmdb->db_realloc && rpmdb->db_free)
	    {
		rc = db->set_alloc(db,
			rpmdb->db_malloc, rpmdb->db_realloc, rpmdb->db_free);
		rc = cvtdberr(dbi, "db->set_alloc", rc, _debug);
	    }

/* 4.1: db->set_cache_priority(???) */
	    if (rc == 0 && !dbi->dbi_use_dbenv && dbi->dbi_cachesize) {
		rc = db->set_cachesize(db, 0, dbi->dbi_cachesize, 0);
		rc = cvtdberr(dbi, "db->set_cachesize", rc, _debug);
	    }
/* 4.1: db->set_encrypt(???) */
/* 4.1: db->set_errcall(dbenv, rpmdb->db_errcall); */
/* 4.1: db->set_errfile(dbenv, rpmdb->db_errfile); */
/* 4.1: db->set_errpfx(dbenv, rpmdb->db_errpfx); */
 /* 4.1: db->set_feedback(???) */

	    if (rc == 0 && dbi->dbi_lorder) {
		rc = db->set_lorder(db, dbi->dbi_lorder);
		rc = cvtdberr(dbi, "db->set_lorder", rc, _debug);
	    }
	    if (rc == 0 && dbi->dbi_pagesize) {
		rc = db->set_pagesize(db, dbi->dbi_pagesize);
		rc = cvtdberr(dbi, "db->set_pagesize", rc, _debug);
	    }
 /* 4.1: db->set_paniccall(???) */
	    if (rc == 0 && oflags & DB_CREATE) {
		switch(dbi->dbi_type) {
		default:
		case DB_HASH:
		    if (dbi->dbi_h_ffactor) {
			rc = db->set_h_ffactor(db, dbi->dbi_h_ffactor);
			rc = cvtdberr(dbi, "db->set_h_ffactor", rc, _debug);
			if (rc) break;
		    }
		    if (dbi->dbi_h_nelem) {
			rc = db->set_h_nelem(db, dbi->dbi_h_nelem);
			rc = cvtdberr(dbi, "db->set_h_nelem", rc, _debug);
			if (rc) break;
		    }
		    if (dbi->dbi_h_flags) {
			rc = db->set_flags(db, dbi->dbi_h_flags);
			rc = cvtdberr(dbi, "db->set_h_flags", rc, _debug);
			if (rc) break;
		    }
		    if (dbi->dbi_h_hash_fcn) {
			rc = db->set_h_hash(db, dbi->dbi_h_hash_fcn);
			rc = cvtdberr(dbi, "db->set_h_hash", rc, _debug);
			if (rc) break;
		    }
		    if (dbi->dbi_h_dup_compare_fcn) {
			rc = db->set_dup_compare(db, dbi->dbi_h_dup_compare_fcn);
			rc = cvtdberr(dbi, "db->set_dup_compare", rc, _debug);
			if (rc) break;
		    }
		    break;
		case DB_BTREE:
/* 4.1: db->set_append_recno(???) */
		    if (dbi->dbi_bt_flags) {
			rc = db->set_flags(db, dbi->dbi_bt_flags);
			rc = cvtdberr(dbi, "db->set_bt_flags", rc, _debug);
			if (rc) break;
		    }
		    if (dbi->dbi_bt_minkey) {
			rc = db->set_bt_minkey(db, dbi->dbi_bt_minkey);
			rc = cvtdberr(dbi, "db->set_bt_minkey", rc, _debug);
			if (rc) break;
		    }
		    if (dbi->dbi_bt_compare_fcn) {
			rc = db->set_bt_compare(db, dbi->dbi_bt_compare_fcn);
			rc = cvtdberr(dbi, "db->set_bt_compare", rc, _debug);
			if (rc) break;
		    }
		    if (dbi->dbi_bt_dup_compare_fcn) {
			rc = db->set_dup_compare(db, dbi->dbi_bt_dup_compare_fcn);
			rc = cvtdberr(dbi, "db->set_dup_compare", rc, _debug);
			if (rc) break;
		    }
		    if (dbi->dbi_bt_prefix_fcn) {
			rc = db->set_bt_prefix(db, dbi->dbi_bt_prefix_fcn);
			rc = cvtdberr(dbi, "db->set_bt_prefix", rc, _debug);
			if (rc) break;
		    }
		    break;
		case DB_RECNO:
		    if (dbi->dbi_re_delim) {
/* 4.1: db->set_append_recno(???) */
			rc = db->set_re_delim(db, dbi->dbi_re_delim);
			rc = cvtdberr(dbi, "db->set_re_selim", rc, _debug);
			if (rc) break;
		    }
		    if (dbi->dbi_re_len) {
			rc = db->set_re_len(db, dbi->dbi_re_len);
			rc = cvtdberr(dbi, "db->set_re_len", rc, _debug);
			if (rc) break;
		    }
		    if (dbi->dbi_re_pad) {
			rc = db->set_re_pad(db, dbi->dbi_re_pad);
			rc = cvtdberr(dbi, "db->set_re_pad", rc, _debug);
			if (rc) break;
		    }
		    if (dbi->dbi_re_source) {
			rc = db->set_re_source(db, dbi->dbi_re_source);
			rc = cvtdberr(dbi, "db->set_re_source", rc, _debug);
			if (rc) break;
		    }
		    break;
		case DB_QUEUE:
		    if (dbi->dbi_q_extentsize) {
			rc = db->set_q_extentsize(db, dbi->dbi_q_extentsize);
			rc = cvtdberr(dbi, "db->set_q_extentsize", rc, _debug);
			if (rc) break;
		    }
		    break;
		}
	    }

	    if (rc == 0) {
		char * fullpath;
		const char * dbpath;
		fullpath = rpmGetPath(dbhome, "/", dbfile ? dbfile : "", NULL);

#ifdef	HACK	/* XXX necessary to support dbsubfile */
		dbpath = (!dbi->dbi_use_dbenv && !dbi->dbi_temporary)
			? fullpath : dbfile;
#else
		dbpath = (!dbi->dbi_temporary)
			? fullpath : dbfile;
#endif

		rc = (db->open)(db, txnid, dbpath, dbsubfile,
		    dbi->dbi_type, oflags, dbi->dbi_perms);

		if (rc == 0 && dbi->dbi_type == DB_UNKNOWN) {
		    DBTYPE dbi_type = DB_UNKNOWN;
		    xx = db->get_type(db, &dbi_type);
		    if (xx == 0)
			dbi->dbi_type = dbi_type;
		}
		free(fullpath);
	    }

	    /* XXX return rc == errno without printing */
	    _printit = (rc > 0 ? 0 : _debug);
	    xx = cvtdberr(dbi, "db->open", rc, _printit);

	    dbi->dbi_txnid = NULL;

	    /*
	     * Lock a file using fcntl(2). Traditionally this is Packages,
	     * the file used to store metadata of installed header(s),
	     * as Packages is always opened, and should be opened first,
	     * for any rpmdb access.
	     *
	     * If no DBENV is used, then access is protected with a
	     * shared/exclusive locking scheme, as always.
	     *
	     * With a DBENV, the fcntl(2) lock is necessary only to keep
	     * the riff-raff from playing where they don't belong, as
	     * the DBENV should provide it's own locking scheme. So try to
	     * acquire a lock, but permit failures, as some other
	     * DBENV player may already have acquired the lock.
	     *
	     * With NPTL posix mutexes, revert to fcntl lock on non-functioning
	     * glibc/kernel combinations.
	     */
	    if (rc == 0 && dbi->dbi_lockdbfd &&
		!((dbi->dbi_ecflags & DB_CLIENT) && dbi->dbi_host) &&
		(!dbi->dbi_use_dbenv || _lockdbfd++ == 0))
	    {
		int fdno = -1;

		if (!(db->fd(db, &fdno) == 0 && fdno >= 0)) {
		    rc = 1;
		} else {
		    struct flock l;
		    memset(&l, 0, sizeof(l));
		    l.l_whence = 0;
		    l.l_start = 0;
		    l.l_len = 0;
		    l.l_type = (dbi->dbi_mode & O_ACCMODE) == O_RDONLY
				? F_RDLCK : F_WRLCK;
		    l.l_pid = 0;

		    rc = fcntl(fdno, F_SETLK, (void *) &l);
		    if (rc) {
			/* Warning iff using non-private CDB locking. */
			rc = ((dbi->dbi_use_dbenv &&
				(dbi->dbi_eflags & DB_INIT_CDB) &&
				!(dbi->dbi_eflags & DB_PRIVATE))
			    ? 0 : 1);
			rpmlog( (rc ? RPMLOG_ERR : RPMLOG_WARNING),
				_("cannot get %s lock on %s/%s\n"),
				((dbi->dbi_mode & O_ACCMODE) == O_RDONLY)
					? _("shared") : _("exclusive"),
				dbhome, (dbfile ? dbfile : ""));
		    } else if (dbfile) {
			rpmlog(RPMLOG_DEBUG,
				"locked   db index       %s/%s\n",
				dbhome, dbfile);
		    }
		}
	    }
	}
    }

    dbi->dbi_db = db;

    if (rc == 0 && dbi->dbi_db != NULL && dbip != NULL) {
	dbi->dbi_vec = &db3vec;
	*dbip = dbi;
    } else {
	dbi->dbi_verify_on_close = 0;
	(void) db3close(dbi, 0);
    }

    free(dbhome);

    return rc;
}
Пример #5
0
/* {{{ rberkeley_db_stat */
SEXP rberkeley_db_stat (SEXP _dbp, SEXP _txnid, SEXP _flags)
{
  DB *dbp;
  DB_TXN *txnid;
  DBTYPE type;
  u_int32_t flags;

  dbp = R_ExternalPtrAddr(_dbp);
  if(R_ExternalPtrTag(_dbp) != RBerkeley_DB || dbp == NULL)
    error("invalid 'db' handle");
  if(!isNull(_txnid)) {
    txnid = R_ExternalPtrAddr(_txnid);
  } else txnid = NULL;
  flags = (u_int32_t)INTEGER(_flags)[0];

  dbp->get_type(dbp, &type); /* DBTYPE to know structure returned */
  
  SEXP DBstat=NULL, DBstatnames=NULL;
  DB_HASH_STAT *hash=NULL;
  DB_BTREE_STAT  *bt=NULL;
  DB_QUEUE_STAT  *qs=NULL;
  switch(type) {
    case DB_HASH:
      dbp->stat(dbp, txnid, &hash, flags);
      PROTECT(DBstat = allocVector(VECSXP,16));
      PROTECT(DBstatnames = allocVector(STRSXP,16));
      SET_VECTOR_ELT(DBstat,  0, ScalarInteger(hash->hash_magic));
      SET_STRING_ELT(DBstatnames,  0, mkChar("hash_magic"));
      SET_VECTOR_ELT(DBstat,  1, ScalarInteger(hash->hash_version));
      SET_STRING_ELT(DBstatnames,  1, mkChar("hash_version"));
      SET_VECTOR_ELT(DBstat,  2, ScalarInteger(hash->hash_nkeys));
      SET_STRING_ELT(DBstatnames,  2, mkChar("hash_nkeys"));
      SET_VECTOR_ELT(DBstat,  3, ScalarInteger(hash->hash_ndata));
      SET_STRING_ELT(DBstatnames,  3, mkChar("hash_ndata"));
      SET_VECTOR_ELT(DBstat,  4, ScalarInteger(hash->hash_pagecnt));
      SET_STRING_ELT(DBstatnames,  4, mkChar("hash_pagecnt"));
      SET_VECTOR_ELT(DBstat,  5, ScalarInteger(hash->hash_pagesize));
      SET_STRING_ELT(DBstatnames,  5, mkChar("hash_pagesize"));
      SET_VECTOR_ELT(DBstat,  6, ScalarInteger(hash->hash_ffactor));
      SET_STRING_ELT(DBstatnames,  6, mkChar("hash_ffactor"));
      SET_VECTOR_ELT(DBstat,  7, ScalarInteger(hash->hash_buckets));
      SET_STRING_ELT(DBstatnames,  7, mkChar("hash_buckets"));
      SET_VECTOR_ELT(DBstat,  8, ScalarInteger(hash->hash_free));
      SET_STRING_ELT(DBstatnames,  8, mkChar("hash_free"));
      SET_VECTOR_ELT(DBstat,  9, ScalarInteger(hash->hash_bfree));
      SET_STRING_ELT(DBstatnames,  9, mkChar("hash_bfree"));
      SET_VECTOR_ELT(DBstat, 10, ScalarInteger(hash->hash_bigpages));
      SET_STRING_ELT(DBstatnames,  10, mkChar("hash_bigpages"));
      SET_VECTOR_ELT(DBstat, 11, ScalarInteger(hash->hash_big_bfree));
      SET_STRING_ELT(DBstatnames,  11, mkChar("hash_big_bfree"));
      SET_VECTOR_ELT(DBstat, 12, ScalarInteger(hash->hash_overflows));
      SET_STRING_ELT(DBstatnames,  12, mkChar("hash_overflows"));
      SET_VECTOR_ELT(DBstat, 13, ScalarInteger(hash->hash_ovfl_free));
      SET_STRING_ELT(DBstatnames,  13, mkChar("hash_ovfl_free"));
      SET_VECTOR_ELT(DBstat, 14, ScalarInteger(hash->hash_dup));
      SET_STRING_ELT(DBstatnames,  14, mkChar("hash_dup"));
      SET_VECTOR_ELT(DBstat, 15, ScalarInteger(hash->hash_dup_free));
      SET_STRING_ELT(DBstatnames,  15, mkChar("hash_dup_free"));
    case DB_BTREE:
    case DB_RECNO:
      dbp->stat(dbp, txnid, &bt, flags);
      PROTECT(DBstat = allocVector(VECSXP,19));
      PROTECT(DBstatnames = allocVector(STRSXP,19));
      SET_VECTOR_ELT(DBstat,  0, ScalarInteger(bt->bt_magic));
      SET_STRING_ELT(DBstatnames,  0, mkChar("bt_magic"));
      SET_VECTOR_ELT(DBstat,  1, ScalarInteger(bt->bt_version));
      SET_STRING_ELT(DBstatnames,  1, mkChar("bt_version"));
      SET_VECTOR_ELT(DBstat,  2, ScalarInteger(bt->bt_nkeys));
      SET_STRING_ELT(DBstatnames,  2, mkChar("bt_nkeys"));
      SET_VECTOR_ELT(DBstat,  3, ScalarInteger(bt->bt_ndata));
      SET_STRING_ELT(DBstatnames,  3, mkChar("bt_ndata"));
      SET_VECTOR_ELT(DBstat,  4, ScalarInteger(bt->bt_pagecnt));
      SET_STRING_ELT(DBstatnames,  4, mkChar("bt_pagecnt"));
      SET_VECTOR_ELT(DBstat,  5, ScalarInteger(bt->bt_minkey));
      SET_STRING_ELT(DBstatnames,  5, mkChar("bt_minkey"));
      SET_VECTOR_ELT(DBstat,  6, ScalarInteger(bt->bt_re_len));
      SET_STRING_ELT(DBstatnames,  6, mkChar("bt_re_len"));
      SET_VECTOR_ELT(DBstat,  7, ScalarInteger(bt->bt_re_pad));
      SET_STRING_ELT(DBstatnames,  7, mkChar("bt_re_pad"));
      SET_VECTOR_ELT(DBstat,  8, ScalarInteger(bt->bt_levels));
      SET_STRING_ELT(DBstatnames,  8, mkChar("bt_levels"));
      SET_VECTOR_ELT(DBstat,  9, ScalarInteger(bt->bt_int_pg));
      SET_STRING_ELT(DBstatnames,  9, mkChar("bt_int_pg"));
      SET_VECTOR_ELT(DBstat, 10, ScalarInteger(bt->bt_leaf_pg));
      SET_STRING_ELT(DBstatnames,  10, mkChar("bt_leaf_pg"));
      SET_VECTOR_ELT(DBstat, 11, ScalarInteger(bt->bt_dup_pg));
      SET_STRING_ELT(DBstatnames,  11, mkChar("bt_dup_pg"));
      SET_VECTOR_ELT(DBstat, 12, ScalarInteger(bt->bt_over_pg));
      SET_STRING_ELT(DBstatnames,  12, mkChar("bt_over_pg"));
      SET_VECTOR_ELT(DBstat, 13, ScalarInteger(bt->bt_empty_pg));
      SET_STRING_ELT(DBstatnames,  13, mkChar("bt_empty_pg"));
      SET_VECTOR_ELT(DBstat, 14, ScalarInteger(bt->bt_free));
      SET_STRING_ELT(DBstatnames,  14, mkChar("bt_free"));
      SET_VECTOR_ELT(DBstat, 15, ScalarInteger(bt->bt_int_pgfree));
      SET_STRING_ELT(DBstatnames,  15, mkChar("bt_int_pgfree"));
      SET_VECTOR_ELT(DBstat, 16, ScalarInteger(bt->bt_leaf_pgfree));
      SET_STRING_ELT(DBstatnames,  16, mkChar("bt_leaf_pgfree"));
      SET_VECTOR_ELT(DBstat, 17, ScalarInteger(bt->bt_dup_pgfree));
      SET_STRING_ELT(DBstatnames,  17, mkChar("bt_dup_pgfree"));
      SET_VECTOR_ELT(DBstat, 18, ScalarInteger(bt->bt_over_pgfree));
      SET_STRING_ELT(DBstatnames,  18, mkChar("bt_over_pgfree"));
      break;
    case DB_QUEUE:
      dbp->stat(dbp, txnid, &qs, flags);
      PROTECT(DBstat = allocVector(VECSXP,12));
      PROTECT(DBstatnames = allocVector(STRSXP,12));
      SET_VECTOR_ELT(DBstat,  0, ScalarInteger(qs->qs_magic));
      SET_STRING_ELT(DBstatnames,  0, mkChar("qs_magic"));
      SET_VECTOR_ELT(DBstat,  1, ScalarInteger(qs->qs_version));
      SET_STRING_ELT(DBstatnames,  1, mkChar("qs_version"));
      SET_VECTOR_ELT(DBstat,  2, ScalarInteger(qs->qs_nkeys));
      SET_STRING_ELT(DBstatnames,  2, mkChar("qs_nkeys"));
      SET_VECTOR_ELT(DBstat,  3, ScalarInteger(qs->qs_ndata));
      SET_STRING_ELT(DBstatnames,  3, mkChar("qs_ndata"));
      SET_VECTOR_ELT(DBstat,  4, ScalarInteger(qs->qs_pagesize));
      SET_STRING_ELT(DBstatnames,  4, mkChar("qs_pagesize"));
      SET_VECTOR_ELT(DBstat,  5, ScalarInteger(qs->qs_extentsize));
      SET_STRING_ELT(DBstatnames,  5, mkChar("qs_extentsize"));
      SET_VECTOR_ELT(DBstat,  6, ScalarInteger(qs->qs_pages));
      SET_STRING_ELT(DBstatnames,  6, mkChar("qs_pages"));
      SET_VECTOR_ELT(DBstat,  7, ScalarInteger(qs->qs_re_len));
      SET_STRING_ELT(DBstatnames,  7, mkChar("qs_re_len"));
      SET_VECTOR_ELT(DBstat,  8, ScalarInteger(qs->qs_re_pad));
      SET_STRING_ELT(DBstatnames,  8, mkChar("qs_re_pad"));
      SET_VECTOR_ELT(DBstat,  9, ScalarInteger(qs->qs_pgfree));
      SET_STRING_ELT(DBstatnames,  9, mkChar("qs_pgfree"));
      SET_VECTOR_ELT(DBstat, 10, ScalarInteger(qs->qs_first_recno));
      SET_STRING_ELT(DBstatnames,  10, mkChar("qs_first_recno"));
      SET_VECTOR_ELT(DBstat, 11, ScalarInteger(qs->qs_cur_recno));
      SET_STRING_ELT(DBstatnames,  11, mkChar("qs_cur_recno"));
      break;
    case DB_UNKNOWN:
      error("DB_UNKNOWN"); /* FIXME not too sure of correct handling here */
      break;
  }
  setAttrib(DBstat, R_NamesSymbol, DBstatnames); 
  UNPROTECT(2);
  return(DBstat);   
}
Пример #6
0
DBTYPE Db::get_type() const
{
	DB *db = (DB *)unwrapConst(this);
	return ((DBTYPE)db->get_type(db));
}