~ken-vandine/+junk/mysql-3.23.58

« back to all changes in this revision

Viewing changes to bdb/btree/btree_auto.c

  • Committer: Ken VanDine
  • Date: 2018-01-27 03:45:15 UTC
  • Revision ID: ken.vandine@canonical.com-20180127034515-wpgsf0e7g0dq3qhv
init

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Do not edit: automatically built by gen_rec.awk. */
 
2
#include "db_config.h"
 
3
 
 
4
#ifndef NO_SYSTEM_INCLUDES
 
5
#include <sys/types.h>
 
6
 
 
7
#include <ctype.h>
 
8
#include <errno.h>
 
9
#include <string.h>
 
10
#endif
 
11
 
 
12
#include "db_int.h"
 
13
#include "db_page.h"
 
14
#include "db_dispatch.h"
 
15
#include "db_am.h"
 
16
#include "btree.h"
 
17
#include "txn.h"
 
18
 
 
19
int
 
20
__bam_pg_alloc_log(dbenv, txnid, ret_lsnp, flags,
 
21
        fileid, meta_lsn, page_lsn, pgno, ptype, next)
 
22
        DB_ENV *dbenv;
 
23
        DB_TXN *txnid;
 
24
        DB_LSN *ret_lsnp;
 
25
        u_int32_t flags;
 
26
        int32_t fileid;
 
27
        DB_LSN * meta_lsn;
 
28
        DB_LSN * page_lsn;
 
29
        db_pgno_t pgno;
 
30
        u_int32_t ptype;
 
31
        db_pgno_t next;
 
32
{
 
33
        DBT logrec;
 
34
        DB_LSN *lsnp, null_lsn;
 
35
        u_int32_t rectype, txn_num;
 
36
        int ret;
 
37
        u_int8_t *bp;
 
38
 
 
39
        rectype = DB_bam_pg_alloc;
 
40
        if (txnid != NULL &&
 
41
            TAILQ_FIRST(&txnid->kids) != NULL &&
 
42
            (ret = __txn_activekids(dbenv, rectype, txnid)) != 0)
 
43
                return (ret);
 
44
        txn_num = txnid == NULL ? 0 : txnid->txnid;
 
45
        if (txnid == NULL) {
 
46
                ZERO_LSN(null_lsn);
 
47
                lsnp = &null_lsn;
 
48
        } else
 
49
                lsnp = &txnid->last_lsn;
 
50
        logrec.size = sizeof(rectype) + sizeof(txn_num) + sizeof(DB_LSN)
 
51
            + sizeof(fileid)
 
52
            + sizeof(*meta_lsn)
 
53
            + sizeof(*page_lsn)
 
54
            + sizeof(pgno)
 
55
            + sizeof(ptype)
 
56
            + sizeof(next);
 
57
        if ((ret = __os_malloc(dbenv, logrec.size, NULL, &logrec.data)) != 0)
 
58
                return (ret);
 
59
 
 
60
        bp = logrec.data;
 
61
        memcpy(bp, &rectype, sizeof(rectype));
 
62
        bp += sizeof(rectype);
 
63
        memcpy(bp, &txn_num, sizeof(txn_num));
 
64
        bp += sizeof(txn_num);
 
65
        memcpy(bp, lsnp, sizeof(DB_LSN));
 
66
        bp += sizeof(DB_LSN);
 
67
        memcpy(bp, &fileid, sizeof(fileid));
 
68
        bp += sizeof(fileid);
 
69
        if (meta_lsn != NULL)
 
70
                memcpy(bp, meta_lsn, sizeof(*meta_lsn));
 
71
        else
 
72
                memset(bp, 0, sizeof(*meta_lsn));
 
73
        bp += sizeof(*meta_lsn);
 
74
        if (page_lsn != NULL)
 
75
                memcpy(bp, page_lsn, sizeof(*page_lsn));
 
76
        else
 
77
                memset(bp, 0, sizeof(*page_lsn));
 
78
        bp += sizeof(*page_lsn);
 
79
        memcpy(bp, &pgno, sizeof(pgno));
 
80
        bp += sizeof(pgno);
 
81
        memcpy(bp, &ptype, sizeof(ptype));
 
82
        bp += sizeof(ptype);
 
83
        memcpy(bp, &next, sizeof(next));
 
84
        bp += sizeof(next);
 
85
        DB_ASSERT((u_int32_t)(bp - (u_int8_t *)logrec.data) == logrec.size);
 
86
        ret = log_put(dbenv, ret_lsnp, (DBT *)&logrec, flags);
 
87
        if (txnid != NULL)
 
88
                txnid->last_lsn = *ret_lsnp;
 
89
        __os_free(logrec.data, logrec.size);
 
90
        return (ret);
 
91
}
 
92
 
 
93
int
 
94
__bam_pg_alloc_print(dbenv, dbtp, lsnp, notused2, notused3)
 
95
        DB_ENV *dbenv;
 
96
        DBT *dbtp;
 
97
        DB_LSN *lsnp;
 
98
        db_recops notused2;
 
99
        void *notused3;
 
100
{
 
101
        __bam_pg_alloc_args *argp;
 
102
        u_int32_t i;
 
103
        u_int ch;
 
104
        int ret;
 
105
 
 
106
        i = 0;
 
107
        ch = 0;
 
108
        notused2 = DB_TXN_ABORT;
 
109
        notused3 = NULL;
 
110
 
 
111
        if ((ret = __bam_pg_alloc_read(dbenv, dbtp->data, &argp)) != 0)
 
112
                return (ret);
 
113
        printf("[%lu][%lu]bam_pg_alloc: rec: %lu txnid %lx prevlsn [%lu][%lu]\n",
 
114
            (u_long)lsnp->file,
 
115
            (u_long)lsnp->offset,
 
116
            (u_long)argp->type,
 
117
            (u_long)argp->txnid->txnid,
 
118
            (u_long)argp->prev_lsn.file,
 
119
            (u_long)argp->prev_lsn.offset);
 
120
        printf("\tfileid: %ld\n", (long)argp->fileid);
 
121
        printf("\tmeta_lsn: [%lu][%lu]\n",
 
122
            (u_long)argp->meta_lsn.file, (u_long)argp->meta_lsn.offset);
 
123
        printf("\tpage_lsn: [%lu][%lu]\n",
 
124
            (u_long)argp->page_lsn.file, (u_long)argp->page_lsn.offset);
 
125
        printf("\tpgno: %lu\n", (u_long)argp->pgno);
 
126
        printf("\tptype: %lu\n", (u_long)argp->ptype);
 
127
        printf("\tnext: %lu\n", (u_long)argp->next);
 
128
        printf("\n");
 
129
        __os_free(argp, 0);
 
130
        return (0);
 
131
}
 
132
 
 
133
int
 
134
__bam_pg_alloc_read(dbenv, recbuf, argpp)
 
135
        DB_ENV *dbenv;
 
136
        void *recbuf;
 
137
        __bam_pg_alloc_args **argpp;
 
138
{
 
139
        __bam_pg_alloc_args *argp;
 
140
        u_int8_t *bp;
 
141
        int ret;
 
142
 
 
143
        ret = __os_malloc(dbenv, sizeof(__bam_pg_alloc_args) +
 
144
            sizeof(DB_TXN), NULL, &argp);
 
145
        if (ret != 0)
 
146
                return (ret);
 
147
        argp->txnid = (DB_TXN *)&argp[1];
 
148
        bp = recbuf;
 
149
        memcpy(&argp->type, bp, sizeof(argp->type));
 
150
        bp += sizeof(argp->type);
 
151
        memcpy(&argp->txnid->txnid,  bp, sizeof(argp->txnid->txnid));
 
152
        bp += sizeof(argp->txnid->txnid);
 
153
        memcpy(&argp->prev_lsn, bp, sizeof(DB_LSN));
 
154
        bp += sizeof(DB_LSN);
 
155
        memcpy(&argp->fileid, bp, sizeof(argp->fileid));
 
156
        bp += sizeof(argp->fileid);
 
157
        memcpy(&argp->meta_lsn, bp,  sizeof(argp->meta_lsn));
 
158
        bp += sizeof(argp->meta_lsn);
 
159
        memcpy(&argp->page_lsn, bp,  sizeof(argp->page_lsn));
 
160
        bp += sizeof(argp->page_lsn);
 
161
        memcpy(&argp->pgno, bp, sizeof(argp->pgno));
 
162
        bp += sizeof(argp->pgno);
 
163
        memcpy(&argp->ptype, bp, sizeof(argp->ptype));
 
164
        bp += sizeof(argp->ptype);
 
165
        memcpy(&argp->next, bp, sizeof(argp->next));
 
166
        bp += sizeof(argp->next);
 
167
        *argpp = argp;
 
168
        return (0);
 
169
}
 
170
 
 
171
int
 
172
__bam_pg_alloc1_print(dbenv, dbtp, lsnp, notused2, notused3)
 
173
        DB_ENV *dbenv;
 
174
        DBT *dbtp;
 
175
        DB_LSN *lsnp;
 
176
        db_recops notused2;
 
177
        void *notused3;
 
178
{
 
179
        __bam_pg_alloc1_args *argp;
 
180
        u_int32_t i;
 
181
        u_int ch;
 
182
        int ret;
 
183
 
 
184
        i = 0;
 
185
        ch = 0;
 
186
        notused2 = DB_TXN_ABORT;
 
187
        notused3 = NULL;
 
188
 
 
189
        if ((ret = __bam_pg_alloc1_read(dbenv, dbtp->data, &argp)) != 0)
 
190
                return (ret);
 
191
        printf("[%lu][%lu]bam_pg_alloc1: rec: %lu txnid %lx prevlsn [%lu][%lu]\n",
 
192
            (u_long)lsnp->file,
 
193
            (u_long)lsnp->offset,
 
194
            (u_long)argp->type,
 
195
            (u_long)argp->txnid->txnid,
 
196
            (u_long)argp->prev_lsn.file,
 
197
            (u_long)argp->prev_lsn.offset);
 
198
        printf("\tfileid: %ld\n", (long)argp->fileid);
 
199
        printf("\tmeta_lsn: [%lu][%lu]\n",
 
200
            (u_long)argp->meta_lsn.file, (u_long)argp->meta_lsn.offset);
 
201
        printf("\talloc_lsn: [%lu][%lu]\n",
 
202
            (u_long)argp->alloc_lsn.file, (u_long)argp->alloc_lsn.offset);
 
203
        printf("\tpage_lsn: [%lu][%lu]\n",
 
204
            (u_long)argp->page_lsn.file, (u_long)argp->page_lsn.offset);
 
205
        printf("\tpgno: %lu\n", (u_long)argp->pgno);
 
206
        printf("\tptype: %lu\n", (u_long)argp->ptype);
 
207
        printf("\tnext: %lu\n", (u_long)argp->next);
 
208
        printf("\n");
 
209
        __os_free(argp, 0);
 
210
        return (0);
 
211
}
 
212
 
 
213
int
 
214
__bam_pg_alloc1_read(dbenv, recbuf, argpp)
 
215
        DB_ENV *dbenv;
 
216
        void *recbuf;
 
217
        __bam_pg_alloc1_args **argpp;
 
218
{
 
219
        __bam_pg_alloc1_args *argp;
 
220
        u_int8_t *bp;
 
221
        int ret;
 
222
 
 
223
        ret = __os_malloc(dbenv, sizeof(__bam_pg_alloc1_args) +
 
224
            sizeof(DB_TXN), NULL, &argp);
 
225
        if (ret != 0)
 
226
                return (ret);
 
227
        argp->txnid = (DB_TXN *)&argp[1];
 
228
        bp = recbuf;
 
229
        memcpy(&argp->type, bp, sizeof(argp->type));
 
230
        bp += sizeof(argp->type);
 
231
        memcpy(&argp->txnid->txnid,  bp, sizeof(argp->txnid->txnid));
 
232
        bp += sizeof(argp->txnid->txnid);
 
233
        memcpy(&argp->prev_lsn, bp, sizeof(DB_LSN));
 
234
        bp += sizeof(DB_LSN);
 
235
        memcpy(&argp->fileid, bp, sizeof(argp->fileid));
 
236
        bp += sizeof(argp->fileid);
 
237
        memcpy(&argp->meta_lsn, bp,  sizeof(argp->meta_lsn));
 
238
        bp += sizeof(argp->meta_lsn);
 
239
        memcpy(&argp->alloc_lsn, bp,  sizeof(argp->alloc_lsn));
 
240
        bp += sizeof(argp->alloc_lsn);
 
241
        memcpy(&argp->page_lsn, bp,  sizeof(argp->page_lsn));
 
242
        bp += sizeof(argp->page_lsn);
 
243
        memcpy(&argp->pgno, bp, sizeof(argp->pgno));
 
244
        bp += sizeof(argp->pgno);
 
245
        memcpy(&argp->ptype, bp, sizeof(argp->ptype));
 
246
        bp += sizeof(argp->ptype);
 
247
        memcpy(&argp->next, bp, sizeof(argp->next));
 
248
        bp += sizeof(argp->next);
 
249
        *argpp = argp;
 
250
        return (0);
 
251
}
 
252
 
 
253
int
 
254
__bam_pg_free_log(dbenv, txnid, ret_lsnp, flags,
 
255
        fileid, pgno, meta_lsn, header, next)
 
256
        DB_ENV *dbenv;
 
257
        DB_TXN *txnid;
 
258
        DB_LSN *ret_lsnp;
 
259
        u_int32_t flags;
 
260
        int32_t fileid;
 
261
        db_pgno_t pgno;
 
262
        DB_LSN * meta_lsn;
 
263
        const DBT *header;
 
264
        db_pgno_t next;
 
265
{
 
266
        DBT logrec;
 
267
        DB_LSN *lsnp, null_lsn;
 
268
        u_int32_t zero;
 
269
        u_int32_t rectype, txn_num;
 
270
        int ret;
 
271
        u_int8_t *bp;
 
272
 
 
273
        rectype = DB_bam_pg_free;
 
274
        if (txnid != NULL &&
 
275
            TAILQ_FIRST(&txnid->kids) != NULL &&
 
276
            (ret = __txn_activekids(dbenv, rectype, txnid)) != 0)
 
277
                return (ret);
 
278
        txn_num = txnid == NULL ? 0 : txnid->txnid;
 
279
        if (txnid == NULL) {
 
280
                ZERO_LSN(null_lsn);
 
281
                lsnp = &null_lsn;
 
282
        } else
 
283
                lsnp = &txnid->last_lsn;
 
284
        logrec.size = sizeof(rectype) + sizeof(txn_num) + sizeof(DB_LSN)
 
285
            + sizeof(fileid)
 
286
            + sizeof(pgno)
 
287
            + sizeof(*meta_lsn)
 
288
            + sizeof(u_int32_t) + (header == NULL ? 0 : header->size)
 
289
            + sizeof(next);
 
290
        if ((ret = __os_malloc(dbenv, logrec.size, NULL, &logrec.data)) != 0)
 
291
                return (ret);
 
292
 
 
293
        bp = logrec.data;
 
294
        memcpy(bp, &rectype, sizeof(rectype));
 
295
        bp += sizeof(rectype);
 
296
        memcpy(bp, &txn_num, sizeof(txn_num));
 
297
        bp += sizeof(txn_num);
 
298
        memcpy(bp, lsnp, sizeof(DB_LSN));
 
299
        bp += sizeof(DB_LSN);
 
300
        memcpy(bp, &fileid, sizeof(fileid));
 
301
        bp += sizeof(fileid);
 
302
        memcpy(bp, &pgno, sizeof(pgno));
 
303
        bp += sizeof(pgno);
 
304
        if (meta_lsn != NULL)
 
305
                memcpy(bp, meta_lsn, sizeof(*meta_lsn));
 
306
        else
 
307
                memset(bp, 0, sizeof(*meta_lsn));
 
308
        bp += sizeof(*meta_lsn);
 
309
        if (header == NULL) {
 
310
                zero = 0;
 
311
                memcpy(bp, &zero, sizeof(u_int32_t));
 
312
                bp += sizeof(u_int32_t);
 
313
        } else {
 
314
                memcpy(bp, &header->size, sizeof(header->size));
 
315
                bp += sizeof(header->size);
 
316
                memcpy(bp, header->data, header->size);
 
317
                bp += header->size;
 
318
        }
 
319
        memcpy(bp, &next, sizeof(next));
 
320
        bp += sizeof(next);
 
321
        DB_ASSERT((u_int32_t)(bp - (u_int8_t *)logrec.data) == logrec.size);
 
322
        ret = log_put(dbenv, ret_lsnp, (DBT *)&logrec, flags);
 
323
        if (txnid != NULL)
 
324
                txnid->last_lsn = *ret_lsnp;
 
325
        __os_free(logrec.data, logrec.size);
 
326
        return (ret);
 
327
}
 
328
 
 
329
int
 
330
__bam_pg_free_print(dbenv, dbtp, lsnp, notused2, notused3)
 
331
        DB_ENV *dbenv;
 
332
        DBT *dbtp;
 
333
        DB_LSN *lsnp;
 
334
        db_recops notused2;
 
335
        void *notused3;
 
336
{
 
337
        __bam_pg_free_args *argp;
 
338
        u_int32_t i;
 
339
        u_int ch;
 
340
        int ret;
 
341
 
 
342
        i = 0;
 
343
        ch = 0;
 
344
        notused2 = DB_TXN_ABORT;
 
345
        notused3 = NULL;
 
346
 
 
347
        if ((ret = __bam_pg_free_read(dbenv, dbtp->data, &argp)) != 0)
 
348
                return (ret);
 
349
        printf("[%lu][%lu]bam_pg_free: rec: %lu txnid %lx prevlsn [%lu][%lu]\n",
 
350
            (u_long)lsnp->file,
 
351
            (u_long)lsnp->offset,
 
352
            (u_long)argp->type,
 
353
            (u_long)argp->txnid->txnid,
 
354
            (u_long)argp->prev_lsn.file,
 
355
            (u_long)argp->prev_lsn.offset);
 
356
        printf("\tfileid: %ld\n", (long)argp->fileid);
 
357
        printf("\tpgno: %lu\n", (u_long)argp->pgno);
 
358
        printf("\tmeta_lsn: [%lu][%lu]\n",
 
359
            (u_long)argp->meta_lsn.file, (u_long)argp->meta_lsn.offset);
 
360
        printf("\theader: ");
 
361
        for (i = 0; i < argp->header.size; i++) {
 
362
                ch = ((u_int8_t *)argp->header.data)[i];
 
363
                if (isprint(ch) || ch == 0xa)
 
364
                        putchar(ch);
 
365
                else
 
366
                        printf("%#x ", ch);
 
367
        }
 
368
        printf("\n");
 
369
        printf("\tnext: %lu\n", (u_long)argp->next);
 
370
        printf("\n");
 
371
        __os_free(argp, 0);
 
372
        return (0);
 
373
}
 
374
 
 
375
int
 
376
__bam_pg_free_read(dbenv, recbuf, argpp)
 
377
        DB_ENV *dbenv;
 
378
        void *recbuf;
 
379
        __bam_pg_free_args **argpp;
 
380
{
 
381
        __bam_pg_free_args *argp;
 
382
        u_int8_t *bp;
 
383
        int ret;
 
384
 
 
385
        ret = __os_malloc(dbenv, sizeof(__bam_pg_free_args) +
 
386
            sizeof(DB_TXN), NULL, &argp);
 
387
        if (ret != 0)
 
388
                return (ret);
 
389
        argp->txnid = (DB_TXN *)&argp[1];
 
390
        bp = recbuf;
 
391
        memcpy(&argp->type, bp, sizeof(argp->type));
 
392
        bp += sizeof(argp->type);
 
393
        memcpy(&argp->txnid->txnid,  bp, sizeof(argp->txnid->txnid));
 
394
        bp += sizeof(argp->txnid->txnid);
 
395
        memcpy(&argp->prev_lsn, bp, sizeof(DB_LSN));
 
396
        bp += sizeof(DB_LSN);
 
397
        memcpy(&argp->fileid, bp, sizeof(argp->fileid));
 
398
        bp += sizeof(argp->fileid);
 
399
        memcpy(&argp->pgno, bp, sizeof(argp->pgno));
 
400
        bp += sizeof(argp->pgno);
 
401
        memcpy(&argp->meta_lsn, bp,  sizeof(argp->meta_lsn));
 
402
        bp += sizeof(argp->meta_lsn);
 
403
        memset(&argp->header, 0, sizeof(argp->header));
 
404
        memcpy(&argp->header.size, bp, sizeof(u_int32_t));
 
405
        bp += sizeof(u_int32_t);
 
406
        argp->header.data = bp;
 
407
        bp += argp->header.size;
 
408
        memcpy(&argp->next, bp, sizeof(argp->next));
 
409
        bp += sizeof(argp->next);
 
410
        *argpp = argp;
 
411
        return (0);
 
412
}
 
413
 
 
414
int
 
415
__bam_pg_free1_print(dbenv, dbtp, lsnp, notused2, notused3)
 
416
        DB_ENV *dbenv;
 
417
        DBT *dbtp;
 
418
        DB_LSN *lsnp;
 
419
        db_recops notused2;
 
420
        void *notused3;
 
421
{
 
422
        __bam_pg_free1_args *argp;
 
423
        u_int32_t i;
 
424
        u_int ch;
 
425
        int ret;
 
426
 
 
427
        i = 0;
 
428
        ch = 0;
 
429
        notused2 = DB_TXN_ABORT;
 
430
        notused3 = NULL;
 
431
 
 
432
        if ((ret = __bam_pg_free1_read(dbenv, dbtp->data, &argp)) != 0)
 
433
                return (ret);
 
434
        printf("[%lu][%lu]bam_pg_free1: rec: %lu txnid %lx prevlsn [%lu][%lu]\n",
 
435
            (u_long)lsnp->file,
 
436
            (u_long)lsnp->offset,
 
437
            (u_long)argp->type,
 
438
            (u_long)argp->txnid->txnid,
 
439
            (u_long)argp->prev_lsn.file,
 
440
            (u_long)argp->prev_lsn.offset);
 
441
        printf("\tfileid: %ld\n", (long)argp->fileid);
 
442
        printf("\tpgno: %lu\n", (u_long)argp->pgno);
 
443
        printf("\tmeta_lsn: [%lu][%lu]\n",
 
444
            (u_long)argp->meta_lsn.file, (u_long)argp->meta_lsn.offset);
 
445
        printf("\talloc_lsn: [%lu][%lu]\n",
 
446
            (u_long)argp->alloc_lsn.file, (u_long)argp->alloc_lsn.offset);
 
447
        printf("\theader: ");
 
448
        for (i = 0; i < argp->header.size; i++) {
 
449
                ch = ((u_int8_t *)argp->header.data)[i];
 
450
                if (isprint(ch) || ch == 0xa)
 
451
                        putchar(ch);
 
452
                else
 
453
                        printf("%#x ", ch);
 
454
        }
 
455
        printf("\n");
 
456
        printf("\tnext: %lu\n", (u_long)argp->next);
 
457
        printf("\n");
 
458
        __os_free(argp, 0);
 
459
        return (0);
 
460
}
 
461
 
 
462
int
 
463
__bam_pg_free1_read(dbenv, recbuf, argpp)
 
464
        DB_ENV *dbenv;
 
465
        void *recbuf;
 
466
        __bam_pg_free1_args **argpp;
 
467
{
 
468
        __bam_pg_free1_args *argp;
 
469
        u_int8_t *bp;
 
470
        int ret;
 
471
 
 
472
        ret = __os_malloc(dbenv, sizeof(__bam_pg_free1_args) +
 
473
            sizeof(DB_TXN), NULL, &argp);
 
474
        if (ret != 0)
 
475
                return (ret);
 
476
        argp->txnid = (DB_TXN *)&argp[1];
 
477
        bp = recbuf;
 
478
        memcpy(&argp->type, bp, sizeof(argp->type));
 
479
        bp += sizeof(argp->type);
 
480
        memcpy(&argp->txnid->txnid,  bp, sizeof(argp->txnid->txnid));
 
481
        bp += sizeof(argp->txnid->txnid);
 
482
        memcpy(&argp->prev_lsn, bp, sizeof(DB_LSN));
 
483
        bp += sizeof(DB_LSN);
 
484
        memcpy(&argp->fileid, bp, sizeof(argp->fileid));
 
485
        bp += sizeof(argp->fileid);
 
486
        memcpy(&argp->pgno, bp, sizeof(argp->pgno));
 
487
        bp += sizeof(argp->pgno);
 
488
        memcpy(&argp->meta_lsn, bp,  sizeof(argp->meta_lsn));
 
489
        bp += sizeof(argp->meta_lsn);
 
490
        memcpy(&argp->alloc_lsn, bp,  sizeof(argp->alloc_lsn));
 
491
        bp += sizeof(argp->alloc_lsn);
 
492
        memset(&argp->header, 0, sizeof(argp->header));
 
493
        memcpy(&argp->header.size, bp, sizeof(u_int32_t));
 
494
        bp += sizeof(u_int32_t);
 
495
        argp->header.data = bp;
 
496
        bp += argp->header.size;
 
497
        memcpy(&argp->next, bp, sizeof(argp->next));
 
498
        bp += sizeof(argp->next);
 
499
        *argpp = argp;
 
500
        return (0);
 
501
}
 
502
 
 
503
int
 
504
__bam_split1_print(dbenv, dbtp, lsnp, notused2, notused3)
 
505
        DB_ENV *dbenv;
 
506
        DBT *dbtp;
 
507
        DB_LSN *lsnp;
 
508
        db_recops notused2;
 
509
        void *notused3;
 
510
{
 
511
        __bam_split1_args *argp;
 
512
        u_int32_t i;
 
513
        u_int ch;
 
514
        int ret;
 
515
 
 
516
        i = 0;
 
517
        ch = 0;
 
518
        notused2 = DB_TXN_ABORT;
 
519
        notused3 = NULL;
 
520
 
 
521
        if ((ret = __bam_split1_read(dbenv, dbtp->data, &argp)) != 0)
 
522
                return (ret);
 
523
        printf("[%lu][%lu]bam_split1: rec: %lu txnid %lx prevlsn [%lu][%lu]\n",
 
524
            (u_long)lsnp->file,
 
525
            (u_long)lsnp->offset,
 
526
            (u_long)argp->type,
 
527
            (u_long)argp->txnid->txnid,
 
528
            (u_long)argp->prev_lsn.file,
 
529
            (u_long)argp->prev_lsn.offset);
 
530
        printf("\tfileid: %ld\n", (long)argp->fileid);
 
531
        printf("\tleft: %lu\n", (u_long)argp->left);
 
532
        printf("\tllsn: [%lu][%lu]\n",
 
533
            (u_long)argp->llsn.file, (u_long)argp->llsn.offset);
 
534
        printf("\tright: %lu\n", (u_long)argp->right);
 
535
        printf("\trlsn: [%lu][%lu]\n",
 
536
            (u_long)argp->rlsn.file, (u_long)argp->rlsn.offset);
 
537
        printf("\tindx: %lu\n", (u_long)argp->indx);
 
538
        printf("\tnpgno: %lu\n", (u_long)argp->npgno);
 
539
        printf("\tnlsn: [%lu][%lu]\n",
 
540
            (u_long)argp->nlsn.file, (u_long)argp->nlsn.offset);
 
541
        printf("\tpg: ");
 
542
        for (i = 0; i < argp->pg.size; i++) {
 
543
                ch = ((u_int8_t *)argp->pg.data)[i];
 
544
                if (isprint(ch) || ch == 0xa)
 
545
                        putchar(ch);
 
546
                else
 
547
                        printf("%#x ", ch);
 
548
        }
 
549
        printf("\n");
 
550
        printf("\n");
 
551
        __os_free(argp, 0);
 
552
        return (0);
 
553
}
 
554
 
 
555
int
 
556
__bam_split1_read(dbenv, recbuf, argpp)
 
557
        DB_ENV *dbenv;
 
558
        void *recbuf;
 
559
        __bam_split1_args **argpp;
 
560
{
 
561
        __bam_split1_args *argp;
 
562
        u_int8_t *bp;
 
563
        int ret;
 
564
 
 
565
        ret = __os_malloc(dbenv, sizeof(__bam_split1_args) +
 
566
            sizeof(DB_TXN), NULL, &argp);
 
567
        if (ret != 0)
 
568
                return (ret);
 
569
        argp->txnid = (DB_TXN *)&argp[1];
 
570
        bp = recbuf;
 
571
        memcpy(&argp->type, bp, sizeof(argp->type));
 
572
        bp += sizeof(argp->type);
 
573
        memcpy(&argp->txnid->txnid,  bp, sizeof(argp->txnid->txnid));
 
574
        bp += sizeof(argp->txnid->txnid);
 
575
        memcpy(&argp->prev_lsn, bp, sizeof(DB_LSN));
 
576
        bp += sizeof(DB_LSN);
 
577
        memcpy(&argp->fileid, bp, sizeof(argp->fileid));
 
578
        bp += sizeof(argp->fileid);
 
579
        memcpy(&argp->left, bp, sizeof(argp->left));
 
580
        bp += sizeof(argp->left);
 
581
        memcpy(&argp->llsn, bp,  sizeof(argp->llsn));
 
582
        bp += sizeof(argp->llsn);
 
583
        memcpy(&argp->right, bp, sizeof(argp->right));
 
584
        bp += sizeof(argp->right);
 
585
        memcpy(&argp->rlsn, bp,  sizeof(argp->rlsn));
 
586
        bp += sizeof(argp->rlsn);
 
587
        memcpy(&argp->indx, bp, sizeof(argp->indx));
 
588
        bp += sizeof(argp->indx);
 
589
        memcpy(&argp->npgno, bp, sizeof(argp->npgno));
 
590
        bp += sizeof(argp->npgno);
 
591
        memcpy(&argp->nlsn, bp,  sizeof(argp->nlsn));
 
592
        bp += sizeof(argp->nlsn);
 
593
        memset(&argp->pg, 0, sizeof(argp->pg));
 
594
        memcpy(&argp->pg.size, bp, sizeof(u_int32_t));
 
595
        bp += sizeof(u_int32_t);
 
596
        argp->pg.data = bp;
 
597
        bp += argp->pg.size;
 
598
        *argpp = argp;
 
599
        return (0);
 
600
}
 
601
 
 
602
int
 
603
__bam_split_log(dbenv, txnid, ret_lsnp, flags,
 
604
        fileid, left, llsn, right, rlsn, indx,
 
605
        npgno, nlsn, root_pgno, pg, opflags)
 
606
        DB_ENV *dbenv;
 
607
        DB_TXN *txnid;
 
608
        DB_LSN *ret_lsnp;
 
609
        u_int32_t flags;
 
610
        int32_t fileid;
 
611
        db_pgno_t left;
 
612
        DB_LSN * llsn;
 
613
        db_pgno_t right;
 
614
        DB_LSN * rlsn;
 
615
        u_int32_t indx;
 
616
        db_pgno_t npgno;
 
617
        DB_LSN * nlsn;
 
618
        db_pgno_t root_pgno;
 
619
        const DBT *pg;
 
620
        u_int32_t opflags;
 
621
{
 
622
        DBT logrec;
 
623
        DB_LSN *lsnp, null_lsn;
 
624
        u_int32_t zero;
 
625
        u_int32_t rectype, txn_num;
 
626
        int ret;
 
627
        u_int8_t *bp;
 
628
 
 
629
        rectype = DB_bam_split;
 
630
        if (txnid != NULL &&
 
631
            TAILQ_FIRST(&txnid->kids) != NULL &&
 
632
            (ret = __txn_activekids(dbenv, rectype, txnid)) != 0)
 
633
                return (ret);
 
634
        txn_num = txnid == NULL ? 0 : txnid->txnid;
 
635
        if (txnid == NULL) {
 
636
                ZERO_LSN(null_lsn);
 
637
                lsnp = &null_lsn;
 
638
        } else
 
639
                lsnp = &txnid->last_lsn;
 
640
        logrec.size = sizeof(rectype) + sizeof(txn_num) + sizeof(DB_LSN)
 
641
            + sizeof(fileid)
 
642
            + sizeof(left)
 
643
            + sizeof(*llsn)
 
644
            + sizeof(right)
 
645
            + sizeof(*rlsn)
 
646
            + sizeof(indx)
 
647
            + sizeof(npgno)
 
648
            + sizeof(*nlsn)
 
649
            + sizeof(root_pgno)
 
650
            + sizeof(u_int32_t) + (pg == NULL ? 0 : pg->size)
 
651
            + sizeof(opflags);
 
652
        if ((ret = __os_malloc(dbenv, logrec.size, NULL, &logrec.data)) != 0)
 
653
                return (ret);
 
654
 
 
655
        bp = logrec.data;
 
656
        memcpy(bp, &rectype, sizeof(rectype));
 
657
        bp += sizeof(rectype);
 
658
        memcpy(bp, &txn_num, sizeof(txn_num));
 
659
        bp += sizeof(txn_num);
 
660
        memcpy(bp, lsnp, sizeof(DB_LSN));
 
661
        bp += sizeof(DB_LSN);
 
662
        memcpy(bp, &fileid, sizeof(fileid));
 
663
        bp += sizeof(fileid);
 
664
        memcpy(bp, &left, sizeof(left));
 
665
        bp += sizeof(left);
 
666
        if (llsn != NULL)
 
667
                memcpy(bp, llsn, sizeof(*llsn));
 
668
        else
 
669
                memset(bp, 0, sizeof(*llsn));
 
670
        bp += sizeof(*llsn);
 
671
        memcpy(bp, &right, sizeof(right));
 
672
        bp += sizeof(right);
 
673
        if (rlsn != NULL)
 
674
                memcpy(bp, rlsn, sizeof(*rlsn));
 
675
        else
 
676
                memset(bp, 0, sizeof(*rlsn));
 
677
        bp += sizeof(*rlsn);
 
678
        memcpy(bp, &indx, sizeof(indx));
 
679
        bp += sizeof(indx);
 
680
        memcpy(bp, &npgno, sizeof(npgno));
 
681
        bp += sizeof(npgno);
 
682
        if (nlsn != NULL)
 
683
                memcpy(bp, nlsn, sizeof(*nlsn));
 
684
        else
 
685
                memset(bp, 0, sizeof(*nlsn));
 
686
        bp += sizeof(*nlsn);
 
687
        memcpy(bp, &root_pgno, sizeof(root_pgno));
 
688
        bp += sizeof(root_pgno);
 
689
        if (pg == NULL) {
 
690
                zero = 0;
 
691
                memcpy(bp, &zero, sizeof(u_int32_t));
 
692
                bp += sizeof(u_int32_t);
 
693
        } else {
 
694
                memcpy(bp, &pg->size, sizeof(pg->size));
 
695
                bp += sizeof(pg->size);
 
696
                memcpy(bp, pg->data, pg->size);
 
697
                bp += pg->size;
 
698
        }
 
699
        memcpy(bp, &opflags, sizeof(opflags));
 
700
        bp += sizeof(opflags);
 
701
        DB_ASSERT((u_int32_t)(bp - (u_int8_t *)logrec.data) == logrec.size);
 
702
        ret = log_put(dbenv, ret_lsnp, (DBT *)&logrec, flags);
 
703
        if (txnid != NULL)
 
704
                txnid->last_lsn = *ret_lsnp;
 
705
        __os_free(logrec.data, logrec.size);
 
706
        return (ret);
 
707
}
 
708
 
 
709
int
 
710
__bam_split_print(dbenv, dbtp, lsnp, notused2, notused3)
 
711
        DB_ENV *dbenv;
 
712
        DBT *dbtp;
 
713
        DB_LSN *lsnp;
 
714
        db_recops notused2;
 
715
        void *notused3;
 
716
{
 
717
        __bam_split_args *argp;
 
718
        u_int32_t i;
 
719
        u_int ch;
 
720
        int ret;
 
721
 
 
722
        i = 0;
 
723
        ch = 0;
 
724
        notused2 = DB_TXN_ABORT;
 
725
        notused3 = NULL;
 
726
 
 
727
        if ((ret = __bam_split_read(dbenv, dbtp->data, &argp)) != 0)
 
728
                return (ret);
 
729
        printf("[%lu][%lu]bam_split: rec: %lu txnid %lx prevlsn [%lu][%lu]\n",
 
730
            (u_long)lsnp->file,
 
731
            (u_long)lsnp->offset,
 
732
            (u_long)argp->type,
 
733
            (u_long)argp->txnid->txnid,
 
734
            (u_long)argp->prev_lsn.file,
 
735
            (u_long)argp->prev_lsn.offset);
 
736
        printf("\tfileid: %ld\n", (long)argp->fileid);
 
737
        printf("\tleft: %lu\n", (u_long)argp->left);
 
738
        printf("\tllsn: [%lu][%lu]\n",
 
739
            (u_long)argp->llsn.file, (u_long)argp->llsn.offset);
 
740
        printf("\tright: %lu\n", (u_long)argp->right);
 
741
        printf("\trlsn: [%lu][%lu]\n",
 
742
            (u_long)argp->rlsn.file, (u_long)argp->rlsn.offset);
 
743
        printf("\tindx: %lu\n", (u_long)argp->indx);
 
744
        printf("\tnpgno: %lu\n", (u_long)argp->npgno);
 
745
        printf("\tnlsn: [%lu][%lu]\n",
 
746
            (u_long)argp->nlsn.file, (u_long)argp->nlsn.offset);
 
747
        printf("\troot_pgno: %lu\n", (u_long)argp->root_pgno);
 
748
        printf("\tpg: ");
 
749
        for (i = 0; i < argp->pg.size; i++) {
 
750
                ch = ((u_int8_t *)argp->pg.data)[i];
 
751
                if (isprint(ch) || ch == 0xa)
 
752
                        putchar(ch);
 
753
                else
 
754
                        printf("%#x ", ch);
 
755
        }
 
756
        printf("\n");
 
757
        printf("\topflags: %lu\n", (u_long)argp->opflags);
 
758
        printf("\n");
 
759
        __os_free(argp, 0);
 
760
        return (0);
 
761
}
 
762
 
 
763
int
 
764
__bam_split_read(dbenv, recbuf, argpp)
 
765
        DB_ENV *dbenv;
 
766
        void *recbuf;
 
767
        __bam_split_args **argpp;
 
768
{
 
769
        __bam_split_args *argp;
 
770
        u_int8_t *bp;
 
771
        int ret;
 
772
 
 
773
        ret = __os_malloc(dbenv, sizeof(__bam_split_args) +
 
774
            sizeof(DB_TXN), NULL, &argp);
 
775
        if (ret != 0)
 
776
                return (ret);
 
777
        argp->txnid = (DB_TXN *)&argp[1];
 
778
        bp = recbuf;
 
779
        memcpy(&argp->type, bp, sizeof(argp->type));
 
780
        bp += sizeof(argp->type);
 
781
        memcpy(&argp->txnid->txnid,  bp, sizeof(argp->txnid->txnid));
 
782
        bp += sizeof(argp->txnid->txnid);
 
783
        memcpy(&argp->prev_lsn, bp, sizeof(DB_LSN));
 
784
        bp += sizeof(DB_LSN);
 
785
        memcpy(&argp->fileid, bp, sizeof(argp->fileid));
 
786
        bp += sizeof(argp->fileid);
 
787
        memcpy(&argp->left, bp, sizeof(argp->left));
 
788
        bp += sizeof(argp->left);
 
789
        memcpy(&argp->llsn, bp,  sizeof(argp->llsn));
 
790
        bp += sizeof(argp->llsn);
 
791
        memcpy(&argp->right, bp, sizeof(argp->right));
 
792
        bp += sizeof(argp->right);
 
793
        memcpy(&argp->rlsn, bp,  sizeof(argp->rlsn));
 
794
        bp += sizeof(argp->rlsn);
 
795
        memcpy(&argp->indx, bp, sizeof(argp->indx));
 
796
        bp += sizeof(argp->indx);
 
797
        memcpy(&argp->npgno, bp, sizeof(argp->npgno));
 
798
        bp += sizeof(argp->npgno);
 
799
        memcpy(&argp->nlsn, bp,  sizeof(argp->nlsn));
 
800
        bp += sizeof(argp->nlsn);
 
801
        memcpy(&argp->root_pgno, bp, sizeof(argp->root_pgno));
 
802
        bp += sizeof(argp->root_pgno);
 
803
        memset(&argp->pg, 0, sizeof(argp->pg));
 
804
        memcpy(&argp->pg.size, bp, sizeof(u_int32_t));
 
805
        bp += sizeof(u_int32_t);
 
806
        argp->pg.data = bp;
 
807
        bp += argp->pg.size;
 
808
        memcpy(&argp->opflags, bp, sizeof(argp->opflags));
 
809
        bp += sizeof(argp->opflags);
 
810
        *argpp = argp;
 
811
        return (0);
 
812
}
 
813
 
 
814
int
 
815
__bam_rsplit1_print(dbenv, dbtp, lsnp, notused2, notused3)
 
816
        DB_ENV *dbenv;
 
817
        DBT *dbtp;
 
818
        DB_LSN *lsnp;
 
819
        db_recops notused2;
 
820
        void *notused3;
 
821
{
 
822
        __bam_rsplit1_args *argp;
 
823
        u_int32_t i;
 
824
        u_int ch;
 
825
        int ret;
 
826
 
 
827
        i = 0;
 
828
        ch = 0;
 
829
        notused2 = DB_TXN_ABORT;
 
830
        notused3 = NULL;
 
831
 
 
832
        if ((ret = __bam_rsplit1_read(dbenv, dbtp->data, &argp)) != 0)
 
833
                return (ret);
 
834
        printf("[%lu][%lu]bam_rsplit1: rec: %lu txnid %lx prevlsn [%lu][%lu]\n",
 
835
            (u_long)lsnp->file,
 
836
            (u_long)lsnp->offset,
 
837
            (u_long)argp->type,
 
838
            (u_long)argp->txnid->txnid,
 
839
            (u_long)argp->prev_lsn.file,
 
840
            (u_long)argp->prev_lsn.offset);
 
841
        printf("\tfileid: %ld\n", (long)argp->fileid);
 
842
        printf("\tpgno: %lu\n", (u_long)argp->pgno);
 
843
        printf("\tpgdbt: ");
 
844
        for (i = 0; i < argp->pgdbt.size; i++) {
 
845
                ch = ((u_int8_t *)argp->pgdbt.data)[i];
 
846
                if (isprint(ch) || ch == 0xa)
 
847
                        putchar(ch);
 
848
                else
 
849
                        printf("%#x ", ch);
 
850
        }
 
851
        printf("\n");
 
852
        printf("\tnrec: %lu\n", (u_long)argp->nrec);
 
853
        printf("\trootent: ");
 
854
        for (i = 0; i < argp->rootent.size; i++) {
 
855
                ch = ((u_int8_t *)argp->rootent.data)[i];
 
856
                if (isprint(ch) || ch == 0xa)
 
857
                        putchar(ch);
 
858
                else
 
859
                        printf("%#x ", ch);
 
860
        }
 
861
        printf("\n");
 
862
        printf("\trootlsn: [%lu][%lu]\n",
 
863
            (u_long)argp->rootlsn.file, (u_long)argp->rootlsn.offset);
 
864
        printf("\n");
 
865
        __os_free(argp, 0);
 
866
        return (0);
 
867
}
 
868
 
 
869
int
 
870
__bam_rsplit1_read(dbenv, recbuf, argpp)
 
871
        DB_ENV *dbenv;
 
872
        void *recbuf;
 
873
        __bam_rsplit1_args **argpp;
 
874
{
 
875
        __bam_rsplit1_args *argp;
 
876
        u_int8_t *bp;
 
877
        int ret;
 
878
 
 
879
        ret = __os_malloc(dbenv, sizeof(__bam_rsplit1_args) +
 
880
            sizeof(DB_TXN), NULL, &argp);
 
881
        if (ret != 0)
 
882
                return (ret);
 
883
        argp->txnid = (DB_TXN *)&argp[1];
 
884
        bp = recbuf;
 
885
        memcpy(&argp->type, bp, sizeof(argp->type));
 
886
        bp += sizeof(argp->type);
 
887
        memcpy(&argp->txnid->txnid,  bp, sizeof(argp->txnid->txnid));
 
888
        bp += sizeof(argp->txnid->txnid);
 
889
        memcpy(&argp->prev_lsn, bp, sizeof(DB_LSN));
 
890
        bp += sizeof(DB_LSN);
 
891
        memcpy(&argp->fileid, bp, sizeof(argp->fileid));
 
892
        bp += sizeof(argp->fileid);
 
893
        memcpy(&argp->pgno, bp, sizeof(argp->pgno));
 
894
        bp += sizeof(argp->pgno);
 
895
        memset(&argp->pgdbt, 0, sizeof(argp->pgdbt));
 
896
        memcpy(&argp->pgdbt.size, bp, sizeof(u_int32_t));
 
897
        bp += sizeof(u_int32_t);
 
898
        argp->pgdbt.data = bp;
 
899
        bp += argp->pgdbt.size;
 
900
        memcpy(&argp->nrec, bp, sizeof(argp->nrec));
 
901
        bp += sizeof(argp->nrec);
 
902
        memset(&argp->rootent, 0, sizeof(argp->rootent));
 
903
        memcpy(&argp->rootent.size, bp, sizeof(u_int32_t));
 
904
        bp += sizeof(u_int32_t);
 
905
        argp->rootent.data = bp;
 
906
        bp += argp->rootent.size;
 
907
        memcpy(&argp->rootlsn, bp,  sizeof(argp->rootlsn));
 
908
        bp += sizeof(argp->rootlsn);
 
909
        *argpp = argp;
 
910
        return (0);
 
911
}
 
912
 
 
913
int
 
914
__bam_rsplit_log(dbenv, txnid, ret_lsnp, flags,
 
915
        fileid, pgno, pgdbt, root_pgno, nrec, rootent,
 
916
        rootlsn)
 
917
        DB_ENV *dbenv;
 
918
        DB_TXN *txnid;
 
919
        DB_LSN *ret_lsnp;
 
920
        u_int32_t flags;
 
921
        int32_t fileid;
 
922
        db_pgno_t pgno;
 
923
        const DBT *pgdbt;
 
924
        db_pgno_t root_pgno;
 
925
        db_pgno_t nrec;
 
926
        const DBT *rootent;
 
927
        DB_LSN * rootlsn;
 
928
{
 
929
        DBT logrec;
 
930
        DB_LSN *lsnp, null_lsn;
 
931
        u_int32_t zero;
 
932
        u_int32_t rectype, txn_num;
 
933
        int ret;
 
934
        u_int8_t *bp;
 
935
 
 
936
        rectype = DB_bam_rsplit;
 
937
        if (txnid != NULL &&
 
938
            TAILQ_FIRST(&txnid->kids) != NULL &&
 
939
            (ret = __txn_activekids(dbenv, rectype, txnid)) != 0)
 
940
                return (ret);
 
941
        txn_num = txnid == NULL ? 0 : txnid->txnid;
 
942
        if (txnid == NULL) {
 
943
                ZERO_LSN(null_lsn);
 
944
                lsnp = &null_lsn;
 
945
        } else
 
946
                lsnp = &txnid->last_lsn;
 
947
        logrec.size = sizeof(rectype) + sizeof(txn_num) + sizeof(DB_LSN)
 
948
            + sizeof(fileid)
 
949
            + sizeof(pgno)
 
950
            + sizeof(u_int32_t) + (pgdbt == NULL ? 0 : pgdbt->size)
 
951
            + sizeof(root_pgno)
 
952
            + sizeof(nrec)
 
953
            + sizeof(u_int32_t) + (rootent == NULL ? 0 : rootent->size)
 
954
            + sizeof(*rootlsn);
 
955
        if ((ret = __os_malloc(dbenv, logrec.size, NULL, &logrec.data)) != 0)
 
956
                return (ret);
 
957
 
 
958
        bp = logrec.data;
 
959
        memcpy(bp, &rectype, sizeof(rectype));
 
960
        bp += sizeof(rectype);
 
961
        memcpy(bp, &txn_num, sizeof(txn_num));
 
962
        bp += sizeof(txn_num);
 
963
        memcpy(bp, lsnp, sizeof(DB_LSN));
 
964
        bp += sizeof(DB_LSN);
 
965
        memcpy(bp, &fileid, sizeof(fileid));
 
966
        bp += sizeof(fileid);
 
967
        memcpy(bp, &pgno, sizeof(pgno));
 
968
        bp += sizeof(pgno);
 
969
        if (pgdbt == NULL) {
 
970
                zero = 0;
 
971
                memcpy(bp, &zero, sizeof(u_int32_t));
 
972
                bp += sizeof(u_int32_t);
 
973
        } else {
 
974
                memcpy(bp, &pgdbt->size, sizeof(pgdbt->size));
 
975
                bp += sizeof(pgdbt->size);
 
976
                memcpy(bp, pgdbt->data, pgdbt->size);
 
977
                bp += pgdbt->size;
 
978
        }
 
979
        memcpy(bp, &root_pgno, sizeof(root_pgno));
 
980
        bp += sizeof(root_pgno);
 
981
        memcpy(bp, &nrec, sizeof(nrec));
 
982
        bp += sizeof(nrec);
 
983
        if (rootent == NULL) {
 
984
                zero = 0;
 
985
                memcpy(bp, &zero, sizeof(u_int32_t));
 
986
                bp += sizeof(u_int32_t);
 
987
        } else {
 
988
                memcpy(bp, &rootent->size, sizeof(rootent->size));
 
989
                bp += sizeof(rootent->size);
 
990
                memcpy(bp, rootent->data, rootent->size);
 
991
                bp += rootent->size;
 
992
        }
 
993
        if (rootlsn != NULL)
 
994
                memcpy(bp, rootlsn, sizeof(*rootlsn));
 
995
        else
 
996
                memset(bp, 0, sizeof(*rootlsn));
 
997
        bp += sizeof(*rootlsn);
 
998
        DB_ASSERT((u_int32_t)(bp - (u_int8_t *)logrec.data) == logrec.size);
 
999
        ret = log_put(dbenv, ret_lsnp, (DBT *)&logrec, flags);
 
1000
        if (txnid != NULL)
 
1001
                txnid->last_lsn = *ret_lsnp;
 
1002
        __os_free(logrec.data, logrec.size);
 
1003
        return (ret);
 
1004
}
 
1005
 
 
1006
int
 
1007
__bam_rsplit_print(dbenv, dbtp, lsnp, notused2, notused3)
 
1008
        DB_ENV *dbenv;
 
1009
        DBT *dbtp;
 
1010
        DB_LSN *lsnp;
 
1011
        db_recops notused2;
 
1012
        void *notused3;
 
1013
{
 
1014
        __bam_rsplit_args *argp;
 
1015
        u_int32_t i;
 
1016
        u_int ch;
 
1017
        int ret;
 
1018
 
 
1019
        i = 0;
 
1020
        ch = 0;
 
1021
        notused2 = DB_TXN_ABORT;
 
1022
        notused3 = NULL;
 
1023
 
 
1024
        if ((ret = __bam_rsplit_read(dbenv, dbtp->data, &argp)) != 0)
 
1025
                return (ret);
 
1026
        printf("[%lu][%lu]bam_rsplit: rec: %lu txnid %lx prevlsn [%lu][%lu]\n",
 
1027
            (u_long)lsnp->file,
 
1028
            (u_long)lsnp->offset,
 
1029
            (u_long)argp->type,
 
1030
            (u_long)argp->txnid->txnid,
 
1031
            (u_long)argp->prev_lsn.file,
 
1032
            (u_long)argp->prev_lsn.offset);
 
1033
        printf("\tfileid: %ld\n", (long)argp->fileid);
 
1034
        printf("\tpgno: %lu\n", (u_long)argp->pgno);
 
1035
        printf("\tpgdbt: ");
 
1036
        for (i = 0; i < argp->pgdbt.size; i++) {
 
1037
                ch = ((u_int8_t *)argp->pgdbt.data)[i];
 
1038
                if (isprint(ch) || ch == 0xa)
 
1039
                        putchar(ch);
 
1040
                else
 
1041
                        printf("%#x ", ch);
 
1042
        }
 
1043
        printf("\n");
 
1044
        printf("\troot_pgno: %lu\n", (u_long)argp->root_pgno);
 
1045
        printf("\tnrec: %lu\n", (u_long)argp->nrec);
 
1046
        printf("\trootent: ");
 
1047
        for (i = 0; i < argp->rootent.size; i++) {
 
1048
                ch = ((u_int8_t *)argp->rootent.data)[i];
 
1049
                if (isprint(ch) || ch == 0xa)
 
1050
                        putchar(ch);
 
1051
                else
 
1052
                        printf("%#x ", ch);
 
1053
        }
 
1054
        printf("\n");
 
1055
        printf("\trootlsn: [%lu][%lu]\n",
 
1056
            (u_long)argp->rootlsn.file, (u_long)argp->rootlsn.offset);
 
1057
        printf("\n");
 
1058
        __os_free(argp, 0);
 
1059
        return (0);
 
1060
}
 
1061
 
 
1062
int
 
1063
__bam_rsplit_read(dbenv, recbuf, argpp)
 
1064
        DB_ENV *dbenv;
 
1065
        void *recbuf;
 
1066
        __bam_rsplit_args **argpp;
 
1067
{
 
1068
        __bam_rsplit_args *argp;
 
1069
        u_int8_t *bp;
 
1070
        int ret;
 
1071
 
 
1072
        ret = __os_malloc(dbenv, sizeof(__bam_rsplit_args) +
 
1073
            sizeof(DB_TXN), NULL, &argp);
 
1074
        if (ret != 0)
 
1075
                return (ret);
 
1076
        argp->txnid = (DB_TXN *)&argp[1];
 
1077
        bp = recbuf;
 
1078
        memcpy(&argp->type, bp, sizeof(argp->type));
 
1079
        bp += sizeof(argp->type);
 
1080
        memcpy(&argp->txnid->txnid,  bp, sizeof(argp->txnid->txnid));
 
1081
        bp += sizeof(argp->txnid->txnid);
 
1082
        memcpy(&argp->prev_lsn, bp, sizeof(DB_LSN));
 
1083
        bp += sizeof(DB_LSN);
 
1084
        memcpy(&argp->fileid, bp, sizeof(argp->fileid));
 
1085
        bp += sizeof(argp->fileid);
 
1086
        memcpy(&argp->pgno, bp, sizeof(argp->pgno));
 
1087
        bp += sizeof(argp->pgno);
 
1088
        memset(&argp->pgdbt, 0, sizeof(argp->pgdbt));
 
1089
        memcpy(&argp->pgdbt.size, bp, sizeof(u_int32_t));
 
1090
        bp += sizeof(u_int32_t);
 
1091
        argp->pgdbt.data = bp;
 
1092
        bp += argp->pgdbt.size;
 
1093
        memcpy(&argp->root_pgno, bp, sizeof(argp->root_pgno));
 
1094
        bp += sizeof(argp->root_pgno);
 
1095
        memcpy(&argp->nrec, bp, sizeof(argp->nrec));
 
1096
        bp += sizeof(argp->nrec);
 
1097
        memset(&argp->rootent, 0, sizeof(argp->rootent));
 
1098
        memcpy(&argp->rootent.size, bp, sizeof(u_int32_t));
 
1099
        bp += sizeof(u_int32_t);
 
1100
        argp->rootent.data = bp;
 
1101
        bp += argp->rootent.size;
 
1102
        memcpy(&argp->rootlsn, bp,  sizeof(argp->rootlsn));
 
1103
        bp += sizeof(argp->rootlsn);
 
1104
        *argpp = argp;
 
1105
        return (0);
 
1106
}
 
1107
 
 
1108
int
 
1109
__bam_adj_log(dbenv, txnid, ret_lsnp, flags,
 
1110
        fileid, pgno, lsn, indx, indx_copy, is_insert)
 
1111
        DB_ENV *dbenv;
 
1112
        DB_TXN *txnid;
 
1113
        DB_LSN *ret_lsnp;
 
1114
        u_int32_t flags;
 
1115
        int32_t fileid;
 
1116
        db_pgno_t pgno;
 
1117
        DB_LSN * lsn;
 
1118
        u_int32_t indx;
 
1119
        u_int32_t indx_copy;
 
1120
        u_int32_t is_insert;
 
1121
{
 
1122
        DBT logrec;
 
1123
        DB_LSN *lsnp, null_lsn;
 
1124
        u_int32_t rectype, txn_num;
 
1125
        int ret;
 
1126
        u_int8_t *bp;
 
1127
 
 
1128
        rectype = DB_bam_adj;
 
1129
        if (txnid != NULL &&
 
1130
            TAILQ_FIRST(&txnid->kids) != NULL &&
 
1131
            (ret = __txn_activekids(dbenv, rectype, txnid)) != 0)
 
1132
                return (ret);
 
1133
        txn_num = txnid == NULL ? 0 : txnid->txnid;
 
1134
        if (txnid == NULL) {
 
1135
                ZERO_LSN(null_lsn);
 
1136
                lsnp = &null_lsn;
 
1137
        } else
 
1138
                lsnp = &txnid->last_lsn;
 
1139
        logrec.size = sizeof(rectype) + sizeof(txn_num) + sizeof(DB_LSN)
 
1140
            + sizeof(fileid)
 
1141
            + sizeof(pgno)
 
1142
            + sizeof(*lsn)
 
1143
            + sizeof(indx)
 
1144
            + sizeof(indx_copy)
 
1145
            + sizeof(is_insert);
 
1146
        if ((ret = __os_malloc(dbenv, logrec.size, NULL, &logrec.data)) != 0)
 
1147
                return (ret);
 
1148
 
 
1149
        bp = logrec.data;
 
1150
        memcpy(bp, &rectype, sizeof(rectype));
 
1151
        bp += sizeof(rectype);
 
1152
        memcpy(bp, &txn_num, sizeof(txn_num));
 
1153
        bp += sizeof(txn_num);
 
1154
        memcpy(bp, lsnp, sizeof(DB_LSN));
 
1155
        bp += sizeof(DB_LSN);
 
1156
        memcpy(bp, &fileid, sizeof(fileid));
 
1157
        bp += sizeof(fileid);
 
1158
        memcpy(bp, &pgno, sizeof(pgno));
 
1159
        bp += sizeof(pgno);
 
1160
        if (lsn != NULL)
 
1161
                memcpy(bp, lsn, sizeof(*lsn));
 
1162
        else
 
1163
                memset(bp, 0, sizeof(*lsn));
 
1164
        bp += sizeof(*lsn);
 
1165
        memcpy(bp, &indx, sizeof(indx));
 
1166
        bp += sizeof(indx);
 
1167
        memcpy(bp, &indx_copy, sizeof(indx_copy));
 
1168
        bp += sizeof(indx_copy);
 
1169
        memcpy(bp, &is_insert, sizeof(is_insert));
 
1170
        bp += sizeof(is_insert);
 
1171
        DB_ASSERT((u_int32_t)(bp - (u_int8_t *)logrec.data) == logrec.size);
 
1172
        ret = log_put(dbenv, ret_lsnp, (DBT *)&logrec, flags);
 
1173
        if (txnid != NULL)
 
1174
                txnid->last_lsn = *ret_lsnp;
 
1175
        __os_free(logrec.data, logrec.size);
 
1176
        return (ret);
 
1177
}
 
1178
 
 
1179
int
 
1180
__bam_adj_print(dbenv, dbtp, lsnp, notused2, notused3)
 
1181
        DB_ENV *dbenv;
 
1182
        DBT *dbtp;
 
1183
        DB_LSN *lsnp;
 
1184
        db_recops notused2;
 
1185
        void *notused3;
 
1186
{
 
1187
        __bam_adj_args *argp;
 
1188
        u_int32_t i;
 
1189
        u_int ch;
 
1190
        int ret;
 
1191
 
 
1192
        i = 0;
 
1193
        ch = 0;
 
1194
        notused2 = DB_TXN_ABORT;
 
1195
        notused3 = NULL;
 
1196
 
 
1197
        if ((ret = __bam_adj_read(dbenv, dbtp->data, &argp)) != 0)
 
1198
                return (ret);
 
1199
        printf("[%lu][%lu]bam_adj: rec: %lu txnid %lx prevlsn [%lu][%lu]\n",
 
1200
            (u_long)lsnp->file,
 
1201
            (u_long)lsnp->offset,
 
1202
            (u_long)argp->type,
 
1203
            (u_long)argp->txnid->txnid,
 
1204
            (u_long)argp->prev_lsn.file,
 
1205
            (u_long)argp->prev_lsn.offset);
 
1206
        printf("\tfileid: %ld\n", (long)argp->fileid);
 
1207
        printf("\tpgno: %lu\n", (u_long)argp->pgno);
 
1208
        printf("\tlsn: [%lu][%lu]\n",
 
1209
            (u_long)argp->lsn.file, (u_long)argp->lsn.offset);
 
1210
        printf("\tindx: %lu\n", (u_long)argp->indx);
 
1211
        printf("\tindx_copy: %lu\n", (u_long)argp->indx_copy);
 
1212
        printf("\tis_insert: %lu\n", (u_long)argp->is_insert);
 
1213
        printf("\n");
 
1214
        __os_free(argp, 0);
 
1215
        return (0);
 
1216
}
 
1217
 
 
1218
int
 
1219
__bam_adj_read(dbenv, recbuf, argpp)
 
1220
        DB_ENV *dbenv;
 
1221
        void *recbuf;
 
1222
        __bam_adj_args **argpp;
 
1223
{
 
1224
        __bam_adj_args *argp;
 
1225
        u_int8_t *bp;
 
1226
        int ret;
 
1227
 
 
1228
        ret = __os_malloc(dbenv, sizeof(__bam_adj_args) +
 
1229
            sizeof(DB_TXN), NULL, &argp);
 
1230
        if (ret != 0)
 
1231
                return (ret);
 
1232
        argp->txnid = (DB_TXN *)&argp[1];
 
1233
        bp = recbuf;
 
1234
        memcpy(&argp->type, bp, sizeof(argp->type));
 
1235
        bp += sizeof(argp->type);
 
1236
        memcpy(&argp->txnid->txnid,  bp, sizeof(argp->txnid->txnid));
 
1237
        bp += sizeof(argp->txnid->txnid);
 
1238
        memcpy(&argp->prev_lsn, bp, sizeof(DB_LSN));
 
1239
        bp += sizeof(DB_LSN);
 
1240
        memcpy(&argp->fileid, bp, sizeof(argp->fileid));
 
1241
        bp += sizeof(argp->fileid);
 
1242
        memcpy(&argp->pgno, bp, sizeof(argp->pgno));
 
1243
        bp += sizeof(argp->pgno);
 
1244
        memcpy(&argp->lsn, bp,  sizeof(argp->lsn));
 
1245
        bp += sizeof(argp->lsn);
 
1246
        memcpy(&argp->indx, bp, sizeof(argp->indx));
 
1247
        bp += sizeof(argp->indx);
 
1248
        memcpy(&argp->indx_copy, bp, sizeof(argp->indx_copy));
 
1249
        bp += sizeof(argp->indx_copy);
 
1250
        memcpy(&argp->is_insert, bp, sizeof(argp->is_insert));
 
1251
        bp += sizeof(argp->is_insert);
 
1252
        *argpp = argp;
 
1253
        return (0);
 
1254
}
 
1255
 
 
1256
int
 
1257
__bam_cadjust_log(dbenv, txnid, ret_lsnp, flags,
 
1258
        fileid, pgno, lsn, indx, adjust, opflags)
 
1259
        DB_ENV *dbenv;
 
1260
        DB_TXN *txnid;
 
1261
        DB_LSN *ret_lsnp;
 
1262
        u_int32_t flags;
 
1263
        int32_t fileid;
 
1264
        db_pgno_t pgno;
 
1265
        DB_LSN * lsn;
 
1266
        u_int32_t indx;
 
1267
        int32_t adjust;
 
1268
        u_int32_t opflags;
 
1269
{
 
1270
        DBT logrec;
 
1271
        DB_LSN *lsnp, null_lsn;
 
1272
        u_int32_t rectype, txn_num;
 
1273
        int ret;
 
1274
        u_int8_t *bp;
 
1275
 
 
1276
        rectype = DB_bam_cadjust;
 
1277
        if (txnid != NULL &&
 
1278
            TAILQ_FIRST(&txnid->kids) != NULL &&
 
1279
            (ret = __txn_activekids(dbenv, rectype, txnid)) != 0)
 
1280
                return (ret);
 
1281
        txn_num = txnid == NULL ? 0 : txnid->txnid;
 
1282
        if (txnid == NULL) {
 
1283
                ZERO_LSN(null_lsn);
 
1284
                lsnp = &null_lsn;
 
1285
        } else
 
1286
                lsnp = &txnid->last_lsn;
 
1287
        logrec.size = sizeof(rectype) + sizeof(txn_num) + sizeof(DB_LSN)
 
1288
            + sizeof(fileid)
 
1289
            + sizeof(pgno)
 
1290
            + sizeof(*lsn)
 
1291
            + sizeof(indx)
 
1292
            + sizeof(adjust)
 
1293
            + sizeof(opflags);
 
1294
        if ((ret = __os_malloc(dbenv, logrec.size, NULL, &logrec.data)) != 0)
 
1295
                return (ret);
 
1296
 
 
1297
        bp = logrec.data;
 
1298
        memcpy(bp, &rectype, sizeof(rectype));
 
1299
        bp += sizeof(rectype);
 
1300
        memcpy(bp, &txn_num, sizeof(txn_num));
 
1301
        bp += sizeof(txn_num);
 
1302
        memcpy(bp, lsnp, sizeof(DB_LSN));
 
1303
        bp += sizeof(DB_LSN);
 
1304
        memcpy(bp, &fileid, sizeof(fileid));
 
1305
        bp += sizeof(fileid);
 
1306
        memcpy(bp, &pgno, sizeof(pgno));
 
1307
        bp += sizeof(pgno);
 
1308
        if (lsn != NULL)
 
1309
                memcpy(bp, lsn, sizeof(*lsn));
 
1310
        else
 
1311
                memset(bp, 0, sizeof(*lsn));
 
1312
        bp += sizeof(*lsn);
 
1313
        memcpy(bp, &indx, sizeof(indx));
 
1314
        bp += sizeof(indx);
 
1315
        memcpy(bp, &adjust, sizeof(adjust));
 
1316
        bp += sizeof(adjust);
 
1317
        memcpy(bp, &opflags, sizeof(opflags));
 
1318
        bp += sizeof(opflags);
 
1319
        DB_ASSERT((u_int32_t)(bp - (u_int8_t *)logrec.data) == logrec.size);
 
1320
        ret = log_put(dbenv, ret_lsnp, (DBT *)&logrec, flags);
 
1321
        if (txnid != NULL)
 
1322
                txnid->last_lsn = *ret_lsnp;
 
1323
        __os_free(logrec.data, logrec.size);
 
1324
        return (ret);
 
1325
}
 
1326
 
 
1327
int
 
1328
__bam_cadjust_print(dbenv, dbtp, lsnp, notused2, notused3)
 
1329
        DB_ENV *dbenv;
 
1330
        DBT *dbtp;
 
1331
        DB_LSN *lsnp;
 
1332
        db_recops notused2;
 
1333
        void *notused3;
 
1334
{
 
1335
        __bam_cadjust_args *argp;
 
1336
        u_int32_t i;
 
1337
        u_int ch;
 
1338
        int ret;
 
1339
 
 
1340
        i = 0;
 
1341
        ch = 0;
 
1342
        notused2 = DB_TXN_ABORT;
 
1343
        notused3 = NULL;
 
1344
 
 
1345
        if ((ret = __bam_cadjust_read(dbenv, dbtp->data, &argp)) != 0)
 
1346
                return (ret);
 
1347
        printf("[%lu][%lu]bam_cadjust: rec: %lu txnid %lx prevlsn [%lu][%lu]\n",
 
1348
            (u_long)lsnp->file,
 
1349
            (u_long)lsnp->offset,
 
1350
            (u_long)argp->type,
 
1351
            (u_long)argp->txnid->txnid,
 
1352
            (u_long)argp->prev_lsn.file,
 
1353
            (u_long)argp->prev_lsn.offset);
 
1354
        printf("\tfileid: %ld\n", (long)argp->fileid);
 
1355
        printf("\tpgno: %lu\n", (u_long)argp->pgno);
 
1356
        printf("\tlsn: [%lu][%lu]\n",
 
1357
            (u_long)argp->lsn.file, (u_long)argp->lsn.offset);
 
1358
        printf("\tindx: %lu\n", (u_long)argp->indx);
 
1359
        printf("\tadjust: %ld\n", (long)argp->adjust);
 
1360
        printf("\topflags: %lu\n", (u_long)argp->opflags);
 
1361
        printf("\n");
 
1362
        __os_free(argp, 0);
 
1363
        return (0);
 
1364
}
 
1365
 
 
1366
int
 
1367
__bam_cadjust_read(dbenv, recbuf, argpp)
 
1368
        DB_ENV *dbenv;
 
1369
        void *recbuf;
 
1370
        __bam_cadjust_args **argpp;
 
1371
{
 
1372
        __bam_cadjust_args *argp;
 
1373
        u_int8_t *bp;
 
1374
        int ret;
 
1375
 
 
1376
        ret = __os_malloc(dbenv, sizeof(__bam_cadjust_args) +
 
1377
            sizeof(DB_TXN), NULL, &argp);
 
1378
        if (ret != 0)
 
1379
                return (ret);
 
1380
        argp->txnid = (DB_TXN *)&argp[1];
 
1381
        bp = recbuf;
 
1382
        memcpy(&argp->type, bp, sizeof(argp->type));
 
1383
        bp += sizeof(argp->type);
 
1384
        memcpy(&argp->txnid->txnid,  bp, sizeof(argp->txnid->txnid));
 
1385
        bp += sizeof(argp->txnid->txnid);
 
1386
        memcpy(&argp->prev_lsn, bp, sizeof(DB_LSN));
 
1387
        bp += sizeof(DB_LSN);
 
1388
        memcpy(&argp->fileid, bp, sizeof(argp->fileid));
 
1389
        bp += sizeof(argp->fileid);
 
1390
        memcpy(&argp->pgno, bp, sizeof(argp->pgno));
 
1391
        bp += sizeof(argp->pgno);
 
1392
        memcpy(&argp->lsn, bp,  sizeof(argp->lsn));
 
1393
        bp += sizeof(argp->lsn);
 
1394
        memcpy(&argp->indx, bp, sizeof(argp->indx));
 
1395
        bp += sizeof(argp->indx);
 
1396
        memcpy(&argp->adjust, bp, sizeof(argp->adjust));
 
1397
        bp += sizeof(argp->adjust);
 
1398
        memcpy(&argp->opflags, bp, sizeof(argp->opflags));
 
1399
        bp += sizeof(argp->opflags);
 
1400
        *argpp = argp;
 
1401
        return (0);
 
1402
}
 
1403
 
 
1404
int
 
1405
__bam_cdel_log(dbenv, txnid, ret_lsnp, flags,
 
1406
        fileid, pgno, lsn, indx)
 
1407
        DB_ENV *dbenv;
 
1408
        DB_TXN *txnid;
 
1409
        DB_LSN *ret_lsnp;
 
1410
        u_int32_t flags;
 
1411
        int32_t fileid;
 
1412
        db_pgno_t pgno;
 
1413
        DB_LSN * lsn;
 
1414
        u_int32_t indx;
 
1415
{
 
1416
        DBT logrec;
 
1417
        DB_LSN *lsnp, null_lsn;
 
1418
        u_int32_t rectype, txn_num;
 
1419
        int ret;
 
1420
        u_int8_t *bp;
 
1421
 
 
1422
        rectype = DB_bam_cdel;
 
1423
        if (txnid != NULL &&
 
1424
            TAILQ_FIRST(&txnid->kids) != NULL &&
 
1425
            (ret = __txn_activekids(dbenv, rectype, txnid)) != 0)
 
1426
                return (ret);
 
1427
        txn_num = txnid == NULL ? 0 : txnid->txnid;
 
1428
        if (txnid == NULL) {
 
1429
                ZERO_LSN(null_lsn);
 
1430
                lsnp = &null_lsn;
 
1431
        } else
 
1432
                lsnp = &txnid->last_lsn;
 
1433
        logrec.size = sizeof(rectype) + sizeof(txn_num) + sizeof(DB_LSN)
 
1434
            + sizeof(fileid)
 
1435
            + sizeof(pgno)
 
1436
            + sizeof(*lsn)
 
1437
            + sizeof(indx);
 
1438
        if ((ret = __os_malloc(dbenv, logrec.size, NULL, &logrec.data)) != 0)
 
1439
                return (ret);
 
1440
 
 
1441
        bp = logrec.data;
 
1442
        memcpy(bp, &rectype, sizeof(rectype));
 
1443
        bp += sizeof(rectype);
 
1444
        memcpy(bp, &txn_num, sizeof(txn_num));
 
1445
        bp += sizeof(txn_num);
 
1446
        memcpy(bp, lsnp, sizeof(DB_LSN));
 
1447
        bp += sizeof(DB_LSN);
 
1448
        memcpy(bp, &fileid, sizeof(fileid));
 
1449
        bp += sizeof(fileid);
 
1450
        memcpy(bp, &pgno, sizeof(pgno));
 
1451
        bp += sizeof(pgno);
 
1452
        if (lsn != NULL)
 
1453
                memcpy(bp, lsn, sizeof(*lsn));
 
1454
        else
 
1455
                memset(bp, 0, sizeof(*lsn));
 
1456
        bp += sizeof(*lsn);
 
1457
        memcpy(bp, &indx, sizeof(indx));
 
1458
        bp += sizeof(indx);
 
1459
        DB_ASSERT((u_int32_t)(bp - (u_int8_t *)logrec.data) == logrec.size);
 
1460
        ret = log_put(dbenv, ret_lsnp, (DBT *)&logrec, flags);
 
1461
        if (txnid != NULL)
 
1462
                txnid->last_lsn = *ret_lsnp;
 
1463
        __os_free(logrec.data, logrec.size);
 
1464
        return (ret);
 
1465
}
 
1466
 
 
1467
int
 
1468
__bam_cdel_print(dbenv, dbtp, lsnp, notused2, notused3)
 
1469
        DB_ENV *dbenv;
 
1470
        DBT *dbtp;
 
1471
        DB_LSN *lsnp;
 
1472
        db_recops notused2;
 
1473
        void *notused3;
 
1474
{
 
1475
        __bam_cdel_args *argp;
 
1476
        u_int32_t i;
 
1477
        u_int ch;
 
1478
        int ret;
 
1479
 
 
1480
        i = 0;
 
1481
        ch = 0;
 
1482
        notused2 = DB_TXN_ABORT;
 
1483
        notused3 = NULL;
 
1484
 
 
1485
        if ((ret = __bam_cdel_read(dbenv, dbtp->data, &argp)) != 0)
 
1486
                return (ret);
 
1487
        printf("[%lu][%lu]bam_cdel: rec: %lu txnid %lx prevlsn [%lu][%lu]\n",
 
1488
            (u_long)lsnp->file,
 
1489
            (u_long)lsnp->offset,
 
1490
            (u_long)argp->type,
 
1491
            (u_long)argp->txnid->txnid,
 
1492
            (u_long)argp->prev_lsn.file,
 
1493
            (u_long)argp->prev_lsn.offset);
 
1494
        printf("\tfileid: %ld\n", (long)argp->fileid);
 
1495
        printf("\tpgno: %lu\n", (u_long)argp->pgno);
 
1496
        printf("\tlsn: [%lu][%lu]\n",
 
1497
            (u_long)argp->lsn.file, (u_long)argp->lsn.offset);
 
1498
        printf("\tindx: %lu\n", (u_long)argp->indx);
 
1499
        printf("\n");
 
1500
        __os_free(argp, 0);
 
1501
        return (0);
 
1502
}
 
1503
 
 
1504
int
 
1505
__bam_cdel_read(dbenv, recbuf, argpp)
 
1506
        DB_ENV *dbenv;
 
1507
        void *recbuf;
 
1508
        __bam_cdel_args **argpp;
 
1509
{
 
1510
        __bam_cdel_args *argp;
 
1511
        u_int8_t *bp;
 
1512
        int ret;
 
1513
 
 
1514
        ret = __os_malloc(dbenv, sizeof(__bam_cdel_args) +
 
1515
            sizeof(DB_TXN), NULL, &argp);
 
1516
        if (ret != 0)
 
1517
                return (ret);
 
1518
        argp->txnid = (DB_TXN *)&argp[1];
 
1519
        bp = recbuf;
 
1520
        memcpy(&argp->type, bp, sizeof(argp->type));
 
1521
        bp += sizeof(argp->type);
 
1522
        memcpy(&argp->txnid->txnid,  bp, sizeof(argp->txnid->txnid));
 
1523
        bp += sizeof(argp->txnid->txnid);
 
1524
        memcpy(&argp->prev_lsn, bp, sizeof(DB_LSN));
 
1525
        bp += sizeof(DB_LSN);
 
1526
        memcpy(&argp->fileid, bp, sizeof(argp->fileid));
 
1527
        bp += sizeof(argp->fileid);
 
1528
        memcpy(&argp->pgno, bp, sizeof(argp->pgno));
 
1529
        bp += sizeof(argp->pgno);
 
1530
        memcpy(&argp->lsn, bp,  sizeof(argp->lsn));
 
1531
        bp += sizeof(argp->lsn);
 
1532
        memcpy(&argp->indx, bp, sizeof(argp->indx));
 
1533
        bp += sizeof(argp->indx);
 
1534
        *argpp = argp;
 
1535
        return (0);
 
1536
}
 
1537
 
 
1538
int
 
1539
__bam_repl_log(dbenv, txnid, ret_lsnp, flags,
 
1540
        fileid, pgno, lsn, indx, isdeleted, orig,
 
1541
        repl, prefix, suffix)
 
1542
        DB_ENV *dbenv;
 
1543
        DB_TXN *txnid;
 
1544
        DB_LSN *ret_lsnp;
 
1545
        u_int32_t flags;
 
1546
        int32_t fileid;
 
1547
        db_pgno_t pgno;
 
1548
        DB_LSN * lsn;
 
1549
        u_int32_t indx;
 
1550
        u_int32_t isdeleted;
 
1551
        const DBT *orig;
 
1552
        const DBT *repl;
 
1553
        u_int32_t prefix;
 
1554
        u_int32_t suffix;
 
1555
{
 
1556
        DBT logrec;
 
1557
        DB_LSN *lsnp, null_lsn;
 
1558
        u_int32_t zero;
 
1559
        u_int32_t rectype, txn_num;
 
1560
        int ret;
 
1561
        u_int8_t *bp;
 
1562
 
 
1563
        rectype = DB_bam_repl;
 
1564
        if (txnid != NULL &&
 
1565
            TAILQ_FIRST(&txnid->kids) != NULL &&
 
1566
            (ret = __txn_activekids(dbenv, rectype, txnid)) != 0)
 
1567
                return (ret);
 
1568
        txn_num = txnid == NULL ? 0 : txnid->txnid;
 
1569
        if (txnid == NULL) {
 
1570
                ZERO_LSN(null_lsn);
 
1571
                lsnp = &null_lsn;
 
1572
        } else
 
1573
                lsnp = &txnid->last_lsn;
 
1574
        logrec.size = sizeof(rectype) + sizeof(txn_num) + sizeof(DB_LSN)
 
1575
            + sizeof(fileid)
 
1576
            + sizeof(pgno)
 
1577
            + sizeof(*lsn)
 
1578
            + sizeof(indx)
 
1579
            + sizeof(isdeleted)
 
1580
            + sizeof(u_int32_t) + (orig == NULL ? 0 : orig->size)
 
1581
            + sizeof(u_int32_t) + (repl == NULL ? 0 : repl->size)
 
1582
            + sizeof(prefix)
 
1583
            + sizeof(suffix);
 
1584
        if ((ret = __os_malloc(dbenv, logrec.size, NULL, &logrec.data)) != 0)
 
1585
                return (ret);
 
1586
 
 
1587
        bp = logrec.data;
 
1588
        memcpy(bp, &rectype, sizeof(rectype));
 
1589
        bp += sizeof(rectype);
 
1590
        memcpy(bp, &txn_num, sizeof(txn_num));
 
1591
        bp += sizeof(txn_num);
 
1592
        memcpy(bp, lsnp, sizeof(DB_LSN));
 
1593
        bp += sizeof(DB_LSN);
 
1594
        memcpy(bp, &fileid, sizeof(fileid));
 
1595
        bp += sizeof(fileid);
 
1596
        memcpy(bp, &pgno, sizeof(pgno));
 
1597
        bp += sizeof(pgno);
 
1598
        if (lsn != NULL)
 
1599
                memcpy(bp, lsn, sizeof(*lsn));
 
1600
        else
 
1601
                memset(bp, 0, sizeof(*lsn));
 
1602
        bp += sizeof(*lsn);
 
1603
        memcpy(bp, &indx, sizeof(indx));
 
1604
        bp += sizeof(indx);
 
1605
        memcpy(bp, &isdeleted, sizeof(isdeleted));
 
1606
        bp += sizeof(isdeleted);
 
1607
        if (orig == NULL) {
 
1608
                zero = 0;
 
1609
                memcpy(bp, &zero, sizeof(u_int32_t));
 
1610
                bp += sizeof(u_int32_t);
 
1611
        } else {
 
1612
                memcpy(bp, &orig->size, sizeof(orig->size));
 
1613
                bp += sizeof(orig->size);
 
1614
                memcpy(bp, orig->data, orig->size);
 
1615
                bp += orig->size;
 
1616
        }
 
1617
        if (repl == NULL) {
 
1618
                zero = 0;
 
1619
                memcpy(bp, &zero, sizeof(u_int32_t));
 
1620
                bp += sizeof(u_int32_t);
 
1621
        } else {
 
1622
                memcpy(bp, &repl->size, sizeof(repl->size));
 
1623
                bp += sizeof(repl->size);
 
1624
                memcpy(bp, repl->data, repl->size);
 
1625
                bp += repl->size;
 
1626
        }
 
1627
        memcpy(bp, &prefix, sizeof(prefix));
 
1628
        bp += sizeof(prefix);
 
1629
        memcpy(bp, &suffix, sizeof(suffix));
 
1630
        bp += sizeof(suffix);
 
1631
        DB_ASSERT((u_int32_t)(bp - (u_int8_t *)logrec.data) == logrec.size);
 
1632
        ret = log_put(dbenv, ret_lsnp, (DBT *)&logrec, flags);
 
1633
        if (txnid != NULL)
 
1634
                txnid->last_lsn = *ret_lsnp;
 
1635
        __os_free(logrec.data, logrec.size);
 
1636
        return (ret);
 
1637
}
 
1638
 
 
1639
int
 
1640
__bam_repl_print(dbenv, dbtp, lsnp, notused2, notused3)
 
1641
        DB_ENV *dbenv;
 
1642
        DBT *dbtp;
 
1643
        DB_LSN *lsnp;
 
1644
        db_recops notused2;
 
1645
        void *notused3;
 
1646
{
 
1647
        __bam_repl_args *argp;
 
1648
        u_int32_t i;
 
1649
        u_int ch;
 
1650
        int ret;
 
1651
 
 
1652
        i = 0;
 
1653
        ch = 0;
 
1654
        notused2 = DB_TXN_ABORT;
 
1655
        notused3 = NULL;
 
1656
 
 
1657
        if ((ret = __bam_repl_read(dbenv, dbtp->data, &argp)) != 0)
 
1658
                return (ret);
 
1659
        printf("[%lu][%lu]bam_repl: rec: %lu txnid %lx prevlsn [%lu][%lu]\n",
 
1660
            (u_long)lsnp->file,
 
1661
            (u_long)lsnp->offset,
 
1662
            (u_long)argp->type,
 
1663
            (u_long)argp->txnid->txnid,
 
1664
            (u_long)argp->prev_lsn.file,
 
1665
            (u_long)argp->prev_lsn.offset);
 
1666
        printf("\tfileid: %ld\n", (long)argp->fileid);
 
1667
        printf("\tpgno: %lu\n", (u_long)argp->pgno);
 
1668
        printf("\tlsn: [%lu][%lu]\n",
 
1669
            (u_long)argp->lsn.file, (u_long)argp->lsn.offset);
 
1670
        printf("\tindx: %lu\n", (u_long)argp->indx);
 
1671
        printf("\tisdeleted: %lu\n", (u_long)argp->isdeleted);
 
1672
        printf("\torig: ");
 
1673
        for (i = 0; i < argp->orig.size; i++) {
 
1674
                ch = ((u_int8_t *)argp->orig.data)[i];
 
1675
                if (isprint(ch) || ch == 0xa)
 
1676
                        putchar(ch);
 
1677
                else
 
1678
                        printf("%#x ", ch);
 
1679
        }
 
1680
        printf("\n");
 
1681
        printf("\trepl: ");
 
1682
        for (i = 0; i < argp->repl.size; i++) {
 
1683
                ch = ((u_int8_t *)argp->repl.data)[i];
 
1684
                if (isprint(ch) || ch == 0xa)
 
1685
                        putchar(ch);
 
1686
                else
 
1687
                        printf("%#x ", ch);
 
1688
        }
 
1689
        printf("\n");
 
1690
        printf("\tprefix: %lu\n", (u_long)argp->prefix);
 
1691
        printf("\tsuffix: %lu\n", (u_long)argp->suffix);
 
1692
        printf("\n");
 
1693
        __os_free(argp, 0);
 
1694
        return (0);
 
1695
}
 
1696
 
 
1697
int
 
1698
__bam_repl_read(dbenv, recbuf, argpp)
 
1699
        DB_ENV *dbenv;
 
1700
        void *recbuf;
 
1701
        __bam_repl_args **argpp;
 
1702
{
 
1703
        __bam_repl_args *argp;
 
1704
        u_int8_t *bp;
 
1705
        int ret;
 
1706
 
 
1707
        ret = __os_malloc(dbenv, sizeof(__bam_repl_args) +
 
1708
            sizeof(DB_TXN), NULL, &argp);
 
1709
        if (ret != 0)
 
1710
                return (ret);
 
1711
        argp->txnid = (DB_TXN *)&argp[1];
 
1712
        bp = recbuf;
 
1713
        memcpy(&argp->type, bp, sizeof(argp->type));
 
1714
        bp += sizeof(argp->type);
 
1715
        memcpy(&argp->txnid->txnid,  bp, sizeof(argp->txnid->txnid));
 
1716
        bp += sizeof(argp->txnid->txnid);
 
1717
        memcpy(&argp->prev_lsn, bp, sizeof(DB_LSN));
 
1718
        bp += sizeof(DB_LSN);
 
1719
        memcpy(&argp->fileid, bp, sizeof(argp->fileid));
 
1720
        bp += sizeof(argp->fileid);
 
1721
        memcpy(&argp->pgno, bp, sizeof(argp->pgno));
 
1722
        bp += sizeof(argp->pgno);
 
1723
        memcpy(&argp->lsn, bp,  sizeof(argp->lsn));
 
1724
        bp += sizeof(argp->lsn);
 
1725
        memcpy(&argp->indx, bp, sizeof(argp->indx));
 
1726
        bp += sizeof(argp->indx);
 
1727
        memcpy(&argp->isdeleted, bp, sizeof(argp->isdeleted));
 
1728
        bp += sizeof(argp->isdeleted);
 
1729
        memset(&argp->orig, 0, sizeof(argp->orig));
 
1730
        memcpy(&argp->orig.size, bp, sizeof(u_int32_t));
 
1731
        bp += sizeof(u_int32_t);
 
1732
        argp->orig.data = bp;
 
1733
        bp += argp->orig.size;
 
1734
        memset(&argp->repl, 0, sizeof(argp->repl));
 
1735
        memcpy(&argp->repl.size, bp, sizeof(u_int32_t));
 
1736
        bp += sizeof(u_int32_t);
 
1737
        argp->repl.data = bp;
 
1738
        bp += argp->repl.size;
 
1739
        memcpy(&argp->prefix, bp, sizeof(argp->prefix));
 
1740
        bp += sizeof(argp->prefix);
 
1741
        memcpy(&argp->suffix, bp, sizeof(argp->suffix));
 
1742
        bp += sizeof(argp->suffix);
 
1743
        *argpp = argp;
 
1744
        return (0);
 
1745
}
 
1746
 
 
1747
int
 
1748
__bam_root_log(dbenv, txnid, ret_lsnp, flags,
 
1749
        fileid, meta_pgno, root_pgno, meta_lsn)
 
1750
        DB_ENV *dbenv;
 
1751
        DB_TXN *txnid;
 
1752
        DB_LSN *ret_lsnp;
 
1753
        u_int32_t flags;
 
1754
        int32_t fileid;
 
1755
        db_pgno_t meta_pgno;
 
1756
        db_pgno_t root_pgno;
 
1757
        DB_LSN * meta_lsn;
 
1758
{
 
1759
        DBT logrec;
 
1760
        DB_LSN *lsnp, null_lsn;
 
1761
        u_int32_t rectype, txn_num;
 
1762
        int ret;
 
1763
        u_int8_t *bp;
 
1764
 
 
1765
        rectype = DB_bam_root;
 
1766
        if (txnid != NULL &&
 
1767
            TAILQ_FIRST(&txnid->kids) != NULL &&
 
1768
            (ret = __txn_activekids(dbenv, rectype, txnid)) != 0)
 
1769
                return (ret);
 
1770
        txn_num = txnid == NULL ? 0 : txnid->txnid;
 
1771
        if (txnid == NULL) {
 
1772
                ZERO_LSN(null_lsn);
 
1773
                lsnp = &null_lsn;
 
1774
        } else
 
1775
                lsnp = &txnid->last_lsn;
 
1776
        logrec.size = sizeof(rectype) + sizeof(txn_num) + sizeof(DB_LSN)
 
1777
            + sizeof(fileid)
 
1778
            + sizeof(meta_pgno)
 
1779
            + sizeof(root_pgno)
 
1780
            + sizeof(*meta_lsn);
 
1781
        if ((ret = __os_malloc(dbenv, logrec.size, NULL, &logrec.data)) != 0)
 
1782
                return (ret);
 
1783
 
 
1784
        bp = logrec.data;
 
1785
        memcpy(bp, &rectype, sizeof(rectype));
 
1786
        bp += sizeof(rectype);
 
1787
        memcpy(bp, &txn_num, sizeof(txn_num));
 
1788
        bp += sizeof(txn_num);
 
1789
        memcpy(bp, lsnp, sizeof(DB_LSN));
 
1790
        bp += sizeof(DB_LSN);
 
1791
        memcpy(bp, &fileid, sizeof(fileid));
 
1792
        bp += sizeof(fileid);
 
1793
        memcpy(bp, &meta_pgno, sizeof(meta_pgno));
 
1794
        bp += sizeof(meta_pgno);
 
1795
        memcpy(bp, &root_pgno, sizeof(root_pgno));
 
1796
        bp += sizeof(root_pgno);
 
1797
        if (meta_lsn != NULL)
 
1798
                memcpy(bp, meta_lsn, sizeof(*meta_lsn));
 
1799
        else
 
1800
                memset(bp, 0, sizeof(*meta_lsn));
 
1801
        bp += sizeof(*meta_lsn);
 
1802
        DB_ASSERT((u_int32_t)(bp - (u_int8_t *)logrec.data) == logrec.size);
 
1803
        ret = log_put(dbenv, ret_lsnp, (DBT *)&logrec, flags);
 
1804
        if (txnid != NULL)
 
1805
                txnid->last_lsn = *ret_lsnp;
 
1806
        __os_free(logrec.data, logrec.size);
 
1807
        return (ret);
 
1808
}
 
1809
 
 
1810
int
 
1811
__bam_root_print(dbenv, dbtp, lsnp, notused2, notused3)
 
1812
        DB_ENV *dbenv;
 
1813
        DBT *dbtp;
 
1814
        DB_LSN *lsnp;
 
1815
        db_recops notused2;
 
1816
        void *notused3;
 
1817
{
 
1818
        __bam_root_args *argp;
 
1819
        u_int32_t i;
 
1820
        u_int ch;
 
1821
        int ret;
 
1822
 
 
1823
        i = 0;
 
1824
        ch = 0;
 
1825
        notused2 = DB_TXN_ABORT;
 
1826
        notused3 = NULL;
 
1827
 
 
1828
        if ((ret = __bam_root_read(dbenv, dbtp->data, &argp)) != 0)
 
1829
                return (ret);
 
1830
        printf("[%lu][%lu]bam_root: rec: %lu txnid %lx prevlsn [%lu][%lu]\n",
 
1831
            (u_long)lsnp->file,
 
1832
            (u_long)lsnp->offset,
 
1833
            (u_long)argp->type,
 
1834
            (u_long)argp->txnid->txnid,
 
1835
            (u_long)argp->prev_lsn.file,
 
1836
            (u_long)argp->prev_lsn.offset);
 
1837
        printf("\tfileid: %ld\n", (long)argp->fileid);
 
1838
        printf("\tmeta_pgno: %lu\n", (u_long)argp->meta_pgno);
 
1839
        printf("\troot_pgno: %lu\n", (u_long)argp->root_pgno);
 
1840
        printf("\tmeta_lsn: [%lu][%lu]\n",
 
1841
            (u_long)argp->meta_lsn.file, (u_long)argp->meta_lsn.offset);
 
1842
        printf("\n");
 
1843
        __os_free(argp, 0);
 
1844
        return (0);
 
1845
}
 
1846
 
 
1847
int
 
1848
__bam_root_read(dbenv, recbuf, argpp)
 
1849
        DB_ENV *dbenv;
 
1850
        void *recbuf;
 
1851
        __bam_root_args **argpp;
 
1852
{
 
1853
        __bam_root_args *argp;
 
1854
        u_int8_t *bp;
 
1855
        int ret;
 
1856
 
 
1857
        ret = __os_malloc(dbenv, sizeof(__bam_root_args) +
 
1858
            sizeof(DB_TXN), NULL, &argp);
 
1859
        if (ret != 0)
 
1860
                return (ret);
 
1861
        argp->txnid = (DB_TXN *)&argp[1];
 
1862
        bp = recbuf;
 
1863
        memcpy(&argp->type, bp, sizeof(argp->type));
 
1864
        bp += sizeof(argp->type);
 
1865
        memcpy(&argp->txnid->txnid,  bp, sizeof(argp->txnid->txnid));
 
1866
        bp += sizeof(argp->txnid->txnid);
 
1867
        memcpy(&argp->prev_lsn, bp, sizeof(DB_LSN));
 
1868
        bp += sizeof(DB_LSN);
 
1869
        memcpy(&argp->fileid, bp, sizeof(argp->fileid));
 
1870
        bp += sizeof(argp->fileid);
 
1871
        memcpy(&argp->meta_pgno, bp, sizeof(argp->meta_pgno));
 
1872
        bp += sizeof(argp->meta_pgno);
 
1873
        memcpy(&argp->root_pgno, bp, sizeof(argp->root_pgno));
 
1874
        bp += sizeof(argp->root_pgno);
 
1875
        memcpy(&argp->meta_lsn, bp,  sizeof(argp->meta_lsn));
 
1876
        bp += sizeof(argp->meta_lsn);
 
1877
        *argpp = argp;
 
1878
        return (0);
 
1879
}
 
1880
 
 
1881
int
 
1882
__bam_curadj_log(dbenv, txnid, ret_lsnp, flags,
 
1883
        fileid, mode, from_pgno, to_pgno, left_pgno, first_indx,
 
1884
        from_indx, to_indx)
 
1885
        DB_ENV *dbenv;
 
1886
        DB_TXN *txnid;
 
1887
        DB_LSN *ret_lsnp;
 
1888
        u_int32_t flags;
 
1889
        int32_t fileid;
 
1890
        db_ca_mode mode;
 
1891
        db_pgno_t from_pgno;
 
1892
        db_pgno_t to_pgno;
 
1893
        db_pgno_t left_pgno;
 
1894
        u_int32_t first_indx;
 
1895
        u_int32_t from_indx;
 
1896
        u_int32_t to_indx;
 
1897
{
 
1898
        DBT logrec;
 
1899
        DB_LSN *lsnp, null_lsn;
 
1900
        u_int32_t rectype, txn_num;
 
1901
        int ret;
 
1902
        u_int8_t *bp;
 
1903
 
 
1904
        rectype = DB_bam_curadj;
 
1905
        if (txnid != NULL &&
 
1906
            TAILQ_FIRST(&txnid->kids) != NULL &&
 
1907
            (ret = __txn_activekids(dbenv, rectype, txnid)) != 0)
 
1908
                return (ret);
 
1909
        txn_num = txnid == NULL ? 0 : txnid->txnid;
 
1910
        if (txnid == NULL) {
 
1911
                ZERO_LSN(null_lsn);
 
1912
                lsnp = &null_lsn;
 
1913
        } else
 
1914
                lsnp = &txnid->last_lsn;
 
1915
        logrec.size = sizeof(rectype) + sizeof(txn_num) + sizeof(DB_LSN)
 
1916
            + sizeof(fileid)
 
1917
            + sizeof(mode)
 
1918
            + sizeof(from_pgno)
 
1919
            + sizeof(to_pgno)
 
1920
            + sizeof(left_pgno)
 
1921
            + sizeof(first_indx)
 
1922
            + sizeof(from_indx)
 
1923
            + sizeof(to_indx);
 
1924
        if ((ret = __os_malloc(dbenv, logrec.size, NULL, &logrec.data)) != 0)
 
1925
                return (ret);
 
1926
 
 
1927
        bp = logrec.data;
 
1928
        memcpy(bp, &rectype, sizeof(rectype));
 
1929
        bp += sizeof(rectype);
 
1930
        memcpy(bp, &txn_num, sizeof(txn_num));
 
1931
        bp += sizeof(txn_num);
 
1932
        memcpy(bp, lsnp, sizeof(DB_LSN));
 
1933
        bp += sizeof(DB_LSN);
 
1934
        memcpy(bp, &fileid, sizeof(fileid));
 
1935
        bp += sizeof(fileid);
 
1936
        memcpy(bp, &mode, sizeof(mode));
 
1937
        bp += sizeof(mode);
 
1938
        memcpy(bp, &from_pgno, sizeof(from_pgno));
 
1939
        bp += sizeof(from_pgno);
 
1940
        memcpy(bp, &to_pgno, sizeof(to_pgno));
 
1941
        bp += sizeof(to_pgno);
 
1942
        memcpy(bp, &left_pgno, sizeof(left_pgno));
 
1943
        bp += sizeof(left_pgno);
 
1944
        memcpy(bp, &first_indx, sizeof(first_indx));
 
1945
        bp += sizeof(first_indx);
 
1946
        memcpy(bp, &from_indx, sizeof(from_indx));
 
1947
        bp += sizeof(from_indx);
 
1948
        memcpy(bp, &to_indx, sizeof(to_indx));
 
1949
        bp += sizeof(to_indx);
 
1950
        DB_ASSERT((u_int32_t)(bp - (u_int8_t *)logrec.data) == logrec.size);
 
1951
        ret = log_put(dbenv, ret_lsnp, (DBT *)&logrec, flags);
 
1952
        if (txnid != NULL)
 
1953
                txnid->last_lsn = *ret_lsnp;
 
1954
        __os_free(logrec.data, logrec.size);
 
1955
        return (ret);
 
1956
}
 
1957
 
 
1958
int
 
1959
__bam_curadj_print(dbenv, dbtp, lsnp, notused2, notused3)
 
1960
        DB_ENV *dbenv;
 
1961
        DBT *dbtp;
 
1962
        DB_LSN *lsnp;
 
1963
        db_recops notused2;
 
1964
        void *notused3;
 
1965
{
 
1966
        __bam_curadj_args *argp;
 
1967
        u_int32_t i;
 
1968
        u_int ch;
 
1969
        int ret;
 
1970
 
 
1971
        i = 0;
 
1972
        ch = 0;
 
1973
        notused2 = DB_TXN_ABORT;
 
1974
        notused3 = NULL;
 
1975
 
 
1976
        if ((ret = __bam_curadj_read(dbenv, dbtp->data, &argp)) != 0)
 
1977
                return (ret);
 
1978
        printf("[%lu][%lu]bam_curadj: rec: %lu txnid %lx prevlsn [%lu][%lu]\n",
 
1979
            (u_long)lsnp->file,
 
1980
            (u_long)lsnp->offset,
 
1981
            (u_long)argp->type,
 
1982
            (u_long)argp->txnid->txnid,
 
1983
            (u_long)argp->prev_lsn.file,
 
1984
            (u_long)argp->prev_lsn.offset);
 
1985
        printf("\tfileid: %ld\n", (long)argp->fileid);
 
1986
        printf("\tmode: %ld\n", (long)argp->mode);
 
1987
        printf("\tfrom_pgno: %lu\n", (u_long)argp->from_pgno);
 
1988
        printf("\tto_pgno: %lu\n", (u_long)argp->to_pgno);
 
1989
        printf("\tleft_pgno: %lu\n", (u_long)argp->left_pgno);
 
1990
        printf("\tfirst_indx: %lu\n", (u_long)argp->first_indx);
 
1991
        printf("\tfrom_indx: %lu\n", (u_long)argp->from_indx);
 
1992
        printf("\tto_indx: %lu\n", (u_long)argp->to_indx);
 
1993
        printf("\n");
 
1994
        __os_free(argp, 0);
 
1995
        return (0);
 
1996
}
 
1997
 
 
1998
int
 
1999
__bam_curadj_read(dbenv, recbuf, argpp)
 
2000
        DB_ENV *dbenv;
 
2001
        void *recbuf;
 
2002
        __bam_curadj_args **argpp;
 
2003
{
 
2004
        __bam_curadj_args *argp;
 
2005
        u_int8_t *bp;
 
2006
        int ret;
 
2007
 
 
2008
        ret = __os_malloc(dbenv, sizeof(__bam_curadj_args) +
 
2009
            sizeof(DB_TXN), NULL, &argp);
 
2010
        if (ret != 0)
 
2011
                return (ret);
 
2012
        argp->txnid = (DB_TXN *)&argp[1];
 
2013
        bp = recbuf;
 
2014
        memcpy(&argp->type, bp, sizeof(argp->type));
 
2015
        bp += sizeof(argp->type);
 
2016
        memcpy(&argp->txnid->txnid,  bp, sizeof(argp->txnid->txnid));
 
2017
        bp += sizeof(argp->txnid->txnid);
 
2018
        memcpy(&argp->prev_lsn, bp, sizeof(DB_LSN));
 
2019
        bp += sizeof(DB_LSN);
 
2020
        memcpy(&argp->fileid, bp, sizeof(argp->fileid));
 
2021
        bp += sizeof(argp->fileid);
 
2022
        memcpy(&argp->mode, bp, sizeof(argp->mode));
 
2023
        bp += sizeof(argp->mode);
 
2024
        memcpy(&argp->from_pgno, bp, sizeof(argp->from_pgno));
 
2025
        bp += sizeof(argp->from_pgno);
 
2026
        memcpy(&argp->to_pgno, bp, sizeof(argp->to_pgno));
 
2027
        bp += sizeof(argp->to_pgno);
 
2028
        memcpy(&argp->left_pgno, bp, sizeof(argp->left_pgno));
 
2029
        bp += sizeof(argp->left_pgno);
 
2030
        memcpy(&argp->first_indx, bp, sizeof(argp->first_indx));
 
2031
        bp += sizeof(argp->first_indx);
 
2032
        memcpy(&argp->from_indx, bp, sizeof(argp->from_indx));
 
2033
        bp += sizeof(argp->from_indx);
 
2034
        memcpy(&argp->to_indx, bp, sizeof(argp->to_indx));
 
2035
        bp += sizeof(argp->to_indx);
 
2036
        *argpp = argp;
 
2037
        return (0);
 
2038
}
 
2039
 
 
2040
int
 
2041
__bam_rcuradj_log(dbenv, txnid, ret_lsnp, flags,
 
2042
        fileid, mode, root, recno, order)
 
2043
        DB_ENV *dbenv;
 
2044
        DB_TXN *txnid;
 
2045
        DB_LSN *ret_lsnp;
 
2046
        u_int32_t flags;
 
2047
        int32_t fileid;
 
2048
        ca_recno_arg mode;
 
2049
        db_pgno_t root;
 
2050
        db_recno_t recno;
 
2051
        u_int32_t order;
 
2052
{
 
2053
        DBT logrec;
 
2054
        DB_LSN *lsnp, null_lsn;
 
2055
        u_int32_t rectype, txn_num;
 
2056
        int ret;
 
2057
        u_int8_t *bp;
 
2058
 
 
2059
        rectype = DB_bam_rcuradj;
 
2060
        if (txnid != NULL &&
 
2061
            TAILQ_FIRST(&txnid->kids) != NULL &&
 
2062
            (ret = __txn_activekids(dbenv, rectype, txnid)) != 0)
 
2063
                return (ret);
 
2064
        txn_num = txnid == NULL ? 0 : txnid->txnid;
 
2065
        if (txnid == NULL) {
 
2066
                ZERO_LSN(null_lsn);
 
2067
                lsnp = &null_lsn;
 
2068
        } else
 
2069
                lsnp = &txnid->last_lsn;
 
2070
        logrec.size = sizeof(rectype) + sizeof(txn_num) + sizeof(DB_LSN)
 
2071
            + sizeof(fileid)
 
2072
            + sizeof(mode)
 
2073
            + sizeof(root)
 
2074
            + sizeof(recno)
 
2075
            + sizeof(order);
 
2076
        if ((ret = __os_malloc(dbenv, logrec.size, NULL, &logrec.data)) != 0)
 
2077
                return (ret);
 
2078
 
 
2079
        bp = logrec.data;
 
2080
        memcpy(bp, &rectype, sizeof(rectype));
 
2081
        bp += sizeof(rectype);
 
2082
        memcpy(bp, &txn_num, sizeof(txn_num));
 
2083
        bp += sizeof(txn_num);
 
2084
        memcpy(bp, lsnp, sizeof(DB_LSN));
 
2085
        bp += sizeof(DB_LSN);
 
2086
        memcpy(bp, &fileid, sizeof(fileid));
 
2087
        bp += sizeof(fileid);
 
2088
        memcpy(bp, &mode, sizeof(mode));
 
2089
        bp += sizeof(mode);
 
2090
        memcpy(bp, &root, sizeof(root));
 
2091
        bp += sizeof(root);
 
2092
        memcpy(bp, &recno, sizeof(recno));
 
2093
        bp += sizeof(recno);
 
2094
        memcpy(bp, &order, sizeof(order));
 
2095
        bp += sizeof(order);
 
2096
        DB_ASSERT((u_int32_t)(bp - (u_int8_t *)logrec.data) == logrec.size);
 
2097
        ret = log_put(dbenv, ret_lsnp, (DBT *)&logrec, flags);
 
2098
        if (txnid != NULL)
 
2099
                txnid->last_lsn = *ret_lsnp;
 
2100
        __os_free(logrec.data, logrec.size);
 
2101
        return (ret);
 
2102
}
 
2103
 
 
2104
int
 
2105
__bam_rcuradj_print(dbenv, dbtp, lsnp, notused2, notused3)
 
2106
        DB_ENV *dbenv;
 
2107
        DBT *dbtp;
 
2108
        DB_LSN *lsnp;
 
2109
        db_recops notused2;
 
2110
        void *notused3;
 
2111
{
 
2112
        __bam_rcuradj_args *argp;
 
2113
        u_int32_t i;
 
2114
        u_int ch;
 
2115
        int ret;
 
2116
 
 
2117
        i = 0;
 
2118
        ch = 0;
 
2119
        notused2 = DB_TXN_ABORT;
 
2120
        notused3 = NULL;
 
2121
 
 
2122
        if ((ret = __bam_rcuradj_read(dbenv, dbtp->data, &argp)) != 0)
 
2123
                return (ret);
 
2124
        printf("[%lu][%lu]bam_rcuradj: rec: %lu txnid %lx prevlsn [%lu][%lu]\n",
 
2125
            (u_long)lsnp->file,
 
2126
            (u_long)lsnp->offset,
 
2127
            (u_long)argp->type,
 
2128
            (u_long)argp->txnid->txnid,
 
2129
            (u_long)argp->prev_lsn.file,
 
2130
            (u_long)argp->prev_lsn.offset);
 
2131
        printf("\tfileid: %ld\n", (long)argp->fileid);
 
2132
        printf("\tmode: %ld\n", (long)argp->mode);
 
2133
        printf("\troot: %ld\n", (long)argp->root);
 
2134
        printf("\trecno: %ld\n", (long)argp->recno);
 
2135
        printf("\torder: %ld\n", (long)argp->order);
 
2136
        printf("\n");
 
2137
        __os_free(argp, 0);
 
2138
        return (0);
 
2139
}
 
2140
 
 
2141
int
 
2142
__bam_rcuradj_read(dbenv, recbuf, argpp)
 
2143
        DB_ENV *dbenv;
 
2144
        void *recbuf;
 
2145
        __bam_rcuradj_args **argpp;
 
2146
{
 
2147
        __bam_rcuradj_args *argp;
 
2148
        u_int8_t *bp;
 
2149
        int ret;
 
2150
 
 
2151
        ret = __os_malloc(dbenv, sizeof(__bam_rcuradj_args) +
 
2152
            sizeof(DB_TXN), NULL, &argp);
 
2153
        if (ret != 0)
 
2154
                return (ret);
 
2155
        argp->txnid = (DB_TXN *)&argp[1];
 
2156
        bp = recbuf;
 
2157
        memcpy(&argp->type, bp, sizeof(argp->type));
 
2158
        bp += sizeof(argp->type);
 
2159
        memcpy(&argp->txnid->txnid,  bp, sizeof(argp->txnid->txnid));
 
2160
        bp += sizeof(argp->txnid->txnid);
 
2161
        memcpy(&argp->prev_lsn, bp, sizeof(DB_LSN));
 
2162
        bp += sizeof(DB_LSN);
 
2163
        memcpy(&argp->fileid, bp, sizeof(argp->fileid));
 
2164
        bp += sizeof(argp->fileid);
 
2165
        memcpy(&argp->mode, bp, sizeof(argp->mode));
 
2166
        bp += sizeof(argp->mode);
 
2167
        memcpy(&argp->root, bp, sizeof(argp->root));
 
2168
        bp += sizeof(argp->root);
 
2169
        memcpy(&argp->recno, bp, sizeof(argp->recno));
 
2170
        bp += sizeof(argp->recno);
 
2171
        memcpy(&argp->order, bp, sizeof(argp->order));
 
2172
        bp += sizeof(argp->order);
 
2173
        *argpp = argp;
 
2174
        return (0);
 
2175
}
 
2176
 
 
2177
int
 
2178
__bam_init_print(dbenv)
 
2179
        DB_ENV *dbenv;
 
2180
{
 
2181
        int ret;
 
2182
 
 
2183
        if ((ret = __db_add_recovery(dbenv,
 
2184
            __bam_pg_alloc_print, DB_bam_pg_alloc)) != 0)
 
2185
                return (ret);
 
2186
        if ((ret = __db_add_recovery(dbenv,
 
2187
            __bam_pg_alloc1_print, DB_bam_pg_alloc1)) != 0)
 
2188
                return (ret);
 
2189
        if ((ret = __db_add_recovery(dbenv,
 
2190
            __bam_pg_free_print, DB_bam_pg_free)) != 0)
 
2191
                return (ret);
 
2192
        if ((ret = __db_add_recovery(dbenv,
 
2193
            __bam_pg_free1_print, DB_bam_pg_free1)) != 0)
 
2194
                return (ret);
 
2195
        if ((ret = __db_add_recovery(dbenv,
 
2196
            __bam_split1_print, DB_bam_split1)) != 0)
 
2197
                return (ret);
 
2198
        if ((ret = __db_add_recovery(dbenv,
 
2199
            __bam_split_print, DB_bam_split)) != 0)
 
2200
                return (ret);
 
2201
        if ((ret = __db_add_recovery(dbenv,
 
2202
            __bam_rsplit1_print, DB_bam_rsplit1)) != 0)
 
2203
                return (ret);
 
2204
        if ((ret = __db_add_recovery(dbenv,
 
2205
            __bam_rsplit_print, DB_bam_rsplit)) != 0)
 
2206
                return (ret);
 
2207
        if ((ret = __db_add_recovery(dbenv,
 
2208
            __bam_adj_print, DB_bam_adj)) != 0)
 
2209
                return (ret);
 
2210
        if ((ret = __db_add_recovery(dbenv,
 
2211
            __bam_cadjust_print, DB_bam_cadjust)) != 0)
 
2212
                return (ret);
 
2213
        if ((ret = __db_add_recovery(dbenv,
 
2214
            __bam_cdel_print, DB_bam_cdel)) != 0)
 
2215
                return (ret);
 
2216
        if ((ret = __db_add_recovery(dbenv,
 
2217
            __bam_repl_print, DB_bam_repl)) != 0)
 
2218
                return (ret);
 
2219
        if ((ret = __db_add_recovery(dbenv,
 
2220
            __bam_root_print, DB_bam_root)) != 0)
 
2221
                return (ret);
 
2222
        if ((ret = __db_add_recovery(dbenv,
 
2223
            __bam_curadj_print, DB_bam_curadj)) != 0)
 
2224
                return (ret);
 
2225
        if ((ret = __db_add_recovery(dbenv,
 
2226
            __bam_rcuradj_print, DB_bam_rcuradj)) != 0)
 
2227
                return (ret);
 
2228
        return (0);
 
2229
}
 
2230
 
 
2231
int
 
2232
__bam_init_recover(dbenv)
 
2233
        DB_ENV *dbenv;
 
2234
{
 
2235
        int ret;
 
2236
 
 
2237
        if ((ret = __db_add_recovery(dbenv,
 
2238
            __bam_pg_alloc_recover, DB_bam_pg_alloc)) != 0)
 
2239
                return (ret);
 
2240
        if ((ret = __db_add_recovery(dbenv,
 
2241
            __deprecated_recover, DB_bam_pg_alloc1)) != 0)
 
2242
                return (ret);
 
2243
        if ((ret = __db_add_recovery(dbenv,
 
2244
            __bam_pg_free_recover, DB_bam_pg_free)) != 0)
 
2245
                return (ret);
 
2246
        if ((ret = __db_add_recovery(dbenv,
 
2247
            __deprecated_recover, DB_bam_pg_free1)) != 0)
 
2248
                return (ret);
 
2249
        if ((ret = __db_add_recovery(dbenv,
 
2250
            __deprecated_recover, DB_bam_split1)) != 0)
 
2251
                return (ret);
 
2252
        if ((ret = __db_add_recovery(dbenv,
 
2253
            __bam_split_recover, DB_bam_split)) != 0)
 
2254
                return (ret);
 
2255
        if ((ret = __db_add_recovery(dbenv,
 
2256
            __deprecated_recover, DB_bam_rsplit1)) != 0)
 
2257
                return (ret);
 
2258
        if ((ret = __db_add_recovery(dbenv,
 
2259
            __bam_rsplit_recover, DB_bam_rsplit)) != 0)
 
2260
                return (ret);
 
2261
        if ((ret = __db_add_recovery(dbenv,
 
2262
            __bam_adj_recover, DB_bam_adj)) != 0)
 
2263
                return (ret);
 
2264
        if ((ret = __db_add_recovery(dbenv,
 
2265
            __bam_cadjust_recover, DB_bam_cadjust)) != 0)
 
2266
                return (ret);
 
2267
        if ((ret = __db_add_recovery(dbenv,
 
2268
            __bam_cdel_recover, DB_bam_cdel)) != 0)
 
2269
                return (ret);
 
2270
        if ((ret = __db_add_recovery(dbenv,
 
2271
            __bam_repl_recover, DB_bam_repl)) != 0)
 
2272
                return (ret);
 
2273
        if ((ret = __db_add_recovery(dbenv,
 
2274
            __bam_root_recover, DB_bam_root)) != 0)
 
2275
                return (ret);
 
2276
        if ((ret = __db_add_recovery(dbenv,
 
2277
            __bam_curadj_recover, DB_bam_curadj)) != 0)
 
2278
                return (ret);
 
2279
        if ((ret = __db_add_recovery(dbenv,
 
2280
            __bam_rcuradj_recover, DB_bam_rcuradj)) != 0)
 
2281
                return (ret);
 
2282
        return (0);
 
2283
}
 
2284