Update.
[glibc.git] / db2 / db / db_auto.c
blob5203e0a94c632f7e798ba432b57fa4f267ffae60
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"
18 * PUBLIC: int __db_addrem_log
19 * PUBLIC: __P((DB_LOG *, DB_TXN *, DB_LSN *, u_int32_t,
20 * PUBLIC: u_int32_t, u_int32_t, db_pgno_t, u_int32_t,
21 * PUBLIC: size_t, const DBT *, const DBT *, DB_LSN *));
23 int __db_addrem_log(logp, txnid, ret_lsnp, flags,
24 opcode, fileid, pgno, indx, nbytes, hdr,
25 dbt, pagelsn)
26 DB_LOG *logp;
27 DB_TXN *txnid;
28 DB_LSN *ret_lsnp;
29 u_int32_t flags;
30 u_int32_t opcode;
31 u_int32_t fileid;
32 db_pgno_t pgno;
33 u_int32_t indx;
34 size_t nbytes;
35 const DBT *hdr;
36 const DBT *dbt;
37 DB_LSN * pagelsn;
39 DBT logrec;
40 DB_LSN *lsnp, null_lsn;
41 u_int32_t zero;
42 u_int32_t rectype, txn_num;
43 int ret;
44 u_int8_t *bp;
46 rectype = DB_db_addrem;
47 txn_num = txnid == NULL ? 0 : txnid->txnid;
48 if (txnid == NULL) {
49 null_lsn.file = 0;
50 null_lsn.offset = 0;
51 lsnp = &null_lsn;
52 } else
53 lsnp = &txnid->last_lsn;
54 logrec.size = sizeof(rectype) + sizeof(txn_num) + sizeof(DB_LSN)
55 + sizeof(opcode)
56 + sizeof(fileid)
57 + sizeof(pgno)
58 + sizeof(indx)
59 + sizeof(nbytes)
60 + sizeof(u_int32_t) + (hdr == NULL ? 0 : hdr->size)
61 + sizeof(u_int32_t) + (dbt == NULL ? 0 : dbt->size)
62 + sizeof(*pagelsn);
63 if ((logrec.data = (void *)__db_malloc(logrec.size)) == NULL)
64 return (ENOMEM);
66 bp = logrec.data;
67 memcpy(bp, &rectype, sizeof(rectype));
68 bp += sizeof(rectype);
69 memcpy(bp, &txn_num, sizeof(txn_num));
70 bp += sizeof(txn_num);
71 memcpy(bp, lsnp, sizeof(DB_LSN));
72 bp += sizeof(DB_LSN);
73 memcpy(bp, &opcode, sizeof(opcode));
74 bp += sizeof(opcode);
75 memcpy(bp, &fileid, sizeof(fileid));
76 bp += sizeof(fileid);
77 memcpy(bp, &pgno, sizeof(pgno));
78 bp += sizeof(pgno);
79 memcpy(bp, &indx, sizeof(indx));
80 bp += sizeof(indx);
81 memcpy(bp, &nbytes, sizeof(nbytes));
82 bp += sizeof(nbytes);
83 if (hdr == NULL) {
84 zero = 0;
85 memcpy(bp, &zero, sizeof(u_int32_t));
86 bp += sizeof(u_int32_t);
87 } else {
88 memcpy(bp, &hdr->size, sizeof(hdr->size));
89 bp += sizeof(hdr->size);
90 memcpy(bp, hdr->data, hdr->size);
91 bp += hdr->size;
93 if (dbt == NULL) {
94 zero = 0;
95 memcpy(bp, &zero, sizeof(u_int32_t));
96 bp += sizeof(u_int32_t);
97 } else {
98 memcpy(bp, &dbt->size, sizeof(dbt->size));
99 bp += sizeof(dbt->size);
100 memcpy(bp, dbt->data, dbt->size);
101 bp += dbt->size;
103 if (pagelsn != NULL)
104 memcpy(bp, pagelsn, sizeof(*pagelsn));
105 else
106 memset(bp, 0, sizeof(*pagelsn));
107 bp += sizeof(*pagelsn);
108 #ifdef DIAGNOSTIC
109 if ((u_int32_t)(bp - (u_int8_t *)logrec.data) != logrec.size)
110 fprintf(stderr, "Error in log record length");
111 #endif
112 ret = log_put(logp, ret_lsnp, (DBT *)&logrec, flags);
113 if (txnid != NULL)
114 txnid->last_lsn = *ret_lsnp;
115 __db_free(logrec.data);
116 return (ret);
120 * PUBLIC: int __db_addrem_print
121 * PUBLIC: __P((DB_LOG *, DBT *, DB_LSN *, int, void *));
124 __db_addrem_print(notused1, dbtp, lsnp, notused2, notused3)
125 DB_LOG *notused1;
126 DBT *dbtp;
127 DB_LSN *lsnp;
128 int notused2;
129 void *notused3;
131 __db_addrem_args *argp;
132 u_int32_t i;
133 u_int ch;
134 int ret;
136 i = 0;
137 ch = 0;
138 notused1 = NULL;
139 notused2 = 0;
140 notused3 = NULL;
142 if ((ret = __db_addrem_read(dbtp->data, &argp)) != 0)
143 return (ret);
144 printf("[%lu][%lu]db_addrem: rec: %lu txnid %lx prevlsn [%lu][%lu]\n",
145 (u_long)lsnp->file,
146 (u_long)lsnp->offset,
147 (u_long)argp->type,
148 (u_long)argp->txnid->txnid,
149 (u_long)argp->prev_lsn.file,
150 (u_long)argp->prev_lsn.offset);
151 printf("\topcode: %lu\n", (u_long)argp->opcode);
152 printf("\tfileid: %lu\n", (u_long)argp->fileid);
153 printf("\tpgno: %lu\n", (u_long)argp->pgno);
154 printf("\tindx: %lu\n", (u_long)argp->indx);
155 printf("\tnbytes: %lu\n", (u_long)argp->nbytes);
156 printf("\thdr: ");
157 for (i = 0; i < argp->hdr.size; i++) {
158 ch = ((u_int8_t *)argp->hdr.data)[i];
159 if (isprint(ch) || ch == 0xa)
160 putchar(ch);
161 else
162 printf("%#x ", ch);
164 printf("\n");
165 printf("\tdbt: ");
166 for (i = 0; i < argp->dbt.size; i++) {
167 ch = ((u_int8_t *)argp->dbt.data)[i];
168 if (isprint(ch) || ch == 0xa)
169 putchar(ch);
170 else
171 printf("%#x ", ch);
173 printf("\n");
174 printf("\tpagelsn: [%lu][%lu]\n",
175 (u_long)argp->pagelsn.file, (u_long)argp->pagelsn.offset);
176 printf("\n");
177 __db_free(argp);
178 return (0);
182 * PUBLIC: int __db_addrem_read __P((void *, __db_addrem_args **));
185 __db_addrem_read(recbuf, argpp)
186 void *recbuf;
187 __db_addrem_args **argpp;
189 __db_addrem_args *argp;
190 u_int8_t *bp;
192 argp = (__db_addrem_args *)__db_malloc(sizeof(__db_addrem_args) +
193 sizeof(DB_TXN));
194 if (argp == NULL)
195 return (ENOMEM);
196 argp->txnid = (DB_TXN *)&argp[1];
197 bp = recbuf;
198 memcpy(&argp->type, bp, sizeof(argp->type));
199 bp += sizeof(argp->type);
200 memcpy(&argp->txnid->txnid, bp, sizeof(argp->txnid->txnid));
201 bp += sizeof(argp->txnid->txnid);
202 memcpy(&argp->prev_lsn, bp, sizeof(DB_LSN));
203 bp += sizeof(DB_LSN);
204 memcpy(&argp->opcode, bp, sizeof(argp->opcode));
205 bp += sizeof(argp->opcode);
206 memcpy(&argp->fileid, bp, sizeof(argp->fileid));
207 bp += sizeof(argp->fileid);
208 memcpy(&argp->pgno, bp, sizeof(argp->pgno));
209 bp += sizeof(argp->pgno);
210 memcpy(&argp->indx, bp, sizeof(argp->indx));
211 bp += sizeof(argp->indx);
212 memcpy(&argp->nbytes, bp, sizeof(argp->nbytes));
213 bp += sizeof(argp->nbytes);
214 memcpy(&argp->hdr.size, bp, sizeof(u_int32_t));
215 bp += sizeof(u_int32_t);
216 argp->hdr.data = bp;
217 bp += argp->hdr.size;
218 memcpy(&argp->dbt.size, bp, sizeof(u_int32_t));
219 bp += sizeof(u_int32_t);
220 argp->dbt.data = bp;
221 bp += argp->dbt.size;
222 memcpy(&argp->pagelsn, bp, sizeof(argp->pagelsn));
223 bp += sizeof(argp->pagelsn);
224 *argpp = argp;
225 return (0);
229 * PUBLIC: int __db_split_log
230 * PUBLIC: __P((DB_LOG *, DB_TXN *, DB_LSN *, u_int32_t,
231 * PUBLIC: u_int32_t, u_int32_t, db_pgno_t, const DBT *,
232 * PUBLIC: DB_LSN *));
234 int __db_split_log(logp, txnid, ret_lsnp, flags,
235 opcode, fileid, pgno, pageimage, pagelsn)
236 DB_LOG *logp;
237 DB_TXN *txnid;
238 DB_LSN *ret_lsnp;
239 u_int32_t flags;
240 u_int32_t opcode;
241 u_int32_t fileid;
242 db_pgno_t pgno;
243 const DBT *pageimage;
244 DB_LSN * pagelsn;
246 DBT logrec;
247 DB_LSN *lsnp, null_lsn;
248 u_int32_t zero;
249 u_int32_t rectype, txn_num;
250 int ret;
251 u_int8_t *bp;
253 rectype = DB_db_split;
254 txn_num = txnid == NULL ? 0 : txnid->txnid;
255 if (txnid == NULL) {
256 null_lsn.file = 0;
257 null_lsn.offset = 0;
258 lsnp = &null_lsn;
259 } else
260 lsnp = &txnid->last_lsn;
261 logrec.size = sizeof(rectype) + sizeof(txn_num) + sizeof(DB_LSN)
262 + sizeof(opcode)
263 + sizeof(fileid)
264 + sizeof(pgno)
265 + sizeof(u_int32_t) + (pageimage == NULL ? 0 : pageimage->size)
266 + sizeof(*pagelsn);
267 if ((logrec.data = (void *)__db_malloc(logrec.size)) == NULL)
268 return (ENOMEM);
270 bp = logrec.data;
271 memcpy(bp, &rectype, sizeof(rectype));
272 bp += sizeof(rectype);
273 memcpy(bp, &txn_num, sizeof(txn_num));
274 bp += sizeof(txn_num);
275 memcpy(bp, lsnp, sizeof(DB_LSN));
276 bp += sizeof(DB_LSN);
277 memcpy(bp, &opcode, sizeof(opcode));
278 bp += sizeof(opcode);
279 memcpy(bp, &fileid, sizeof(fileid));
280 bp += sizeof(fileid);
281 memcpy(bp, &pgno, sizeof(pgno));
282 bp += sizeof(pgno);
283 if (pageimage == NULL) {
284 zero = 0;
285 memcpy(bp, &zero, sizeof(u_int32_t));
286 bp += sizeof(u_int32_t);
287 } else {
288 memcpy(bp, &pageimage->size, sizeof(pageimage->size));
289 bp += sizeof(pageimage->size);
290 memcpy(bp, pageimage->data, pageimage->size);
291 bp += pageimage->size;
293 if (pagelsn != NULL)
294 memcpy(bp, pagelsn, sizeof(*pagelsn));
295 else
296 memset(bp, 0, sizeof(*pagelsn));
297 bp += sizeof(*pagelsn);
298 #ifdef DIAGNOSTIC
299 if ((u_int32_t)(bp - (u_int8_t *)logrec.data) != logrec.size)
300 fprintf(stderr, "Error in log record length");
301 #endif
302 ret = log_put(logp, ret_lsnp, (DBT *)&logrec, flags);
303 if (txnid != NULL)
304 txnid->last_lsn = *ret_lsnp;
305 __db_free(logrec.data);
306 return (ret);
310 * PUBLIC: int __db_split_print
311 * PUBLIC: __P((DB_LOG *, DBT *, DB_LSN *, int, void *));
314 __db_split_print(notused1, dbtp, lsnp, notused2, notused3)
315 DB_LOG *notused1;
316 DBT *dbtp;
317 DB_LSN *lsnp;
318 int notused2;
319 void *notused3;
321 __db_split_args *argp;
322 u_int32_t i;
323 u_int ch;
324 int ret;
326 i = 0;
327 ch = 0;
328 notused1 = NULL;
329 notused2 = 0;
330 notused3 = NULL;
332 if ((ret = __db_split_read(dbtp->data, &argp)) != 0)
333 return (ret);
334 printf("[%lu][%lu]db_split: rec: %lu txnid %lx prevlsn [%lu][%lu]\n",
335 (u_long)lsnp->file,
336 (u_long)lsnp->offset,
337 (u_long)argp->type,
338 (u_long)argp->txnid->txnid,
339 (u_long)argp->prev_lsn.file,
340 (u_long)argp->prev_lsn.offset);
341 printf("\topcode: %lu\n", (u_long)argp->opcode);
342 printf("\tfileid: %lu\n", (u_long)argp->fileid);
343 printf("\tpgno: %lu\n", (u_long)argp->pgno);
344 printf("\tpageimage: ");
345 for (i = 0; i < argp->pageimage.size; i++) {
346 ch = ((u_int8_t *)argp->pageimage.data)[i];
347 if (isprint(ch) || ch == 0xa)
348 putchar(ch);
349 else
350 printf("%#x ", ch);
352 printf("\n");
353 printf("\tpagelsn: [%lu][%lu]\n",
354 (u_long)argp->pagelsn.file, (u_long)argp->pagelsn.offset);
355 printf("\n");
356 __db_free(argp);
357 return (0);
361 * PUBLIC: int __db_split_read __P((void *, __db_split_args **));
364 __db_split_read(recbuf, argpp)
365 void *recbuf;
366 __db_split_args **argpp;
368 __db_split_args *argp;
369 u_int8_t *bp;
371 argp = (__db_split_args *)__db_malloc(sizeof(__db_split_args) +
372 sizeof(DB_TXN));
373 if (argp == NULL)
374 return (ENOMEM);
375 argp->txnid = (DB_TXN *)&argp[1];
376 bp = recbuf;
377 memcpy(&argp->type, bp, sizeof(argp->type));
378 bp += sizeof(argp->type);
379 memcpy(&argp->txnid->txnid, bp, sizeof(argp->txnid->txnid));
380 bp += sizeof(argp->txnid->txnid);
381 memcpy(&argp->prev_lsn, bp, sizeof(DB_LSN));
382 bp += sizeof(DB_LSN);
383 memcpy(&argp->opcode, bp, sizeof(argp->opcode));
384 bp += sizeof(argp->opcode);
385 memcpy(&argp->fileid, bp, sizeof(argp->fileid));
386 bp += sizeof(argp->fileid);
387 memcpy(&argp->pgno, bp, sizeof(argp->pgno));
388 bp += sizeof(argp->pgno);
389 memcpy(&argp->pageimage.size, bp, sizeof(u_int32_t));
390 bp += sizeof(u_int32_t);
391 argp->pageimage.data = bp;
392 bp += argp->pageimage.size;
393 memcpy(&argp->pagelsn, bp, sizeof(argp->pagelsn));
394 bp += sizeof(argp->pagelsn);
395 *argpp = argp;
396 return (0);
400 * PUBLIC: int __db_big_log
401 * PUBLIC: __P((DB_LOG *, DB_TXN *, DB_LSN *, u_int32_t,
402 * PUBLIC: u_int32_t, u_int32_t, db_pgno_t, db_pgno_t,
403 * PUBLIC: db_pgno_t, const DBT *, DB_LSN *, DB_LSN *,
404 * PUBLIC: DB_LSN *));
406 int __db_big_log(logp, txnid, ret_lsnp, flags,
407 opcode, fileid, pgno, prev_pgno, next_pgno, dbt,
408 pagelsn, prevlsn, nextlsn)
409 DB_LOG *logp;
410 DB_TXN *txnid;
411 DB_LSN *ret_lsnp;
412 u_int32_t flags;
413 u_int32_t opcode;
414 u_int32_t fileid;
415 db_pgno_t pgno;
416 db_pgno_t prev_pgno;
417 db_pgno_t next_pgno;
418 const DBT *dbt;
419 DB_LSN * pagelsn;
420 DB_LSN * prevlsn;
421 DB_LSN * nextlsn;
423 DBT logrec;
424 DB_LSN *lsnp, null_lsn;
425 u_int32_t zero;
426 u_int32_t rectype, txn_num;
427 int ret;
428 u_int8_t *bp;
430 rectype = DB_db_big;
431 txn_num = txnid == NULL ? 0 : txnid->txnid;
432 if (txnid == NULL) {
433 null_lsn.file = 0;
434 null_lsn.offset = 0;
435 lsnp = &null_lsn;
436 } else
437 lsnp = &txnid->last_lsn;
438 logrec.size = sizeof(rectype) + sizeof(txn_num) + sizeof(DB_LSN)
439 + sizeof(opcode)
440 + sizeof(fileid)
441 + sizeof(pgno)
442 + sizeof(prev_pgno)
443 + sizeof(next_pgno)
444 + sizeof(u_int32_t) + (dbt == NULL ? 0 : dbt->size)
445 + sizeof(*pagelsn)
446 + sizeof(*prevlsn)
447 + sizeof(*nextlsn);
448 if ((logrec.data = (void *)__db_malloc(logrec.size)) == NULL)
449 return (ENOMEM);
451 bp = logrec.data;
452 memcpy(bp, &rectype, sizeof(rectype));
453 bp += sizeof(rectype);
454 memcpy(bp, &txn_num, sizeof(txn_num));
455 bp += sizeof(txn_num);
456 memcpy(bp, lsnp, sizeof(DB_LSN));
457 bp += sizeof(DB_LSN);
458 memcpy(bp, &opcode, sizeof(opcode));
459 bp += sizeof(opcode);
460 memcpy(bp, &fileid, sizeof(fileid));
461 bp += sizeof(fileid);
462 memcpy(bp, &pgno, sizeof(pgno));
463 bp += sizeof(pgno);
464 memcpy(bp, &prev_pgno, sizeof(prev_pgno));
465 bp += sizeof(prev_pgno);
466 memcpy(bp, &next_pgno, sizeof(next_pgno));
467 bp += sizeof(next_pgno);
468 if (dbt == NULL) {
469 zero = 0;
470 memcpy(bp, &zero, sizeof(u_int32_t));
471 bp += sizeof(u_int32_t);
472 } else {
473 memcpy(bp, &dbt->size, sizeof(dbt->size));
474 bp += sizeof(dbt->size);
475 memcpy(bp, dbt->data, dbt->size);
476 bp += dbt->size;
478 if (pagelsn != NULL)
479 memcpy(bp, pagelsn, sizeof(*pagelsn));
480 else
481 memset(bp, 0, sizeof(*pagelsn));
482 bp += sizeof(*pagelsn);
483 if (prevlsn != NULL)
484 memcpy(bp, prevlsn, sizeof(*prevlsn));
485 else
486 memset(bp, 0, sizeof(*prevlsn));
487 bp += sizeof(*prevlsn);
488 if (nextlsn != NULL)
489 memcpy(bp, nextlsn, sizeof(*nextlsn));
490 else
491 memset(bp, 0, sizeof(*nextlsn));
492 bp += sizeof(*nextlsn);
493 #ifdef DIAGNOSTIC
494 if ((u_int32_t)(bp - (u_int8_t *)logrec.data) != logrec.size)
495 fprintf(stderr, "Error in log record length");
496 #endif
497 ret = log_put(logp, ret_lsnp, (DBT *)&logrec, flags);
498 if (txnid != NULL)
499 txnid->last_lsn = *ret_lsnp;
500 __db_free(logrec.data);
501 return (ret);
505 * PUBLIC: int __db_big_print
506 * PUBLIC: __P((DB_LOG *, DBT *, DB_LSN *, int, void *));
509 __db_big_print(notused1, dbtp, lsnp, notused2, notused3)
510 DB_LOG *notused1;
511 DBT *dbtp;
512 DB_LSN *lsnp;
513 int notused2;
514 void *notused3;
516 __db_big_args *argp;
517 u_int32_t i;
518 u_int ch;
519 int ret;
521 i = 0;
522 ch = 0;
523 notused1 = NULL;
524 notused2 = 0;
525 notused3 = NULL;
527 if ((ret = __db_big_read(dbtp->data, &argp)) != 0)
528 return (ret);
529 printf("[%lu][%lu]db_big: rec: %lu txnid %lx prevlsn [%lu][%lu]\n",
530 (u_long)lsnp->file,
531 (u_long)lsnp->offset,
532 (u_long)argp->type,
533 (u_long)argp->txnid->txnid,
534 (u_long)argp->prev_lsn.file,
535 (u_long)argp->prev_lsn.offset);
536 printf("\topcode: %lu\n", (u_long)argp->opcode);
537 printf("\tfileid: %lu\n", (u_long)argp->fileid);
538 printf("\tpgno: %lu\n", (u_long)argp->pgno);
539 printf("\tprev_pgno: %lu\n", (u_long)argp->prev_pgno);
540 printf("\tnext_pgno: %lu\n", (u_long)argp->next_pgno);
541 printf("\tdbt: ");
542 for (i = 0; i < argp->dbt.size; i++) {
543 ch = ((u_int8_t *)argp->dbt.data)[i];
544 if (isprint(ch) || ch == 0xa)
545 putchar(ch);
546 else
547 printf("%#x ", ch);
549 printf("\n");
550 printf("\tpagelsn: [%lu][%lu]\n",
551 (u_long)argp->pagelsn.file, (u_long)argp->pagelsn.offset);
552 printf("\tprevlsn: [%lu][%lu]\n",
553 (u_long)argp->prevlsn.file, (u_long)argp->prevlsn.offset);
554 printf("\tnextlsn: [%lu][%lu]\n",
555 (u_long)argp->nextlsn.file, (u_long)argp->nextlsn.offset);
556 printf("\n");
557 __db_free(argp);
558 return (0);
562 * PUBLIC: int __db_big_read __P((void *, __db_big_args **));
565 __db_big_read(recbuf, argpp)
566 void *recbuf;
567 __db_big_args **argpp;
569 __db_big_args *argp;
570 u_int8_t *bp;
572 argp = (__db_big_args *)__db_malloc(sizeof(__db_big_args) +
573 sizeof(DB_TXN));
574 if (argp == NULL)
575 return (ENOMEM);
576 argp->txnid = (DB_TXN *)&argp[1];
577 bp = recbuf;
578 memcpy(&argp->type, bp, sizeof(argp->type));
579 bp += sizeof(argp->type);
580 memcpy(&argp->txnid->txnid, bp, sizeof(argp->txnid->txnid));
581 bp += sizeof(argp->txnid->txnid);
582 memcpy(&argp->prev_lsn, bp, sizeof(DB_LSN));
583 bp += sizeof(DB_LSN);
584 memcpy(&argp->opcode, bp, sizeof(argp->opcode));
585 bp += sizeof(argp->opcode);
586 memcpy(&argp->fileid, bp, sizeof(argp->fileid));
587 bp += sizeof(argp->fileid);
588 memcpy(&argp->pgno, bp, sizeof(argp->pgno));
589 bp += sizeof(argp->pgno);
590 memcpy(&argp->prev_pgno, bp, sizeof(argp->prev_pgno));
591 bp += sizeof(argp->prev_pgno);
592 memcpy(&argp->next_pgno, bp, sizeof(argp->next_pgno));
593 bp += sizeof(argp->next_pgno);
594 memcpy(&argp->dbt.size, bp, sizeof(u_int32_t));
595 bp += sizeof(u_int32_t);
596 argp->dbt.data = bp;
597 bp += argp->dbt.size;
598 memcpy(&argp->pagelsn, bp, sizeof(argp->pagelsn));
599 bp += sizeof(argp->pagelsn);
600 memcpy(&argp->prevlsn, bp, sizeof(argp->prevlsn));
601 bp += sizeof(argp->prevlsn);
602 memcpy(&argp->nextlsn, bp, sizeof(argp->nextlsn));
603 bp += sizeof(argp->nextlsn);
604 *argpp = argp;
605 return (0);
609 * PUBLIC: int __db_ovref_log
610 * PUBLIC: __P((DB_LOG *, DB_TXN *, DB_LSN *, u_int32_t,
611 * PUBLIC: u_int32_t, db_pgno_t, int32_t, DB_LSN *));
613 int __db_ovref_log(logp, txnid, ret_lsnp, flags,
614 fileid, pgno, adjust, lsn)
615 DB_LOG *logp;
616 DB_TXN *txnid;
617 DB_LSN *ret_lsnp;
618 u_int32_t flags;
619 u_int32_t fileid;
620 db_pgno_t pgno;
621 int32_t adjust;
622 DB_LSN * lsn;
624 DBT logrec;
625 DB_LSN *lsnp, null_lsn;
626 u_int32_t rectype, txn_num;
627 int ret;
628 u_int8_t *bp;
630 rectype = DB_db_ovref;
631 txn_num = txnid == NULL ? 0 : txnid->txnid;
632 if (txnid == NULL) {
633 null_lsn.file = 0;
634 null_lsn.offset = 0;
635 lsnp = &null_lsn;
636 } else
637 lsnp = &txnid->last_lsn;
638 logrec.size = sizeof(rectype) + sizeof(txn_num) + sizeof(DB_LSN)
639 + sizeof(fileid)
640 + sizeof(pgno)
641 + sizeof(adjust)
642 + sizeof(*lsn);
643 if ((logrec.data = (void *)__db_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 memcpy(bp, &adjust, sizeof(adjust));
658 bp += sizeof(adjust);
659 if (lsn != NULL)
660 memcpy(bp, lsn, sizeof(*lsn));
661 else
662 memset(bp, 0, sizeof(*lsn));
663 bp += sizeof(*lsn);
664 #ifdef DIAGNOSTIC
665 if ((u_int32_t)(bp - (u_int8_t *)logrec.data) != logrec.size)
666 fprintf(stderr, "Error in log record length");
667 #endif
668 ret = log_put(logp, ret_lsnp, (DBT *)&logrec, flags);
669 if (txnid != NULL)
670 txnid->last_lsn = *ret_lsnp;
671 __db_free(logrec.data);
672 return (ret);
676 * PUBLIC: int __db_ovref_print
677 * PUBLIC: __P((DB_LOG *, DBT *, DB_LSN *, int, void *));
680 __db_ovref_print(notused1, dbtp, lsnp, notused2, notused3)
681 DB_LOG *notused1;
682 DBT *dbtp;
683 DB_LSN *lsnp;
684 int notused2;
685 void *notused3;
687 __db_ovref_args *argp;
688 u_int32_t i;
689 u_int ch;
690 int ret;
692 i = 0;
693 ch = 0;
694 notused1 = NULL;
695 notused2 = 0;
696 notused3 = NULL;
698 if ((ret = __db_ovref_read(dbtp->data, &argp)) != 0)
699 return (ret);
700 printf("[%lu][%lu]db_ovref: rec: %lu txnid %lx prevlsn [%lu][%lu]\n",
701 (u_long)lsnp->file,
702 (u_long)lsnp->offset,
703 (u_long)argp->type,
704 (u_long)argp->txnid->txnid,
705 (u_long)argp->prev_lsn.file,
706 (u_long)argp->prev_lsn.offset);
707 printf("\tfileid: %lu\n", (u_long)argp->fileid);
708 printf("\tpgno: %lu\n", (u_long)argp->pgno);
709 printf("\tadjust: %ld\n", (long)argp->adjust);
710 printf("\tlsn: [%lu][%lu]\n",
711 (u_long)argp->lsn.file, (u_long)argp->lsn.offset);
712 printf("\n");
713 __db_free(argp);
714 return (0);
718 * PUBLIC: int __db_ovref_read __P((void *, __db_ovref_args **));
721 __db_ovref_read(recbuf, argpp)
722 void *recbuf;
723 __db_ovref_args **argpp;
725 __db_ovref_args *argp;
726 u_int8_t *bp;
728 argp = (__db_ovref_args *)__db_malloc(sizeof(__db_ovref_args) +
729 sizeof(DB_TXN));
730 if (argp == NULL)
731 return (ENOMEM);
732 argp->txnid = (DB_TXN *)&argp[1];
733 bp = recbuf;
734 memcpy(&argp->type, bp, sizeof(argp->type));
735 bp += sizeof(argp->type);
736 memcpy(&argp->txnid->txnid, bp, sizeof(argp->txnid->txnid));
737 bp += sizeof(argp->txnid->txnid);
738 memcpy(&argp->prev_lsn, bp, sizeof(DB_LSN));
739 bp += sizeof(DB_LSN);
740 memcpy(&argp->fileid, bp, sizeof(argp->fileid));
741 bp += sizeof(argp->fileid);
742 memcpy(&argp->pgno, bp, sizeof(argp->pgno));
743 bp += sizeof(argp->pgno);
744 memcpy(&argp->adjust, bp, sizeof(argp->adjust));
745 bp += sizeof(argp->adjust);
746 memcpy(&argp->lsn, bp, sizeof(argp->lsn));
747 bp += sizeof(argp->lsn);
748 *argpp = argp;
749 return (0);
753 * PUBLIC: int __db_relink_log
754 * PUBLIC: __P((DB_LOG *, DB_TXN *, DB_LSN *, u_int32_t,
755 * PUBLIC: u_int32_t, db_pgno_t, DB_LSN *, db_pgno_t,
756 * PUBLIC: DB_LSN *, db_pgno_t, DB_LSN *));
758 int __db_relink_log(logp, txnid, ret_lsnp, flags,
759 fileid, pgno, lsn, prev, lsn_prev, next,
760 lsn_next)
761 DB_LOG *logp;
762 DB_TXN *txnid;
763 DB_LSN *ret_lsnp;
764 u_int32_t flags;
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;
773 DBT logrec;
774 DB_LSN *lsnp, null_lsn;
775 u_int32_t rectype, txn_num;
776 int ret;
777 u_int8_t *bp;
779 rectype = DB_db_relink;
780 txn_num = txnid == NULL ? 0 : txnid->txnid;
781 if (txnid == NULL) {
782 null_lsn.file = 0;
783 null_lsn.offset = 0;
784 lsnp = &null_lsn;
785 } else
786 lsnp = &txnid->last_lsn;
787 logrec.size = sizeof(rectype) + sizeof(txn_num) + sizeof(DB_LSN)
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 ((logrec.data = (void *)__db_malloc(logrec.size)) == NULL)
796 return (ENOMEM);
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, &fileid, sizeof(fileid));
806 bp += sizeof(fileid);
807 memcpy(bp, &pgno, sizeof(pgno));
808 bp += sizeof(pgno);
809 if (lsn != NULL)
810 memcpy(bp, lsn, sizeof(*lsn));
811 else
812 memset(bp, 0, sizeof(*lsn));
813 bp += sizeof(*lsn);
814 memcpy(bp, &prev, sizeof(prev));
815 bp += sizeof(prev);
816 if (lsn_prev != NULL)
817 memcpy(bp, lsn_prev, sizeof(*lsn_prev));
818 else
819 memset(bp, 0, sizeof(*lsn_prev));
820 bp += sizeof(*lsn_prev);
821 memcpy(bp, &next, sizeof(next));
822 bp += sizeof(next);
823 if (lsn_next != NULL)
824 memcpy(bp, lsn_next, sizeof(*lsn_next));
825 else
826 memset(bp, 0, sizeof(*lsn_next));
827 bp += sizeof(*lsn_next);
828 #ifdef DIAGNOSTIC
829 if ((u_int32_t)(bp - (u_int8_t *)logrec.data) != logrec.size)
830 fprintf(stderr, "Error in log record length");
831 #endif
832 ret = log_put(logp, ret_lsnp, (DBT *)&logrec, flags);
833 if (txnid != NULL)
834 txnid->last_lsn = *ret_lsnp;
835 __db_free(logrec.data);
836 return (ret);
840 * PUBLIC: int __db_relink_print
841 * PUBLIC: __P((DB_LOG *, DBT *, DB_LSN *, int, void *));
844 __db_relink_print(notused1, dbtp, lsnp, notused2, notused3)
845 DB_LOG *notused1;
846 DBT *dbtp;
847 DB_LSN *lsnp;
848 int notused2;
849 void *notused3;
851 __db_relink_args *argp;
852 u_int32_t i;
853 u_int ch;
854 int ret;
856 i = 0;
857 ch = 0;
858 notused1 = NULL;
859 notused2 = 0;
860 notused3 = NULL;
862 if ((ret = __db_relink_read(dbtp->data, &argp)) != 0)
863 return (ret);
864 printf("[%lu][%lu]db_relink: rec: %lu txnid %lx prevlsn [%lu][%lu]\n",
865 (u_long)lsnp->file,
866 (u_long)lsnp->offset,
867 (u_long)argp->type,
868 (u_long)argp->txnid->txnid,
869 (u_long)argp->prev_lsn.file,
870 (u_long)argp->prev_lsn.offset);
871 printf("\tfileid: %lu\n", (u_long)argp->fileid);
872 printf("\tpgno: %lu\n", (u_long)argp->pgno);
873 printf("\tlsn: [%lu][%lu]\n",
874 (u_long)argp->lsn.file, (u_long)argp->lsn.offset);
875 printf("\tprev: %lu\n", (u_long)argp->prev);
876 printf("\tlsn_prev: [%lu][%lu]\n",
877 (u_long)argp->lsn_prev.file, (u_long)argp->lsn_prev.offset);
878 printf("\tnext: %lu\n", (u_long)argp->next);
879 printf("\tlsn_next: [%lu][%lu]\n",
880 (u_long)argp->lsn_next.file, (u_long)argp->lsn_next.offset);
881 printf("\n");
882 __db_free(argp);
883 return (0);
887 * PUBLIC: int __db_relink_read __P((void *, __db_relink_args **));
890 __db_relink_read(recbuf, argpp)
891 void *recbuf;
892 __db_relink_args **argpp;
894 __db_relink_args *argp;
895 u_int8_t *bp;
897 argp = (__db_relink_args *)__db_malloc(sizeof(__db_relink_args) +
898 sizeof(DB_TXN));
899 if (argp == NULL)
900 return (ENOMEM);
901 argp->txnid = (DB_TXN *)&argp[1];
902 bp = recbuf;
903 memcpy(&argp->type, bp, sizeof(argp->type));
904 bp += sizeof(argp->type);
905 memcpy(&argp->txnid->txnid, bp, sizeof(argp->txnid->txnid));
906 bp += sizeof(argp->txnid->txnid);
907 memcpy(&argp->prev_lsn, bp, sizeof(DB_LSN));
908 bp += sizeof(DB_LSN);
909 memcpy(&argp->fileid, bp, sizeof(argp->fileid));
910 bp += sizeof(argp->fileid);
911 memcpy(&argp->pgno, bp, sizeof(argp->pgno));
912 bp += sizeof(argp->pgno);
913 memcpy(&argp->lsn, bp, sizeof(argp->lsn));
914 bp += sizeof(argp->lsn);
915 memcpy(&argp->prev, bp, sizeof(argp->prev));
916 bp += sizeof(argp->prev);
917 memcpy(&argp->lsn_prev, bp, sizeof(argp->lsn_prev));
918 bp += sizeof(argp->lsn_prev);
919 memcpy(&argp->next, bp, sizeof(argp->next));
920 bp += sizeof(argp->next);
921 memcpy(&argp->lsn_next, bp, sizeof(argp->lsn_next));
922 bp += sizeof(argp->lsn_next);
923 *argpp = argp;
924 return (0);
928 * PUBLIC: int __db_addpage_log
929 * PUBLIC: __P((DB_LOG *, DB_TXN *, DB_LSN *, u_int32_t,
930 * PUBLIC: u_int32_t, db_pgno_t, DB_LSN *, db_pgno_t,
931 * PUBLIC: DB_LSN *));
933 int __db_addpage_log(logp, txnid, ret_lsnp, flags,
934 fileid, pgno, lsn, nextpgno, nextlsn)
935 DB_LOG *logp;
936 DB_TXN *txnid;
937 DB_LSN *ret_lsnp;
938 u_int32_t flags;
939 u_int32_t fileid;
940 db_pgno_t pgno;
941 DB_LSN * lsn;
942 db_pgno_t nextpgno;
943 DB_LSN * nextlsn;
945 DBT logrec;
946 DB_LSN *lsnp, null_lsn;
947 u_int32_t rectype, txn_num;
948 int ret;
949 u_int8_t *bp;
951 rectype = DB_db_addpage;
952 txn_num = txnid == NULL ? 0 : txnid->txnid;
953 if (txnid == NULL) {
954 null_lsn.file = 0;
955 null_lsn.offset = 0;
956 lsnp = &null_lsn;
957 } else
958 lsnp = &txnid->last_lsn;
959 logrec.size = sizeof(rectype) + sizeof(txn_num) + sizeof(DB_LSN)
960 + sizeof(fileid)
961 + sizeof(pgno)
962 + sizeof(*lsn)
963 + sizeof(nextpgno)
964 + sizeof(*nextlsn);
965 if ((logrec.data = (void *)__db_malloc(logrec.size)) == NULL)
966 return (ENOMEM);
968 bp = logrec.data;
969 memcpy(bp, &rectype, sizeof(rectype));
970 bp += sizeof(rectype);
971 memcpy(bp, &txn_num, sizeof(txn_num));
972 bp += sizeof(txn_num);
973 memcpy(bp, lsnp, sizeof(DB_LSN));
974 bp += sizeof(DB_LSN);
975 memcpy(bp, &fileid, sizeof(fileid));
976 bp += sizeof(fileid);
977 memcpy(bp, &pgno, sizeof(pgno));
978 bp += sizeof(pgno);
979 if (lsn != NULL)
980 memcpy(bp, lsn, sizeof(*lsn));
981 else
982 memset(bp, 0, sizeof(*lsn));
983 bp += sizeof(*lsn);
984 memcpy(bp, &nextpgno, sizeof(nextpgno));
985 bp += sizeof(nextpgno);
986 if (nextlsn != NULL)
987 memcpy(bp, nextlsn, sizeof(*nextlsn));
988 else
989 memset(bp, 0, sizeof(*nextlsn));
990 bp += sizeof(*nextlsn);
991 #ifdef DIAGNOSTIC
992 if ((u_int32_t)(bp - (u_int8_t *)logrec.data) != logrec.size)
993 fprintf(stderr, "Error in log record length");
994 #endif
995 ret = log_put(logp, ret_lsnp, (DBT *)&logrec, flags);
996 if (txnid != NULL)
997 txnid->last_lsn = *ret_lsnp;
998 __db_free(logrec.data);
999 return (ret);
1003 * PUBLIC: int __db_addpage_print
1004 * PUBLIC: __P((DB_LOG *, DBT *, DB_LSN *, int, void *));
1007 __db_addpage_print(notused1, dbtp, lsnp, notused2, notused3)
1008 DB_LOG *notused1;
1009 DBT *dbtp;
1010 DB_LSN *lsnp;
1011 int notused2;
1012 void *notused3;
1014 __db_addpage_args *argp;
1015 u_int32_t i;
1016 u_int ch;
1017 int ret;
1019 i = 0;
1020 ch = 0;
1021 notused1 = NULL;
1022 notused2 = 0;
1023 notused3 = NULL;
1025 if ((ret = __db_addpage_read(dbtp->data, &argp)) != 0)
1026 return (ret);
1027 printf("[%lu][%lu]db_addpage: rec: %lu txnid %lx prevlsn [%lu][%lu]\n",
1028 (u_long)lsnp->file,
1029 (u_long)lsnp->offset,
1030 (u_long)argp->type,
1031 (u_long)argp->txnid->txnid,
1032 (u_long)argp->prev_lsn.file,
1033 (u_long)argp->prev_lsn.offset);
1034 printf("\tfileid: %lu\n", (u_long)argp->fileid);
1035 printf("\tpgno: %lu\n", (u_long)argp->pgno);
1036 printf("\tlsn: [%lu][%lu]\n",
1037 (u_long)argp->lsn.file, (u_long)argp->lsn.offset);
1038 printf("\tnextpgno: %lu\n", (u_long)argp->nextpgno);
1039 printf("\tnextlsn: [%lu][%lu]\n",
1040 (u_long)argp->nextlsn.file, (u_long)argp->nextlsn.offset);
1041 printf("\n");
1042 __db_free(argp);
1043 return (0);
1047 * PUBLIC: int __db_addpage_read __P((void *, __db_addpage_args **));
1050 __db_addpage_read(recbuf, argpp)
1051 void *recbuf;
1052 __db_addpage_args **argpp;
1054 __db_addpage_args *argp;
1055 u_int8_t *bp;
1057 argp = (__db_addpage_args *)__db_malloc(sizeof(__db_addpage_args) +
1058 sizeof(DB_TXN));
1059 if (argp == NULL)
1060 return (ENOMEM);
1061 argp->txnid = (DB_TXN *)&argp[1];
1062 bp = recbuf;
1063 memcpy(&argp->type, bp, sizeof(argp->type));
1064 bp += sizeof(argp->type);
1065 memcpy(&argp->txnid->txnid, bp, sizeof(argp->txnid->txnid));
1066 bp += sizeof(argp->txnid->txnid);
1067 memcpy(&argp->prev_lsn, bp, sizeof(DB_LSN));
1068 bp += sizeof(DB_LSN);
1069 memcpy(&argp->fileid, bp, sizeof(argp->fileid));
1070 bp += sizeof(argp->fileid);
1071 memcpy(&argp->pgno, bp, sizeof(argp->pgno));
1072 bp += sizeof(argp->pgno);
1073 memcpy(&argp->lsn, bp, sizeof(argp->lsn));
1074 bp += sizeof(argp->lsn);
1075 memcpy(&argp->nextpgno, bp, sizeof(argp->nextpgno));
1076 bp += sizeof(argp->nextpgno);
1077 memcpy(&argp->nextlsn, bp, sizeof(argp->nextlsn));
1078 bp += sizeof(argp->nextlsn);
1079 *argpp = argp;
1080 return (0);
1084 * PUBLIC: int __db_debug_log
1085 * PUBLIC: __P((DB_LOG *, DB_TXN *, DB_LSN *, u_int32_t,
1086 * PUBLIC: const DBT *, u_int32_t, const DBT *, const DBT *,
1087 * PUBLIC: u_int32_t));
1089 int __db_debug_log(logp, txnid, ret_lsnp, flags,
1090 op, fileid, key, data, arg_flags)
1091 DB_LOG *logp;
1092 DB_TXN *txnid;
1093 DB_LSN *ret_lsnp;
1094 u_int32_t flags;
1095 const DBT *op;
1096 u_int32_t fileid;
1097 const DBT *key;
1098 const DBT *data;
1099 u_int32_t arg_flags;
1101 DBT logrec;
1102 DB_LSN *lsnp, null_lsn;
1103 u_int32_t zero;
1104 u_int32_t rectype, txn_num;
1105 int ret;
1106 u_int8_t *bp;
1108 rectype = DB_db_debug;
1109 txn_num = txnid == NULL ? 0 : txnid->txnid;
1110 if (txnid == NULL) {
1111 null_lsn.file = 0;
1112 null_lsn.offset = 0;
1113 lsnp = &null_lsn;
1114 } else
1115 lsnp = &txnid->last_lsn;
1116 logrec.size = sizeof(rectype) + sizeof(txn_num) + sizeof(DB_LSN)
1117 + sizeof(u_int32_t) + (op == NULL ? 0 : op->size)
1118 + sizeof(fileid)
1119 + sizeof(u_int32_t) + (key == NULL ? 0 : key->size)
1120 + sizeof(u_int32_t) + (data == NULL ? 0 : data->size)
1121 + sizeof(arg_flags);
1122 if ((logrec.data = (void *)__db_malloc(logrec.size)) == NULL)
1123 return (ENOMEM);
1125 bp = logrec.data;
1126 memcpy(bp, &rectype, sizeof(rectype));
1127 bp += sizeof(rectype);
1128 memcpy(bp, &txn_num, sizeof(txn_num));
1129 bp += sizeof(txn_num);
1130 memcpy(bp, lsnp, sizeof(DB_LSN));
1131 bp += sizeof(DB_LSN);
1132 if (op == NULL) {
1133 zero = 0;
1134 memcpy(bp, &zero, sizeof(u_int32_t));
1135 bp += sizeof(u_int32_t);
1136 } else {
1137 memcpy(bp, &op->size, sizeof(op->size));
1138 bp += sizeof(op->size);
1139 memcpy(bp, op->data, op->size);
1140 bp += op->size;
1142 memcpy(bp, &fileid, sizeof(fileid));
1143 bp += sizeof(fileid);
1144 if (key == NULL) {
1145 zero = 0;
1146 memcpy(bp, &zero, sizeof(u_int32_t));
1147 bp += sizeof(u_int32_t);
1148 } else {
1149 memcpy(bp, &key->size, sizeof(key->size));
1150 bp += sizeof(key->size);
1151 memcpy(bp, key->data, key->size);
1152 bp += key->size;
1154 if (data == NULL) {
1155 zero = 0;
1156 memcpy(bp, &zero, sizeof(u_int32_t));
1157 bp += sizeof(u_int32_t);
1158 } else {
1159 memcpy(bp, &data->size, sizeof(data->size));
1160 bp += sizeof(data->size);
1161 memcpy(bp, data->data, data->size);
1162 bp += data->size;
1164 memcpy(bp, &arg_flags, sizeof(arg_flags));
1165 bp += sizeof(arg_flags);
1166 #ifdef DIAGNOSTIC
1167 if ((u_int32_t)(bp - (u_int8_t *)logrec.data) != logrec.size)
1168 fprintf(stderr, "Error in log record length");
1169 #endif
1170 ret = log_put(logp, ret_lsnp, (DBT *)&logrec, flags);
1171 if (txnid != NULL)
1172 txnid->last_lsn = *ret_lsnp;
1173 __db_free(logrec.data);
1174 return (ret);
1178 * PUBLIC: int __db_debug_print
1179 * PUBLIC: __P((DB_LOG *, DBT *, DB_LSN *, int, void *));
1182 __db_debug_print(notused1, dbtp, lsnp, notused2, notused3)
1183 DB_LOG *notused1;
1184 DBT *dbtp;
1185 DB_LSN *lsnp;
1186 int notused2;
1187 void *notused3;
1189 __db_debug_args *argp;
1190 u_int32_t i;
1191 u_int ch;
1192 int ret;
1194 i = 0;
1195 ch = 0;
1196 notused1 = NULL;
1197 notused2 = 0;
1198 notused3 = NULL;
1200 if ((ret = __db_debug_read(dbtp->data, &argp)) != 0)
1201 return (ret);
1202 printf("[%lu][%lu]db_debug: rec: %lu txnid %lx prevlsn [%lu][%lu]\n",
1203 (u_long)lsnp->file,
1204 (u_long)lsnp->offset,
1205 (u_long)argp->type,
1206 (u_long)argp->txnid->txnid,
1207 (u_long)argp->prev_lsn.file,
1208 (u_long)argp->prev_lsn.offset);
1209 printf("\top: ");
1210 for (i = 0; i < argp->op.size; i++) {
1211 ch = ((u_int8_t *)argp->op.data)[i];
1212 if (isprint(ch) || ch == 0xa)
1213 putchar(ch);
1214 else
1215 printf("%#x ", ch);
1217 printf("\n");
1218 printf("\tfileid: %lu\n", (u_long)argp->fileid);
1219 printf("\tkey: ");
1220 for (i = 0; i < argp->key.size; i++) {
1221 ch = ((u_int8_t *)argp->key.data)[i];
1222 if (isprint(ch) || ch == 0xa)
1223 putchar(ch);
1224 else
1225 printf("%#x ", ch);
1227 printf("\n");
1228 printf("\tdata: ");
1229 for (i = 0; i < argp->data.size; i++) {
1230 ch = ((u_int8_t *)argp->data.data)[i];
1231 if (isprint(ch) || ch == 0xa)
1232 putchar(ch);
1233 else
1234 printf("%#x ", ch);
1236 printf("\n");
1237 printf("\targ_flags: %lu\n", (u_long)argp->arg_flags);
1238 printf("\n");
1239 __db_free(argp);
1240 return (0);
1244 * PUBLIC: int __db_debug_read __P((void *, __db_debug_args **));
1247 __db_debug_read(recbuf, argpp)
1248 void *recbuf;
1249 __db_debug_args **argpp;
1251 __db_debug_args *argp;
1252 u_int8_t *bp;
1254 argp = (__db_debug_args *)__db_malloc(sizeof(__db_debug_args) +
1255 sizeof(DB_TXN));
1256 if (argp == NULL)
1257 return (ENOMEM);
1258 argp->txnid = (DB_TXN *)&argp[1];
1259 bp = recbuf;
1260 memcpy(&argp->type, bp, sizeof(argp->type));
1261 bp += sizeof(argp->type);
1262 memcpy(&argp->txnid->txnid, bp, sizeof(argp->txnid->txnid));
1263 bp += sizeof(argp->txnid->txnid);
1264 memcpy(&argp->prev_lsn, bp, sizeof(DB_LSN));
1265 bp += sizeof(DB_LSN);
1266 memcpy(&argp->op.size, bp, sizeof(u_int32_t));
1267 bp += sizeof(u_int32_t);
1268 argp->op.data = bp;
1269 bp += argp->op.size;
1270 memcpy(&argp->fileid, bp, sizeof(argp->fileid));
1271 bp += sizeof(argp->fileid);
1272 memcpy(&argp->key.size, bp, sizeof(u_int32_t));
1273 bp += sizeof(u_int32_t);
1274 argp->key.data = bp;
1275 bp += argp->key.size;
1276 memcpy(&argp->data.size, bp, sizeof(u_int32_t));
1277 bp += sizeof(u_int32_t);
1278 argp->data.data = bp;
1279 bp += argp->data.size;
1280 memcpy(&argp->arg_flags, bp, sizeof(argp->arg_flags));
1281 bp += sizeof(argp->arg_flags);
1282 *argpp = argp;
1283 return (0);
1287 * PUBLIC: int __db_noop_log
1288 * PUBLIC: __P((DB_LOG *, DB_TXN *, DB_LSN *, u_int32_t,
1289 * PUBLIC: u_int32_t, db_pgno_t, DB_LSN *));
1291 int __db_noop_log(logp, txnid, ret_lsnp, flags,
1292 fileid, pgno, prevlsn)
1293 DB_LOG *logp;
1294 DB_TXN *txnid;
1295 DB_LSN *ret_lsnp;
1296 u_int32_t flags;
1297 u_int32_t fileid;
1298 db_pgno_t pgno;
1299 DB_LSN * prevlsn;
1301 DBT logrec;
1302 DB_LSN *lsnp, null_lsn;
1303 u_int32_t rectype, txn_num;
1304 int ret;
1305 u_int8_t *bp;
1307 rectype = DB_db_noop;
1308 txn_num = txnid == NULL ? 0 : txnid->txnid;
1309 if (txnid == NULL) {
1310 null_lsn.file = 0;
1311 null_lsn.offset = 0;
1312 lsnp = &null_lsn;
1313 } else
1314 lsnp = &txnid->last_lsn;
1315 logrec.size = sizeof(rectype) + sizeof(txn_num) + sizeof(DB_LSN)
1316 + sizeof(fileid)
1317 + sizeof(pgno)
1318 + sizeof(*prevlsn);
1319 if ((logrec.data = (void *)__db_malloc(logrec.size)) == NULL)
1320 return (ENOMEM);
1322 bp = logrec.data;
1323 memcpy(bp, &rectype, sizeof(rectype));
1324 bp += sizeof(rectype);
1325 memcpy(bp, &txn_num, sizeof(txn_num));
1326 bp += sizeof(txn_num);
1327 memcpy(bp, lsnp, sizeof(DB_LSN));
1328 bp += sizeof(DB_LSN);
1329 memcpy(bp, &fileid, sizeof(fileid));
1330 bp += sizeof(fileid);
1331 memcpy(bp, &pgno, sizeof(pgno));
1332 bp += sizeof(pgno);
1333 if (prevlsn != NULL)
1334 memcpy(bp, prevlsn, sizeof(*prevlsn));
1335 else
1336 memset(bp, 0, sizeof(*prevlsn));
1337 bp += sizeof(*prevlsn);
1338 #ifdef DIAGNOSTIC
1339 if ((u_int32_t)(bp - (u_int8_t *)logrec.data) != logrec.size)
1340 fprintf(stderr, "Error in log record length");
1341 #endif
1342 ret = log_put(logp, ret_lsnp, (DBT *)&logrec, flags);
1343 if (txnid != NULL)
1344 txnid->last_lsn = *ret_lsnp;
1345 __db_free(logrec.data);
1346 return (ret);
1350 * PUBLIC: int __db_noop_print
1351 * PUBLIC: __P((DB_LOG *, DBT *, DB_LSN *, int, void *));
1354 __db_noop_print(notused1, dbtp, lsnp, notused2, notused3)
1355 DB_LOG *notused1;
1356 DBT *dbtp;
1357 DB_LSN *lsnp;
1358 int notused2;
1359 void *notused3;
1361 __db_noop_args *argp;
1362 u_int32_t i;
1363 u_int ch;
1364 int ret;
1366 i = 0;
1367 ch = 0;
1368 notused1 = NULL;
1369 notused2 = 0;
1370 notused3 = NULL;
1372 if ((ret = __db_noop_read(dbtp->data, &argp)) != 0)
1373 return (ret);
1374 printf("[%lu][%lu]db_noop: rec: %lu txnid %lx prevlsn [%lu][%lu]\n",
1375 (u_long)lsnp->file,
1376 (u_long)lsnp->offset,
1377 (u_long)argp->type,
1378 (u_long)argp->txnid->txnid,
1379 (u_long)argp->prev_lsn.file,
1380 (u_long)argp->prev_lsn.offset);
1381 printf("\tfileid: %lu\n", (u_long)argp->fileid);
1382 printf("\tpgno: %lu\n", (u_long)argp->pgno);
1383 printf("\tprevlsn: [%lu][%lu]\n",
1384 (u_long)argp->prevlsn.file, (u_long)argp->prevlsn.offset);
1385 printf("\n");
1386 __db_free(argp);
1387 return (0);
1391 * PUBLIC: int __db_noop_read __P((void *, __db_noop_args **));
1394 __db_noop_read(recbuf, argpp)
1395 void *recbuf;
1396 __db_noop_args **argpp;
1398 __db_noop_args *argp;
1399 u_int8_t *bp;
1401 argp = (__db_noop_args *)__db_malloc(sizeof(__db_noop_args) +
1402 sizeof(DB_TXN));
1403 if (argp == NULL)
1404 return (ENOMEM);
1405 argp->txnid = (DB_TXN *)&argp[1];
1406 bp = recbuf;
1407 memcpy(&argp->type, bp, sizeof(argp->type));
1408 bp += sizeof(argp->type);
1409 memcpy(&argp->txnid->txnid, bp, sizeof(argp->txnid->txnid));
1410 bp += sizeof(argp->txnid->txnid);
1411 memcpy(&argp->prev_lsn, bp, sizeof(DB_LSN));
1412 bp += sizeof(DB_LSN);
1413 memcpy(&argp->fileid, bp, sizeof(argp->fileid));
1414 bp += sizeof(argp->fileid);
1415 memcpy(&argp->pgno, bp, sizeof(argp->pgno));
1416 bp += sizeof(argp->pgno);
1417 memcpy(&argp->prevlsn, bp, sizeof(argp->prevlsn));
1418 bp += sizeof(argp->prevlsn);
1419 *argpp = argp;
1420 return (0);
1424 * PUBLIC: int __db_init_print __P((DB_ENV *));
1427 __db_init_print(dbenv)
1428 DB_ENV *dbenv;
1430 int ret;
1432 if ((ret = __db_add_recovery(dbenv,
1433 __db_addrem_print, DB_db_addrem)) != 0)
1434 return (ret);
1435 if ((ret = __db_add_recovery(dbenv,
1436 __db_split_print, DB_db_split)) != 0)
1437 return (ret);
1438 if ((ret = __db_add_recovery(dbenv,
1439 __db_big_print, DB_db_big)) != 0)
1440 return (ret);
1441 if ((ret = __db_add_recovery(dbenv,
1442 __db_ovref_print, DB_db_ovref)) != 0)
1443 return (ret);
1444 if ((ret = __db_add_recovery(dbenv,
1445 __db_relink_print, DB_db_relink)) != 0)
1446 return (ret);
1447 if ((ret = __db_add_recovery(dbenv,
1448 __db_addpage_print, DB_db_addpage)) != 0)
1449 return (ret);
1450 if ((ret = __db_add_recovery(dbenv,
1451 __db_debug_print, DB_db_debug)) != 0)
1452 return (ret);
1453 if ((ret = __db_add_recovery(dbenv,
1454 __db_noop_print, DB_db_noop)) != 0)
1455 return (ret);
1456 return (0);
1460 * PUBLIC: int __db_init_recover __P((DB_ENV *));
1463 __db_init_recover(dbenv)
1464 DB_ENV *dbenv;
1466 int ret;
1468 if ((ret = __db_add_recovery(dbenv,
1469 __db_addrem_recover, DB_db_addrem)) != 0)
1470 return (ret);
1471 if ((ret = __db_add_recovery(dbenv,
1472 __db_split_recover, DB_db_split)) != 0)
1473 return (ret);
1474 if ((ret = __db_add_recovery(dbenv,
1475 __db_big_recover, DB_db_big)) != 0)
1476 return (ret);
1477 if ((ret = __db_add_recovery(dbenv,
1478 __db_ovref_recover, DB_db_ovref)) != 0)
1479 return (ret);
1480 if ((ret = __db_add_recovery(dbenv,
1481 __db_relink_recover, DB_db_relink)) != 0)
1482 return (ret);
1483 if ((ret = __db_add_recovery(dbenv,
1484 __db_addpage_recover, DB_db_addpage)) != 0)
1485 return (ret);
1486 if ((ret = __db_add_recovery(dbenv,
1487 __db_debug_recover, DB_db_debug)) != 0)
1488 return (ret);
1489 if ((ret = __db_add_recovery(dbenv,
1490 __db_noop_recover, DB_db_noop)) != 0)
1491 return (ret);
1492 return (0);