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