Update.
[glibc.git] / db2 / db / db_pr.c
bloba294cdd1355b02fc5e25a1f5e6621974fcf216b8
1 /*-
2 * See the file LICENSE for redistribution information.
4 * Copyright (c) 1996, 1997, 1998
5 * Sleepycat Software. All rights reserved.
6 */
8 #include "config.h"
10 #ifndef lint
11 static const char sccsid[] = "@(#)db_pr.c 10.29 (Sleepycat) 5/23/98";
12 #endif /* not lint */
14 #ifndef NO_SYSTEM_INCLUDES
15 #include <sys/types.h>
17 #include <ctype.h>
18 #include <errno.h>
19 #include <stdlib.h>
20 #include <string.h>
21 #include <unistd.h>
22 #endif
24 #include "db_int.h"
25 #include "db_page.h"
26 #include "btree.h"
27 #include "hash.h"
28 #include "db_am.h"
30 static void __db_proff __P((void *));
31 static void __db_psize __P((DB_MPOOLFILE *));
34 * __db_loadme --
35 * Force loading of this file.
37 * PUBLIC: void __db_loadme __P((void));
39 void
40 __db_loadme()
42 getpid();
45 static FILE *set_fp;
48 * 64K is the maximum page size, so by default we check for offsets
49 * larger than that, and, where possible, we refine the test.
51 #define PSIZE_BOUNDARY (64 * 1024 + 1)
52 static size_t set_psize = PSIZE_BOUNDARY;
55 * __db_prinit --
56 * Initialize tree printing routines.
58 * PUBLIC: FILE *__db_prinit __P((FILE *));
60 FILE *
61 __db_prinit(fp)
62 FILE *fp;
64 if (set_fp == NULL)
65 set_fp = fp == NULL ? stdout : fp;
66 return (set_fp);
70 * __db_dump --
71 * Dump the tree to a file.
73 * PUBLIC: int __db_dump __P((DB *, char *, int));
75 int
76 __db_dump(dbp, name, all)
77 DB *dbp;
78 char *name;
79 int all;
81 FILE *fp, *save_fp;
83 COMPQUIET(save_fp, NULL);
85 if (set_psize == PSIZE_BOUNDARY)
86 __db_psize(dbp->mpf);
88 if (name != NULL) {
89 if ((fp = fopen(name, "w")) == NULL)
90 return (errno);
91 save_fp = set_fp;
92 set_fp = fp;
93 } else
94 fp = __db_prinit(NULL);
96 (void)__db_prdb(dbp);
97 if (dbp->type == DB_HASH)
98 (void)__db_prhash(dbp);
99 else
100 (void)__db_prbtree(dbp);
101 fprintf(fp, "%s\n", DB_LINE);
102 __db_prtree(dbp->mpf, all);
104 if (name != NULL) {
105 (void)fclose(fp);
106 set_fp = save_fp;
108 return (0);
112 * __db_prdb --
113 * Print out the DB structure information.
115 * PUBLIC: int __db_prdb __P((DB *));
118 __db_prdb(dbp)
119 DB *dbp;
121 static const FN fn[] = {
122 { DB_AM_DUP, "duplicates" },
123 { DB_AM_INMEM, "in-memory" },
124 { DB_AM_LOCKING, "locking" },
125 { DB_AM_LOGGING, "logging" },
126 { DB_AM_MLOCAL, "local mpool" },
127 { DB_AM_PGDEF, "default page size" },
128 { DB_AM_RDONLY, "read-only" },
129 { DB_AM_RECOVER, "recover" },
130 { DB_AM_SWAP, "needswap" },
131 { DB_AM_THREAD, "thread" },
132 { DB_BT_RECNUM, "btree:records" },
133 { DB_HS_DIRTYMETA, "hash:dirty-meta" },
134 { DB_RE_DELIMITER, "recno:delimiter" },
135 { DB_RE_FIXEDLEN, "recno:fixed-length" },
136 { DB_RE_PAD, "recno:pad" },
137 { DB_RE_RENUMBER, "recno:renumber" },
138 { DB_RE_SNAPSHOT, "recno:snapshot" },
139 { 0 },
141 FILE *fp;
142 const char *t;
144 fp = __db_prinit(NULL);
146 switch (dbp->type) {
147 case DB_BTREE:
148 t = "btree";
149 break;
150 case DB_HASH:
151 t = "hash";
152 break;
153 case DB_RECNO:
154 t = "recno";
155 break;
156 default:
157 t = "UNKNOWN";
158 break;
161 fprintf(fp, "%s ", t);
162 __db_prflags(dbp->flags, fn, fp);
163 fprintf(fp, "\n");
165 return (0);
169 * __db_prbtree --
170 * Print out the btree internal information.
172 * PUBLIC: int __db_prbtree __P((DB *));
175 __db_prbtree(dbp)
176 DB *dbp;
178 static const FN mfn[] = {
179 { BTM_DUP, "duplicates" },
180 { BTM_RECNO, "recno" },
181 { BTM_RECNUM, "btree:records" },
182 { BTM_FIXEDLEN, "recno:fixed-length" },
183 { BTM_RENUMBER, "recno:renumber" },
184 { 0 },
186 BTMETA *mp;
187 BTREE *t;
188 EPG *epg;
189 FILE *fp;
190 PAGE *h;
191 RECNO *rp;
192 db_pgno_t i;
193 int ret;
195 t = dbp->internal;
196 fp = __db_prinit(NULL);
198 (void)fprintf(fp, "%s\nOn-page metadata:\n", DB_LINE);
200 i = PGNO_METADATA;
201 if ((ret = __bam_pget(dbp, (PAGE **)&mp, &i, 0)) != 0)
202 return (ret);
204 (void)fprintf(fp, "magic %#lx\n", (u_long)mp->magic);
205 (void)fprintf(fp, "version %#lx\n", (u_long)mp->version);
206 (void)fprintf(fp, "pagesize %lu\n", (u_long)mp->pagesize);
207 (void)fprintf(fp, "maxkey: %lu minkey: %lu\n",
208 (u_long)mp->maxkey, (u_long)mp->minkey);
210 (void)fprintf(fp, "free %lu", (u_long)mp->free);
211 for (i = mp->free; i != PGNO_INVALID;) {
212 if ((ret = __bam_pget(dbp, &h, &i, 0)) != 0)
213 return (ret);
214 i = h->next_pgno;
215 (void)memp_fput(dbp->mpf, h, 0);
216 (void)fprintf(fp, ", %lu", (u_long)i);
218 (void)fprintf(fp, "\n");
220 (void)fprintf(fp, "flags %#lx", (u_long)mp->flags);
221 __db_prflags(mp->flags, mfn, fp);
222 (void)fprintf(fp, "\n");
223 (void)memp_fput(dbp->mpf, mp, 0);
225 (void)fprintf(fp, "%s\nDB_INFO:\n", DB_LINE);
226 (void)fprintf(fp, "bt_maxkey: %lu bt_minkey: %lu\n",
227 (u_long)t->bt_maxkey, (u_long)t->bt_minkey);
228 (void)fprintf(fp, "bt_compare: %#lx bt_prefix: %#lx\n",
229 (u_long)t->bt_compare, (u_long)t->bt_prefix);
230 if ((rp = t->bt_recno) != NULL) {
231 (void)fprintf(fp,
232 "re_delim: %#lx re_pad: %#lx re_len: %lu re_source: %s\n",
233 (u_long)rp->re_delim, (u_long)rp->re_pad,
234 (u_long)rp->re_len,
235 rp->re_source == NULL ? "" : rp->re_source);
236 (void)fprintf(fp,
237 "cmap: %#lx smap: %#lx emap: %#lx msize: %lu\n",
238 (u_long)rp->re_cmap, (u_long)rp->re_smap,
239 (u_long)rp->re_emap, (u_long)rp->re_msize);
241 (void)fprintf(fp, "stack:");
242 for (epg = t->bt_stack; epg < t->bt_sp; ++epg)
243 (void)fprintf(fp, " %lu", (u_long)epg->page->pgno);
244 (void)fprintf(fp, "\n");
245 (void)fprintf(fp, "ovflsize: %lu\n", (u_long)t->bt_ovflsize);
246 (void)fflush(fp);
247 return (0);
251 * __db_prhash --
252 * Print out the hash internal information.
254 * PUBLIC: int __db_prhash __P((DB *));
257 __db_prhash(dbp)
258 DB *dbp;
260 FILE *fp;
261 HTAB *t;
262 int i, put_page, ret;
263 db_pgno_t pgno;
265 t = dbp->internal;
267 fp = __db_prinit(NULL);
269 fprintf(fp, "\thash_accesses %lu\n", (u_long)t->hash_accesses);
270 fprintf(fp, "\thash_collisions %lu\n", (u_long)t->hash_collisions);
271 fprintf(fp, "\thash_expansions %lu\n", (u_long)t->hash_expansions);
272 fprintf(fp, "\thash_overflows %lu\n", (u_long)t->hash_overflows);
273 fprintf(fp, "\thash_bigpages %lu\n", (u_long)t->hash_bigpages);
274 fprintf(fp, "\n");
276 if (t->hdr == NULL) {
277 pgno = PGNO_METADATA;
278 if ((ret = memp_fget(dbp->mpf, &pgno, 0, &t->hdr)) != 0)
279 return (ret);
280 put_page = 1;
281 } else
282 put_page = 0;
284 fprintf(fp, "\tmagic %#lx\n", (u_long)t->hdr->magic);
285 fprintf(fp, "\tversion %lu\n", (u_long)t->hdr->version);
286 fprintf(fp, "\tpagesize %lu\n", (u_long)t->hdr->pagesize);
287 fprintf(fp, "\tovfl_point %lu\n", (u_long)t->hdr->ovfl_point);
288 fprintf(fp, "\tlast_freed %lu\n", (u_long)t->hdr->last_freed);
289 fprintf(fp, "\tmax_bucket %lu\n", (u_long)t->hdr->max_bucket);
290 fprintf(fp, "\thigh_mask %#lx\n", (u_long)t->hdr->high_mask);
291 fprintf(fp, "\tlow_mask %#lx\n", (u_long)t->hdr->low_mask);
292 fprintf(fp, "\tffactor %lu\n", (u_long)t->hdr->ffactor);
293 fprintf(fp, "\tnelem %lu\n", (u_long)t->hdr->nelem);
294 fprintf(fp, "\th_charkey %#lx\n", (u_long)t->hdr->h_charkey);
296 for (i = 0; i < NCACHED; i++)
297 fprintf(fp, "%lu ", (u_long)t->hdr->spares[i]);
298 fprintf(fp, "\n");
300 (void)fflush(fp);
301 if (put_page) {
302 (void)memp_fput(dbp->mpf, (PAGE *)t->hdr, 0);
303 t->hdr = NULL;
305 return (0);
309 * __db_prtree --
310 * Print out the entire tree.
312 * PUBLIC: int __db_prtree __P((DB_MPOOLFILE *, int));
315 __db_prtree(mpf, all)
316 DB_MPOOLFILE *mpf;
317 int all;
319 PAGE *h;
320 db_pgno_t i;
321 int ret, t_ret;
323 if (set_psize == PSIZE_BOUNDARY)
324 __db_psize(mpf);
326 ret = 0;
327 for (i = PGNO_ROOT;; ++i) {
328 if ((ret = memp_fget(mpf, &i, 0, &h)) != 0)
329 break;
330 if (TYPE(h) != P_INVALID)
331 if ((t_ret = __db_prpage(h, all)) != 0 && ret == 0)
332 ret = t_ret;
333 (void)memp_fput(mpf, h, 0);
335 (void)fflush(__db_prinit(NULL));
336 return (ret);
340 * __db_prnpage
341 * -- Print out a specific page.
343 * PUBLIC: int __db_prnpage __P((DB_MPOOLFILE *, db_pgno_t));
346 __db_prnpage(mpf, pgno)
347 DB_MPOOLFILE *mpf;
348 db_pgno_t pgno;
350 PAGE *h;
351 int ret;
353 if (set_psize == PSIZE_BOUNDARY)
354 __db_psize(mpf);
356 if ((ret = memp_fget(mpf, &pgno, 0, &h)) != 0)
357 return (ret);
359 ret = __db_prpage(h, 1);
360 (void)fflush(__db_prinit(NULL));
362 (void)memp_fput(mpf, h, 0);
363 return (ret);
367 * __db_prpage
368 * -- Print out a page.
370 * PUBLIC: int __db_prpage __P((PAGE *, int));
373 __db_prpage(h, all)
374 PAGE *h;
375 int all;
377 BINTERNAL *bi;
378 BKEYDATA *bk;
379 HOFFPAGE a_hkd;
380 FILE *fp;
381 RINTERNAL *ri;
382 db_indx_t dlen, len, i;
383 db_pgno_t pgno;
384 int deleted, ret;
385 const char *s;
386 u_int8_t *ep, *hk, *p;
387 void *sp;
389 fp = __db_prinit(NULL);
391 switch (TYPE(h)) {
392 case P_DUPLICATE:
393 s = "duplicate";
394 break;
395 case P_HASH:
396 s = "hash";
397 break;
398 case P_IBTREE:
399 s = "btree internal";
400 break;
401 case P_INVALID:
402 s = "invalid";
403 break;
404 case P_IRECNO:
405 s = "recno internal";
406 break;
407 case P_LBTREE:
408 s = "btree leaf";
409 break;
410 case P_LRECNO:
411 s = "recno leaf";
412 break;
413 case P_OVERFLOW:
414 s = "overflow";
415 break;
416 default:
417 fprintf(fp, "ILLEGAL PAGE TYPE: page: %lu type: %lu\n",
418 (u_long)h->pgno, (u_long)TYPE(h));
419 return (1);
421 fprintf(fp, "page %4lu: (%s)\n", (u_long)h->pgno, s);
422 fprintf(fp, " lsn.file: %lu lsn.offset: %lu",
423 (u_long)LSN(h).file, (u_long)LSN(h).offset);
424 if (TYPE(h) == P_IBTREE || TYPE(h) == P_IRECNO ||
425 (TYPE(h) == P_LRECNO && h->pgno == PGNO_ROOT))
426 fprintf(fp, " total records: %4lu", (u_long)RE_NREC(h));
427 fprintf(fp, "\n");
428 if (TYPE(h) == P_LBTREE || TYPE(h) == P_LRECNO ||
429 TYPE(h) == P_DUPLICATE || TYPE(h) == P_OVERFLOW)
430 fprintf(fp, " prev: %4lu next: %4lu",
431 (u_long)PREV_PGNO(h), (u_long)NEXT_PGNO(h));
432 if (TYPE(h) == P_IBTREE || TYPE(h) == P_LBTREE)
433 fprintf(fp, " level: %2lu", (u_long)h->level);
434 if (TYPE(h) == P_OVERFLOW) {
435 fprintf(fp, " ref cnt: %4lu ", (u_long)OV_REF(h));
436 __db_pr((u_int8_t *)h + P_OVERHEAD, OV_LEN(h));
437 return (0);
439 fprintf(fp, " entries: %4lu", (u_long)NUM_ENT(h));
440 fprintf(fp, " offset: %4lu\n", (u_long)HOFFSET(h));
442 if (!all || TYPE(h) == P_INVALID)
443 return (0);
445 ret = 0;
446 for (i = 0; i < NUM_ENT(h); i++) {
447 if (P_ENTRY(h, i) - (u_int8_t *)h < P_OVERHEAD ||
448 (size_t)(P_ENTRY(h, i) - (u_int8_t *)h) >= set_psize) {
449 fprintf(fp,
450 "ILLEGAL PAGE OFFSET: indx: %lu of %lu\n",
451 (u_long)i, (u_long)h->inp[i]);
452 ret = EINVAL;
453 continue;
455 deleted = 0;
456 switch (TYPE(h)) {
457 case P_HASH:
458 case P_IBTREE:
459 case P_IRECNO:
460 sp = P_ENTRY(h, i);
461 break;
462 case P_LBTREE:
463 sp = P_ENTRY(h, i);
464 deleted = i % 2 == 0 &&
465 B_DISSET(GET_BKEYDATA(h, i + O_INDX)->type);
466 break;
467 case P_LRECNO:
468 case P_DUPLICATE:
469 sp = P_ENTRY(h, i);
470 deleted = B_DISSET(GET_BKEYDATA(h, i)->type);
471 break;
472 default:
473 fprintf(fp,
474 "ILLEGAL PAGE ITEM: %lu\n", (u_long)TYPE(h));
475 ret = EINVAL;
476 continue;
478 fprintf(fp, " %s[%03lu] %4lu ",
479 deleted ? "D" : " ", (u_long)i, (u_long)h->inp[i]);
480 switch (TYPE(h)) {
481 case P_HASH:
482 hk = sp;
483 switch (HPAGE_PTYPE(hk)) {
484 case H_OFFDUP:
485 memcpy(&pgno,
486 HOFFDUP_PGNO(hk), sizeof(db_pgno_t));
487 fprintf(fp,
488 "%4lu [offpage dups]\n", (u_long)pgno);
489 break;
490 case H_DUPLICATE:
492 * If this is the first item on a page, then
493 * we cannot figure out how long it is, so
494 * we only print the first one in the duplicate
495 * set.
497 if (i != 0)
498 len = LEN_HKEYDATA(h, 0, i);
499 else
500 len = 1;
502 fprintf(fp, "Duplicates:\n");
503 for (p = HKEYDATA_DATA(hk),
504 ep = p + len; p < ep;) {
505 memcpy(&dlen, p, sizeof(db_indx_t));
506 p += sizeof(db_indx_t);
507 fprintf(fp, "\t\t");
508 __db_pr(p, dlen);
509 p += sizeof(db_indx_t) + dlen;
511 break;
512 case H_KEYDATA:
513 if (i != 0)
514 __db_pr(HKEYDATA_DATA(hk),
515 LEN_HKEYDATA(h, 0, i));
516 else
517 fprintf(fp, "%s\n", HKEYDATA_DATA(hk));
518 break;
519 case H_OFFPAGE:
520 memcpy(&a_hkd, hk, HOFFPAGE_SIZE);
521 fprintf(fp,
522 "overflow: total len: %4lu page: %4lu\n",
523 (u_long)a_hkd.tlen, (u_long)a_hkd.pgno);
524 break;
526 break;
527 case P_IBTREE:
528 bi = sp;
529 fprintf(fp, "count: %4lu pgno: %4lu ",
530 (u_long)bi->nrecs, (u_long)bi->pgno);
531 switch (B_TYPE(bi->type)) {
532 case B_KEYDATA:
533 __db_pr(bi->data, bi->len);
534 break;
535 case B_DUPLICATE:
536 case B_OVERFLOW:
537 __db_proff(bi->data);
538 break;
539 default:
540 fprintf(fp, "ILLEGAL BINTERNAL TYPE: %lu\n",
541 (u_long)B_TYPE(bi->type));
542 ret = EINVAL;
543 break;
545 break;
546 case P_IRECNO:
547 ri = sp;
548 fprintf(fp, "entries %4lu pgno %4lu\n",
549 (u_long)ri->nrecs, (u_long)ri->pgno);
550 break;
551 case P_LBTREE:
552 case P_LRECNO:
553 case P_DUPLICATE:
554 bk = sp;
555 switch (B_TYPE(bk->type)) {
556 case B_KEYDATA:
557 __db_pr(bk->data, bk->len);
558 break;
559 case B_DUPLICATE:
560 case B_OVERFLOW:
561 __db_proff(bk);
562 break;
563 default:
564 fprintf(fp,
565 "ILLEGAL DUPLICATE/LBTREE/LRECNO TYPE: %lu\n",
566 (u_long)B_TYPE(bk->type));
567 ret = EINVAL;
568 break;
570 break;
573 (void)fflush(fp);
574 return (ret);
578 * __db_isbad
579 * -- Decide if a page is corrupted.
581 * PUBLIC: int __db_isbad __P((PAGE *, int));
584 __db_isbad(h, die)
585 PAGE *h;
586 int die;
588 BINTERNAL *bi;
589 BKEYDATA *bk;
590 FILE *fp;
591 db_indx_t i;
592 u_int type;
594 fp = __db_prinit(NULL);
596 switch (TYPE(h)) {
597 case P_DUPLICATE:
598 case P_HASH:
599 case P_IBTREE:
600 case P_INVALID:
601 case P_IRECNO:
602 case P_LBTREE:
603 case P_LRECNO:
604 case P_OVERFLOW:
605 break;
606 default:
607 fprintf(fp, "ILLEGAL PAGE TYPE: page: %lu type: %lu\n",
608 (u_long)h->pgno, (u_long)TYPE(h));
609 goto bad;
612 for (i = 0; i < NUM_ENT(h); i++) {
613 if (P_ENTRY(h, i) - (u_int8_t *)h < P_OVERHEAD ||
614 (size_t)(P_ENTRY(h, i) - (u_int8_t *)h) >= set_psize) {
615 fprintf(fp,
616 "ILLEGAL PAGE OFFSET: indx: %lu of %lu\n",
617 (u_long)i, (u_long)h->inp[i]);
618 goto bad;
620 switch (TYPE(h)) {
621 case P_HASH:
622 type = HPAGE_TYPE(h, i);
623 if (type != H_OFFDUP &&
624 type != H_DUPLICATE &&
625 type != H_KEYDATA &&
626 type != H_OFFPAGE) {
627 fprintf(fp, "ILLEGAL HASH TYPE: %lu\n",
628 (u_long)type);
629 goto bad;
631 break;
632 case P_IBTREE:
633 bi = GET_BINTERNAL(h, i);
634 if (B_TYPE(bi->type) != B_KEYDATA &&
635 B_TYPE(bi->type) != B_DUPLICATE &&
636 B_TYPE(bi->type) != B_OVERFLOW) {
637 fprintf(fp, "ILLEGAL BINTERNAL TYPE: %lu\n",
638 (u_long)B_TYPE(bi->type));
639 goto bad;
641 break;
642 case P_IRECNO:
643 case P_LBTREE:
644 case P_LRECNO:
645 break;
646 case P_DUPLICATE:
647 bk = GET_BKEYDATA(h, i);
648 if (B_TYPE(bk->type) != B_KEYDATA &&
649 B_TYPE(bk->type) != B_DUPLICATE &&
650 B_TYPE(bk->type) != B_OVERFLOW) {
651 fprintf(fp,
652 "ILLEGAL DUPLICATE/LBTREE/LRECNO TYPE: %lu\n",
653 (u_long)B_TYPE(bk->type));
654 goto bad;
656 break;
657 default:
658 fprintf(fp,
659 "ILLEGAL PAGE ITEM: %lu\n", (u_long)TYPE(h));
660 goto bad;
663 return (0);
665 bad: if (die) {
666 abort();
667 /* NOTREACHED */
669 return (1);
673 * __db_pr --
674 * Print out a data element.
676 * PUBLIC: void __db_pr __P((u_int8_t *, u_int32_t));
678 void
679 __db_pr(p, len)
680 u_int8_t *p;
681 u_int32_t len;
683 FILE *fp;
684 u_int lastch;
685 int i;
687 fp = __db_prinit(NULL);
689 fprintf(fp, "len: %3lu", (u_long)len);
690 lastch = '.';
691 if (len != 0) {
692 fprintf(fp, " data: ");
693 for (i = len <= 20 ? len : 20; i > 0; --i, ++p) {
694 lastch = *p;
695 if (isprint(*p) || *p == '\n')
696 fprintf(fp, "%c", *p);
697 else
698 fprintf(fp, "0x%.2x", (u_int)*p);
700 if (len > 20) {
701 fprintf(fp, "...");
702 lastch = '.';
705 if (lastch != '\n')
706 fprintf(fp, "\n");
710 * __db_prdbt --
711 * Print out a DBT data element.
713 * PUBLIC: int __db_prdbt __P((DBT *, int, FILE *));
716 __db_prdbt(dbtp, checkprint, fp)
717 DBT *dbtp;
718 int checkprint;
719 FILE *fp;
721 static const char hex[] = "0123456789abcdef";
722 u_int8_t *p;
723 u_int32_t len;
726 * !!!
727 * This routine is the routine that dumps out items in the format
728 * used by db_dump(1) and db_load(1). This means that the format
729 * cannot change.
731 if (checkprint) {
732 for (len = dbtp->size, p = dbtp->data; len--; ++p)
733 if (isprint(*p)) {
734 if (*p == '\\' && fprintf(fp, "\\") != 1)
735 return (EIO);
736 if (fprintf(fp, "%c", *p) != 1)
737 return (EIO);
738 } else
739 if (fprintf(fp, "\\%c%c",
740 hex[(u_int8_t)(*p & 0xf0) >> 4],
741 hex[*p & 0x0f]) != 3)
742 return (EIO);
743 } else
744 for (len = dbtp->size, p = dbtp->data; len--; ++p)
745 if (fprintf(fp, "%c%c",
746 hex[(u_int8_t)(*p & 0xf0) >> 4],
747 hex[*p & 0x0f]) != 2)
748 return (EIO);
750 return (fprintf(fp, "\n") == 1 ? 0 : EIO);
754 * __db_proff --
755 * Print out an off-page element.
757 static void
758 __db_proff(vp)
759 void *vp;
761 FILE *fp;
762 BOVERFLOW *bo;
764 fp = __db_prinit(NULL);
766 bo = vp;
767 switch (B_TYPE(bo->type)) {
768 case B_OVERFLOW:
769 fprintf(fp, "overflow: total len: %4lu page: %4lu\n",
770 (u_long)bo->tlen, (u_long)bo->pgno);
771 break;
772 case B_DUPLICATE:
773 fprintf(fp, "duplicate: page: %4lu\n", (u_long)bo->pgno);
774 break;
779 * __db_prflags --
780 * Print out flags values.
782 * PUBLIC: void __db_prflags __P((u_int32_t, const FN *, FILE *));
784 void
785 __db_prflags(flags, fn, fp)
786 u_int32_t flags;
787 FN const *fn;
788 FILE *fp;
790 const FN *fnp;
791 int found;
792 const char *sep;
794 sep = " (";
795 for (found = 0, fnp = fn; fnp->mask != 0; ++fnp)
796 if (LF_ISSET(fnp->mask)) {
797 fprintf(fp, "%s%s", sep, fnp->name);
798 sep = ", ";
799 found = 1;
801 if (found)
802 fprintf(fp, ")");
806 * __db_psize --
807 * Get the page size.
809 static void
810 __db_psize(mpf)
811 DB_MPOOLFILE *mpf;
813 BTMETA *mp;
814 db_pgno_t pgno;
816 set_psize = PSIZE_BOUNDARY - 1;
818 pgno = PGNO_METADATA;
819 if (memp_fget(mpf, &pgno, 0, &mp) != 0)
820 return;
822 switch (mp->magic) {
823 case DB_BTREEMAGIC:
824 case DB_HASHMAGIC:
825 set_psize = mp->pagesize;
826 break;
828 (void)memp_fput(mpf, mp, 0);