2
* See the file LICENSE for redistribution information.
4
* Copyright (c) 1999-2002
5
* Sleepycat Software. All rights reserved.
11
static const char revid[] = "$Id: qam_verify.c,v 1.30 2002/06/26 20:49:27 bostic Exp $";
14
#ifndef NO_SYSTEM_INCLUDES
15
#include <sys/types.h>
20
#include "dbinc/db_page.h"
21
#include "dbinc/db_verify.h"
22
#include "dbinc/qam.h"
23
#include "dbinc/db_am.h"
27
* Verify the queue-specific part of a metadata page.
29
* PUBLIC: int __qam_vrfy_meta __P((DB *, VRFY_DBINFO *, QMETA *,
30
* PUBLIC: db_pgno_t, u_int32_t));
33
__qam_vrfy_meta(dbp, vdp, meta, pgno, flags)
41
int isbad, ret, t_ret;
43
if ((ret = __db_vrfy_getpageinfo(vdp, pgno, &pip)) != 0)
48
* Queue can't be used in subdatabases, so if this isn't set
49
* something very odd is going on.
51
if (!F_ISSET(pip, VRFY_INCOMPLETE))
53
"Page %lu: queue databases must be one-per-file",
58
* Cur_recno may be one beyond the end of the page and
59
* we start numbering from 1.
61
if (vdp->last_pgno > 0 && meta->cur_recno > 0 &&
62
meta->cur_recno - 1 > meta->rec_page * vdp->last_pgno) {
64
"Page %lu: current recno %lu references record past last page number %lu",
66
(u_long)meta->cur_recno, (u_long)vdp->last_pgno));
71
* re_len: If this is bad, we can't safely verify queue data pages, so
72
* return DB_VERIFY_FATAL
74
if (ALIGN(meta->re_len + sizeof(QAMDATA) - 1, sizeof(u_int32_t)) *
75
meta->rec_page + QPAGE_SZ(dbp) > dbp->pgsize) {
77
"Page %lu: queue record length %lu too high for page size and recs/page",
78
(u_long)pgno, (u_long)meta->re_len));
79
ret = DB_VERIFY_FATAL;
82
vdp->re_len = meta->re_len;
83
vdp->rec_page = meta->rec_page;
87
__db_vrfy_putpageinfo(dbp->dbenv, vdp, pip)) != 0 && ret == 0)
89
return (ret == 0 && isbad == 1 ? DB_VERIFY_BAD : ret);
94
* Verify a queue data page.
96
* PUBLIC: int __qam_vrfy_data __P((DB *, VRFY_DBINFO *, QPAGE *,
97
* PUBLIC: db_pgno_t, u_int32_t));
100
__qam_vrfy_data(dbp, vdp, h, pgno, flags)
108
struct __queue fakeq;
114
* Not much to do here, except make sure that flags are reasonable.
116
* QAM_GET_RECORD assumes a properly initialized q_internal
117
* structure, however, and we don't have one, so we play
118
* some gross games to fake it out.
120
fakedb.q_internal = &fakeq;
121
fakedb.flags = dbp->flags;
122
fakeq.re_len = vdp->re_len;
124
for (i = 0; i < vdp->rec_page; i++) {
125
qp = QAM_GET_RECORD(&fakedb, h, i);
126
if ((u_int8_t *)qp >= (u_int8_t *)h + dbp->pgsize) {
128
"Page %lu: queue record %lu extends past end of page",
129
(u_long)pgno, (u_long)i));
130
return (DB_VERIFY_BAD);
134
qflags &= !(QAM_VALID | QAM_SET);
137
"Page %lu: queue record %lu has bad flags",
138
(u_long)pgno, (u_long)i));
139
return (DB_VERIFY_BAD);
147
* __qam_vrfy_structure --
148
* Verify a queue database structure, such as it is.
150
* PUBLIC: int __qam_vrfy_structure __P((DB *, VRFY_DBINFO *, u_int32_t));
153
__qam_vrfy_structure(dbp, vdp, flags)
164
if ((ret = __db_vrfy_getpageinfo(vdp, PGNO_BASE_MD, &pip)) != 0)
167
if (pip->type != P_QAMMETA) {
169
"Page %lu: queue database has no meta page",
170
(u_long)PGNO_BASE_MD));
175
if ((ret = __db_vrfy_pgset_inc(vdp->pgset, 0)) != 0)
178
for (i = 1; i <= vdp->last_pgno; i++) {
179
/* Send feedback to the application about our progress. */
180
if (!LF_ISSET(DB_SALVAGE))
181
__db_vrfy_struct_feedback(dbp, vdp);
183
if ((ret = __db_vrfy_putpageinfo(dbp->dbenv, vdp, pip)) != 0 ||
184
(ret = __db_vrfy_getpageinfo(vdp, i, &pip)) != 0)
186
if (!F_ISSET(pip, VRFY_IS_ALLZEROES) &&
187
pip->type != P_QAMDATA) {
189
"Page %lu: queue database page of incorrect type %lu",
190
(u_long)i, (u_long)pip->type));
193
} else if ((ret = __db_vrfy_pgset_inc(vdp->pgset, i)) != 0)
197
err: if ((ret = __db_vrfy_putpageinfo(dbp->dbenv, vdp, pip)) != 0)
199
return (isbad == 1 ? DB_VERIFY_BAD : 0);