📄 db_method.c
字号:
/* * __db_set_cachesize -- * Set underlying cache size. */static int__db_set_cachesize(dbp, cache_gbytes, cache_bytes, ncache) DB *dbp; u_int32_t cache_gbytes, cache_bytes; int ncache;{ DB_ILLEGAL_IN_ENV(dbp, "set_cachesize"); DB_ILLEGAL_AFTER_OPEN(dbp, "set_cachesize"); return (dbp->dbenv->set_cachesize( dbp->dbenv, cache_gbytes, cache_bytes, ncache));}/* * __db_set_cache_priority -- * Set cache priority for pages from this file. */static int__db_set_cache_priority(dbp, priority) DB *dbp; DB_CACHE_PRIORITY priority;{ /* * If an underlying DB_MPOOLFILE exists, call it. Otherwise, save * the information away until DB->open is called. */ if (dbp->mpf == NULL) { dbp->priority = priority; return (0); } return (dbp->mpf->set_priority(dbp->mpf, priority));}/* * __db_set_dup_compare -- * Set duplicate comparison routine. */static int__db_set_dup_compare(dbp, func) DB *dbp; int (*func) __P((DB *, const DBT *, const DBT *));{ int ret; DB_ILLEGAL_AFTER_OPEN(dbp, "dup_compare"); DB_ILLEGAL_METHOD(dbp, DB_OK_BTREE | DB_OK_HASH); if ((ret = dbp->set_flags(dbp, DB_DUPSORT)) != 0) return (ret); dbp->dup_compare = func; return (0);}/* * __db_set_encrypt -- * Set database passwd. */static int__db_set_encrypt(dbp, passwd, flags) DB *dbp; const char *passwd; u_int32_t flags;{ DB_CIPHER *db_cipher; int ret; DB_ILLEGAL_IN_ENV(dbp, "set_encrypt"); DB_ILLEGAL_AFTER_OPEN(dbp, "set_encrypt"); if ((ret = dbp->dbenv->set_encrypt(dbp->dbenv, passwd, flags)) != 0) return (ret); /* * In a real env, this gets initialized with the region. In a local * env, we must do it here. */ db_cipher = (DB_CIPHER *)dbp->dbenv->crypto_handle; if (!F_ISSET(db_cipher, CIPHER_ANY) && (ret = db_cipher->init(dbp->dbenv, db_cipher)) != 0) return (ret); return (dbp->set_flags(dbp, DB_ENCRYPT));}static void__db_set_errcall(dbp, errcall) DB *dbp; void (*errcall) __P((const char *, char *));{ dbp->dbenv->set_errcall(dbp->dbenv, errcall);}static void__db_set_errfile(dbp, errfile) DB *dbp; FILE *errfile;{ dbp->dbenv->set_errfile(dbp->dbenv, errfile);}static void__db_set_errpfx(dbp, errpfx) DB *dbp; const char *errpfx;{ dbp->dbenv->set_errpfx(dbp->dbenv, errpfx);}static int__db_set_feedback(dbp, feedback) DB *dbp; void (*feedback) __P((DB *, int, int));{ dbp->db_feedback = feedback; return (0);}static int__db_set_flags(dbp, flags) DB *dbp; u_int32_t flags;{ int ret; /* * !!! * The hash access method only takes two flags: DB_DUP and DB_DUPSORT. * The Btree access method uses them for the same purposes, and so we * resolve them there. * * The queue access method takes no flags. */ if (LF_ISSET(DB_ENCRYPT)) { if (!CRYPTO_ON(dbp->dbenv)) { __db_err(dbp->dbenv, "Database environment not configured for encryption"); return (EINVAL); } F_SET(dbp, DB_AM_ENCRYPT); F_SET(dbp, DB_AM_CHKSUM); LF_CLR(DB_ENCRYPT); } if (LF_ISSET(DB_CHKSUM_SHA1)) { F_SET(dbp, DB_AM_CHKSUM); LF_CLR(DB_CHKSUM_SHA1); } if ((ret = __bam_set_flags(dbp, &flags)) != 0) return (ret); if ((ret = __ram_set_flags(dbp, &flags)) != 0) return (ret); return (flags == 0 ? 0 : __db_ferr(dbp->dbenv, "DB->set_flags", 0));}/* * __db_set_lorder -- * Set whether lorder is swapped or not. * * PUBLIC: int __db_set_lorder __P((DB *, int)); */int__db_set_lorder(dbp, db_lorder) DB *dbp; int db_lorder;{ int ret; DB_ILLEGAL_AFTER_OPEN(dbp, "set_lorder"); /* Flag if the specified byte order requires swapping. */ switch (ret = __db_byteorder(dbp->dbenv, db_lorder)) { case 0: F_CLR(dbp, DB_AM_SWAP); break; case DB_SWAPBYTES: F_SET(dbp, DB_AM_SWAP); break; default: return (ret); /* NOTREACHED */ } return (0);}static int__db_set_alloc(dbp, mal_func, real_func, free_func) DB *dbp; void *(*mal_func) __P((size_t)); void *(*real_func) __P((void *, size_t)); void (*free_func) __P((void *));{ DB_ILLEGAL_IN_ENV(dbp, "set_alloc"); DB_ILLEGAL_AFTER_OPEN(dbp, "set_alloc"); return (dbp->dbenv->set_alloc(dbp->dbenv, mal_func, real_func, free_func));}static int__db_set_pagesize(dbp, db_pagesize) DB *dbp; u_int32_t db_pagesize;{ DB_ILLEGAL_AFTER_OPEN(dbp, "set_pagesize"); if (db_pagesize < DB_MIN_PGSIZE) { __db_err(dbp->dbenv, "page sizes may not be smaller than %lu", (u_long)DB_MIN_PGSIZE); return (EINVAL); } if (db_pagesize > DB_MAX_PGSIZE) { __db_err(dbp->dbenv, "page sizes may not be larger than %lu", (u_long)DB_MAX_PGSIZE); return (EINVAL); } /* * We don't want anything that's not a power-of-2, as we rely on that * for alignment of various types on the pages. */ if (!POWER_OF_TWO(db_pagesize)) { __db_err(dbp->dbenv, "page sizes must be a power-of-2"); return (EINVAL); } /* * XXX * Should we be checking for a page size that's not a multiple of 512, * so that we never try and write less than a disk sector? */ dbp->pgsize = db_pagesize; return (0);}static int__db_set_paniccall(dbp, paniccall) DB *dbp; void (*paniccall) __P((DB_ENV *, int));{ return (dbp->dbenv->set_paniccall(dbp->dbenv, paniccall));}static int__db_stat_fail(dbp, sp, flags) DB *dbp; void *sp; u_int32_t flags;{ COMPQUIET(sp, NULL); COMPQUIET(flags, 0); /* * DB->stat isn't initialized until the actual DB->open call, * but we don't want to core dump. */ PANIC_CHECK(dbp->dbenv); DB_ILLEGAL_BEFORE_OPEN(dbp, "DB->stat"); /* NOTREACHED */ return (EINVAL);}#ifdef HAVE_RPC/* * __dbcl_init -- * Initialize a DB structure on the server. */static int__dbcl_init(dbp, dbenv, flags) DB *dbp; DB_ENV *dbenv; u_int32_t flags;{ TAILQ_INIT(&dbp->free_queue); TAILQ_INIT(&dbp->active_queue); /* !!! * Note that we don't need to initialize the join_queue; it's * not used in RPC clients. See the comment in __dbcl_db_join_ret(). */ dbp->associate = __dbcl_db_associate; dbp->close = __dbcl_db_close; dbp->cursor = __dbcl_db_cursor; dbp->del = __dbcl_db_del; dbp->err = __dbh_err; dbp->errx = __dbh_errx; dbp->fd = __dbcl_db_fd; dbp->get = __dbcl_db_get; dbp->get_byteswapped = __db_get_byteswapped; dbp->get_type = __db_get_type; dbp->join = __dbcl_db_join; dbp->key_range = __dbcl_db_key_range; dbp->open = __dbcl_db_open_wrap; dbp->pget = __dbcl_db_pget; dbp->put = __dbcl_db_put; dbp->remove = __dbcl_db_remove; dbp->rename = __dbcl_db_rename; dbp->set_alloc = __dbcl_db_alloc; dbp->set_append_recno = __dbcl_db_set_append_recno; dbp->set_cachesize = __dbcl_db_cachesize; dbp->set_cache_priority = __dbcl_db_cache_priority; dbp->set_dup_compare = __dbcl_db_dup_compare; dbp->set_encrypt = __dbcl_db_encrypt; dbp->set_errcall = __db_set_errcall; dbp->set_errfile = __db_set_errfile; dbp->set_errpfx = __db_set_errpfx; dbp->set_feedback = __dbcl_db_feedback; dbp->set_flags = __dbcl_db_flags; dbp->set_lorder = __dbcl_db_lorder; dbp->set_pagesize = __dbcl_db_pagesize; dbp->set_paniccall = __dbcl_db_panic; dbp->stat = __dbcl_db_stat; dbp->sync = __dbcl_db_sync; dbp->truncate = __dbcl_db_truncate; dbp->upgrade = __dbcl_db_upgrade; dbp->verify = __dbcl_db_verify; /* * Set all the method specific functions to client funcs as well. */ dbp->set_bt_compare = __dbcl_db_bt_compare; dbp->set_bt_maxkey = __dbcl_db_bt_maxkey; dbp->set_bt_minkey = __dbcl_db_bt_minkey; dbp->set_bt_prefix = __dbcl_db_bt_prefix; dbp->set_h_ffactor = __dbcl_db_h_ffactor; dbp->set_h_hash = __dbcl_db_h_hash; dbp->set_h_nelem = __dbcl_db_h_nelem; dbp->set_q_extentsize = __dbcl_db_extentsize; dbp->set_re_delim = __dbcl_db_re_delim; dbp->set_re_len = __dbcl_db_re_len; dbp->set_re_pad = __dbcl_db_re_pad; dbp->set_re_source = __dbcl_db_re_source; return (__dbcl_db_create(dbp, dbenv, flags));}#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -