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