17c478bdstevel@tonic-gate/* Do not edit: automatically built by dist/db_gen.sh. */
27c478bdstevel@tonic-gate#include "config.h"
37c478bdstevel@tonic-gate
47c478bdstevel@tonic-gate#ifndef NO_SYSTEM_INCLUDES
57c478bdstevel@tonic-gate#include <ctype.h>
67c478bdstevel@tonic-gate#include <errno.h>
77c478bdstevel@tonic-gate#include <stddef.h>
87c478bdstevel@tonic-gate#include <stdlib.h>
97c478bdstevel@tonic-gate#include <string.h>
107c478bdstevel@tonic-gate#endif
117c478bdstevel@tonic-gate
127c478bdstevel@tonic-gate#include "db_int.h"
137c478bdstevel@tonic-gate#include "db_page.h"
147c478bdstevel@tonic-gate#include "db_dispatch.h"
157c478bdstevel@tonic-gate#include "txn.h"
167c478bdstevel@tonic-gate#include "db_am.h"
177c478bdstevel@tonic-gate/*
187c478bdstevel@tonic-gate * PUBLIC: int __txn_regop_log
197c478bdstevel@tonic-gate * PUBLIC:     __P((DB_LOG *, DB_TXN *, DB_LSN *, u_int32_t,
207c478bdstevel@tonic-gate * PUBLIC:     u_int32_t));
217c478bdstevel@tonic-gate */
227c478bdstevel@tonic-gateint __txn_regop_log(logp, txnid, ret_lsnp, flags,
237c478bdstevel@tonic-gate	opcode)
247c478bdstevel@tonic-gate	DB_LOG *logp;
257c478bdstevel@tonic-gate	DB_TXN *txnid;
267c478bdstevel@tonic-gate	DB_LSN *ret_lsnp;
277c478bdstevel@tonic-gate	u_int32_t flags;
287c478bdstevel@tonic-gate	u_int32_t opcode;
297c478bdstevel@tonic-gate{
307c478bdstevel@tonic-gate	DBT logrec;
317c478bdstevel@tonic-gate	DB_LSN *lsnp, null_lsn;
327c478bdstevel@tonic-gate	u_int32_t rectype, txn_num;
337c478bdstevel@tonic-gate	int ret;
347c478bdstevel@tonic-gate	u_int8_t *bp;
357c478bdstevel@tonic-gate
367c478bdstevel@tonic-gate	rectype = DB_txn_regop;
377c478bdstevel@tonic-gate	txn_num = txnid == NULL ? 0 : txnid->txnid;
387c478bdstevel@tonic-gate	if (txnid == NULL) {
397c478bdstevel@tonic-gate		ZERO_LSN(null_lsn);
407c478bdstevel@tonic-gate		lsnp = &null_lsn;
417c478bdstevel@tonic-gate	} else
427c478bdstevel@tonic-gate		lsnp = &txnid->last_lsn;
437c478bdstevel@tonic-gate	logrec.size = sizeof(rectype) + sizeof(txn_num) + sizeof(DB_LSN)
447c478bdstevel@tonic-gate	    + sizeof(opcode);
457c478bdstevel@tonic-gate	if ((ret = __os_malloc(logrec.size, NULL, &logrec.data)) != 0)
467c478bdstevel@tonic-gate		return (ret);
477c478bdstevel@tonic-gate
487c478bdstevel@tonic-gate	bp = logrec.data;
497c478bdstevel@tonic-gate	memcpy(bp, &rectype, sizeof(rectype));
507c478bdstevel@tonic-gate	bp += sizeof(rectype);
517c478bdstevel@tonic-gate	memcpy(bp, &txn_num, sizeof(txn_num));
527c478bdstevel@tonic-gate	bp += sizeof(txn_num);
537c478bdstevel@tonic-gate	memcpy(bp, lsnp, sizeof(DB_LSN));
547c478bdstevel@tonic-gate	bp += sizeof(DB_LSN);
557c478bdstevel@tonic-gate	memcpy(bp, &opcode, sizeof(opcode));
567c478bdstevel@tonic-gate	bp += sizeof(opcode);
577c478bdstevel@tonic-gate#ifdef DIAGNOSTIC
587c478bdstevel@tonic-gate	if ((u_int32_t)(bp - (u_int8_t *)logrec.data) != logrec.size)
597c478bdstevel@tonic-gate		fprintf(stderr, "Error in log record length");
607c478bdstevel@tonic-gate#endif
617c478bdstevel@tonic-gate	ret = log_put(logp, ret_lsnp, (DBT *)&logrec, flags);
627c478bdstevel@tonic-gate	if (txnid != NULL)
637c478bdstevel@tonic-gate		txnid->last_lsn = *ret_lsnp;
647c478bdstevel@tonic-gate	__os_free(logrec.data, 0);
657c478bdstevel@tonic-gate	return (ret);
667c478bdstevel@tonic-gate}
677c478bdstevel@tonic-gate
687c478bdstevel@tonic-gate/*
697c478bdstevel@tonic-gate * PUBLIC: int __txn_regop_print
707c478bdstevel@tonic-gate * PUBLIC:    __P((DB_LOG *, DBT *, DB_LSN *, int, void *));
717c478bdstevel@tonic-gate */
727c478bdstevel@tonic-gateint
737c478bdstevel@tonic-gate__txn_regop_print(notused1, dbtp, lsnp, notused2, notused3)
747c478bdstevel@tonic-gate	DB_LOG *notused1;
757c478bdstevel@tonic-gate	DBT *dbtp;
767c478bdstevel@tonic-gate	DB_LSN *lsnp;
777c478bdstevel@tonic-gate	int notused2;
787c478bdstevel@tonic-gate	void *notused3;
797c478bdstevel@tonic-gate{
807c478bdstevel@tonic-gate	__txn_regop_args *argp;
817c478bdstevel@tonic-gate	u_int32_t i;
827c478bdstevel@tonic-gate	u_int ch;
837c478bdstevel@tonic-gate	int ret;
847c478bdstevel@tonic-gate
857c478bdstevel@tonic-gate	i = 0;
867c478bdstevel@tonic-gate	ch = 0;
877c478bdstevel@tonic-gate	notused1 = NULL;
887c478bdstevel@tonic-gate	notused2 = 0;
897c478bdstevel@tonic-gate	notused3 = NULL;
907c478bdstevel@tonic-gate
917c478bdstevel@tonic-gate	if ((ret = __txn_regop_read(dbtp->data, &argp)) != 0)
927c478bdstevel@tonic-gate		return (ret);
937c478bdstevel@tonic-gate	printf("[%lu][%lu]txn_regop: rec: %lu txnid %lx prevlsn [%lu][%lu]\n",
947c478bdstevel@tonic-gate	    (u_long)lsnp->file,
957c478bdstevel@tonic-gate	    (u_long)lsnp->offset,
967c478bdstevel@tonic-gate	    (u_long)argp->type,
977c478bdstevel@tonic-gate	    (u_long)argp->txnid->txnid,
987c478bdstevel@tonic-gate	    (u_long)argp->prev_lsn.file,
997c478bdstevel@tonic-gate	    (u_long)argp->prev_lsn.offset);
1007c478bdstevel@tonic-gate	printf("\topcode: %lu\n", (u_long)argp->opcode);
1017c478bdstevel@tonic-gate	printf("\n");
1027c478bdstevel@tonic-gate	__os_free(argp, 0);
1037c478bdstevel@tonic-gate	return (0);
1047c478bdstevel@tonic-gate}
1057c478bdstevel@tonic-gate
1067c478bdstevel@tonic-gate/*
1077c478bdstevel@tonic-gate * PUBLIC: int __txn_regop_read __P((void *, __txn_regop_args **));
1087c478bdstevel@tonic-gate */
1097c478bdstevel@tonic-gateint
1107c478bdstevel@tonic-gate__txn_regop_read(recbuf, argpp)
1117c478bdstevel@tonic-gate	void *recbuf;
1127c478bdstevel@tonic-gate	__txn_regop_args **argpp;
1137c478bdstevel@tonic-gate{
1147c478bdstevel@tonic-gate	__txn_regop_args *argp;
1157c478bdstevel@tonic-gate	u_int8_t *bp;
1167c478bdstevel@tonic-gate	int ret;
1177c478bdstevel@tonic-gate
1187c478bdstevel@tonic-gate	ret = __os_malloc(sizeof(__txn_regop_args) +
1197c478bdstevel@tonic-gate	    sizeof(DB_TXN), NULL, &argp);
1207c478bdstevel@tonic-gate	if (ret != 0)
1217c478bdstevel@tonic-gate		return (ret);
1227c478bdstevel@tonic-gate	argp->txnid = (DB_TXN *)&argp[1];
1237c478bdstevel@tonic-gate	bp = recbuf;
1247c478bdstevel@tonic-gate	memcpy(&argp->type, bp, sizeof(argp->type));
1257c478bdstevel@tonic-gate	bp += sizeof(argp->type);
1267c478bdstevel@tonic-gate	memcpy(&argp->txnid->txnid,  bp, sizeof(argp->txnid->txnid));
1277c478bdstevel@tonic-gate	bp += sizeof(argp->txnid->txnid);
1287c478bdstevel@tonic-gate	memcpy(&argp->prev_lsn, bp, sizeof(DB_LSN));
1297c478bdstevel@tonic-gate	bp += sizeof(DB_LSN);
1307c478bdstevel@tonic-gate	memcpy(&argp->opcode, bp, sizeof(argp->opcode));
1317c478bdstevel@tonic-gate	bp += sizeof(argp->opcode);
1327c478bdstevel@tonic-gate	*argpp = argp;
1337c478bdstevel@tonic-gate	return (0);
1347c478bdstevel@tonic-gate}
1357c478bdstevel@tonic-gate
1367c478bdstevel@tonic-gate/*
1377c478bdstevel@tonic-gate * PUBLIC: int __txn_ckp_log
1387c478bdstevel@tonic-gate * PUBLIC:     __P((DB_LOG *, DB_TXN *, DB_LSN *, u_int32_t,
1397c478bdstevel@tonic-gate * PUBLIC:     DB_LSN *, DB_LSN *));
1407c478bdstevel@tonic-gate */
1417c478bdstevel@tonic-gateint __txn_ckp_log(logp, txnid, ret_lsnp, flags,
1427c478bdstevel@tonic-gate	ckp_lsn, last_ckp)
1437c478bdstevel@tonic-gate	DB_LOG *logp;
1447c478bdstevel@tonic-gate	DB_TXN *txnid;
1457c478bdstevel@tonic-gate	DB_LSN *ret_lsnp;
1467c478bdstevel@tonic-gate	u_int32_t flags;
1477c478bdstevel@tonic-gate	DB_LSN * ckp_lsn;
1487c478bdstevel@tonic-gate	DB_LSN * last_ckp;
1497c478bdstevel@tonic-gate{
1507c478bdstevel@tonic-gate	DBT logrec;
1517c478bdstevel@tonic-gate	DB_LSN *lsnp, null_lsn;
1527c478bdstevel@tonic-gate	u_int32_t rectype, txn_num;
1537c478bdstevel@tonic-gate	int ret;
1547c478bdstevel@tonic-gate	u_int8_t *bp;
1557c478bdstevel@tonic-gate
1567c478bdstevel@tonic-gate	rectype = DB_txn_ckp;
1577c478bdstevel@tonic-gate	txn_num = txnid == NULL ? 0 : txnid->txnid;
1587c478bdstevel@tonic-gate	if (txnid == NULL) {
1597c478bdstevel@tonic-gate		ZERO_LSN(null_lsn);
1607c478bdstevel@tonic-gate		lsnp = &null_lsn;
1617c478bdstevel@tonic-gate	} else
1627c478bdstevel@tonic-gate		lsnp = &txnid->last_lsn;
1637c478bdstevel@tonic-gate	logrec.size = sizeof(rectype) + sizeof(txn_num) + sizeof(DB_LSN)
1647c478bdstevel@tonic-gate	    + sizeof(*ckp_lsn)
1657c478bdstevel@tonic-gate	    + sizeof(*last_ckp);
1667c478bdstevel@tonic-gate	if ((ret = __os_malloc(logrec.size, NULL, &logrec.data)) != 0)
1677c478bdstevel@tonic-gate		return (ret);
1687c478bdstevel@tonic-gate
1697c478bdstevel@tonic-gate	bp = logrec.data;
1707c478bdstevel@tonic-gate	memcpy(bp, &rectype, sizeof(rectype));
1717c478bdstevel@tonic-gate	bp += sizeof(rectype);
1727c478bdstevel@tonic-gate	memcpy(bp, &txn_num, sizeof(txn_num));
1737c478bdstevel@tonic-gate	bp += sizeof(txn_num);
1747c478bdstevel@tonic-gate	memcpy(bp, lsnp, sizeof(DB_LSN));
1757c478bdstevel@tonic-gate	bp += sizeof(DB_LSN);
1767c478bdstevel@tonic-gate	if (ckp_lsn != NULL)
1777c478bdstevel@tonic-gate		memcpy(bp, ckp_lsn, sizeof(*ckp_lsn));
1787c478bdstevel@tonic-gate	else
1797c478bdstevel@tonic-gate		memset(bp, 0, sizeof(*ckp_lsn));
1807c478bdstevel@tonic-gate	bp += sizeof(*ckp_lsn);
1817c478bdstevel@tonic-gate	if (last_ckp != NULL)
1827c478bdstevel@tonic-gate		memcpy(bp, last_ckp, sizeof(*last_ckp));
1837c478bdstevel@tonic-gate	else
1847c478bdstevel@tonic-gate		memset(bp, 0, sizeof(*last_ckp));
1857c478bdstevel@tonic-gate	bp += sizeof(*last_ckp);
1867c478bdstevel@tonic-gate#ifdef DIAGNOSTIC
1877c478bdstevel@tonic-gate	if ((u_int32_t)(bp - (u_int8_t *)logrec.data) != logrec.size)
1887c478bdstevel@tonic-gate		fprintf(stderr, "Error in log record length");
1897c478bdstevel@tonic-gate#endif
1907c478bdstevel@tonic-gate	ret = log_put(logp, ret_lsnp, (DBT *)&logrec, flags);
1917c478bdstevel@tonic-gate	if (txnid != NULL)
1927c478bdstevel@tonic-gate		txnid->last_lsn = *ret_lsnp;
1937c478bdstevel@tonic-gate	__os_free(logrec.data, 0);
1947c478bdstevel@tonic-gate	return (ret);
1957c478bdstevel@tonic-gate}
1967c478bdstevel@tonic-gate
1977c478bdstevel@tonic-gate/*
1987c478bdstevel@tonic-gate * PUBLIC: int __txn_ckp_print
1997c478bdstevel@tonic-gate * PUBLIC:    __P((DB_LOG *, DBT *, DB_LSN *, int, void *));
2007c478bdstevel@tonic-gate */
2017c478bdstevel@tonic-gateint
2027c478bdstevel@tonic-gate__txn_ckp_print(notused1, dbtp, lsnp, notused2, notused3)
2037c478bdstevel@tonic-gate	DB_LOG *notused1;
2047c478bdstevel@tonic-gate	DBT *dbtp;
2057c478bdstevel@tonic-gate	DB_LSN *lsnp;
2067c478bdstevel@tonic-gate	int notused2;
2077c478bdstevel@tonic-gate	void *notused3;
2087c478bdstevel@tonic-gate{
2097c478bdstevel@tonic-gate	__txn_ckp_args *argp;
2107c478bdstevel@tonic-gate	u_int32_t i;
2117c478bdstevel@tonic-gate	u_int ch;
2127c478bdstevel@tonic-gate	int ret;
2137c478bdstevel@tonic-gate
2147c478bdstevel@tonic-gate	i = 0;
2157c478bdstevel@tonic-gate	ch = 0;
2167c478bdstevel@tonic-gate	notused1 = NULL;
2177c478bdstevel@tonic-gate	notused2 = 0;
2187c478bdstevel@tonic-gate	notused3 = NULL;
2197c478bdstevel@tonic-gate
2207c478bdstevel@tonic-gate	if ((ret = __txn_ckp_read(dbtp->data, &argp)) != 0)
2217c478bdstevel@tonic-gate		return (ret);
2227c478bdstevel@tonic-gate	printf("[%lu][%lu]txn_ckp: rec: %lu txnid %lx prevlsn [%lu][%lu]\n",
2237c478bdstevel@tonic-gate	    (u_long)lsnp->file,
2247c478bdstevel@tonic-gate	    (u_long)lsnp->offset,
2257c478bdstevel@tonic-gate	    (u_long)argp->type,
2267c478bdstevel@tonic-gate	    (u_long)argp->txnid->txnid,
2277c478bdstevel@tonic-gate	    (u_long)argp->prev_lsn.file,
2287c478bdstevel@tonic-gate	    (u_long)argp->prev_lsn.offset);
2297c478bdstevel@tonic-gate	printf("\tckp_lsn: [%lu][%lu]\n",
2307c478bdstevel@tonic-gate	    (u_long)argp->ckp_lsn.file, (u_long)argp->ckp_lsn.offset);
2317c478bdstevel@tonic-gate	printf("\tlast_ckp: [%lu][%lu]\n",
2327c478bdstevel@tonic-gate	    (u_long)argp->last_ckp.file, (u_long)argp->last_ckp.offset);
2337c478bdstevel@tonic-gate	printf("\n");
2347c478bdstevel@tonic-gate	__os_free(argp, 0);
2357c478bdstevel@tonic-gate	return (0);
2367c478bdstevel@tonic-gate}
2377c478bdstevel@tonic-gate
2387c478bdstevel@tonic-gate/*
2397c478bdstevel@tonic-gate * PUBLIC: int __txn_ckp_read __P((void *, __txn_ckp_args **));
2407c478bdstevel@tonic-gate */
2417c478bdstevel@tonic-gateint
2427c478bdstevel@tonic-gate__txn_ckp_read(recbuf, argpp)
2437c478bdstevel@tonic-gate	void *recbuf;
2447c478bdstevel@tonic-gate	__txn_ckp_args **argpp;
2457c478bdstevel@tonic-gate{
2467c478bdstevel@tonic-gate	__txn_ckp_args *argp;
2477c478bdstevel@tonic-gate	u_int8_t *bp;
2487c478bdstevel@tonic-gate	int ret;
2497c478bdstevel@tonic-gate
2507c478bdstevel@tonic-gate	ret = __os_malloc(sizeof(__txn_ckp_args) +
2517c478bdstevel@tonic-gate	    sizeof(DB_TXN), NULL, &argp);
2527c478bdstevel@tonic-gate	if (ret != 0)
2537c478bdstevel@tonic-gate		return (ret);
2547c478bdstevel@tonic-gate	argp->txnid = (DB_TXN *)&argp[1];
2557c478bdstevel@tonic-gate	bp = recbuf;
2567c478bdstevel@tonic-gate	memcpy(&argp->type, bp, sizeof(argp->type));
2577c478bdstevel@tonic-gate	bp += sizeof(argp->type);
2587c478bdstevel@tonic-gate	memcpy(&argp->txnid->txnid,  bp, sizeof(argp->txnid->txnid));
2597c478bdstevel@tonic-gate	bp += sizeof(argp->txnid->txnid);
2607c478bdstevel@tonic-gate	memcpy(&argp->prev_lsn, bp, sizeof(DB_LSN));
2617c478bdstevel@tonic-gate	bp += sizeof(DB_LSN);
2627c478bdstevel@tonic-gate	memcpy(&argp->ckp_lsn, bp,  sizeof(argp->ckp_lsn));
2637c478bdstevel@tonic-gate	bp += sizeof(argp->ckp_lsn);
2647c478bdstevel@tonic-gate	memcpy(&argp->last_ckp, bp,  sizeof(argp->last_ckp));
2657c478bdstevel@tonic-gate	bp += sizeof(argp->last_ckp);
2667c478bdstevel@tonic-gate	*argpp = argp;
2677c478bdstevel@tonic-gate	return (0);
2687c478bdstevel@tonic-gate}
2697c478bdstevel@tonic-gate
2707c478bdstevel@tonic-gate/*
2717c478bdstevel@tonic-gate * PUBLIC: int __txn_xa_regop_log
2727c478bdstevel@tonic-gate * PUBLIC:     __P((DB_LOG *, DB_TXN *, DB_LSN *, u_int32_t,
2737c478bdstevel@tonic-gate * PUBLIC:     u_int32_t, const DBT *, int32_t, u_int32_t,
2747c478bdstevel@tonic-gate * PUBLIC:     u_int32_t, DB_LSN *));
2757c478bdstevel@tonic-gate */
2767c478bdstevel@tonic-gateint __txn_xa_regop_log(logp, txnid, ret_lsnp, flags,
2777c478bdstevel@tonic-gate	opcode, xid, formatID, gtrid, bqual, begin_lsn)
2787c478bdstevel@tonic-gate	DB_LOG *logp;
2797c478bdstevel@tonic-gate	DB_TXN *txnid;
2807c478bdstevel@tonic-gate	DB_LSN *ret_lsnp;
2817c478bdstevel@tonic-gate	u_int32_t flags;
2827c478bdstevel@tonic-gate	u_int32_t opcode;
2837c478bdstevel@tonic-gate	const DBT *xid;
2847c478bdstevel@tonic-gate	int32_t formatID;
2857c478bdstevel@tonic-gate	u_int32_t gtrid;
2867c478bdstevel@tonic-gate	u_int32_t bqual;
2877c478bdstevel@tonic-gate	DB_LSN * begin_lsn;
2887c478bdstevel@tonic-gate{
2897c478bdstevel@tonic-gate	DBT logrec;
2907c478bdstevel@tonic-gate	DB_LSN *lsnp, null_lsn;
2917c478bdstevel@tonic-gate	u_int32_t zero;
2927c478bdstevel@tonic-gate	u_int32_t rectype, txn_num;
2937c478bdstevel@tonic-gate	int ret;
2947c478bdstevel@tonic-gate	u_int8_t *bp;
2957c478bdstevel@tonic-gate
2967c478bdstevel@tonic-gate	rectype = DB_txn_xa_regop;
2977c478bdstevel@tonic-gate	txn_num = txnid == NULL ? 0 : txnid->txnid;
2987c478bdstevel@tonic-gate	if (txnid == NULL) {
2997c478bdstevel@tonic-gate		ZERO_LSN(null_lsn);
3007c478bdstevel@tonic-gate		lsnp = &null_lsn;
3017c478bdstevel@tonic-gate	} else
3027c478bdstevel@tonic-gate		lsnp = &txnid->last_lsn;
3037c478bdstevel@tonic-gate	logrec.size = sizeof(rectype) + sizeof(txn_num) + sizeof(DB_LSN)
3047c478bdstevel@tonic-gate	    + sizeof(opcode)
3057c478bdstevel@tonic-gate	    + sizeof(u_int32_t) + (xid == NULL ? 0 : xid->size)
3067c478bdstevel@tonic-gate	    + sizeof(formatID)
3077c478bdstevel@tonic-gate	    + sizeof(gtrid)
3087c478bdstevel@tonic-gate	    + sizeof(bqual)
3097c478bdstevel@tonic-gate	    + sizeof(*begin_lsn);
3107c478bdstevel@tonic-gate	if ((ret = __os_malloc(logrec.size, NULL, &logrec.data)) != 0)
3117c478bdstevel@tonic-gate		return (ret);
3127c478bdstevel@tonic-gate
3137c478bdstevel@tonic-gate	bp = logrec.data;
3147c478bdstevel@tonic-gate	memcpy(bp, &rectype, sizeof(rectype));
3157c478bdstevel@tonic-gate	bp += sizeof(rectype);
3167c478bdstevel@tonic-gate	memcpy(bp, &txn_num, sizeof(txn_num));
3177c478bdstevel@tonic-gate	bp += sizeof(txn_num);
3187c478bdstevel@tonic-gate	memcpy(bp, lsnp, sizeof(DB_LSN));
3197c478bdstevel@tonic-gate	bp += sizeof(DB_LSN);
3207c478bdstevel@tonic-gate	memcpy(bp, &opcode, sizeof(opcode));
3217c478bdstevel@tonic-gate	bp += sizeof(opcode);
3227c478bdstevel@tonic-gate	if (xid == NULL) {
3237c478bdstevel@tonic-gate		zero = 0;
3247c478bdstevel@tonic-gate		memcpy(bp, &zero, sizeof(u_int32_t));
3257c478bdstevel@tonic-gate		bp += sizeof(u_int32_t);
3267c478bdstevel@tonic-gate	} else {
3277c478bdstevel@tonic-gate		memcpy(bp, &xid->size, sizeof(xid->size));
3287c478bdstevel@tonic-gate		bp += sizeof(xid->size);
3297c478bdstevel@tonic-gate		memcpy(bp, xid->data, xid->size);
3307c478bdstevel@tonic-gate		bp += xid->size;
3317c478bdstevel@tonic-gate	}
3327c478bdstevel@tonic-gate	memcpy(bp, &formatID, sizeof(formatID));
3337c478bdstevel@tonic-gate	bp += sizeof(formatID);
3347c478bdstevel@tonic-gate	memcpy(bp, &gtrid, sizeof(gtrid));
3357c478bdstevel@tonic-gate	bp += sizeof(gtrid);
3367c478bdstevel@tonic-gate	memcpy(bp, &bqual, sizeof(bqual));
3377c478bdstevel@tonic-gate	bp += sizeof(bqual);
3387c478bdstevel@tonic-gate	if (begin_lsn != NULL)
3397c478bdstevel@tonic-gate		memcpy(bp, begin_lsn, sizeof(*begin_lsn));
3407c478bdstevel@tonic-gate	else
3417c478bdstevel@tonic-gate		memset(bp, 0, sizeof(*begin_lsn));
3427c478bdstevel@tonic-gate	bp += sizeof(*begin_lsn);
3437c478bdstevel@tonic-gate#ifdef DIAGNOSTIC
3447c478bdstevel@tonic-gate	if ((u_int32_t)(bp - (u_int8_t *)logrec.data) != logrec.size)
3457c478bdstevel@tonic-gate		fprintf(stderr, "Error in log record length");
3467c478bdstevel@tonic-gate#endif
3477c478bdstevel@tonic-gate	ret = log_put(logp, ret_lsnp, (DBT *)&logrec, flags);
3487c478bdstevel@tonic-gate	if (txnid != NULL)
3497c478bdstevel@tonic-gate		txnid->last_lsn = *ret_lsnp;
3507c478bdstevel@tonic-gate	__os_free(logrec.data, 0);
3517c478bdstevel@tonic-gate	return (ret);
3527c478bdstevel@tonic-gate}
3537c478bdstevel@tonic-gate
3547c478bdstevel@tonic-gate/*
3557c478bdstevel@tonic-gate * PUBLIC: int __txn_xa_regop_print
3567c478bdstevel@tonic-gate * PUBLIC:    __P((DB_LOG *, DBT *, DB_LSN *, int, void *));
3577c478bdstevel@tonic-gate */
3587c478bdstevel@tonic-gateint
3597c478bdstevel@tonic-gate__txn_xa_regop_print(notused1, dbtp, lsnp, notused2, notused3)
3607c478bdstevel@tonic-gate	DB_LOG *notused1;
3617c478bdstevel@tonic-gate	DBT *dbtp;
3627c478bdstevel@tonic-gate	DB_LSN *lsnp;
3637c478bdstevel@tonic-gate	int notused2;
3647c478bdstevel@tonic-gate	void *notused3;
3657c478bdstevel@tonic-gate{
3667c478bdstevel@tonic-gate	__txn_xa_regop_args *argp;
3677c478bdstevel@tonic-gate	u_int32_t i;
3687c478bdstevel@tonic-gate	u_int ch;
3697c478bdstevel@tonic-gate	int ret;
3707c478bdstevel@tonic-gate
3717c478bdstevel@tonic-gate	i = 0;
3727c478bdstevel@tonic-gate	ch = 0;
3737c478bdstevel@tonic-gate	notused1 = NULL;
3747c478bdstevel@tonic-gate	notused2 = 0;
3757c478bdstevel@tonic-gate	notused3 = NULL;
3767c478bdstevel@tonic-gate
3777c478bdstevel@tonic-gate	if ((ret = __txn_xa_regop_read(dbtp->data, &argp)) != 0)
3787c478bdstevel@tonic-gate		return (ret);
3797c478bdstevel@tonic-gate	printf("[%lu][%lu]txn_xa_regop: rec: %lu txnid %lx prevlsn [%lu][%lu]\n",
3807c478bdstevel@tonic-gate	    (u_long)lsnp->file,
3817c478bdstevel@tonic-gate	    (u_long)lsnp->offset,
3827c478bdstevel@tonic-gate	    (u_long)argp->type,
3837c478bdstevel@tonic-gate	    (u_long)argp->txnid->txnid,
3847c478bdstevel@tonic-gate	    (u_long)argp->prev_lsn.file,
3857c478bdstevel@tonic-gate	    (u_long)argp->prev_lsn.offset);
3867c478bdstevel@tonic-gate	printf("\topcode: %lu\n", (u_long)argp->opcode);
3877c478bdstevel@tonic-gate	printf("\txid: ");
3887c478bdstevel@tonic-gate	for (i = 0; i < argp->xid.size; i++) {
3897c478bdstevel@tonic-gate		ch = ((u_int8_t *)argp->xid.data)[i];
3907c478bdstevel@tonic-gate		if (isprint(ch) || ch == 0xa)
3917c478bdstevel@tonic-gate			putchar(ch);
3927c478bdstevel@tonic-gate		else
3937c478bdstevel@tonic-gate			printf("%#x ", ch);
3947c478bdstevel@tonic-gate	}
3957c478bdstevel@tonic-gate	printf("\n");
3967c478bdstevel@tonic-gate	printf("\tformatID: %ld\n", (long)argp->formatID);
3977c478bdstevel@tonic-gate	printf("\tgtrid: %u\n", argp->gtrid);
3987c478bdstevel@tonic-gate	printf("\tbqual: %u\n", argp->bqual);
3997c478bdstevel@tonic-gate	printf("\tbegin_lsn: [%lu][%lu]\n",
4007c478bdstevel@tonic-gate	    (u_long)argp->begin_lsn.file, (u_long)argp->begin_lsn.offset);
4017c478bdstevel@tonic-gate	printf("\n");
4027c478bdstevel@tonic-gate	__os_free(argp, 0);
4037c478bdstevel@tonic-gate	return (0);
4047c478bdstevel@tonic-gate}
4057c478bdstevel@tonic-gate
4067c478bdstevel@tonic-gate/*
4077c478bdstevel@tonic-gate * PUBLIC: int __txn_xa_regop_read __P((void *, __txn_xa_regop_args **));
4087c478bdstevel@tonic-gate */
4097c478bdstevel@tonic-gateint
4107c478bdstevel@tonic-gate__txn_xa_regop_read(recbuf, argpp)
4117c478bdstevel@tonic-gate	void *recbuf;
4127c478bdstevel@tonic-gate	__txn_xa_regop_args **argpp;
4137c478bdstevel@tonic-gate{
4147c478bdstevel@tonic-gate	__txn_xa_regop_args *argp;
4157c478bdstevel@tonic-gate	u_int8_t *bp;
4167c478bdstevel@tonic-gate	int ret;
4177c478bdstevel@tonic-gate
4187c478bdstevel@tonic-gate	ret = __os_malloc(sizeof(__txn_xa_regop_args) +
4197c478bdstevel@tonic-gate	    sizeof(DB_TXN), NULL, &argp);
4207c478bdstevel@tonic-gate	if (ret != 0)
4217c478bdstevel@tonic-gate		return (ret);
4227c478bdstevel@tonic-gate	argp->txnid = (DB_TXN *)&argp[1];
4237c478bdstevel@tonic-gate	bp = recbuf;
4247c478bdstevel@tonic-gate	memcpy(&argp->type, bp, sizeof(argp->type));
4257c478bdstevel@tonic-gate	bp += sizeof(argp->type);
4267c478bdstevel@tonic-gate	memcpy(&argp->txnid->txnid,  bp, sizeof(argp->txnid->txnid));
4277c478bdstevel@tonic-gate	bp += sizeof(argp->txnid->txnid);
4287c478bdstevel@tonic-gate	memcpy(&argp->prev_lsn, bp, sizeof(DB_LSN));
4297c478bdstevel@tonic-gate	bp += sizeof(DB_LSN);
4307c478bdstevel@tonic-gate	memcpy(&argp->opcode, bp, sizeof(argp->opcode));
4317c478bdstevel@tonic-gate	bp += sizeof(argp->opcode);
4327c478bdstevel@tonic-gate	memcpy(&argp->xid.size, bp, sizeof(u_int32_t));
4337c478bdstevel@tonic-gate	bp += sizeof(u_int32_t);
4347c478bdstevel@tonic-gate	argp->xid.data = bp;
4357c478bdstevel@tonic-gate	bp += argp->xid.size;
4367c478bdstevel@tonic-gate	memcpy(&argp->formatID, bp, sizeof(argp->formatID));
4377c478bdstevel@tonic-gate	bp += sizeof(argp->formatID);
4387c478bdstevel@tonic-gate	memcpy(&argp->gtrid, bp, sizeof(argp->gtrid));
4397c478bdstevel@tonic-gate	bp += sizeof(argp->gtrid);
4407c478bdstevel@tonic-gate	memcpy(&argp->bqual, bp, sizeof(argp->bqual));
4417c478bdstevel@tonic-gate	bp += sizeof(argp->bqual);
4427c478bdstevel@tonic-gate	memcpy(&argp->begin_lsn, bp,  sizeof(argp->begin_lsn));
4437c478bdstevel@tonic-gate	bp += sizeof(argp->begin_lsn);
4447c478bdstevel@tonic-gate	*argpp = argp;
4457c478bdstevel@tonic-gate	return (0);
4467c478bdstevel@tonic-gate}
4477c478bdstevel@tonic-gate
4487c478bdstevel@tonic-gate/*
4497c478bdstevel@tonic-gate * PUBLIC: int __txn_child_log
4507c478bdstevel@tonic-gate * PUBLIC:     __P((DB_LOG *, DB_TXN *, DB_LSN *, u_int32_t,
4517c478bdstevel@tonic-gate * PUBLIC:     u_int32_t, u_int32_t));
4527c478bdstevel@tonic-gate */
4537c478bdstevel@tonic-gateint __txn_child_log(logp, txnid, ret_lsnp, flags,
4547c478bdstevel@tonic-gate	opcode, parent)
4557c478bdstevel@tonic-gate	DB_LOG *logp;
4567c478bdstevel@tonic-gate	DB_TXN *txnid;
4577c478bdstevel@tonic-gate	DB_LSN *ret_lsnp;
4587c478bdstevel@tonic-gate	u_int32_t flags;
4597c478bdstevel@tonic-gate	u_int32_t opcode;
4607c478bdstevel@tonic-gate	u_int32_t parent;
4617c478bdstevel@tonic-gate{
4627c478bdstevel@tonic-gate	DBT logrec;
4637c478bdstevel@tonic-gate	DB_LSN *lsnp, null_lsn;
4647c478bdstevel@tonic-gate	u_int32_t rectype, txn_num;
4657c478bdstevel@tonic-gate	int ret;
4667c478bdstevel@tonic-gate	u_int8_t *bp;
4677c478bdstevel@tonic-gate
4687c478bdstevel@tonic-gate	rectype = DB_txn_child;
4697c478bdstevel@tonic-gate	txn_num = txnid == NULL ? 0 : txnid->txnid;
4707c478bdstevel@tonic-gate	if (txnid == NULL) {
4717c478bdstevel@tonic-gate		ZERO_LSN(null_lsn);
4727c478bdstevel@tonic-gate		lsnp = &null_lsn;
4737c478bdstevel@tonic-gate	} else
4747c478bdstevel@tonic-gate		lsnp = &txnid->last_lsn;
4757c478bdstevel@tonic-gate	logrec.size = sizeof(rectype) + sizeof(txn_num) + sizeof(DB_LSN)
4767c478bdstevel@tonic-gate	    + sizeof(opcode)
4777c478bdstevel@tonic-gate	    + sizeof(parent);
4787c478bdstevel@tonic-gate	if ((ret = __os_malloc(logrec.size, NULL, &logrec.data)) != 0)
4797c478bdstevel@tonic-gate		return (ret);
4807c478bdstevel@tonic-gate
4817c478bdstevel@tonic-gate	bp = logrec.data;
4827c478bdstevel@tonic-gate	memcpy(bp, &rectype, sizeof(rectype));
4837c478bdstevel@tonic-gate	bp += sizeof(rectype);
4847c478bdstevel@tonic-gate	memcpy(bp, &txn_num, sizeof(txn_num));
4857c478bdstevel@tonic-gate	bp += sizeof(txn_num);
4867c478bdstevel@tonic-gate	memcpy(bp, lsnp, sizeof(DB_LSN));
4877c478bdstevel@tonic-gate	bp += sizeof(DB_LSN);
4887c478bdstevel@tonic-gate	memcpy(bp, &opcode, sizeof(opcode));
4897c478bdstevel@tonic-gate	bp += sizeof(opcode);
4907c478bdstevel@tonic-gate	memcpy(bp, &parent, sizeof(parent));
4917c478bdstevel@tonic-gate	bp += sizeof(parent);
4927c478bdstevel@tonic-gate#ifdef DIAGNOSTIC
4937c478bdstevel@tonic-gate	if ((u_int32_t)(bp - (u_int8_t *)logrec.data) != logrec.size)
4947c478bdstevel@tonic-gate		fprintf(stderr, "Error in log record length");
4957c478bdstevel@tonic-gate#endif
4967c478bdstevel@tonic-gate	ret = log_put(logp, ret_lsnp, (DBT *)&logrec, flags);
4977c478bdstevel@tonic-gate	if (txnid != NULL)
4987c478bdstevel@tonic-gate		txnid->last_lsn = *ret_lsnp;
4997c478bdstevel@tonic-gate	__os_free(logrec.data, 0);
5007c478bdstevel@tonic-gate	return (ret);
5017c478bdstevel@tonic-gate}
5027c478bdstevel@tonic-gate
5037c478bdstevel@tonic-gate/*
5047c478bdstevel@tonic-gate * PUBLIC: int __txn_child_print
5057c478bdstevel@tonic-gate * PUBLIC:    __P((DB_LOG *, DBT *, DB_LSN *, int, void *));
5067c478bdstevel@tonic-gate */
5077c478bdstevel@tonic-gateint
5087c478bdstevel@tonic-gate__txn_child_print(notused1, dbtp, lsnp, notused2, notused3)
5097c478bdstevel@tonic-gate	DB_LOG *notused1;
5107c478bdstevel@tonic-gate	DBT *dbtp;
5117c478bdstevel@tonic-gate	DB_LSN *lsnp;
5127c478bdstevel@tonic-gate	int notused2;
5137c478bdstevel@tonic-gate	void *notused3;
5147c478bdstevel@tonic-gate{
5157c478bdstevel@tonic-gate	__txn_child_args *argp;
5167c478bdstevel@tonic-gate	u_int32_t i;
5177c478bdstevel@tonic-gate	u_int ch;
5187c478bdstevel@tonic-gate	int ret;
5197c478bdstevel@tonic-gate
5207c478bdstevel@tonic-gate	i = 0;
5217c478bdstevel@tonic-gate	ch = 0;
5227c478bdstevel@tonic-gate	notused1 = NULL;
5237c478bdstevel@tonic-gate	notused2 = 0;
5247c478bdstevel@tonic-gate	notused3 = NULL;
5257c478bdstevel@tonic-gate
5267c478bdstevel@tonic-gate	if ((ret = __txn_child_read(dbtp->data, &argp)) != 0)
5277c478bdstevel@tonic-gate		return (ret);
5287c478bdstevel@tonic-gate	printf("[%lu][%lu]txn_child: rec: %lu txnid %lx prevlsn [%lu][%lu]\n",
5297c478bdstevel@tonic-gate	    (u_long)lsnp->file,
5307c478bdstevel@tonic-gate	    (u_long)lsnp->offset,
5317c478bdstevel@tonic-gate	    (u_long)argp->type,
5327c478bdstevel@tonic-gate	    (u_long)argp->txnid->txnid,
5337c478bdstevel@tonic-gate	    (u_long)argp->prev_lsn.file,
5347c478bdstevel@tonic-gate	    (u_long)argp->prev_lsn.offset);
5357c478bdstevel@tonic-gate	printf("\topcode: %lu\n", (u_long)argp->opcode);
5367c478bdstevel@tonic-gate	printf("\tparent: %lu\n", (u_long)argp->parent);
5377c478bdstevel@tonic-gate	printf("\n");
5387c478bdstevel@tonic-gate	__os_free(argp, 0);
5397c478bdstevel@tonic-gate	return (0);
5407c478bdstevel@tonic-gate}
5417c478bdstevel@tonic-gate
5427c478bdstevel@tonic-gate/*
5437c478bdstevel@tonic-gate * PUBLIC: int __txn_child_read __P((void *, __txn_child_args **));
5447c478bdstevel@tonic-gate */
5457c478bdstevel@tonic-gateint
5467c478bdstevel@tonic-gate__txn_child_read(recbuf, argpp)
5477c478bdstevel@tonic-gate	void *recbuf;
5487c478bdstevel@tonic-gate	__txn_child_args **argpp;
5497c478bdstevel@tonic-gate{
5507c478bdstevel@tonic-gate	__txn_child_args *argp;
5517c478bdstevel@tonic-gate	u_int8_t *bp;
5527c478bdstevel@tonic-gate	int ret;
5537c478bdstevel@tonic-gate
5547c478bdstevel@tonic-gate	ret = __os_malloc(sizeof(__txn_child_args) +
5557c478bdstevel@tonic-gate	    sizeof(DB_TXN), NULL, &argp);
5567c478bdstevel@tonic-gate	if (ret != 0)
5577c478bdstevel@tonic-gate		return (ret);
5587c478bdstevel@tonic-gate	argp->txnid = (DB_TXN *)&argp[1];
5597c478bdstevel@tonic-gate	bp = recbuf;
5607c478bdstevel@tonic-gate	memcpy(&argp->type, bp, sizeof(argp->type));
5617c478bdstevel@tonic-gate	bp += sizeof(argp->type);
5627c478bdstevel@tonic-gate	memcpy(&argp->txnid->txnid,  bp, sizeof(argp->txnid->txnid));
5637c478bdstevel@tonic-gate	bp += sizeof(argp->txnid->txnid);
5647c478bdstevel@tonic-gate	memcpy(&argp->prev_lsn, bp, sizeof(DB_LSN));
5657c478bdstevel@tonic-gate	bp += sizeof(DB_LSN);
5667c478bdstevel@tonic-gate	memcpy(&argp->opcode, bp, sizeof(argp->opcode));
5677c478bdstevel@tonic-gate	bp += sizeof(argp->opcode);
5687c478bdstevel@tonic-gate	memcpy(&argp->parent, bp, sizeof(argp->parent));
5697c478bdstevel@tonic-gate	bp += sizeof(argp->parent);
5707c478bdstevel@tonic-gate	*argpp = argp;
5717c478bdstevel@tonic-gate	return (0);
5727c478bdstevel@tonic-gate}
5737c478bdstevel@tonic-gate
5747c478bdstevel@tonic-gate/*
5757c478bdstevel@tonic-gate * PUBLIC: int __txn_init_print __P((DB_ENV *));
5767c478bdstevel@tonic-gate */
5777c478bdstevel@tonic-gateint
5787c478bdstevel@tonic-gate__txn_init_print(dbenv)
5797c478bdstevel@tonic-gate	DB_ENV *dbenv;
5807c478bdstevel@tonic-gate{
5817c478bdstevel@tonic-gate	int ret;
5827c478bdstevel@tonic-gate
5837c478bdstevel@tonic-gate	if ((ret = __db_add_recovery(dbenv,
5847c478bdstevel@tonic-gate	    __txn_regop_print, DB_txn_regop)) != 0)
5857c478bdstevel@tonic-gate		return (ret);
5867c478bdstevel@tonic-gate	if ((ret = __db_add_recovery(dbenv,
5877c478bdstevel@tonic-gate	    __txn_ckp_print, DB_txn_ckp)) != 0)
5887c478bdstevel@tonic-gate		return (ret);
5897c478bdstevel@tonic-gate	if ((ret = __db_add_recovery(dbenv,
5907c478bdstevel@tonic-gate	    __txn_xa_regop_print, DB_txn_xa_regop)) != 0)
5917c478bdstevel@tonic-gate		return (ret);
5927c478bdstevel@tonic-gate	if ((ret = __db_add_recovery(dbenv,
5937c478bdstevel@tonic-gate	    __txn_child_print, DB_txn_child)) != 0)
5947c478bdstevel@tonic-gate		return (ret);
5957c478bdstevel@tonic-gate	return (0);
5967c478bdstevel@tonic-gate}
5977c478bdstevel@tonic-gate
5987c478bdstevel@tonic-gate/*
5997c478bdstevel@tonic-gate * PUBLIC: int __txn_init_recover __P((DB_ENV *));
6007c478bdstevel@tonic-gate */
6017c478bdstevel@tonic-gateint
6027c478bdstevel@tonic-gate__txn_init_recover(dbenv)
6037c478bdstevel@tonic-gate	DB_ENV *dbenv;
6047c478bdstevel@tonic-gate{
6057c478bdstevel@tonic-gate	int ret;
6067c478bdstevel@tonic-gate
6077c478bdstevel@tonic-gate	if ((ret = __db_add_recovery(dbenv,
6087c478bdstevel@tonic-gate	    __txn_regop_recover, DB_txn_regop)) != 0)
6097c478bdstevel@tonic-gate		return (ret);
6107c478bdstevel@tonic-gate	if ((ret = __db_add_recovery(dbenv,
6117c478bdstevel@tonic-gate	    __txn_ckp_recover, DB_txn_ckp)) != 0)
6127c478bdstevel@tonic-gate		return (ret);
6137c478bdstevel@tonic-gate	if ((ret = __db_add_recovery(dbenv,
6147c478bdstevel@tonic-gate	    __txn_xa_regop_recover, DB_txn_xa_regop)) != 0)
6157c478bdstevel@tonic-gate		return (ret);
6167c478bdstevel@tonic-gate	if ((ret = __db_add_recovery(dbenv,
6177c478bdstevel@tonic-gate	    __txn_child_recover, DB_txn_child)) != 0)
6187c478bdstevel@tonic-gate		return (ret);
6197c478bdstevel@tonic-gate	return (0);
6207c478bdstevel@tonic-gate}
6217c478bdstevel@tonic-gate
622