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 "db_am.h"
16 /*
17 * PUBLIC: int __db_addrem_log
18 * PUBLIC: __P((DB_LOG *, DB_TXN *, DB_LSN *, u_int32_t,
19 * PUBLIC: u_int32_t, u_int32_t, db_pgno_t, u_int32_t,
20 * PUBLIC: size_t, const DBT *, const DBT *, DB_LSN *));
21 */
__db_addrem_log(logp,txnid,ret_lsnp,flags,opcode,fileid,pgno,indx,nbytes,hdr,dbt,pagelsn)22 int __db_addrem_log(logp, txnid, ret_lsnp, flags,
23 opcode, fileid, pgno, indx, nbytes, hdr,
24 dbt, pagelsn)
25 DB_LOG *logp;
26 DB_TXN *txnid;
27 DB_LSN *ret_lsnp;
28 u_int32_t flags;
29 u_int32_t opcode;
30 u_int32_t fileid;
31 db_pgno_t pgno;
32 u_int32_t indx;
33 size_t nbytes;
34 const DBT *hdr;
35 const DBT *dbt;
36 DB_LSN * pagelsn;
37 {
38 DBT logrec;
39 DB_LSN *lsnp, null_lsn;
40 u_int32_t zero;
41 u_int32_t rectype, txn_num;
42 int ret;
43 u_int8_t *bp;
44
45 rectype = DB_db_addrem;
46 txn_num = txnid == NULL ? 0 : txnid->txnid;
47 if (txnid == NULL) {
48 ZERO_LSN(null_lsn);
49 lsnp = &null_lsn;
50 } else
51 lsnp = &txnid->last_lsn;
52 logrec.size = sizeof(rectype) + sizeof(txn_num) + sizeof(DB_LSN)
53 + sizeof(opcode)
54 + sizeof(fileid)
55 + sizeof(pgno)
56 + sizeof(indx)
57 + sizeof(nbytes)
58 + sizeof(u_int32_t) + (hdr == NULL ? 0 : hdr->size)
59 + sizeof(u_int32_t) + (dbt == NULL ? 0 : dbt->size)
60 + sizeof(*pagelsn);
61 if ((ret = __os_malloc(logrec.size, NULL, &logrec.data)) != 0)
62 return (ret);
63
64 bp = logrec.data;
65 memcpy(bp, &rectype, sizeof(rectype));
66 bp += sizeof(rectype);
67 memcpy(bp, &txn_num, sizeof(txn_num));
68 bp += sizeof(txn_num);
69 memcpy(bp, lsnp, sizeof(DB_LSN));
70 bp += sizeof(DB_LSN);
71 memcpy(bp, &opcode, sizeof(opcode));
72 bp += sizeof(opcode);
73 memcpy(bp, &fileid, sizeof(fileid));
74 bp += sizeof(fileid);
75 memcpy(bp, &pgno, sizeof(pgno));
76 bp += sizeof(pgno);
77 memcpy(bp, &indx, sizeof(indx));
78 bp += sizeof(indx);
79 memcpy(bp, &nbytes, sizeof(nbytes));
80 bp += sizeof(nbytes);
81 if (hdr == NULL) {
82 zero = 0;
83 memcpy(bp, &zero, sizeof(u_int32_t));
84 bp += sizeof(u_int32_t);
85 } else {
86 memcpy(bp, &hdr->size, sizeof(hdr->size));
87 bp += sizeof(hdr->size);
88 memcpy(bp, hdr->data, hdr->size);
89 bp += hdr->size;
90 }
91 if (dbt == NULL) {
92 zero = 0;
93 memcpy(bp, &zero, sizeof(u_int32_t));
94 bp += sizeof(u_int32_t);
95 } else {
96 memcpy(bp, &dbt->size, sizeof(dbt->size));
97 bp += sizeof(dbt->size);
98 memcpy(bp, dbt->data, dbt->size);
99 bp += dbt->size;
100 }
101 if (pagelsn != NULL)
102 memcpy(bp, pagelsn, sizeof(*pagelsn));
103 else
104 memset(bp, 0, sizeof(*pagelsn));
105 bp += sizeof(*pagelsn);
106 #ifdef DIAGNOSTIC
107 if ((u_int32_t)(bp - (u_int8_t *)logrec.data) != logrec.size)
108 fprintf(stderr, "Error in log record length");
109 #endif
110 ret = log_put(logp, ret_lsnp, (DBT *)&logrec, flags);
111 if (txnid != NULL)
112 txnid->last_lsn = *ret_lsnp;
113 __os_free(logrec.data, 0);
114 return (ret);
115 }
116
117 /*
118 * PUBLIC: int __db_addrem_print
119 * PUBLIC: __P((DB_LOG *, DBT *, DB_LSN *, int, void *));
120 */
121 int
__db_addrem_print(notused1,dbtp,lsnp,notused2,notused3)122 __db_addrem_print(notused1, dbtp, lsnp, notused2, notused3)
123 DB_LOG *notused1;
124 DBT *dbtp;
125 DB_LSN *lsnp;
126 int notused2;
127 void *notused3;
128 {
129 __db_addrem_args *argp;
130 u_int32_t i;
131 u_int ch;
132 int ret;
133
134 i = 0;
135 ch = 0;
136 notused1 = NULL;
137 notused2 = 0;
138 notused3 = NULL;
139
140 if ((ret = __db_addrem_read(dbtp->data, &argp)) != 0)
141 return (ret);
142 printf("[%lu][%lu]db_addrem: rec: %lu txnid %lx prevlsn [%lu][%lu]\n",
143 (u_long)lsnp->file,
144 (u_long)lsnp->offset,
145 (u_long)argp->type,
146 (u_long)argp->txnid->txnid,
147 (u_long)argp->prev_lsn.file,
148 (u_long)argp->prev_lsn.offset);
149 printf("\topcode: %lu\n", (u_long)argp->opcode);
150 printf("\tfileid: %lu\n", (u_long)argp->fileid);
151 printf("\tpgno: %lu\n", (u_long)argp->pgno);
152 printf("\tindx: %lu\n", (u_long)argp->indx);
153 printf("\tnbytes: %lu\n", (u_long)argp->nbytes);
154 printf("\thdr: ");
155 for (i = 0; i < argp->hdr.size; i++) {
156 ch = ((u_int8_t *)argp->hdr.data)[i];
157 if (isprint(ch) || ch == 0xa)
158 putchar(ch);
159 else
160 printf("%#x ", ch);
161 }
162 printf("\n");
163 printf("\tdbt: ");
164 for (i = 0; i < argp->dbt.size; i++) {
165 ch = ((u_int8_t *)argp->dbt.data)[i];
166 if (isprint(ch) || ch == 0xa)
167 putchar(ch);
168 else
169 printf("%#x ", ch);
170 }
171 printf("\n");
172 printf("\tpagelsn: [%lu][%lu]\n",
173 (u_long)argp->pagelsn.file, (u_long)argp->pagelsn.offset);
174 printf("\n");
175 __os_free(argp, 0);
176 return (0);
177 }
178
179 /*
180 * PUBLIC: int __db_addrem_read __P((void *, __db_addrem_args **));
181 */
182 int
__db_addrem_read(recbuf,argpp)183 __db_addrem_read(recbuf, argpp)
184 void *recbuf;
185 __db_addrem_args **argpp;
186 {
187 __db_addrem_args *argp;
188 u_int8_t *bp;
189 int ret;
190
191 ret = __os_malloc(sizeof(__db_addrem_args) +
192 sizeof(DB_TXN), NULL, &argp);
193 if (ret != 0)
194 return (ret);
195 argp->txnid = (DB_TXN *)&argp[1];
196 bp = recbuf;
197 memcpy(&argp->type, bp, sizeof(argp->type));
198 bp += sizeof(argp->type);
199 memcpy(&argp->txnid->txnid, bp, sizeof(argp->txnid->txnid));
200 bp += sizeof(argp->txnid->txnid);
201 memcpy(&argp->prev_lsn, bp, sizeof(DB_LSN));
202 bp += sizeof(DB_LSN);
203 memcpy(&argp->opcode, bp, sizeof(argp->opcode));
204 bp += sizeof(argp->opcode);
205 memcpy(&argp->fileid, bp, sizeof(argp->fileid));
206 bp += sizeof(argp->fileid);
207 memcpy(&argp->pgno, bp, sizeof(argp->pgno));
208 bp += sizeof(argp->pgno);
209 memcpy(&argp->indx, bp, sizeof(argp->indx));
210 bp += sizeof(argp->indx);
211 memcpy(&argp->nbytes, bp, sizeof(argp->nbytes));
212 bp += sizeof(argp->nbytes);
213 memcpy(&argp->hdr.size, bp, sizeof(u_int32_t));
214 bp += sizeof(u_int32_t);
215 argp->hdr.data = bp;
216 bp += argp->hdr.size;
217 memcpy(&argp->dbt.size, bp, sizeof(u_int32_t));
218 bp += sizeof(u_int32_t);
219 argp->dbt.data = bp;
220 bp += argp->dbt.size;
221 memcpy(&argp->pagelsn, bp, sizeof(argp->pagelsn));
222 bp += sizeof(argp->pagelsn);
223 *argpp = argp;
224 return (0);
225 }
226
227 /*
228 * PUBLIC: int __db_split_log
229 * PUBLIC: __P((DB_LOG *, DB_TXN *, DB_LSN *, u_int32_t,
230 * PUBLIC: u_int32_t, u_int32_t, db_pgno_t, const DBT *,
231 * PUBLIC: DB_LSN *));
232 */
__db_split_log(logp,txnid,ret_lsnp,flags,opcode,fileid,pgno,pageimage,pagelsn)233 int __db_split_log(logp, txnid, ret_lsnp, flags,
234 opcode, fileid, pgno, pageimage, pagelsn)
235 DB_LOG *logp;
236 DB_TXN *txnid;
237 DB_LSN *ret_lsnp;
238 u_int32_t flags;
239 u_int32_t opcode;
240 u_int32_t fileid;
241 db_pgno_t pgno;
242 const DBT *pageimage;
243 DB_LSN * pagelsn;
244 {
245 DBT logrec;
246 DB_LSN *lsnp, null_lsn;
247 u_int32_t zero;
248 u_int32_t rectype, txn_num;
249 int ret;
250 u_int8_t *bp;
251
252 rectype = DB_db_split;
253 txn_num = txnid == NULL ? 0 : txnid->txnid;
254 if (txnid == NULL) {
255 ZERO_LSN(null_lsn);
256 lsnp = &null_lsn;
257 } else
258 lsnp = &txnid->last_lsn;
259 logrec.size = sizeof(rectype) + sizeof(txn_num) + sizeof(DB_LSN)
260 + sizeof(opcode)
261 + sizeof(fileid)
262 + sizeof(pgno)
263 + sizeof(u_int32_t) + (pageimage == NULL ? 0 : pageimage->size)
264 + sizeof(*pagelsn);
265 if ((ret = __os_malloc(logrec.size, NULL, &logrec.data)) != 0)
266 return (ret);
267
268 bp = logrec.data;
269 memcpy(bp, &rectype, sizeof(rectype));
270 bp += sizeof(rectype);
271 memcpy(bp, &txn_num, sizeof(txn_num));
272 bp += sizeof(txn_num);
273 memcpy(bp, lsnp, sizeof(DB_LSN));
274 bp += sizeof(DB_LSN);
275 memcpy(bp, &opcode, sizeof(opcode));
276 bp += sizeof(opcode);
277 memcpy(bp, &fileid, sizeof(fileid));
278 bp += sizeof(fileid);
279 memcpy(bp, &pgno, sizeof(pgno));
280 bp += sizeof(pgno);
281 if (pageimage == NULL) {
282 zero = 0;
283 memcpy(bp, &zero, sizeof(u_int32_t));
284 bp += sizeof(u_int32_t);
285 } else {
286 memcpy(bp, &pageimage->size, sizeof(pageimage->size));
287 bp += sizeof(pageimage->size);
288 memcpy(bp, pageimage->data, pageimage->size);
289 bp += pageimage->size;
290 }
291 if (pagelsn != NULL)
292 memcpy(bp, pagelsn, sizeof(*pagelsn));
293 else
294 memset(bp, 0, sizeof(*pagelsn));
295 bp += sizeof(*pagelsn);
296 #ifdef DIAGNOSTIC
297 if ((u_int32_t)(bp - (u_int8_t *)logrec.data) != logrec.size)
298 fprintf(stderr, "Error in log record length");
299 #endif
300 ret = log_put(logp, ret_lsnp, (DBT *)&logrec, flags);
301 if (txnid != NULL)
302 txnid->last_lsn = *ret_lsnp;
303 __os_free(logrec.data, 0);
304 return (ret);
305 }
306
307 /*
308 * PUBLIC: int __db_split_print
309 * PUBLIC: __P((DB_LOG *, DBT *, DB_LSN *, int, void *));
310 */
311 int
__db_split_print(notused1,dbtp,lsnp,notused2,notused3)312 __db_split_print(notused1, dbtp, lsnp, notused2, notused3)
313 DB_LOG *notused1;
314 DBT *dbtp;
315 DB_LSN *lsnp;
316 int notused2;
317 void *notused3;
318 {
319 __db_split_args *argp;
320 u_int32_t i;
321 u_int ch;
322 int ret;
323
324 i = 0;
325 ch = 0;
326 notused1 = NULL;
327 notused2 = 0;
328 notused3 = NULL;
329
330 if ((ret = __db_split_read(dbtp->data, &argp)) != 0)
331 return (ret);
332 printf("[%lu][%lu]db_split: rec: %lu txnid %lx prevlsn [%lu][%lu]\n",
333 (u_long)lsnp->file,
334 (u_long)lsnp->offset,
335 (u_long)argp->type,
336 (u_long)argp->txnid->txnid,
337 (u_long)argp->prev_lsn.file,
338 (u_long)argp->prev_lsn.offset);
339 printf("\topcode: %lu\n", (u_long)argp->opcode);
340 printf("\tfileid: %lu\n", (u_long)argp->fileid);
341 printf("\tpgno: %lu\n", (u_long)argp->pgno);
342 printf("\tpageimage: ");
343 for (i = 0; i < argp->pageimage.size; i++) {
344 ch = ((u_int8_t *)argp->pageimage.data)[i];
345 if (isprint(ch) || ch == 0xa)
346 putchar(ch);
347 else
348 printf("%#x ", ch);
349 }
350 printf("\n");
351 printf("\tpagelsn: [%lu][%lu]\n",
352 (u_long)argp->pagelsn.file, (u_long)argp->pagelsn.offset);
353 printf("\n");
354 __os_free(argp, 0);
355 return (0);
356 }
357
358 /*
359 * PUBLIC: int __db_split_read __P((void *, __db_split_args **));
360 */
361 int
__db_split_read(recbuf,argpp)362 __db_split_read(recbuf, argpp)
363 void *recbuf;
364 __db_split_args **argpp;
365 {
366 __db_split_args *argp;
367 u_int8_t *bp;
368 int ret;
369
370 ret = __os_malloc(sizeof(__db_split_args) +
371 sizeof(DB_TXN), NULL, &argp);
372 if (ret != 0)
373 return (ret);
374 argp->txnid = (DB_TXN *)&argp[1];
375 bp = recbuf;
376 memcpy(&argp->type, bp, sizeof(argp->type));
377 bp += sizeof(argp->type);
378 memcpy(&argp->txnid->txnid, bp, sizeof(argp->txnid->txnid));
379 bp += sizeof(argp->txnid->txnid);
380 memcpy(&argp->prev_lsn, bp, sizeof(DB_LSN));
381 bp += sizeof(DB_LSN);
382 memcpy(&argp->opcode, bp, sizeof(argp->opcode));
383 bp += sizeof(argp->opcode);
384 memcpy(&argp->fileid, bp, sizeof(argp->fileid));
385 bp += sizeof(argp->fileid);
386 memcpy(&argp->pgno, bp, sizeof(argp->pgno));
387 bp += sizeof(argp->pgno);
388 memcpy(&argp->pageimage.size, bp, sizeof(u_int32_t));
389 bp += sizeof(u_int32_t);
390 argp->pageimage.data = bp;
391 bp += argp->pageimage.size;
392 memcpy(&argp->pagelsn, bp, sizeof(argp->pagelsn));
393 bp += sizeof(argp->pagelsn);
394 *argpp = argp;
395 return (0);
396 }
397
398 /*
399 * PUBLIC: int __db_big_log
400 * PUBLIC: __P((DB_LOG *, DB_TXN *, DB_LSN *, u_int32_t,
401 * PUBLIC: u_int32_t, u_int32_t, db_pgno_t, db_pgno_t,
402 * PUBLIC: db_pgno_t, const DBT *, DB_LSN *, DB_LSN *,
403 * PUBLIC: DB_LSN *));
404 */
__db_big_log(logp,txnid,ret_lsnp,flags,opcode,fileid,pgno,prev_pgno,next_pgno,dbt,pagelsn,prevlsn,nextlsn)405 int __db_big_log(logp, txnid, ret_lsnp, flags,
406 opcode, fileid, pgno, prev_pgno, next_pgno, dbt,
407 pagelsn, prevlsn, nextlsn)
408 DB_LOG *logp;
409 DB_TXN *txnid;
410 DB_LSN *ret_lsnp;
411 u_int32_t flags;
412 u_int32_t opcode;
413 u_int32_t fileid;
414 db_pgno_t pgno;
415 db_pgno_t prev_pgno;
416 db_pgno_t next_pgno;
417 const DBT *dbt;
418 DB_LSN * pagelsn;
419 DB_LSN * prevlsn;
420 DB_LSN * nextlsn;
421 {
422 DBT logrec;
423 DB_LSN *lsnp, null_lsn;
424 u_int32_t zero;
425 u_int32_t rectype, txn_num;
426 int ret;
427 u_int8_t *bp;
428
429 rectype = DB_db_big;
430 txn_num = txnid == NULL ? 0 : txnid->txnid;
431 if (txnid == NULL) {
432 ZERO_LSN(null_lsn);
433 lsnp = &null_lsn;
434 } else
435 lsnp = &txnid->last_lsn;
436 logrec.size = sizeof(rectype) + sizeof(txn_num) + sizeof(DB_LSN)
437 + sizeof(opcode)
438 + sizeof(fileid)
439 + sizeof(pgno)
440 + sizeof(prev_pgno)
441 + sizeof(next_pgno)
442 + sizeof(u_int32_t) + (dbt == NULL ? 0 : dbt->size)
443 + sizeof(*pagelsn)
444 + sizeof(*prevlsn)
445 + sizeof(*nextlsn);
446 if ((ret = __os_malloc(logrec.size, NULL, &logrec.data)) != 0)
447 return (ret);
448
449 bp = logrec.data;
450 memcpy(bp, &rectype, sizeof(rectype));
451 bp += sizeof(rectype);
452 memcpy(bp, &txn_num, sizeof(txn_num));
453 bp += sizeof(txn_num);
454 memcpy(bp, lsnp, sizeof(DB_LSN));
455 bp += sizeof(DB_LSN);
456 memcpy(bp, &opcode, sizeof(opcode));
457 bp += sizeof(opcode);
458 memcpy(bp, &fileid, sizeof(fileid));
459 bp += sizeof(fileid);
460 memcpy(bp, &pgno, sizeof(pgno));
461 bp += sizeof(pgno);
462 memcpy(bp, &prev_pgno, sizeof(prev_pgno));
463 bp += sizeof(prev_pgno);
464 memcpy(bp, &next_pgno, sizeof(next_pgno));
465 bp += sizeof(next_pgno);
466 if (dbt == NULL) {
467 zero = 0;
468 memcpy(bp, &zero, sizeof(u_int32_t));
469 bp += sizeof(u_int32_t);
470 } else {
471 memcpy(bp, &dbt->size, sizeof(dbt->size));
472 bp += sizeof(dbt->size);
473 memcpy(bp, dbt->data, dbt->size);
474 bp += dbt->size;
475 }
476 if (pagelsn != NULL)
477 memcpy(bp, pagelsn, sizeof(*pagelsn));
478 else
479 memset(bp, 0, sizeof(*pagelsn));
480 bp += sizeof(*pagelsn);
481 if (prevlsn != NULL)
482 memcpy(bp, prevlsn, sizeof(*prevlsn));
483 else
484 memset(bp, 0, sizeof(*prevlsn));
485 bp += sizeof(*prevlsn);
486 if (nextlsn != NULL)
487 memcpy(bp, nextlsn, sizeof(*nextlsn));
488 else
489 memset(bp, 0, sizeof(*nextlsn));
490 bp += sizeof(*nextlsn);
491 #ifdef DIAGNOSTIC
492 if ((u_int32_t)(bp - (u_int8_t *)logrec.data) != logrec.size)
493 fprintf(stderr, "Error in log record length");
494 #endif
495 ret = log_put(logp, ret_lsnp, (DBT *)&logrec, flags);
496 if (txnid != NULL)
497 txnid->last_lsn = *ret_lsnp;
498 __os_free(logrec.data, 0);
499 return (ret);
500 }
501
502 /*
503 * PUBLIC: int __db_big_print
504 * PUBLIC: __P((DB_LOG *, DBT *, DB_LSN *, int, void *));
505 */
506 int
__db_big_print(notused1,dbtp,lsnp,notused2,notused3)507 __db_big_print(notused1, dbtp, lsnp, notused2, notused3)
508 DB_LOG *notused1;
509 DBT *dbtp;
510 DB_LSN *lsnp;
511 int notused2;
512 void *notused3;
513 {
514 __db_big_args *argp;
515 u_int32_t i;
516 u_int ch;
517 int ret;
518
519 i = 0;
520 ch = 0;
521 notused1 = NULL;
522 notused2 = 0;
523 notused3 = NULL;
524
525 if ((ret = __db_big_read(dbtp->data, &argp)) != 0)
526 return (ret);
527 printf("[%lu][%lu]db_big: rec: %lu txnid %lx prevlsn [%lu][%lu]\n",
528 (u_long)lsnp->file,
529 (u_long)lsnp->offset,
530 (u_long)argp->type,
531 (u_long)argp->txnid->txnid,
532 (u_long)argp->prev_lsn.file,
533 (u_long)argp->prev_lsn.offset);
534 printf("\topcode: %lu\n", (u_long)argp->opcode);
535 printf("\tfileid: %lu\n", (u_long)argp->fileid);
536 printf("\tpgno: %lu\n", (u_long)argp->pgno);
537 printf("\tprev_pgno: %lu\n", (u_long)argp->prev_pgno);
538 printf("\tnext_pgno: %lu\n", (u_long)argp->next_pgno);
539 printf("\tdbt: ");
540 for (i = 0; i < argp->dbt.size; i++) {
541 ch = ((u_int8_t *)argp->dbt.data)[i];
542 if (isprint(ch) || ch == 0xa)
543 putchar(ch);
544 else
545 printf("%#x ", ch);
546 }
547 printf("\n");
548 printf("\tpagelsn: [%lu][%lu]\n",
549 (u_long)argp->pagelsn.file, (u_long)argp->pagelsn.offset);
550 printf("\tprevlsn: [%lu][%lu]\n",
551 (u_long)argp->prevlsn.file, (u_long)argp->prevlsn.offset);
552 printf("\tnextlsn: [%lu][%lu]\n",
553 (u_long)argp->nextlsn.file, (u_long)argp->nextlsn.offset);
554 printf("\n");
555 __os_free(argp, 0);
556 return (0);
557 }
558
559 /*
560 * PUBLIC: int __db_big_read __P((void *, __db_big_args **));
561 */
562 int
__db_big_read(recbuf,argpp)563 __db_big_read(recbuf, argpp)
564 void *recbuf;
565 __db_big_args **argpp;
566 {
567 __db_big_args *argp;
568 u_int8_t *bp;
569 int ret;
570
571 ret = __os_malloc(sizeof(__db_big_args) +
572 sizeof(DB_TXN), NULL, &argp);
573 if (ret != 0)
574 return (ret);
575 argp->txnid = (DB_TXN *)&argp[1];
576 bp = recbuf;
577 memcpy(&argp->type, bp, sizeof(argp->type));
578 bp += sizeof(argp->type);
579 memcpy(&argp->txnid->txnid, bp, sizeof(argp->txnid->txnid));
580 bp += sizeof(argp->txnid->txnid);
581 memcpy(&argp->prev_lsn, bp, sizeof(DB_LSN));
582 bp += sizeof(DB_LSN);
583 memcpy(&argp->opcode, bp, sizeof(argp->opcode));
584 bp += sizeof(argp->opcode);
585 memcpy(&argp->fileid, bp, sizeof(argp->fileid));
586 bp += sizeof(argp->fileid);
587 memcpy(&argp->pgno, bp, sizeof(argp->pgno));
588 bp += sizeof(argp->pgno);
589 memcpy(&argp->prev_pgno, bp, sizeof(argp->prev_pgno));
590 bp += sizeof(argp->prev_pgno);
591 memcpy(&argp->next_pgno, bp, sizeof(argp->next_pgno));
592 bp += sizeof(argp->next_pgno);
593 memcpy(&argp->dbt.size, bp, sizeof(u_int32_t));
594 bp += sizeof(u_int32_t);
595 argp->dbt.data = bp;
596 bp += argp->dbt.size;
597 memcpy(&argp->pagelsn, bp, sizeof(argp->pagelsn));
598 bp += sizeof(argp->pagelsn);
599 memcpy(&argp->prevlsn, bp, sizeof(argp->prevlsn));
600 bp += sizeof(argp->prevlsn);
601 memcpy(&argp->nextlsn, bp, sizeof(argp->nextlsn));
602 bp += sizeof(argp->nextlsn);
603 *argpp = argp;
604 return (0);
605 }
606
607 /*
608 * PUBLIC: int __db_ovref_log
609 * PUBLIC: __P((DB_LOG *, DB_TXN *, DB_LSN *, u_int32_t,
610 * PUBLIC: u_int32_t, db_pgno_t, int32_t, DB_LSN *));
611 */
__db_ovref_log(logp,txnid,ret_lsnp,flags,fileid,pgno,adjust,lsn)612 int __db_ovref_log(logp, txnid, ret_lsnp, flags,
613 fileid, pgno, adjust, lsn)
614 DB_LOG *logp;
615 DB_TXN *txnid;
616 DB_LSN *ret_lsnp;
617 u_int32_t flags;
618 u_int32_t fileid;
619 db_pgno_t pgno;
620 int32_t adjust;
621 DB_LSN * lsn;
622 {
623 DBT logrec;
624 DB_LSN *lsnp, null_lsn;
625 u_int32_t rectype, txn_num;
626 int ret;
627 u_int8_t *bp;
628
629 rectype = DB_db_ovref;
630 txn_num = txnid == NULL ? 0 : txnid->txnid;
631 if (txnid == NULL) {
632 ZERO_LSN(null_lsn);
633 lsnp = &null_lsn;
634 } else
635 lsnp = &txnid->last_lsn;
636 logrec.size = sizeof(rectype) + sizeof(txn_num) + sizeof(DB_LSN)
637 + sizeof(fileid)
638 + sizeof(pgno)
639 + sizeof(adjust)
640 + sizeof(*lsn);
641 if ((ret = __os_malloc(logrec.size, NULL, &logrec.data)) != 0)
642 return (ret);
643
644 bp = logrec.data;
645 memcpy(bp, &rectype, sizeof(rectype));
646 bp += sizeof(rectype);
647 memcpy(bp, &txn_num, sizeof(txn_num));
648 bp += sizeof(txn_num);
649 memcpy(bp, lsnp, sizeof(DB_LSN));
650 bp += sizeof(DB_LSN);
651 memcpy(bp, &fileid, sizeof(fileid));
652 bp += sizeof(fileid);
653 memcpy(bp, &pgno, sizeof(pgno));
654 bp += sizeof(pgno);
655 memcpy(bp, &adjust, sizeof(adjust));
656 bp += sizeof(adjust);
657 if (lsn != NULL)
658 memcpy(bp, lsn, sizeof(*lsn));
659 else
660 memset(bp, 0, sizeof(*lsn));
661 bp += sizeof(*lsn);
662 #ifdef DIAGNOSTIC
663 if ((u_int32_t)(bp - (u_int8_t *)logrec.data) != logrec.size)
664 fprintf(stderr, "Error in log record length");
665 #endif
666 ret = log_put(logp, ret_lsnp, (DBT *)&logrec, flags);
667 if (txnid != NULL)
668 txnid->last_lsn = *ret_lsnp;
669 __os_free(logrec.data, 0);
670 return (ret);
671 }
672
673 /*
674 * PUBLIC: int __db_ovref_print
675 * PUBLIC: __P((DB_LOG *, DBT *, DB_LSN *, int, void *));
676 */
677 int
__db_ovref_print(notused1,dbtp,lsnp,notused2,notused3)678 __db_ovref_print(notused1, dbtp, lsnp, notused2, notused3)
679 DB_LOG *notused1;
680 DBT *dbtp;
681 DB_LSN *lsnp;
682 int notused2;
683 void *notused3;
684 {
685 __db_ovref_args *argp;
686 u_int32_t i;
687 u_int ch;
688 int ret;
689
690 i = 0;
691 ch = 0;
692 notused1 = NULL;
693 notused2 = 0;
694 notused3 = NULL;
695
696 if ((ret = __db_ovref_read(dbtp->data, &argp)) != 0)
697 return (ret);
698 printf("[%lu][%lu]db_ovref: rec: %lu txnid %lx prevlsn [%lu][%lu]\n",
699 (u_long)lsnp->file,
700 (u_long)lsnp->offset,
701 (u_long)argp->type,
702 (u_long)argp->txnid->txnid,
703 (u_long)argp->prev_lsn.file,
704 (u_long)argp->prev_lsn.offset);
705 printf("\tfileid: %lu\n", (u_long)argp->fileid);
706 printf("\tpgno: %lu\n", (u_long)argp->pgno);
707 printf("\tadjust: %ld\n", (long)argp->adjust);
708 printf("\tlsn: [%lu][%lu]\n",
709 (u_long)argp->lsn.file, (u_long)argp->lsn.offset);
710 printf("\n");
711 __os_free(argp, 0);
712 return (0);
713 }
714
715 /*
716 * PUBLIC: int __db_ovref_read __P((void *, __db_ovref_args **));
717 */
718 int
__db_ovref_read(recbuf,argpp)719 __db_ovref_read(recbuf, argpp)
720 void *recbuf;
721 __db_ovref_args **argpp;
722 {
723 __db_ovref_args *argp;
724 u_int8_t *bp;
725 int ret;
726
727 ret = __os_malloc(sizeof(__db_ovref_args) +
728 sizeof(DB_TXN), NULL, &argp);
729 if (ret != 0)
730 return (ret);
731 argp->txnid = (DB_TXN *)&argp[1];
732 bp = recbuf;
733 memcpy(&argp->type, bp, sizeof(argp->type));
734 bp += sizeof(argp->type);
735 memcpy(&argp->txnid->txnid, bp, sizeof(argp->txnid->txnid));
736 bp += sizeof(argp->txnid->txnid);
737 memcpy(&argp->prev_lsn, bp, sizeof(DB_LSN));
738 bp += sizeof(DB_LSN);
739 memcpy(&argp->fileid, bp, sizeof(argp->fileid));
740 bp += sizeof(argp->fileid);
741 memcpy(&argp->pgno, bp, sizeof(argp->pgno));
742 bp += sizeof(argp->pgno);
743 memcpy(&argp->adjust, bp, sizeof(argp->adjust));
744 bp += sizeof(argp->adjust);
745 memcpy(&argp->lsn, bp, sizeof(argp->lsn));
746 bp += sizeof(argp->lsn);
747 *argpp = argp;
748 return (0);
749 }
750
751 /*
752 * PUBLIC: int __db_relink_log
753 * PUBLIC: __P((DB_LOG *, DB_TXN *, DB_LSN *, u_int32_t,
754 * PUBLIC: u_int32_t, u_int32_t, db_pgno_t, DB_LSN *,
755 * PUBLIC: db_pgno_t, DB_LSN *, db_pgno_t, DB_LSN *));
756 */
__db_relink_log(logp,txnid,ret_lsnp,flags,opcode,fileid,pgno,lsn,prev,lsn_prev,next,lsn_next)757 int __db_relink_log(logp, txnid, ret_lsnp, flags,
758 opcode, fileid, pgno, lsn, prev, lsn_prev,
759 next, lsn_next)
760 DB_LOG *logp;
761 DB_TXN *txnid;
762 DB_LSN *ret_lsnp;
763 u_int32_t flags;
764 u_int32_t opcode;
765 u_int32_t fileid;
766 db_pgno_t pgno;
767 DB_LSN * lsn;
768 db_pgno_t prev;
769 DB_LSN * lsn_prev;
770 db_pgno_t next;
771 DB_LSN * lsn_next;
772 {
773 DBT logrec;
774 DB_LSN *lsnp, null_lsn;
775 u_int32_t rectype, txn_num;
776 int ret;
777 u_int8_t *bp;
778
779 rectype = DB_db_relink;
780 txn_num = txnid == NULL ? 0 : txnid->txnid;
781 if (txnid == NULL) {
782 ZERO_LSN(null_lsn);
783 lsnp = &null_lsn;
784 } else
785 lsnp = &txnid->last_lsn;
786 logrec.size = sizeof(rectype) + sizeof(txn_num) + sizeof(DB_LSN)
787 + sizeof(opcode)
788 + sizeof(fileid)
789 + sizeof(pgno)
790 + sizeof(*lsn)
791 + sizeof(prev)
792 + sizeof(*lsn_prev)
793 + sizeof(next)
794 + sizeof(*lsn_next);
795 if ((ret = __os_malloc(logrec.size, NULL, &logrec.data)) != 0)
796 return (ret);
797
798 bp = logrec.data;
799 memcpy(bp, &rectype, sizeof(rectype));
800 bp += sizeof(rectype);
801 memcpy(bp, &txn_num, sizeof(txn_num));
802 bp += sizeof(txn_num);
803 memcpy(bp, lsnp, sizeof(DB_LSN));
804 bp += sizeof(DB_LSN);
805 memcpy(bp, &opcode, sizeof(opcode));
806 bp += sizeof(opcode);
807 memcpy(bp, &fileid, sizeof(fileid));
808 bp += sizeof(fileid);
809 memcpy(bp, &pgno, sizeof(pgno));
810 bp += sizeof(pgno);
811 if (lsn != NULL)
812 memcpy(bp, lsn, sizeof(*lsn));
813 else
814 memset(bp, 0, sizeof(*lsn));
815 bp += sizeof(*lsn);
816 memcpy(bp, &prev, sizeof(prev));
817 bp += sizeof(prev);
818 if (lsn_prev != NULL)
819 memcpy(bp, lsn_prev, sizeof(*lsn_prev));
820 else
821 memset(bp, 0, sizeof(*lsn_prev));
822 bp += sizeof(*lsn_prev);
823 memcpy(bp, &next, sizeof(next));
824 bp += sizeof(next);
825 if (lsn_next != NULL)
826 memcpy(bp, lsn_next, sizeof(*lsn_next));
827 else
828 memset(bp, 0, sizeof(*lsn_next));
829 bp += sizeof(*lsn_next);
830 #ifdef DIAGNOSTIC
831 if ((u_int32_t)(bp - (u_int8_t *)logrec.data) != logrec.size)
832 fprintf(stderr, "Error in log record length");
833 #endif
834 ret = log_put(logp, ret_lsnp, (DBT *)&logrec, flags);
835 if (txnid != NULL)
836 txnid->last_lsn = *ret_lsnp;
837 __os_free(logrec.data, 0);
838 return (ret);
839 }
840
841 /*
842 * PUBLIC: int __db_relink_print
843 * PUBLIC: __P((DB_LOG *, DBT *, DB_LSN *, int, void *));
844 */
845 int
__db_relink_print(notused1,dbtp,lsnp,notused2,notused3)846 __db_relink_print(notused1, dbtp, lsnp, notused2, notused3)
847 DB_LOG *notused1;
848 DBT *dbtp;
849 DB_LSN *lsnp;
850 int notused2;
851 void *notused3;
852 {
853 __db_relink_args *argp;
854 u_int32_t i;
855 u_int ch;
856 int ret;
857
858 i = 0;
859 ch = 0;
860 notused1 = NULL;
861 notused2 = 0;
862 notused3 = NULL;
863
864 if ((ret = __db_relink_read(dbtp->data, &argp)) != 0)
865 return (ret);
866 printf("[%lu][%lu]db_relink: rec: %lu txnid %lx prevlsn [%lu][%lu]\n",
867 (u_long)lsnp->file,
868 (u_long)lsnp->offset,
869 (u_long)argp->type,
870 (u_long)argp->txnid->txnid,
871 (u_long)argp->prev_lsn.file,
872 (u_long)argp->prev_lsn.offset);
873 printf("\topcode: %lu\n", (u_long)argp->opcode);
874 printf("\tfileid: %lu\n", (u_long)argp->fileid);
875 printf("\tpgno: %lu\n", (u_long)argp->pgno);
876 printf("\tlsn: [%lu][%lu]\n",
877 (u_long)argp->lsn.file, (u_long)argp->lsn.offset);
878 printf("\tprev: %lu\n", (u_long)argp->prev);
879 printf("\tlsn_prev: [%lu][%lu]\n",
880 (u_long)argp->lsn_prev.file, (u_long)argp->lsn_prev.offset);
881 printf("\tnext: %lu\n", (u_long)argp->next);
882 printf("\tlsn_next: [%lu][%lu]\n",
883 (u_long)argp->lsn_next.file, (u_long)argp->lsn_next.offset);
884 printf("\n");
885 __os_free(argp, 0);
886 return (0);
887 }
888
889 /*
890 * PUBLIC: int __db_relink_read __P((void *, __db_relink_args **));
891 */
892 int
__db_relink_read(recbuf,argpp)893 __db_relink_read(recbuf, argpp)
894 void *recbuf;
895 __db_relink_args **argpp;
896 {
897 __db_relink_args *argp;
898 u_int8_t *bp;
899 int ret;
900
901 ret = __os_malloc(sizeof(__db_relink_args) +
902 sizeof(DB_TXN), NULL, &argp);
903 if (ret != 0)
904 return (ret);
905 argp->txnid = (DB_TXN *)&argp[1];
906 bp = recbuf;
907 memcpy(&argp->type, bp, sizeof(argp->type));
908 bp += sizeof(argp->type);
909 memcpy(&argp->txnid->txnid, bp, sizeof(argp->txnid->txnid));
910 bp += sizeof(argp->txnid->txnid);
911 memcpy(&argp->prev_lsn, bp, sizeof(DB_LSN));
912 bp += sizeof(DB_LSN);
913 memcpy(&argp->opcode, bp, sizeof(argp->opcode));
914 bp += sizeof(argp->opcode);
915 memcpy(&argp->fileid, bp, sizeof(argp->fileid));
916 bp += sizeof(argp->fileid);
917 memcpy(&argp->pgno, bp, sizeof(argp->pgno));
918 bp += sizeof(argp->pgno);
919 memcpy(&argp->lsn, bp, sizeof(argp->lsn));
920 bp += sizeof(argp->lsn);
921 memcpy(&argp->prev, bp, sizeof(argp->prev));
922 bp += sizeof(argp->prev);
923 memcpy(&argp->lsn_prev, bp, sizeof(argp->lsn_prev));
924 bp += sizeof(argp->lsn_prev);
925 memcpy(&argp->next, bp, sizeof(argp->next));
926 bp += sizeof(argp->next);
927 memcpy(&argp->lsn_next, bp, sizeof(argp->lsn_next));
928 bp += sizeof(argp->lsn_next);
929 *argpp = argp;
930 return (0);
931 }
932
933 /*
934 * PUBLIC: int __db_addpage_log
935 * PUBLIC: __P((DB_LOG *, DB_TXN *, DB_LSN *, u_int32_t,
936 * PUBLIC: u_int32_t, db_pgno_t, DB_LSN *, db_pgno_t,
937 * PUBLIC: DB_LSN *));
938 */
__db_addpage_log(logp,txnid,ret_lsnp,flags,fileid,pgno,lsn,nextpgno,nextlsn)939 int __db_addpage_log(logp, txnid, ret_lsnp, flags,
940 fileid, pgno, lsn, nextpgno, nextlsn)
941 DB_LOG *logp;
942 DB_TXN *txnid;
943 DB_LSN *ret_lsnp;
944 u_int32_t flags;
945 u_int32_t fileid;
946 db_pgno_t pgno;
947 DB_LSN * lsn;
948 db_pgno_t nextpgno;
949 DB_LSN * nextlsn;
950 {
951 DBT logrec;
952 DB_LSN *lsnp, null_lsn;
953 u_int32_t rectype, txn_num;
954 int ret;
955 u_int8_t *bp;
956
957 rectype = DB_db_addpage;
958 txn_num = txnid == NULL ? 0 : txnid->txnid;
959 if (txnid == NULL) {
960 ZERO_LSN(null_lsn);
961 lsnp = &null_lsn;
962 } else
963 lsnp = &txnid->last_lsn;
964 logrec.size = sizeof(rectype) + sizeof(txn_num) + sizeof(DB_LSN)
965 + sizeof(fileid)
966 + sizeof(pgno)
967 + sizeof(*lsn)
968 + sizeof(nextpgno)
969 + sizeof(*nextlsn);
970 if ((ret = __os_malloc(logrec.size, NULL, &logrec.data)) != 0)
971 return (ret);
972
973 bp = logrec.data;
974 memcpy(bp, &rectype, sizeof(rectype));
975 bp += sizeof(rectype);
976 memcpy(bp, &txn_num, sizeof(txn_num));
977 bp += sizeof(txn_num);
978 memcpy(bp, lsnp, sizeof(DB_LSN));
979 bp += sizeof(DB_LSN);
980 memcpy(bp, &fileid, sizeof(fileid));
981 bp += sizeof(fileid);
982 memcpy(bp, &pgno, sizeof(pgno));
983 bp += sizeof(pgno);
984 if (lsn != NULL)
985 memcpy(bp, lsn, sizeof(*lsn));
986 else
987 memset(bp, 0, sizeof(*lsn));
988 bp += sizeof(*lsn);
989 memcpy(bp, &nextpgno, sizeof(nextpgno));
990 bp += sizeof(nextpgno);
991 if (nextlsn != NULL)
992 memcpy(bp, nextlsn, sizeof(*nextlsn));
993 else
994 memset(bp, 0, sizeof(*nextlsn));
995 bp += sizeof(*nextlsn);
996 #ifdef DIAGNOSTIC
997 if ((u_int32_t)(bp - (u_int8_t *)logrec.data) != logrec.size)
998 fprintf(stderr, "Error in log record length");
999 #endif
1000 ret = log_put(logp, ret_lsnp, (DBT *)&logrec, flags);
1001 if (txnid != NULL)
1002 txnid->last_lsn = *ret_lsnp;
1003 __os_free(logrec.data, 0);
1004 return (ret);
1005 }
1006
1007 /*
1008 * PUBLIC: int __db_addpage_print
1009 * PUBLIC: __P((DB_LOG *, DBT *, DB_LSN *, int, void *));
1010 */
1011 int
__db_addpage_print(notused1,dbtp,lsnp,notused2,notused3)1012 __db_addpage_print(notused1, dbtp, lsnp, notused2, notused3)
1013 DB_LOG *notused1;
1014 DBT *dbtp;
1015 DB_LSN *lsnp;
1016 int notused2;
1017 void *notused3;
1018 {
1019 __db_addpage_args *argp;
1020 u_int32_t i;
1021 u_int ch;
1022 int ret;
1023
1024 i = 0;
1025 ch = 0;
1026 notused1 = NULL;
1027 notused2 = 0;
1028 notused3 = NULL;
1029
1030 if ((ret = __db_addpage_read(dbtp->data, &argp)) != 0)
1031 return (ret);
1032 printf("[%lu][%lu]db_addpage: rec: %lu txnid %lx prevlsn [%lu][%lu]\n",
1033 (u_long)lsnp->file,
1034 (u_long)lsnp->offset,
1035 (u_long)argp->type,
1036 (u_long)argp->txnid->txnid,
1037 (u_long)argp->prev_lsn.file,
1038 (u_long)argp->prev_lsn.offset);
1039 printf("\tfileid: %lu\n", (u_long)argp->fileid);
1040 printf("\tpgno: %lu\n", (u_long)argp->pgno);
1041 printf("\tlsn: [%lu][%lu]\n",
1042 (u_long)argp->lsn.file, (u_long)argp->lsn.offset);
1043 printf("\tnextpgno: %lu\n", (u_long)argp->nextpgno);
1044 printf("\tnextlsn: [%lu][%lu]\n",
1045 (u_long)argp->nextlsn.file, (u_long)argp->nextlsn.offset);
1046 printf("\n");
1047 __os_free(argp, 0);
1048 return (0);
1049 }
1050
1051 /*
1052 * PUBLIC: int __db_addpage_read __P((void *, __db_addpage_args **));
1053 */
1054 int
__db_addpage_read(recbuf,argpp)1055 __db_addpage_read(recbuf, argpp)
1056 void *recbuf;
1057 __db_addpage_args **argpp;
1058 {
1059 __db_addpage_args *argp;
1060 u_int8_t *bp;
1061 int ret;
1062
1063 ret = __os_malloc(sizeof(__db_addpage_args) +
1064 sizeof(DB_TXN), NULL, &argp);
1065 if (ret != 0)
1066 return (ret);
1067 argp->txnid = (DB_TXN *)&argp[1];
1068 bp = recbuf;
1069 memcpy(&argp->type, bp, sizeof(argp->type));
1070 bp += sizeof(argp->type);
1071 memcpy(&argp->txnid->txnid, bp, sizeof(argp->txnid->txnid));
1072 bp += sizeof(argp->txnid->txnid);
1073 memcpy(&argp->prev_lsn, bp, sizeof(DB_LSN));
1074 bp += sizeof(DB_LSN);
1075 memcpy(&argp->fileid, bp, sizeof(argp->fileid));
1076 bp += sizeof(argp->fileid);
1077 memcpy(&argp->pgno, bp, sizeof(argp->pgno));
1078 bp += sizeof(argp->pgno);
1079 memcpy(&argp->lsn, bp, sizeof(argp->lsn));
1080 bp += sizeof(argp->lsn);
1081 memcpy(&argp->nextpgno, bp, sizeof(argp->nextpgno));
1082 bp += sizeof(argp->nextpgno);
1083 memcpy(&argp->nextlsn, bp, sizeof(argp->nextlsn));
1084 bp += sizeof(argp->nextlsn);
1085 *argpp = argp;
1086 return (0);
1087 }
1088
1089 /*
1090 * PUBLIC: int __db_debug_log
1091 * PUBLIC: __P((DB_LOG *, DB_TXN *, DB_LSN *, u_int32_t,
1092 * PUBLIC: const DBT *, u_int32_t, const DBT *, const DBT *,
1093 * PUBLIC: u_int32_t));
1094 */
__db_debug_log(logp,txnid,ret_lsnp,flags,op,fileid,key,data,arg_flags)1095 int __db_debug_log(logp, txnid, ret_lsnp, flags,
1096 op, fileid, key, data, arg_flags)
1097 DB_LOG *logp;
1098 DB_TXN *txnid;
1099 DB_LSN *ret_lsnp;
1100 u_int32_t flags;
1101 const DBT *op;
1102 u_int32_t fileid;
1103 const DBT *key;
1104 const DBT *data;
1105 u_int32_t arg_flags;
1106 {
1107 DBT logrec;
1108 DB_LSN *lsnp, null_lsn;
1109 u_int32_t zero;
1110 u_int32_t rectype, txn_num;
1111 int ret;
1112 u_int8_t *bp;
1113
1114 rectype = DB_db_debug;
1115 txn_num = txnid == NULL ? 0 : txnid->txnid;
1116 if (txnid == NULL) {
1117 ZERO_LSN(null_lsn);
1118 lsnp = &null_lsn;
1119 } else
1120 lsnp = &txnid->last_lsn;
1121 logrec.size = sizeof(rectype) + sizeof(txn_num) + sizeof(DB_LSN)
1122 + sizeof(u_int32_t) + (op == NULL ? 0 : op->size)
1123 + sizeof(fileid)
1124 + sizeof(u_int32_t) + (key == NULL ? 0 : key->size)
1125 + sizeof(u_int32_t) + (data == NULL ? 0 : data->size)
1126 + sizeof(arg_flags);
1127 if ((ret = __os_malloc(logrec.size, NULL, &logrec.data)) != 0)
1128 return (ret);
1129
1130 bp = logrec.data;
1131 memcpy(bp, &rectype, sizeof(rectype));
1132 bp += sizeof(rectype);
1133 memcpy(bp, &txn_num, sizeof(txn_num));
1134 bp += sizeof(txn_num);
1135 memcpy(bp, lsnp, sizeof(DB_LSN));
1136 bp += sizeof(DB_LSN);
1137 if (op == NULL) {
1138 zero = 0;
1139 memcpy(bp, &zero, sizeof(u_int32_t));
1140 bp += sizeof(u_int32_t);
1141 } else {
1142 memcpy(bp, &op->size, sizeof(op->size));
1143 bp += sizeof(op->size);
1144 memcpy(bp, op->data, op->size);
1145 bp += op->size;
1146 }
1147 memcpy(bp, &fileid, sizeof(fileid));
1148 bp += sizeof(fileid);
1149 if (key == NULL) {
1150 zero = 0;
1151 memcpy(bp, &zero, sizeof(u_int32_t));
1152 bp += sizeof(u_int32_t);
1153 } else {
1154 memcpy(bp, &key->size, sizeof(key->size));
1155 bp += sizeof(key->size);
1156 memcpy(bp, key->data, key->size);
1157 bp += key->size;
1158 }
1159 if (data == NULL) {
1160 zero = 0;
1161 memcpy(bp, &zero, sizeof(u_int32_t));
1162 bp += sizeof(u_int32_t);
1163 } else {
1164 memcpy(bp, &data->size, sizeof(data->size));
1165 bp += sizeof(data->size);
1166 memcpy(bp, data->data, data->size);
1167 bp += data->size;
1168 }
1169 memcpy(bp, &arg_flags, sizeof(arg_flags));
1170 bp += sizeof(arg_flags);
1171 #ifdef DIAGNOSTIC
1172 if ((u_int32_t)(bp - (u_int8_t *)logrec.data) != logrec.size)
1173 fprintf(stderr, "Error in log record length");
1174 #endif
1175 ret = log_put(logp, ret_lsnp, (DBT *)&logrec, flags);
1176 if (txnid != NULL)
1177 txnid->last_lsn = *ret_lsnp;
1178 __os_free(logrec.data, 0);
1179 return (ret);
1180 }
1181
1182 /*
1183 * PUBLIC: int __db_debug_print
1184 * PUBLIC: __P((DB_LOG *, DBT *, DB_LSN *, int, void *));
1185 */
1186 int
__db_debug_print(notused1,dbtp,lsnp,notused2,notused3)1187 __db_debug_print(notused1, dbtp, lsnp, notused2, notused3)
1188 DB_LOG *notused1;
1189 DBT *dbtp;
1190 DB_LSN *lsnp;
1191 int notused2;
1192 void *notused3;
1193 {
1194 __db_debug_args *argp;
1195 u_int32_t i;
1196 u_int ch;
1197 int ret;
1198
1199 i = 0;
1200 ch = 0;
1201 notused1 = NULL;
1202 notused2 = 0;
1203 notused3 = NULL;
1204
1205 if ((ret = __db_debug_read(dbtp->data, &argp)) != 0)
1206 return (ret);
1207 printf("[%lu][%lu]db_debug: rec: %lu txnid %lx prevlsn [%lu][%lu]\n",
1208 (u_long)lsnp->file,
1209 (u_long)lsnp->offset,
1210 (u_long)argp->type,
1211 (u_long)argp->txnid->txnid,
1212 (u_long)argp->prev_lsn.file,
1213 (u_long)argp->prev_lsn.offset);
1214 printf("\top: ");
1215 for (i = 0; i < argp->op.size; i++) {
1216 ch = ((u_int8_t *)argp->op.data)[i];
1217 if (isprint(ch) || ch == 0xa)
1218 putchar(ch);
1219 else
1220 printf("%#x ", ch);
1221 }
1222 printf("\n");
1223 printf("\tfileid: %lu\n", (u_long)argp->fileid);
1224 printf("\tkey: ");
1225 for (i = 0; i < argp->key.size; i++) {
1226 ch = ((u_int8_t *)argp->key.data)[i];
1227 if (isprint(ch) || ch == 0xa)
1228 putchar(ch);
1229 else
1230 printf("%#x ", ch);
1231 }
1232 printf("\n");
1233 printf("\tdata: ");
1234 for (i = 0; i < argp->data.size; i++) {
1235 ch = ((u_int8_t *)argp->data.data)[i];
1236 if (isprint(ch) || ch == 0xa)
1237 putchar(ch);
1238 else
1239 printf("%#x ", ch);
1240 }
1241 printf("\n");
1242 printf("\targ_flags: %lu\n", (u_long)argp->arg_flags);
1243 printf("\n");
1244 __os_free(argp, 0);
1245 return (0);
1246 }
1247
1248 /*
1249 * PUBLIC: int __db_debug_read __P((void *, __db_debug_args **));
1250 */
1251 int
__db_debug_read(recbuf,argpp)1252 __db_debug_read(recbuf, argpp)
1253 void *recbuf;
1254 __db_debug_args **argpp;
1255 {
1256 __db_debug_args *argp;
1257 u_int8_t *bp;
1258 int ret;
1259
1260 ret = __os_malloc(sizeof(__db_debug_args) +
1261 sizeof(DB_TXN), NULL, &argp);
1262 if (ret != 0)
1263 return (ret);
1264 argp->txnid = (DB_TXN *)&argp[1];
1265 bp = recbuf;
1266 memcpy(&argp->type, bp, sizeof(argp->type));
1267 bp += sizeof(argp->type);
1268 memcpy(&argp->txnid->txnid, bp, sizeof(argp->txnid->txnid));
1269 bp += sizeof(argp->txnid->txnid);
1270 memcpy(&argp->prev_lsn, bp, sizeof(DB_LSN));
1271 bp += sizeof(DB_LSN);
1272 memcpy(&argp->op.size, bp, sizeof(u_int32_t));
1273 bp += sizeof(u_int32_t);
1274 argp->op.data = bp;
1275 bp += argp->op.size;
1276 memcpy(&argp->fileid, bp, sizeof(argp->fileid));
1277 bp += sizeof(argp->fileid);
1278 memcpy(&argp->key.size, bp, sizeof(u_int32_t));
1279 bp += sizeof(u_int32_t);
1280 argp->key.data = bp;
1281 bp += argp->key.size;
1282 memcpy(&argp->data.size, bp, sizeof(u_int32_t));
1283 bp += sizeof(u_int32_t);
1284 argp->data.data = bp;
1285 bp += argp->data.size;
1286 memcpy(&argp->arg_flags, bp, sizeof(argp->arg_flags));
1287 bp += sizeof(argp->arg_flags);
1288 *argpp = argp;
1289 return (0);
1290 }
1291
1292 /*
1293 * PUBLIC: int __db_init_print __P((DB_ENV *));
1294 */
1295 int
__db_init_print(dbenv)1296 __db_init_print(dbenv)
1297 DB_ENV *dbenv;
1298 {
1299 int ret;
1300
1301 if ((ret = __db_add_recovery(dbenv,
1302 __db_addrem_print, DB_db_addrem)) != 0)
1303 return (ret);
1304 if ((ret = __db_add_recovery(dbenv,
1305 __db_split_print, DB_db_split)) != 0)
1306 return (ret);
1307 if ((ret = __db_add_recovery(dbenv,
1308 __db_big_print, DB_db_big)) != 0)
1309 return (ret);
1310 if ((ret = __db_add_recovery(dbenv,
1311 __db_ovref_print, DB_db_ovref)) != 0)
1312 return (ret);
1313 if ((ret = __db_add_recovery(dbenv,
1314 __db_relink_print, DB_db_relink)) != 0)
1315 return (ret);
1316 if ((ret = __db_add_recovery(dbenv,
1317 __db_addpage_print, DB_db_addpage)) != 0)
1318 return (ret);
1319 if ((ret = __db_add_recovery(dbenv,
1320 __db_debug_print, DB_db_debug)) != 0)
1321 return (ret);
1322 return (0);
1323 }
1324
1325 /*
1326 * PUBLIC: int __db_init_recover __P((DB_ENV *));
1327 */
1328 int
__db_init_recover(dbenv)1329 __db_init_recover(dbenv)
1330 DB_ENV *dbenv;
1331 {
1332 int ret;
1333
1334 if ((ret = __db_add_recovery(dbenv,
1335 __db_addrem_recover, DB_db_addrem)) != 0)
1336 return (ret);
1337 if ((ret = __db_add_recovery(dbenv,
1338 __db_split_recover, DB_db_split)) != 0)
1339 return (ret);
1340 if ((ret = __db_add_recovery(dbenv,
1341 __db_big_recover, DB_db_big)) != 0)
1342 return (ret);
1343 if ((ret = __db_add_recovery(dbenv,
1344 __db_ovref_recover, DB_db_ovref)) != 0)
1345 return (ret);
1346 if ((ret = __db_add_recovery(dbenv,
1347 __db_relink_recover, DB_db_relink)) != 0)
1348 return (ret);
1349 if ((ret = __db_add_recovery(dbenv,
1350 __db_addpage_recover, DB_db_addpage)) != 0)
1351 return (ret);
1352 if ((ret = __db_add_recovery(dbenv,
1353 __db_debug_recover, DB_db_debug)) != 0)
1354 return (ret);
1355 return (0);
1356 }
1357
1358