2
* See the file LICENSE for redistribution information.
4
* Copyright (c) 1996-2002
5
* Sleepycat Software. All rights reserved.
9
static char copyright[] =
10
"Copyright (c) 1996-2002\nSleepycat Software Inc. All rights reserved.\n";
15
#include <sys/types.h>
26
/* Hash Table Information */
27
typedef struct hashhdr185 { /* Disk resident portion */
28
int magic; /* Magic NO for hash tables */
29
int version; /* Version ID */
30
u_int32_t lorder; /* Byte Order */
31
int bsize; /* Bucket/Page Size */
32
int bshift; /* Bucket shift */
33
int dsize; /* Directory Size */
34
int ssize; /* Segment Size */
35
int sshift; /* Segment shift */
36
int ovfl_point; /* Where overflow pages are being
38
int last_freed; /* Last overflow page freed */
39
int max_bucket; /* ID of Maximum bucket in use */
40
int high_mask; /* Mask to modulo into entire table */
41
int low_mask; /* Mask to modulo into lower half of
43
int ffactor; /* Fill factor */
44
int nkeys; /* Number of keys in hash table */
46
typedef struct htab185 { /* Memory resident data structure */
47
HASHHDR185 hdr; /* Header */
50
/* Hash Table Information */
51
typedef struct hashhdr186 { /* Disk resident portion */
52
int32_t magic; /* Magic NO for hash tables */
53
int32_t version; /* Version ID */
54
int32_t lorder; /* Byte Order */
55
int32_t bsize; /* Bucket/Page Size */
56
int32_t bshift; /* Bucket shift */
57
int32_t ovfl_point; /* Where overflow pages are being allocated */
58
int32_t last_freed; /* Last overflow page freed */
59
int32_t max_bucket; /* ID of Maximum bucket in use */
60
int32_t high_mask; /* Mask to modulo into entire table */
61
int32_t low_mask; /* Mask to modulo into lower half of table */
62
int32_t ffactor; /* Fill factor */
63
int32_t nkeys; /* Number of keys in hash table */
64
int32_t hdrpages; /* Size of table header */
65
int32_t h_charkey; /* value of hash(CHARKEY) */
66
#define NCACHED 32 /* number of bit maps and spare points */
67
int32_t spares[NCACHED];/* spare pages for overflow */
68
/* address of overflow page bitmaps */
69
u_int16_t bitmaps[NCACHED];
71
typedef struct htab186 { /* Memory resident data structure */
73
HASHHDR186 hdr; /* Header */
76
typedef struct _epgno {
77
u_int32_t pgno; /* the page number */
78
u_int16_t index; /* the index on the page */
82
void *page; /* the (pinned) page */
83
u_int16_t index; /* the index on the page */
86
typedef struct _cursor {
87
EPGNO pg; /* B: Saved tree reference. */
88
DBT key; /* B: Saved key, or key.data == NULL. */
89
u_int32_t rcursor; /* R: recno cursor (1-based) */
91
#define CURS_ACQUIRE 0x01 /* B: Cursor needs to be reacquired. */
92
#define CURS_AFTER 0x02 /* B: Unreturned cursor after key. */
93
#define CURS_BEFORE 0x04 /* B: Unreturned cursor before key. */
94
#define CURS_INIT 0x08 /* RB: Cursor initialized. */
98
/* The in-memory btree/recno data structure. */
99
typedef struct _btree {
100
void *bt_mp; /* memory pool cookie */
102
void *bt_dbp; /* pointer to enclosing DB */
104
EPG bt_cur; /* current (pinned) page */
105
void *bt_pinned; /* page pinned across calls */
107
CURSOR bt_cursor; /* cursor */
109
EPGNO bt_stack[50]; /* stack of parent pages */
110
EPGNO *bt_sp; /* current stack pointer */
112
DBT bt_rkey; /* returned key */
113
DBT bt_rdata; /* returned data */
115
int bt_fd; /* tree file descriptor */
117
u_int32_t bt_free; /* next free page */
118
u_int32_t bt_psize; /* page size */
119
u_int16_t bt_ovflsize; /* cut-off for key/data overflow */
120
int bt_lorder; /* byte order */
122
enum { NOT, BACK, FORWARD } bt_order;
123
EPGNO bt_last; /* last insert */
125
/* B: key comparison function */
126
int (*bt_cmp) __P((DBT *, DBT *));
127
/* B: prefix comparison function */
128
size_t (*bt_pfx) __P((DBT *, DBT *));
129
/* R: recno input function */
130
int (*bt_irec) __P((struct _btree *, u_int32_t));
132
FILE *bt_rfp; /* R: record FILE pointer */
133
int bt_rfd; /* R: record file descriptor */
135
void *bt_cmap; /* R: current point in mapped space */
136
void *bt_smap; /* R: start of mapped space */
137
void *bt_emap; /* R: end of mapped space */
138
size_t bt_msize; /* R: size of mapped region. */
140
u_int32_t bt_nrecs; /* R: number of records */
141
size_t bt_reclen; /* R: fixed record length */
142
u_char bt_bval; /* R: delimiting byte/pad character */
146
* B_NODUPS and R_RECNO are stored on disk, and may not be changed.
148
#define B_INMEM 0x00001 /* in-memory tree */
149
#define B_METADIRTY 0x00002 /* need to write metadata */
150
#define B_MODIFIED 0x00004 /* tree modified */
151
#define B_NEEDSWAP 0x00008 /* if byte order requires swapping */
152
#define B_RDONLY 0x00010 /* read-only tree */
154
#define B_NODUPS 0x00020 /* no duplicate keys permitted */
155
#define R_RECNO 0x00080 /* record oriented tree */
157
#define R_CLOSEFP 0x00040 /* opened a file pointer */
158
#define R_EOF 0x00100 /* end of input file reached. */
159
#define R_FIXLEN 0x00200 /* fixed length records */
160
#define R_MEMMAPPED 0x00400 /* memory mapped file. */
161
#define R_INMEM 0x00800 /* in-memory file */
162
#define R_MODIFIED 0x01000 /* modified file */
163
#define R_RDONLY 0x02000 /* read-only file */
165
#define B_DB_LOCK 0x04000 /* DB_LOCK specified. */
166
#define B_DB_SHMEM 0x08000 /* DB_SHMEM specified. */
167
#define B_DB_TXN 0x10000 /* DB_TXN specified. */
171
void db_btree __P((DB *, int));
172
void db_hash __P((DB *, int));
173
void dbt_dump __P((DBT *));
174
void dbt_print __P((DBT *));
175
int main __P((int, char *[]));
176
int usage __P((void));
190
while ((ch = getopt(argc, argv, "f:p")) != EOF)
193
if (freopen(optarg, "w", stdout) == NULL) {
194
fprintf(stderr, "db_dump185: %s: %s\n",
195
optarg, strerror(errno));
196
return (EXIT_FAILURE);
212
if ((dbp = dbopen(argv[0], O_RDONLY, 0, DB_BTREE, NULL)) == NULL) {
214
dbopen(argv[0], O_RDONLY, 0, DB_HASH, NULL)) == NULL) {
216
"db_dump185: %s: %s\n", argv[0], strerror(errno));
217
return (EXIT_FAILURE);
221
db_btree(dbp, pflag);
225
* DB 1.85 DBTs are a subset of DB 2.0 DBTs, so we just use the
226
* new dump/print routines.
229
while (!(rval = dbp->seq(dbp, &key, &data, R_NEXT))) {
234
while (!(rval = dbp->seq(dbp, &key, &data, R_NEXT))) {
240
fprintf(stderr, "db_dump185: seq: %s\n", strerror(errno));
241
return (EXIT_FAILURE);
243
return (EXIT_SUCCESS);
248
* Dump out hash header information.
258
printf("format=%s\n", pflag ? "print" : "bytevalue");
259
printf("type=hash\n");
261
/* DB 1.85 was version 2, DB 1.86 was version 3. */
262
hash185p = dbp->internal;
263
if (hash185p->hdr.version > 2) {
264
hash186p = dbp->internal;
265
printf("h_ffactor=%lu\n", (u_long)hash186p->hdr.ffactor);
266
if (hash186p->hdr.lorder != 0)
267
printf("db_lorder=%lu\n", (u_long)hash186p->hdr.lorder);
268
printf("db_pagesize=%lu\n", (u_long)hash186p->hdr.bsize);
270
printf("h_ffactor=%lu\n", (u_long)hash185p->hdr.ffactor);
271
if (hash185p->hdr.lorder != 0)
272
printf("db_lorder=%lu\n", (u_long)hash185p->hdr.lorder);
273
printf("db_pagesize=%lu\n", (u_long)hash185p->hdr.bsize);
275
printf("HEADER=END\n");
280
* Dump out btree header information.
291
printf("format=%s\n", pflag ? "print" : "bytevalue");
292
printf("type=btree\n");
293
#ifdef NOT_AVAILABLE_IN_185
294
printf("bt_minkey=%lu\n", (u_long)XXX);
295
printf("bt_maxkey=%lu\n", (u_long)XXX);
297
if (btp->bt_lorder != 0)
298
printf("db_lorder=%lu\n", (u_long)btp->bt_lorder);
299
printf("db_pagesize=%lu\n", (u_long)btp->bt_psize);
300
if (!(btp->flags & B_NODUPS))
301
printf("duplicates=1\n");
302
printf("HEADER=END\n");
305
static char hex[] = "0123456789abcdef";
309
* Write out a key or data item using byte values.
318
for (len = dbtp->size, p = dbtp->data; len--; ++p)
320
hex[(*p & 0xf0) >> 4], hex[*p & 0x0f]);
326
* Write out a key or data item using printable characters.
335
for (len = dbtp->size, p = dbtp->data; len--; ++p)
336
if (isprint((int)*p)) {
339
(void)printf("%c", *p);
341
(void)printf("\\%c%c",
342
hex[(*p & 0xf0) >> 4], hex[*p & 0x0f]);
348
* Display the usage message.
353
(void)fprintf(stderr, "usage: db_dump185 [-p] [-f file] db_file\n");
354
return (EXIT_FAILURE);