1/*- 2 * See the file LICENSE for redistribution information. 3 * 4 * Copyright (c) 1999,2008 Oracle. All rights reserved. 5 * 6 * $Id: db_verify.h,v 12.17 2008/05/07 12:27:33 bschmeck Exp $ 7 */ 8 9#ifndef _DB_VERIFY_H_ 10#define _DB_VERIFY_H_ 11 12#if defined(__cplusplus) 13extern "C" { 14#endif 15 16/* 17 * Structures and macros for the storage and retrieval of all information 18 * needed for inter-page verification of a database. 19 */ 20 21/* 22 * EPRINT is the macro for error printing. Takes as an arg the arg set 23 * for DB->err. 24 */ 25#define EPRINT(x) do { \ 26 if (!LF_ISSET(DB_SALVAGE)) \ 27 __db_errx x; \ 28} while (0) 29 30/* Complain about a totally zeroed page where we don't expect one. */ 31#define ZEROPG_ERR_PRINT(dbenv, pgno, str) do { \ 32 EPRINT(((dbenv), "Page %lu: %s is of inappropriate type %lu", \ 33 (u_long)(pgno), str, (u_long)P_INVALID)); \ 34 EPRINT(((dbenv), "Page %lu: totally zeroed page", \ 35 (u_long)(pgno))); \ 36} while (0) 37 38/* 39 * Note that 0 is, in general, a valid pgno, despite equaling PGNO_INVALID; 40 * we have to test it separately where it's not appropriate. 41 */ 42#define IS_VALID_PGNO(x) ((x) <= vdp->last_pgno) 43 44/* 45 * VRFY_DBINFO is the fundamental structure; it either represents the database 46 * of subdatabases, or the sole database if there are no subdatabases. 47 */ 48struct __vrfy_dbinfo { 49 DB_THREAD_INFO *thread_info; 50 /* Info about this database in particular. */ 51 DBTYPE type; 52 53 /* List of subdatabase meta pages, if any. */ 54 LIST_HEAD(__subdbs, __vrfy_childinfo) subdbs; 55 56 /* File-global info--stores VRFY_PAGEINFOs for each page. */ 57 DB *pgdbp; 58 59 /* Child database--stores VRFY_CHILDINFOs of each page. */ 60 DB *cdbp; 61 62 /* Page info structures currently in use. */ 63 LIST_HEAD(__activepips, __vrfy_pageinfo) activepips; 64 65 /* 66 * DB we use to keep track of which pages are linked somehow 67 * during verification. 0 is the default, "unseen"; 1 is seen. 68 */ 69 DB *pgset; 70 71 /* 72 * This is a database we use during salvaging to keep track of which 73 * overflow and dup pages we need to come back to at the end and print 74 * with key "UNKNOWN". Pages which print with a good key get set 75 * to SALVAGE_IGNORE; others get set, as appropriate, to SALVAGE_LDUP, 76 * SALVAGE_LRECNODUP, SALVAGE_OVERFLOW for normal db overflow pages, 77 * and SALVAGE_BTREE, SALVAGE_LRECNO, and SALVAGE_HASH for subdb 78 * pages. 79 */ 80#define SALVAGE_INVALID 0 81#define SALVAGE_IGNORE 1 82#define SALVAGE_LDUP 2 83#define SALVAGE_IBTREE 3 84#define SALVAGE_OVERFLOW 4 85#define SALVAGE_LBTREE 5 86#define SALVAGE_HASH 6 87#define SALVAGE_LRECNO 7 88#define SALVAGE_LRECNODUP 8 89 DB *salvage_pages; 90 91 db_pgno_t last_pgno; 92 db_pgno_t meta_last_pgno; 93 db_pgno_t pgs_remaining; /* For dbp->db_feedback(). */ 94 95 /* 96 * These are used during __bam_vrfy_subtree to keep track, while 97 * walking up and down the Btree structure, of the prev- and next-page 98 * chain of leaf pages and verify that it's intact. Also, make sure 99 * that this chain contains pages of only one type. 100 */ 101 db_pgno_t prev_pgno; 102 db_pgno_t next_pgno; 103 u_int8_t leaf_type; 104 105 /* Queue needs these to verify data pages in the first pass. */ 106 u_int32_t re_pad; /* Record pad character. */ 107 u_int32_t re_len; /* Record length. */ 108 u_int32_t rec_page; 109 u_int32_t page_ext; 110 u_int32_t first_recno; 111 u_int32_t last_recno; 112 int nextents; 113 db_pgno_t *extents; 114 115#define SALVAGE_PRINTABLE 0x01 /* Output printable chars literally. */ 116#define SALVAGE_PRINTHEADER 0x02 /* Print the unknown-key header. */ 117#define SALVAGE_PRINTFOOTER 0x04 /* Print the unknown-key footer. */ 118#define VRFY_LEAFCHAIN_BROKEN 0x08 /* Lost one or more Btree leaf pgs. */ 119#define VRFY_QMETA_SET 0x10 /* We've seen a QUEUE meta page and 120 set things up for it. */ 121 u_int32_t flags; 122}; /* VRFY_DBINFO */ 123 124/* 125 * The amount of state information we need per-page is small enough that 126 * it's not worth the trouble to define separate structures for each 127 * possible type of page, and since we're doing verification with these we 128 * have to be open to the possibility that page N will be of a completely 129 * unexpected type anyway. So we define one structure here with all the 130 * info we need for inter-page verification. 131 */ 132struct __vrfy_pageinfo { 133 u_int8_t type; 134 u_int8_t bt_level; 135 u_int8_t unused1; 136 u_int8_t unused2; 137 db_pgno_t pgno; 138 db_pgno_t prev_pgno; 139 db_pgno_t next_pgno; 140 141 /* meta pages */ 142 db_pgno_t root; 143 db_pgno_t free; /* Free list head. */ 144 145 db_indx_t entries; /* Actual number of entries. */ 146 u_int16_t unused; 147 db_recno_t rec_cnt; /* Record count. */ 148 u_int32_t re_pad; /* Record pad character. */ 149 u_int32_t re_len; /* Record length. */ 150 u_int32_t bt_minkey; 151 u_int32_t h_ffactor; 152 u_int32_t h_nelem; 153 154 /* overflow pages */ 155 /* 156 * Note that refcount is the refcount for an overflow page; pi_refcount 157 * is this structure's own refcount! 158 */ 159 u_int32_t refcount; 160 u_int32_t olen; 161 162#define VRFY_DUPS_UNSORTED 0x0001 /* Have to flag the negative! */ 163#define VRFY_HAS_CHKSUM 0x0002 164#define VRFY_HAS_DUPS 0x0004 165#define VRFY_HAS_DUPSORT 0x0008 /* Has the flag set. */ 166#define VRFY_HAS_RECNUMS 0x0010 167#define VRFY_HAS_SUBDBS 0x0020 168#define VRFY_INCOMPLETE 0x0040 /* Meta or item order checks incomp. */ 169#define VRFY_IS_ALLZEROES 0x0080 /* Hash page we haven't touched? */ 170#define VRFY_IS_FIXEDLEN 0x0100 171#define VRFY_IS_RECNO 0x0200 172#define VRFY_IS_RRECNO 0x0400 173#define VRFY_OVFL_LEAFSEEN 0x0800 174 u_int32_t flags; 175 176 LIST_ENTRY(__vrfy_pageinfo) links; 177 u_int32_t pi_refcount; 178}; /* VRFY_PAGEINFO */ 179 180struct __vrfy_childinfo { 181 /* The following fields are set by the caller of __db_vrfy_childput. */ 182 db_pgno_t pgno; 183 184#define V_DUPLICATE 1 /* off-page dup metadata */ 185#define V_OVERFLOW 2 /* overflow page */ 186#define V_RECNO 3 /* btree internal or leaf page */ 187 u_int32_t type; 188 db_recno_t nrecs; /* record count on a btree subtree */ 189 u_int32_t tlen; /* ovfl. item total size */ 190 191 /* The following field is maintained by __db_vrfy_childput. */ 192 u_int32_t refcnt; /* # of times parent points to child. */ 193 194 LIST_ENTRY(__vrfy_childinfo) links; 195}; /* VRFY_CHILDINFO */ 196 197#if defined(__cplusplus) 198} 199#endif 200#endif /* !_DB_VERIFY_H_ */ 201