Update.
[glibc.git] / db2 / db / db_auto.c
blob5d3526410372bfd78a144420795702d80caa3afa
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, const DBT *, const 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 const DBT *hdr;
38 const 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 *)__db_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 __db_free(logrec.data);
118 return (ret);
122 * PUBLIC: int __db_addrem_print
123 * PUBLIC: __P((DB_LOG *, DBT *, DB_LSN *, int, void *));
126 __db_addrem_print(notused1, dbtp, lsnp, notused3, notused4)
127 DB_LOG *notused1;
128 DBT *dbtp;
129 DB_LSN *lsnp;
130 int notused3;
131 void *notused4;
133 __db_addrem_args *argp;
134 u_int32_t i;
135 int c, ret;
137 i = 0;
138 c = 0;
139 notused1 = NULL;
140 notused3 = 0;
141 notused4 = NULL;
143 if ((ret = __db_addrem_read(dbtp->data, &argp)) != 0)
144 return (ret);
145 printf("[%lu][%lu]db_addrem: rec: %lu txnid %lx prevlsn [%lu][%lu]\n",
146 (u_long)lsnp->file,
147 (u_long)lsnp->offset,
148 (u_long)argp->type,
149 (u_long)argp->txnid->txnid,
150 (u_long)argp->prev_lsn.file,
151 (u_long)argp->prev_lsn.offset);
152 printf("\topcode: %lu\n", (u_long)argp->opcode);
153 printf("\tfileid: %lu\n", (u_long)argp->fileid);
154 printf("\tpgno: %lu\n", (u_long)argp->pgno);
155 printf("\tindx: %lu\n", (u_long)argp->indx);
156 printf("\tnbytes: %lu\n", (u_long)argp->nbytes);
157 printf("\thdr: ");
158 for (i = 0; i < argp->hdr.size; i++) {
159 c = ((char *)argp->hdr.data)[i];
160 if (isprint(c) || c == 0xa)
161 putchar(c);
162 else
163 printf("%#x ", c);
165 printf("\n");
166 printf("\tdbt: ");
167 for (i = 0; i < argp->dbt.size; i++) {
168 c = ((char *)argp->dbt.data)[i];
169 if (isprint(c) || c == 0xa)
170 putchar(c);
171 else
172 printf("%#x ", c);
174 printf("\n");
175 printf("\tpagelsn: [%lu][%lu]\n",
176 (u_long)argp->pagelsn.file, (u_long)argp->pagelsn.offset);
177 printf("\n");
178 __db_free(argp);
179 return (0);
183 * PUBLIC: int __db_addrem_read __P((void *, __db_addrem_args **));
186 __db_addrem_read(recbuf, argpp)
187 void *recbuf;
188 __db_addrem_args **argpp;
190 __db_addrem_args *argp;
191 u_int8_t *bp;
193 argp = (__db_addrem_args *)__db_malloc(sizeof(__db_addrem_args) +
194 sizeof(DB_TXN));
195 if (argp == NULL)
196 return (ENOMEM);
197 argp->txnid = (DB_TXN *)&argp[1];
198 bp = recbuf;
199 memcpy(&argp->type, bp, sizeof(argp->type));
200 bp += sizeof(argp->type);
201 memcpy(&argp->txnid->txnid, bp, sizeof(argp->txnid->txnid));
202 bp += sizeof(argp->txnid->txnid);
203 memcpy(&argp->prev_lsn, bp, sizeof(DB_LSN));
204 bp += sizeof(DB_LSN);
205 memcpy(&argp->opcode, bp, sizeof(argp->opcode));
206 bp += sizeof(argp->opcode);
207 memcpy(&argp->fileid, bp, sizeof(argp->fileid));
208 bp += sizeof(argp->fileid);
209 memcpy(&argp->pgno, bp, sizeof(argp->pgno));
210 bp += sizeof(argp->pgno);
211 memcpy(&argp->indx, bp, sizeof(argp->indx));
212 bp += sizeof(argp->indx);
213 memcpy(&argp->nbytes, bp, sizeof(argp->nbytes));
214 bp += sizeof(argp->nbytes);
215 memcpy(&argp->hdr.size, bp, sizeof(u_int32_t));
216 bp += sizeof(u_int32_t);
217 argp->hdr.data = bp;
218 bp += argp->hdr.size;
219 memcpy(&argp->dbt.size, bp, sizeof(u_int32_t));
220 bp += sizeof(u_int32_t);
221 argp->dbt.data = bp;
222 bp += argp->dbt.size;
223 memcpy(&argp->pagelsn, bp, sizeof(argp->pagelsn));
224 bp += sizeof(argp->pagelsn);
225 *argpp = argp;
226 return (0);
230 * PUBLIC: int __db_split_log
231 * PUBLIC: __P((DB_LOG *, DB_TXN *, DB_LSN *, u_int32_t,
232 * PUBLIC: u_int32_t, u_int32_t, db_pgno_t, const DBT *,
233 * PUBLIC: DB_LSN *));
235 int __db_split_log(logp, txnid, ret_lsnp, flags,
236 opcode, fileid, pgno, pageimage, pagelsn)
237 DB_LOG *logp;
238 DB_TXN *txnid;
239 DB_LSN *ret_lsnp;
240 u_int32_t flags;
241 u_int32_t opcode;
242 u_int32_t fileid;
243 db_pgno_t pgno;
244 const DBT *pageimage;
245 DB_LSN * pagelsn;
247 DBT logrec;
248 DB_LSN *lsnp, null_lsn;
249 u_int32_t zero;
250 u_int32_t rectype, txn_num;
251 int ret;
252 u_int8_t *bp;
254 rectype = DB_db_split;
255 txn_num = txnid == NULL ? 0 : txnid->txnid;
256 if (txnid == NULL) {
257 null_lsn.file = 0;
258 null_lsn.offset = 0;
259 lsnp = &null_lsn;
260 } else
261 lsnp = &txnid->last_lsn;
262 logrec.size = sizeof(rectype) + sizeof(txn_num) + sizeof(DB_LSN)
263 + sizeof(opcode)
264 + sizeof(fileid)
265 + sizeof(pgno)
266 + sizeof(u_int32_t) + (pageimage == NULL ? 0 : pageimage->size)
267 + sizeof(*pagelsn);
268 if ((logrec.data = (void *)__db_malloc(logrec.size)) == NULL)
269 return (ENOMEM);
271 bp = logrec.data;
272 memcpy(bp, &rectype, sizeof(rectype));
273 bp += sizeof(rectype);
274 memcpy(bp, &txn_num, sizeof(txn_num));
275 bp += sizeof(txn_num);
276 memcpy(bp, lsnp, sizeof(DB_LSN));
277 bp += sizeof(DB_LSN);
278 memcpy(bp, &opcode, sizeof(opcode));
279 bp += sizeof(opcode);
280 memcpy(bp, &fileid, sizeof(fileid));
281 bp += sizeof(fileid);
282 memcpy(bp, &pgno, sizeof(pgno));
283 bp += sizeof(pgno);
284 if (pageimage == NULL) {
285 zero = 0;
286 memcpy(bp, &zero, sizeof(u_int32_t));
287 bp += sizeof(u_int32_t);
288 } else {
289 memcpy(bp, &pageimage->size, sizeof(pageimage->size));
290 bp += sizeof(pageimage->size);
291 memcpy(bp, pageimage->data, pageimage->size);
292 bp += pageimage->size;
294 if (pagelsn != NULL)
295 memcpy(bp, pagelsn, sizeof(*pagelsn));
296 else
297 memset(bp, 0, sizeof(*pagelsn));
298 bp += sizeof(*pagelsn);
299 #ifdef DEBUG
300 if ((u_int32_t)(bp - (u_int8_t *)logrec.data) != logrec.size)
301 fprintf(stderr, "Error in log record length");
302 #endif
303 ret = log_put(logp, ret_lsnp, (DBT *)&logrec, flags);
304 if (txnid != NULL)
305 txnid->last_lsn = *ret_lsnp;
306 __db_free(logrec.data);
307 return (ret);
311 * PUBLIC: int __db_split_print
312 * PUBLIC: __P((DB_LOG *, DBT *, DB_LSN *, int, void *));
315 __db_split_print(notused1, dbtp, lsnp, notused3, notused4)
316 DB_LOG *notused1;
317 DBT *dbtp;
318 DB_LSN *lsnp;
319 int notused3;
320 void *notused4;
322 __db_split_args *argp;
323 u_int32_t i;
324 int c, ret;
326 i = 0;
327 c = 0;
328 notused1 = NULL;
329 notused3 = 0;
330 notused4 = 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 c = ((char *)argp->pageimage.data)[i];
347 if (isprint(c) || c == 0xa)
348 putchar(c);
349 else
350 printf("%#x ", c);
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 DEBUG
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, notused3, notused4)
510 DB_LOG *notused1;
511 DBT *dbtp;
512 DB_LSN *lsnp;
513 int notused3;
514 void *notused4;
516 __db_big_args *argp;
517 u_int32_t i;
518 int c, ret;
520 i = 0;
521 c = 0;
522 notused1 = NULL;
523 notused3 = 0;
524 notused4 = NULL;
526 if ((ret = __db_big_read(dbtp->data, &argp)) != 0)
527 return (ret);
528 printf("[%lu][%lu]db_big: rec: %lu txnid %lx prevlsn [%lu][%lu]\n",
529 (u_long)lsnp->file,
530 (u_long)lsnp->offset,
531 (u_long)argp->type,
532 (u_long)argp->txnid->txnid,
533 (u_long)argp->prev_lsn.file,
534 (u_long)argp->prev_lsn.offset);
535 printf("\topcode: %lu\n", (u_long)argp->opcode);
536 printf("\tfileid: %lu\n", (u_long)argp->fileid);
537 printf("\tpgno: %lu\n", (u_long)argp->pgno);
538 printf("\tprev_pgno: %lu\n", (u_long)argp->prev_pgno);
539 printf("\tnext_pgno: %lu\n", (u_long)argp->next_pgno);
540 printf("\tdbt: ");
541 for (i = 0; i < argp->dbt.size; i++) {
542 c = ((char *)argp->dbt.data)[i];
543 if (isprint(c) || c == 0xa)
544 putchar(c);
545 else
546 printf("%#x ", c);
548 printf("\n");
549 printf("\tpagelsn: [%lu][%lu]\n",
550 (u_long)argp->pagelsn.file, (u_long)argp->pagelsn.offset);
551 printf("\tprevlsn: [%lu][%lu]\n",
552 (u_long)argp->prevlsn.file, (u_long)argp->prevlsn.offset);
553 printf("\tnextlsn: [%lu][%lu]\n",
554 (u_long)argp->nextlsn.file, (u_long)argp->nextlsn.offset);
555 printf("\n");
556 __db_free(argp);
557 return (0);
561 * PUBLIC: int __db_big_read __P((void *, __db_big_args **));
564 __db_big_read(recbuf, argpp)
565 void *recbuf;
566 __db_big_args **argpp;
568 __db_big_args *argp;
569 u_int8_t *bp;
571 argp = (__db_big_args *)__db_malloc(sizeof(__db_big_args) +
572 sizeof(DB_TXN));
573 if (argp == NULL)
574 return (ENOMEM);
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);
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 *));
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;
623 DBT logrec;
624 DB_LSN *lsnp, null_lsn;
625 u_int32_t rectype, txn_num;
626 int ret;
627 u_int8_t *bp;
629 rectype = DB_db_ovref;
630 txn_num = txnid == NULL ? 0 : txnid->txnid;
631 if (txnid == NULL) {
632 null_lsn.file = 0;
633 null_lsn.offset = 0;
634 lsnp = &null_lsn;
635 } else
636 lsnp = &txnid->last_lsn;
637 logrec.size = sizeof(rectype) + sizeof(txn_num) + sizeof(DB_LSN)
638 + sizeof(fileid)
639 + sizeof(pgno)
640 + sizeof(adjust)
641 + sizeof(*lsn);
642 if ((logrec.data = (void *)__db_malloc(logrec.size)) == NULL)
643 return (ENOMEM);
645 bp = logrec.data;
646 memcpy(bp, &rectype, sizeof(rectype));
647 bp += sizeof(rectype);
648 memcpy(bp, &txn_num, sizeof(txn_num));
649 bp += sizeof(txn_num);
650 memcpy(bp, lsnp, sizeof(DB_LSN));
651 bp += sizeof(DB_LSN);
652 memcpy(bp, &fileid, sizeof(fileid));
653 bp += sizeof(fileid);
654 memcpy(bp, &pgno, sizeof(pgno));
655 bp += sizeof(pgno);
656 memcpy(bp, &adjust, sizeof(adjust));
657 bp += sizeof(adjust);
658 if (lsn != NULL)
659 memcpy(bp, lsn, sizeof(*lsn));
660 else
661 memset(bp, 0, sizeof(*lsn));
662 bp += sizeof(*lsn);
663 #ifdef DEBUG
664 if ((u_int32_t)(bp - (u_int8_t *)logrec.data) != logrec.size)
665 fprintf(stderr, "Error in log record length");
666 #endif
667 ret = log_put(logp, ret_lsnp, (DBT *)&logrec, flags);
668 if (txnid != NULL)
669 txnid->last_lsn = *ret_lsnp;
670 __db_free(logrec.data);
671 return (ret);
675 * PUBLIC: int __db_ovref_print
676 * 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("\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 __db_free(argp);
712 return (0);
716 * PUBLIC: int __db_ovref_read __P((void *, __db_ovref_args **));
719 __db_ovref_read(recbuf, argpp)
720 void *recbuf;
721 __db_ovref_args **argpp;
723 __db_ovref_args *argp;
724 u_int8_t *bp;
726 argp = (__db_ovref_args *)__db_malloc(sizeof(__db_ovref_args) +
727 sizeof(DB_TXN));
728 if (argp == NULL)
729 return (ENOMEM);
730 argp->txnid = (DB_TXN *)&argp[1];
731 bp = recbuf;
732 memcpy(&argp->type, bp, sizeof(argp->type));
733 bp += sizeof(argp->type);
734 memcpy(&argp->txnid->txnid, bp, sizeof(argp->txnid->txnid));
735 bp += sizeof(argp->txnid->txnid);
736 memcpy(&argp->prev_lsn, bp, sizeof(DB_LSN));
737 bp += sizeof(DB_LSN);
738 memcpy(&argp->fileid, bp, sizeof(argp->fileid));
739 bp += sizeof(argp->fileid);
740 memcpy(&argp->pgno, bp, sizeof(argp->pgno));
741 bp += sizeof(argp->pgno);
742 memcpy(&argp->adjust, bp, sizeof(argp->adjust));
743 bp += sizeof(argp->adjust);
744 memcpy(&argp->lsn, bp, sizeof(argp->lsn));
745 bp += sizeof(argp->lsn);
746 *argpp = argp;
747 return (0);
751 * PUBLIC: int __db_relink_log
752 * PUBLIC: __P((DB_LOG *, DB_TXN *, DB_LSN *, u_int32_t,
753 * PUBLIC: u_int32_t, db_pgno_t, DB_LSN *, db_pgno_t,
754 * PUBLIC: DB_LSN *, db_pgno_t, DB_LSN *));
756 int __db_relink_log(logp, txnid, ret_lsnp, flags,
757 fileid, pgno, lsn, prev, lsn_prev, next,
758 lsn_next)
759 DB_LOG *logp;
760 DB_TXN *txnid;
761 DB_LSN *ret_lsnp;
762 u_int32_t flags;
763 u_int32_t fileid;
764 db_pgno_t pgno;
765 DB_LSN * lsn;
766 db_pgno_t prev;
767 DB_LSN * lsn_prev;
768 db_pgno_t next;
769 DB_LSN * lsn_next;
771 DBT logrec;
772 DB_LSN *lsnp, null_lsn;
773 u_int32_t rectype, txn_num;
774 int ret;
775 u_int8_t *bp;
777 rectype = DB_db_relink;
778 txn_num = txnid == NULL ? 0 : txnid->txnid;
779 if (txnid == NULL) {
780 null_lsn.file = 0;
781 null_lsn.offset = 0;
782 lsnp = &null_lsn;
783 } else
784 lsnp = &txnid->last_lsn;
785 logrec.size = sizeof(rectype) + sizeof(txn_num) + sizeof(DB_LSN)
786 + sizeof(fileid)
787 + sizeof(pgno)
788 + sizeof(*lsn)
789 + sizeof(prev)
790 + sizeof(*lsn_prev)
791 + sizeof(next)
792 + sizeof(*lsn_next);
793 if ((logrec.data = (void *)__db_malloc(logrec.size)) == NULL)
794 return (ENOMEM);
796 bp = logrec.data;
797 memcpy(bp, &rectype, sizeof(rectype));
798 bp += sizeof(rectype);
799 memcpy(bp, &txn_num, sizeof(txn_num));
800 bp += sizeof(txn_num);
801 memcpy(bp, lsnp, sizeof(DB_LSN));
802 bp += sizeof(DB_LSN);
803 memcpy(bp, &fileid, sizeof(fileid));
804 bp += sizeof(fileid);
805 memcpy(bp, &pgno, sizeof(pgno));
806 bp += sizeof(pgno);
807 if (lsn != NULL)
808 memcpy(bp, lsn, sizeof(*lsn));
809 else
810 memset(bp, 0, sizeof(*lsn));
811 bp += sizeof(*lsn);
812 memcpy(bp, &prev, sizeof(prev));
813 bp += sizeof(prev);
814 if (lsn_prev != NULL)
815 memcpy(bp, lsn_prev, sizeof(*lsn_prev));
816 else
817 memset(bp, 0, sizeof(*lsn_prev));
818 bp += sizeof(*lsn_prev);
819 memcpy(bp, &next, sizeof(next));
820 bp += sizeof(next);
821 if (lsn_next != NULL)
822 memcpy(bp, lsn_next, sizeof(*lsn_next));
823 else
824 memset(bp, 0, sizeof(*lsn_next));
825 bp += sizeof(*lsn_next);
826 #ifdef DEBUG
827 if ((u_int32_t)(bp - (u_int8_t *)logrec.data) != logrec.size)
828 fprintf(stderr, "Error in log record length");
829 #endif
830 ret = log_put(logp, ret_lsnp, (DBT *)&logrec, flags);
831 if (txnid != NULL)
832 txnid->last_lsn = *ret_lsnp;
833 __db_free(logrec.data);
834 return (ret);
838 * PUBLIC: int __db_relink_print
839 * PUBLIC: __P((DB_LOG *, DBT *, DB_LSN *, int, void *));
842 __db_relink_print(notused1, dbtp, lsnp, notused3, notused4)
843 DB_LOG *notused1;
844 DBT *dbtp;
845 DB_LSN *lsnp;
846 int notused3;
847 void *notused4;
849 __db_relink_args *argp;
850 u_int32_t i;
851 int c, ret;
853 i = 0;
854 c = 0;
855 notused1 = NULL;
856 notused3 = 0;
857 notused4 = NULL;
859 if ((ret = __db_relink_read(dbtp->data, &argp)) != 0)
860 return (ret);
861 printf("[%lu][%lu]db_relink: rec: %lu txnid %lx prevlsn [%lu][%lu]\n",
862 (u_long)lsnp->file,
863 (u_long)lsnp->offset,
864 (u_long)argp->type,
865 (u_long)argp->txnid->txnid,
866 (u_long)argp->prev_lsn.file,
867 (u_long)argp->prev_lsn.offset);
868 printf("\tfileid: %lu\n", (u_long)argp->fileid);
869 printf("\tpgno: %lu\n", (u_long)argp->pgno);
870 printf("\tlsn: [%lu][%lu]\n",
871 (u_long)argp->lsn.file, (u_long)argp->lsn.offset);
872 printf("\tprev: %lu\n", (u_long)argp->prev);
873 printf("\tlsn_prev: [%lu][%lu]\n",
874 (u_long)argp->lsn_prev.file, (u_long)argp->lsn_prev.offset);
875 printf("\tnext: %lu\n", (u_long)argp->next);
876 printf("\tlsn_next: [%lu][%lu]\n",
877 (u_long)argp->lsn_next.file, (u_long)argp->lsn_next.offset);
878 printf("\n");
879 __db_free(argp);
880 return (0);
884 * PUBLIC: int __db_relink_read __P((void *, __db_relink_args **));
887 __db_relink_read(recbuf, argpp)
888 void *recbuf;
889 __db_relink_args **argpp;
891 __db_relink_args *argp;
892 u_int8_t *bp;
894 argp = (__db_relink_args *)__db_malloc(sizeof(__db_relink_args) +
895 sizeof(DB_TXN));
896 if (argp == NULL)
897 return (ENOMEM);
898 argp->txnid = (DB_TXN *)&argp[1];
899 bp = recbuf;
900 memcpy(&argp->type, bp, sizeof(argp->type));
901 bp += sizeof(argp->type);
902 memcpy(&argp->txnid->txnid, bp, sizeof(argp->txnid->txnid));
903 bp += sizeof(argp->txnid->txnid);
904 memcpy(&argp->prev_lsn, bp, sizeof(DB_LSN));
905 bp += sizeof(DB_LSN);
906 memcpy(&argp->fileid, bp, sizeof(argp->fileid));
907 bp += sizeof(argp->fileid);
908 memcpy(&argp->pgno, bp, sizeof(argp->pgno));
909 bp += sizeof(argp->pgno);
910 memcpy(&argp->lsn, bp, sizeof(argp->lsn));
911 bp += sizeof(argp->lsn);
912 memcpy(&argp->prev, bp, sizeof(argp->prev));
913 bp += sizeof(argp->prev);
914 memcpy(&argp->lsn_prev, bp, sizeof(argp->lsn_prev));
915 bp += sizeof(argp->lsn_prev);
916 memcpy(&argp->next, bp, sizeof(argp->next));
917 bp += sizeof(argp->next);
918 memcpy(&argp->lsn_next, bp, sizeof(argp->lsn_next));
919 bp += sizeof(argp->lsn_next);
920 *argpp = argp;
921 return (0);
925 * PUBLIC: int __db_addpage_log
926 * PUBLIC: __P((DB_LOG *, DB_TXN *, DB_LSN *, u_int32_t,
927 * PUBLIC: u_int32_t, db_pgno_t, DB_LSN *, db_pgno_t,
928 * PUBLIC: DB_LSN *));
930 int __db_addpage_log(logp, txnid, ret_lsnp, flags,
931 fileid, pgno, lsn, nextpgno, nextlsn)
932 DB_LOG *logp;
933 DB_TXN *txnid;
934 DB_LSN *ret_lsnp;
935 u_int32_t flags;
936 u_int32_t fileid;
937 db_pgno_t pgno;
938 DB_LSN * lsn;
939 db_pgno_t nextpgno;
940 DB_LSN * nextlsn;
942 DBT logrec;
943 DB_LSN *lsnp, null_lsn;
944 u_int32_t rectype, txn_num;
945 int ret;
946 u_int8_t *bp;
948 rectype = DB_db_addpage;
949 txn_num = txnid == NULL ? 0 : txnid->txnid;
950 if (txnid == NULL) {
951 null_lsn.file = 0;
952 null_lsn.offset = 0;
953 lsnp = &null_lsn;
954 } else
955 lsnp = &txnid->last_lsn;
956 logrec.size = sizeof(rectype) + sizeof(txn_num) + sizeof(DB_LSN)
957 + sizeof(fileid)
958 + sizeof(pgno)
959 + sizeof(*lsn)
960 + sizeof(nextpgno)
961 + sizeof(*nextlsn);
962 if ((logrec.data = (void *)__db_malloc(logrec.size)) == NULL)
963 return (ENOMEM);
965 bp = logrec.data;
966 memcpy(bp, &rectype, sizeof(rectype));
967 bp += sizeof(rectype);
968 memcpy(bp, &txn_num, sizeof(txn_num));
969 bp += sizeof(txn_num);
970 memcpy(bp, lsnp, sizeof(DB_LSN));
971 bp += sizeof(DB_LSN);
972 memcpy(bp, &fileid, sizeof(fileid));
973 bp += sizeof(fileid);
974 memcpy(bp, &pgno, sizeof(pgno));
975 bp += sizeof(pgno);
976 if (lsn != NULL)
977 memcpy(bp, lsn, sizeof(*lsn));
978 else
979 memset(bp, 0, sizeof(*lsn));
980 bp += sizeof(*lsn);
981 memcpy(bp, &nextpgno, sizeof(nextpgno));
982 bp += sizeof(nextpgno);
983 if (nextlsn != NULL)
984 memcpy(bp, nextlsn, sizeof(*nextlsn));
985 else
986 memset(bp, 0, sizeof(*nextlsn));
987 bp += sizeof(*nextlsn);
988 #ifdef DEBUG
989 if ((u_int32_t)(bp - (u_int8_t *)logrec.data) != logrec.size)
990 fprintf(stderr, "Error in log record length");
991 #endif
992 ret = log_put(logp, ret_lsnp, (DBT *)&logrec, flags);
993 if (txnid != NULL)
994 txnid->last_lsn = *ret_lsnp;
995 __db_free(logrec.data);
996 return (ret);
1000 * PUBLIC: int __db_addpage_print
1001 * PUBLIC: __P((DB_LOG *, DBT *, DB_LSN *, int, void *));
1004 __db_addpage_print(notused1, dbtp, lsnp, notused3, notused4)
1005 DB_LOG *notused1;
1006 DBT *dbtp;
1007 DB_LSN *lsnp;
1008 int notused3;
1009 void *notused4;
1011 __db_addpage_args *argp;
1012 u_int32_t i;
1013 int c, ret;
1015 i = 0;
1016 c = 0;
1017 notused1 = NULL;
1018 notused3 = 0;
1019 notused4 = NULL;
1021 if ((ret = __db_addpage_read(dbtp->data, &argp)) != 0)
1022 return (ret);
1023 printf("[%lu][%lu]db_addpage: rec: %lu txnid %lx prevlsn [%lu][%lu]\n",
1024 (u_long)lsnp->file,
1025 (u_long)lsnp->offset,
1026 (u_long)argp->type,
1027 (u_long)argp->txnid->txnid,
1028 (u_long)argp->prev_lsn.file,
1029 (u_long)argp->prev_lsn.offset);
1030 printf("\tfileid: %lu\n", (u_long)argp->fileid);
1031 printf("\tpgno: %lu\n", (u_long)argp->pgno);
1032 printf("\tlsn: [%lu][%lu]\n",
1033 (u_long)argp->lsn.file, (u_long)argp->lsn.offset);
1034 printf("\tnextpgno: %lu\n", (u_long)argp->nextpgno);
1035 printf("\tnextlsn: [%lu][%lu]\n",
1036 (u_long)argp->nextlsn.file, (u_long)argp->nextlsn.offset);
1037 printf("\n");
1038 __db_free(argp);
1039 return (0);
1043 * PUBLIC: int __db_addpage_read __P((void *, __db_addpage_args **));
1046 __db_addpage_read(recbuf, argpp)
1047 void *recbuf;
1048 __db_addpage_args **argpp;
1050 __db_addpage_args *argp;
1051 u_int8_t *bp;
1053 argp = (__db_addpage_args *)__db_malloc(sizeof(__db_addpage_args) +
1054 sizeof(DB_TXN));
1055 if (argp == NULL)
1056 return (ENOMEM);
1057 argp->txnid = (DB_TXN *)&argp[1];
1058 bp = recbuf;
1059 memcpy(&argp->type, bp, sizeof(argp->type));
1060 bp += sizeof(argp->type);
1061 memcpy(&argp->txnid->txnid, bp, sizeof(argp->txnid->txnid));
1062 bp += sizeof(argp->txnid->txnid);
1063 memcpy(&argp->prev_lsn, bp, sizeof(DB_LSN));
1064 bp += sizeof(DB_LSN);
1065 memcpy(&argp->fileid, bp, sizeof(argp->fileid));
1066 bp += sizeof(argp->fileid);
1067 memcpy(&argp->pgno, bp, sizeof(argp->pgno));
1068 bp += sizeof(argp->pgno);
1069 memcpy(&argp->lsn, bp, sizeof(argp->lsn));
1070 bp += sizeof(argp->lsn);
1071 memcpy(&argp->nextpgno, bp, sizeof(argp->nextpgno));
1072 bp += sizeof(argp->nextpgno);
1073 memcpy(&argp->nextlsn, bp, sizeof(argp->nextlsn));
1074 bp += sizeof(argp->nextlsn);
1075 *argpp = argp;
1076 return (0);
1080 * PUBLIC: int __db_debug_log
1081 * PUBLIC: __P((DB_LOG *, DB_TXN *, DB_LSN *, u_int32_t,
1082 * PUBLIC: const DBT *, u_int32_t, const DBT *, const DBT *,
1083 * PUBLIC: u_int32_t));
1085 int __db_debug_log(logp, txnid, ret_lsnp, flags,
1086 op, fileid, key, data, arg_flags)
1087 DB_LOG *logp;
1088 DB_TXN *txnid;
1089 DB_LSN *ret_lsnp;
1090 u_int32_t flags;
1091 const DBT *op;
1092 u_int32_t fileid;
1093 const DBT *key;
1094 const DBT *data;
1095 u_int32_t arg_flags;
1097 DBT logrec;
1098 DB_LSN *lsnp, null_lsn;
1099 u_int32_t zero;
1100 u_int32_t rectype, txn_num;
1101 int ret;
1102 u_int8_t *bp;
1104 rectype = DB_db_debug;
1105 txn_num = txnid == NULL ? 0 : txnid->txnid;
1106 if (txnid == NULL) {
1107 null_lsn.file = 0;
1108 null_lsn.offset = 0;
1109 lsnp = &null_lsn;
1110 } else
1111 lsnp = &txnid->last_lsn;
1112 logrec.size = sizeof(rectype) + sizeof(txn_num) + sizeof(DB_LSN)
1113 + sizeof(u_int32_t) + (op == NULL ? 0 : op->size)
1114 + sizeof(fileid)
1115 + sizeof(u_int32_t) + (key == NULL ? 0 : key->size)
1116 + sizeof(u_int32_t) + (data == NULL ? 0 : data->size)
1117 + sizeof(arg_flags);
1118 if ((logrec.data = (void *)__db_malloc(logrec.size)) == NULL)
1119 return (ENOMEM);
1121 bp = logrec.data;
1122 memcpy(bp, &rectype, sizeof(rectype));
1123 bp += sizeof(rectype);
1124 memcpy(bp, &txn_num, sizeof(txn_num));
1125 bp += sizeof(txn_num);
1126 memcpy(bp, lsnp, sizeof(DB_LSN));
1127 bp += sizeof(DB_LSN);
1128 if (op == NULL) {
1129 zero = 0;
1130 memcpy(bp, &zero, sizeof(u_int32_t));
1131 bp += sizeof(u_int32_t);
1132 } else {
1133 memcpy(bp, &op->size, sizeof(op->size));
1134 bp += sizeof(op->size);
1135 memcpy(bp, op->data, op->size);
1136 bp += op->size;
1138 memcpy(bp, &fileid, sizeof(fileid));
1139 bp += sizeof(fileid);
1140 if (key == NULL) {
1141 zero = 0;
1142 memcpy(bp, &zero, sizeof(u_int32_t));
1143 bp += sizeof(u_int32_t);
1144 } else {
1145 memcpy(bp, &key->size, sizeof(key->size));
1146 bp += sizeof(key->size);
1147 memcpy(bp, key->data, key->size);
1148 bp += key->size;
1150 if (data == NULL) {
1151 zero = 0;
1152 memcpy(bp, &zero, sizeof(u_int32_t));
1153 bp += sizeof(u_int32_t);
1154 } else {
1155 memcpy(bp, &data->size, sizeof(data->size));
1156 bp += sizeof(data->size);
1157 memcpy(bp, data->data, data->size);
1158 bp += data->size;
1160 memcpy(bp, &arg_flags, sizeof(arg_flags));
1161 bp += sizeof(arg_flags);
1162 #ifdef DEBUG
1163 if ((u_int32_t)(bp - (u_int8_t *)logrec.data) != logrec.size)
1164 fprintf(stderr, "Error in log record length");
1165 #endif
1166 ret = log_put(logp, ret_lsnp, (DBT *)&logrec, flags);
1167 if (txnid != NULL)
1168 txnid->last_lsn = *ret_lsnp;
1169 __db_free(logrec.data);
1170 return (ret);
1174 * PUBLIC: int __db_debug_print
1175 * 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 __db_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 *)__db_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 *)__db_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 __db_free(logrec.data);
1324 return (ret);
1328 * PUBLIC: int __db_noop_print
1329 * PUBLIC: __P((DB_LOG *, DBT *, DB_LSN *, int, void *));
1332 __db_noop_print(notused1, dbtp, lsnp, notused3, notused4)
1333 DB_LOG *notused1;
1334 DBT *dbtp;
1335 DB_LSN *lsnp;
1336 int notused3;
1337 void *notused4;
1339 __db_noop_args *argp;
1340 u_int32_t i;
1341 int c, ret;
1343 i = 0;
1344 c = 0;
1345 notused1 = NULL;
1346 notused3 = 0;
1347 notused4 = NULL;
1349 if ((ret = __db_noop_read(dbtp->data, &argp)) != 0)
1350 return (ret);
1351 printf("[%lu][%lu]db_noop: rec: %lu txnid %lx prevlsn [%lu][%lu]\n",
1352 (u_long)lsnp->file,
1353 (u_long)lsnp->offset,
1354 (u_long)argp->type,
1355 (u_long)argp->txnid->txnid,
1356 (u_long)argp->prev_lsn.file,
1357 (u_long)argp->prev_lsn.offset);
1358 printf("\n");
1359 __db_free(argp);
1360 return (0);
1364 * PUBLIC: int __db_noop_read __P((void *, __db_noop_args **));
1367 __db_noop_read(recbuf, argpp)
1368 void *recbuf;
1369 __db_noop_args **argpp;
1371 __db_noop_args *argp;
1372 u_int8_t *bp;
1374 argp = (__db_noop_args *)__db_malloc(sizeof(__db_noop_args) +
1375 sizeof(DB_TXN));
1376 if (argp == NULL)
1377 return (ENOMEM);
1378 argp->txnid = (DB_TXN *)&argp[1];
1379 bp = recbuf;
1380 memcpy(&argp->type, bp, sizeof(argp->type));
1381 bp += sizeof(argp->type);
1382 memcpy(&argp->txnid->txnid, bp, sizeof(argp->txnid->txnid));
1383 bp += sizeof(argp->txnid->txnid);
1384 memcpy(&argp->prev_lsn, bp, sizeof(DB_LSN));
1385 bp += sizeof(DB_LSN);
1386 *argpp = argp;
1387 return (0);
1391 * PUBLIC: int __db_init_print __P((DB_ENV *));
1394 __db_init_print(dbenv)
1395 DB_ENV *dbenv;
1397 int ret;
1399 if ((ret = __db_add_recovery(dbenv,
1400 __db_addrem_print, DB_db_addrem)) != 0)
1401 return (ret);
1402 if ((ret = __db_add_recovery(dbenv,
1403 __db_split_print, DB_db_split)) != 0)
1404 return (ret);
1405 if ((ret = __db_add_recovery(dbenv,
1406 __db_big_print, DB_db_big)) != 0)
1407 return (ret);
1408 if ((ret = __db_add_recovery(dbenv,
1409 __db_ovref_print, DB_db_ovref)) != 0)
1410 return (ret);
1411 if ((ret = __db_add_recovery(dbenv,
1412 __db_relink_print, DB_db_relink)) != 0)
1413 return (ret);
1414 if ((ret = __db_add_recovery(dbenv,
1415 __db_addpage_print, DB_db_addpage)) != 0)
1416 return (ret);
1417 if ((ret = __db_add_recovery(dbenv,
1418 __db_debug_print, DB_db_debug)) != 0)
1419 return (ret);
1420 if ((ret = __db_add_recovery(dbenv,
1421 __db_noop_print, DB_db_noop)) != 0)
1422 return (ret);
1423 return (0);
1427 * PUBLIC: int __db_init_recover __P((DB_ENV *));
1430 __db_init_recover(dbenv)
1431 DB_ENV *dbenv;
1433 int ret;
1435 if ((ret = __db_add_recovery(dbenv,
1436 __db_addrem_recover, DB_db_addrem)) != 0)
1437 return (ret);
1438 if ((ret = __db_add_recovery(dbenv,
1439 __db_split_recover, DB_db_split)) != 0)
1440 return (ret);
1441 if ((ret = __db_add_recovery(dbenv,
1442 __db_big_recover, DB_db_big)) != 0)
1443 return (ret);
1444 if ((ret = __db_add_recovery(dbenv,
1445 __db_ovref_recover, DB_db_ovref)) != 0)
1446 return (ret);
1447 if ((ret = __db_add_recovery(dbenv,
1448 __db_relink_recover, DB_db_relink)) != 0)
1449 return (ret);
1450 if ((ret = __db_add_recovery(dbenv,
1451 __db_addpage_recover, DB_db_addpage)) != 0)
1452 return (ret);
1453 if ((ret = __db_add_recovery(dbenv,
1454 __db_debug_recover, DB_db_debug)) != 0)
1455 return (ret);
1456 if ((ret = __db_add_recovery(dbenv,
1457 __db_noop_recover, DB_db_noop)) != 0)
1458 return (ret);
1459 return (0);