~ubuntu-branches/ubuntu/maverick/evolution-data-server/maverick-proposed

« back to all changes in this revision

Viewing changes to libdb/db_dump185/db_dump185.c

  • Committer: Bazaar Package Importer
  • Author(s): Didier Roche
  • Date: 2010-05-17 17:02:06 UTC
  • mfrom: (1.1.79 upstream) (1.6.12 experimental)
  • Revision ID: james.westby@ubuntu.com-20100517170206-4ufr52vwrhh26yh0
Tags: 2.30.1-1ubuntu1
* Merge from debian experimental. Remaining change:
  (LP: #42199, #229669, #173703, #360344, #508494)
  + debian/control:
    - add Vcs-Bzr tag
    - don't use libgnome
    - Use Breaks instead of Conflicts against evolution 2.25 and earlier.
  + debian/evolution-data-server.install,
    debian/patches/45_libcamel_providers_version.patch:
    - use the upstream versioning, not a Debian-specific one 
  + debian/libedata-book1.2-dev.install, debian/libebackend-1.2-dev.install,
    debian/libcamel1.2-dev.install, debian/libedataserverui1.2-dev.install:
    - install html documentation
  + debian/rules:
    - don't build documentation it's shipped with the tarball

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*-
2
 
 * See the file LICENSE for redistribution information.
3
 
 *
4
 
 * Copyright (c) 1996-2002
5
 
 *      Sleepycat Software.  All rights reserved.
6
 
 */
7
 
 
8
 
#ifndef lint
9
 
static char copyright[] =
10
 
    "Copyright (c) 1996-2002\nSleepycat Software Inc.  All rights reserved.\n";
11
 
static char revid[] =
12
 
    "$Id$";
13
 
#endif
14
 
 
15
 
#include <sys/types.h>
16
 
 
17
 
#include <ctype.h>
18
 
#include <errno.h>
19
 
#include <fcntl.h>
20
 
#include <stdio.h>
21
 
#include <stdlib.h>
22
 
#include <string.h>
23
 
 
24
 
#include <db.h>
25
 
 
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
37
 
                                         * allocated */
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
42
 
                                         * table */
43
 
        int             ffactor;        /* Fill factor */
44
 
        int             nkeys;          /* Number of keys in hash table */
45
 
} HASHHDR185;
46
 
typedef struct htab185   {              /* Memory resident data structure */
47
 
        HASHHDR185      hdr;            /* Header */
48
 
} HTAB185;
49
 
 
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];
70
 
} HASHHDR186;
71
 
typedef struct htab186   {              /* Memory resident data structure */
72
 
        void *unused[2];
73
 
        HASHHDR186      hdr;            /* Header */
74
 
} HTAB186;
75
 
 
76
 
typedef struct _epgno {
77
 
        u_int32_t pgno;                 /* the page number */
78
 
        u_int16_t index;                /* the index on the page */
79
 
} EPGNO;
80
 
 
81
 
typedef struct _epg {
82
 
        void    *page;                  /* the (pinned) page */
83
 
        u_int16_t index;                /* the index on the page */
84
 
} EPG;
85
 
 
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) */
90
 
 
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. */
95
 
        u_int8_t flags;
96
 
} CURSOR;
97
 
 
98
 
/* The in-memory btree/recno data structure. */
99
 
typedef struct _btree {
100
 
        void     *bt_mp;                /* memory pool cookie */
101
 
 
102
 
        void     *bt_dbp;               /* pointer to enclosing DB */
103
 
 
104
 
        EPG       bt_cur;               /* current (pinned) page */
105
 
        void     *bt_pinned;            /* page pinned across calls */
106
 
 
107
 
        CURSOR    bt_cursor;            /* cursor */
108
 
 
109
 
        EPGNO     bt_stack[50];         /* stack of parent pages */
110
 
        EPGNO    *bt_sp;                /* current stack pointer */
111
 
 
112
 
        DBT       bt_rkey;              /* returned key */
113
 
        DBT       bt_rdata;             /* returned data */
114
 
 
115
 
        int       bt_fd;                /* tree file descriptor */
116
 
 
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 */
121
 
                                        /* sorted order */
122
 
        enum { NOT, BACK, FORWARD } bt_order;
123
 
        EPGNO     bt_last;              /* last insert */
124
 
 
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));
131
 
 
132
 
        FILE     *bt_rfp;               /* R: record FILE pointer */
133
 
        int       bt_rfd;               /* R: record file descriptor */
134
 
 
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. */
139
 
 
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 */
143
 
 
144
 
/*
145
 
 * NB:
146
 
 * B_NODUPS and R_RECNO are stored on disk, and may not be changed.
147
 
 */
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 */
153
 
 
154
 
#define B_NODUPS        0x00020         /* no duplicate keys permitted */
155
 
#define R_RECNO         0x00080         /* record oriented tree */
156
 
 
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 */
164
 
 
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. */
168
 
        u_int32_t flags;
169
 
} BTREE;
170
 
 
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));
177
 
 
178
 
int
179
 
main(argc, argv)
180
 
        int argc;
181
 
        char *argv[];
182
 
{
183
 
        extern char *optarg;
184
 
        extern int optind;
185
 
        DB *dbp;
186
 
        DBT key, data;
187
 
        int ch, pflag, rval;
188
 
 
189
 
        pflag = 0;
190
 
        while ((ch = getopt(argc, argv, "f:p")) != EOF)
191
 
                switch (ch) {
192
 
                case 'f':
193
 
                        if (freopen(optarg, "w", stdout) == NULL) {
194
 
                                fprintf(stderr, "db_dump185: %s: %s\n",
195
 
                                    optarg, strerror(errno));
196
 
                                return (EXIT_FAILURE);
197
 
                        }
198
 
                        break;
199
 
                case 'p':
200
 
                        pflag = 1;
201
 
                        break;
202
 
                case '?':
203
 
                default:
204
 
                        return (usage());
205
 
                }
206
 
        argc -= optind;
207
 
        argv += optind;
208
 
 
209
 
        if (argc != 1)
210
 
                return (usage());
211
 
 
212
 
        if ((dbp = dbopen(argv[0], O_RDONLY, 0, DB_BTREE, NULL)) == NULL) {
213
 
                if ((dbp =
214
 
                    dbopen(argv[0], O_RDONLY, 0, DB_HASH, NULL)) == NULL) {
215
 
                        fprintf(stderr,
216
 
                            "db_dump185: %s: %s\n", argv[0], strerror(errno));
217
 
                        return (EXIT_FAILURE);
218
 
                }
219
 
                db_hash(dbp, pflag);
220
 
        } else
221
 
                db_btree(dbp, pflag);
222
 
 
223
 
        /*
224
 
         * !!!
225
 
         * DB 1.85 DBTs are a subset of DB 2.0 DBTs, so we just use the
226
 
         * new dump/print routines.
227
 
         */
228
 
        if (pflag)
229
 
                while (!(rval = dbp->seq(dbp, &key, &data, R_NEXT))) {
230
 
                        dbt_print(&key);
231
 
                        dbt_print(&data);
232
 
                }
233
 
        else
234
 
                while (!(rval = dbp->seq(dbp, &key, &data, R_NEXT))) {
235
 
                        dbt_dump(&key);
236
 
                        dbt_dump(&data);
237
 
                }
238
 
 
239
 
        if (rval == -1) {
240
 
                fprintf(stderr, "db_dump185: seq: %s\n", strerror(errno));
241
 
                return (EXIT_FAILURE);
242
 
        }
243
 
        return (EXIT_SUCCESS);
244
 
}
245
 
 
246
 
/*
247
 
 * db_hash --
248
 
 *      Dump out hash header information.
249
 
 */
250
 
void
251
 
db_hash(dbp, pflag)
252
 
        DB *dbp;
253
 
        int pflag;
254
 
{
255
 
        HTAB185 *hash185p;
256
 
        HTAB186 *hash186p;
257
 
 
258
 
        printf("format=%s\n", pflag ? "print" : "bytevalue");
259
 
        printf("type=hash\n");
260
 
 
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);
269
 
        } else {
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);
274
 
        }
275
 
        printf("HEADER=END\n");
276
 
}
277
 
 
278
 
/*
279
 
 * db_btree --
280
 
 *      Dump out btree header information.
281
 
 */
282
 
void
283
 
db_btree(dbp, pflag)
284
 
        DB *dbp;
285
 
        int pflag;
286
 
{
287
 
        BTREE *btp;
288
 
 
289
 
        btp = dbp->internal;
290
 
 
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);
296
 
#endif
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");
303
 
}
304
 
 
305
 
static char hex[] = "0123456789abcdef";
306
 
 
307
 
/*
308
 
 * dbt_dump --
309
 
 *      Write out a key or data item using byte values.
310
 
 */
311
 
void
312
 
dbt_dump(dbtp)
313
 
        DBT *dbtp;
314
 
{
315
 
        size_t len;
316
 
        u_int8_t *p;
317
 
 
318
 
        for (len = dbtp->size, p = dbtp->data; len--; ++p)
319
 
                (void)printf("%c%c",
320
 
                    hex[(*p & 0xf0) >> 4], hex[*p & 0x0f]);
321
 
        printf("\n");
322
 
}
323
 
 
324
 
/*
325
 
 * dbt_print --
326
 
 *      Write out a key or data item using printable characters.
327
 
 */
328
 
void
329
 
dbt_print(dbtp)
330
 
        DBT *dbtp;
331
 
{
332
 
        size_t len;
333
 
        u_int8_t *p;
334
 
 
335
 
        for (len = dbtp->size, p = dbtp->data; len--; ++p)
336
 
                if (isprint((int)*p)) {
337
 
                        if (*p == '\\')
338
 
                                (void)printf("\\");
339
 
                        (void)printf("%c", *p);
340
 
                } else
341
 
                        (void)printf("\\%c%c",
342
 
                            hex[(*p & 0xf0) >> 4], hex[*p & 0x0f]);
343
 
        printf("\n");
344
 
}
345
 
 
346
 
/*
347
 
 * usage --
348
 
 *      Display the usage message.
349
 
 */
350
 
int
351
 
usage()
352
 
{
353
 
        (void)fprintf(stderr, "usage: db_dump185 [-p] [-f file] db_file\n");
354
 
        return (EXIT_FAILURE);
355
 
}