xref: /illumos-gate/usr/src/cmd/sendmail/db/btree/btree_auto.c (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
1 /* Do not edit: automatically built by dist/db_gen.sh. */
2 #include "config.h"
3 
4 #ifndef NO_SYSTEM_INCLUDES
5 #include <ctype.h>
6 #include <errno.h>
7 #include <stddef.h>
8 #include <stdlib.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 "btree.h"
16 #include "db_am.h"
17 /*
18  * PUBLIC: int __bam_pg_alloc_log
19  * PUBLIC:     __P((DB_LOG *, DB_TXN *, DB_LSN *, u_int32_t,
20  * PUBLIC:     u_int32_t, DB_LSN *, DB_LSN *, db_pgno_t,
21  * PUBLIC:     u_int32_t, db_pgno_t));
22  */
__bam_pg_alloc_log(logp,txnid,ret_lsnp,flags,fileid,meta_lsn,page_lsn,pgno,ptype,next)23 int __bam_pg_alloc_log(logp, txnid, ret_lsnp, flags,
24 	fileid, meta_lsn, page_lsn, pgno, ptype, next)
25 	DB_LOG *logp;
26 	DB_TXN *txnid;
27 	DB_LSN *ret_lsnp;
28 	u_int32_t flags;
29 	u_int32_t fileid;
30 	DB_LSN * meta_lsn;
31 	DB_LSN * page_lsn;
32 	db_pgno_t pgno;
33 	u_int32_t ptype;
34 	db_pgno_t next;
35 {
36 	DBT logrec;
37 	DB_LSN *lsnp, null_lsn;
38 	u_int32_t rectype, txn_num;
39 	int ret;
40 	u_int8_t *bp;
41 
42 	rectype = DB_bam_pg_alloc;
43 	txn_num = txnid == NULL ? 0 : txnid->txnid;
44 	if (txnid == NULL) {
45 		ZERO_LSN(null_lsn);
46 		lsnp = &null_lsn;
47 	} else
48 		lsnp = &txnid->last_lsn;
49 	logrec.size = sizeof(rectype) + sizeof(txn_num) + sizeof(DB_LSN)
50 	    + sizeof(fileid)
51 	    + sizeof(*meta_lsn)
52 	    + sizeof(*page_lsn)
53 	    + sizeof(pgno)
54 	    + sizeof(ptype)
55 	    + sizeof(next);
56 	if ((ret = __os_malloc(logrec.size, NULL, &logrec.data)) != 0)
57 		return (ret);
58 
59 	bp = logrec.data;
60 	memcpy(bp, &rectype, sizeof(rectype));
61 	bp += sizeof(rectype);
62 	memcpy(bp, &txn_num, sizeof(txn_num));
63 	bp += sizeof(txn_num);
64 	memcpy(bp, lsnp, sizeof(DB_LSN));
65 	bp += sizeof(DB_LSN);
66 	memcpy(bp, &fileid, sizeof(fileid));
67 	bp += sizeof(fileid);
68 	if (meta_lsn != NULL)
69 		memcpy(bp, meta_lsn, sizeof(*meta_lsn));
70 	else
71 		memset(bp, 0, sizeof(*meta_lsn));
72 	bp += sizeof(*meta_lsn);
73 	if (page_lsn != NULL)
74 		memcpy(bp, page_lsn, sizeof(*page_lsn));
75 	else
76 		memset(bp, 0, sizeof(*page_lsn));
77 	bp += sizeof(*page_lsn);
78 	memcpy(bp, &pgno, sizeof(pgno));
79 	bp += sizeof(pgno);
80 	memcpy(bp, &ptype, sizeof(ptype));
81 	bp += sizeof(ptype);
82 	memcpy(bp, &next, sizeof(next));
83 	bp += sizeof(next);
84 #ifdef DIAGNOSTIC
85 	if ((u_int32_t)(bp - (u_int8_t *)logrec.data) != logrec.size)
86 		fprintf(stderr, "Error in log record length");
87 #endif
88 	ret = log_put(logp, ret_lsnp, (DBT *)&logrec, flags);
89 	if (txnid != NULL)
90 		txnid->last_lsn = *ret_lsnp;
91 	__os_free(logrec.data, 0);
92 	return (ret);
93 }
94 
95 /*
96  * PUBLIC: int __bam_pg_alloc_print
97  * PUBLIC:    __P((DB_LOG *, DBT *, DB_LSN *, int, void *));
98  */
99 int
__bam_pg_alloc_print(notused1,dbtp,lsnp,notused2,notused3)100 __bam_pg_alloc_print(notused1, dbtp, lsnp, notused2, notused3)
101 	DB_LOG *notused1;
102 	DBT *dbtp;
103 	DB_LSN *lsnp;
104 	int notused2;
105 	void *notused3;
106 {
107 	__bam_pg_alloc_args *argp;
108 	u_int32_t i;
109 	u_int ch;
110 	int ret;
111 
112 	i = 0;
113 	ch = 0;
114 	notused1 = NULL;
115 	notused2 = 0;
116 	notused3 = NULL;
117 
118 	if ((ret = __bam_pg_alloc_read(dbtp->data, &argp)) != 0)
119 		return (ret);
120 	printf("[%lu][%lu]bam_pg_alloc: rec: %lu txnid %lx prevlsn [%lu][%lu]\n",
121 	    (u_long)lsnp->file,
122 	    (u_long)lsnp->offset,
123 	    (u_long)argp->type,
124 	    (u_long)argp->txnid->txnid,
125 	    (u_long)argp->prev_lsn.file,
126 	    (u_long)argp->prev_lsn.offset);
127 	printf("\tfileid: %lu\n", (u_long)argp->fileid);
128 	printf("\tmeta_lsn: [%lu][%lu]\n",
129 	    (u_long)argp->meta_lsn.file, (u_long)argp->meta_lsn.offset);
130 	printf("\tpage_lsn: [%lu][%lu]\n",
131 	    (u_long)argp->page_lsn.file, (u_long)argp->page_lsn.offset);
132 	printf("\tpgno: %lu\n", (u_long)argp->pgno);
133 	printf("\tptype: %lu\n", (u_long)argp->ptype);
134 	printf("\tnext: %lu\n", (u_long)argp->next);
135 	printf("\n");
136 	__os_free(argp, 0);
137 	return (0);
138 }
139 
140 /*
141  * PUBLIC: int __bam_pg_alloc_read __P((void *, __bam_pg_alloc_args **));
142  */
143 int
__bam_pg_alloc_read(recbuf,argpp)144 __bam_pg_alloc_read(recbuf, argpp)
145 	void *recbuf;
146 	__bam_pg_alloc_args **argpp;
147 {
148 	__bam_pg_alloc_args *argp;
149 	u_int8_t *bp;
150 	int ret;
151 
152 	ret = __os_malloc(sizeof(__bam_pg_alloc_args) +
153 	    sizeof(DB_TXN), NULL, &argp);
154 	if (ret != 0)
155 		return (ret);
156 	argp->txnid = (DB_TXN *)&argp[1];
157 	bp = recbuf;
158 	memcpy(&argp->type, bp, sizeof(argp->type));
159 	bp += sizeof(argp->type);
160 	memcpy(&argp->txnid->txnid,  bp, sizeof(argp->txnid->txnid));
161 	bp += sizeof(argp->txnid->txnid);
162 	memcpy(&argp->prev_lsn, bp, sizeof(DB_LSN));
163 	bp += sizeof(DB_LSN);
164 	memcpy(&argp->fileid, bp, sizeof(argp->fileid));
165 	bp += sizeof(argp->fileid);
166 	memcpy(&argp->meta_lsn, bp,  sizeof(argp->meta_lsn));
167 	bp += sizeof(argp->meta_lsn);
168 	memcpy(&argp->page_lsn, bp,  sizeof(argp->page_lsn));
169 	bp += sizeof(argp->page_lsn);
170 	memcpy(&argp->pgno, bp, sizeof(argp->pgno));
171 	bp += sizeof(argp->pgno);
172 	memcpy(&argp->ptype, bp, sizeof(argp->ptype));
173 	bp += sizeof(argp->ptype);
174 	memcpy(&argp->next, bp, sizeof(argp->next));
175 	bp += sizeof(argp->next);
176 	*argpp = argp;
177 	return (0);
178 }
179 
180 /*
181  * PUBLIC: int __bam_pg_free_log
182  * PUBLIC:     __P((DB_LOG *, DB_TXN *, DB_LSN *, u_int32_t,
183  * PUBLIC:     u_int32_t, db_pgno_t, DB_LSN *, const DBT *,
184  * PUBLIC:     db_pgno_t));
185  */
__bam_pg_free_log(logp,txnid,ret_lsnp,flags,fileid,pgno,meta_lsn,header,next)186 int __bam_pg_free_log(logp, txnid, ret_lsnp, flags,
187 	fileid, pgno, meta_lsn, header, next)
188 	DB_LOG *logp;
189 	DB_TXN *txnid;
190 	DB_LSN *ret_lsnp;
191 	u_int32_t flags;
192 	u_int32_t fileid;
193 	db_pgno_t pgno;
194 	DB_LSN * meta_lsn;
195 	const DBT *header;
196 	db_pgno_t next;
197 {
198 	DBT logrec;
199 	DB_LSN *lsnp, null_lsn;
200 	u_int32_t zero;
201 	u_int32_t rectype, txn_num;
202 	int ret;
203 	u_int8_t *bp;
204 
205 	rectype = DB_bam_pg_free;
206 	txn_num = txnid == NULL ? 0 : txnid->txnid;
207 	if (txnid == NULL) {
208 		ZERO_LSN(null_lsn);
209 		lsnp = &null_lsn;
210 	} else
211 		lsnp = &txnid->last_lsn;
212 	logrec.size = sizeof(rectype) + sizeof(txn_num) + sizeof(DB_LSN)
213 	    + sizeof(fileid)
214 	    + sizeof(pgno)
215 	    + sizeof(*meta_lsn)
216 	    + sizeof(u_int32_t) + (header == NULL ? 0 : header->size)
217 	    + sizeof(next);
218 	if ((ret = __os_malloc(logrec.size, NULL, &logrec.data)) != 0)
219 		return (ret);
220 
221 	bp = logrec.data;
222 	memcpy(bp, &rectype, sizeof(rectype));
223 	bp += sizeof(rectype);
224 	memcpy(bp, &txn_num, sizeof(txn_num));
225 	bp += sizeof(txn_num);
226 	memcpy(bp, lsnp, sizeof(DB_LSN));
227 	bp += sizeof(DB_LSN);
228 	memcpy(bp, &fileid, sizeof(fileid));
229 	bp += sizeof(fileid);
230 	memcpy(bp, &pgno, sizeof(pgno));
231 	bp += sizeof(pgno);
232 	if (meta_lsn != NULL)
233 		memcpy(bp, meta_lsn, sizeof(*meta_lsn));
234 	else
235 		memset(bp, 0, sizeof(*meta_lsn));
236 	bp += sizeof(*meta_lsn);
237 	if (header == NULL) {
238 		zero = 0;
239 		memcpy(bp, &zero, sizeof(u_int32_t));
240 		bp += sizeof(u_int32_t);
241 	} else {
242 		memcpy(bp, &header->size, sizeof(header->size));
243 		bp += sizeof(header->size);
244 		memcpy(bp, header->data, header->size);
245 		bp += header->size;
246 	}
247 	memcpy(bp, &next, sizeof(next));
248 	bp += sizeof(next);
249 #ifdef DIAGNOSTIC
250 	if ((u_int32_t)(bp - (u_int8_t *)logrec.data) != logrec.size)
251 		fprintf(stderr, "Error in log record length");
252 #endif
253 	ret = log_put(logp, ret_lsnp, (DBT *)&logrec, flags);
254 	if (txnid != NULL)
255 		txnid->last_lsn = *ret_lsnp;
256 	__os_free(logrec.data, 0);
257 	return (ret);
258 }
259 
260 /*
261  * PUBLIC: int __bam_pg_free_print
262  * PUBLIC:    __P((DB_LOG *, DBT *, DB_LSN *, int, void *));
263  */
264 int
__bam_pg_free_print(notused1,dbtp,lsnp,notused2,notused3)265 __bam_pg_free_print(notused1, dbtp, lsnp, notused2, notused3)
266 	DB_LOG *notused1;
267 	DBT *dbtp;
268 	DB_LSN *lsnp;
269 	int notused2;
270 	void *notused3;
271 {
272 	__bam_pg_free_args *argp;
273 	u_int32_t i;
274 	u_int ch;
275 	int ret;
276 
277 	i = 0;
278 	ch = 0;
279 	notused1 = NULL;
280 	notused2 = 0;
281 	notused3 = NULL;
282 
283 	if ((ret = __bam_pg_free_read(dbtp->data, &argp)) != 0)
284 		return (ret);
285 	printf("[%lu][%lu]bam_pg_free: rec: %lu txnid %lx prevlsn [%lu][%lu]\n",
286 	    (u_long)lsnp->file,
287 	    (u_long)lsnp->offset,
288 	    (u_long)argp->type,
289 	    (u_long)argp->txnid->txnid,
290 	    (u_long)argp->prev_lsn.file,
291 	    (u_long)argp->prev_lsn.offset);
292 	printf("\tfileid: %lu\n", (u_long)argp->fileid);
293 	printf("\tpgno: %lu\n", (u_long)argp->pgno);
294 	printf("\tmeta_lsn: [%lu][%lu]\n",
295 	    (u_long)argp->meta_lsn.file, (u_long)argp->meta_lsn.offset);
296 	printf("\theader: ");
297 	for (i = 0; i < argp->header.size; i++) {
298 		ch = ((u_int8_t *)argp->header.data)[i];
299 		if (isprint(ch) || ch == 0xa)
300 			putchar(ch);
301 		else
302 			printf("%#x ", ch);
303 	}
304 	printf("\n");
305 	printf("\tnext: %lu\n", (u_long)argp->next);
306 	printf("\n");
307 	__os_free(argp, 0);
308 	return (0);
309 }
310 
311 /*
312  * PUBLIC: int __bam_pg_free_read __P((void *, __bam_pg_free_args **));
313  */
314 int
__bam_pg_free_read(recbuf,argpp)315 __bam_pg_free_read(recbuf, argpp)
316 	void *recbuf;
317 	__bam_pg_free_args **argpp;
318 {
319 	__bam_pg_free_args *argp;
320 	u_int8_t *bp;
321 	int ret;
322 
323 	ret = __os_malloc(sizeof(__bam_pg_free_args) +
324 	    sizeof(DB_TXN), NULL, &argp);
325 	if (ret != 0)
326 		return (ret);
327 	argp->txnid = (DB_TXN *)&argp[1];
328 	bp = recbuf;
329 	memcpy(&argp->type, bp, sizeof(argp->type));
330 	bp += sizeof(argp->type);
331 	memcpy(&argp->txnid->txnid,  bp, sizeof(argp->txnid->txnid));
332 	bp += sizeof(argp->txnid->txnid);
333 	memcpy(&argp->prev_lsn, bp, sizeof(DB_LSN));
334 	bp += sizeof(DB_LSN);
335 	memcpy(&argp->fileid, bp, sizeof(argp->fileid));
336 	bp += sizeof(argp->fileid);
337 	memcpy(&argp->pgno, bp, sizeof(argp->pgno));
338 	bp += sizeof(argp->pgno);
339 	memcpy(&argp->meta_lsn, bp,  sizeof(argp->meta_lsn));
340 	bp += sizeof(argp->meta_lsn);
341 	memcpy(&argp->header.size, bp, sizeof(u_int32_t));
342 	bp += sizeof(u_int32_t);
343 	argp->header.data = bp;
344 	bp += argp->header.size;
345 	memcpy(&argp->next, bp, sizeof(argp->next));
346 	bp += sizeof(argp->next);
347 	*argpp = argp;
348 	return (0);
349 }
350 
351 /*
352  * PUBLIC: int __bam_split_log
353  * PUBLIC:     __P((DB_LOG *, DB_TXN *, DB_LSN *, u_int32_t,
354  * PUBLIC:     u_int32_t, db_pgno_t, DB_LSN *, db_pgno_t,
355  * PUBLIC:     DB_LSN *, u_int32_t, db_pgno_t, DB_LSN *,
356  * PUBLIC:     const DBT *));
357  */
__bam_split_log(logp,txnid,ret_lsnp,flags,fileid,left,llsn,right,rlsn,indx,npgno,nlsn,pg)358 int __bam_split_log(logp, txnid, ret_lsnp, flags,
359 	fileid, left, llsn, right, rlsn, indx,
360 	npgno, nlsn, pg)
361 	DB_LOG *logp;
362 	DB_TXN *txnid;
363 	DB_LSN *ret_lsnp;
364 	u_int32_t flags;
365 	u_int32_t fileid;
366 	db_pgno_t left;
367 	DB_LSN * llsn;
368 	db_pgno_t right;
369 	DB_LSN * rlsn;
370 	u_int32_t indx;
371 	db_pgno_t npgno;
372 	DB_LSN * nlsn;
373 	const DBT *pg;
374 {
375 	DBT logrec;
376 	DB_LSN *lsnp, null_lsn;
377 	u_int32_t zero;
378 	u_int32_t rectype, txn_num;
379 	int ret;
380 	u_int8_t *bp;
381 
382 	rectype = DB_bam_split;
383 	txn_num = txnid == NULL ? 0 : txnid->txnid;
384 	if (txnid == NULL) {
385 		ZERO_LSN(null_lsn);
386 		lsnp = &null_lsn;
387 	} else
388 		lsnp = &txnid->last_lsn;
389 	logrec.size = sizeof(rectype) + sizeof(txn_num) + sizeof(DB_LSN)
390 	    + sizeof(fileid)
391 	    + sizeof(left)
392 	    + sizeof(*llsn)
393 	    + sizeof(right)
394 	    + sizeof(*rlsn)
395 	    + sizeof(indx)
396 	    + sizeof(npgno)
397 	    + sizeof(*nlsn)
398 	    + sizeof(u_int32_t) + (pg == NULL ? 0 : pg->size);
399 	if ((ret = __os_malloc(logrec.size, NULL, &logrec.data)) != 0)
400 		return (ret);
401 
402 	bp = logrec.data;
403 	memcpy(bp, &rectype, sizeof(rectype));
404 	bp += sizeof(rectype);
405 	memcpy(bp, &txn_num, sizeof(txn_num));
406 	bp += sizeof(txn_num);
407 	memcpy(bp, lsnp, sizeof(DB_LSN));
408 	bp += sizeof(DB_LSN);
409 	memcpy(bp, &fileid, sizeof(fileid));
410 	bp += sizeof(fileid);
411 	memcpy(bp, &left, sizeof(left));
412 	bp += sizeof(left);
413 	if (llsn != NULL)
414 		memcpy(bp, llsn, sizeof(*llsn));
415 	else
416 		memset(bp, 0, sizeof(*llsn));
417 	bp += sizeof(*llsn);
418 	memcpy(bp, &right, sizeof(right));
419 	bp += sizeof(right);
420 	if (rlsn != NULL)
421 		memcpy(bp, rlsn, sizeof(*rlsn));
422 	else
423 		memset(bp, 0, sizeof(*rlsn));
424 	bp += sizeof(*rlsn);
425 	memcpy(bp, &indx, sizeof(indx));
426 	bp += sizeof(indx);
427 	memcpy(bp, &npgno, sizeof(npgno));
428 	bp += sizeof(npgno);
429 	if (nlsn != NULL)
430 		memcpy(bp, nlsn, sizeof(*nlsn));
431 	else
432 		memset(bp, 0, sizeof(*nlsn));
433 	bp += sizeof(*nlsn);
434 	if (pg == NULL) {
435 		zero = 0;
436 		memcpy(bp, &zero, sizeof(u_int32_t));
437 		bp += sizeof(u_int32_t);
438 	} else {
439 		memcpy(bp, &pg->size, sizeof(pg->size));
440 		bp += sizeof(pg->size);
441 		memcpy(bp, pg->data, pg->size);
442 		bp += pg->size;
443 	}
444 #ifdef DIAGNOSTIC
445 	if ((u_int32_t)(bp - (u_int8_t *)logrec.data) != logrec.size)
446 		fprintf(stderr, "Error in log record length");
447 #endif
448 	ret = log_put(logp, ret_lsnp, (DBT *)&logrec, flags);
449 	if (txnid != NULL)
450 		txnid->last_lsn = *ret_lsnp;
451 	__os_free(logrec.data, 0);
452 	return (ret);
453 }
454 
455 /*
456  * PUBLIC: int __bam_split_print
457  * PUBLIC:    __P((DB_LOG *, DBT *, DB_LSN *, int, void *));
458  */
459 int
__bam_split_print(notused1,dbtp,lsnp,notused2,notused3)460 __bam_split_print(notused1, dbtp, lsnp, notused2, notused3)
461 	DB_LOG *notused1;
462 	DBT *dbtp;
463 	DB_LSN *lsnp;
464 	int notused2;
465 	void *notused3;
466 {
467 	__bam_split_args *argp;
468 	u_int32_t i;
469 	u_int ch;
470 	int ret;
471 
472 	i = 0;
473 	ch = 0;
474 	notused1 = NULL;
475 	notused2 = 0;
476 	notused3 = NULL;
477 
478 	if ((ret = __bam_split_read(dbtp->data, &argp)) != 0)
479 		return (ret);
480 	printf("[%lu][%lu]bam_split: rec: %lu txnid %lx prevlsn [%lu][%lu]\n",
481 	    (u_long)lsnp->file,
482 	    (u_long)lsnp->offset,
483 	    (u_long)argp->type,
484 	    (u_long)argp->txnid->txnid,
485 	    (u_long)argp->prev_lsn.file,
486 	    (u_long)argp->prev_lsn.offset);
487 	printf("\tfileid: %lu\n", (u_long)argp->fileid);
488 	printf("\tleft: %lu\n", (u_long)argp->left);
489 	printf("\tllsn: [%lu][%lu]\n",
490 	    (u_long)argp->llsn.file, (u_long)argp->llsn.offset);
491 	printf("\tright: %lu\n", (u_long)argp->right);
492 	printf("\trlsn: [%lu][%lu]\n",
493 	    (u_long)argp->rlsn.file, (u_long)argp->rlsn.offset);
494 	printf("\tindx: %lu\n", (u_long)argp->indx);
495 	printf("\tnpgno: %lu\n", (u_long)argp->npgno);
496 	printf("\tnlsn: [%lu][%lu]\n",
497 	    (u_long)argp->nlsn.file, (u_long)argp->nlsn.offset);
498 	printf("\tpg: ");
499 	for (i = 0; i < argp->pg.size; i++) {
500 		ch = ((u_int8_t *)argp->pg.data)[i];
501 		if (isprint(ch) || ch == 0xa)
502 			putchar(ch);
503 		else
504 			printf("%#x ", ch);
505 	}
506 	printf("\n");
507 	printf("\n");
508 	__os_free(argp, 0);
509 	return (0);
510 }
511 
512 /*
513  * PUBLIC: int __bam_split_read __P((void *, __bam_split_args **));
514  */
515 int
__bam_split_read(recbuf,argpp)516 __bam_split_read(recbuf, argpp)
517 	void *recbuf;
518 	__bam_split_args **argpp;
519 {
520 	__bam_split_args *argp;
521 	u_int8_t *bp;
522 	int ret;
523 
524 	ret = __os_malloc(sizeof(__bam_split_args) +
525 	    sizeof(DB_TXN), NULL, &argp);
526 	if (ret != 0)
527 		return (ret);
528 	argp->txnid = (DB_TXN *)&argp[1];
529 	bp = recbuf;
530 	memcpy(&argp->type, bp, sizeof(argp->type));
531 	bp += sizeof(argp->type);
532 	memcpy(&argp->txnid->txnid,  bp, sizeof(argp->txnid->txnid));
533 	bp += sizeof(argp->txnid->txnid);
534 	memcpy(&argp->prev_lsn, bp, sizeof(DB_LSN));
535 	bp += sizeof(DB_LSN);
536 	memcpy(&argp->fileid, bp, sizeof(argp->fileid));
537 	bp += sizeof(argp->fileid);
538 	memcpy(&argp->left, bp, sizeof(argp->left));
539 	bp += sizeof(argp->left);
540 	memcpy(&argp->llsn, bp,  sizeof(argp->llsn));
541 	bp += sizeof(argp->llsn);
542 	memcpy(&argp->right, bp, sizeof(argp->right));
543 	bp += sizeof(argp->right);
544 	memcpy(&argp->rlsn, bp,  sizeof(argp->rlsn));
545 	bp += sizeof(argp->rlsn);
546 	memcpy(&argp->indx, bp, sizeof(argp->indx));
547 	bp += sizeof(argp->indx);
548 	memcpy(&argp->npgno, bp, sizeof(argp->npgno));
549 	bp += sizeof(argp->npgno);
550 	memcpy(&argp->nlsn, bp,  sizeof(argp->nlsn));
551 	bp += sizeof(argp->nlsn);
552 	memcpy(&argp->pg.size, bp, sizeof(u_int32_t));
553 	bp += sizeof(u_int32_t);
554 	argp->pg.data = bp;
555 	bp += argp->pg.size;
556 	*argpp = argp;
557 	return (0);
558 }
559 
560 /*
561  * PUBLIC: int __bam_rsplit_log
562  * PUBLIC:     __P((DB_LOG *, DB_TXN *, DB_LSN *, u_int32_t,
563  * PUBLIC:     u_int32_t, db_pgno_t, const DBT *, db_pgno_t,
564  * PUBLIC:     const DBT *, DB_LSN *));
565  */
__bam_rsplit_log(logp,txnid,ret_lsnp,flags,fileid,pgno,pgdbt,nrec,rootent,rootlsn)566 int __bam_rsplit_log(logp, txnid, ret_lsnp, flags,
567 	fileid, pgno, pgdbt, nrec, rootent, rootlsn)
568 	DB_LOG *logp;
569 	DB_TXN *txnid;
570 	DB_LSN *ret_lsnp;
571 	u_int32_t flags;
572 	u_int32_t fileid;
573 	db_pgno_t pgno;
574 	const DBT *pgdbt;
575 	db_pgno_t nrec;
576 	const DBT *rootent;
577 	DB_LSN * rootlsn;
578 {
579 	DBT logrec;
580 	DB_LSN *lsnp, null_lsn;
581 	u_int32_t zero;
582 	u_int32_t rectype, txn_num;
583 	int ret;
584 	u_int8_t *bp;
585 
586 	rectype = DB_bam_rsplit;
587 	txn_num = txnid == NULL ? 0 : txnid->txnid;
588 	if (txnid == NULL) {
589 		ZERO_LSN(null_lsn);
590 		lsnp = &null_lsn;
591 	} else
592 		lsnp = &txnid->last_lsn;
593 	logrec.size = sizeof(rectype) + sizeof(txn_num) + sizeof(DB_LSN)
594 	    + sizeof(fileid)
595 	    + sizeof(pgno)
596 	    + sizeof(u_int32_t) + (pgdbt == NULL ? 0 : pgdbt->size)
597 	    + sizeof(nrec)
598 	    + sizeof(u_int32_t) + (rootent == NULL ? 0 : rootent->size)
599 	    + sizeof(*rootlsn);
600 	if ((ret = __os_malloc(logrec.size, NULL, &logrec.data)) != 0)
601 		return (ret);
602 
603 	bp = logrec.data;
604 	memcpy(bp, &rectype, sizeof(rectype));
605 	bp += sizeof(rectype);
606 	memcpy(bp, &txn_num, sizeof(txn_num));
607 	bp += sizeof(txn_num);
608 	memcpy(bp, lsnp, sizeof(DB_LSN));
609 	bp += sizeof(DB_LSN);
610 	memcpy(bp, &fileid, sizeof(fileid));
611 	bp += sizeof(fileid);
612 	memcpy(bp, &pgno, sizeof(pgno));
613 	bp += sizeof(pgno);
614 	if (pgdbt == NULL) {
615 		zero = 0;
616 		memcpy(bp, &zero, sizeof(u_int32_t));
617 		bp += sizeof(u_int32_t);
618 	} else {
619 		memcpy(bp, &pgdbt->size, sizeof(pgdbt->size));
620 		bp += sizeof(pgdbt->size);
621 		memcpy(bp, pgdbt->data, pgdbt->size);
622 		bp += pgdbt->size;
623 	}
624 	memcpy(bp, &nrec, sizeof(nrec));
625 	bp += sizeof(nrec);
626 	if (rootent == NULL) {
627 		zero = 0;
628 		memcpy(bp, &zero, sizeof(u_int32_t));
629 		bp += sizeof(u_int32_t);
630 	} else {
631 		memcpy(bp, &rootent->size, sizeof(rootent->size));
632 		bp += sizeof(rootent->size);
633 		memcpy(bp, rootent->data, rootent->size);
634 		bp += rootent->size;
635 	}
636 	if (rootlsn != NULL)
637 		memcpy(bp, rootlsn, sizeof(*rootlsn));
638 	else
639 		memset(bp, 0, sizeof(*rootlsn));
640 	bp += sizeof(*rootlsn);
641 #ifdef DIAGNOSTIC
642 	if ((u_int32_t)(bp - (u_int8_t *)logrec.data) != logrec.size)
643 		fprintf(stderr, "Error in log record length");
644 #endif
645 	ret = log_put(logp, ret_lsnp, (DBT *)&logrec, flags);
646 	if (txnid != NULL)
647 		txnid->last_lsn = *ret_lsnp;
648 	__os_free(logrec.data, 0);
649 	return (ret);
650 }
651 
652 /*
653  * PUBLIC: int __bam_rsplit_print
654  * PUBLIC:    __P((DB_LOG *, DBT *, DB_LSN *, int, void *));
655  */
656 int
__bam_rsplit_print(notused1,dbtp,lsnp,notused2,notused3)657 __bam_rsplit_print(notused1, dbtp, lsnp, notused2, notused3)
658 	DB_LOG *notused1;
659 	DBT *dbtp;
660 	DB_LSN *lsnp;
661 	int notused2;
662 	void *notused3;
663 {
664 	__bam_rsplit_args *argp;
665 	u_int32_t i;
666 	u_int ch;
667 	int ret;
668 
669 	i = 0;
670 	ch = 0;
671 	notused1 = NULL;
672 	notused2 = 0;
673 	notused3 = NULL;
674 
675 	if ((ret = __bam_rsplit_read(dbtp->data, &argp)) != 0)
676 		return (ret);
677 	printf("[%lu][%lu]bam_rsplit: rec: %lu txnid %lx prevlsn [%lu][%lu]\n",
678 	    (u_long)lsnp->file,
679 	    (u_long)lsnp->offset,
680 	    (u_long)argp->type,
681 	    (u_long)argp->txnid->txnid,
682 	    (u_long)argp->prev_lsn.file,
683 	    (u_long)argp->prev_lsn.offset);
684 	printf("\tfileid: %lu\n", (u_long)argp->fileid);
685 	printf("\tpgno: %lu\n", (u_long)argp->pgno);
686 	printf("\tpgdbt: ");
687 	for (i = 0; i < argp->pgdbt.size; i++) {
688 		ch = ((u_int8_t *)argp->pgdbt.data)[i];
689 		if (isprint(ch) || ch == 0xa)
690 			putchar(ch);
691 		else
692 			printf("%#x ", ch);
693 	}
694 	printf("\n");
695 	printf("\tnrec: %lu\n", (u_long)argp->nrec);
696 	printf("\trootent: ");
697 	for (i = 0; i < argp->rootent.size; i++) {
698 		ch = ((u_int8_t *)argp->rootent.data)[i];
699 		if (isprint(ch) || ch == 0xa)
700 			putchar(ch);
701 		else
702 			printf("%#x ", ch);
703 	}
704 	printf("\n");
705 	printf("\trootlsn: [%lu][%lu]\n",
706 	    (u_long)argp->rootlsn.file, (u_long)argp->rootlsn.offset);
707 	printf("\n");
708 	__os_free(argp, 0);
709 	return (0);
710 }
711 
712 /*
713  * PUBLIC: int __bam_rsplit_read __P((void *, __bam_rsplit_args **));
714  */
715 int
__bam_rsplit_read(recbuf,argpp)716 __bam_rsplit_read(recbuf, argpp)
717 	void *recbuf;
718 	__bam_rsplit_args **argpp;
719 {
720 	__bam_rsplit_args *argp;
721 	u_int8_t *bp;
722 	int ret;
723 
724 	ret = __os_malloc(sizeof(__bam_rsplit_args) +
725 	    sizeof(DB_TXN), NULL, &argp);
726 	if (ret != 0)
727 		return (ret);
728 	argp->txnid = (DB_TXN *)&argp[1];
729 	bp = recbuf;
730 	memcpy(&argp->type, bp, sizeof(argp->type));
731 	bp += sizeof(argp->type);
732 	memcpy(&argp->txnid->txnid,  bp, sizeof(argp->txnid->txnid));
733 	bp += sizeof(argp->txnid->txnid);
734 	memcpy(&argp->prev_lsn, bp, sizeof(DB_LSN));
735 	bp += sizeof(DB_LSN);
736 	memcpy(&argp->fileid, bp, sizeof(argp->fileid));
737 	bp += sizeof(argp->fileid);
738 	memcpy(&argp->pgno, bp, sizeof(argp->pgno));
739 	bp += sizeof(argp->pgno);
740 	memcpy(&argp->pgdbt.size, bp, sizeof(u_int32_t));
741 	bp += sizeof(u_int32_t);
742 	argp->pgdbt.data = bp;
743 	bp += argp->pgdbt.size;
744 	memcpy(&argp->nrec, bp, sizeof(argp->nrec));
745 	bp += sizeof(argp->nrec);
746 	memcpy(&argp->rootent.size, bp, sizeof(u_int32_t));
747 	bp += sizeof(u_int32_t);
748 	argp->rootent.data = bp;
749 	bp += argp->rootent.size;
750 	memcpy(&argp->rootlsn, bp,  sizeof(argp->rootlsn));
751 	bp += sizeof(argp->rootlsn);
752 	*argpp = argp;
753 	return (0);
754 }
755 
756 /*
757  * PUBLIC: int __bam_adj_log
758  * PUBLIC:     __P((DB_LOG *, DB_TXN *, DB_LSN *, u_int32_t,
759  * PUBLIC:     u_int32_t, db_pgno_t, DB_LSN *, u_int32_t,
760  * PUBLIC:     u_int32_t, u_int32_t));
761  */
__bam_adj_log(logp,txnid,ret_lsnp,flags,fileid,pgno,lsn,indx,indx_copy,is_insert)762 int __bam_adj_log(logp, txnid, ret_lsnp, flags,
763 	fileid, pgno, lsn, indx, indx_copy, is_insert)
764 	DB_LOG *logp;
765 	DB_TXN *txnid;
766 	DB_LSN *ret_lsnp;
767 	u_int32_t flags;
768 	u_int32_t fileid;
769 	db_pgno_t pgno;
770 	DB_LSN * lsn;
771 	u_int32_t indx;
772 	u_int32_t indx_copy;
773 	u_int32_t is_insert;
774 {
775 	DBT logrec;
776 	DB_LSN *lsnp, null_lsn;
777 	u_int32_t rectype, txn_num;
778 	int ret;
779 	u_int8_t *bp;
780 
781 	rectype = DB_bam_adj;
782 	txn_num = txnid == NULL ? 0 : txnid->txnid;
783 	if (txnid == NULL) {
784 		ZERO_LSN(null_lsn);
785 		lsnp = &null_lsn;
786 	} else
787 		lsnp = &txnid->last_lsn;
788 	logrec.size = sizeof(rectype) + sizeof(txn_num) + sizeof(DB_LSN)
789 	    + sizeof(fileid)
790 	    + sizeof(pgno)
791 	    + sizeof(*lsn)
792 	    + sizeof(indx)
793 	    + sizeof(indx_copy)
794 	    + sizeof(is_insert);
795 	if ((ret = __os_malloc(logrec.size, NULL, &logrec.data)) != 0)
796 		return (ret);
797 
798 	bp = logrec.data;
799 	memcpy(bp, &rectype, sizeof(rectype));
800 	bp += sizeof(rectype);
801 	memcpy(bp, &txn_num, sizeof(txn_num));
802 	bp += sizeof(txn_num);
803 	memcpy(bp, lsnp, sizeof(DB_LSN));
804 	bp += sizeof(DB_LSN);
805 	memcpy(bp, &fileid, sizeof(fileid));
806 	bp += sizeof(fileid);
807 	memcpy(bp, &pgno, sizeof(pgno));
808 	bp += sizeof(pgno);
809 	if (lsn != NULL)
810 		memcpy(bp, lsn, sizeof(*lsn));
811 	else
812 		memset(bp, 0, sizeof(*lsn));
813 	bp += sizeof(*lsn);
814 	memcpy(bp, &indx, sizeof(indx));
815 	bp += sizeof(indx);
816 	memcpy(bp, &indx_copy, sizeof(indx_copy));
817 	bp += sizeof(indx_copy);
818 	memcpy(bp, &is_insert, sizeof(is_insert));
819 	bp += sizeof(is_insert);
820 #ifdef DIAGNOSTIC
821 	if ((u_int32_t)(bp - (u_int8_t *)logrec.data) != logrec.size)
822 		fprintf(stderr, "Error in log record length");
823 #endif
824 	ret = log_put(logp, ret_lsnp, (DBT *)&logrec, flags);
825 	if (txnid != NULL)
826 		txnid->last_lsn = *ret_lsnp;
827 	__os_free(logrec.data, 0);
828 	return (ret);
829 }
830 
831 /*
832  * PUBLIC: int __bam_adj_print
833  * PUBLIC:    __P((DB_LOG *, DBT *, DB_LSN *, int, void *));
834  */
835 int
__bam_adj_print(notused1,dbtp,lsnp,notused2,notused3)836 __bam_adj_print(notused1, dbtp, lsnp, notused2, notused3)
837 	DB_LOG *notused1;
838 	DBT *dbtp;
839 	DB_LSN *lsnp;
840 	int notused2;
841 	void *notused3;
842 {
843 	__bam_adj_args *argp;
844 	u_int32_t i;
845 	u_int ch;
846 	int ret;
847 
848 	i = 0;
849 	ch = 0;
850 	notused1 = NULL;
851 	notused2 = 0;
852 	notused3 = NULL;
853 
854 	if ((ret = __bam_adj_read(dbtp->data, &argp)) != 0)
855 		return (ret);
856 	printf("[%lu][%lu]bam_adj: rec: %lu txnid %lx prevlsn [%lu][%lu]\n",
857 	    (u_long)lsnp->file,
858 	    (u_long)lsnp->offset,
859 	    (u_long)argp->type,
860 	    (u_long)argp->txnid->txnid,
861 	    (u_long)argp->prev_lsn.file,
862 	    (u_long)argp->prev_lsn.offset);
863 	printf("\tfileid: %lu\n", (u_long)argp->fileid);
864 	printf("\tpgno: %lu\n", (u_long)argp->pgno);
865 	printf("\tlsn: [%lu][%lu]\n",
866 	    (u_long)argp->lsn.file, (u_long)argp->lsn.offset);
867 	printf("\tindx: %lu\n", (u_long)argp->indx);
868 	printf("\tindx_copy: %lu\n", (u_long)argp->indx_copy);
869 	printf("\tis_insert: %lu\n", (u_long)argp->is_insert);
870 	printf("\n");
871 	__os_free(argp, 0);
872 	return (0);
873 }
874 
875 /*
876  * PUBLIC: int __bam_adj_read __P((void *, __bam_adj_args **));
877  */
878 int
__bam_adj_read(recbuf,argpp)879 __bam_adj_read(recbuf, argpp)
880 	void *recbuf;
881 	__bam_adj_args **argpp;
882 {
883 	__bam_adj_args *argp;
884 	u_int8_t *bp;
885 	int ret;
886 
887 	ret = __os_malloc(sizeof(__bam_adj_args) +
888 	    sizeof(DB_TXN), NULL, &argp);
889 	if (ret != 0)
890 		return (ret);
891 	argp->txnid = (DB_TXN *)&argp[1];
892 	bp = recbuf;
893 	memcpy(&argp->type, bp, sizeof(argp->type));
894 	bp += sizeof(argp->type);
895 	memcpy(&argp->txnid->txnid,  bp, sizeof(argp->txnid->txnid));
896 	bp += sizeof(argp->txnid->txnid);
897 	memcpy(&argp->prev_lsn, bp, sizeof(DB_LSN));
898 	bp += sizeof(DB_LSN);
899 	memcpy(&argp->fileid, bp, sizeof(argp->fileid));
900 	bp += sizeof(argp->fileid);
901 	memcpy(&argp->pgno, bp, sizeof(argp->pgno));
902 	bp += sizeof(argp->pgno);
903 	memcpy(&argp->lsn, bp,  sizeof(argp->lsn));
904 	bp += sizeof(argp->lsn);
905 	memcpy(&argp->indx, bp, sizeof(argp->indx));
906 	bp += sizeof(argp->indx);
907 	memcpy(&argp->indx_copy, bp, sizeof(argp->indx_copy));
908 	bp += sizeof(argp->indx_copy);
909 	memcpy(&argp->is_insert, bp, sizeof(argp->is_insert));
910 	bp += sizeof(argp->is_insert);
911 	*argpp = argp;
912 	return (0);
913 }
914 
915 /*
916  * PUBLIC: int __bam_cadjust_log
917  * PUBLIC:     __P((DB_LOG *, DB_TXN *, DB_LSN *, u_int32_t,
918  * PUBLIC:     u_int32_t, db_pgno_t, DB_LSN *, u_int32_t,
919  * PUBLIC:     int32_t, int32_t));
920  */
__bam_cadjust_log(logp,txnid,ret_lsnp,flags,fileid,pgno,lsn,indx,adjust,total)921 int __bam_cadjust_log(logp, txnid, ret_lsnp, flags,
922 	fileid, pgno, lsn, indx, adjust, total)
923 	DB_LOG *logp;
924 	DB_TXN *txnid;
925 	DB_LSN *ret_lsnp;
926 	u_int32_t flags;
927 	u_int32_t fileid;
928 	db_pgno_t pgno;
929 	DB_LSN * lsn;
930 	u_int32_t indx;
931 	int32_t adjust;
932 	int32_t total;
933 {
934 	DBT logrec;
935 	DB_LSN *lsnp, null_lsn;
936 	u_int32_t rectype, txn_num;
937 	int ret;
938 	u_int8_t *bp;
939 
940 	rectype = DB_bam_cadjust;
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(*lsn)
951 	    + sizeof(indx)
952 	    + sizeof(adjust)
953 	    + sizeof(total);
954 	if ((ret = __os_malloc(logrec.size, NULL, &logrec.data)) != 0)
955 		return (ret);
956 
957 	bp = logrec.data;
958 	memcpy(bp, &rectype, sizeof(rectype));
959 	bp += sizeof(rectype);
960 	memcpy(bp, &txn_num, sizeof(txn_num));
961 	bp += sizeof(txn_num);
962 	memcpy(bp, lsnp, sizeof(DB_LSN));
963 	bp += sizeof(DB_LSN);
964 	memcpy(bp, &fileid, sizeof(fileid));
965 	bp += sizeof(fileid);
966 	memcpy(bp, &pgno, sizeof(pgno));
967 	bp += sizeof(pgno);
968 	if (lsn != NULL)
969 		memcpy(bp, lsn, sizeof(*lsn));
970 	else
971 		memset(bp, 0, sizeof(*lsn));
972 	bp += sizeof(*lsn);
973 	memcpy(bp, &indx, sizeof(indx));
974 	bp += sizeof(indx);
975 	memcpy(bp, &adjust, sizeof(adjust));
976 	bp += sizeof(adjust);
977 	memcpy(bp, &total, sizeof(total));
978 	bp += sizeof(total);
979 #ifdef DIAGNOSTIC
980 	if ((u_int32_t)(bp - (u_int8_t *)logrec.data) != logrec.size)
981 		fprintf(stderr, "Error in log record length");
982 #endif
983 	ret = log_put(logp, ret_lsnp, (DBT *)&logrec, flags);
984 	if (txnid != NULL)
985 		txnid->last_lsn = *ret_lsnp;
986 	__os_free(logrec.data, 0);
987 	return (ret);
988 }
989 
990 /*
991  * PUBLIC: int __bam_cadjust_print
992  * PUBLIC:    __P((DB_LOG *, DBT *, DB_LSN *, int, void *));
993  */
994 int
__bam_cadjust_print(notused1,dbtp,lsnp,notused2,notused3)995 __bam_cadjust_print(notused1, dbtp, lsnp, notused2, notused3)
996 	DB_LOG *notused1;
997 	DBT *dbtp;
998 	DB_LSN *lsnp;
999 	int notused2;
1000 	void *notused3;
1001 {
1002 	__bam_cadjust_args *argp;
1003 	u_int32_t i;
1004 	u_int ch;
1005 	int ret;
1006 
1007 	i = 0;
1008 	ch = 0;
1009 	notused1 = NULL;
1010 	notused2 = 0;
1011 	notused3 = NULL;
1012 
1013 	if ((ret = __bam_cadjust_read(dbtp->data, &argp)) != 0)
1014 		return (ret);
1015 	printf("[%lu][%lu]bam_cadjust: rec: %lu txnid %lx prevlsn [%lu][%lu]\n",
1016 	    (u_long)lsnp->file,
1017 	    (u_long)lsnp->offset,
1018 	    (u_long)argp->type,
1019 	    (u_long)argp->txnid->txnid,
1020 	    (u_long)argp->prev_lsn.file,
1021 	    (u_long)argp->prev_lsn.offset);
1022 	printf("\tfileid: %lu\n", (u_long)argp->fileid);
1023 	printf("\tpgno: %lu\n", (u_long)argp->pgno);
1024 	printf("\tlsn: [%lu][%lu]\n",
1025 	    (u_long)argp->lsn.file, (u_long)argp->lsn.offset);
1026 	printf("\tindx: %lu\n", (u_long)argp->indx);
1027 	printf("\tadjust: %ld\n", (long)argp->adjust);
1028 	printf("\ttotal: %ld\n", (long)argp->total);
1029 	printf("\n");
1030 	__os_free(argp, 0);
1031 	return (0);
1032 }
1033 
1034 /*
1035  * PUBLIC: int __bam_cadjust_read __P((void *, __bam_cadjust_args **));
1036  */
1037 int
__bam_cadjust_read(recbuf,argpp)1038 __bam_cadjust_read(recbuf, argpp)
1039 	void *recbuf;
1040 	__bam_cadjust_args **argpp;
1041 {
1042 	__bam_cadjust_args *argp;
1043 	u_int8_t *bp;
1044 	int ret;
1045 
1046 	ret = __os_malloc(sizeof(__bam_cadjust_args) +
1047 	    sizeof(DB_TXN), NULL, &argp);
1048 	if (ret != 0)
1049 		return (ret);
1050 	argp->txnid = (DB_TXN *)&argp[1];
1051 	bp = recbuf;
1052 	memcpy(&argp->type, bp, sizeof(argp->type));
1053 	bp += sizeof(argp->type);
1054 	memcpy(&argp->txnid->txnid,  bp, sizeof(argp->txnid->txnid));
1055 	bp += sizeof(argp->txnid->txnid);
1056 	memcpy(&argp->prev_lsn, bp, sizeof(DB_LSN));
1057 	bp += sizeof(DB_LSN);
1058 	memcpy(&argp->fileid, bp, sizeof(argp->fileid));
1059 	bp += sizeof(argp->fileid);
1060 	memcpy(&argp->pgno, bp, sizeof(argp->pgno));
1061 	bp += sizeof(argp->pgno);
1062 	memcpy(&argp->lsn, bp,  sizeof(argp->lsn));
1063 	bp += sizeof(argp->lsn);
1064 	memcpy(&argp->indx, bp, sizeof(argp->indx));
1065 	bp += sizeof(argp->indx);
1066 	memcpy(&argp->adjust, bp, sizeof(argp->adjust));
1067 	bp += sizeof(argp->adjust);
1068 	memcpy(&argp->total, bp, sizeof(argp->total));
1069 	bp += sizeof(argp->total);
1070 	*argpp = argp;
1071 	return (0);
1072 }
1073 
1074 /*
1075  * PUBLIC: int __bam_cdel_log
1076  * PUBLIC:     __P((DB_LOG *, DB_TXN *, DB_LSN *, u_int32_t,
1077  * PUBLIC:     u_int32_t, db_pgno_t, DB_LSN *, u_int32_t));
1078  */
__bam_cdel_log(logp,txnid,ret_lsnp,flags,fileid,pgno,lsn,indx)1079 int __bam_cdel_log(logp, txnid, ret_lsnp, flags,
1080 	fileid, pgno, lsn, indx)
1081 	DB_LOG *logp;
1082 	DB_TXN *txnid;
1083 	DB_LSN *ret_lsnp;
1084 	u_int32_t flags;
1085 	u_int32_t fileid;
1086 	db_pgno_t pgno;
1087 	DB_LSN * lsn;
1088 	u_int32_t indx;
1089 {
1090 	DBT logrec;
1091 	DB_LSN *lsnp, null_lsn;
1092 	u_int32_t rectype, txn_num;
1093 	int ret;
1094 	u_int8_t *bp;
1095 
1096 	rectype = DB_bam_cdel;
1097 	txn_num = txnid == NULL ? 0 : txnid->txnid;
1098 	if (txnid == NULL) {
1099 		ZERO_LSN(null_lsn);
1100 		lsnp = &null_lsn;
1101 	} else
1102 		lsnp = &txnid->last_lsn;
1103 	logrec.size = sizeof(rectype) + sizeof(txn_num) + sizeof(DB_LSN)
1104 	    + sizeof(fileid)
1105 	    + sizeof(pgno)
1106 	    + sizeof(*lsn)
1107 	    + sizeof(indx);
1108 	if ((ret = __os_malloc(logrec.size, NULL, &logrec.data)) != 0)
1109 		return (ret);
1110 
1111 	bp = logrec.data;
1112 	memcpy(bp, &rectype, sizeof(rectype));
1113 	bp += sizeof(rectype);
1114 	memcpy(bp, &txn_num, sizeof(txn_num));
1115 	bp += sizeof(txn_num);
1116 	memcpy(bp, lsnp, sizeof(DB_LSN));
1117 	bp += sizeof(DB_LSN);
1118 	memcpy(bp, &fileid, sizeof(fileid));
1119 	bp += sizeof(fileid);
1120 	memcpy(bp, &pgno, sizeof(pgno));
1121 	bp += sizeof(pgno);
1122 	if (lsn != NULL)
1123 		memcpy(bp, lsn, sizeof(*lsn));
1124 	else
1125 		memset(bp, 0, sizeof(*lsn));
1126 	bp += sizeof(*lsn);
1127 	memcpy(bp, &indx, sizeof(indx));
1128 	bp += sizeof(indx);
1129 #ifdef DIAGNOSTIC
1130 	if ((u_int32_t)(bp - (u_int8_t *)logrec.data) != logrec.size)
1131 		fprintf(stderr, "Error in log record length");
1132 #endif
1133 	ret = log_put(logp, ret_lsnp, (DBT *)&logrec, flags);
1134 	if (txnid != NULL)
1135 		txnid->last_lsn = *ret_lsnp;
1136 	__os_free(logrec.data, 0);
1137 	return (ret);
1138 }
1139 
1140 /*
1141  * PUBLIC: int __bam_cdel_print
1142  * PUBLIC:    __P((DB_LOG *, DBT *, DB_LSN *, int, void *));
1143  */
1144 int
__bam_cdel_print(notused1,dbtp,lsnp,notused2,notused3)1145 __bam_cdel_print(notused1, dbtp, lsnp, notused2, notused3)
1146 	DB_LOG *notused1;
1147 	DBT *dbtp;
1148 	DB_LSN *lsnp;
1149 	int notused2;
1150 	void *notused3;
1151 {
1152 	__bam_cdel_args *argp;
1153 	u_int32_t i;
1154 	u_int ch;
1155 	int ret;
1156 
1157 	i = 0;
1158 	ch = 0;
1159 	notused1 = NULL;
1160 	notused2 = 0;
1161 	notused3 = NULL;
1162 
1163 	if ((ret = __bam_cdel_read(dbtp->data, &argp)) != 0)
1164 		return (ret);
1165 	printf("[%lu][%lu]bam_cdel: rec: %lu txnid %lx prevlsn [%lu][%lu]\n",
1166 	    (u_long)lsnp->file,
1167 	    (u_long)lsnp->offset,
1168 	    (u_long)argp->type,
1169 	    (u_long)argp->txnid->txnid,
1170 	    (u_long)argp->prev_lsn.file,
1171 	    (u_long)argp->prev_lsn.offset);
1172 	printf("\tfileid: %lu\n", (u_long)argp->fileid);
1173 	printf("\tpgno: %lu\n", (u_long)argp->pgno);
1174 	printf("\tlsn: [%lu][%lu]\n",
1175 	    (u_long)argp->lsn.file, (u_long)argp->lsn.offset);
1176 	printf("\tindx: %lu\n", (u_long)argp->indx);
1177 	printf("\n");
1178 	__os_free(argp, 0);
1179 	return (0);
1180 }
1181 
1182 /*
1183  * PUBLIC: int __bam_cdel_read __P((void *, __bam_cdel_args **));
1184  */
1185 int
__bam_cdel_read(recbuf,argpp)1186 __bam_cdel_read(recbuf, argpp)
1187 	void *recbuf;
1188 	__bam_cdel_args **argpp;
1189 {
1190 	__bam_cdel_args *argp;
1191 	u_int8_t *bp;
1192 	int ret;
1193 
1194 	ret = __os_malloc(sizeof(__bam_cdel_args) +
1195 	    sizeof(DB_TXN), NULL, &argp);
1196 	if (ret != 0)
1197 		return (ret);
1198 	argp->txnid = (DB_TXN *)&argp[1];
1199 	bp = recbuf;
1200 	memcpy(&argp->type, bp, sizeof(argp->type));
1201 	bp += sizeof(argp->type);
1202 	memcpy(&argp->txnid->txnid,  bp, sizeof(argp->txnid->txnid));
1203 	bp += sizeof(argp->txnid->txnid);
1204 	memcpy(&argp->prev_lsn, bp, sizeof(DB_LSN));
1205 	bp += sizeof(DB_LSN);
1206 	memcpy(&argp->fileid, bp, sizeof(argp->fileid));
1207 	bp += sizeof(argp->fileid);
1208 	memcpy(&argp->pgno, bp, sizeof(argp->pgno));
1209 	bp += sizeof(argp->pgno);
1210 	memcpy(&argp->lsn, bp,  sizeof(argp->lsn));
1211 	bp += sizeof(argp->lsn);
1212 	memcpy(&argp->indx, bp, sizeof(argp->indx));
1213 	bp += sizeof(argp->indx);
1214 	*argpp = argp;
1215 	return (0);
1216 }
1217 
1218 /*
1219  * PUBLIC: int __bam_repl_log
1220  * PUBLIC:     __P((DB_LOG *, DB_TXN *, DB_LSN *, u_int32_t,
1221  * PUBLIC:     u_int32_t, db_pgno_t, DB_LSN *, u_int32_t,
1222  * PUBLIC:     u_int32_t, const DBT *, const DBT *, u_int32_t,
1223  * PUBLIC:     u_int32_t));
1224  */
__bam_repl_log(logp,txnid,ret_lsnp,flags,fileid,pgno,lsn,indx,isdeleted,orig,repl,prefix,suffix)1225 int __bam_repl_log(logp, txnid, ret_lsnp, flags,
1226 	fileid, pgno, lsn, indx, isdeleted, orig,
1227 	repl, prefix, suffix)
1228 	DB_LOG *logp;
1229 	DB_TXN *txnid;
1230 	DB_LSN *ret_lsnp;
1231 	u_int32_t flags;
1232 	u_int32_t fileid;
1233 	db_pgno_t pgno;
1234 	DB_LSN * lsn;
1235 	u_int32_t indx;
1236 	u_int32_t isdeleted;
1237 	const DBT *orig;
1238 	const DBT *repl;
1239 	u_int32_t prefix;
1240 	u_int32_t suffix;
1241 {
1242 	DBT logrec;
1243 	DB_LSN *lsnp, null_lsn;
1244 	u_int32_t zero;
1245 	u_int32_t rectype, txn_num;
1246 	int ret;
1247 	u_int8_t *bp;
1248 
1249 	rectype = DB_bam_repl;
1250 	txn_num = txnid == NULL ? 0 : txnid->txnid;
1251 	if (txnid == NULL) {
1252 		ZERO_LSN(null_lsn);
1253 		lsnp = &null_lsn;
1254 	} else
1255 		lsnp = &txnid->last_lsn;
1256 	logrec.size = sizeof(rectype) + sizeof(txn_num) + sizeof(DB_LSN)
1257 	    + sizeof(fileid)
1258 	    + sizeof(pgno)
1259 	    + sizeof(*lsn)
1260 	    + sizeof(indx)
1261 	    + sizeof(isdeleted)
1262 	    + sizeof(u_int32_t) + (orig == NULL ? 0 : orig->size)
1263 	    + sizeof(u_int32_t) + (repl == NULL ? 0 : repl->size)
1264 	    + sizeof(prefix)
1265 	    + sizeof(suffix);
1266 	if ((ret = __os_malloc(logrec.size, NULL, &logrec.data)) != 0)
1267 		return (ret);
1268 
1269 	bp = logrec.data;
1270 	memcpy(bp, &rectype, sizeof(rectype));
1271 	bp += sizeof(rectype);
1272 	memcpy(bp, &txn_num, sizeof(txn_num));
1273 	bp += sizeof(txn_num);
1274 	memcpy(bp, lsnp, sizeof(DB_LSN));
1275 	bp += sizeof(DB_LSN);
1276 	memcpy(bp, &fileid, sizeof(fileid));
1277 	bp += sizeof(fileid);
1278 	memcpy(bp, &pgno, sizeof(pgno));
1279 	bp += sizeof(pgno);
1280 	if (lsn != NULL)
1281 		memcpy(bp, lsn, sizeof(*lsn));
1282 	else
1283 		memset(bp, 0, sizeof(*lsn));
1284 	bp += sizeof(*lsn);
1285 	memcpy(bp, &indx, sizeof(indx));
1286 	bp += sizeof(indx);
1287 	memcpy(bp, &isdeleted, sizeof(isdeleted));
1288 	bp += sizeof(isdeleted);
1289 	if (orig == NULL) {
1290 		zero = 0;
1291 		memcpy(bp, &zero, sizeof(u_int32_t));
1292 		bp += sizeof(u_int32_t);
1293 	} else {
1294 		memcpy(bp, &orig->size, sizeof(orig->size));
1295 		bp += sizeof(orig->size);
1296 		memcpy(bp, orig->data, orig->size);
1297 		bp += orig->size;
1298 	}
1299 	if (repl == NULL) {
1300 		zero = 0;
1301 		memcpy(bp, &zero, sizeof(u_int32_t));
1302 		bp += sizeof(u_int32_t);
1303 	} else {
1304 		memcpy(bp, &repl->size, sizeof(repl->size));
1305 		bp += sizeof(repl->size);
1306 		memcpy(bp, repl->data, repl->size);
1307 		bp += repl->size;
1308 	}
1309 	memcpy(bp, &prefix, sizeof(prefix));
1310 	bp += sizeof(prefix);
1311 	memcpy(bp, &suffix, sizeof(suffix));
1312 	bp += sizeof(suffix);
1313 #ifdef DIAGNOSTIC
1314 	if ((u_int32_t)(bp - (u_int8_t *)logrec.data) != logrec.size)
1315 		fprintf(stderr, "Error in log record length");
1316 #endif
1317 	ret = log_put(logp, ret_lsnp, (DBT *)&logrec, flags);
1318 	if (txnid != NULL)
1319 		txnid->last_lsn = *ret_lsnp;
1320 	__os_free(logrec.data, 0);
1321 	return (ret);
1322 }
1323 
1324 /*
1325  * PUBLIC: int __bam_repl_print
1326  * PUBLIC:    __P((DB_LOG *, DBT *, DB_LSN *, int, void *));
1327  */
1328 int
__bam_repl_print(notused1,dbtp,lsnp,notused2,notused3)1329 __bam_repl_print(notused1, dbtp, lsnp, notused2, notused3)
1330 	DB_LOG *notused1;
1331 	DBT *dbtp;
1332 	DB_LSN *lsnp;
1333 	int notused2;
1334 	void *notused3;
1335 {
1336 	__bam_repl_args *argp;
1337 	u_int32_t i;
1338 	u_int ch;
1339 	int ret;
1340 
1341 	i = 0;
1342 	ch = 0;
1343 	notused1 = NULL;
1344 	notused2 = 0;
1345 	notused3 = NULL;
1346 
1347 	if ((ret = __bam_repl_read(dbtp->data, &argp)) != 0)
1348 		return (ret);
1349 	printf("[%lu][%lu]bam_repl: rec: %lu txnid %lx prevlsn [%lu][%lu]\n",
1350 	    (u_long)lsnp->file,
1351 	    (u_long)lsnp->offset,
1352 	    (u_long)argp->type,
1353 	    (u_long)argp->txnid->txnid,
1354 	    (u_long)argp->prev_lsn.file,
1355 	    (u_long)argp->prev_lsn.offset);
1356 	printf("\tfileid: %lu\n", (u_long)argp->fileid);
1357 	printf("\tpgno: %lu\n", (u_long)argp->pgno);
1358 	printf("\tlsn: [%lu][%lu]\n",
1359 	    (u_long)argp->lsn.file, (u_long)argp->lsn.offset);
1360 	printf("\tindx: %lu\n", (u_long)argp->indx);
1361 	printf("\tisdeleted: %lu\n", (u_long)argp->isdeleted);
1362 	printf("\torig: ");
1363 	for (i = 0; i < argp->orig.size; i++) {
1364 		ch = ((u_int8_t *)argp->orig.data)[i];
1365 		if (isprint(ch) || ch == 0xa)
1366 			putchar(ch);
1367 		else
1368 			printf("%#x ", ch);
1369 	}
1370 	printf("\n");
1371 	printf("\trepl: ");
1372 	for (i = 0; i < argp->repl.size; i++) {
1373 		ch = ((u_int8_t *)argp->repl.data)[i];
1374 		if (isprint(ch) || ch == 0xa)
1375 			putchar(ch);
1376 		else
1377 			printf("%#x ", ch);
1378 	}
1379 	printf("\n");
1380 	printf("\tprefix: %lu\n", (u_long)argp->prefix);
1381 	printf("\tsuffix: %lu\n", (u_long)argp->suffix);
1382 	printf("\n");
1383 	__os_free(argp, 0);
1384 	return (0);
1385 }
1386 
1387 /*
1388  * PUBLIC: int __bam_repl_read __P((void *, __bam_repl_args **));
1389  */
1390 int
__bam_repl_read(recbuf,argpp)1391 __bam_repl_read(recbuf, argpp)
1392 	void *recbuf;
1393 	__bam_repl_args **argpp;
1394 {
1395 	__bam_repl_args *argp;
1396 	u_int8_t *bp;
1397 	int ret;
1398 
1399 	ret = __os_malloc(sizeof(__bam_repl_args) +
1400 	    sizeof(DB_TXN), NULL, &argp);
1401 	if (ret != 0)
1402 		return (ret);
1403 	argp->txnid = (DB_TXN *)&argp[1];
1404 	bp = recbuf;
1405 	memcpy(&argp->type, bp, sizeof(argp->type));
1406 	bp += sizeof(argp->type);
1407 	memcpy(&argp->txnid->txnid,  bp, sizeof(argp->txnid->txnid));
1408 	bp += sizeof(argp->txnid->txnid);
1409 	memcpy(&argp->prev_lsn, bp, sizeof(DB_LSN));
1410 	bp += sizeof(DB_LSN);
1411 	memcpy(&argp->fileid, bp, sizeof(argp->fileid));
1412 	bp += sizeof(argp->fileid);
1413 	memcpy(&argp->pgno, bp, sizeof(argp->pgno));
1414 	bp += sizeof(argp->pgno);
1415 	memcpy(&argp->lsn, bp,  sizeof(argp->lsn));
1416 	bp += sizeof(argp->lsn);
1417 	memcpy(&argp->indx, bp, sizeof(argp->indx));
1418 	bp += sizeof(argp->indx);
1419 	memcpy(&argp->isdeleted, bp, sizeof(argp->isdeleted));
1420 	bp += sizeof(argp->isdeleted);
1421 	memcpy(&argp->orig.size, bp, sizeof(u_int32_t));
1422 	bp += sizeof(u_int32_t);
1423 	argp->orig.data = bp;
1424 	bp += argp->orig.size;
1425 	memcpy(&argp->repl.size, bp, sizeof(u_int32_t));
1426 	bp += sizeof(u_int32_t);
1427 	argp->repl.data = bp;
1428 	bp += argp->repl.size;
1429 	memcpy(&argp->prefix, bp, sizeof(argp->prefix));
1430 	bp += sizeof(argp->prefix);
1431 	memcpy(&argp->suffix, bp, sizeof(argp->suffix));
1432 	bp += sizeof(argp->suffix);
1433 	*argpp = argp;
1434 	return (0);
1435 }
1436 
1437 /*
1438  * PUBLIC: int __bam_init_print __P((DB_ENV *));
1439  */
1440 int
__bam_init_print(dbenv)1441 __bam_init_print(dbenv)
1442 	DB_ENV *dbenv;
1443 {
1444 	int ret;
1445 
1446 	if ((ret = __db_add_recovery(dbenv,
1447 	    __bam_pg_alloc_print, DB_bam_pg_alloc)) != 0)
1448 		return (ret);
1449 	if ((ret = __db_add_recovery(dbenv,
1450 	    __bam_pg_free_print, DB_bam_pg_free)) != 0)
1451 		return (ret);
1452 	if ((ret = __db_add_recovery(dbenv,
1453 	    __bam_split_print, DB_bam_split)) != 0)
1454 		return (ret);
1455 	if ((ret = __db_add_recovery(dbenv,
1456 	    __bam_rsplit_print, DB_bam_rsplit)) != 0)
1457 		return (ret);
1458 	if ((ret = __db_add_recovery(dbenv,
1459 	    __bam_adj_print, DB_bam_adj)) != 0)
1460 		return (ret);
1461 	if ((ret = __db_add_recovery(dbenv,
1462 	    __bam_cadjust_print, DB_bam_cadjust)) != 0)
1463 		return (ret);
1464 	if ((ret = __db_add_recovery(dbenv,
1465 	    __bam_cdel_print, DB_bam_cdel)) != 0)
1466 		return (ret);
1467 	if ((ret = __db_add_recovery(dbenv,
1468 	    __bam_repl_print, DB_bam_repl)) != 0)
1469 		return (ret);
1470 	return (0);
1471 }
1472 
1473 /*
1474  * PUBLIC: int __bam_init_recover __P((DB_ENV *));
1475  */
1476 int
__bam_init_recover(dbenv)1477 __bam_init_recover(dbenv)
1478 	DB_ENV *dbenv;
1479 {
1480 	int ret;
1481 
1482 	if ((ret = __db_add_recovery(dbenv,
1483 	    __bam_pg_alloc_recover, DB_bam_pg_alloc)) != 0)
1484 		return (ret);
1485 	if ((ret = __db_add_recovery(dbenv,
1486 	    __bam_pg_free_recover, DB_bam_pg_free)) != 0)
1487 		return (ret);
1488 	if ((ret = __db_add_recovery(dbenv,
1489 	    __bam_split_recover, DB_bam_split)) != 0)
1490 		return (ret);
1491 	if ((ret = __db_add_recovery(dbenv,
1492 	    __bam_rsplit_recover, DB_bam_rsplit)) != 0)
1493 		return (ret);
1494 	if ((ret = __db_add_recovery(dbenv,
1495 	    __bam_adj_recover, DB_bam_adj)) != 0)
1496 		return (ret);
1497 	if ((ret = __db_add_recovery(dbenv,
1498 	    __bam_cadjust_recover, DB_bam_cadjust)) != 0)
1499 		return (ret);
1500 	if ((ret = __db_add_recovery(dbenv,
1501 	    __bam_cdel_recover, DB_bam_cdel)) != 0)
1502 		return (ret);
1503 	if ((ret = __db_add_recovery(dbenv,
1504 	    __bam_repl_recover, DB_bam_repl)) != 0)
1505 		return (ret);
1506 	return (0);
1507 }
1508 
1509