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