📄 db_pr.c
字号:
void *vfp;{ FILE *fp; const FN *fnp; int found; const char *sep; /* * We pass the FILE * through a void * so that we can use * this function as as a callback. */ fp = (FILE *)vfp; sep = " ("; for (found = 0, fnp = fn; fnp->mask != 0; ++fnp) if (LF_ISSET(fnp->mask)) { fprintf(fp, "%s%s", sep, fnp->name); sep = ", "; found = 1; } if (found) fprintf(fp, ")");}/* * __db_dbtype_to_string -- * Return the name of the database type. * PUBLIC: const char * __db_dbtype_to_string __P((DBTYPE)); */const char *__db_dbtype_to_string(type) DBTYPE type;{ switch (type) { case DB_BTREE: return ("btree"); case DB_HASH: return ("hash"); case DB_RECNO: return ("recno"); case DB_QUEUE: return ("queue"); default: return ("UNKNOWN TYPE"); } /* NOTREACHED */}/* * __db_pagetype_to_string -- * Return the name of the specified page type. */static const char *__db_pagetype_to_string(type) u_int32_t type;{ char *s; s = NULL; switch (type) { case P_BTREEMETA: s = "btree metadata"; break; case P_LDUP: s = "duplicate"; break; case P_HASH: s = "hash"; break; case P_HASHMETA: s = "hash metadata"; break; case P_IBTREE: s = "btree internal"; break; case P_INVALID: s = "invalid"; break; case P_IRECNO: s = "recno internal"; break; case P_LBTREE: s = "btree leaf"; break; case P_LRECNO: s = "recno leaf"; break; case P_OVERFLOW: s = "overflow"; break; case P_QAMMETA: s = "queue metadata"; break; case P_QAMDATA: s = "queue"; break; default: /* Just return a NULL. */ break; } return (s);}/* * __db_prheader -- * Write out header information in the format expected by db_load. * * PUBLIC: int __db_prheader __P((DB *, char *, int, int, void *, * PUBLIC: int (*)(void *, const void *), VRFY_DBINFO *, db_pgno_t)); */int__db_prheader(dbp, subname, pflag, keyflag, handle, callback, vdp, meta_pgno) DB *dbp; char *subname; int pflag, keyflag; void *handle; int (*callback) __P((void *, const void *)); VRFY_DBINFO *vdp; db_pgno_t meta_pgno;{ DB_BTREE_STAT *btsp; DB_ENV *dbenv; DB_HASH_STAT *hsp; DB_QUEUE_STAT *qsp; DBT dbt; VRFY_PAGEINFO *pip; char *buf; int buflen, ret, t_ret; u_int32_t dbtype; btsp = NULL; hsp = NULL; qsp = NULL; ret = 0; buf = NULL; COMPQUIET(buflen, 0); if (dbp == NULL) dbenv = NULL; else dbenv = dbp->dbenv; /* * If we've been passed a verifier statistics object, use * that; we're being called in a context where dbp->stat * is unsafe. * * Also, the verifier may set the pflag on a per-salvage basis. * If so, respect that. */ if (vdp != NULL) { if ((ret = __db_vrfy_getpageinfo(vdp, meta_pgno, &pip)) != 0) return (ret); if (F_ISSET(vdp, SALVAGE_PRINTABLE)) pflag = 1; } else pip = NULL; /* * If dbp is NULL, we're being called from inside __db_prdbt, * and this is a special subdatabase for "lost" items. Make it a btree. * Otherwise, set dbtype to the appropriate type for the specified * meta page, or the type of the dbp. */ if (dbp == NULL) dbtype = DB_BTREE; else if (pip != NULL) switch (pip->type) { case P_BTREEMETA: if (F_ISSET(pip, VRFY_IS_RECNO)) dbtype = DB_RECNO; else dbtype = DB_BTREE; break; case P_HASHMETA: dbtype = DB_HASH; break; default: /* * If the meta page is of a bogus type, it's * because we have a badly corrupt database. * (We must be in the verifier for pip to be non-NULL.) * Pretend we're a Btree and salvage what we can. */ DB_ASSERT(F_ISSET(dbp, DB_AM_VERIFYING)); dbtype = DB_BTREE; break; } else dbtype = dbp->type; if ((ret = callback(handle, "VERSION=3\n")) != 0) goto err; if (pflag) { if ((ret = callback(handle, "format=print\n")) != 0) goto err; } else if ((ret = callback(handle, "format=bytevalue\n")) != 0) goto err; /* * 64 bytes is long enough, as a minimum bound, for any of the * fields besides subname. Subname uses __db_prdbt and therefore * does not need buffer space here. */ buflen = 64; if ((ret = __os_malloc(dbenv, buflen, &buf)) != 0) goto err; if (subname != NULL) { snprintf(buf, buflen, "database="); if ((ret = callback(handle, buf)) != 0) goto err; memset(&dbt, 0, sizeof(dbt)); dbt.data = subname; dbt.size = (u_int32_t)strlen(subname); if ((ret = __db_prdbt(&dbt, 1, NULL, handle, callback, 0, NULL)) != 0) goto err; } switch (dbtype) { case DB_BTREE: if ((ret = callback(handle, "type=btree\n")) != 0) goto err; if (pip != NULL) { if (F_ISSET(pip, VRFY_HAS_RECNUMS)) if ((ret = callback(handle, "recnum=1\n")) != 0) goto err; if (pip->bt_maxkey != 0) { snprintf(buf, buflen, "bt_maxkey=%lu\n", (u_long)pip->bt_maxkey); if ((ret = callback(handle, buf)) != 0) goto err; } if (pip->bt_minkey != 0 && pip->bt_minkey != DEFMINKEYPAGE) { snprintf(buf, buflen, "bt_minkey=%lu\n", (u_long)pip->bt_minkey); if ((ret = callback(handle, buf)) != 0) goto err; } break; } if ((ret = dbp->stat(dbp, &btsp, 0)) != 0) { dbp->err(dbp, ret, "DB->stat"); goto err; } if (F_ISSET(dbp, DB_AM_RECNUM)) if ((ret = callback(handle, "recnum=1\n")) != 0) goto err; if (btsp->bt_maxkey != 0) { snprintf(buf, buflen, "bt_maxkey=%lu\n", (u_long)btsp->bt_maxkey); if ((ret = callback(handle, buf)) != 0) goto err; } if (btsp->bt_minkey != 0 && btsp->bt_minkey != DEFMINKEYPAGE) { snprintf(buf, buflen, "bt_minkey=%lu\n", (u_long)btsp->bt_minkey); if ((ret = callback(handle, buf)) != 0) goto err; } break; case DB_HASH: if ((ret = callback(handle, "type=hash\n")) != 0) goto err; if (pip != NULL) { if (pip->h_ffactor != 0) { snprintf(buf, buflen, "h_ffactor=%lu\n", (u_long)pip->h_ffactor); if ((ret = callback(handle, buf)) != 0) goto err; } if (pip->h_nelem != 0) { snprintf(buf, buflen, "h_nelem=%lu\n", (u_long)pip->h_nelem); if ((ret = callback(handle, buf)) != 0) goto err; } break; } if ((ret = dbp->stat(dbp, &hsp, 0)) != 0) { dbp->err(dbp, ret, "DB->stat"); goto err; } if (hsp->hash_ffactor != 0) { snprintf(buf, buflen, "h_ffactor=%lu\n", (u_long)hsp->hash_ffactor); if ((ret = callback(handle, buf)) != 0) goto err; } if (hsp->hash_nkeys != 0) { snprintf(buf, buflen, "h_nelem=%lu\n", (u_long)hsp->hash_nkeys); if ((ret = callback(handle, buf)) != 0) goto err; } break; case DB_QUEUE: if ((ret = callback(handle, "type=queue\n")) != 0) goto err; if (vdp != NULL) { snprintf(buf, buflen, "re_len=%lu\n", (u_long)vdp->re_len); if ((ret = callback(handle, buf)) != 0) goto err; break; } if ((ret = dbp->stat(dbp, &qsp, 0)) != 0) { dbp->err(dbp, ret, "DB->stat"); goto err; } snprintf(buf, buflen, "re_len=%lu\n", (u_long)qsp->qs_re_len); if ((ret = callback(handle, buf)) != 0) goto err; if (qsp->qs_re_pad != 0 && qsp->qs_re_pad != ' ') { snprintf(buf, buflen, "re_pad=%#x\n", qsp->qs_re_pad); if ((ret = callback(handle, buf)) != 0) goto err; } if (qsp->qs_extentsize != 0) { snprintf(buf, buflen, "extentsize=%lu\n", (u_long)qsp->qs_extentsize); if ((ret = callback(handle, buf)) != 0) goto err; } break; case DB_RECNO: if ((ret = callback(handle, "type=recno\n")) != 0) goto err; if (pip != NULL) { if (F_ISSET(pip, VRFY_IS_RRECNO)) if ((ret = callback(handle, "renumber=1\n")) != 0) goto err; if (pip->re_len > 0) { snprintf(buf, buflen, "re_len=%lu\n", (u_long)pip->re_len); if ((ret = callback(handle, buf)) != 0) goto err; } break; } if ((ret = dbp->stat(dbp, &btsp, 0)) != 0) { dbp->err(dbp, ret, "DB->stat"); goto err; } if (F_ISSET(dbp, DB_AM_RENUMBER)) if ((ret = callback(handle, "renumber=1\n")) != 0) goto err; if (F_ISSET(dbp, DB_AM_FIXEDLEN)) { snprintf(buf, buflen, "re_len=%lu\n", (u_long)btsp->bt_re_len); if ((ret = callback(handle, buf)) != 0) goto err; } if (btsp->bt_re_pad != 0 && btsp->bt_re_pad != ' ') { snprintf(buf, buflen, "re_pad=%#x\n", btsp->bt_re_pad); if ((ret = callback(handle, buf)) != 0) goto err; } break; case DB_UNKNOWN: DB_ASSERT(0); /* Impossible. */ __db_err(dbp->dbenv, "Impossible DB type in __db_prheader"); ret = EINVAL; goto err; } if (pip != NULL) { if (F_ISSET(pip, VRFY_HAS_DUPS)) if ((ret = callback(handle, "duplicates=1\n")) != 0) goto err; if (F_ISSET(pip, VRFY_HAS_DUPSORT)) if ((ret = callback(handle, "dupsort=1\n")) != 0) goto err; /* We should handle page size. XXX */ } else { if (F_ISSET(dbp, DB_AM_CHKSUM)) if ((ret = callback(handle, "chksum=1\n")) != 0) goto err; if (F_ISSET(dbp, DB_AM_DUP)) if ((ret = callback(handle, "duplicates=1\n")) != 0) goto err; if (F_ISSET(dbp, DB_AM_DUPSORT)) if ((ret = callback(handle, "dupsort=1\n")) != 0) goto err; if (!F_ISSET(dbp, DB_AM_PGDEF)) { snprintf(buf, buflen, "db_pagesize=%lu\n", (u_long)dbp->pgsize); if ((ret = callback(handle, buf)) != 0) goto err; } } if (keyflag && (ret = callback(handle, "keys=1\n")) != 0) goto err; ret = callback(handle, "HEADER=END\n");err: if (pip != NULL && (t_ret = __db_vrfy_putpageinfo(dbenv, vdp, pip)) != 0 && ret == 0) ret = t_ret; if (btsp != NULL) __os_ufree(dbenv, btsp); if (hsp != NULL) __os_ufree(dbenv, hsp); if (qsp != NULL) __os_ufree(dbenv, qsp); if (buf != NULL) __os_free(dbenv, buf); return (ret);}/* * __db_prfooter -- * Print the footer that marks the end of a DB dump. This is trivial, * but for consistency's sake we don't want to put its literal contents * in multiple places. * * PUBLIC: int __db_prfooter __P((void *, int (*)(void *, const void *))); */int__db_prfooter(handle, callback) void *handle; int (*callback) __P((void *, const void *));{ return (callback(handle, "DATA=END\n"));}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -