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