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 "log.h" 16*7c478bd9Sstevel@tonic-gate #include "db_am.h" 17*7c478bd9Sstevel@tonic-gate /* 18*7c478bd9Sstevel@tonic-gate * PUBLIC: int __log_register_log 19*7c478bd9Sstevel@tonic-gate * PUBLIC: __P((DB_LOG *, DB_TXN *, DB_LSN *, u_int32_t, 20*7c478bd9Sstevel@tonic-gate * PUBLIC: u_int32_t, const DBT *, const DBT *, u_int32_t, 21*7c478bd9Sstevel@tonic-gate * PUBLIC: DBTYPE)); 22*7c478bd9Sstevel@tonic-gate */ 23*7c478bd9Sstevel@tonic-gate int __log_register_log(logp, txnid, ret_lsnp, flags, 24*7c478bd9Sstevel@tonic-gate opcode, name, uid, id, ftype) 25*7c478bd9Sstevel@tonic-gate DB_LOG *logp; 26*7c478bd9Sstevel@tonic-gate DB_TXN *txnid; 27*7c478bd9Sstevel@tonic-gate DB_LSN *ret_lsnp; 28*7c478bd9Sstevel@tonic-gate u_int32_t flags; 29*7c478bd9Sstevel@tonic-gate u_int32_t opcode; 30*7c478bd9Sstevel@tonic-gate const DBT *name; 31*7c478bd9Sstevel@tonic-gate const DBT *uid; 32*7c478bd9Sstevel@tonic-gate u_int32_t id; 33*7c478bd9Sstevel@tonic-gate DBTYPE ftype; 34*7c478bd9Sstevel@tonic-gate { 35*7c478bd9Sstevel@tonic-gate DBT logrec; 36*7c478bd9Sstevel@tonic-gate DB_LSN *lsnp, null_lsn; 37*7c478bd9Sstevel@tonic-gate u_int32_t zero; 38*7c478bd9Sstevel@tonic-gate u_int32_t rectype, txn_num; 39*7c478bd9Sstevel@tonic-gate int ret; 40*7c478bd9Sstevel@tonic-gate u_int8_t *bp; 41*7c478bd9Sstevel@tonic-gate 42*7c478bd9Sstevel@tonic-gate rectype = DB_log_register; 43*7c478bd9Sstevel@tonic-gate txn_num = txnid == NULL ? 0 : txnid->txnid; 44*7c478bd9Sstevel@tonic-gate if (txnid == NULL) { 45*7c478bd9Sstevel@tonic-gate ZERO_LSN(null_lsn); 46*7c478bd9Sstevel@tonic-gate lsnp = &null_lsn; 47*7c478bd9Sstevel@tonic-gate } else 48*7c478bd9Sstevel@tonic-gate lsnp = &txnid->last_lsn; 49*7c478bd9Sstevel@tonic-gate logrec.size = sizeof(rectype) + sizeof(txn_num) + sizeof(DB_LSN) 50*7c478bd9Sstevel@tonic-gate + sizeof(opcode) 51*7c478bd9Sstevel@tonic-gate + sizeof(u_int32_t) + (name == NULL ? 0 : name->size) 52*7c478bd9Sstevel@tonic-gate + sizeof(u_int32_t) + (uid == NULL ? 0 : uid->size) 53*7c478bd9Sstevel@tonic-gate + sizeof(id) 54*7c478bd9Sstevel@tonic-gate + sizeof(ftype); 55*7c478bd9Sstevel@tonic-gate if ((ret = __os_malloc(logrec.size, NULL, &logrec.data)) != 0) 56*7c478bd9Sstevel@tonic-gate return (ret); 57*7c478bd9Sstevel@tonic-gate 58*7c478bd9Sstevel@tonic-gate bp = logrec.data; 59*7c478bd9Sstevel@tonic-gate memcpy(bp, &rectype, sizeof(rectype)); 60*7c478bd9Sstevel@tonic-gate bp += sizeof(rectype); 61*7c478bd9Sstevel@tonic-gate memcpy(bp, &txn_num, sizeof(txn_num)); 62*7c478bd9Sstevel@tonic-gate bp += sizeof(txn_num); 63*7c478bd9Sstevel@tonic-gate memcpy(bp, lsnp, sizeof(DB_LSN)); 64*7c478bd9Sstevel@tonic-gate bp += sizeof(DB_LSN); 65*7c478bd9Sstevel@tonic-gate memcpy(bp, &opcode, sizeof(opcode)); 66*7c478bd9Sstevel@tonic-gate bp += sizeof(opcode); 67*7c478bd9Sstevel@tonic-gate if (name == NULL) { 68*7c478bd9Sstevel@tonic-gate zero = 0; 69*7c478bd9Sstevel@tonic-gate memcpy(bp, &zero, sizeof(u_int32_t)); 70*7c478bd9Sstevel@tonic-gate bp += sizeof(u_int32_t); 71*7c478bd9Sstevel@tonic-gate } else { 72*7c478bd9Sstevel@tonic-gate memcpy(bp, &name->size, sizeof(name->size)); 73*7c478bd9Sstevel@tonic-gate bp += sizeof(name->size); 74*7c478bd9Sstevel@tonic-gate memcpy(bp, name->data, name->size); 75*7c478bd9Sstevel@tonic-gate bp += name->size; 76*7c478bd9Sstevel@tonic-gate } 77*7c478bd9Sstevel@tonic-gate if (uid == NULL) { 78*7c478bd9Sstevel@tonic-gate zero = 0; 79*7c478bd9Sstevel@tonic-gate memcpy(bp, &zero, sizeof(u_int32_t)); 80*7c478bd9Sstevel@tonic-gate bp += sizeof(u_int32_t); 81*7c478bd9Sstevel@tonic-gate } else { 82*7c478bd9Sstevel@tonic-gate memcpy(bp, &uid->size, sizeof(uid->size)); 83*7c478bd9Sstevel@tonic-gate bp += sizeof(uid->size); 84*7c478bd9Sstevel@tonic-gate memcpy(bp, uid->data, uid->size); 85*7c478bd9Sstevel@tonic-gate bp += uid->size; 86*7c478bd9Sstevel@tonic-gate } 87*7c478bd9Sstevel@tonic-gate memcpy(bp, &id, sizeof(id)); 88*7c478bd9Sstevel@tonic-gate bp += sizeof(id); 89*7c478bd9Sstevel@tonic-gate memcpy(bp, &ftype, sizeof(ftype)); 90*7c478bd9Sstevel@tonic-gate bp += sizeof(ftype); 91*7c478bd9Sstevel@tonic-gate #ifdef DIAGNOSTIC 92*7c478bd9Sstevel@tonic-gate if ((u_int32_t)(bp - (u_int8_t *)logrec.data) != logrec.size) 93*7c478bd9Sstevel@tonic-gate fprintf(stderr, "Error in log record length"); 94*7c478bd9Sstevel@tonic-gate #endif 95*7c478bd9Sstevel@tonic-gate ret = __log_put(logp, ret_lsnp, (DBT *)&logrec, flags); 96*7c478bd9Sstevel@tonic-gate if (txnid != NULL) 97*7c478bd9Sstevel@tonic-gate txnid->last_lsn = *ret_lsnp; 98*7c478bd9Sstevel@tonic-gate __os_free(logrec.data, 0); 99*7c478bd9Sstevel@tonic-gate return (ret); 100*7c478bd9Sstevel@tonic-gate } 101*7c478bd9Sstevel@tonic-gate 102*7c478bd9Sstevel@tonic-gate /* 103*7c478bd9Sstevel@tonic-gate * PUBLIC: int __log_register_print 104*7c478bd9Sstevel@tonic-gate * PUBLIC: __P((DB_LOG *, DBT *, DB_LSN *, int, void *)); 105*7c478bd9Sstevel@tonic-gate */ 106*7c478bd9Sstevel@tonic-gate int 107*7c478bd9Sstevel@tonic-gate __log_register_print(notused1, dbtp, lsnp, notused2, notused3) 108*7c478bd9Sstevel@tonic-gate DB_LOG *notused1; 109*7c478bd9Sstevel@tonic-gate DBT *dbtp; 110*7c478bd9Sstevel@tonic-gate DB_LSN *lsnp; 111*7c478bd9Sstevel@tonic-gate int notused2; 112*7c478bd9Sstevel@tonic-gate void *notused3; 113*7c478bd9Sstevel@tonic-gate { 114*7c478bd9Sstevel@tonic-gate __log_register_args *argp; 115*7c478bd9Sstevel@tonic-gate u_int32_t i; 116*7c478bd9Sstevel@tonic-gate u_int ch; 117*7c478bd9Sstevel@tonic-gate int ret; 118*7c478bd9Sstevel@tonic-gate 119*7c478bd9Sstevel@tonic-gate i = 0; 120*7c478bd9Sstevel@tonic-gate ch = 0; 121*7c478bd9Sstevel@tonic-gate notused1 = NULL; 122*7c478bd9Sstevel@tonic-gate notused2 = 0; 123*7c478bd9Sstevel@tonic-gate notused3 = NULL; 124*7c478bd9Sstevel@tonic-gate 125*7c478bd9Sstevel@tonic-gate if ((ret = __log_register_read(dbtp->data, &argp)) != 0) 126*7c478bd9Sstevel@tonic-gate return (ret); 127*7c478bd9Sstevel@tonic-gate printf("[%lu][%lu]log_register: rec: %lu txnid %lx prevlsn [%lu][%lu]\n", 128*7c478bd9Sstevel@tonic-gate (u_long)lsnp->file, 129*7c478bd9Sstevel@tonic-gate (u_long)lsnp->offset, 130*7c478bd9Sstevel@tonic-gate (u_long)argp->type, 131*7c478bd9Sstevel@tonic-gate (u_long)argp->txnid->txnid, 132*7c478bd9Sstevel@tonic-gate (u_long)argp->prev_lsn.file, 133*7c478bd9Sstevel@tonic-gate (u_long)argp->prev_lsn.offset); 134*7c478bd9Sstevel@tonic-gate printf("\topcode: %lu\n", (u_long)argp->opcode); 135*7c478bd9Sstevel@tonic-gate printf("\tname: "); 136*7c478bd9Sstevel@tonic-gate for (i = 0; i < argp->name.size; i++) { 137*7c478bd9Sstevel@tonic-gate ch = ((u_int8_t *)argp->name.data)[i]; 138*7c478bd9Sstevel@tonic-gate if (isprint(ch) || ch == 0xa) 139*7c478bd9Sstevel@tonic-gate putchar(ch); 140*7c478bd9Sstevel@tonic-gate else 141*7c478bd9Sstevel@tonic-gate printf("%#x ", ch); 142*7c478bd9Sstevel@tonic-gate } 143*7c478bd9Sstevel@tonic-gate printf("\n"); 144*7c478bd9Sstevel@tonic-gate printf("\tuid: "); 145*7c478bd9Sstevel@tonic-gate for (i = 0; i < argp->uid.size; i++) { 146*7c478bd9Sstevel@tonic-gate ch = ((u_int8_t *)argp->uid.data)[i]; 147*7c478bd9Sstevel@tonic-gate if (isprint(ch) || ch == 0xa) 148*7c478bd9Sstevel@tonic-gate putchar(ch); 149*7c478bd9Sstevel@tonic-gate else 150*7c478bd9Sstevel@tonic-gate printf("%#x ", ch); 151*7c478bd9Sstevel@tonic-gate } 152*7c478bd9Sstevel@tonic-gate printf("\n"); 153*7c478bd9Sstevel@tonic-gate printf("\tid: %lu\n", (u_long)argp->id); 154*7c478bd9Sstevel@tonic-gate printf("\tftype: 0x%lx\n", (u_long)argp->ftype); 155*7c478bd9Sstevel@tonic-gate printf("\n"); 156*7c478bd9Sstevel@tonic-gate __os_free(argp, 0); 157*7c478bd9Sstevel@tonic-gate return (0); 158*7c478bd9Sstevel@tonic-gate } 159*7c478bd9Sstevel@tonic-gate 160*7c478bd9Sstevel@tonic-gate /* 161*7c478bd9Sstevel@tonic-gate * PUBLIC: int __log_register_read __P((void *, __log_register_args **)); 162*7c478bd9Sstevel@tonic-gate */ 163*7c478bd9Sstevel@tonic-gate int 164*7c478bd9Sstevel@tonic-gate __log_register_read(recbuf, argpp) 165*7c478bd9Sstevel@tonic-gate void *recbuf; 166*7c478bd9Sstevel@tonic-gate __log_register_args **argpp; 167*7c478bd9Sstevel@tonic-gate { 168*7c478bd9Sstevel@tonic-gate __log_register_args *argp; 169*7c478bd9Sstevel@tonic-gate u_int8_t *bp; 170*7c478bd9Sstevel@tonic-gate int ret; 171*7c478bd9Sstevel@tonic-gate 172*7c478bd9Sstevel@tonic-gate ret = __os_malloc(sizeof(__log_register_args) + 173*7c478bd9Sstevel@tonic-gate sizeof(DB_TXN), NULL, &argp); 174*7c478bd9Sstevel@tonic-gate if (ret != 0) 175*7c478bd9Sstevel@tonic-gate return (ret); 176*7c478bd9Sstevel@tonic-gate argp->txnid = (DB_TXN *)&argp[1]; 177*7c478bd9Sstevel@tonic-gate bp = recbuf; 178*7c478bd9Sstevel@tonic-gate memcpy(&argp->type, bp, sizeof(argp->type)); 179*7c478bd9Sstevel@tonic-gate bp += sizeof(argp->type); 180*7c478bd9Sstevel@tonic-gate memcpy(&argp->txnid->txnid, bp, sizeof(argp->txnid->txnid)); 181*7c478bd9Sstevel@tonic-gate bp += sizeof(argp->txnid->txnid); 182*7c478bd9Sstevel@tonic-gate memcpy(&argp->prev_lsn, bp, sizeof(DB_LSN)); 183*7c478bd9Sstevel@tonic-gate bp += sizeof(DB_LSN); 184*7c478bd9Sstevel@tonic-gate memcpy(&argp->opcode, bp, sizeof(argp->opcode)); 185*7c478bd9Sstevel@tonic-gate bp += sizeof(argp->opcode); 186*7c478bd9Sstevel@tonic-gate memcpy(&argp->name.size, bp, sizeof(u_int32_t)); 187*7c478bd9Sstevel@tonic-gate bp += sizeof(u_int32_t); 188*7c478bd9Sstevel@tonic-gate argp->name.data = bp; 189*7c478bd9Sstevel@tonic-gate bp += argp->name.size; 190*7c478bd9Sstevel@tonic-gate memcpy(&argp->uid.size, bp, sizeof(u_int32_t)); 191*7c478bd9Sstevel@tonic-gate bp += sizeof(u_int32_t); 192*7c478bd9Sstevel@tonic-gate argp->uid.data = bp; 193*7c478bd9Sstevel@tonic-gate bp += argp->uid.size; 194*7c478bd9Sstevel@tonic-gate memcpy(&argp->id, bp, sizeof(argp->id)); 195*7c478bd9Sstevel@tonic-gate bp += sizeof(argp->id); 196*7c478bd9Sstevel@tonic-gate memcpy(&argp->ftype, bp, sizeof(argp->ftype)); 197*7c478bd9Sstevel@tonic-gate bp += sizeof(argp->ftype); 198*7c478bd9Sstevel@tonic-gate *argpp = argp; 199*7c478bd9Sstevel@tonic-gate return (0); 200*7c478bd9Sstevel@tonic-gate } 201*7c478bd9Sstevel@tonic-gate 202*7c478bd9Sstevel@tonic-gate /* 203*7c478bd9Sstevel@tonic-gate * PUBLIC: int __log_init_print __P((DB_ENV *)); 204*7c478bd9Sstevel@tonic-gate */ 205*7c478bd9Sstevel@tonic-gate int 206*7c478bd9Sstevel@tonic-gate __log_init_print(dbenv) 207*7c478bd9Sstevel@tonic-gate DB_ENV *dbenv; 208*7c478bd9Sstevel@tonic-gate { 209*7c478bd9Sstevel@tonic-gate int ret; 210*7c478bd9Sstevel@tonic-gate 211*7c478bd9Sstevel@tonic-gate if ((ret = __db_add_recovery(dbenv, 212*7c478bd9Sstevel@tonic-gate __log_register_print, DB_log_register)) != 0) 213*7c478bd9Sstevel@tonic-gate return (ret); 214*7c478bd9Sstevel@tonic-gate return (0); 215*7c478bd9Sstevel@tonic-gate } 216*7c478bd9Sstevel@tonic-gate 217*7c478bd9Sstevel@tonic-gate /* 218*7c478bd9Sstevel@tonic-gate * PUBLIC: int __log_init_recover __P((DB_ENV *)); 219*7c478bd9Sstevel@tonic-gate */ 220*7c478bd9Sstevel@tonic-gate int 221*7c478bd9Sstevel@tonic-gate __log_init_recover(dbenv) 222*7c478bd9Sstevel@tonic-gate DB_ENV *dbenv; 223*7c478bd9Sstevel@tonic-gate { 224*7c478bd9Sstevel@tonic-gate int ret; 225*7c478bd9Sstevel@tonic-gate 226*7c478bd9Sstevel@tonic-gate if ((ret = __db_add_recovery(dbenv, 227*7c478bd9Sstevel@tonic-gate __log_register_recover, DB_log_register)) != 0) 228*7c478bd9Sstevel@tonic-gate return (ret); 229*7c478bd9Sstevel@tonic-gate return (0); 230*7c478bd9Sstevel@tonic-gate } 231*7c478bd9Sstevel@tonic-gate 232