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