1 /*-
2 * Copyright (c) 2014-2018 MongoDB, Inc.
3 * Copyright (c) 2008-2014 WiredTiger, Inc.
4 * All rights reserved.
5 *
6 * See the file LICENSE for redistribution information.
7 */
8
9 #include "wt_internal.h"
10
11 /*
12 * __wt_page_type_string --
13 * Return a string representing the page type.
14 */
15 const char *
__wt_page_type_string(u_int type)16 __wt_page_type_string(u_int type)
17 WT_GCC_FUNC_ATTRIBUTE((visibility("default")))
18 {
19 switch (type) {
20 case WT_PAGE_INVALID:
21 return ("invalid");
22 case WT_PAGE_BLOCK_MANAGER:
23 return ("block manager");
24 case WT_PAGE_COL_FIX:
25 return ("column-store fixed-length leaf");
26 case WT_PAGE_COL_INT:
27 return ("column-store internal");
28 case WT_PAGE_COL_VAR:
29 return ("column-store variable-length leaf");
30 case WT_PAGE_OVFL:
31 return ("overflow");
32 case WT_PAGE_ROW_INT:
33 return ("row-store internal");
34 case WT_PAGE_ROW_LEAF:
35 return ("row-store leaf");
36 default:
37 return ("unknown");
38 }
39 /* NOTREACHED */
40 }
41
42 /*
43 * __wt_cell_type_string --
44 * Return a string representing the cell type.
45 */
46 const char *
__wt_cell_type_string(uint8_t type)47 __wt_cell_type_string(uint8_t type)
48 {
49 switch (type) {
50 case WT_CELL_ADDR_DEL:
51 return ("addr/del");
52 case WT_CELL_ADDR_INT:
53 return ("addr/int");
54 case WT_CELL_ADDR_LEAF:
55 return ("addr/leaf");
56 case WT_CELL_ADDR_LEAF_NO:
57 return ("addr/leaf-no");
58 case WT_CELL_DEL:
59 return ("deleted");
60 case WT_CELL_KEY:
61 return ("key");
62 case WT_CELL_KEY_PFX:
63 return ("key/pfx");
64 case WT_CELL_KEY_OVFL:
65 return ("key/ovfl");
66 case WT_CELL_KEY_SHORT:
67 return ("key/short");
68 case WT_CELL_KEY_SHORT_PFX:
69 return ("key/short,pfx");
70 case WT_CELL_KEY_OVFL_RM:
71 return ("key/ovfl,rm");
72 case WT_CELL_VALUE:
73 return ("value");
74 case WT_CELL_VALUE_COPY:
75 return ("value/copy");
76 case WT_CELL_VALUE_OVFL:
77 return ("value/ovfl");
78 case WT_CELL_VALUE_OVFL_RM:
79 return ("value/ovfl,rm");
80 case WT_CELL_VALUE_SHORT:
81 return ("value/short");
82 default:
83 return ("unknown");
84 }
85 /* NOTREACHED */
86 }
87
88 /*
89 * __wt_page_addr_string --
90 * Figure out a page's "address" and load a buffer with a printable,
91 * nul-terminated representation of that address.
92 */
93 const char *
__wt_page_addr_string(WT_SESSION_IMPL * session,WT_REF * ref,WT_ITEM * buf)94 __wt_page_addr_string(WT_SESSION_IMPL *session, WT_REF *ref, WT_ITEM *buf)
95 {
96 size_t addr_size;
97 const uint8_t *addr;
98
99 if (__wt_ref_is_root(ref)) {
100 buf->data = "[Root]";
101 buf->size = strlen("[Root]");
102 return (buf->data);
103 }
104
105 __wt_ref_info(ref, &addr, &addr_size, NULL);
106 return (__wt_addr_string(session, addr, addr_size, buf));
107 }
108
109 /*
110 * __wt_addr_string --
111 * Load a buffer with a printable, nul-terminated representation of an
112 * address.
113 */
114 const char *
__wt_addr_string(WT_SESSION_IMPL * session,const uint8_t * addr,size_t addr_size,WT_ITEM * buf)115 __wt_addr_string(WT_SESSION_IMPL *session,
116 const uint8_t *addr, size_t addr_size, WT_ITEM *buf)
117 {
118 WT_BM *bm;
119 WT_BTREE *btree;
120
121 btree = S2BT_SAFE(session);
122
123 if (addr == NULL) {
124 buf->data = "[NoAddr]";
125 buf->size = strlen("[NoAddr]");
126 } else if (btree == NULL || (bm = btree->bm) == NULL ||
127 bm->addr_string(bm, session, buf, addr, addr_size) != 0) {
128 buf->data = "[Error]";
129 buf->size = strlen("[Error]");
130 }
131 return (buf->data);
132 }
133