00001 /*- 00002 * See the file LICENSE for redistribution information. 00003 * 00004 * Copyright (c) 1999, 2000 00005 * Sleepycat Software. All rights reserved. 00006 * 00007 * $Id: db__verify_8h-source.html,v 1.1 2008/06/08 10:18:23 sebdiaz Exp $ 00008 */ 00009 00010 #ifndef _DB_VERIFY_H 00011 #define _DB_VERIFY_H_ 00012 00013 /* 00014 * Structures and macros for the storage and retrieval of all information 00015 * needed for inter-page verification of a database. 00016 */ 00017 00018 /* 00019 * EPRINT is the macro for error printing. Takes as an arg the arg set 00020 * for DB->err. 00021 */ 00022 #define EPRINT(x) \ 00023 do { \ 00024 if (!LF_ISSET(DB_SALVAGE)) \ 00025 CDB___db_err x; \ 00026 } while (0) 00027 00028 #define TYPE_ERR_PRINT(dbp, func, pgno, type) \ 00029 EPRINT(((dbp), "%s called on nonsensical page %lu of type %lu", \ 00030 (func), (u_long)(pgno), (u_long)(type))); 00031 00032 /* Is x a power of two? (Tests true for zero, which doesn't matter here.) */ 00033 #define POWER_OF_TWO(x) (((x) & ((x) - 1)) == 0) 00034 00035 #define IS_VALID_PAGESIZE(x) \ 00036 (POWER_OF_TWO(x) && (x) >= DB_MIN_PGSIZE && ((x) <= DB_MAX_PGSIZE)) 00037 00038 /* 00039 * Note that 0 is, in general, a valid pgno, despite equalling PGNO_INVALID; 00040 * we have to test it separately where it's not appropriate. 00041 */ 00042 #define IS_VALID_PGNO(x) ((x) <= vdp->last_pgno) 00043 00044 /* 00045 * Flags understood by the btree structure checks (esp. CDB___bam_vrfy_subtree). 00046 * These share the same space as the global flags to CDB___db_verify, and must not 00047 * dip below 0x00010000. 00048 */ 00049 #define ST_DUPOK 0x00010000 00050 #define ST_DUPSORT 0x00020000 00051 #define ST_IS_RECNO 0x00040000 00052 #define ST_OVFL_LEAF 0x00080000 /* Overflow reffed from leaf page. */ 00053 #define ST_RECNUM 0x00100000 00054 #define ST_RELEN 0x00200000 00055 #define ST_TOPLEVEL 0x00400000 /* subtree == entire tree */ 00056 00057 /* 00058 * Flags understood by CDB___bam_salvage and CDB___db_salvage. These need not share 00059 * the same space with the CDB___bam_vrfy_subtree flags, but must share with 00060 * CDB___db_verify. 00061 */ 00062 #define SA_HASDUPS 0x00010000 00063 #define SA_MARKDATAPGS 0x00020000 00064 #define SA_PRINTHEADER 0x00040000 00065 #define SA_SKIPFIRSTKEY 0x00080000 00066 00067 /* 00068 * VRFY_DBINFO is the fundamental structure; it either represents the database 00069 * of subdatabases, or the sole database if there are no subdatabases. 00070 */ 00071 struct __vrfy_dbinfo { 00072 /* Info about this database in particular. */ 00073 DBTYPE type; 00074 00075 /* List of subdatabase meta pages, if any. */ 00076 LIST_HEAD(__subdbs, __vrfy_childinfo) subdbs; 00077 00078 /* File-global info--stores VRFY_PAGEINFOs for each page. */ 00079 DB *pgdbp; 00080 00081 /* Child database--stores VRFY_CHILDINFOs of each page. */ 00082 DB *cdbp; 00083 00084 /* Page info structures currently in use. */ 00085 LIST_HEAD(__activepips, __vrfy_pageinfo) activepips; 00086 00087 /* 00088 * DB we use to keep track of which pages are linked somehow 00089 * during verification. 0 is the default, "unseen"; 1 is seen. 00090 */ 00091 DB *pgset; 00092 00093 /* 00094 * This is a database we use during salvaging to keep track of which 00095 * overflow and dup pages we need to come back to at the end and print 00096 * with key "UNKNOWN". Pages which print with a good key get set 00097 * to SALVAGE_IGNORE; others get set, as appropriate, to SALVAGE_LDUP, 00098 * SALVAGE_LRECNODUP, SALVAGE_OVERFLOW for normal db overflow pages, 00099 * and SALVAGE_BTREE, SALVAGE_LRECNO, and SALVAGE_HASH for subdb 00100 * pages. 00101 */ 00102 #define SALVAGE_INVALID 0 00103 #define SALVAGE_IGNORE 1 00104 #define SALVAGE_LDUP 2 00105 #define SALVAGE_LRECNODUP 3 00106 #define SALVAGE_OVERFLOW 4 00107 #define SALVAGE_LBTREE 5 00108 #define SALVAGE_HASH 6 00109 #define SALVAGE_LRECNO 7 00110 DB *salvage_pages; 00111 00112 db_pgno_t last_pgno; 00113 00114 /* Queue needs these to verify data pages in the first pass. */ 00115 u_int32_t re_len; 00116 u_int32_t rec_page; 00117 00118 #define SALVAGE_PRINTHEADER 0x01 00119 #define SALVAGE_PRINTFOOTER 0x02 00120 u_int32_t flags; 00121 }; /* VRFY_DBINFO */ 00122 00123 /* 00124 * The amount of state information we need per-page is small enough that 00125 * it's not worth the trouble to define separate structures for each 00126 * possible type of page, and since we're doing verification with these we 00127 * have to be open to the possibility that page N will be of a completely 00128 * unexpected type anyway. So we define one structure here with all the 00129 * info we need for inter-page verification. 00130 */ 00131 struct __vrfy_pageinfo { 00132 u_int8_t type; 00133 u_int8_t bt_level; 00134 u_int8_t unused1; 00135 u_int8_t unused2; 00136 db_pgno_t pgno; 00137 db_pgno_t prev_pgno; 00138 db_pgno_t next_pgno; 00139 00140 /* meta pages */ 00141 db_pgno_t root; 00142 db_pgno_t free; /* Free list head. */ 00143 00144 db_indx_t entries; /* Actual number of entries. */ 00145 u_int16_t unused; 00146 db_recno_t rec_cnt; /* Record count. */ 00147 u_int32_t re_len; /* Record length. */ 00148 u_int32_t bt_minkey; 00149 u_int32_t bt_maxkey; 00150 u_int32_t h_ffactor; 00151 u_int32_t h_nelem; 00152 00153 /* overflow pages */ 00154 /* 00155 * Note that refcount is the refcount for an overflow page; pi_refcount 00156 * is this structure's own refcount! 00157 */ 00158 u_int32_t refcount; 00159 u_int32_t olen; 00160 00161 #define VRFY_DUPS_UNSORTED 0x0001 /* Have to flag the negative! */ 00162 #define VRFY_HAS_DUPS 0x0002 00163 #define VRFY_HAS_DUPSORT 0x0004 /* Has the flag set. */ 00164 #define VRFY_HAS_SUBDBS 0x0008 00165 #define VRFY_HAS_RECNUMS 0x0010 00166 #define VRFY_INCOMPLETE 0x0020 /* Meta or item order checks incomp. */ 00167 #define VRFY_IS_ALLZEROES 0x0040 /* Hash page we haven't touched? */ 00168 #define VRFY_IS_FIXEDLEN 0x0080 00169 #define VRFY_IS_RECNO 0x0100 00170 #define VRFY_IS_RRECNO 0x0200 00171 #define VRFY_OVFL_LEAFSEEN 0x0400 00172 u_int32_t flags; 00173 00174 LIST_ENTRY(__vrfy_pageinfo) links; 00175 u_int32_t pi_refcount; 00176 }; /* VRFY_PAGEINFO */ 00177 00178 struct __vrfy_childinfo { 00179 db_pgno_t pgno; 00180 00181 #define V_DUPLICATE 1 /* off-page dup metadata */ 00182 #define V_OVERFLOW 2 /* overflow page */ 00183 #define V_RECNO 3 /* btree internal or leaf page */ 00184 u_int32_t type; 00185 db_recno_t nrecs; /* record count on a btree subtree */ 00186 u_int32_t tlen; /* ovfl. item total size */ 00187 00188 LIST_ENTRY(__vrfy_childinfo) links; 00189 }; /* VRFY_CHILDINFO */ 00190 00191 #endif /* _DB_VERIFY_H_ */