source: trunk/third/rpm/db/btree/bt_upgrade.c @ 19079

Revision 19079, 3.5 KB checked in by ghudson, 22 years ago (diff)
This commit was generated by cvs2svn to compensate for changes in r19078, which included commits to RCS files with non-trunk default branches.
Line 
1/*-
2 * See the file LICENSE for redistribution information.
3 *
4 * Copyright (c) 1996-2002
5 *      Sleepycat Software.  All rights reserved.
6 */
7#include "db_config.h"
8
9#ifndef lint
10static const char revid[] = "Id: bt_upgrade.c,v 11.25 2002/08/06 06:11:13 bostic Exp ";
11#endif /* not lint */
12
13#ifndef NO_SYSTEM_INCLUDES
14#include <sys/types.h>
15
16#include <limits.h>
17#include <string.h>
18#endif
19
20#include "db_int.h"
21#include "dbinc/db_page.h"
22#include "dbinc/db_am.h"
23#include "dbinc/db_upgrade.h"
24
25/*
26 * __bam_30_btreemeta --
27 *      Upgrade the metadata pages from version 6 to version 7.
28 *
29 * PUBLIC: int __bam_30_btreemeta __P((DB *, char *, u_int8_t *));
30 */
31int
32__bam_30_btreemeta(dbp, real_name, buf)
33        DB *dbp;
34        char *real_name;
35        u_int8_t *buf;
36{
37        BTMETA30 *newmeta;
38        BTMETA2X *oldmeta;
39        DB_ENV *dbenv;
40        int ret;
41
42        dbenv = dbp->dbenv;
43
44        newmeta = (BTMETA30 *)buf;
45        oldmeta = (BTMETA2X *)buf;
46
47        /*
48         * Move things from the end up, so we do not overwrite things.
49         * We are going to create a new uid, so we can move the stuff
50         * at the end of the structure first, overwriting the uid.
51         */
52
53        newmeta->re_pad = oldmeta->re_pad;
54        newmeta->re_len = oldmeta->re_len;
55        newmeta->minkey = oldmeta->minkey;
56        newmeta->maxkey = oldmeta->maxkey;
57        newmeta->dbmeta.free = oldmeta->free;
58        newmeta->dbmeta.flags = oldmeta->flags;
59        newmeta->dbmeta.type  = P_BTREEMETA;
60
61        newmeta->dbmeta.version = 7;
62        /* Replace the unique ID. */
63        if ((ret = __os_fileid(dbenv, real_name, 1, buf + 36)) != 0)
64                return (ret);
65
66        newmeta->root = 1;
67
68        return (0);
69}
70
71/*
72 * __bam_31_btreemeta --
73 *      Upgrade the database from version 7 to version 8.
74 *
75 * PUBLIC: int __bam_31_btreemeta
76 * PUBLIC:      __P((DB *, char *, u_int32_t, DB_FH *, PAGE *, int *));
77 */
78int
79__bam_31_btreemeta(dbp, real_name, flags, fhp, h, dirtyp)
80        DB *dbp;
81        char *real_name;
82        u_int32_t flags;
83        DB_FH *fhp;
84        PAGE *h;
85        int *dirtyp;
86{
87        BTMETA31 *newmeta;
88        BTMETA30 *oldmeta;
89
90        COMPQUIET(dbp, NULL);
91        COMPQUIET(real_name, NULL);
92        COMPQUIET(fhp, NULL);
93
94        newmeta = (BTMETA31 *)h;
95        oldmeta = (BTMETA30 *)h;
96
97        /*
98         * Copy the effected fields down the page.
99         * The fields may overlap each other so we
100         * start at the bottom and use memmove.
101         */
102        newmeta->root = oldmeta->root;
103        newmeta->re_pad = oldmeta->re_pad;
104        newmeta->re_len = oldmeta->re_len;
105        newmeta->minkey = oldmeta->minkey;
106        newmeta->maxkey = oldmeta->maxkey;
107        memmove(newmeta->dbmeta.uid,
108            oldmeta->dbmeta.uid, sizeof(oldmeta->dbmeta.uid));
109        newmeta->dbmeta.flags = oldmeta->dbmeta.flags;
110        newmeta->dbmeta.record_count = 0;
111        newmeta->dbmeta.key_count = 0;
112        ZERO_LSN(newmeta->dbmeta.unused3);
113
114        /* Set the version number. */
115        newmeta->dbmeta.version = 8;
116
117        /* Upgrade the flags. */
118        if (LF_ISSET(DB_DUPSORT))
119                F_SET(&newmeta->dbmeta, BTM_DUPSORT);
120
121        *dirtyp = 1;
122        return (0);
123}
124
125/*
126 * __bam_31_lbtree --
127 *      Upgrade the database btree leaf pages.
128 *
129 * PUBLIC: int __bam_31_lbtree
130 * PUBLIC:      __P((DB *, char *, u_int32_t, DB_FH *, PAGE *, int *));
131 */
132int
133__bam_31_lbtree(dbp, real_name, flags, fhp, h, dirtyp)
134        DB *dbp;
135        char *real_name;
136        u_int32_t flags;
137        DB_FH *fhp;
138        PAGE *h;
139        int *dirtyp;
140{
141        BKEYDATA *bk;
142        db_pgno_t pgno;
143        db_indx_t indx;
144        int ret;
145
146        ret = 0;
147        for (indx = O_INDX; indx < NUM_ENT(h); indx += P_INDX) {
148                bk = GET_BKEYDATA(dbp, h, indx);
149                if (B_TYPE(bk->type) == B_DUPLICATE) {
150                        pgno = GET_BOVERFLOW(dbp, h, indx)->pgno;
151                        if ((ret = __db_31_offdup(dbp, real_name, fhp,
152                            LF_ISSET(DB_DUPSORT) ? 1 : 0, &pgno)) != 0)
153                                break;
154                        if (pgno != GET_BOVERFLOW(dbp, h, indx)->pgno) {
155                                *dirtyp = 1;
156                                GET_BOVERFLOW(dbp, h, indx)->pgno = pgno;
157                        }
158                }
159        }
160
161        return (ret);
162}
Note: See TracBrowser for help on using the repository browser.