1N/A/* Do not edit: automatically built by dist/db_gen.sh. */
1N/A#include "config.h"
1N/A
1N/A#ifndef NO_SYSTEM_INCLUDES
1N/A#include <ctype.h>
1N/A#include <errno.h>
1N/A#include <stddef.h>
1N/A#include <stdlib.h>
1N/A#include <string.h>
1N/A#endif
1N/A
1N/A#include "db_int.h"
1N/A#include "db_page.h"
1N/A#include "db_dispatch.h"
1N/A#include "log.h"
1N/A#include "db_am.h"
1N/A/*
1N/A * PUBLIC: int __log_register_log
1N/A * PUBLIC: __P((DB_LOG *, DB_TXN *, DB_LSN *, u_int32_t,
1N/A * PUBLIC: u_int32_t, const DBT *, const DBT *, u_int32_t,
1N/A * PUBLIC: DBTYPE));
1N/A */
1N/Aint __log_register_log(logp, txnid, ret_lsnp, flags,
1N/A opcode, name, uid, id, ftype)
1N/A DB_LOG *logp;
1N/A DB_TXN *txnid;
1N/A DB_LSN *ret_lsnp;
1N/A u_int32_t flags;
1N/A u_int32_t opcode;
1N/A const DBT *name;
1N/A const DBT *uid;
1N/A u_int32_t id;
1N/A DBTYPE ftype;
1N/A{
1N/A DBT logrec;
1N/A DB_LSN *lsnp, null_lsn;
1N/A u_int32_t zero;
1N/A u_int32_t rectype, txn_num;
1N/A int ret;
1N/A u_int8_t *bp;
1N/A
1N/A rectype = DB_log_register;
1N/A txn_num = txnid == NULL ? 0 : txnid->txnid;
1N/A if (txnid == NULL) {
1N/A ZERO_LSN(null_lsn);
1N/A lsnp = &null_lsn;
1N/A } else
1N/A lsnp = &txnid->last_lsn;
1N/A logrec.size = sizeof(rectype) + sizeof(txn_num) + sizeof(DB_LSN)
1N/A + sizeof(opcode)
1N/A + sizeof(u_int32_t) + (name == NULL ? 0 : name->size)
1N/A + sizeof(u_int32_t) + (uid == NULL ? 0 : uid->size)
1N/A + sizeof(id)
1N/A + sizeof(ftype);
1N/A if ((ret = __os_malloc(logrec.size, NULL, &logrec.data)) != 0)
1N/A return (ret);
1N/A
1N/A bp = logrec.data;
1N/A memcpy(bp, &rectype, sizeof(rectype));
1N/A bp += sizeof(rectype);
1N/A memcpy(bp, &txn_num, sizeof(txn_num));
1N/A bp += sizeof(txn_num);
1N/A memcpy(bp, lsnp, sizeof(DB_LSN));
1N/A bp += sizeof(DB_LSN);
1N/A memcpy(bp, &opcode, sizeof(opcode));
1N/A bp += sizeof(opcode);
1N/A if (name == NULL) {
1N/A zero = 0;
1N/A memcpy(bp, &zero, sizeof(u_int32_t));
1N/A bp += sizeof(u_int32_t);
1N/A } else {
1N/A memcpy(bp, &name->size, sizeof(name->size));
1N/A bp += sizeof(name->size);
1N/A memcpy(bp, name->data, name->size);
1N/A bp += name->size;
1N/A }
1N/A if (uid == NULL) {
1N/A zero = 0;
1N/A memcpy(bp, &zero, sizeof(u_int32_t));
1N/A bp += sizeof(u_int32_t);
1N/A } else {
1N/A memcpy(bp, &uid->size, sizeof(uid->size));
1N/A bp += sizeof(uid->size);
1N/A memcpy(bp, uid->data, uid->size);
1N/A bp += uid->size;
1N/A }
1N/A memcpy(bp, &id, sizeof(id));
1N/A bp += sizeof(id);
1N/A memcpy(bp, &ftype, sizeof(ftype));
1N/A bp += sizeof(ftype);
1N/A#ifdef DIAGNOSTIC
1N/A if ((u_int32_t)(bp - (u_int8_t *)logrec.data) != logrec.size)
1N/A fprintf(stderr, "Error in log record length");
1N/A#endif
1N/A ret = __log_put(logp, ret_lsnp, (DBT *)&logrec, flags);
1N/A if (txnid != NULL)
1N/A txnid->last_lsn = *ret_lsnp;
1N/A __os_free(logrec.data, 0);
1N/A return (ret);
1N/A}
1N/A
1N/A/*
1N/A * PUBLIC: int __log_register_print
1N/A * PUBLIC: __P((DB_LOG *, DBT *, DB_LSN *, int, void *));
1N/A */
1N/Aint
1N/A__log_register_print(notused1, dbtp, lsnp, notused2, notused3)
1N/A DB_LOG *notused1;
1N/A DBT *dbtp;
1N/A DB_LSN *lsnp;
1N/A int notused2;
1N/A void *notused3;
1N/A{
1N/A __log_register_args *argp;
1N/A u_int32_t i;
1N/A u_int ch;
1N/A int ret;
1N/A
1N/A i = 0;
1N/A ch = 0;
1N/A notused1 = NULL;
1N/A notused2 = 0;
1N/A notused3 = NULL;
1N/A
1N/A if ((ret = __log_register_read(dbtp->data, &argp)) != 0)
1N/A return (ret);
1N/A printf("[%lu][%lu]log_register: rec: %lu txnid %lx prevlsn [%lu][%lu]\n",
1N/A (u_long)lsnp->file,
1N/A (u_long)lsnp->offset,
1N/A (u_long)argp->type,
1N/A (u_long)argp->txnid->txnid,
1N/A (u_long)argp->prev_lsn.file,
1N/A (u_long)argp->prev_lsn.offset);
1N/A printf("\topcode: %lu\n", (u_long)argp->opcode);
1N/A printf("\tname: ");
1N/A for (i = 0; i < argp->name.size; i++) {
1N/A ch = ((u_int8_t *)argp->name.data)[i];
1N/A if (isprint(ch) || ch == 0xa)
1N/A putchar(ch);
1N/A else
1N/A printf("%#x ", ch);
1N/A }
1N/A printf("\n");
1N/A printf("\tuid: ");
1N/A for (i = 0; i < argp->uid.size; i++) {
1N/A ch = ((u_int8_t *)argp->uid.data)[i];
1N/A if (isprint(ch) || ch == 0xa)
1N/A putchar(ch);
1N/A else
1N/A printf("%#x ", ch);
1N/A }
1N/A printf("\n");
1N/A printf("\tid: %lu\n", (u_long)argp->id);
1N/A printf("\tftype: 0x%lx\n", (u_long)argp->ftype);
1N/A printf("\n");
1N/A __os_free(argp, 0);
1N/A return (0);
1N/A}
1N/A
1N/A/*
1N/A * PUBLIC: int __log_register_read __P((void *, __log_register_args **));
1N/A */
1N/Aint
1N/A__log_register_read(recbuf, argpp)
1N/A void *recbuf;
1N/A __log_register_args **argpp;
1N/A{
1N/A __log_register_args *argp;
1N/A u_int8_t *bp;
1N/A int ret;
1N/A
1N/A ret = __os_malloc(sizeof(__log_register_args) +
1N/A sizeof(DB_TXN), NULL, &argp);
1N/A if (ret != 0)
1N/A return (ret);
1N/A argp->txnid = (DB_TXN *)&argp[1];
1N/A bp = recbuf;
1N/A memcpy(&argp->type, bp, sizeof(argp->type));
1N/A bp += sizeof(argp->type);
1N/A memcpy(&argp->txnid->txnid, bp, sizeof(argp->txnid->txnid));
1N/A bp += sizeof(argp->txnid->txnid);
1N/A memcpy(&argp->prev_lsn, bp, sizeof(DB_LSN));
1N/A bp += sizeof(DB_LSN);
1N/A memcpy(&argp->opcode, bp, sizeof(argp->opcode));
1N/A bp += sizeof(argp->opcode);
1N/A memcpy(&argp->name.size, bp, sizeof(u_int32_t));
1N/A bp += sizeof(u_int32_t);
1N/A argp->name.data = bp;
1N/A bp += argp->name.size;
1N/A memcpy(&argp->uid.size, bp, sizeof(u_int32_t));
1N/A bp += sizeof(u_int32_t);
1N/A argp->uid.data = bp;
1N/A bp += argp->uid.size;
1N/A memcpy(&argp->id, bp, sizeof(argp->id));
1N/A bp += sizeof(argp->id);
1N/A memcpy(&argp->ftype, bp, sizeof(argp->ftype));
1N/A bp += sizeof(argp->ftype);
1N/A *argpp = argp;
1N/A return (0);
1N/A}
1N/A
1N/A/*
1N/A * PUBLIC: int __log_init_print __P((DB_ENV *));
1N/A */
1N/Aint
1N/A__log_init_print(dbenv)
1N/A DB_ENV *dbenv;
1N/A{
1N/A int ret;
1N/A
1N/A if ((ret = __db_add_recovery(dbenv,
1N/A __log_register_print, DB_log_register)) != 0)
1N/A return (ret);
1N/A return (0);
1N/A}
1N/A
1N/A/*
1N/A * PUBLIC: int __log_init_recover __P((DB_ENV *));
1N/A */
1N/Aint
1N/A__log_init_recover(dbenv)
1N/A DB_ENV *dbenv;
1N/A{
1N/A int ret;
1N/A
1N/A if ((ret = __db_add_recovery(dbenv,
1N/A __log_register_recover, DB_log_register)) != 0)
1N/A return (ret);
1N/A return (0);
1N/A}
1N/A