1*7c478bd9Sstevel@tonic-gate /* Do not edit: automatically built by dist/db_gen.sh. */
2*7c478bd9Sstevel@tonic-gate #include "config.h"
3*7c478bd9Sstevel@tonic-gate 
4*7c478bd9Sstevel@tonic-gate #ifndef NO_SYSTEM_INCLUDES
5*7c478bd9Sstevel@tonic-gate #include <ctype.h>
6*7c478bd9Sstevel@tonic-gate #include <errno.h>
7*7c478bd9Sstevel@tonic-gate #include <stddef.h>
8*7c478bd9Sstevel@tonic-gate #include <stdlib.h>
9*7c478bd9Sstevel@tonic-gate #include <string.h>
10*7c478bd9Sstevel@tonic-gate #endif
11*7c478bd9Sstevel@tonic-gate 
12*7c478bd9Sstevel@tonic-gate #include "db_int.h"
13*7c478bd9Sstevel@tonic-gate #include "db_page.h"
14*7c478bd9Sstevel@tonic-gate #include "db_dispatch.h"
15*7c478bd9Sstevel@tonic-gate #include "hash.h"
16*7c478bd9Sstevel@tonic-gate #include "db_am.h"
17*7c478bd9Sstevel@tonic-gate /*
18*7c478bd9Sstevel@tonic-gate  * PUBLIC: int __ham_insdel_log
19*7c478bd9Sstevel@tonic-gate  * PUBLIC:     __P((DB_LOG *, DB_TXN *, DB_LSN *, u_int32_t,
20*7c478bd9Sstevel@tonic-gate  * PUBLIC:     u_int32_t, u_int32_t, db_pgno_t, u_int32_t,
21*7c478bd9Sstevel@tonic-gate  * PUBLIC:     DB_LSN *, const DBT *, const DBT *));
22*7c478bd9Sstevel@tonic-gate  */
__ham_insdel_log(logp,txnid,ret_lsnp,flags,opcode,fileid,pgno,ndx,pagelsn,key,data)23*7c478bd9Sstevel@tonic-gate int __ham_insdel_log(logp, txnid, ret_lsnp, flags,
24*7c478bd9Sstevel@tonic-gate 	opcode, fileid, pgno, ndx, pagelsn, key,
25*7c478bd9Sstevel@tonic-gate 	data)
26*7c478bd9Sstevel@tonic-gate 	DB_LOG *logp;
27*7c478bd9Sstevel@tonic-gate 	DB_TXN *txnid;
28*7c478bd9Sstevel@tonic-gate 	DB_LSN *ret_lsnp;
29*7c478bd9Sstevel@tonic-gate 	u_int32_t flags;
30*7c478bd9Sstevel@tonic-gate 	u_int32_t opcode;
31*7c478bd9Sstevel@tonic-gate 	u_int32_t fileid;
32*7c478bd9Sstevel@tonic-gate 	db_pgno_t pgno;
33*7c478bd9Sstevel@tonic-gate 	u_int32_t ndx;
34*7c478bd9Sstevel@tonic-gate 	DB_LSN * pagelsn;
35*7c478bd9Sstevel@tonic-gate 	const DBT *key;
36*7c478bd9Sstevel@tonic-gate 	const DBT *data;
37*7c478bd9Sstevel@tonic-gate {
38*7c478bd9Sstevel@tonic-gate 	DBT logrec;
39*7c478bd9Sstevel@tonic-gate 	DB_LSN *lsnp, null_lsn;
40*7c478bd9Sstevel@tonic-gate 	u_int32_t zero;
41*7c478bd9Sstevel@tonic-gate 	u_int32_t rectype, txn_num;
42*7c478bd9Sstevel@tonic-gate 	int ret;
43*7c478bd9Sstevel@tonic-gate 	u_int8_t *bp;
44*7c478bd9Sstevel@tonic-gate 
45*7c478bd9Sstevel@tonic-gate 	rectype = DB_ham_insdel;
46*7c478bd9Sstevel@tonic-gate 	txn_num = txnid == NULL ? 0 : txnid->txnid;
47*7c478bd9Sstevel@tonic-gate 	if (txnid == NULL) {
48*7c478bd9Sstevel@tonic-gate 		ZERO_LSN(null_lsn);
49*7c478bd9Sstevel@tonic-gate 		lsnp = &null_lsn;
50*7c478bd9Sstevel@tonic-gate 	} else
51*7c478bd9Sstevel@tonic-gate 		lsnp = &txnid->last_lsn;
52*7c478bd9Sstevel@tonic-gate 	logrec.size = sizeof(rectype) + sizeof(txn_num) + sizeof(DB_LSN)
53*7c478bd9Sstevel@tonic-gate 	    + sizeof(opcode)
54*7c478bd9Sstevel@tonic-gate 	    + sizeof(fileid)
55*7c478bd9Sstevel@tonic-gate 	    + sizeof(pgno)
56*7c478bd9Sstevel@tonic-gate 	    + sizeof(ndx)
57*7c478bd9Sstevel@tonic-gate 	    + sizeof(*pagelsn)
58*7c478bd9Sstevel@tonic-gate 	    + sizeof(u_int32_t) + (key == NULL ? 0 : key->size)
59*7c478bd9Sstevel@tonic-gate 	    + sizeof(u_int32_t) + (data == NULL ? 0 : data->size);
60*7c478bd9Sstevel@tonic-gate 	if ((ret = __os_malloc(logrec.size, NULL, &logrec.data)) != 0)
61*7c478bd9Sstevel@tonic-gate 		return (ret);
62*7c478bd9Sstevel@tonic-gate 
63*7c478bd9Sstevel@tonic-gate 	bp = logrec.data;
64*7c478bd9Sstevel@tonic-gate 	memcpy(bp, &rectype, sizeof(rectype));
65*7c478bd9Sstevel@tonic-gate 	bp += sizeof(rectype);
66*7c478bd9Sstevel@tonic-gate 	memcpy(bp, &txn_num, sizeof(txn_num));
67*7c478bd9Sstevel@tonic-gate 	bp += sizeof(txn_num);
68*7c478bd9Sstevel@tonic-gate 	memcpy(bp, lsnp, sizeof(DB_LSN));
69*7c478bd9Sstevel@tonic-gate 	bp += sizeof(DB_LSN);
70*7c478bd9Sstevel@tonic-gate 	memcpy(bp, &opcode, sizeof(opcode));
71*7c478bd9Sstevel@tonic-gate 	bp += sizeof(opcode);
72*7c478bd9Sstevel@tonic-gate 	memcpy(bp, &fileid, sizeof(fileid));
73*7c478bd9Sstevel@tonic-gate 	bp += sizeof(fileid);
74*7c478bd9Sstevel@tonic-gate 	memcpy(bp, &pgno, sizeof(pgno));
75*7c478bd9Sstevel@tonic-gate 	bp += sizeof(pgno);
76*7c478bd9Sstevel@tonic-gate 	memcpy(bp, &ndx, sizeof(ndx));
77*7c478bd9Sstevel@tonic-gate 	bp += sizeof(ndx);
78*7c478bd9Sstevel@tonic-gate 	if (pagelsn != NULL)
79*7c478bd9Sstevel@tonic-gate 		memcpy(bp, pagelsn, sizeof(*pagelsn));
80*7c478bd9Sstevel@tonic-gate 	else
81*7c478bd9Sstevel@tonic-gate 		memset(bp, 0, sizeof(*pagelsn));
82*7c478bd9Sstevel@tonic-gate 	bp += sizeof(*pagelsn);
83*7c478bd9Sstevel@tonic-gate 	if (key == NULL) {
84*7c478bd9Sstevel@tonic-gate 		zero = 0;
85*7c478bd9Sstevel@tonic-gate 		memcpy(bp, &zero, sizeof(u_int32_t));
86*7c478bd9Sstevel@tonic-gate 		bp += sizeof(u_int32_t);
87*7c478bd9Sstevel@tonic-gate 	} else {
88*7c478bd9Sstevel@tonic-gate 		memcpy(bp, &key->size, sizeof(key->size));
89*7c478bd9Sstevel@tonic-gate 		bp += sizeof(key->size);
90*7c478bd9Sstevel@tonic-gate 		memcpy(bp, key->data, key->size);
91*7c478bd9Sstevel@tonic-gate 		bp += key->size;
92*7c478bd9Sstevel@tonic-gate 	}
93*7c478bd9Sstevel@tonic-gate 	if (data == NULL) {
94*7c478bd9Sstevel@tonic-gate 		zero = 0;
95*7c478bd9Sstevel@tonic-gate 		memcpy(bp, &zero, sizeof(u_int32_t));
96*7c478bd9Sstevel@tonic-gate 		bp += sizeof(u_int32_t);
97*7c478bd9Sstevel@tonic-gate 	} else {
98*7c478bd9Sstevel@tonic-gate 		memcpy(bp, &data->size, sizeof(data->size));
99*7c478bd9Sstevel@tonic-gate 		bp += sizeof(data->size);
100*7c478bd9Sstevel@tonic-gate 		memcpy(bp, data->data, data->size);
101*7c478bd9Sstevel@tonic-gate 		bp += data->size;
102*7c478bd9Sstevel@tonic-gate 	}
103*7c478bd9Sstevel@tonic-gate #ifdef DIAGNOSTIC
104*7c478bd9Sstevel@tonic-gate 	if ((u_int32_t)(bp - (u_int8_t *)logrec.data) != logrec.size)
105*7c478bd9Sstevel@tonic-gate 		fprintf(stderr, "Error in log record length");
106*7c478bd9Sstevel@tonic-gate #endif
107*7c478bd9Sstevel@tonic-gate 	ret = log_put(logp, ret_lsnp, (DBT *)&logrec, flags);
108*7c478bd9Sstevel@tonic-gate 	if (txnid != NULL)
109*7c478bd9Sstevel@tonic-gate 		txnid->last_lsn = *ret_lsnp;
110*7c478bd9Sstevel@tonic-gate 	__os_free(logrec.data, 0);
111*7c478bd9Sstevel@tonic-gate 	return (ret);
112*7c478bd9Sstevel@tonic-gate }
113*7c478bd9Sstevel@tonic-gate 
114*7c478bd9Sstevel@tonic-gate /*
115*7c478bd9Sstevel@tonic-gate  * PUBLIC: int __ham_insdel_print
116*7c478bd9Sstevel@tonic-gate  * PUBLIC:    __P((DB_LOG *, DBT *, DB_LSN *, int, void *));
117*7c478bd9Sstevel@tonic-gate  */
118*7c478bd9Sstevel@tonic-gate int
__ham_insdel_print(notused1,dbtp,lsnp,notused2,notused3)119*7c478bd9Sstevel@tonic-gate __ham_insdel_print(notused1, dbtp, lsnp, notused2, notused3)
120*7c478bd9Sstevel@tonic-gate 	DB_LOG *notused1;
121*7c478bd9Sstevel@tonic-gate 	DBT *dbtp;
122*7c478bd9Sstevel@tonic-gate 	DB_LSN *lsnp;
123*7c478bd9Sstevel@tonic-gate 	int notused2;
124*7c478bd9Sstevel@tonic-gate 	void *notused3;
125*7c478bd9Sstevel@tonic-gate {
126*7c478bd9Sstevel@tonic-gate 	__ham_insdel_args *argp;
127*7c478bd9Sstevel@tonic-gate 	u_int32_t i;
128*7c478bd9Sstevel@tonic-gate 	u_int ch;
129*7c478bd9Sstevel@tonic-gate 	int ret;
130*7c478bd9Sstevel@tonic-gate 
131*7c478bd9Sstevel@tonic-gate 	i = 0;
132*7c478bd9Sstevel@tonic-gate 	ch = 0;
133*7c478bd9Sstevel@tonic-gate 	notused1 = NULL;
134*7c478bd9Sstevel@tonic-gate 	notused2 = 0;
135*7c478bd9Sstevel@tonic-gate 	notused3 = NULL;
136*7c478bd9Sstevel@tonic-gate 
137*7c478bd9Sstevel@tonic-gate 	if ((ret = __ham_insdel_read(dbtp->data, &argp)) != 0)
138*7c478bd9Sstevel@tonic-gate 		return (ret);
139*7c478bd9Sstevel@tonic-gate 	printf("[%lu][%lu]ham_insdel: rec: %lu txnid %lx prevlsn [%lu][%lu]\n",
140*7c478bd9Sstevel@tonic-gate 	    (u_long)lsnp->file,
141*7c478bd9Sstevel@tonic-gate 	    (u_long)lsnp->offset,
142*7c478bd9Sstevel@tonic-gate 	    (u_long)argp->type,
143*7c478bd9Sstevel@tonic-gate 	    (u_long)argp->txnid->txnid,
144*7c478bd9Sstevel@tonic-gate 	    (u_long)argp->prev_lsn.file,
145*7c478bd9Sstevel@tonic-gate 	    (u_long)argp->prev_lsn.offset);
146*7c478bd9Sstevel@tonic-gate 	printf("\topcode: %lu\n", (u_long)argp->opcode);
147*7c478bd9Sstevel@tonic-gate 	printf("\tfileid: %lu\n", (u_long)argp->fileid);
148*7c478bd9Sstevel@tonic-gate 	printf("\tpgno: %lu\n", (u_long)argp->pgno);
149*7c478bd9Sstevel@tonic-gate 	printf("\tndx: %lu\n", (u_long)argp->ndx);
150*7c478bd9Sstevel@tonic-gate 	printf("\tpagelsn: [%lu][%lu]\n",
151*7c478bd9Sstevel@tonic-gate 	    (u_long)argp->pagelsn.file, (u_long)argp->pagelsn.offset);
152*7c478bd9Sstevel@tonic-gate 	printf("\tkey: ");
153*7c478bd9Sstevel@tonic-gate 	for (i = 0; i < argp->key.size; i++) {
154*7c478bd9Sstevel@tonic-gate 		ch = ((u_int8_t *)argp->key.data)[i];
155*7c478bd9Sstevel@tonic-gate 		if (isprint(ch) || ch == 0xa)
156*7c478bd9Sstevel@tonic-gate 			putchar(ch);
157*7c478bd9Sstevel@tonic-gate 		else
158*7c478bd9Sstevel@tonic-gate 			printf("%#x ", ch);
159*7c478bd9Sstevel@tonic-gate 	}
160*7c478bd9Sstevel@tonic-gate 	printf("\n");
161*7c478bd9Sstevel@tonic-gate 	printf("\tdata: ");
162*7c478bd9Sstevel@tonic-gate 	for (i = 0; i < argp->data.size; i++) {
163*7c478bd9Sstevel@tonic-gate 		ch = ((u_int8_t *)argp->data.data)[i];
164*7c478bd9Sstevel@tonic-gate 		if (isprint(ch) || ch == 0xa)
165*7c478bd9Sstevel@tonic-gate 			putchar(ch);
166*7c478bd9Sstevel@tonic-gate 		else
167*7c478bd9Sstevel@tonic-gate 			printf("%#x ", ch);
168*7c478bd9Sstevel@tonic-gate 	}
169*7c478bd9Sstevel@tonic-gate 	printf("\n");
170*7c478bd9Sstevel@tonic-gate 	printf("\n");
171*7c478bd9Sstevel@tonic-gate 	__os_free(argp, 0);
172*7c478bd9Sstevel@tonic-gate 	return (0);
173*7c478bd9Sstevel@tonic-gate }
174*7c478bd9Sstevel@tonic-gate 
175*7c478bd9Sstevel@tonic-gate /*
176*7c478bd9Sstevel@tonic-gate  * PUBLIC: int __ham_insdel_read __P((void *, __ham_insdel_args **));
177*7c478bd9Sstevel@tonic-gate  */
178*7c478bd9Sstevel@tonic-gate int
__ham_insdel_read(recbuf,argpp)179*7c478bd9Sstevel@tonic-gate __ham_insdel_read(recbuf, argpp)
180*7c478bd9Sstevel@tonic-gate 	void *recbuf;
181*7c478bd9Sstevel@tonic-gate 	__ham_insdel_args **argpp;
182*7c478bd9Sstevel@tonic-gate {
183*7c478bd9Sstevel@tonic-gate 	__ham_insdel_args *argp;
184*7c478bd9Sstevel@tonic-gate 	u_int8_t *bp;
185*7c478bd9Sstevel@tonic-gate 	int ret;
186*7c478bd9Sstevel@tonic-gate 
187*7c478bd9Sstevel@tonic-gate 	ret = __os_malloc(sizeof(__ham_insdel_args) +
188*7c478bd9Sstevel@tonic-gate 	    sizeof(DB_TXN), NULL, &argp);
189*7c478bd9Sstevel@tonic-gate 	if (ret != 0)
190*7c478bd9Sstevel@tonic-gate 		return (ret);
191*7c478bd9Sstevel@tonic-gate 	argp->txnid = (DB_TXN *)&argp[1];
192*7c478bd9Sstevel@tonic-gate 	bp = recbuf;
193*7c478bd9Sstevel@tonic-gate 	memcpy(&argp->type, bp, sizeof(argp->type));
194*7c478bd9Sstevel@tonic-gate 	bp += sizeof(argp->type);
195*7c478bd9Sstevel@tonic-gate 	memcpy(&argp->txnid->txnid,  bp, sizeof(argp->txnid->txnid));
196*7c478bd9Sstevel@tonic-gate 	bp += sizeof(argp->txnid->txnid);
197*7c478bd9Sstevel@tonic-gate 	memcpy(&argp->prev_lsn, bp, sizeof(DB_LSN));
198*7c478bd9Sstevel@tonic-gate 	bp += sizeof(DB_LSN);
199*7c478bd9Sstevel@tonic-gate 	memcpy(&argp->opcode, bp, sizeof(argp->opcode));
200*7c478bd9Sstevel@tonic-gate 	bp += sizeof(argp->opcode);
201*7c478bd9Sstevel@tonic-gate 	memcpy(&argp->fileid, bp, sizeof(argp->fileid));
202*7c478bd9Sstevel@tonic-gate 	bp += sizeof(argp->fileid);
203*7c478bd9Sstevel@tonic-gate 	memcpy(&argp->pgno, bp, sizeof(argp->pgno));
204*7c478bd9Sstevel@tonic-gate 	bp += sizeof(argp->pgno);
205*7c478bd9Sstevel@tonic-gate 	memcpy(&argp->ndx, bp, sizeof(argp->ndx));
206*7c478bd9Sstevel@tonic-gate 	bp += sizeof(argp->ndx);
207*7c478bd9Sstevel@tonic-gate 	memcpy(&argp->pagelsn, bp,  sizeof(argp->pagelsn));
208*7c478bd9Sstevel@tonic-gate 	bp += sizeof(argp->pagelsn);
209*7c478bd9Sstevel@tonic-gate 	memcpy(&argp->key.size, bp, sizeof(u_int32_t));
210*7c478bd9Sstevel@tonic-gate 	bp += sizeof(u_int32_t);
211*7c478bd9Sstevel@tonic-gate 	argp->key.data = bp;
212*7c478bd9Sstevel@tonic-gate 	bp += argp->key.size;
213*7c478bd9Sstevel@tonic-gate 	memcpy(&argp->data.size, bp, sizeof(u_int32_t));
214*7c478bd9Sstevel@tonic-gate 	bp += sizeof(u_int32_t);
215*7c478bd9Sstevel@tonic-gate 	argp->data.data = bp;
216*7c478bd9Sstevel@tonic-gate 	bp += argp->data.size;
217*7c478bd9Sstevel@tonic-gate 	*argpp = argp;
218*7c478bd9Sstevel@tonic-gate 	return (0);
219*7c478bd9Sstevel@tonic-gate }
220*7c478bd9Sstevel@tonic-gate 
221*7c478bd9Sstevel@tonic-gate /*
222*7c478bd9Sstevel@tonic-gate  * PUBLIC: int __ham_newpage_log
223*7c478bd9Sstevel@tonic-gate  * PUBLIC:     __P((DB_LOG *, DB_TXN *, DB_LSN *, u_int32_t,
224*7c478bd9Sstevel@tonic-gate  * PUBLIC:     u_int32_t, u_int32_t, db_pgno_t, DB_LSN *,
225*7c478bd9Sstevel@tonic-gate  * PUBLIC:     db_pgno_t, DB_LSN *, db_pgno_t, DB_LSN *));
226*7c478bd9Sstevel@tonic-gate  */
__ham_newpage_log(logp,txnid,ret_lsnp,flags,opcode,fileid,prev_pgno,prevlsn,new_pgno,pagelsn,next_pgno,nextlsn)227*7c478bd9Sstevel@tonic-gate int __ham_newpage_log(logp, txnid, ret_lsnp, flags,
228*7c478bd9Sstevel@tonic-gate 	opcode, fileid, prev_pgno, prevlsn, new_pgno, pagelsn,
229*7c478bd9Sstevel@tonic-gate 	next_pgno, nextlsn)
230*7c478bd9Sstevel@tonic-gate 	DB_LOG *logp;
231*7c478bd9Sstevel@tonic-gate 	DB_TXN *txnid;
232*7c478bd9Sstevel@tonic-gate 	DB_LSN *ret_lsnp;
233*7c478bd9Sstevel@tonic-gate 	u_int32_t flags;
234*7c478bd9Sstevel@tonic-gate 	u_int32_t opcode;
235*7c478bd9Sstevel@tonic-gate 	u_int32_t fileid;
236*7c478bd9Sstevel@tonic-gate 	db_pgno_t prev_pgno;
237*7c478bd9Sstevel@tonic-gate 	DB_LSN * prevlsn;
238*7c478bd9Sstevel@tonic-gate 	db_pgno_t new_pgno;
239*7c478bd9Sstevel@tonic-gate 	DB_LSN * pagelsn;
240*7c478bd9Sstevel@tonic-gate 	db_pgno_t next_pgno;
241*7c478bd9Sstevel@tonic-gate 	DB_LSN * nextlsn;
242*7c478bd9Sstevel@tonic-gate {
243*7c478bd9Sstevel@tonic-gate 	DBT logrec;
244*7c478bd9Sstevel@tonic-gate 	DB_LSN *lsnp, null_lsn;
245*7c478bd9Sstevel@tonic-gate 	u_int32_t rectype, txn_num;
246*7c478bd9Sstevel@tonic-gate 	int ret;
247*7c478bd9Sstevel@tonic-gate 	u_int8_t *bp;
248*7c478bd9Sstevel@tonic-gate 
249*7c478bd9Sstevel@tonic-gate 	rectype = DB_ham_newpage;
250*7c478bd9Sstevel@tonic-gate 	txn_num = txnid == NULL ? 0 : txnid->txnid;
251*7c478bd9Sstevel@tonic-gate 	if (txnid == NULL) {
252*7c478bd9Sstevel@tonic-gate 		ZERO_LSN(null_lsn);
253*7c478bd9Sstevel@tonic-gate 		lsnp = &null_lsn;
254*7c478bd9Sstevel@tonic-gate 	} else
255*7c478bd9Sstevel@tonic-gate 		lsnp = &txnid->last_lsn;
256*7c478bd9Sstevel@tonic-gate 	logrec.size = sizeof(rectype) + sizeof(txn_num) + sizeof(DB_LSN)
257*7c478bd9Sstevel@tonic-gate 	    + sizeof(opcode)
258*7c478bd9Sstevel@tonic-gate 	    + sizeof(fileid)
259*7c478bd9Sstevel@tonic-gate 	    + sizeof(prev_pgno)
260*7c478bd9Sstevel@tonic-gate 	    + sizeof(*prevlsn)
261*7c478bd9Sstevel@tonic-gate 	    + sizeof(new_pgno)
262*7c478bd9Sstevel@tonic-gate 	    + sizeof(*pagelsn)
263*7c478bd9Sstevel@tonic-gate 	    + sizeof(next_pgno)
264*7c478bd9Sstevel@tonic-gate 	    + sizeof(*nextlsn);
265*7c478bd9Sstevel@tonic-gate 	if ((ret = __os_malloc(logrec.size, NULL, &logrec.data)) != 0)
266*7c478bd9Sstevel@tonic-gate 		return (ret);
267*7c478bd9Sstevel@tonic-gate 
268*7c478bd9Sstevel@tonic-gate 	bp = logrec.data;
269*7c478bd9Sstevel@tonic-gate 	memcpy(bp, &rectype, sizeof(rectype));
270*7c478bd9Sstevel@tonic-gate 	bp += sizeof(rectype);
271*7c478bd9Sstevel@tonic-gate 	memcpy(bp, &txn_num, sizeof(txn_num));
272*7c478bd9Sstevel@tonic-gate 	bp += sizeof(txn_num);
273*7c478bd9Sstevel@tonic-gate 	memcpy(bp, lsnp, sizeof(DB_LSN));
274*7c478bd9Sstevel@tonic-gate 	bp += sizeof(DB_LSN);
275*7c478bd9Sstevel@tonic-gate 	memcpy(bp, &opcode, sizeof(opcode));
276*7c478bd9Sstevel@tonic-gate 	bp += sizeof(opcode);
277*7c478bd9Sstevel@tonic-gate 	memcpy(bp, &fileid, sizeof(fileid));
278*7c478bd9Sstevel@tonic-gate 	bp += sizeof(fileid);
279*7c478bd9Sstevel@tonic-gate 	memcpy(bp, &prev_pgno, sizeof(prev_pgno));
280*7c478bd9Sstevel@tonic-gate 	bp += sizeof(prev_pgno);
281*7c478bd9Sstevel@tonic-gate 	if (prevlsn != NULL)
282*7c478bd9Sstevel@tonic-gate 		memcpy(bp, prevlsn, sizeof(*prevlsn));
283*7c478bd9Sstevel@tonic-gate 	else
284*7c478bd9Sstevel@tonic-gate 		memset(bp, 0, sizeof(*prevlsn));
285*7c478bd9Sstevel@tonic-gate 	bp += sizeof(*prevlsn);
286*7c478bd9Sstevel@tonic-gate 	memcpy(bp, &new_pgno, sizeof(new_pgno));
287*7c478bd9Sstevel@tonic-gate 	bp += sizeof(new_pgno);
288*7c478bd9Sstevel@tonic-gate 	if (pagelsn != NULL)
289*7c478bd9Sstevel@tonic-gate 		memcpy(bp, pagelsn, sizeof(*pagelsn));
290*7c478bd9Sstevel@tonic-gate 	else
291*7c478bd9Sstevel@tonic-gate 		memset(bp, 0, sizeof(*pagelsn));
292*7c478bd9Sstevel@tonic-gate 	bp += sizeof(*pagelsn);
293*7c478bd9Sstevel@tonic-gate 	memcpy(bp, &next_pgno, sizeof(next_pgno));
294*7c478bd9Sstevel@tonic-gate 	bp += sizeof(next_pgno);
295*7c478bd9Sstevel@tonic-gate 	if (nextlsn != NULL)
296*7c478bd9Sstevel@tonic-gate 		memcpy(bp, nextlsn, sizeof(*nextlsn));
297*7c478bd9Sstevel@tonic-gate 	else
298*7c478bd9Sstevel@tonic-gate 		memset(bp, 0, sizeof(*nextlsn));
299*7c478bd9Sstevel@tonic-gate 	bp += sizeof(*nextlsn);
300*7c478bd9Sstevel@tonic-gate #ifdef DIAGNOSTIC
301*7c478bd9Sstevel@tonic-gate 	if ((u_int32_t)(bp - (u_int8_t *)logrec.data) != logrec.size)
302*7c478bd9Sstevel@tonic-gate 		fprintf(stderr, "Error in log record length");
303*7c478bd9Sstevel@tonic-gate #endif
304*7c478bd9Sstevel@tonic-gate 	ret = log_put(logp, ret_lsnp, (DBT *)&logrec, flags);
305*7c478bd9Sstevel@tonic-gate 	if (txnid != NULL)
306*7c478bd9Sstevel@tonic-gate 		txnid->last_lsn = *ret_lsnp;
307*7c478bd9Sstevel@tonic-gate 	__os_free(logrec.data, 0);
308*7c478bd9Sstevel@tonic-gate 	return (ret);
309*7c478bd9Sstevel@tonic-gate }
310*7c478bd9Sstevel@tonic-gate 
311*7c478bd9Sstevel@tonic-gate /*
312*7c478bd9Sstevel@tonic-gate  * PUBLIC: int __ham_newpage_print
313*7c478bd9Sstevel@tonic-gate  * PUBLIC:    __P((DB_LOG *, DBT *, DB_LSN *, int, void *));
314*7c478bd9Sstevel@tonic-gate  */
315*7c478bd9Sstevel@tonic-gate int
__ham_newpage_print(notused1,dbtp,lsnp,notused2,notused3)316*7c478bd9Sstevel@tonic-gate __ham_newpage_print(notused1, dbtp, lsnp, notused2, notused3)
317*7c478bd9Sstevel@tonic-gate 	DB_LOG *notused1;
318*7c478bd9Sstevel@tonic-gate 	DBT *dbtp;
319*7c478bd9Sstevel@tonic-gate 	DB_LSN *lsnp;
320*7c478bd9Sstevel@tonic-gate 	int notused2;
321*7c478bd9Sstevel@tonic-gate 	void *notused3;
322*7c478bd9Sstevel@tonic-gate {
323*7c478bd9Sstevel@tonic-gate 	__ham_newpage_args *argp;
324*7c478bd9Sstevel@tonic-gate 	u_int32_t i;
325*7c478bd9Sstevel@tonic-gate 	u_int ch;
326*7c478bd9Sstevel@tonic-gate 	int ret;
327*7c478bd9Sstevel@tonic-gate 
328*7c478bd9Sstevel@tonic-gate 	i = 0;
329*7c478bd9Sstevel@tonic-gate 	ch = 0;
330*7c478bd9Sstevel@tonic-gate 	notused1 = NULL;
331*7c478bd9Sstevel@tonic-gate 	notused2 = 0;
332*7c478bd9Sstevel@tonic-gate 	notused3 = NULL;
333*7c478bd9Sstevel@tonic-gate 
334*7c478bd9Sstevel@tonic-gate 	if ((ret = __ham_newpage_read(dbtp->data, &argp)) != 0)
335*7c478bd9Sstevel@tonic-gate 		return (ret);
336*7c478bd9Sstevel@tonic-gate 	printf("[%lu][%lu]ham_newpage: rec: %lu txnid %lx prevlsn [%lu][%lu]\n",
337*7c478bd9Sstevel@tonic-gate 	    (u_long)lsnp->file,
338*7c478bd9Sstevel@tonic-gate 	    (u_long)lsnp->offset,
339*7c478bd9Sstevel@tonic-gate 	    (u_long)argp->type,
340*7c478bd9Sstevel@tonic-gate 	    (u_long)argp->txnid->txnid,
341*7c478bd9Sstevel@tonic-gate 	    (u_long)argp->prev_lsn.file,
342*7c478bd9Sstevel@tonic-gate 	    (u_long)argp->prev_lsn.offset);
343*7c478bd9Sstevel@tonic-gate 	printf("\topcode: %lu\n", (u_long)argp->opcode);
344*7c478bd9Sstevel@tonic-gate 	printf("\tfileid: %lu\n", (u_long)argp->fileid);
345*7c478bd9Sstevel@tonic-gate 	printf("\tprev_pgno: %lu\n", (u_long)argp->prev_pgno);
346*7c478bd9Sstevel@tonic-gate 	printf("\tprevlsn: [%lu][%lu]\n",
347*7c478bd9Sstevel@tonic-gate 	    (u_long)argp->prevlsn.file, (u_long)argp->prevlsn.offset);
348*7c478bd9Sstevel@tonic-gate 	printf("\tnew_pgno: %lu\n", (u_long)argp->new_pgno);
349*7c478bd9Sstevel@tonic-gate 	printf("\tpagelsn: [%lu][%lu]\n",
350*7c478bd9Sstevel@tonic-gate 	    (u_long)argp->pagelsn.file, (u_long)argp->pagelsn.offset);
351*7c478bd9Sstevel@tonic-gate 	printf("\tnext_pgno: %lu\n", (u_long)argp->next_pgno);
352*7c478bd9Sstevel@tonic-gate 	printf("\tnextlsn: [%lu][%lu]\n",
353*7c478bd9Sstevel@tonic-gate 	    (u_long)argp->nextlsn.file, (u_long)argp->nextlsn.offset);
354*7c478bd9Sstevel@tonic-gate 	printf("\n");
355*7c478bd9Sstevel@tonic-gate 	__os_free(argp, 0);
356*7c478bd9Sstevel@tonic-gate 	return (0);
357*7c478bd9Sstevel@tonic-gate }
358*7c478bd9Sstevel@tonic-gate 
359*7c478bd9Sstevel@tonic-gate /*
360*7c478bd9Sstevel@tonic-gate  * PUBLIC: int __ham_newpage_read __P((void *, __ham_newpage_args **));
361*7c478bd9Sstevel@tonic-gate  */
362*7c478bd9Sstevel@tonic-gate int
__ham_newpage_read(recbuf,argpp)363*7c478bd9Sstevel@tonic-gate __ham_newpage_read(recbuf, argpp)
364*7c478bd9Sstevel@tonic-gate 	void *recbuf;
365*7c478bd9Sstevel@tonic-gate 	__ham_newpage_args **argpp;
366*7c478bd9Sstevel@tonic-gate {
367*7c478bd9Sstevel@tonic-gate 	__ham_newpage_args *argp;
368*7c478bd9Sstevel@tonic-gate 	u_int8_t *bp;
369*7c478bd9Sstevel@tonic-gate 	int ret;
370*7c478bd9Sstevel@tonic-gate 
371*7c478bd9Sstevel@tonic-gate 	ret = __os_malloc(sizeof(__ham_newpage_args) +
372*7c478bd9Sstevel@tonic-gate 	    sizeof(DB_TXN), NULL, &argp);
373*7c478bd9Sstevel@tonic-gate 	if (ret != 0)
374*7c478bd9Sstevel@tonic-gate 		return (ret);
375*7c478bd9Sstevel@tonic-gate 	argp->txnid = (DB_TXN *)&argp[1];
376*7c478bd9Sstevel@tonic-gate 	bp = recbuf;
377*7c478bd9Sstevel@tonic-gate 	memcpy(&argp->type, bp, sizeof(argp->type));
378*7c478bd9Sstevel@tonic-gate 	bp += sizeof(argp->type);
379*7c478bd9Sstevel@tonic-gate 	memcpy(&argp->txnid->txnid,  bp, sizeof(argp->txnid->txnid));
380*7c478bd9Sstevel@tonic-gate 	bp += sizeof(argp->txnid->txnid);
381*7c478bd9Sstevel@tonic-gate 	memcpy(&argp->prev_lsn, bp, sizeof(DB_LSN));
382*7c478bd9Sstevel@tonic-gate 	bp += sizeof(DB_LSN);
383*7c478bd9Sstevel@tonic-gate 	memcpy(&argp->opcode, bp, sizeof(argp->opcode));
384*7c478bd9Sstevel@tonic-gate 	bp += sizeof(argp->opcode);
385*7c478bd9Sstevel@tonic-gate 	memcpy(&argp->fileid, bp, sizeof(argp->fileid));
386*7c478bd9Sstevel@tonic-gate 	bp += sizeof(argp->fileid);
387*7c478bd9Sstevel@tonic-gate 	memcpy(&argp->prev_pgno, bp, sizeof(argp->prev_pgno));
388*7c478bd9Sstevel@tonic-gate 	bp += sizeof(argp->prev_pgno);
389*7c478bd9Sstevel@tonic-gate 	memcpy(&argp->prevlsn, bp,  sizeof(argp->prevlsn));
390*7c478bd9Sstevel@tonic-gate 	bp += sizeof(argp->prevlsn);
391*7c478bd9Sstevel@tonic-gate 	memcpy(&argp->new_pgno, bp, sizeof(argp->new_pgno));
392*7c478bd9Sstevel@tonic-gate 	bp += sizeof(argp->new_pgno);
393*7c478bd9Sstevel@tonic-gate 	memcpy(&argp->pagelsn, bp,  sizeof(argp->pagelsn));
394*7c478bd9Sstevel@tonic-gate 	bp += sizeof(argp->pagelsn);
395*7c478bd9Sstevel@tonic-gate 	memcpy(&argp->next_pgno, bp, sizeof(argp->next_pgno));
396*7c478bd9Sstevel@tonic-gate 	bp += sizeof(argp->next_pgno);
397*7c478bd9Sstevel@tonic-gate 	memcpy(&argp->nextlsn, bp,  sizeof(argp->nextlsn));
398*7c478bd9Sstevel@tonic-gate 	bp += sizeof(argp->nextlsn);
399*7c478bd9Sstevel@tonic-gate 	*argpp = argp;
400*7c478bd9Sstevel@tonic-gate 	return (0);
401*7c478bd9Sstevel@tonic-gate }
402*7c478bd9Sstevel@tonic-gate 
403*7c478bd9Sstevel@tonic-gate /*
404*7c478bd9Sstevel@tonic-gate  * PUBLIC: int __ham_splitmeta_log
405*7c478bd9Sstevel@tonic-gate  * PUBLIC:     __P((DB_LOG *, DB_TXN *, DB_LSN *, u_int32_t,
406*7c478bd9Sstevel@tonic-gate  * PUBLIC:     u_int32_t, u_int32_t, u_int32_t, u_int32_t,
407*7c478bd9Sstevel@tonic-gate  * PUBLIC:     DB_LSN *));
408*7c478bd9Sstevel@tonic-gate  */
__ham_splitmeta_log(logp,txnid,ret_lsnp,flags,fileid,bucket,ovflpoint,spares,metalsn)409*7c478bd9Sstevel@tonic-gate int __ham_splitmeta_log(logp, txnid, ret_lsnp, flags,
410*7c478bd9Sstevel@tonic-gate 	fileid, bucket, ovflpoint, spares, metalsn)
411*7c478bd9Sstevel@tonic-gate 	DB_LOG *logp;
412*7c478bd9Sstevel@tonic-gate 	DB_TXN *txnid;
413*7c478bd9Sstevel@tonic-gate 	DB_LSN *ret_lsnp;
414*7c478bd9Sstevel@tonic-gate 	u_int32_t flags;
415*7c478bd9Sstevel@tonic-gate 	u_int32_t fileid;
416*7c478bd9Sstevel@tonic-gate 	u_int32_t bucket;
417*7c478bd9Sstevel@tonic-gate 	u_int32_t ovflpoint;
418*7c478bd9Sstevel@tonic-gate 	u_int32_t spares;
419*7c478bd9Sstevel@tonic-gate 	DB_LSN * metalsn;
420*7c478bd9Sstevel@tonic-gate {
421*7c478bd9Sstevel@tonic-gate 	DBT logrec;
422*7c478bd9Sstevel@tonic-gate 	DB_LSN *lsnp, null_lsn;
423*7c478bd9Sstevel@tonic-gate 	u_int32_t rectype, txn_num;
424*7c478bd9Sstevel@tonic-gate 	int ret;
425*7c478bd9Sstevel@tonic-gate 	u_int8_t *bp;
426*7c478bd9Sstevel@tonic-gate 
427*7c478bd9Sstevel@tonic-gate 	rectype = DB_ham_splitmeta;
428*7c478bd9Sstevel@tonic-gate 	txn_num = txnid == NULL ? 0 : txnid->txnid;
429*7c478bd9Sstevel@tonic-gate 	if (txnid == NULL) {
430*7c478bd9Sstevel@tonic-gate 		ZERO_LSN(null_lsn);
431*7c478bd9Sstevel@tonic-gate 		lsnp = &null_lsn;
432*7c478bd9Sstevel@tonic-gate 	} else
433*7c478bd9Sstevel@tonic-gate 		lsnp = &txnid->last_lsn;
434*7c478bd9Sstevel@tonic-gate 	logrec.size = sizeof(rectype) + sizeof(txn_num) + sizeof(DB_LSN)
435*7c478bd9Sstevel@tonic-gate 	    + sizeof(fileid)
436*7c478bd9Sstevel@tonic-gate 	    + sizeof(bucket)
437*7c478bd9Sstevel@tonic-gate 	    + sizeof(ovflpoint)
438*7c478bd9Sstevel@tonic-gate 	    + sizeof(spares)
439*7c478bd9Sstevel@tonic-gate 	    + sizeof(*metalsn);
440*7c478bd9Sstevel@tonic-gate 	if ((ret = __os_malloc(logrec.size, NULL, &logrec.data)) != 0)
441*7c478bd9Sstevel@tonic-gate 		return (ret);
442*7c478bd9Sstevel@tonic-gate 
443*7c478bd9Sstevel@tonic-gate 	bp = logrec.data;
444*7c478bd9Sstevel@tonic-gate 	memcpy(bp, &rectype, sizeof(rectype));
445*7c478bd9Sstevel@tonic-gate 	bp += sizeof(rectype);
446*7c478bd9Sstevel@tonic-gate 	memcpy(bp, &txn_num, sizeof(txn_num));
447*7c478bd9Sstevel@tonic-gate 	bp += sizeof(txn_num);
448*7c478bd9Sstevel@tonic-gate 	memcpy(bp, lsnp, sizeof(DB_LSN));
449*7c478bd9Sstevel@tonic-gate 	bp += sizeof(DB_LSN);
450*7c478bd9Sstevel@tonic-gate 	memcpy(bp, &fileid, sizeof(fileid));
451*7c478bd9Sstevel@tonic-gate 	bp += sizeof(fileid);
452*7c478bd9Sstevel@tonic-gate 	memcpy(bp, &bucket, sizeof(bucket));
453*7c478bd9Sstevel@tonic-gate 	bp += sizeof(bucket);
454*7c478bd9Sstevel@tonic-gate 	memcpy(bp, &ovflpoint, sizeof(ovflpoint));
455*7c478bd9Sstevel@tonic-gate 	bp += sizeof(ovflpoint);
456*7c478bd9Sstevel@tonic-gate 	memcpy(bp, &spares, sizeof(spares));
457*7c478bd9Sstevel@tonic-gate 	bp += sizeof(spares);
458*7c478bd9Sstevel@tonic-gate 	if (metalsn != NULL)
459*7c478bd9Sstevel@tonic-gate 		memcpy(bp, metalsn, sizeof(*metalsn));
460*7c478bd9Sstevel@tonic-gate 	else
461*7c478bd9Sstevel@tonic-gate 		memset(bp, 0, sizeof(*metalsn));
462*7c478bd9Sstevel@tonic-gate 	bp += sizeof(*metalsn);
463*7c478bd9Sstevel@tonic-gate #ifdef DIAGNOSTIC
464*7c478bd9Sstevel@tonic-gate 	if ((u_int32_t)(bp - (u_int8_t *)logrec.data) != logrec.size)
465*7c478bd9Sstevel@tonic-gate 		fprintf(stderr, "Error in log record length");
466*7c478bd9Sstevel@tonic-gate #endif
467*7c478bd9Sstevel@tonic-gate 	ret = log_put(logp, ret_lsnp, (DBT *)&logrec, flags);
468*7c478bd9Sstevel@tonic-gate 	if (txnid != NULL)
469*7c478bd9Sstevel@tonic-gate 		txnid->last_lsn = *ret_lsnp;
470*7c478bd9Sstevel@tonic-gate 	__os_free(logrec.data, 0);
471*7c478bd9Sstevel@tonic-gate 	return (ret);
472*7c478bd9Sstevel@tonic-gate }
473*7c478bd9Sstevel@tonic-gate 
474*7c478bd9Sstevel@tonic-gate /*
475*7c478bd9Sstevel@tonic-gate  * PUBLIC: int __ham_splitmeta_print
476*7c478bd9Sstevel@tonic-gate  * PUBLIC:    __P((DB_LOG *, DBT *, DB_LSN *, int, void *));
477*7c478bd9Sstevel@tonic-gate  */
478*7c478bd9Sstevel@tonic-gate int
__ham_splitmeta_print(notused1,dbtp,lsnp,notused2,notused3)479*7c478bd9Sstevel@tonic-gate __ham_splitmeta_print(notused1, dbtp, lsnp, notused2, notused3)
480*7c478bd9Sstevel@tonic-gate 	DB_LOG *notused1;
481*7c478bd9Sstevel@tonic-gate 	DBT *dbtp;
482*7c478bd9Sstevel@tonic-gate 	DB_LSN *lsnp;
483*7c478bd9Sstevel@tonic-gate 	int notused2;
484*7c478bd9Sstevel@tonic-gate 	void *notused3;
485*7c478bd9Sstevel@tonic-gate {
486*7c478bd9Sstevel@tonic-gate 	__ham_splitmeta_args *argp;
487*7c478bd9Sstevel@tonic-gate 	u_int32_t i;
488*7c478bd9Sstevel@tonic-gate 	u_int ch;
489*7c478bd9Sstevel@tonic-gate 	int ret;
490*7c478bd9Sstevel@tonic-gate 
491*7c478bd9Sstevel@tonic-gate 	i = 0;
492*7c478bd9Sstevel@tonic-gate 	ch = 0;
493*7c478bd9Sstevel@tonic-gate 	notused1 = NULL;
494*7c478bd9Sstevel@tonic-gate 	notused2 = 0;
495*7c478bd9Sstevel@tonic-gate 	notused3 = NULL;
496*7c478bd9Sstevel@tonic-gate 
497*7c478bd9Sstevel@tonic-gate 	if ((ret = __ham_splitmeta_read(dbtp->data, &argp)) != 0)
498*7c478bd9Sstevel@tonic-gate 		return (ret);
499*7c478bd9Sstevel@tonic-gate 	printf("[%lu][%lu]ham_splitmeta: rec: %lu txnid %lx prevlsn [%lu][%lu]\n",
500*7c478bd9Sstevel@tonic-gate 	    (u_long)lsnp->file,
501*7c478bd9Sstevel@tonic-gate 	    (u_long)lsnp->offset,
502*7c478bd9Sstevel@tonic-gate 	    (u_long)argp->type,
503*7c478bd9Sstevel@tonic-gate 	    (u_long)argp->txnid->txnid,
504*7c478bd9Sstevel@tonic-gate 	    (u_long)argp->prev_lsn.file,
505*7c478bd9Sstevel@tonic-gate 	    (u_long)argp->prev_lsn.offset);
506*7c478bd9Sstevel@tonic-gate 	printf("\tfileid: %lu\n", (u_long)argp->fileid);
507*7c478bd9Sstevel@tonic-gate 	printf("\tbucket: %lu\n", (u_long)argp->bucket);
508*7c478bd9Sstevel@tonic-gate 	printf("\tovflpoint: %lu\n", (u_long)argp->ovflpoint);
509*7c478bd9Sstevel@tonic-gate 	printf("\tspares: %lu\n", (u_long)argp->spares);
510*7c478bd9Sstevel@tonic-gate 	printf("\tmetalsn: [%lu][%lu]\n",
511*7c478bd9Sstevel@tonic-gate 	    (u_long)argp->metalsn.file, (u_long)argp->metalsn.offset);
512*7c478bd9Sstevel@tonic-gate 	printf("\n");
513*7c478bd9Sstevel@tonic-gate 	__os_free(argp, 0);
514*7c478bd9Sstevel@tonic-gate 	return (0);
515*7c478bd9Sstevel@tonic-gate }
516*7c478bd9Sstevel@tonic-gate 
517*7c478bd9Sstevel@tonic-gate /*
518*7c478bd9Sstevel@tonic-gate  * PUBLIC: int __ham_splitmeta_read __P((void *, __ham_splitmeta_args **));
519*7c478bd9Sstevel@tonic-gate  */
520*7c478bd9Sstevel@tonic-gate int
__ham_splitmeta_read(recbuf,argpp)521*7c478bd9Sstevel@tonic-gate __ham_splitmeta_read(recbuf, argpp)
522*7c478bd9Sstevel@tonic-gate 	void *recbuf;
523*7c478bd9Sstevel@tonic-gate 	__ham_splitmeta_args **argpp;
524*7c478bd9Sstevel@tonic-gate {
525*7c478bd9Sstevel@tonic-gate 	__ham_splitmeta_args *argp;
526*7c478bd9Sstevel@tonic-gate 	u_int8_t *bp;
527*7c478bd9Sstevel@tonic-gate 	int ret;
528*7c478bd9Sstevel@tonic-gate 
529*7c478bd9Sstevel@tonic-gate 	ret = __os_malloc(sizeof(__ham_splitmeta_args) +
530*7c478bd9Sstevel@tonic-gate 	    sizeof(DB_TXN), NULL, &argp);
531*7c478bd9Sstevel@tonic-gate 	if (ret != 0)
532*7c478bd9Sstevel@tonic-gate 		return (ret);
533*7c478bd9Sstevel@tonic-gate 	argp->txnid = (DB_TXN *)&argp[1];
534*7c478bd9Sstevel@tonic-gate 	bp = recbuf;
535*7c478bd9Sstevel@tonic-gate 	memcpy(&argp->type, bp, sizeof(argp->type));
536*7c478bd9Sstevel@tonic-gate 	bp += sizeof(argp->type);
537*7c478bd9Sstevel@tonic-gate 	memcpy(&argp->txnid->txnid,  bp, sizeof(argp->txnid->txnid));
538*7c478bd9Sstevel@tonic-gate 	bp += sizeof(argp->txnid->txnid);
539*7c478bd9Sstevel@tonic-gate 	memcpy(&argp->prev_lsn, bp, sizeof(DB_LSN));
540*7c478bd9Sstevel@tonic-gate 	bp += sizeof(DB_LSN);
541*7c478bd9Sstevel@tonic-gate 	memcpy(&argp->fileid, bp, sizeof(argp->fileid));
542*7c478bd9Sstevel@tonic-gate 	bp += sizeof(argp->fileid);
543*7c478bd9Sstevel@tonic-gate 	memcpy(&argp->bucket, bp, sizeof(argp->bucket));
544*7c478bd9Sstevel@tonic-gate 	bp += sizeof(argp->bucket);
545*7c478bd9Sstevel@tonic-gate 	memcpy(&argp->ovflpoint, bp, sizeof(argp->ovflpoint));
546*7c478bd9Sstevel@tonic-gate 	bp += sizeof(argp->ovflpoint);
547*7c478bd9Sstevel@tonic-gate 	memcpy(&argp->spares, bp, sizeof(argp->spares));
548*7c478bd9Sstevel@tonic-gate 	bp += sizeof(argp->spares);
549*7c478bd9Sstevel@tonic-gate 	memcpy(&argp->metalsn, bp,  sizeof(argp->metalsn));
550*7c478bd9Sstevel@tonic-gate 	bp += sizeof(argp->metalsn);
551*7c478bd9Sstevel@tonic-gate 	*argpp = argp;
552*7c478bd9Sstevel@tonic-gate 	return (0);
553*7c478bd9Sstevel@tonic-gate }
554*7c478bd9Sstevel@tonic-gate 
555*7c478bd9Sstevel@tonic-gate /*
556*7c478bd9Sstevel@tonic-gate  * PUBLIC: int __ham_splitdata_log
557*7c478bd9Sstevel@tonic-gate  * PUBLIC:     __P((DB_LOG *, DB_TXN *, DB_LSN *, u_int32_t,
558*7c478bd9Sstevel@tonic-gate  * PUBLIC:     u_int32_t, u_int32_t, db_pgno_t, const DBT *,
559*7c478bd9Sstevel@tonic-gate  * PUBLIC:     DB_LSN *));
560*7c478bd9Sstevel@tonic-gate  */
__ham_splitdata_log(logp,txnid,ret_lsnp,flags,fileid,opcode,pgno,pageimage,pagelsn)561*7c478bd9Sstevel@tonic-gate int __ham_splitdata_log(logp, txnid, ret_lsnp, flags,
562*7c478bd9Sstevel@tonic-gate 	fileid, opcode, pgno, pageimage, pagelsn)
563*7c478bd9Sstevel@tonic-gate 	DB_LOG *logp;
564*7c478bd9Sstevel@tonic-gate 	DB_TXN *txnid;
565*7c478bd9Sstevel@tonic-gate 	DB_LSN *ret_lsnp;
566*7c478bd9Sstevel@tonic-gate 	u_int32_t flags;
567*7c478bd9Sstevel@tonic-gate 	u_int32_t fileid;
568*7c478bd9Sstevel@tonic-gate 	u_int32_t opcode;
569*7c478bd9Sstevel@tonic-gate 	db_pgno_t pgno;
570*7c478bd9Sstevel@tonic-gate 	const DBT *pageimage;
571*7c478bd9Sstevel@tonic-gate 	DB_LSN * pagelsn;
572*7c478bd9Sstevel@tonic-gate {
573*7c478bd9Sstevel@tonic-gate 	DBT logrec;
574*7c478bd9Sstevel@tonic-gate 	DB_LSN *lsnp, null_lsn;
575*7c478bd9Sstevel@tonic-gate 	u_int32_t zero;
576*7c478bd9Sstevel@tonic-gate 	u_int32_t rectype, txn_num;
577*7c478bd9Sstevel@tonic-gate 	int ret;
578*7c478bd9Sstevel@tonic-gate 	u_int8_t *bp;
579*7c478bd9Sstevel@tonic-gate 
580*7c478bd9Sstevel@tonic-gate 	rectype = DB_ham_splitdata;
581*7c478bd9Sstevel@tonic-gate 	txn_num = txnid == NULL ? 0 : txnid->txnid;
582*7c478bd9Sstevel@tonic-gate 	if (txnid == NULL) {
583*7c478bd9Sstevel@tonic-gate 		ZERO_LSN(null_lsn);
584*7c478bd9Sstevel@tonic-gate 		lsnp = &null_lsn;
585*7c478bd9Sstevel@tonic-gate 	} else
586*7c478bd9Sstevel@tonic-gate 		lsnp = &txnid->last_lsn;
587*7c478bd9Sstevel@tonic-gate 	logrec.size = sizeof(rectype) + sizeof(txn_num) + sizeof(DB_LSN)
588*7c478bd9Sstevel@tonic-gate 	    + sizeof(fileid)
589*7c478bd9Sstevel@tonic-gate 	    + sizeof(opcode)
590*7c478bd9Sstevel@tonic-gate 	    + sizeof(pgno)
591*7c478bd9Sstevel@tonic-gate 	    + sizeof(u_int32_t) + (pageimage == NULL ? 0 : pageimage->size)
592*7c478bd9Sstevel@tonic-gate 	    + sizeof(*pagelsn);
593*7c478bd9Sstevel@tonic-gate 	if ((ret = __os_malloc(logrec.size, NULL, &logrec.data)) != 0)
594*7c478bd9Sstevel@tonic-gate 		return (ret);
595*7c478bd9Sstevel@tonic-gate 
596*7c478bd9Sstevel@tonic-gate 	bp = logrec.data;
597*7c478bd9Sstevel@tonic-gate 	memcpy(bp, &rectype, sizeof(rectype));
598*7c478bd9Sstevel@tonic-gate 	bp += sizeof(rectype);
599*7c478bd9Sstevel@tonic-gate 	memcpy(bp, &txn_num, sizeof(txn_num));
600*7c478bd9Sstevel@tonic-gate 	bp += sizeof(txn_num);
601*7c478bd9Sstevel@tonic-gate 	memcpy(bp, lsnp, sizeof(DB_LSN));
602*7c478bd9Sstevel@tonic-gate 	bp += sizeof(DB_LSN);
603*7c478bd9Sstevel@tonic-gate 	memcpy(bp, &fileid, sizeof(fileid));
604*7c478bd9Sstevel@tonic-gate 	bp += sizeof(fileid);
605*7c478bd9Sstevel@tonic-gate 	memcpy(bp, &opcode, sizeof(opcode));
606*7c478bd9Sstevel@tonic-gate 	bp += sizeof(opcode);
607*7c478bd9Sstevel@tonic-gate 	memcpy(bp, &pgno, sizeof(pgno));
608*7c478bd9Sstevel@tonic-gate 	bp += sizeof(pgno);
609*7c478bd9Sstevel@tonic-gate 	if (pageimage == NULL) {
610*7c478bd9Sstevel@tonic-gate 		zero = 0;
611*7c478bd9Sstevel@tonic-gate 		memcpy(bp, &zero, sizeof(u_int32_t));
612*7c478bd9Sstevel@tonic-gate 		bp += sizeof(u_int32_t);
613*7c478bd9Sstevel@tonic-gate 	} else {
614*7c478bd9Sstevel@tonic-gate 		memcpy(bp, &pageimage->size, sizeof(pageimage->size));
615*7c478bd9Sstevel@tonic-gate 		bp += sizeof(pageimage->size);
616*7c478bd9Sstevel@tonic-gate 		memcpy(bp, pageimage->data, pageimage->size);
617*7c478bd9Sstevel@tonic-gate 		bp += pageimage->size;
618*7c478bd9Sstevel@tonic-gate 	}
619*7c478bd9Sstevel@tonic-gate 	if (pagelsn != NULL)
620*7c478bd9Sstevel@tonic-gate 		memcpy(bp, pagelsn, sizeof(*pagelsn));
621*7c478bd9Sstevel@tonic-gate 	else
622*7c478bd9Sstevel@tonic-gate 		memset(bp, 0, sizeof(*pagelsn));
623*7c478bd9Sstevel@tonic-gate 	bp += sizeof(*pagelsn);
624*7c478bd9Sstevel@tonic-gate #ifdef DIAGNOSTIC
625*7c478bd9Sstevel@tonic-gate 	if ((u_int32_t)(bp - (u_int8_t *)logrec.data) != logrec.size)
626*7c478bd9Sstevel@tonic-gate 		fprintf(stderr, "Error in log record length");
627*7c478bd9Sstevel@tonic-gate #endif
628*7c478bd9Sstevel@tonic-gate 	ret = log_put(logp, ret_lsnp, (DBT *)&logrec, flags);
629*7c478bd9Sstevel@tonic-gate 	if (txnid != NULL)
630*7c478bd9Sstevel@tonic-gate 		txnid->last_lsn = *ret_lsnp;
631*7c478bd9Sstevel@tonic-gate 	__os_free(logrec.data, 0);
632*7c478bd9Sstevel@tonic-gate 	return (ret);
633*7c478bd9Sstevel@tonic-gate }
634*7c478bd9Sstevel@tonic-gate 
635*7c478bd9Sstevel@tonic-gate /*
636*7c478bd9Sstevel@tonic-gate  * PUBLIC: int __ham_splitdata_print
637*7c478bd9Sstevel@tonic-gate  * PUBLIC:    __P((DB_LOG *, DBT *, DB_LSN *, int, void *));
638*7c478bd9Sstevel@tonic-gate  */
639*7c478bd9Sstevel@tonic-gate int
__ham_splitdata_print(notused1,dbtp,lsnp,notused2,notused3)640*7c478bd9Sstevel@tonic-gate __ham_splitdata_print(notused1, dbtp, lsnp, notused2, notused3)
641*7c478bd9Sstevel@tonic-gate 	DB_LOG *notused1;
642*7c478bd9Sstevel@tonic-gate 	DBT *dbtp;
643*7c478bd9Sstevel@tonic-gate 	DB_LSN *lsnp;
644*7c478bd9Sstevel@tonic-gate 	int notused2;
645*7c478bd9Sstevel@tonic-gate 	void *notused3;
646*7c478bd9Sstevel@tonic-gate {
647*7c478bd9Sstevel@tonic-gate 	__ham_splitdata_args *argp;
648*7c478bd9Sstevel@tonic-gate 	u_int32_t i;
649*7c478bd9Sstevel@tonic-gate 	u_int ch;
650*7c478bd9Sstevel@tonic-gate 	int ret;
651*7c478bd9Sstevel@tonic-gate 
652*7c478bd9Sstevel@tonic-gate 	i = 0;
653*7c478bd9Sstevel@tonic-gate 	ch = 0;
654*7c478bd9Sstevel@tonic-gate 	notused1 = NULL;
655*7c478bd9Sstevel@tonic-gate 	notused2 = 0;
656*7c478bd9Sstevel@tonic-gate 	notused3 = NULL;
657*7c478bd9Sstevel@tonic-gate 
658*7c478bd9Sstevel@tonic-gate 	if ((ret = __ham_splitdata_read(dbtp->data, &argp)) != 0)
659*7c478bd9Sstevel@tonic-gate 		return (ret);
660*7c478bd9Sstevel@tonic-gate 	printf("[%lu][%lu]ham_splitdata: rec: %lu txnid %lx prevlsn [%lu][%lu]\n",
661*7c478bd9Sstevel@tonic-gate 	    (u_long)lsnp->file,
662*7c478bd9Sstevel@tonic-gate 	    (u_long)lsnp->offset,
663*7c478bd9Sstevel@tonic-gate 	    (u_long)argp->type,
664*7c478bd9Sstevel@tonic-gate 	    (u_long)argp->txnid->txnid,
665*7c478bd9Sstevel@tonic-gate 	    (u_long)argp->prev_lsn.file,
666*7c478bd9Sstevel@tonic-gate 	    (u_long)argp->prev_lsn.offset);
667*7c478bd9Sstevel@tonic-gate 	printf("\tfileid: %lu\n", (u_long)argp->fileid);
668*7c478bd9Sstevel@tonic-gate 	printf("\topcode: %lu\n", (u_long)argp->opcode);
669*7c478bd9Sstevel@tonic-gate 	printf("\tpgno: %lu\n", (u_long)argp->pgno);
670*7c478bd9Sstevel@tonic-gate 	printf("\tpageimage: ");
671*7c478bd9Sstevel@tonic-gate 	for (i = 0; i < argp->pageimage.size; i++) {
672*7c478bd9Sstevel@tonic-gate 		ch = ((u_int8_t *)argp->pageimage.data)[i];
673*7c478bd9Sstevel@tonic-gate 		if (isprint(ch) || ch == 0xa)
674*7c478bd9Sstevel@tonic-gate 			putchar(ch);
675*7c478bd9Sstevel@tonic-gate 		else
676*7c478bd9Sstevel@tonic-gate 			printf("%#x ", ch);
677*7c478bd9Sstevel@tonic-gate 	}
678*7c478bd9Sstevel@tonic-gate 	printf("\n");
679*7c478bd9Sstevel@tonic-gate 	printf("\tpagelsn: [%lu][%lu]\n",
680*7c478bd9Sstevel@tonic-gate 	    (u_long)argp->pagelsn.file, (u_long)argp->pagelsn.offset);
681*7c478bd9Sstevel@tonic-gate 	printf("\n");
682*7c478bd9Sstevel@tonic-gate 	__os_free(argp, 0);
683*7c478bd9Sstevel@tonic-gate 	return (0);
684*7c478bd9Sstevel@tonic-gate }
685*7c478bd9Sstevel@tonic-gate 
686*7c478bd9Sstevel@tonic-gate /*
687*7c478bd9Sstevel@tonic-gate  * PUBLIC: int __ham_splitdata_read __P((void *, __ham_splitdata_args **));
688*7c478bd9Sstevel@tonic-gate  */
689*7c478bd9Sstevel@tonic-gate int
__ham_splitdata_read(recbuf,argpp)690*7c478bd9Sstevel@tonic-gate __ham_splitdata_read(recbuf, argpp)
691*7c478bd9Sstevel@tonic-gate 	void *recbuf;
692*7c478bd9Sstevel@tonic-gate 	__ham_splitdata_args **argpp;
693*7c478bd9Sstevel@tonic-gate {
694*7c478bd9Sstevel@tonic-gate 	__ham_splitdata_args *argp;
695*7c478bd9Sstevel@tonic-gate 	u_int8_t *bp;
696*7c478bd9Sstevel@tonic-gate 	int ret;
697*7c478bd9Sstevel@tonic-gate 
698*7c478bd9Sstevel@tonic-gate 	ret = __os_malloc(sizeof(__ham_splitdata_args) +
699*7c478bd9Sstevel@tonic-gate 	    sizeof(DB_TXN), NULL, &argp);
700*7c478bd9Sstevel@tonic-gate 	if (ret != 0)
701*7c478bd9Sstevel@tonic-gate 		return (ret);
702*7c478bd9Sstevel@tonic-gate 	argp->txnid = (DB_TXN *)&argp[1];
703*7c478bd9Sstevel@tonic-gate 	bp = recbuf;
704*7c478bd9Sstevel@tonic-gate 	memcpy(&argp->type, bp, sizeof(argp->type));
705*7c478bd9Sstevel@tonic-gate 	bp += sizeof(argp->type);
706*7c478bd9Sstevel@tonic-gate 	memcpy(&argp->txnid->txnid,  bp, sizeof(argp->txnid->txnid));
707*7c478bd9Sstevel@tonic-gate 	bp += sizeof(argp->txnid->txnid);
708*7c478bd9Sstevel@tonic-gate 	memcpy(&argp->prev_lsn, bp, sizeof(DB_LSN));
709*7c478bd9Sstevel@tonic-gate 	bp += sizeof(DB_LSN);
710*7c478bd9Sstevel@tonic-gate 	memcpy(&argp->fileid, bp, sizeof(argp->fileid));
711*7c478bd9Sstevel@tonic-gate 	bp += sizeof(argp->fileid);
712*7c478bd9Sstevel@tonic-gate 	memcpy(&argp->opcode, bp, sizeof(argp->opcode));
713*7c478bd9Sstevel@tonic-gate 	bp += sizeof(argp->opcode);
714*7c478bd9Sstevel@tonic-gate 	memcpy(&argp->pgno, bp, sizeof(argp->pgno));
715*7c478bd9Sstevel@tonic-gate 	bp += sizeof(argp->pgno);
716*7c478bd9Sstevel@tonic-gate 	memcpy(&argp->pageimage.size, bp, sizeof(u_int32_t));
717*7c478bd9Sstevel@tonic-gate 	bp += sizeof(u_int32_t);
718*7c478bd9Sstevel@tonic-gate 	argp->pageimage.data = bp;
719*7c478bd9Sstevel@tonic-gate 	bp += argp->pageimage.size;
720*7c478bd9Sstevel@tonic-gate 	memcpy(&argp->pagelsn, bp,  sizeof(argp->pagelsn));
721*7c478bd9Sstevel@tonic-gate 	bp += sizeof(argp->pagelsn);
722*7c478bd9Sstevel@tonic-gate 	*argpp = argp;
723*7c478bd9Sstevel@tonic-gate 	return (0);
724*7c478bd9Sstevel@tonic-gate }
725*7c478bd9Sstevel@tonic-gate 
726*7c478bd9Sstevel@tonic-gate /*
727*7c478bd9Sstevel@tonic-gate  * PUBLIC: int __ham_replace_log
728*7c478bd9Sstevel@tonic-gate  * PUBLIC:     __P((DB_LOG *, DB_TXN *, DB_LSN *, u_int32_t,
729*7c478bd9Sstevel@tonic-gate  * PUBLIC:     u_int32_t, db_pgno_t, u_int32_t, DB_LSN *,
730*7c478bd9Sstevel@tonic-gate  * PUBLIC:     int32_t, const DBT *, const DBT *, u_int32_t));
731*7c478bd9Sstevel@tonic-gate  */
__ham_replace_log(logp,txnid,ret_lsnp,flags,fileid,pgno,ndx,pagelsn,off,olditem,newitem,makedup)732*7c478bd9Sstevel@tonic-gate int __ham_replace_log(logp, txnid, ret_lsnp, flags,
733*7c478bd9Sstevel@tonic-gate 	fileid, pgno, ndx, pagelsn, off, olditem,
734*7c478bd9Sstevel@tonic-gate 	newitem, makedup)
735*7c478bd9Sstevel@tonic-gate 	DB_LOG *logp;
736*7c478bd9Sstevel@tonic-gate 	DB_TXN *txnid;
737*7c478bd9Sstevel@tonic-gate 	DB_LSN *ret_lsnp;
738*7c478bd9Sstevel@tonic-gate 	u_int32_t flags;
739*7c478bd9Sstevel@tonic-gate 	u_int32_t fileid;
740*7c478bd9Sstevel@tonic-gate 	db_pgno_t pgno;
741*7c478bd9Sstevel@tonic-gate 	u_int32_t ndx;
742*7c478bd9Sstevel@tonic-gate 	DB_LSN * pagelsn;
743*7c478bd9Sstevel@tonic-gate 	int32_t off;
744*7c478bd9Sstevel@tonic-gate 	const DBT *olditem;
745*7c478bd9Sstevel@tonic-gate 	const DBT *newitem;
746*7c478bd9Sstevel@tonic-gate 	u_int32_t makedup;
747*7c478bd9Sstevel@tonic-gate {
748*7c478bd9Sstevel@tonic-gate 	DBT logrec;
749*7c478bd9Sstevel@tonic-gate 	DB_LSN *lsnp, null_lsn;
750*7c478bd9Sstevel@tonic-gate 	u_int32_t zero;
751*7c478bd9Sstevel@tonic-gate 	u_int32_t rectype, txn_num;
752*7c478bd9Sstevel@tonic-gate 	int ret;
753*7c478bd9Sstevel@tonic-gate 	u_int8_t *bp;
754*7c478bd9Sstevel@tonic-gate 
755*7c478bd9Sstevel@tonic-gate 	rectype = DB_ham_replace;
756*7c478bd9Sstevel@tonic-gate 	txn_num = txnid == NULL ? 0 : txnid->txnid;
757*7c478bd9Sstevel@tonic-gate 	if (txnid == NULL) {
758*7c478bd9Sstevel@tonic-gate 		ZERO_LSN(null_lsn);
759*7c478bd9Sstevel@tonic-gate 		lsnp = &null_lsn;
760*7c478bd9Sstevel@tonic-gate 	} else
761*7c478bd9Sstevel@tonic-gate 		lsnp = &txnid->last_lsn;
762*7c478bd9Sstevel@tonic-gate 	logrec.size = sizeof(rectype) + sizeof(txn_num) + sizeof(DB_LSN)
763*7c478bd9Sstevel@tonic-gate 	    + sizeof(fileid)
764*7c478bd9Sstevel@tonic-gate 	    + sizeof(pgno)
765*7c478bd9Sstevel@tonic-gate 	    + sizeof(ndx)
766*7c478bd9Sstevel@tonic-gate 	    + sizeof(*pagelsn)
767*7c478bd9Sstevel@tonic-gate 	    + sizeof(off)
768*7c478bd9Sstevel@tonic-gate 	    + sizeof(u_int32_t) + (olditem == NULL ? 0 : olditem->size)
769*7c478bd9Sstevel@tonic-gate 	    + sizeof(u_int32_t) + (newitem == NULL ? 0 : newitem->size)
770*7c478bd9Sstevel@tonic-gate 	    + sizeof(makedup);
771*7c478bd9Sstevel@tonic-gate 	if ((ret = __os_malloc(logrec.size, NULL, &logrec.data)) != 0)
772*7c478bd9Sstevel@tonic-gate 		return (ret);
773*7c478bd9Sstevel@tonic-gate 
774*7c478bd9Sstevel@tonic-gate 	bp = logrec.data;
775*7c478bd9Sstevel@tonic-gate 	memcpy(bp, &rectype, sizeof(rectype));
776*7c478bd9Sstevel@tonic-gate 	bp += sizeof(rectype);
777*7c478bd9Sstevel@tonic-gate 	memcpy(bp, &txn_num, sizeof(txn_num));
778*7c478bd9Sstevel@tonic-gate 	bp += sizeof(txn_num);
779*7c478bd9Sstevel@tonic-gate 	memcpy(bp, lsnp, sizeof(DB_LSN));
780*7c478bd9Sstevel@tonic-gate 	bp += sizeof(DB_LSN);
781*7c478bd9Sstevel@tonic-gate 	memcpy(bp, &fileid, sizeof(fileid));
782*7c478bd9Sstevel@tonic-gate 	bp += sizeof(fileid);
783*7c478bd9Sstevel@tonic-gate 	memcpy(bp, &pgno, sizeof(pgno));
784*7c478bd9Sstevel@tonic-gate 	bp += sizeof(pgno);
785*7c478bd9Sstevel@tonic-gate 	memcpy(bp, &ndx, sizeof(ndx));
786*7c478bd9Sstevel@tonic-gate 	bp += sizeof(ndx);
787*7c478bd9Sstevel@tonic-gate 	if (pagelsn != NULL)
788*7c478bd9Sstevel@tonic-gate 		memcpy(bp, pagelsn, sizeof(*pagelsn));
789*7c478bd9Sstevel@tonic-gate 	else
790*7c478bd9Sstevel@tonic-gate 		memset(bp, 0, sizeof(*pagelsn));
791*7c478bd9Sstevel@tonic-gate 	bp += sizeof(*pagelsn);
792*7c478bd9Sstevel@tonic-gate 	memcpy(bp, &off, sizeof(off));
793*7c478bd9Sstevel@tonic-gate 	bp += sizeof(off);
794*7c478bd9Sstevel@tonic-gate 	if (olditem == NULL) {
795*7c478bd9Sstevel@tonic-gate 		zero = 0;
796*7c478bd9Sstevel@tonic-gate 		memcpy(bp, &zero, sizeof(u_int32_t));
797*7c478bd9Sstevel@tonic-gate 		bp += sizeof(u_int32_t);
798*7c478bd9Sstevel@tonic-gate 	} else {
799*7c478bd9Sstevel@tonic-gate 		memcpy(bp, &olditem->size, sizeof(olditem->size));
800*7c478bd9Sstevel@tonic-gate 		bp += sizeof(olditem->size);
801*7c478bd9Sstevel@tonic-gate 		memcpy(bp, olditem->data, olditem->size);
802*7c478bd9Sstevel@tonic-gate 		bp += olditem->size;
803*7c478bd9Sstevel@tonic-gate 	}
804*7c478bd9Sstevel@tonic-gate 	if (newitem == NULL) {
805*7c478bd9Sstevel@tonic-gate 		zero = 0;
806*7c478bd9Sstevel@tonic-gate 		memcpy(bp, &zero, sizeof(u_int32_t));
807*7c478bd9Sstevel@tonic-gate 		bp += sizeof(u_int32_t);
808*7c478bd9Sstevel@tonic-gate 	} else {
809*7c478bd9Sstevel@tonic-gate 		memcpy(bp, &newitem->size, sizeof(newitem->size));
810*7c478bd9Sstevel@tonic-gate 		bp += sizeof(newitem->size);
811*7c478bd9Sstevel@tonic-gate 		memcpy(bp, newitem->data, newitem->size);
812*7c478bd9Sstevel@tonic-gate 		bp += newitem->size;
813*7c478bd9Sstevel@tonic-gate 	}
814*7c478bd9Sstevel@tonic-gate 	memcpy(bp, &makedup, sizeof(makedup));
815*7c478bd9Sstevel@tonic-gate 	bp += sizeof(makedup);
816*7c478bd9Sstevel@tonic-gate #ifdef DIAGNOSTIC
817*7c478bd9Sstevel@tonic-gate 	if ((u_int32_t)(bp - (u_int8_t *)logrec.data) != logrec.size)
818*7c478bd9Sstevel@tonic-gate 		fprintf(stderr, "Error in log record length");
819*7c478bd9Sstevel@tonic-gate #endif
820*7c478bd9Sstevel@tonic-gate 	ret = log_put(logp, ret_lsnp, (DBT *)&logrec, flags);
821*7c478bd9Sstevel@tonic-gate 	if (txnid != NULL)
822*7c478bd9Sstevel@tonic-gate 		txnid->last_lsn = *ret_lsnp;
823*7c478bd9Sstevel@tonic-gate 	__os_free(logrec.data, 0);
824*7c478bd9Sstevel@tonic-gate 	return (ret);
825*7c478bd9Sstevel@tonic-gate }
826*7c478bd9Sstevel@tonic-gate 
827*7c478bd9Sstevel@tonic-gate /*
828*7c478bd9Sstevel@tonic-gate  * PUBLIC: int __ham_replace_print
829*7c478bd9Sstevel@tonic-gate  * PUBLIC:    __P((DB_LOG *, DBT *, DB_LSN *, int, void *));
830*7c478bd9Sstevel@tonic-gate  */
831*7c478bd9Sstevel@tonic-gate int
__ham_replace_print(notused1,dbtp,lsnp,notused2,notused3)832*7c478bd9Sstevel@tonic-gate __ham_replace_print(notused1, dbtp, lsnp, notused2, notused3)
833*7c478bd9Sstevel@tonic-gate 	DB_LOG *notused1;
834*7c478bd9Sstevel@tonic-gate 	DBT *dbtp;
835*7c478bd9Sstevel@tonic-gate 	DB_LSN *lsnp;
836*7c478bd9Sstevel@tonic-gate 	int notused2;
837*7c478bd9Sstevel@tonic-gate 	void *notused3;
838*7c478bd9Sstevel@tonic-gate {
839*7c478bd9Sstevel@tonic-gate 	__ham_replace_args *argp;
840*7c478bd9Sstevel@tonic-gate 	u_int32_t i;
841*7c478bd9Sstevel@tonic-gate 	u_int ch;
842*7c478bd9Sstevel@tonic-gate 	int ret;
843*7c478bd9Sstevel@tonic-gate 
844*7c478bd9Sstevel@tonic-gate 	i = 0;
845*7c478bd9Sstevel@tonic-gate 	ch = 0;
846*7c478bd9Sstevel@tonic-gate 	notused1 = NULL;
847*7c478bd9Sstevel@tonic-gate 	notused2 = 0;
848*7c478bd9Sstevel@tonic-gate 	notused3 = NULL;
849*7c478bd9Sstevel@tonic-gate 
850*7c478bd9Sstevel@tonic-gate 	if ((ret = __ham_replace_read(dbtp->data, &argp)) != 0)
851*7c478bd9Sstevel@tonic-gate 		return (ret);
852*7c478bd9Sstevel@tonic-gate 	printf("[%lu][%lu]ham_replace: rec: %lu txnid %lx prevlsn [%lu][%lu]\n",
853*7c478bd9Sstevel@tonic-gate 	    (u_long)lsnp->file,
854*7c478bd9Sstevel@tonic-gate 	    (u_long)lsnp->offset,
855*7c478bd9Sstevel@tonic-gate 	    (u_long)argp->type,
856*7c478bd9Sstevel@tonic-gate 	    (u_long)argp->txnid->txnid,
857*7c478bd9Sstevel@tonic-gate 	    (u_long)argp->prev_lsn.file,
858*7c478bd9Sstevel@tonic-gate 	    (u_long)argp->prev_lsn.offset);
859*7c478bd9Sstevel@tonic-gate 	printf("\tfileid: %lu\n", (u_long)argp->fileid);
860*7c478bd9Sstevel@tonic-gate 	printf("\tpgno: %lu\n", (u_long)argp->pgno);
861*7c478bd9Sstevel@tonic-gate 	printf("\tndx: %lu\n", (u_long)argp->ndx);
862*7c478bd9Sstevel@tonic-gate 	printf("\tpagelsn: [%lu][%lu]\n",
863*7c478bd9Sstevel@tonic-gate 	    (u_long)argp->pagelsn.file, (u_long)argp->pagelsn.offset);
864*7c478bd9Sstevel@tonic-gate 	printf("\toff: %ld\n", (long)argp->off);
865*7c478bd9Sstevel@tonic-gate 	printf("\tolditem: ");
866*7c478bd9Sstevel@tonic-gate 	for (i = 0; i < argp->olditem.size; i++) {
867*7c478bd9Sstevel@tonic-gate 		ch = ((u_int8_t *)argp->olditem.data)[i];
868*7c478bd9Sstevel@tonic-gate 		if (isprint(ch) || ch == 0xa)
869*7c478bd9Sstevel@tonic-gate 			putchar(ch);
870*7c478bd9Sstevel@tonic-gate 		else
871*7c478bd9Sstevel@tonic-gate 			printf("%#x ", ch);
872*7c478bd9Sstevel@tonic-gate 	}
873*7c478bd9Sstevel@tonic-gate 	printf("\n");
874*7c478bd9Sstevel@tonic-gate 	printf("\tnewitem: ");
875*7c478bd9Sstevel@tonic-gate 	for (i = 0; i < argp->newitem.size; i++) {
876*7c478bd9Sstevel@tonic-gate 		ch = ((u_int8_t *)argp->newitem.data)[i];
877*7c478bd9Sstevel@tonic-gate 		if (isprint(ch) || ch == 0xa)
878*7c478bd9Sstevel@tonic-gate 			putchar(ch);
879*7c478bd9Sstevel@tonic-gate 		else
880*7c478bd9Sstevel@tonic-gate 			printf("%#x ", ch);
881*7c478bd9Sstevel@tonic-gate 	}
882*7c478bd9Sstevel@tonic-gate 	printf("\n");
883*7c478bd9Sstevel@tonic-gate 	printf("\tmakedup: %lu\n", (u_long)argp->makedup);
884*7c478bd9Sstevel@tonic-gate 	printf("\n");
885*7c478bd9Sstevel@tonic-gate 	__os_free(argp, 0);
886*7c478bd9Sstevel@tonic-gate 	return (0);
887*7c478bd9Sstevel@tonic-gate }
888*7c478bd9Sstevel@tonic-gate 
889*7c478bd9Sstevel@tonic-gate /*
890*7c478bd9Sstevel@tonic-gate  * PUBLIC: int __ham_replace_read __P((void *, __ham_replace_args **));
891*7c478bd9Sstevel@tonic-gate  */
892*7c478bd9Sstevel@tonic-gate int
__ham_replace_read(recbuf,argpp)893*7c478bd9Sstevel@tonic-gate __ham_replace_read(recbuf, argpp)
894*7c478bd9Sstevel@tonic-gate 	void *recbuf;
895*7c478bd9Sstevel@tonic-gate 	__ham_replace_args **argpp;
896*7c478bd9Sstevel@tonic-gate {
897*7c478bd9Sstevel@tonic-gate 	__ham_replace_args *argp;
898*7c478bd9Sstevel@tonic-gate 	u_int8_t *bp;
899*7c478bd9Sstevel@tonic-gate 	int ret;
900*7c478bd9Sstevel@tonic-gate 
901*7c478bd9Sstevel@tonic-gate 	ret = __os_malloc(sizeof(__ham_replace_args) +
902*7c478bd9Sstevel@tonic-gate 	    sizeof(DB_TXN), NULL, &argp);
903*7c478bd9Sstevel@tonic-gate 	if (ret != 0)
904*7c478bd9Sstevel@tonic-gate 		return (ret);
905*7c478bd9Sstevel@tonic-gate 	argp->txnid = (DB_TXN *)&argp[1];
906*7c478bd9Sstevel@tonic-gate 	bp = recbuf;
907*7c478bd9Sstevel@tonic-gate 	memcpy(&argp->type, bp, sizeof(argp->type));
908*7c478bd9Sstevel@tonic-gate 	bp += sizeof(argp->type);
909*7c478bd9Sstevel@tonic-gate 	memcpy(&argp->txnid->txnid,  bp, sizeof(argp->txnid->txnid));
910*7c478bd9Sstevel@tonic-gate 	bp += sizeof(argp->txnid->txnid);
911*7c478bd9Sstevel@tonic-gate 	memcpy(&argp->prev_lsn, bp, sizeof(DB_LSN));
912*7c478bd9Sstevel@tonic-gate 	bp += sizeof(DB_LSN);
913*7c478bd9Sstevel@tonic-gate 	memcpy(&argp->fileid, bp, sizeof(argp->fileid));
914*7c478bd9Sstevel@tonic-gate 	bp += sizeof(argp->fileid);
915*7c478bd9Sstevel@tonic-gate 	memcpy(&argp->pgno, bp, sizeof(argp->pgno));
916*7c478bd9Sstevel@tonic-gate 	bp += sizeof(argp->pgno);
917*7c478bd9Sstevel@tonic-gate 	memcpy(&argp->ndx, bp, sizeof(argp->ndx));
918*7c478bd9Sstevel@tonic-gate 	bp += sizeof(argp->ndx);
919*7c478bd9Sstevel@tonic-gate 	memcpy(&argp->pagelsn, bp,  sizeof(argp->pagelsn));
920*7c478bd9Sstevel@tonic-gate 	bp += sizeof(argp->pagelsn);
921*7c478bd9Sstevel@tonic-gate 	memcpy(&argp->off, bp, sizeof(argp->off));
922*7c478bd9Sstevel@tonic-gate 	bp += sizeof(argp->off);
923*7c478bd9Sstevel@tonic-gate 	memcpy(&argp->olditem.size, bp, sizeof(u_int32_t));
924*7c478bd9Sstevel@tonic-gate 	bp += sizeof(u_int32_t);
925*7c478bd9Sstevel@tonic-gate 	argp->olditem.data = bp;
926*7c478bd9Sstevel@tonic-gate 	bp += argp->olditem.size;
927*7c478bd9Sstevel@tonic-gate 	memcpy(&argp->newitem.size, bp, sizeof(u_int32_t));
928*7c478bd9Sstevel@tonic-gate 	bp += sizeof(u_int32_t);
929*7c478bd9Sstevel@tonic-gate 	argp->newitem.data = bp;
930*7c478bd9Sstevel@tonic-gate 	bp += argp->newitem.size;
931*7c478bd9Sstevel@tonic-gate 	memcpy(&argp->makedup, bp, sizeof(argp->makedup));
932*7c478bd9Sstevel@tonic-gate 	bp += sizeof(argp->makedup);
933*7c478bd9Sstevel@tonic-gate 	*argpp = argp;
934*7c478bd9Sstevel@tonic-gate 	return (0);
935*7c478bd9Sstevel@tonic-gate }
936*7c478bd9Sstevel@tonic-gate 
937*7c478bd9Sstevel@tonic-gate /*
938*7c478bd9Sstevel@tonic-gate  * PUBLIC: int __ham_newpgno_log
939*7c478bd9Sstevel@tonic-gate  * PUBLIC:     __P((DB_LOG *, DB_TXN *, DB_LSN *, u_int32_t,
940*7c478bd9Sstevel@tonic-gate  * PUBLIC:     u_int32_t, u_int32_t, db_pgno_t, db_pgno_t,
941*7c478bd9Sstevel@tonic-gate  * PUBLIC:     u_int32_t, db_pgno_t, u_int32_t, DB_LSN *,
942*7c478bd9Sstevel@tonic-gate  * PUBLIC:     DB_LSN *));
943*7c478bd9Sstevel@tonic-gate  */
__ham_newpgno_log(logp,txnid,ret_lsnp,flags,opcode,fileid,pgno,free_pgno,old_type,old_pgno,new_type,pagelsn,metalsn)944*7c478bd9Sstevel@tonic-gate int __ham_newpgno_log(logp, txnid, ret_lsnp, flags,
945*7c478bd9Sstevel@tonic-gate 	opcode, fileid, pgno, free_pgno, old_type, old_pgno,
946*7c478bd9Sstevel@tonic-gate 	new_type, pagelsn, metalsn)
947*7c478bd9Sstevel@tonic-gate 	DB_LOG *logp;
948*7c478bd9Sstevel@tonic-gate 	DB_TXN *txnid;
949*7c478bd9Sstevel@tonic-gate 	DB_LSN *ret_lsnp;
950*7c478bd9Sstevel@tonic-gate 	u_int32_t flags;
951*7c478bd9Sstevel@tonic-gate 	u_int32_t opcode;
952*7c478bd9Sstevel@tonic-gate 	u_int32_t fileid;
953*7c478bd9Sstevel@tonic-gate 	db_pgno_t pgno;
954*7c478bd9Sstevel@tonic-gate 	db_pgno_t free_pgno;
955*7c478bd9Sstevel@tonic-gate 	u_int32_t old_type;
956*7c478bd9Sstevel@tonic-gate 	db_pgno_t old_pgno;
957*7c478bd9Sstevel@tonic-gate 	u_int32_t new_type;
958*7c478bd9Sstevel@tonic-gate 	DB_LSN * pagelsn;
959*7c478bd9Sstevel@tonic-gate 	DB_LSN * metalsn;
960*7c478bd9Sstevel@tonic-gate {
961*7c478bd9Sstevel@tonic-gate 	DBT logrec;
962*7c478bd9Sstevel@tonic-gate 	DB_LSN *lsnp, null_lsn;
963*7c478bd9Sstevel@tonic-gate 	u_int32_t rectype, txn_num;
964*7c478bd9Sstevel@tonic-gate 	int ret;
965*7c478bd9Sstevel@tonic-gate 	u_int8_t *bp;
966*7c478bd9Sstevel@tonic-gate 
967*7c478bd9Sstevel@tonic-gate 	rectype = DB_ham_newpgno;
968*7c478bd9Sstevel@tonic-gate 	txn_num = txnid == NULL ? 0 : txnid->txnid;
969*7c478bd9Sstevel@tonic-gate 	if (txnid == NULL) {
970*7c478bd9Sstevel@tonic-gate 		ZERO_LSN(null_lsn);
971*7c478bd9Sstevel@tonic-gate 		lsnp = &null_lsn;
972*7c478bd9Sstevel@tonic-gate 	} else
973*7c478bd9Sstevel@tonic-gate 		lsnp = &txnid->last_lsn;
974*7c478bd9Sstevel@tonic-gate 	logrec.size = sizeof(rectype) + sizeof(txn_num) + sizeof(DB_LSN)
975*7c478bd9Sstevel@tonic-gate 	    + sizeof(opcode)
976*7c478bd9Sstevel@tonic-gate 	    + sizeof(fileid)
977*7c478bd9Sstevel@tonic-gate 	    + sizeof(pgno)
978*7c478bd9Sstevel@tonic-gate 	    + sizeof(free_pgno)
979*7c478bd9Sstevel@tonic-gate 	    + sizeof(old_type)
980*7c478bd9Sstevel@tonic-gate 	    + sizeof(old_pgno)
981*7c478bd9Sstevel@tonic-gate 	    + sizeof(new_type)
982*7c478bd9Sstevel@tonic-gate 	    + sizeof(*pagelsn)
983*7c478bd9Sstevel@tonic-gate 	    + sizeof(*metalsn);
984*7c478bd9Sstevel@tonic-gate 	if ((ret = __os_malloc(logrec.size, NULL, &logrec.data)) != 0)
985*7c478bd9Sstevel@tonic-gate 		return (ret);
986*7c478bd9Sstevel@tonic-gate 
987*7c478bd9Sstevel@tonic-gate 	bp = logrec.data;
988*7c478bd9Sstevel@tonic-gate 	memcpy(bp, &rectype, sizeof(rectype));
989*7c478bd9Sstevel@tonic-gate 	bp += sizeof(rectype);
990