Update.
[glibc.git] / db2 / db / db_auto.c
blob6922504383d2c50d870ad8cdeb17fcbe1a6ef613
1 /* Do not edit: automatically built by dist/db_gen.sh. */
2 #include "config.h"
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
12 #include "db_int.h"
13 #include "shqueue.h"
14 #include "db_page.h"
15 #include "db_dispatch.h"
16 #include "db_am.h"
17 #include "common_ext.h"
20 * PUBLIC: int __db_addrem_log
21 * PUBLIC: __P((DB_LOG *, DB_TXN *, DB_LSN *, u_int32_t,
22 * PUBLIC: u_int32_t, u_int32_t, db_pgno_t, u_int32_t,
23 * PUBLIC: size_t, DBT *, DBT *, DB_LSN *));
25 int __db_addrem_log(logp, txnid, ret_lsnp, flags,
26 opcode, fileid, pgno, indx, nbytes, hdr,
27 dbt, pagelsn)
28 DB_LOG *logp;
29 DB_TXN *txnid;
30 DB_LSN *ret_lsnp;
31 u_int32_t flags;
32 u_int32_t opcode;
33 u_int32_t fileid;
34 db_pgno_t pgno;
35 u_int32_t indx;
36 size_t nbytes;
37 DBT *hdr;
38 DBT *dbt;
39 DB_LSN * pagelsn;
41 DBT logrec;
42 DB_LSN *lsnp, null_lsn;
43 u_int32_t zero;
44 u_int32_t rectype, txn_num;
45 int ret;
46 u_int8_t *bp;
48 rectype = DB_db_addrem;
49 txn_num = txnid == NULL ? 0 : txnid->txnid;
50 if (txnid == NULL) {
51 null_lsn.file = 0;
52 null_lsn.offset = 0;
53 lsnp = &null_lsn;
54 } else
55 lsnp = &txnid->last_lsn;
56 logrec.size = sizeof(rectype) + sizeof(txn_num) + sizeof(DB_LSN)
57 + sizeof(opcode)
58 + sizeof(fileid)
59 + sizeof(pgno)
60 + sizeof(indx)
61 + sizeof(nbytes)
62 + sizeof(u_int32_t) + (hdr == NULL ? 0 : hdr->size)
63 + sizeof(u_int32_t) + (dbt == NULL ? 0 : dbt->size)
64 + sizeof(*pagelsn);
65 if ((logrec.data = (void *)malloc(logrec.size)) == NULL)
66 return (ENOMEM);
68 bp = logrec.data;
69 memcpy(bp, &rectype, sizeof(rectype));
70 bp += sizeof(rectype);
71 memcpy(bp, &txn_num, sizeof(txn_num));
72 bp += sizeof(txn_num);
73 memcpy(bp, lsnp, sizeof(DB_LSN));
74 bp += sizeof(DB_LSN);
75 memcpy(bp, &opcode, sizeof(opcode));
76 bp += sizeof(opcode);
77 memcpy(bp, &fileid, sizeof(fileid));
78 bp += sizeof(fileid);
79 memcpy(bp, &pgno, sizeof(pgno));
80 bp += sizeof(pgno);
81 memcpy(bp, &indx, sizeof(indx));
82 bp += sizeof(indx);
83 memcpy(bp, &nbytes, sizeof(nbytes));
84 bp += sizeof(nbytes);
85 if (hdr == NULL) {
86 zero = 0;
87 memcpy(bp, &zero, sizeof(u_int32_t));
88 bp += sizeof(u_int32_t);
89 } else {
90 memcpy(bp, &hdr->size, sizeof(hdr->size));
91 bp += sizeof(hdr->size);
92 memcpy(bp, hdr->data, hdr->size);
93 bp += hdr->size;
95 if (dbt == NULL) {
96 zero = 0;
97 memcpy(bp, &zero, sizeof(u_int32_t));
98 bp += sizeof(u_int32_t);
99 } else {
100 memcpy(bp, &dbt->size, sizeof(dbt->size));
101 bp += sizeof(dbt->size);
102 memcpy(bp, dbt->data, dbt->size);
103 bp += dbt->size;
105 if (pagelsn != NULL)
106 memcpy(bp, pagelsn, sizeof(*pagelsn));
107 else
108 memset(bp, 0, sizeof(*pagelsn));
109 bp += sizeof(*pagelsn);
110 #ifdef DEBUG
111 if ((u_int32_t)(bp - (u_int8_t *)logrec.data) != logrec.size)
112 fprintf(stderr, "Error in log record length");
113 #endif
114 ret = log_put(logp, ret_lsnp, (DBT *)&logrec, flags);
115 if (txnid != NULL)
116 txnid->last_lsn = *ret_lsnp;
117 free(logrec.data);
118 return (ret);
122 * PUBLIC: int __db_addrem_print
123 * PUBLIC: __P((DB_LOG *, DBT *, DB_LSN *, int, void *));
127 __db_addrem_print(notused1, dbtp, lsnp, notused3, notused4)
128 DB_LOG *notused1;
129 DBT *dbtp;
130 DB_LSN *lsnp;
131 int notused3;
132 void *notused4;
134 __db_addrem_args *argp;
135 u_int32_t i;
136 int c, ret;
138 i = 0;
139 c = 0;
140 notused1 = NULL;
141 notused3 = 0;
142 notused4 = NULL;
144 if ((ret = __db_addrem_read(dbtp->data, &argp)) != 0)
145 return (ret);
146 printf("[%lu][%lu]db_addrem: rec: %lu txnid %lx prevlsn [%lu][%lu]\n",
147 (u_long)lsnp->file,
148 (u_long)lsnp->offset,
149 (u_long)argp->type,
150 (u_long)argp->txnid->txnid,
151 (u_long)argp->prev_lsn.file,
152 (u_long)argp->prev_lsn.offset);
153 printf("\topcode: %lu\n", (u_long)argp->opcode);
154 printf("\tfileid: %lu\n", (u_long)argp->fileid);
155 printf("\tpgno: %lu\n", (u_long)argp->pgno);
156 printf("\tindx: %lu\n", (u_long)argp->indx);
157 printf("\tnbytes: %lu\n", (u_long)argp->nbytes);
158 printf("\thdr: ");
159 for (i = 0; i < argp->hdr.size; i++) {
160 c = ((char *)argp->hdr.data)[i];
161 if (isprint(c) || c == 0xa)
162 putchar(c);
163 else
164 printf("%#x ", c);
166 printf("\n");
167 printf("\tdbt: ");
168 for (i = 0; i < argp->dbt.size; i++) {
169 c = ((char *)argp->dbt.data)[i];
170 if (isprint(c) || c == 0xa)
171 putchar(c);
172 else
173 printf("%#x ", c);
175 printf("\n");
176 printf("\tpagelsn: [%lu][%lu]\n",
177 (u_long)argp->pagelsn.file, (u_long)argp->pagelsn.offset);
178 printf("\n");
179 free(argp);
180 return (0);
184 * PUBLIC: int __db_addrem_read __P((void *, __db_addrem_args **));
187 __db_addrem_read(recbuf, argpp)
188 void *recbuf;
189 __db_addrem_args **argpp;
191 __db_addrem_args *argp;
192 u_int8_t *bp;
194 argp = (__db_addrem_args *)malloc(sizeof(__db_addrem_args) +
195 sizeof(DB_TXN));
196 if (argp == NULL)
197 return (ENOMEM);
198 argp->txnid = (DB_TXN *)&argp[1];
199 bp = recbuf;
200 memcpy(&argp->type, bp, sizeof(argp->type));
201 bp += sizeof(argp->type);
202 memcpy(&argp->txnid->txnid, bp, sizeof(argp->txnid->txnid));
203 bp += sizeof(argp->txnid->txnid);
204 memcpy(&argp->prev_lsn, bp, sizeof(DB_LSN));
205 bp += sizeof(DB_LSN);
206 memcpy(&argp->opcode, bp, sizeof(argp->opcode));
207 bp += sizeof(argp->opcode);
208 memcpy(&argp->fileid, bp, sizeof(argp->fileid));
209 bp += sizeof(argp->fileid);
210 memcpy(&argp->pgno, bp, sizeof(argp->pgno));
211 bp += sizeof(argp->pgno);
212 memcpy(&argp->indx, bp, sizeof(argp->indx));
213 bp += sizeof(argp->indx);
214 memcpy(&argp->nbytes, bp, sizeof(argp->nbytes));
215 bp += sizeof(argp->nbytes);
216 memcpy(&argp->hdr.size, bp, sizeof(u_int32_t));
217 bp += sizeof(u_int32_t);
218 argp->hdr.data = bp;
219 bp += argp->hdr.size;
220 memcpy(&argp->dbt.size, bp, sizeof(u_int32_t));
221 bp += sizeof(u_int32_t);
222 argp->dbt.data = bp;
223 bp += argp->dbt.size;
224 memcpy(&argp->pagelsn, bp, sizeof(argp->pagelsn));
225 bp += sizeof(argp->pagelsn);
226 *argpp = argp;
227 return (0);
231 * PUBLIC: int __db_split_log
232 * PUBLIC: __P((DB_LOG *, DB_TXN *, DB_LSN *, u_int32_t,
233 * PUBLIC: u_int32_t, u_int32_t, db_pgno_t, DBT *,
234 * PUBLIC: DB_LSN *));
236 int __db_split_log(logp, txnid, ret_lsnp, flags,
237 opcode, fileid, pgno, pageimage, pagelsn)
238 DB_LOG *logp;
239 DB_TXN *txnid;
240 DB_LSN *ret_lsnp;
241 u_int32_t flags;
242 u_int32_t opcode;
243 u_int32_t fileid;
244 db_pgno_t pgno;
245 DBT *pageimage;
246 DB_LSN * pagelsn;
248 DBT logrec;
249 DB_LSN *lsnp, null_lsn;
250 u_int32_t zero;
251 u_int32_t rectype, txn_num;
252 int ret;
253 u_int8_t *bp;
255 rectype = DB_db_split;
256 txn_num = txnid == NULL ? 0 : txnid->txnid;
257 if (txnid == NULL) {
258 null_lsn.file = 0;
259 null_lsn.offset = 0;
260 lsnp = &null_lsn;
261 } else
262 lsnp = &txnid->last_lsn;
263 logrec.size = sizeof(rectype) + sizeof(txn_num) + sizeof(DB_LSN)
264 + sizeof(opcode)
265 + sizeof(fileid)
266 + sizeof(pgno)
267 + sizeof(u_int32_t) + (pageimage == NULL ? 0 : pageimage->size)
268 + sizeof(*pagelsn);
269 if ((logrec.data = (void *)malloc(logrec.size)) == NULL)
270 return (ENOMEM);
272 bp = logrec.data;
273 memcpy(bp, &rectype, sizeof(rectype));
274 bp += sizeof(rectype);
275 memcpy(bp, &txn_num, sizeof(txn_num));
276 bp += sizeof(txn_num);
277 memcpy(bp, lsnp, sizeof(DB_LSN));
278 bp += sizeof(DB_LSN);
279 memcpy(bp, &opcode, sizeof(opcode));
280 bp += sizeof(opcode);
281 memcpy(bp, &fileid, sizeof(fileid));
282 bp += sizeof(fileid);
283 memcpy(bp, &pgno, sizeof(pgno));
284 bp += sizeof(pgno);
285 if (pageimage == NULL) {
286 zero = 0;
287 memcpy(bp, &zero, sizeof(u_int32_t));
288 bp += sizeof(u_int32_t);
289 } else {
290 memcpy(bp, &pageimage->size, sizeof(pageimage->size));
291 bp += sizeof(pageimage->size);
292 memcpy(bp, pageimage->data, pageimage->size);
293 bp += pageimage->size;
295 if (pagelsn != NULL)
296 memcpy(bp, pagelsn, sizeof(*pagelsn));
297 else
298 memset(bp, 0, sizeof(*pagelsn));
299 bp += sizeof(*pagelsn);
300 #ifdef DEBUG
301 if ((u_int32_t)(bp - (u_int8_t *)logrec.data) != logrec.size)
302 fprintf(stderr, "Error in log record length");
303 #endif
304 ret = log_put(logp, ret_lsnp, (DBT *)&logrec, flags);
305 if (txnid != NULL)
306 txnid->last_lsn = *ret_lsnp;
307 free(logrec.data);
308 return (ret);
312 * PUBLIC: int __db_split_print
313 * PUBLIC: __P((DB_LOG *, DBT *, DB_LSN *, int, void *));
317 __db_split_print(notused1, dbtp, lsnp, notused3, notused4)
318 DB_LOG *notused1;
319 DBT *dbtp;
320 DB_LSN *lsnp;
321 int notused3;
322 void *notused4;
324 __db_split_args *argp;
325 u_int32_t i;
326 int c, ret;
328 i = 0;
329 c = 0;
330 notused1 = NULL;
331 notused3 = 0;
332 notused4 = NULL;
334 if ((ret = __db_split_read(dbtp->data, &argp)) != 0)
335 return (ret);
336 printf("[%lu][%lu]db_split: rec: %lu txnid %lx prevlsn [%lu][%lu]\n",
337 (u_long)lsnp->file,
338 (u_long)lsnp->offset,
339 (u_long)argp->type,
340 (u_long)argp->txnid->txnid,
341 (u_long)argp->prev_lsn.file,
342 (u_long)argp->prev_lsn.offset);
343 printf("\topcode: %lu\n", (u_long)argp->opcode);
344 printf("\tfileid: %lu\n", (u_long)argp->fileid);
345 printf("\tpgno: %lu\n", (u_long)argp->pgno);
346 printf("\tpageimage: ");
347 for (i = 0; i < argp->pageimage.size; i++) {
348 c = ((char *)argp->pageimage.data)[i];
349 if (isprint(c) || c == 0xa)
350 putchar(c);
351 else
352 printf("%#x ", c);
354 printf("\n");
355 printf("\tpagelsn: [%lu][%lu]\n",
356 (u_long)argp->pagelsn.file, (u_long)argp->pagelsn.offset);
357 printf("\n");
358 free(argp);
359 return (0);
363 * PUBLIC: int __db_split_read __P((void *, __db_split_args **));
366 __db_split_read(recbuf, argpp)
367 void *recbuf;
368 __db_split_args **argpp;
370 __db_split_args *argp;
371 u_int8_t *bp;
373 argp = (__db_split_args *)malloc(sizeof(__db_split_args) +
374 sizeof(DB_TXN));
375 if (argp == NULL)
376 return (ENOMEM);
377 argp->txnid = (DB_TXN *)&argp[1];
378 bp = recbuf;
379 memcpy(&argp->type, bp, sizeof(argp->type));
380 bp += sizeof(argp->type);
381 memcpy(&argp->txnid->txnid, bp, sizeof(argp->txnid->txnid));
382 bp += sizeof(argp->txnid->txnid);
383 memcpy(&argp->prev_lsn, bp, sizeof(DB_LSN));
384 bp += sizeof(DB_LSN);
385 memcpy(&argp->opcode, bp, sizeof(argp->opcode));
386 bp += sizeof(argp->opcode);
387 memcpy(&argp->fileid, bp, sizeof(argp->fileid));
388 bp += sizeof(argp->fileid);
389 memcpy(&argp->pgno, bp, sizeof(argp->pgno));
390 bp += sizeof(argp->pgno);
391 memcpy(&argp->pageimage.size, bp, sizeof(u_int32_t));
392 bp += sizeof(u_int32_t);
393 argp->pageimage.data = bp;
394 bp += argp->pageimage.size;
395 memcpy(&argp->pagelsn, bp, sizeof(argp->pagelsn));
396 bp += sizeof(argp->pagelsn);
397 *argpp = argp;
398 return (0);
402 * PUBLIC: int __db_big_log
403 * PUBLIC: __P((DB_LOG *, DB_TXN *, DB_LSN *, u_int32_t,
404 * PUBLIC: u_int32_t, u_int32_t, db_pgno_t, db_pgno_t,
405 * PUBLIC: db_pgno_t, DBT *, DB_LSN *, DB_LSN *,
406 * PUBLIC: DB_LSN *));
408 int __db_big_log(logp, txnid, ret_lsnp, flags,
409 opcode, fileid, pgno, prev_pgno, next_pgno, dbt,
410 pagelsn, prevlsn, nextlsn)
411 DB_LOG *logp;
412 DB_TXN *txnid;
413 DB_LSN *ret_lsnp;
414 u_int32_t flags;
415 u_int32_t opcode;
416 u_int32_t fileid;
417 db_pgno_t pgno;
418 db_pgno_t prev_pgno;
419 db_pgno_t next_pgno;
420 DBT *dbt;
421 DB_LSN * pagelsn;
422 DB_LSN * prevlsn;
423 DB_LSN * nextlsn;
425 DBT logrec;
426 DB_LSN *lsnp, null_lsn;
427 u_int32_t zero;
428 u_int32_t rectype, txn_num;
429 int ret;
430 u_int8_t *bp;
432 rectype = DB_db_big;
433 txn_num = txnid == NULL ? 0 : txnid->txnid;
434 if (txnid == NULL) {
435 null_lsn.file = 0;
436 null_lsn.offset = 0;
437 lsnp = &null_lsn;
438 } else
439 lsnp = &txnid->last_lsn;
440 logrec.size = sizeof(rectype) + sizeof(txn_num) + sizeof(DB_LSN)
441 + sizeof(opcode)
442 + sizeof(fileid)
443 + sizeof(pgno)
444 + sizeof(prev_pgno)
445 + sizeof(next_pgno)
446 + sizeof(u_int32_t) + (dbt == NULL ? 0 : dbt->size)
447 + sizeof(*pagelsn)
448 + sizeof(*prevlsn)
449 + sizeof(*nextlsn);
450 if ((logrec.data = (void *)malloc(logrec.size)) == NULL)
451 return (ENOMEM);
453 bp = logrec.data;
454 memcpy(bp, &rectype, sizeof(rectype));
455 bp += sizeof(rectype);
456 memcpy(bp, &txn_num, sizeof(txn_num));
457 bp += sizeof(txn_num);
458 memcpy(bp, lsnp, sizeof(DB_LSN));
459 bp += sizeof(DB_LSN);
460 memcpy(bp, &opcode, sizeof(opcode));
461 bp += sizeof(opcode);
462 memcpy(bp, &fileid, sizeof(fileid));
463 bp += sizeof(fileid);
464 memcpy(bp, &pgno, sizeof(pgno));
465 bp += sizeof(pgno);
466 memcpy(bp, &prev_pgno, sizeof(prev_pgno));
467 bp += sizeof(prev_pgno);
468 memcpy(bp, &next_pgno, sizeof(next_pgno));
469 bp += sizeof(next_pgno);
470 if (dbt == NULL) {
471 zero = 0;
472 memcpy(bp, &zero, sizeof(u_int32_t));
473 bp += sizeof(u_int32_t);
474 } else {
475 memcpy(bp, &dbt->size, sizeof(dbt->size));
476 bp += sizeof(dbt->size);
477 memcpy(bp, dbt->data, dbt->size);
478 bp += dbt->size;
480 if (pagelsn != NULL)
481 memcpy(bp, pagelsn, sizeof(*pagelsn));
482 else
483 memset(bp, 0, sizeof(*pagelsn));
484 bp += sizeof(*pagelsn);
485 if (prevlsn != NULL)
486 memcpy(bp, prevlsn, sizeof(*prevlsn));
487 else
488 memset(bp, 0, sizeof(*prevlsn));
489 bp += sizeof(*prevlsn);
490 if (nextlsn != NULL)
491 memcpy(bp, nextlsn, sizeof(*nextlsn));
492 else
493 memset(bp, 0, sizeof(*nextlsn));
494 bp += sizeof(*nextlsn);
495 #ifdef DEBUG
496 if ((u_int32_t)(bp - (u_int8_t *)logrec.data) != logrec.size)
497 fprintf(stderr, "Error in log record length");
498 #endif
499 ret = log_put(logp, ret_lsnp, (DBT *)&logrec, flags);
500 if (txnid != NULL)
501 txnid->last_lsn = *ret_lsnp;
502 free(logrec.data);
503 return (ret);
507 * PUBLIC: int __db_big_print
508 * PUBLIC: __P((DB_LOG *, DBT *, DB_LSN *, int, void *));
512 __db_big_print(notused1, dbtp, lsnp, notused3, notused4)
513 DB_LOG *notused1;
514 DBT *dbtp;
515 DB_LSN *lsnp;
516 int notused3;
517 void *notused4;
519 __db_big_args *argp;
520 u_int32_t i;
521 int c, ret;
523 i = 0;
524 c = 0;
525 notused1 = NULL;
526 notused3 = 0;
527 notused4 = NULL;
529 if ((ret = __db_big_read(dbtp->data, &argp)) != 0)
530 return (ret);
531 printf("[%lu][%lu]db_big: rec: %lu txnid %lx prevlsn [%lu][%lu]\n",
532 (u_long)lsnp->file,
533 (u_long)lsnp->offset,
534 (u_long)argp->type,
535 (u_long)argp->txnid->txnid,
536 (u_long)argp->prev_lsn.file,
537 (u_long)argp->prev_lsn.offset);
538 printf("\topcode: %lu\n", (u_long)argp->opcode);
539 printf("\tfileid: %lu\n", (u_long)argp->fileid);
540 printf("\tpgno: %lu\n", (u_long)argp->pgno);
541 printf("\tprev_pgno: %lu\n", (u_long)argp->prev_pgno);
542 printf("\tnext_pgno: %lu\n", (u_long)argp->next_pgno);
543 printf("\tdbt: ");
544 for (i = 0; i < argp->dbt.size; i++) {
545 c = ((char *)argp->dbt.data)[i];
546 if (isprint(c) || c == 0xa)
547 putchar(c);
548 else
549 printf("%#x ", c);
551 printf("\n");
552 printf("\tpagelsn: [%lu][%lu]\n",
553 (u_long)argp->pagelsn.file, (u_long)argp->pagelsn.offset);
554 printf("\tprevlsn: [%lu][%lu]\n",
555 (u_long)argp->prevlsn.file, (u_long)argp->prevlsn.offset);
556 printf("\tnextlsn: [%lu][%lu]\n",
557 (u_long)argp->nextlsn.file, (u_long)argp->nextlsn.offset);
558 printf("\n");
559 free(argp);
560 return (0);
564 * PUBLIC: int __db_big_read __P((void *, __db_big_args **));
567 __db_big_read(recbuf, argpp)
568 void *recbuf;
569 __db_big_args **argpp;
571 __db_big_args *argp;
572 u_int8_t *bp;
574 argp = (__db_big_args *)malloc(sizeof(__db_big_args) +
575 sizeof(DB_TXN));
576 if (argp == NULL)
577 return (ENOMEM);
578 argp->txnid = (DB_TXN *)&argp[1];
579 bp = recbuf;
580 memcpy(&argp->type, bp, sizeof(argp->type));
581 bp += sizeof(argp->type);
582 memcpy(&argp->txnid->txnid, bp, sizeof(argp->txnid->txnid));
583 bp += sizeof(argp->txnid->txnid);
584 memcpy(&argp->prev_lsn, bp, sizeof(DB_LSN));
585 bp += sizeof(DB_LSN);
586 memcpy(&argp->opcode, bp, sizeof(argp->opcode));
587 bp += sizeof(argp->opcode);
588 memcpy(&argp->fileid, bp, sizeof(argp->fileid));
589 bp += sizeof(argp->fileid);
590 memcpy(&argp->pgno, bp, sizeof(argp->pgno));
591 bp += sizeof(argp->pgno);
592 memcpy(&argp->prev_pgno, bp, sizeof(argp->prev_pgno));
593 bp += sizeof(argp->prev_pgno);
594 memcpy(&argp->next_pgno, bp, sizeof(argp->next_pgno));
595 bp += sizeof(argp->next_pgno);
596 memcpy(&argp->dbt.size, bp, sizeof(u_int32_t));
597 bp += sizeof(u_int32_t);
598 argp->dbt.data = bp;
599 bp += argp->dbt.size;
600 memcpy(&argp->pagelsn, bp, sizeof(argp->pagelsn));
601 bp += sizeof(argp->pagelsn);
602 memcpy(&argp->prevlsn, bp, sizeof(argp->prevlsn));
603 bp += sizeof(argp->prevlsn);
604 memcpy(&argp->nextlsn, bp, sizeof(argp->nextlsn));
605 bp += sizeof(argp->nextlsn);
606 *argpp = argp;
607 return (0);
611 * PUBLIC: int __db_ovref_log
612 * PUBLIC: __P((DB_LOG *, DB_TXN *, DB_LSN *, u_int32_t,
613 * PUBLIC: u_int32_t, db_pgno_t, DB_LSN *));
615 int __db_ovref_log(logp, txnid, ret_lsnp, flags,
616 fileid, pgno, lsn)
617 DB_LOG *logp;
618 DB_TXN *txnid;
619 DB_LSN *ret_lsnp;
620 u_int32_t flags;
621 u_int32_t fileid;
622 db_pgno_t pgno;
623 DB_LSN * lsn;
625 DBT logrec;
626 DB_LSN *lsnp, null_lsn;
627 u_int32_t rectype, txn_num;
628 int ret;
629 u_int8_t *bp;
631 rectype = DB_db_ovref;
632 txn_num = txnid == NULL ? 0 : txnid->txnid;
633 if (txnid == NULL) {
634 null_lsn.file = 0;
635 null_lsn.offset = 0;
636 lsnp = &null_lsn;
637 } else
638 lsnp = &txnid->last_lsn;
639 logrec.size = sizeof(rectype) + sizeof(txn_num) + sizeof(DB_LSN)
640 + sizeof(fileid)
641 + sizeof(pgno)
642 + sizeof(*lsn);
643 if ((logrec.data = (void *)malloc(logrec.size)) == NULL)
644 return (ENOMEM);
646 bp = logrec.data;
647 memcpy(bp, &rectype, sizeof(rectype));
648 bp += sizeof(rectype);
649 memcpy(bp, &txn_num, sizeof(txn_num));
650 bp += sizeof(txn_num);
651 memcpy(bp, lsnp, sizeof(DB_LSN));
652 bp += sizeof(DB_LSN);
653 memcpy(bp, &fileid, sizeof(fileid));
654 bp += sizeof(fileid);
655 memcpy(bp, &pgno, sizeof(pgno));
656 bp += sizeof(pgno);
657 if (lsn != NULL)
658 memcpy(bp, lsn, sizeof(*lsn));
659 else
660 memset(bp, 0, sizeof(*lsn));
661 bp += sizeof(*lsn);
662 #ifdef DEBUG
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 free(logrec.data);
670 return (ret);
674 * PUBLIC: int __db_ovref_print
675 * PUBLIC: __P((DB_LOG *, DBT *, DB_LSN *, int, void *));
679 __db_ovref_print(notused1, dbtp, lsnp, notused3, notused4)
680 DB_LOG *notused1;
681 DBT *dbtp;
682 DB_LSN *lsnp;
683 int notused3;
684 void *notused4;
686 __db_ovref_args *argp;
687 u_int32_t i;
688 int c, ret;
690 i = 0;
691 c = 0;
692 notused1 = NULL;
693 notused3 = 0;
694 notused4 = NULL;
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("\tlsn: [%lu][%lu]\n",
708 (u_long)argp->lsn.file, (u_long)argp->lsn.offset);
709 printf("\n");
710 free(argp);
711 return (0);
715 * PUBLIC: int __db_ovref_read __P((void *, __db_ovref_args **));
718 __db_ovref_read(recbuf, argpp)
719 void *recbuf;
720 __db_ovref_args **argpp;
722 __db_ovref_args *argp;
723 u_int8_t *bp;
725 argp = (__db_ovref_args *)malloc(sizeof(__db_ovref_args) +
726 sizeof(DB_TXN));
727 if (argp == NULL)
728 return (ENOMEM);
729 argp->txnid = (DB_TXN *)&argp[1];
730 bp = recbuf;
731 memcpy(&argp->type, bp, sizeof(argp->type));
732 bp += sizeof(argp->type);
733 memcpy(&argp->txnid->txnid, bp, sizeof(argp->txnid->txnid));
734 bp += sizeof(argp->txnid->txnid);
735 memcpy(&argp->prev_lsn, bp, sizeof(DB_LSN));
736 bp += sizeof(DB_LSN);
737 memcpy(&argp->fileid, bp, sizeof(argp->fileid));
738 bp += sizeof(argp->fileid);
739 memcpy(&argp->pgno, bp, sizeof(argp->pgno));
740 bp += sizeof(argp->pgno);
741 memcpy(&argp->lsn, bp, sizeof(argp->lsn));
742 bp += sizeof(argp->lsn);
743 *argpp = argp;
744 return (0);
748 * PUBLIC: int __db_relink_log
749 * PUBLIC: __P((DB_LOG *, DB_TXN *, DB_LSN *, u_int32_t,
750 * PUBLIC: u_int32_t, db_pgno_t, DB_LSN *, db_pgno_t,
751 * PUBLIC: DB_LSN *, db_pgno_t, DB_LSN *));
753 int __db_relink_log(logp, txnid, ret_lsnp, flags,
754 fileid, pgno, lsn, prev, lsn_prev, next,
755 lsn_next)
756 DB_LOG *logp;
757 DB_TXN *txnid;
758 DB_LSN *ret_lsnp;
759 u_int32_t flags;
760 u_int32_t fileid;
761 db_pgno_t pgno;
762 DB_LSN * lsn;
763 db_pgno_t prev;
764 DB_LSN * lsn_prev;
765 db_pgno_t next;
766 DB_LSN * lsn_next;
768 DBT logrec;
769 DB_LSN *lsnp, null_lsn;
770 u_int32_t rectype, txn_num;
771 int ret;
772 u_int8_t *bp;
774 rectype = DB_db_relink;
775 txn_num = txnid == NULL ? 0 : txnid->txnid;
776 if (txnid == NULL) {
777 null_lsn.file = 0;
778 null_lsn.offset = 0;
779 lsnp = &null_lsn;
780 } else
781 lsnp = &txnid->last_lsn;
782 logrec.size = sizeof(rectype) + sizeof(txn_num) + sizeof(DB_LSN)
783 + sizeof(fileid)
784 + sizeof(pgno)
785 + sizeof(*lsn)
786 + sizeof(prev)
787 + sizeof(*lsn_prev)
788 + sizeof(next)
789 + sizeof(*lsn_next);
790 if ((logrec.data = (void *)malloc(logrec.size)) == NULL)
791 return (ENOMEM);
793 bp = logrec.data;
794 memcpy(bp, &rectype, sizeof(rectype));
795 bp += sizeof(rectype);
796 memcpy(bp, &txn_num, sizeof(txn_num));
797 bp += sizeof(txn_num);
798 memcpy(bp, lsnp, sizeof(DB_LSN));
799 bp += sizeof(DB_LSN);
800 memcpy(bp, &fileid, sizeof(fileid));
801 bp += sizeof(fileid);
802 memcpy(bp, &pgno, sizeof(pgno));
803 bp += sizeof(pgno);
804 if (lsn != NULL)
805 memcpy(bp, lsn, sizeof(*lsn));
806 else
807 memset(bp, 0, sizeof(*lsn));
808 bp += sizeof(*lsn);
809 memcpy(bp, &prev, sizeof(prev));
810 bp += sizeof(prev);
811 if (lsn_prev != NULL)
812 memcpy(bp, lsn_prev, sizeof(*lsn_prev));
813 else
814 memset(bp, 0, sizeof(*lsn_prev));
815 bp += sizeof(*lsn_prev);
816 memcpy(bp, &next, sizeof(next));
817 bp += sizeof(next);
818 if (lsn_next != NULL)
819 memcpy(bp, lsn_next, sizeof(*lsn_next));
820 else
821 memset(bp, 0, sizeof(*lsn_next));
822 bp += sizeof(*lsn_next);
823 #ifdef DEBUG
824 if ((u_int32_t)(bp - (u_int8_t *)logrec.data) != logrec.size)
825 fprintf(stderr, "Error in log record length");
826 #endif
827 ret = log_put(logp, ret_lsnp, (DBT *)&logrec, flags);
828 if (txnid != NULL)
829 txnid->last_lsn = *ret_lsnp;
830 free(logrec.data);
831 return (ret);
835 * PUBLIC: int __db_relink_print
836 * PUBLIC: __P((DB_LOG *, DBT *, DB_LSN *, int, void *));
840 __db_relink_print(notused1, dbtp, lsnp, notused3, notused4)
841 DB_LOG *notused1;
842 DBT *dbtp;
843 DB_LSN *lsnp;
844 int notused3;
845 void *notused4;
847 __db_relink_args *argp;
848 u_int32_t i;
849 int c, ret;
851 i = 0;
852 c = 0;
853 notused1 = NULL;
854 notused3 = 0;
855 notused4 = NULL;
857 if ((ret = __db_relink_read(dbtp->data, &argp)) != 0)
858 return (ret);
859 printf("[%lu][%lu]db_relink: rec: %lu txnid %lx prevlsn [%lu][%lu]\n",
860 (u_long)lsnp->file,
861 (u_long)lsnp->offset,
862 (u_long)argp->type,
863 (u_long)argp->txnid->txnid,
864 (u_long)argp->prev_lsn.file,
865 (u_long)argp->prev_lsn.offset);
866 printf("\tfileid: %lu\n", (u_long)argp->fileid);
867 printf("\tpgno: %lu\n", (u_long)argp->pgno);
868 printf("\tlsn: [%lu][%lu]\n",
869 (u_long)argp->lsn.file, (u_long)argp->lsn.offset);
870 printf("\tprev: %lu\n", (u_long)argp->prev);
871 printf("\tlsn_prev: [%lu][%lu]\n",
872 (u_long)argp->lsn_prev.file, (u_long)argp->lsn_prev.offset);
873 printf("\tnext: %lu\n", (u_long)argp->next);
874 printf("\tlsn_next: [%lu][%lu]\n",
875 (u_long)argp->lsn_next.file, (u_long)argp->lsn_next.offset);
876 printf("\n");
877 free(argp);
878 return (0);
882 * PUBLIC: int __db_relink_read __P((void *, __db_relink_args **));
885 __db_relink_read(recbuf, argpp)
886 void *recbuf;
887 __db_relink_args **argpp;
889 __db_relink_args *argp;
890 u_int8_t *bp;
892 argp = (__db_relink_args *)malloc(sizeof(__db_relink_args) +
893 sizeof(DB_TXN));
894 if (argp == NULL)
895 return (ENOMEM);
896 argp->txnid = (DB_TXN *)&argp[1];
897 bp = recbuf;
898 memcpy(&argp->type, bp, sizeof(argp->type));
899 bp += sizeof(argp->type);
900 memcpy(&argp->txnid->txnid, bp, sizeof(argp->txnid->txnid));
901 bp += sizeof(argp->txnid->txnid);
902 memcpy(&argp->prev_lsn, bp, sizeof(DB_LSN));
903 bp += sizeof(DB_LSN);
904 memcpy(&argp->fileid, bp, sizeof(argp->fileid));
905 bp += sizeof(argp->fileid);
906 memcpy(&argp->pgno, bp, sizeof(argp->pgno));
907 bp += sizeof(argp->pgno);
908 memcpy(&argp->lsn, bp, sizeof(argp->lsn));
909 bp += sizeof(argp->lsn);
910 memcpy(&argp->prev, bp, sizeof(argp->prev));
911 bp += sizeof(argp->prev);
912 memcpy(&argp->lsn_prev, bp, sizeof(argp->lsn_prev));
913 bp += sizeof(argp->lsn_prev);
914 memcpy(&argp->next, bp, sizeof(argp->next));
915 bp += sizeof(argp->next);
916 memcpy(&argp->lsn_next, bp, sizeof(argp->lsn_next));
917 bp += sizeof(argp->lsn_next);
918 *argpp = argp;
919 return (0);
923 * PUBLIC: int __db_addpage_log
924 * PUBLIC: __P((DB_LOG *, DB_TXN *, DB_LSN *, u_int32_t,
925 * PUBLIC: u_int32_t, db_pgno_t, DB_LSN *, db_pgno_t,
926 * PUBLIC: DB_LSN *));
928 int __db_addpage_log(logp, txnid, ret_lsnp, flags,
929 fileid, pgno, lsn, nextpgno, nextlsn)
930 DB_LOG *logp;
931 DB_TXN *txnid;
932 DB_LSN *ret_lsnp;
933 u_int32_t flags;
934 u_int32_t fileid;
935 db_pgno_t pgno;
936 DB_LSN * lsn;
937 db_pgno_t nextpgno;
938 DB_LSN * nextlsn;
940 DBT logrec;
941 DB_LSN *lsnp, null_lsn;
942 u_int32_t rectype, txn_num;
943 int ret;
944 u_int8_t *bp;
946 rectype = DB_db_addpage;
947 txn_num = txnid == NULL ? 0 : txnid->txnid;
948 if (txnid == NULL) {
949 null_lsn.file = 0;
950 null_lsn.offset = 0;
951 lsnp = &null_lsn;
952 } else
953 lsnp = &txnid->last_lsn;
954 logrec.size = sizeof(rectype) + sizeof(txn_num) + sizeof(DB_LSN)
955 + sizeof(fileid)
956 + sizeof(pgno)
957 + sizeof(*lsn)
958 + sizeof(nextpgno)
959 + sizeof(*nextlsn);
960 if ((logrec.data = (void *)malloc(logrec.size)) == NULL)
961 return (ENOMEM);
963 bp = logrec.data;
964 memcpy(bp, &rectype, sizeof(rectype));
965 bp += sizeof(rectype);
966 memcpy(bp, &txn_num, sizeof(txn_num));
967 bp += sizeof(txn_num);
968 memcpy(bp, lsnp, sizeof(DB_LSN));
969 bp += sizeof(DB_LSN);
970 memcpy(bp, &fileid, sizeof(fileid));
971 bp += sizeof(fileid);
972 memcpy(bp, &pgno, sizeof(pgno));
973 bp += sizeof(pgno);
974 if (lsn != NULL)
975 memcpy(bp, lsn, sizeof(*lsn));
976 else
977 memset(bp, 0, sizeof(*lsn));
978 bp += sizeof(*lsn);
979 memcpy(bp, &nextpgno, sizeof(nextpgno));
980 bp += sizeof(nextpgno);
981 if (nextlsn != NULL)
982 memcpy(bp, nextlsn, sizeof(*nextlsn));
983 else
984 memset(bp, 0, sizeof(*nextlsn));
985 bp += sizeof(*nextlsn);
986 #ifdef DEBUG
987 if ((u_int32_t)(bp - (u_int8_t *)logrec.data) != logrec.size)
988 fprintf(stderr, "Error in log record length");
989 #endif
990 ret = log_put(logp, ret_lsnp, (DBT *)&logrec, flags);
991 if (txnid != NULL)
992 txnid->last_lsn = *ret_lsnp;
993 free(logrec.data);
994 return (ret);
998 * PUBLIC: int __db_addpage_print
999 * PUBLIC: __P((DB_LOG *, DBT *, DB_LSN *, int, void *));
1003 __db_addpage_print(notused1, dbtp, lsnp, notused3, notused4)
1004 DB_LOG *notused1;
1005 DBT *dbtp;
1006 DB_LSN *lsnp;
1007 int notused3;
1008 void *notused4;
1010 __db_addpage_args *argp;
1011 u_int32_t i;
1012 int c, ret;
1014 i = 0;
1015 c = 0;
1016 notused1 = NULL;
1017 notused3 = 0;
1018 notused4 = NULL;
1020 if ((ret = __db_addpage_read(dbtp->data, &argp)) != 0)
1021 return (ret);
1022 printf("[%lu][%lu]db_addpage: rec: %lu txnid %lx prevlsn [%lu][%lu]\n",
1023 (u_long)lsnp->file,
1024 (u_long)lsnp->offset,
1025 (u_long)argp->type,
1026 (u_long)argp->txnid->txnid,
1027 (u_long)argp->prev_lsn.file,
1028 (u_long)argp->prev_lsn.offset);
1029 printf("\tfileid: %lu\n", (u_long)argp->fileid);
1030 printf("\tpgno: %lu\n", (u_long)argp->pgno);
1031 printf("\tlsn: [%lu][%lu]\n",
1032 (u_long)argp->lsn.file, (u_long)argp->lsn.offset);
1033 printf("\tnextpgno: %lu\n", (u_long)argp->nextpgno);
1034 printf("\tnextlsn: [%lu][%lu]\n",
1035 (u_long)argp->nextlsn.file, (u_long)argp->nextlsn.offset);
1036 printf("\n");
1037 free(argp);
1038 return (0);
1042 * PUBLIC: int __db_addpage_read __P((void *, __db_addpage_args **));
1045 __db_addpage_read(recbuf, argpp)
1046 void *recbuf;
1047 __db_addpage_args **argpp;
1049 __db_addpage_args *argp;
1050 u_int8_t *bp;
1052 argp = (__db_addpage_args *)malloc(sizeof(__db_addpage_args) +
1053 sizeof(DB_TXN));
1054 if (argp == NULL)
1055 return (ENOMEM);
1056 argp->txnid = (DB_TXN *)&argp[1];
1057 bp = recbuf;
1058 memcpy(&argp->type, bp, sizeof(argp->type));
1059 bp += sizeof(argp->type);
1060 memcpy(&argp->txnid->txnid, bp, sizeof(argp->txnid->txnid));
1061 bp += sizeof(argp->txnid->txnid);
1062 memcpy(&argp->prev_lsn, bp, sizeof(DB_LSN));
1063 bp += sizeof(DB_LSN);
1064 memcpy(&argp->fileid, bp, sizeof(argp->fileid));
1065 bp += sizeof(argp->fileid);
1066 memcpy(&argp->pgno, bp, sizeof(argp->pgno));
1067 bp += sizeof(argp->pgno);
1068 memcpy(&argp->lsn, bp, sizeof(argp->lsn));
1069 bp += sizeof(argp->lsn);
1070 memcpy(&argp->nextpgno, bp, sizeof(argp->nextpgno));
1071 bp += sizeof(argp->nextpgno);
1072 memcpy(&argp->nextlsn, bp, sizeof(argp->nextlsn));
1073 bp += sizeof(argp->nextlsn);
1074 *argpp = argp;
1075 return (0);
1079 * PUBLIC: int __db_debug_log
1080 * PUBLIC: __P((DB_LOG *, DB_TXN *, DB_LSN *, u_int32_t,
1081 * PUBLIC: DBT *, u_int32_t, DBT *, DBT *,
1082 * PUBLIC: u_int32_t));
1084 int __db_debug_log(logp, txnid, ret_lsnp, flags,
1085 op, fileid, key, data, arg_flags)
1086 DB_LOG *logp;
1087 DB_TXN *txnid;
1088 DB_LSN *ret_lsnp;
1089 u_int32_t flags;
1090 DBT *op;
1091 u_int32_t fileid;
1092 DBT *key;
1093 DBT *data;
1094 u_int32_t arg_flags;
1096 DBT logrec;
1097 DB_LSN *lsnp, null_lsn;
1098 u_int32_t zero;
1099 u_int32_t rectype, txn_num;
1100 int ret;
1101 u_int8_t *bp;
1103 rectype = DB_db_debug;
1104 txn_num = txnid == NULL ? 0 : txnid->txnid;
1105 if (txnid == NULL) {
1106 null_lsn.file = 0;
1107 null_lsn.offset = 0;
1108 lsnp = &null_lsn;
1109 } else
1110 lsnp = &txnid->last_lsn;
1111 logrec.size = sizeof(rectype) + sizeof(txn_num) + sizeof(DB_LSN)
1112 + sizeof(u_int32_t) + (op == NULL ? 0 : op->size)
1113 + sizeof(fileid)
1114 + sizeof(u_int32_t) + (key == NULL ? 0 : key->size)
1115 + sizeof(u_int32_t) + (data == NULL ? 0 : data->size)
1116 + sizeof(arg_flags);
1117 if ((logrec.data = (void *)malloc(logrec.size)) == NULL)
1118 return (ENOMEM);
1120 bp = logrec.data;
1121 memcpy(bp, &rectype, sizeof(rectype));
1122 bp += sizeof(rectype);
1123 memcpy(bp, &txn_num, sizeof(txn_num));
1124 bp += sizeof(txn_num);
1125 memcpy(bp, lsnp, sizeof(DB_LSN));
1126 bp += sizeof(DB_LSN);
1127 if (op == NULL) {
1128 zero = 0;
1129 memcpy(bp, &zero, sizeof(u_int32_t));
1130 bp += sizeof(u_int32_t);
1131 } else {
1132 memcpy(bp, &op->size, sizeof(op->size));
1133 bp += sizeof(op->size);
1134 memcpy(bp, op->data, op->size);
1135 bp += op->size;
1137 memcpy(bp, &fileid, sizeof(fileid));
1138 bp += sizeof(fileid);
1139 if (key == NULL) {
1140 zero = 0;
1141 memcpy(bp, &zero, sizeof(u_int32_t));
1142 bp += sizeof(u_int32_t);
1143 } else {
1144 memcpy(bp, &key->size, sizeof(key->size));
1145 bp += sizeof(key->size);
1146 memcpy(bp, key->data, key->size);
1147 bp += key->size;
1149 if (data == NULL) {
1150 zero = 0;
1151 memcpy(bp, &zero, sizeof(u_int32_t));
1152 bp += sizeof(u_int32_t);
1153 } else {
1154 memcpy(bp, &data->size, sizeof(data->size));
1155 bp += sizeof(data->size);
1156 memcpy(bp, data->data, data->size);
1157 bp += data->size;
1159 memcpy(bp, &arg_flags, sizeof(arg_flags));
1160 bp += sizeof(arg_flags);
1161 #ifdef DEBUG
1162 if ((u_int32_t)(bp - (u_int8_t *)logrec.data) != logrec.size)
1163 fprintf(stderr, "Error in log record length");
1164 #endif
1165 ret = log_put(logp, ret_lsnp, (DBT *)&logrec, flags);
1166 if (txnid != NULL)
1167 txnid->last_lsn = *ret_lsnp;
1168 free(logrec.data);
1169 return (ret);
1173 * PUBLIC: int __db_debug_print
1174 * PUBLIC: __P((DB_LOG *, DBT *, DB_LSN *, int, void *));
1178 __db_debug_print(notused1, dbtp, lsnp, notused3, notused4)
1179 DB_LOG *notused1;
1180 DBT *dbtp;
1181 DB_LSN *lsnp;
1182 int notused3;
1183 void *notused4;
1185 __db_debug_args *argp;
1186 u_int32_t i;
1187 int c, ret;
1189 i = 0;
1190 c = 0;
1191 notused1 = NULL;
1192 notused3 = 0;
1193 notused4 = NULL;
1195 if ((ret = __db_debug_read(dbtp->data, &argp)) != 0)
1196 return (ret);
1197 printf("[%lu][%lu]db_debug: rec: %lu txnid %lx prevlsn [%lu][%lu]\n",
1198 (u_long)lsnp->file,
1199 (u_long)lsnp->offset,
1200 (u_long)argp->type,
1201 (u_long)argp->txnid->txnid,
1202 (u_long)argp->prev_lsn.file,
1203 (u_long)argp->prev_lsn.offset);
1204 printf("\top: ");
1205 for (i = 0; i < argp->op.size; i++) {
1206 c = ((char *)argp->op.data)[i];
1207 if (isprint(c) || c == 0xa)
1208 putchar(c);
1209 else
1210 printf("%#x ", c);
1212 printf("\n");
1213 printf("\tfileid: %lu\n", (u_long)argp->fileid);
1214 printf("\tkey: ");
1215 for (i = 0; i < argp->key.size; i++) {
1216 c = ((char *)argp->key.data)[i];
1217 if (isprint(c) || c == 0xa)
1218 putchar(c);
1219 else
1220 printf("%#x ", c);
1222 printf("\n");
1223 printf("\tdata: ");
1224 for (i = 0; i < argp->data.size; i++) {
1225 c = ((char *)argp->data.data)[i];
1226 if (isprint(c) || c == 0xa)
1227 putchar(c);
1228 else
1229 printf("%#x ", c);
1231 printf("\n");
1232 printf("\targ_flags: %lu\n", (u_long)argp->arg_flags);
1233 printf("\n");
1234 free(argp);
1235 return (0);
1239 * PUBLIC: int __db_debug_read __P((void *, __db_debug_args **));
1242 __db_debug_read(recbuf, argpp)
1243 void *recbuf;
1244 __db_debug_args **argpp;
1246 __db_debug_args *argp;
1247 u_int8_t *bp;
1249 argp = (__db_debug_args *)malloc(sizeof(__db_debug_args) +
1250 sizeof(DB_TXN));
1251 if (argp == NULL)
1252 return (ENOMEM);
1253 argp->txnid = (DB_TXN *)&argp[1];
1254 bp = recbuf;
1255 memcpy(&argp->type, bp, sizeof(argp->type));
1256 bp += sizeof(argp->type);
1257 memcpy(&argp->txnid->txnid, bp, sizeof(argp->txnid->txnid));
1258 bp += sizeof(argp->txnid->txnid);
1259 memcpy(&argp->prev_lsn, bp, sizeof(DB_LSN));
1260 bp += sizeof(DB_LSN);
1261 memcpy(&argp->op.size, bp, sizeof(u_int32_t));
1262 bp += sizeof(u_int32_t);
1263 argp->op.data = bp;
1264 bp += argp->op.size;
1265 memcpy(&argp->fileid, bp, sizeof(argp->fileid));
1266 bp += sizeof(argp->fileid);
1267 memcpy(&argp->key.size, bp, sizeof(u_int32_t));
1268 bp += sizeof(u_int32_t);
1269 argp->key.data = bp;
1270 bp += argp->key.size;
1271 memcpy(&argp->data.size, bp, sizeof(u_int32_t));
1272 bp += sizeof(u_int32_t);
1273 argp->data.data = bp;
1274 bp += argp->data.size;
1275 memcpy(&argp->arg_flags, bp, sizeof(argp->arg_flags));
1276 bp += sizeof(argp->arg_flags);
1277 *argpp = argp;
1278 return (0);
1282 * PUBLIC: int __db_noop_log
1283 * PUBLIC: __P((DB_LOG *, DB_TXN *, DB_LSN *, u_int32_t));
1285 int __db_noop_log(logp, txnid, ret_lsnp, flags)
1286 DB_LOG *logp;
1287 DB_TXN *txnid;
1288 DB_LSN *ret_lsnp;
1289 u_int32_t flags;
1291 DBT logrec;
1292 DB_LSN *lsnp, null_lsn;
1293 u_int32_t rectype, txn_num;
1294 int ret;
1295 u_int8_t *bp;
1297 rectype = DB_db_noop;
1298 txn_num = txnid == NULL ? 0 : txnid->txnid;
1299 if (txnid == NULL) {
1300 null_lsn.file = 0;
1301 null_lsn.offset = 0;
1302 lsnp = &null_lsn;
1303 } else
1304 lsnp = &txnid->last_lsn;
1305 logrec.size = sizeof(rectype) + sizeof(txn_num) + sizeof(DB_LSN);
1306 if ((logrec.data = (void *)malloc(logrec.size)) == NULL)
1307 return (ENOMEM);
1309 bp = logrec.data;
1310 memcpy(bp, &rectype, sizeof(rectype));
1311 bp += sizeof(rectype);
1312 memcpy(bp, &txn_num, sizeof(txn_num));
1313 bp += sizeof(txn_num);
1314 memcpy(bp, lsnp, sizeof(DB_LSN));
1315 bp += sizeof(DB_LSN);
1316 #ifdef DEBUG
1317 if ((u_int32_t)(bp - (u_int8_t *)logrec.data) != logrec.size)
1318 fprintf(stderr, "Error in log record length");
1319 #endif
1320 ret = log_put(logp, ret_lsnp, (DBT *)&logrec, flags);
1321 if (txnid != NULL)
1322 txnid->last_lsn = *ret_lsnp;
1323 free(logrec.data);
1324 return (ret);
1328 * PUBLIC: int __db_noop_print
1329 * PUBLIC: __P((DB_LOG *, DBT *, DB_LSN *, int, void *));
1333 __db_noop_print(notused1, dbtp, lsnp, notused3, notused4)
1334 DB_LOG *notused1;
1335 DBT *dbtp;
1336 DB_LSN *lsnp;
1337 int notused3;
1338 void *notused4;
1340 __db_noop_args *argp;
1341 u_int32_t i;
1342 int c, ret;
1344 i = 0;
1345 c = 0;
1346 notused1 = NULL;
1347 notused3 = 0;
1348 notused4 = NULL;
1350 if ((ret = __db_noop_read(dbtp->data, &argp)) != 0)
1351 return (ret);
1352 printf("[%lu][%lu]db_noop: rec: %lu txnid %lx prevlsn [%lu][%lu]\n",
1353 (u_long)lsnp->file,
1354 (u_long)lsnp->offset,
1355 (u_long)argp->type,
1356 (u_long)argp->txnid->txnid,
1357 (u_long)argp->prev_lsn.file,
1358 (u_long)argp->prev_lsn.offset);
1359 printf("\n");
1360 free(argp);
1361 return (0);
1365 * PUBLIC: int __db_noop_read __P((void *, __db_noop_args **));
1368 __db_noop_read(recbuf, argpp)
1369 void *recbuf;
1370 __db_noop_args **argpp;
1372 __db_noop_args *argp;
1373 u_int8_t *bp;
1375 argp = (__db_noop_args *)malloc(sizeof(__db_noop_args) +
1376 sizeof(DB_TXN));
1377 if (argp == NULL)
1378 return (ENOMEM);
1379 argp->txnid = (DB_TXN *)&argp[1];
1380 bp = recbuf;
1381 memcpy(&argp->type, bp, sizeof(argp->type));
1382 bp += sizeof(argp->type);
1383 memcpy(&argp->txnid->txnid, bp, sizeof(argp->txnid->txnid));
1384 bp += sizeof(argp->txnid->txnid);
1385 memcpy(&argp->prev_lsn, bp, sizeof(DB_LSN));
1386 bp += sizeof(DB_LSN);
1387 *argpp = argp;
1388 return (0);
1392 * PUBLIC: int __db_init_print __P((DB_ENV *));
1395 __db_init_print(dbenv)
1396 DB_ENV *dbenv;
1398 int ret;
1400 if ((ret = __db_add_recovery(dbenv,
1401 __db_addrem_print, DB_db_addrem)) != 0)
1402 return (ret);
1403 if ((ret = __db_add_recovery(dbenv,
1404 __db_split_print, DB_db_split)) != 0)
1405 return (ret);
1406 if ((ret = __db_add_recovery(dbenv,
1407 __db_big_print, DB_db_big)) != 0)
1408 return (ret);
1409 if ((ret = __db_add_recovery(dbenv,
1410 __db_ovref_print, DB_db_ovref)) != 0)
1411 return (ret);
1412 if ((ret = __db_add_recovery(dbenv,
1413 __db_relink_print, DB_db_relink)) != 0)
1414 return (ret);
1415 if ((ret = __db_add_recovery(dbenv,
1416 __db_addpage_print, DB_db_addpage)) != 0)
1417 return (ret);
1418 if ((ret = __db_add_recovery(dbenv,
1419 __db_debug_print, DB_db_debug)) != 0)
1420 return (ret);
1421 if ((ret = __db_add_recovery(dbenv,
1422 __db_noop_print, DB_db_noop)) != 0)
1423 return (ret);
1424 return (0);
1428 * PUBLIC: int __db_init_recover __P((DB_ENV *));
1431 __db_init_recover(dbenv)
1432 DB_ENV *dbenv;
1434 int ret;
1436 if ((ret = __db_add_recovery(dbenv,
1437 __db_addrem_recover, DB_db_addrem)) != 0)
1438 return (ret);
1439 if ((ret = __db_add_recovery(dbenv,
1440 __db_split_recover, DB_db_split)) != 0)
1441 return (ret);
1442 if ((ret = __db_add_recovery(dbenv,
1443 __db_big_recover, DB_db_big)) != 0)
1444 return (ret);
1445 if ((ret = __db_add_recovery(dbenv,
1446 __db_ovref_recover, DB_db_ovref)) != 0)
1447 return (ret);
1448 if ((ret = __db_add_recovery(dbenv,
1449 __db_relink_recover, DB_db_relink)) != 0)
1450 return (ret);
1451 if ((ret = __db_add_recovery(dbenv,
1452 __db_addpage_recover, DB_db_addpage)) != 0)
1453 return (ret);
1454 if ((ret = __db_add_recovery(dbenv,
1455 __db_debug_recover, DB_db_debug)) != 0)
1456 return (ret);
1457 if ((ret = __db_add_recovery(dbenv,
1458 __db_noop_recover, DB_db_noop)) != 0)
1459 return (ret);
1460 return (0);