Update.
[glibc.git] / db2 / hash / hash_auto.c
blob41b1ebed01675a72701abefa1ea0589c188b354d
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 "hash.h"
17 #include "db_am.h"
19 * PUBLIC: int __ham_insdel_log
20 * PUBLIC: __P((DB_LOG *, DB_TXN *, DB_LSN *, u_int32_t,
21 * PUBLIC: u_int32_t, u_int32_t, db_pgno_t, u_int32_t,
22 * PUBLIC: DB_LSN *, const DBT *, const DBT *));
24 int __ham_insdel_log(logp, txnid, ret_lsnp, flags,
25 opcode, fileid, pgno, ndx, pagelsn, key,
26 data)
27 DB_LOG *logp;
28 DB_TXN *txnid;
29 DB_LSN *ret_lsnp;
30 u_int32_t flags;
31 u_int32_t opcode;
32 u_int32_t fileid;
33 db_pgno_t pgno;
34 u_int32_t ndx;
35 DB_LSN * pagelsn;
36 const DBT *key;
37 const DBT *data;
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_ham_insdel;
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(ndx)
59 + sizeof(*pagelsn)
60 + sizeof(u_int32_t) + (key == NULL ? 0 : key->size)
61 + sizeof(u_int32_t) + (data == NULL ? 0 : data->size);
62 if ((logrec.data = (void *)__db_malloc(logrec.size)) == NULL)
63 return (ENOMEM);
65 bp = logrec.data;
66 memcpy(bp, &rectype, sizeof(rectype));
67 bp += sizeof(rectype);
68 memcpy(bp, &txn_num, sizeof(txn_num));
69 bp += sizeof(txn_num);
70 memcpy(bp, lsnp, sizeof(DB_LSN));
71 bp += sizeof(DB_LSN);
72 memcpy(bp, &opcode, sizeof(opcode));
73 bp += sizeof(opcode);
74 memcpy(bp, &fileid, sizeof(fileid));
75 bp += sizeof(fileid);
76 memcpy(bp, &pgno, sizeof(pgno));
77 bp += sizeof(pgno);
78 memcpy(bp, &ndx, sizeof(ndx));
79 bp += sizeof(ndx);
80 if (pagelsn != NULL)
81 memcpy(bp, pagelsn, sizeof(*pagelsn));
82 else
83 memset(bp, 0, sizeof(*pagelsn));
84 bp += sizeof(*pagelsn);
85 if (key == NULL) {
86 zero = 0;
87 memcpy(bp, &zero, sizeof(u_int32_t));
88 bp += sizeof(u_int32_t);
89 } else {
90 memcpy(bp, &key->size, sizeof(key->size));
91 bp += sizeof(key->size);
92 memcpy(bp, key->data, key->size);
93 bp += key->size;
95 if (data == NULL) {
96 zero = 0;
97 memcpy(bp, &zero, sizeof(u_int32_t));
98 bp += sizeof(u_int32_t);
99 } else {
100 memcpy(bp, &data->size, sizeof(data->size));
101 bp += sizeof(data->size);
102 memcpy(bp, data->data, data->size);
103 bp += data->size;
105 #ifdef DIAGNOSTIC
106 if ((u_int32_t)(bp - (u_int8_t *)logrec.data) != logrec.size)
107 fprintf(stderr, "Error in log record length");
108 #endif
109 ret = log_put(logp, ret_lsnp, (DBT *)&logrec, flags);
110 if (txnid != NULL)
111 txnid->last_lsn = *ret_lsnp;
112 __db_free(logrec.data);
113 return (ret);
117 * PUBLIC: int __ham_insdel_print
118 * PUBLIC: __P((DB_LOG *, DBT *, DB_LSN *, int, void *));
121 __ham_insdel_print(notused1, dbtp, lsnp, notused2, notused3)
122 DB_LOG *notused1;
123 DBT *dbtp;
124 DB_LSN *lsnp;
125 int notused2;
126 void *notused3;
128 __ham_insdel_args *argp;
129 u_int32_t i;
130 u_int ch;
131 int ret;
133 i = 0;
134 ch = 0;
135 notused1 = NULL;
136 notused2 = 0;
137 notused3 = NULL;
139 if ((ret = __ham_insdel_read(dbtp->data, &argp)) != 0)
140 return (ret);
141 printf("[%lu][%lu]ham_insdel: rec: %lu txnid %lx prevlsn [%lu][%lu]\n",
142 (u_long)lsnp->file,
143 (u_long)lsnp->offset,
144 (u_long)argp->type,
145 (u_long)argp->txnid->txnid,
146 (u_long)argp->prev_lsn.file,
147 (u_long)argp->prev_lsn.offset);
148 printf("\topcode: %lu\n", (u_long)argp->opcode);
149 printf("\tfileid: %lu\n", (u_long)argp->fileid);
150 printf("\tpgno: %lu\n", (u_long)argp->pgno);
151 printf("\tndx: %lu\n", (u_long)argp->ndx);
152 printf("\tpagelsn: [%lu][%lu]\n",
153 (u_long)argp->pagelsn.file, (u_long)argp->pagelsn.offset);
154 printf("\tkey: ");
155 for (i = 0; i < argp->key.size; i++) {
156 ch = ((u_int8_t *)argp->key.data)[i];
157 if (isprint(ch) || ch == 0xa)
158 putchar(ch);
159 else
160 printf("%#x ", ch);
162 printf("\n");
163 printf("\tdata: ");
164 for (i = 0; i < argp->data.size; i++) {
165 ch = ((u_int8_t *)argp->data.data)[i];
166 if (isprint(ch) || ch == 0xa)
167 putchar(ch);
168 else
169 printf("%#x ", ch);
171 printf("\n");
172 printf("\n");
173 __db_free(argp);
174 return (0);
178 * PUBLIC: int __ham_insdel_read __P((void *, __ham_insdel_args **));
181 __ham_insdel_read(recbuf, argpp)
182 void *recbuf;
183 __ham_insdel_args **argpp;
185 __ham_insdel_args *argp;
186 u_int8_t *bp;
188 argp = (__ham_insdel_args *)__db_malloc(sizeof(__ham_insdel_args) +
189 sizeof(DB_TXN));
190 if (argp == NULL)
191 return (ENOMEM);
192 argp->txnid = (DB_TXN *)&argp[1];
193 bp = recbuf;
194 memcpy(&argp->type, bp, sizeof(argp->type));
195 bp += sizeof(argp->type);
196 memcpy(&argp->txnid->txnid, bp, sizeof(argp->txnid->txnid));
197 bp += sizeof(argp->txnid->txnid);
198 memcpy(&argp->prev_lsn, bp, sizeof(DB_LSN));
199 bp += sizeof(DB_LSN);
200 memcpy(&argp->opcode, bp, sizeof(argp->opcode));
201 bp += sizeof(argp->opcode);
202 memcpy(&argp->fileid, bp, sizeof(argp->fileid));
203 bp += sizeof(argp->fileid);
204 memcpy(&argp->pgno, bp, sizeof(argp->pgno));
205 bp += sizeof(argp->pgno);
206 memcpy(&argp->ndx, bp, sizeof(argp->ndx));
207 bp += sizeof(argp->ndx);
208 memcpy(&argp->pagelsn, bp, sizeof(argp->pagelsn));
209 bp += sizeof(argp->pagelsn);
210 memcpy(&argp->key.size, bp, sizeof(u_int32_t));
211 bp += sizeof(u_int32_t);
212 argp->key.data = bp;
213 bp += argp->key.size;
214 memcpy(&argp->data.size, bp, sizeof(u_int32_t));
215 bp += sizeof(u_int32_t);
216 argp->data.data = bp;
217 bp += argp->data.size;
218 *argpp = argp;
219 return (0);
223 * PUBLIC: int __ham_newpage_log
224 * PUBLIC: __P((DB_LOG *, DB_TXN *, DB_LSN *, u_int32_t,
225 * PUBLIC: u_int32_t, u_int32_t, db_pgno_t, DB_LSN *,
226 * PUBLIC: db_pgno_t, DB_LSN *, db_pgno_t, DB_LSN *));
228 int __ham_newpage_log(logp, txnid, ret_lsnp, flags,
229 opcode, fileid, prev_pgno, prevlsn, new_pgno, pagelsn,
230 next_pgno, nextlsn)
231 DB_LOG *logp;
232 DB_TXN *txnid;
233 DB_LSN *ret_lsnp;
234 u_int32_t flags;
235 u_int32_t opcode;
236 u_int32_t fileid;
237 db_pgno_t prev_pgno;
238 DB_LSN * prevlsn;
239 db_pgno_t new_pgno;
240 DB_LSN * pagelsn;
241 db_pgno_t next_pgno;
242 DB_LSN * nextlsn;
244 DBT logrec;
245 DB_LSN *lsnp, null_lsn;
246 u_int32_t rectype, txn_num;
247 int ret;
248 u_int8_t *bp;
250 rectype = DB_ham_newpage;
251 txn_num = txnid == NULL ? 0 : txnid->txnid;
252 if (txnid == NULL) {
253 null_lsn.file = 0;
254 null_lsn.offset = 0;
255 lsnp = &null_lsn;
256 } else
257 lsnp = &txnid->last_lsn;
258 logrec.size = sizeof(rectype) + sizeof(txn_num) + sizeof(DB_LSN)
259 + sizeof(opcode)
260 + sizeof(fileid)
261 + sizeof(prev_pgno)
262 + sizeof(*prevlsn)
263 + sizeof(new_pgno)
264 + sizeof(*pagelsn)
265 + sizeof(next_pgno)
266 + sizeof(*nextlsn);
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, &prev_pgno, sizeof(prev_pgno));
282 bp += sizeof(prev_pgno);
283 if (prevlsn != NULL)
284 memcpy(bp, prevlsn, sizeof(*prevlsn));
285 else
286 memset(bp, 0, sizeof(*prevlsn));
287 bp += sizeof(*prevlsn);
288 memcpy(bp, &new_pgno, sizeof(new_pgno));
289 bp += sizeof(new_pgno);
290 if (pagelsn != NULL)
291 memcpy(bp, pagelsn, sizeof(*pagelsn));
292 else
293 memset(bp, 0, sizeof(*pagelsn));
294 bp += sizeof(*pagelsn);
295 memcpy(bp, &next_pgno, sizeof(next_pgno));
296 bp += sizeof(next_pgno);
297 if (nextlsn != NULL)
298 memcpy(bp, nextlsn, sizeof(*nextlsn));
299 else
300 memset(bp, 0, sizeof(*nextlsn));
301 bp += sizeof(*nextlsn);
302 #ifdef DIAGNOSTIC
303 if ((u_int32_t)(bp - (u_int8_t *)logrec.data) != logrec.size)
304 fprintf(stderr, "Error in log record length");
305 #endif
306 ret = log_put(logp, ret_lsnp, (DBT *)&logrec, flags);
307 if (txnid != NULL)
308 txnid->last_lsn = *ret_lsnp;
309 __db_free(logrec.data);
310 return (ret);
314 * PUBLIC: int __ham_newpage_print
315 * PUBLIC: __P((DB_LOG *, DBT *, DB_LSN *, int, void *));
318 __ham_newpage_print(notused1, dbtp, lsnp, notused2, notused3)
319 DB_LOG *notused1;
320 DBT *dbtp;
321 DB_LSN *lsnp;
322 int notused2;
323 void *notused3;
325 __ham_newpage_args *argp;
326 u_int32_t i;
327 u_int ch;
328 int ret;
330 i = 0;
331 ch = 0;
332 notused1 = NULL;
333 notused2 = 0;
334 notused3 = NULL;
336 if ((ret = __ham_newpage_read(dbtp->data, &argp)) != 0)
337 return (ret);
338 printf("[%lu][%lu]ham_newpage: rec: %lu txnid %lx prevlsn [%lu][%lu]\n",
339 (u_long)lsnp->file,
340 (u_long)lsnp->offset,
341 (u_long)argp->type,
342 (u_long)argp->txnid->txnid,
343 (u_long)argp->prev_lsn.file,
344 (u_long)argp->prev_lsn.offset);
345 printf("\topcode: %lu\n", (u_long)argp->opcode);
346 printf("\tfileid: %lu\n", (u_long)argp->fileid);
347 printf("\tprev_pgno: %lu\n", (u_long)argp->prev_pgno);
348 printf("\tprevlsn: [%lu][%lu]\n",
349 (u_long)argp->prevlsn.file, (u_long)argp->prevlsn.offset);
350 printf("\tnew_pgno: %lu\n", (u_long)argp->new_pgno);
351 printf("\tpagelsn: [%lu][%lu]\n",
352 (u_long)argp->pagelsn.file, (u_long)argp->pagelsn.offset);
353 printf("\tnext_pgno: %lu\n", (u_long)argp->next_pgno);
354 printf("\tnextlsn: [%lu][%lu]\n",
355 (u_long)argp->nextlsn.file, (u_long)argp->nextlsn.offset);
356 printf("\n");
357 __db_free(argp);
358 return (0);
362 * PUBLIC: int __ham_newpage_read __P((void *, __ham_newpage_args **));
365 __ham_newpage_read(recbuf, argpp)
366 void *recbuf;
367 __ham_newpage_args **argpp;
369 __ham_newpage_args *argp;
370 u_int8_t *bp;
372 argp = (__ham_newpage_args *)__db_malloc(sizeof(__ham_newpage_args) +
373 sizeof(DB_TXN));
374 if (argp == NULL)
375 return (ENOMEM);
376 argp->txnid = (DB_TXN *)&argp[1];
377 bp = recbuf;
378 memcpy(&argp->type, bp, sizeof(argp->type));
379 bp += sizeof(argp->type);
380 memcpy(&argp->txnid->txnid, bp, sizeof(argp->txnid->txnid));
381 bp += sizeof(argp->txnid->txnid);
382 memcpy(&argp->prev_lsn, bp, sizeof(DB_LSN));
383 bp += sizeof(DB_LSN);
384 memcpy(&argp->opcode, bp, sizeof(argp->opcode));
385 bp += sizeof(argp->opcode);
386 memcpy(&argp->fileid, bp, sizeof(argp->fileid));
387 bp += sizeof(argp->fileid);
388 memcpy(&argp->prev_pgno, bp, sizeof(argp->prev_pgno));
389 bp += sizeof(argp->prev_pgno);
390 memcpy(&argp->prevlsn, bp, sizeof(argp->prevlsn));
391 bp += sizeof(argp->prevlsn);
392 memcpy(&argp->new_pgno, bp, sizeof(argp->new_pgno));
393 bp += sizeof(argp->new_pgno);
394 memcpy(&argp->pagelsn, bp, sizeof(argp->pagelsn));
395 bp += sizeof(argp->pagelsn);
396 memcpy(&argp->next_pgno, bp, sizeof(argp->next_pgno));
397 bp += sizeof(argp->next_pgno);
398 memcpy(&argp->nextlsn, bp, sizeof(argp->nextlsn));
399 bp += sizeof(argp->nextlsn);
400 *argpp = argp;
401 return (0);
405 * PUBLIC: int __ham_splitmeta_log
406 * PUBLIC: __P((DB_LOG *, DB_TXN *, DB_LSN *, u_int32_t,
407 * PUBLIC: u_int32_t, u_int32_t, u_int32_t, u_int32_t,
408 * PUBLIC: DB_LSN *));
410 int __ham_splitmeta_log(logp, txnid, ret_lsnp, flags,
411 fileid, bucket, ovflpoint, spares, metalsn)
412 DB_LOG *logp;
413 DB_TXN *txnid;
414 DB_LSN *ret_lsnp;
415 u_int32_t flags;
416 u_int32_t fileid;
417 u_int32_t bucket;
418 u_int32_t ovflpoint;
419 u_int32_t spares;
420 DB_LSN * metalsn;
422 DBT logrec;
423 DB_LSN *lsnp, null_lsn;
424 u_int32_t rectype, txn_num;
425 int ret;
426 u_int8_t *bp;
428 rectype = DB_ham_splitmeta;
429 txn_num = txnid == NULL ? 0 : txnid->txnid;
430 if (txnid == NULL) {
431 null_lsn.file = 0;
432 null_lsn.offset = 0;
433 lsnp = &null_lsn;
434 } else
435 lsnp = &txnid->last_lsn;
436 logrec.size = sizeof(rectype) + sizeof(txn_num) + sizeof(DB_LSN)
437 + sizeof(fileid)
438 + sizeof(bucket)
439 + sizeof(ovflpoint)
440 + sizeof(spares)
441 + sizeof(*metalsn);
442 if ((logrec.data = (void *)__db_malloc(logrec.size)) == NULL)
443 return (ENOMEM);
445 bp = logrec.data;
446 memcpy(bp, &rectype, sizeof(rectype));
447 bp += sizeof(rectype);
448 memcpy(bp, &txn_num, sizeof(txn_num));
449 bp += sizeof(txn_num);
450 memcpy(bp, lsnp, sizeof(DB_LSN));
451 bp += sizeof(DB_LSN);
452 memcpy(bp, &fileid, sizeof(fileid));
453 bp += sizeof(fileid);
454 memcpy(bp, &bucket, sizeof(bucket));
455 bp += sizeof(bucket);
456 memcpy(bp, &ovflpoint, sizeof(ovflpoint));
457 bp += sizeof(ovflpoint);
458 memcpy(bp, &spares, sizeof(spares));
459 bp += sizeof(spares);
460 if (metalsn != NULL)
461 memcpy(bp, metalsn, sizeof(*metalsn));
462 else
463 memset(bp, 0, sizeof(*metalsn));
464 bp += sizeof(*metalsn);
465 #ifdef DIAGNOSTIC
466 if ((u_int32_t)(bp - (u_int8_t *)logrec.data) != logrec.size)
467 fprintf(stderr, "Error in log record length");
468 #endif
469 ret = log_put(logp, ret_lsnp, (DBT *)&logrec, flags);
470 if (txnid != NULL)
471 txnid->last_lsn = *ret_lsnp;
472 __db_free(logrec.data);
473 return (ret);
477 * PUBLIC: int __ham_splitmeta_print
478 * PUBLIC: __P((DB_LOG *, DBT *, DB_LSN *, int, void *));
481 __ham_splitmeta_print(notused1, dbtp, lsnp, notused2, notused3)
482 DB_LOG *notused1;
483 DBT *dbtp;
484 DB_LSN *lsnp;
485 int notused2;
486 void *notused3;
488 __ham_splitmeta_args *argp;
489 u_int32_t i;
490 u_int ch;
491 int ret;
493 i = 0;
494 ch = 0;
495 notused1 = NULL;
496 notused2 = 0;
497 notused3 = NULL;
499 if ((ret = __ham_splitmeta_read(dbtp->data, &argp)) != 0)
500 return (ret);
501 printf("[%lu][%lu]ham_splitmeta: rec: %lu txnid %lx prevlsn [%lu][%lu]\n",
502 (u_long)lsnp->file,
503 (u_long)lsnp->offset,
504 (u_long)argp->type,
505 (u_long)argp->txnid->txnid,
506 (u_long)argp->prev_lsn.file,
507 (u_long)argp->prev_lsn.offset);
508 printf("\tfileid: %lu\n", (u_long)argp->fileid);
509 printf("\tbucket: %lu\n", (u_long)argp->bucket);
510 printf("\tovflpoint: %lu\n", (u_long)argp->ovflpoint);
511 printf("\tspares: %lu\n", (u_long)argp->spares);
512 printf("\tmetalsn: [%lu][%lu]\n",
513 (u_long)argp->metalsn.file, (u_long)argp->metalsn.offset);
514 printf("\n");
515 __db_free(argp);
516 return (0);
520 * PUBLIC: int __ham_splitmeta_read __P((void *, __ham_splitmeta_args **));
523 __ham_splitmeta_read(recbuf, argpp)
524 void *recbuf;
525 __ham_splitmeta_args **argpp;
527 __ham_splitmeta_args *argp;
528 u_int8_t *bp;
530 argp = (__ham_splitmeta_args *)__db_malloc(sizeof(__ham_splitmeta_args) +
531 sizeof(DB_TXN));
532 if (argp == NULL)
533 return (ENOMEM);
534 argp->txnid = (DB_TXN *)&argp[1];
535 bp = recbuf;
536 memcpy(&argp->type, bp, sizeof(argp->type));
537 bp += sizeof(argp->type);
538 memcpy(&argp->txnid->txnid, bp, sizeof(argp->txnid->txnid));
539 bp += sizeof(argp->txnid->txnid);
540 memcpy(&argp->prev_lsn, bp, sizeof(DB_LSN));
541 bp += sizeof(DB_LSN);
542 memcpy(&argp->fileid, bp, sizeof(argp->fileid));
543 bp += sizeof(argp->fileid);
544 memcpy(&argp->bucket, bp, sizeof(argp->bucket));
545 bp += sizeof(argp->bucket);
546 memcpy(&argp->ovflpoint, bp, sizeof(argp->ovflpoint));
547 bp += sizeof(argp->ovflpoint);
548 memcpy(&argp->spares, bp, sizeof(argp->spares));
549 bp += sizeof(argp->spares);
550 memcpy(&argp->metalsn, bp, sizeof(argp->metalsn));
551 bp += sizeof(argp->metalsn);
552 *argpp = argp;
553 return (0);
557 * PUBLIC: int __ham_splitdata_log
558 * PUBLIC: __P((DB_LOG *, DB_TXN *, DB_LSN *, u_int32_t,
559 * PUBLIC: u_int32_t, u_int32_t, db_pgno_t, const DBT *,
560 * PUBLIC: DB_LSN *));
562 int __ham_splitdata_log(logp, txnid, ret_lsnp, flags,
563 fileid, opcode, pgno, pageimage, pagelsn)
564 DB_LOG *logp;
565 DB_TXN *txnid;
566 DB_LSN *ret_lsnp;
567 u_int32_t flags;
568 u_int32_t fileid;
569 u_int32_t opcode;
570 db_pgno_t pgno;
571 const DBT *pageimage;
572 DB_LSN * pagelsn;
574 DBT logrec;
575 DB_LSN *lsnp, null_lsn;
576 u_int32_t zero;
577 u_int32_t rectype, txn_num;
578 int ret;
579 u_int8_t *bp;
581 rectype = DB_ham_splitdata;
582 txn_num = txnid == NULL ? 0 : txnid->txnid;
583 if (txnid == NULL) {
584 null_lsn.file = 0;
585 null_lsn.offset = 0;
586 lsnp = &null_lsn;
587 } else
588 lsnp = &txnid->last_lsn;
589 logrec.size = sizeof(rectype) + sizeof(txn_num) + sizeof(DB_LSN)
590 + sizeof(fileid)
591 + sizeof(opcode)
592 + sizeof(pgno)
593 + sizeof(u_int32_t) + (pageimage == NULL ? 0 : pageimage->size)
594 + sizeof(*pagelsn);
595 if ((logrec.data = (void *)__db_malloc(logrec.size)) == NULL)
596 return (ENOMEM);
598 bp = logrec.data;
599 memcpy(bp, &rectype, sizeof(rectype));
600 bp += sizeof(rectype);
601 memcpy(bp, &txn_num, sizeof(txn_num));
602 bp += sizeof(txn_num);
603 memcpy(bp, lsnp, sizeof(DB_LSN));
604 bp += sizeof(DB_LSN);
605 memcpy(bp, &fileid, sizeof(fileid));
606 bp += sizeof(fileid);
607 memcpy(bp, &opcode, sizeof(opcode));
608 bp += sizeof(opcode);
609 memcpy(bp, &pgno, sizeof(pgno));
610 bp += sizeof(pgno);
611 if (pageimage == NULL) {
612 zero = 0;
613 memcpy(bp, &zero, sizeof(u_int32_t));
614 bp += sizeof(u_int32_t);
615 } else {
616 memcpy(bp, &pageimage->size, sizeof(pageimage->size));
617 bp += sizeof(pageimage->size);
618 memcpy(bp, pageimage->data, pageimage->size);
619 bp += pageimage->size;
621 if (pagelsn != NULL)
622 memcpy(bp, pagelsn, sizeof(*pagelsn));
623 else
624 memset(bp, 0, sizeof(*pagelsn));
625 bp += sizeof(*pagelsn);
626 #ifdef DIAGNOSTIC
627 if ((u_int32_t)(bp - (u_int8_t *)logrec.data) != logrec.size)
628 fprintf(stderr, "Error in log record length");
629 #endif
630 ret = log_put(logp, ret_lsnp, (DBT *)&logrec, flags);
631 if (txnid != NULL)
632 txnid->last_lsn = *ret_lsnp;
633 __db_free(logrec.data);
634 return (ret);
638 * PUBLIC: int __ham_splitdata_print
639 * PUBLIC: __P((DB_LOG *, DBT *, DB_LSN *, int, void *));
642 __ham_splitdata_print(notused1, dbtp, lsnp, notused2, notused3)
643 DB_LOG *notused1;
644 DBT *dbtp;
645 DB_LSN *lsnp;
646 int notused2;
647 void *notused3;
649 __ham_splitdata_args *argp;
650 u_int32_t i;
651 u_int ch;
652 int ret;
654 i = 0;
655 ch = 0;
656 notused1 = NULL;
657 notused2 = 0;
658 notused3 = NULL;
660 if ((ret = __ham_splitdata_read(dbtp->data, &argp)) != 0)
661 return (ret);
662 printf("[%lu][%lu]ham_splitdata: rec: %lu txnid %lx prevlsn [%lu][%lu]\n",
663 (u_long)lsnp->file,
664 (u_long)lsnp->offset,
665 (u_long)argp->type,
666 (u_long)argp->txnid->txnid,
667 (u_long)argp->prev_lsn.file,
668 (u_long)argp->prev_lsn.offset);
669 printf("\tfileid: %lu\n", (u_long)argp->fileid);
670 printf("\topcode: %lu\n", (u_long)argp->opcode);
671 printf("\tpgno: %lu\n", (u_long)argp->pgno);
672 printf("\tpageimage: ");
673 for (i = 0; i < argp->pageimage.size; i++) {
674 ch = ((u_int8_t *)argp->pageimage.data)[i];
675 if (isprint(ch) || ch == 0xa)
676 putchar(ch);
677 else
678 printf("%#x ", ch);
680 printf("\n");
681 printf("\tpagelsn: [%lu][%lu]\n",
682 (u_long)argp->pagelsn.file, (u_long)argp->pagelsn.offset);
683 printf("\n");
684 __db_free(argp);
685 return (0);
689 * PUBLIC: int __ham_splitdata_read __P((void *, __ham_splitdata_args **));
692 __ham_splitdata_read(recbuf, argpp)
693 void *recbuf;
694 __ham_splitdata_args **argpp;
696 __ham_splitdata_args *argp;
697 u_int8_t *bp;
699 argp = (__ham_splitdata_args *)__db_malloc(sizeof(__ham_splitdata_args) +
700 sizeof(DB_TXN));
701 if (argp == NULL)
702 return (ENOMEM);
703 argp->txnid = (DB_TXN *)&argp[1];
704 bp = recbuf;
705 memcpy(&argp->type, bp, sizeof(argp->type));
706 bp += sizeof(argp->type);
707 memcpy(&argp->txnid->txnid, bp, sizeof(argp->txnid->txnid));
708 bp += sizeof(argp->txnid->txnid);
709 memcpy(&argp->prev_lsn, bp, sizeof(DB_LSN));
710 bp += sizeof(DB_LSN);
711 memcpy(&argp->fileid, bp, sizeof(argp->fileid));
712 bp += sizeof(argp->fileid);
713 memcpy(&argp->opcode, bp, sizeof(argp->opcode));
714 bp += sizeof(argp->opcode);
715 memcpy(&argp->pgno, bp, sizeof(argp->pgno));
716 bp += sizeof(argp->pgno);
717 memcpy(&argp->pageimage.size, bp, sizeof(u_int32_t));
718 bp += sizeof(u_int32_t);
719 argp->pageimage.data = bp;
720 bp += argp->pageimage.size;
721 memcpy(&argp->pagelsn, bp, sizeof(argp->pagelsn));
722 bp += sizeof(argp->pagelsn);
723 *argpp = argp;
724 return (0);
728 * PUBLIC: int __ham_replace_log
729 * PUBLIC: __P((DB_LOG *, DB_TXN *, DB_LSN *, u_int32_t,
730 * PUBLIC: u_int32_t, db_pgno_t, u_int32_t, DB_LSN *,
731 * PUBLIC: int32_t, const DBT *, const DBT *, u_int32_t));
733 int __ham_replace_log(logp, txnid, ret_lsnp, flags,
734 fileid, pgno, ndx, pagelsn, off, olditem,
735 newitem, makedup)
736 DB_LOG *logp;
737 DB_TXN *txnid;
738 DB_LSN *ret_lsnp;
739 u_int32_t flags;
740 u_int32_t fileid;
741 db_pgno_t pgno;
742 u_int32_t ndx;
743 DB_LSN * pagelsn;
744 int32_t off;
745 const DBT *olditem;
746 const DBT *newitem;
747 u_int32_t makedup;
749 DBT logrec;
750 DB_LSN *lsnp, null_lsn;
751 u_int32_t zero;
752 u_int32_t rectype, txn_num;
753 int ret;
754 u_int8_t *bp;
756 rectype = DB_ham_replace;
757 txn_num = txnid == NULL ? 0 : txnid->txnid;
758 if (txnid == NULL) {
759 null_lsn.file = 0;
760 null_lsn.offset = 0;
761 lsnp = &null_lsn;
762 } else
763 lsnp = &txnid->last_lsn;
764 logrec.size = sizeof(rectype) + sizeof(txn_num) + sizeof(DB_LSN)
765 + sizeof(fileid)
766 + sizeof(pgno)
767 + sizeof(ndx)
768 + sizeof(*pagelsn)
769 + sizeof(off)
770 + sizeof(u_int32_t) + (olditem == NULL ? 0 : olditem->size)
771 + sizeof(u_int32_t) + (newitem == NULL ? 0 : newitem->size)
772 + sizeof(makedup);
773 if ((logrec.data = (void *)__db_malloc(logrec.size)) == NULL)
774 return (ENOMEM);
776 bp = logrec.data;
777 memcpy(bp, &rectype, sizeof(rectype));
778 bp += sizeof(rectype);
779 memcpy(bp, &txn_num, sizeof(txn_num));
780 bp += sizeof(txn_num);
781 memcpy(bp, lsnp, sizeof(DB_LSN));
782 bp += sizeof(DB_LSN);
783 memcpy(bp, &fileid, sizeof(fileid));
784 bp += sizeof(fileid);
785 memcpy(bp, &pgno, sizeof(pgno));
786 bp += sizeof(pgno);
787 memcpy(bp, &ndx, sizeof(ndx));
788 bp += sizeof(ndx);
789 if (pagelsn != NULL)
790 memcpy(bp, pagelsn, sizeof(*pagelsn));
791 else
792 memset(bp, 0, sizeof(*pagelsn));
793 bp += sizeof(*pagelsn);
794 memcpy(bp, &off, sizeof(off));
795 bp += sizeof(off);
796 if (olditem == NULL) {
797 zero = 0;
798 memcpy(bp, &zero, sizeof(u_int32_t));
799 bp += sizeof(u_int32_t);
800 } else {
801 memcpy(bp, &olditem->size, sizeof(olditem->size));
802 bp += sizeof(olditem->size);
803 memcpy(bp, olditem->data, olditem->size);
804 bp += olditem->size;
806 if (newitem == NULL) {
807 zero = 0;
808 memcpy(bp, &zero, sizeof(u_int32_t));
809 bp += sizeof(u_int32_t);
810 } else {
811 memcpy(bp, &newitem->size, sizeof(newitem->size));
812 bp += sizeof(newitem->size);
813 memcpy(bp, newitem->data, newitem->size);
814 bp += newitem->size;
816 memcpy(bp, &makedup, sizeof(makedup));
817 bp += sizeof(makedup);
818 #ifdef DIAGNOSTIC
819 if ((u_int32_t)(bp - (u_int8_t *)logrec.data) != logrec.size)
820 fprintf(stderr, "Error in log record length");
821 #endif
822 ret = log_put(logp, ret_lsnp, (DBT *)&logrec, flags);
823 if (txnid != NULL)
824 txnid->last_lsn = *ret_lsnp;
825 __db_free(logrec.data);
826 return (ret);
830 * PUBLIC: int __ham_replace_print
831 * PUBLIC: __P((DB_LOG *, DBT *, DB_LSN *, int, void *));
834 __ham_replace_print(notused1, dbtp, lsnp, notused2, notused3)
835 DB_LOG *notused1;
836 DBT *dbtp;
837 DB_LSN *lsnp;
838 int notused2;
839 void *notused3;
841 __ham_replace_args *argp;
842 u_int32_t i;
843 u_int ch;
844 int ret;
846 i = 0;
847 ch = 0;
848 notused1 = NULL;
849 notused2 = 0;
850 notused3 = NULL;
852 if ((ret = __ham_replace_read(dbtp->data, &argp)) != 0)
853 return (ret);
854 printf("[%lu][%lu]ham_replace: rec: %lu txnid %lx prevlsn [%lu][%lu]\n",
855 (u_long)lsnp->file,
856 (u_long)lsnp->offset,
857 (u_long)argp->type,
858 (u_long)argp->txnid->txnid,
859 (u_long)argp->prev_lsn.file,
860 (u_long)argp->prev_lsn.offset);
861 printf("\tfileid: %lu\n", (u_long)argp->fileid);
862 printf("\tpgno: %lu\n", (u_long)argp->pgno);
863 printf("\tndx: %lu\n", (u_long)argp->ndx);
864 printf("\tpagelsn: [%lu][%lu]\n",
865 (u_long)argp->pagelsn.file, (u_long)argp->pagelsn.offset);
866 printf("\toff: %ld\n", (long)argp->off);
867 printf("\tolditem: ");
868 for (i = 0; i < argp->olditem.size; i++) {
869 ch = ((u_int8_t *)argp->olditem.data)[i];
870 if (isprint(ch) || ch == 0xa)
871 putchar(ch);
872 else
873 printf("%#x ", ch);
875 printf("\n");
876 printf("\tnewitem: ");
877 for (i = 0; i < argp->newitem.size; i++) {
878 ch = ((u_int8_t *)argp->newitem.data)[i];
879 if (isprint(ch) || ch == 0xa)
880 putchar(ch);
881 else
882 printf("%#x ", ch);
884 printf("\n");
885 printf("\tmakedup: %lu\n", (u_long)argp->makedup);
886 printf("\n");
887 __db_free(argp);
888 return (0);
892 * PUBLIC: int __ham_replace_read __P((void *, __ham_replace_args **));
895 __ham_replace_read(recbuf, argpp)
896 void *recbuf;
897 __ham_replace_args **argpp;
899 __ham_replace_args *argp;
900 u_int8_t *bp;
902 argp = (__ham_replace_args *)__db_malloc(sizeof(__ham_replace_args) +
903 sizeof(DB_TXN));
904 if (argp == NULL)
905 return (ENOMEM);
906 argp->txnid = (DB_TXN *)&argp[1];
907 bp = recbuf;
908 memcpy(&argp->type, bp, sizeof(argp->type));
909 bp += sizeof(argp->type);
910 memcpy(&argp->txnid->txnid, bp, sizeof(argp->txnid->txnid));
911 bp += sizeof(argp->txnid->txnid);
912 memcpy(&argp->prev_lsn, bp, sizeof(DB_LSN));
913 bp += sizeof(DB_LSN);
914 memcpy(&argp->fileid, bp, sizeof(argp->fileid));
915 bp += sizeof(argp->fileid);
916 memcpy(&argp->pgno, bp, sizeof(argp->pgno));
917 bp += sizeof(argp->pgno);
918 memcpy(&argp->ndx, bp, sizeof(argp->ndx));
919 bp += sizeof(argp->ndx);
920 memcpy(&argp->pagelsn, bp, sizeof(argp->pagelsn));
921 bp += sizeof(argp->pagelsn);
922 memcpy(&argp->off, bp, sizeof(argp->off));
923 bp += sizeof(argp->off);
924 memcpy(&argp->olditem.size, bp, sizeof(u_int32_t));
925 bp += sizeof(u_int32_t);
926 argp->olditem.data = bp;
927 bp += argp->olditem.size;
928 memcpy(&argp->newitem.size, bp, sizeof(u_int32_t));
929 bp += sizeof(u_int32_t);
930 argp->newitem.data = bp;
931 bp += argp->newitem.size;
932 memcpy(&argp->makedup, bp, sizeof(argp->makedup));
933 bp += sizeof(argp->makedup);
934 *argpp = argp;
935 return (0);
939 * PUBLIC: int __ham_newpgno_log
940 * PUBLIC: __P((DB_LOG *, DB_TXN *, DB_LSN *, u_int32_t,
941 * PUBLIC: u_int32_t, u_int32_t, db_pgno_t, db_pgno_t,
942 * PUBLIC: u_int32_t, db_pgno_t, u_int32_t, DB_LSN *,
943 * PUBLIC: DB_LSN *));
945 int __ham_newpgno_log(logp, txnid, ret_lsnp, flags,
946 opcode, fileid, pgno, free_pgno, old_type, old_pgno,
947 new_type, pagelsn, metalsn)
948 DB_LOG *logp;
949 DB_TXN *txnid;
950 DB_LSN *ret_lsnp;
951 u_int32_t flags;
952 u_int32_t opcode;
953 u_int32_t fileid;
954 db_pgno_t pgno;
955 db_pgno_t free_pgno;
956 u_int32_t old_type;
957 db_pgno_t old_pgno;
958 u_int32_t new_type;
959 DB_LSN * pagelsn;
960 DB_LSN * metalsn;
962 DBT logrec;
963 DB_LSN *lsnp, null_lsn;
964 u_int32_t rectype, txn_num;
965 int ret;
966 u_int8_t *bp;
968 rectype = DB_ham_newpgno;
969 txn_num = txnid == NULL ? 0 : txnid->txnid;
970 if (txnid == NULL) {
971 null_lsn.file = 0;
972 null_lsn.offset = 0;
973 lsnp = &null_lsn;
974 } else
975 lsnp = &txnid->last_lsn;
976 logrec.size = sizeof(rectype) + sizeof(txn_num) + sizeof(DB_LSN)
977 + sizeof(opcode)
978 + sizeof(fileid)
979 + sizeof(pgno)
980 + sizeof(free_pgno)
981 + sizeof(old_type)
982 + sizeof(old_pgno)
983 + sizeof(new_type)
984 + sizeof(*pagelsn)
985 + sizeof(*metalsn);
986 if ((logrec.data = (void *)__db_malloc(logrec.size)) == NULL)
987 return (ENOMEM);
989 bp = logrec.data;
990 memcpy(bp, &rectype, sizeof(rectype));
991 bp += sizeof(rectype);
992 memcpy(bp, &txn_num, sizeof(txn_num));
993 bp += sizeof(txn_num);
994 memcpy(bp, lsnp, sizeof(DB_LSN));
995 bp += sizeof(DB_LSN);
996 memcpy(bp, &opcode, sizeof(opcode));
997 bp += sizeof(opcode);
998 memcpy(bp, &fileid, sizeof(fileid));
999 bp += sizeof(fileid);
1000 memcpy(bp, &pgno, sizeof(pgno));
1001 bp += sizeof(pgno);
1002 memcpy(bp, &free_pgno, sizeof(free_pgno));
1003 bp += sizeof(free_pgno);
1004 memcpy(bp, &old_type, sizeof(old_type));
1005 bp += sizeof(old_type);
1006 memcpy(bp, &old_pgno, sizeof(old_pgno));
1007 bp += sizeof(old_pgno);
1008 memcpy(bp, &new_type, sizeof(new_type));
1009 bp += sizeof(new_type);
1010 if (pagelsn != NULL)
1011 memcpy(bp, pagelsn, sizeof(*pagelsn));
1012 else
1013 memset(bp, 0, sizeof(*pagelsn));
1014 bp += sizeof(*pagelsn);
1015 if (metalsn != NULL)
1016 memcpy(bp, metalsn, sizeof(*metalsn));
1017 else
1018 memset(bp, 0, sizeof(*metalsn));
1019 bp += sizeof(*metalsn);
1020 #ifdef DIAGNOSTIC
1021 if ((u_int32_t)(bp - (u_int8_t *)logrec.data) != logrec.size)
1022 fprintf(stderr, "Error in log record length");
1023 #endif
1024 ret = log_put(logp, ret_lsnp, (DBT *)&logrec, flags);
1025 if (txnid != NULL)
1026 txnid->last_lsn = *ret_lsnp;
1027 __db_free(logrec.data);
1028 return (ret);
1032 * PUBLIC: int __ham_newpgno_print
1033 * PUBLIC: __P((DB_LOG *, DBT *, DB_LSN *, int, void *));
1036 __ham_newpgno_print(notused1, dbtp, lsnp, notused2, notused3)
1037 DB_LOG *notused1;
1038 DBT *dbtp;
1039 DB_LSN *lsnp;
1040 int notused2;
1041 void *notused3;
1043 __ham_newpgno_args *argp;
1044 u_int32_t i;
1045 u_int ch;
1046 int ret;
1048 i = 0;
1049 ch = 0;
1050 notused1 = NULL;
1051 notused2 = 0;
1052 notused3 = NULL;
1054 if ((ret = __ham_newpgno_read(dbtp->data, &argp)) != 0)
1055 return (ret);
1056 printf("[%lu][%lu]ham_newpgno: rec: %lu txnid %lx prevlsn [%lu][%lu]\n",
1057 (u_long)lsnp->file,
1058 (u_long)lsnp->offset,
1059 (u_long)argp->type,
1060 (u_long)argp->txnid->txnid,
1061 (u_long)argp->prev_lsn.file,
1062 (u_long)argp->prev_lsn.offset);
1063 printf("\topcode: %lu\n", (u_long)argp->opcode);
1064 printf("\tfileid: %lu\n", (u_long)argp->fileid);
1065 printf("\tpgno: %lu\n", (u_long)argp->pgno);
1066 printf("\tfree_pgno: %lu\n", (u_long)argp->free_pgno);
1067 printf("\told_type: %lu\n", (u_long)argp->old_type);
1068 printf("\told_pgno: %lu\n", (u_long)argp->old_pgno);
1069 printf("\tnew_type: %lu\n", (u_long)argp->new_type);
1070 printf("\tpagelsn: [%lu][%lu]\n",
1071 (u_long)argp->pagelsn.file, (u_long)argp->pagelsn.offset);
1072 printf("\tmetalsn: [%lu][%lu]\n",
1073 (u_long)argp->metalsn.file, (u_long)argp->metalsn.offset);
1074 printf("\n");
1075 __db_free(argp);
1076 return (0);
1080 * PUBLIC: int __ham_newpgno_read __P((void *, __ham_newpgno_args **));
1083 __ham_newpgno_read(recbuf, argpp)
1084 void *recbuf;
1085 __ham_newpgno_args **argpp;
1087 __ham_newpgno_args *argp;
1088 u_int8_t *bp;
1090 argp = (__ham_newpgno_args *)__db_malloc(sizeof(__ham_newpgno_args) +
1091 sizeof(DB_TXN));
1092 if (argp == NULL)
1093 return (ENOMEM);
1094 argp->txnid = (DB_TXN *)&argp[1];
1095 bp = recbuf;
1096 memcpy(&argp->type, bp, sizeof(argp->type));
1097 bp += sizeof(argp->type);
1098 memcpy(&argp->txnid->txnid, bp, sizeof(argp->txnid->txnid));
1099 bp += sizeof(argp->txnid->txnid);
1100 memcpy(&argp->prev_lsn, bp, sizeof(DB_LSN));
1101 bp += sizeof(DB_LSN);
1102 memcpy(&argp->opcode, bp, sizeof(argp->opcode));
1103 bp += sizeof(argp->opcode);
1104 memcpy(&argp->fileid, bp, sizeof(argp->fileid));
1105 bp += sizeof(argp->fileid);
1106 memcpy(&argp->pgno, bp, sizeof(argp->pgno));
1107 bp += sizeof(argp->pgno);
1108 memcpy(&argp->free_pgno, bp, sizeof(argp->free_pgno));
1109 bp += sizeof(argp->free_pgno);
1110 memcpy(&argp->old_type, bp, sizeof(argp->old_type));
1111 bp += sizeof(argp->old_type);
1112 memcpy(&argp->old_pgno, bp, sizeof(argp->old_pgno));
1113 bp += sizeof(argp->old_pgno);
1114 memcpy(&argp->new_type, bp, sizeof(argp->new_type));
1115 bp += sizeof(argp->new_type);
1116 memcpy(&argp->pagelsn, bp, sizeof(argp->pagelsn));
1117 bp += sizeof(argp->pagelsn);
1118 memcpy(&argp->metalsn, bp, sizeof(argp->metalsn));
1119 bp += sizeof(argp->metalsn);
1120 *argpp = argp;
1121 return (0);
1125 * PUBLIC: int __ham_ovfl_log
1126 * PUBLIC: __P((DB_LOG *, DB_TXN *, DB_LSN *, u_int32_t,
1127 * PUBLIC: u_int32_t, db_pgno_t, u_int32_t, db_pgno_t,
1128 * PUBLIC: u_int32_t, DB_LSN *));
1130 int __ham_ovfl_log(logp, txnid, ret_lsnp, flags,
1131 fileid, start_pgno, npages, free_pgno, ovflpoint, metalsn)
1132 DB_LOG *logp;
1133 DB_TXN *txnid;
1134 DB_LSN *ret_lsnp;
1135 u_int32_t flags;
1136 u_int32_t fileid;
1137 db_pgno_t start_pgno;
1138 u_int32_t npages;
1139 db_pgno_t free_pgno;
1140 u_int32_t ovflpoint;
1141 DB_LSN * metalsn;
1143 DBT logrec;
1144 DB_LSN *lsnp, null_lsn;
1145 u_int32_t rectype, txn_num;
1146 int ret;
1147 u_int8_t *bp;
1149 rectype = DB_ham_ovfl;
1150 txn_num = txnid == NULL ? 0 : txnid->txnid;
1151 if (txnid == NULL) {
1152 null_lsn.file = 0;
1153 null_lsn.offset = 0;
1154 lsnp = &null_lsn;
1155 } else
1156 lsnp = &txnid->last_lsn;
1157 logrec.size = sizeof(rectype) + sizeof(txn_num) + sizeof(DB_LSN)
1158 + sizeof(fileid)
1159 + sizeof(start_pgno)
1160 + sizeof(npages)
1161 + sizeof(free_pgno)
1162 + sizeof(ovflpoint)
1163 + sizeof(*metalsn);
1164 if ((logrec.data = (void *)__db_malloc(logrec.size)) == NULL)
1165 return (ENOMEM);
1167 bp = logrec.data;
1168 memcpy(bp, &rectype, sizeof(rectype));
1169 bp += sizeof(rectype);
1170 memcpy(bp, &txn_num, sizeof(txn_num));
1171 bp += sizeof(txn_num);
1172 memcpy(bp, lsnp, sizeof(DB_LSN));
1173 bp += sizeof(DB_LSN);
1174 memcpy(bp, &fileid, sizeof(fileid));
1175 bp += sizeof(fileid);
1176 memcpy(bp, &start_pgno, sizeof(start_pgno));
1177 bp += sizeof(start_pgno);
1178 memcpy(bp, &npages, sizeof(npages));
1179 bp += sizeof(npages);
1180 memcpy(bp, &free_pgno, sizeof(free_pgno));
1181 bp += sizeof(free_pgno);
1182 memcpy(bp, &ovflpoint, sizeof(ovflpoint));
1183 bp += sizeof(ovflpoint);
1184 if (metalsn != NULL)
1185 memcpy(bp, metalsn, sizeof(*metalsn));
1186 else
1187 memset(bp, 0, sizeof(*metalsn));
1188 bp += sizeof(*metalsn);
1189 #ifdef DIAGNOSTIC
1190 if ((u_int32_t)(bp - (u_int8_t *)logrec.data) != logrec.size)
1191 fprintf(stderr, "Error in log record length");
1192 #endif
1193 ret = log_put(logp, ret_lsnp, (DBT *)&logrec, flags);
1194 if (txnid != NULL)
1195 txnid->last_lsn = *ret_lsnp;
1196 __db_free(logrec.data);
1197 return (ret);
1201 * PUBLIC: int __ham_ovfl_print
1202 * PUBLIC: __P((DB_LOG *, DBT *, DB_LSN *, int, void *));
1205 __ham_ovfl_print(notused1, dbtp, lsnp, notused2, notused3)
1206 DB_LOG *notused1;
1207 DBT *dbtp;
1208 DB_LSN *lsnp;
1209 int notused2;
1210 void *notused3;
1212 __ham_ovfl_args *argp;
1213 u_int32_t i;
1214 u_int ch;
1215 int ret;
1217 i = 0;
1218 ch = 0;
1219 notused1 = NULL;
1220 notused2 = 0;
1221 notused3 = NULL;
1223 if ((ret = __ham_ovfl_read(dbtp->data, &argp)) != 0)
1224 return (ret);
1225 printf("[%lu][%lu]ham_ovfl: rec: %lu txnid %lx prevlsn [%lu][%lu]\n",
1226 (u_long)lsnp->file,
1227 (u_long)lsnp->offset,
1228 (u_long)argp->type,
1229 (u_long)argp->txnid->txnid,
1230 (u_long)argp->prev_lsn.file,
1231 (u_long)argp->prev_lsn.offset);
1232 printf("\tfileid: %lu\n", (u_long)argp->fileid);
1233 printf("\tstart_pgno: %lu\n", (u_long)argp->start_pgno);
1234 printf("\tnpages: %lu\n", (u_long)argp->npages);
1235 printf("\tfree_pgno: %lu\n", (u_long)argp->free_pgno);
1236 printf("\tovflpoint: %lu\n", (u_long)argp->ovflpoint);
1237 printf("\tmetalsn: [%lu][%lu]\n",
1238 (u_long)argp->metalsn.file, (u_long)argp->metalsn.offset);
1239 printf("\n");
1240 __db_free(argp);
1241 return (0);
1245 * PUBLIC: int __ham_ovfl_read __P((void *, __ham_ovfl_args **));
1248 __ham_ovfl_read(recbuf, argpp)
1249 void *recbuf;
1250 __ham_ovfl_args **argpp;
1252 __ham_ovfl_args *argp;
1253 u_int8_t *bp;
1255 argp = (__ham_ovfl_args *)__db_malloc(sizeof(__ham_ovfl_args) +
1256 sizeof(DB_TXN));
1257 if (argp == NULL)
1258 return (ENOMEM);
1259 argp->txnid = (DB_TXN *)&argp[1];
1260 bp = recbuf;
1261 memcpy(&argp->type, bp, sizeof(argp->type));
1262 bp += sizeof(argp->type);
1263 memcpy(&argp->txnid->txnid, bp, sizeof(argp->txnid->txnid));
1264 bp += sizeof(argp->txnid->txnid);
1265 memcpy(&argp->prev_lsn, bp, sizeof(DB_LSN));
1266 bp += sizeof(DB_LSN);
1267 memcpy(&argp->fileid, bp, sizeof(argp->fileid));
1268 bp += sizeof(argp->fileid);
1269 memcpy(&argp->start_pgno, bp, sizeof(argp->start_pgno));
1270 bp += sizeof(argp->start_pgno);
1271 memcpy(&argp->npages, bp, sizeof(argp->npages));
1272 bp += sizeof(argp->npages);
1273 memcpy(&argp->free_pgno, bp, sizeof(argp->free_pgno));
1274 bp += sizeof(argp->free_pgno);
1275 memcpy(&argp->ovflpoint, bp, sizeof(argp->ovflpoint));
1276 bp += sizeof(argp->ovflpoint);
1277 memcpy(&argp->metalsn, bp, sizeof(argp->metalsn));
1278 bp += sizeof(argp->metalsn);
1279 *argpp = argp;
1280 return (0);
1284 * PUBLIC: int __ham_copypage_log
1285 * PUBLIC: __P((DB_LOG *, DB_TXN *, DB_LSN *, u_int32_t,
1286 * PUBLIC: u_int32_t, db_pgno_t, DB_LSN *, db_pgno_t,
1287 * PUBLIC: DB_LSN *, db_pgno_t, DB_LSN *, const DBT *));
1289 int __ham_copypage_log(logp, txnid, ret_lsnp, flags,
1290 fileid, pgno, pagelsn, next_pgno, nextlsn, nnext_pgno,
1291 nnextlsn, page)
1292 DB_LOG *logp;
1293 DB_TXN *txnid;
1294 DB_LSN *ret_lsnp;
1295 u_int32_t flags;
1296 u_int32_t fileid;
1297 db_pgno_t pgno;
1298 DB_LSN * pagelsn;
1299 db_pgno_t next_pgno;
1300 DB_LSN * nextlsn;
1301 db_pgno_t nnext_pgno;
1302 DB_LSN * nnextlsn;
1303 const DBT *page;
1305 DBT logrec;
1306 DB_LSN *lsnp, null_lsn;
1307 u_int32_t zero;
1308 u_int32_t rectype, txn_num;
1309 int ret;
1310 u_int8_t *bp;
1312 rectype = DB_ham_copypage;
1313 txn_num = txnid == NULL ? 0 : txnid->txnid;
1314 if (txnid == NULL) {
1315 null_lsn.file = 0;
1316 null_lsn.offset = 0;
1317 lsnp = &null_lsn;
1318 } else
1319 lsnp = &txnid->last_lsn;
1320 logrec.size = sizeof(rectype) + sizeof(txn_num) + sizeof(DB_LSN)
1321 + sizeof(fileid)
1322 + sizeof(pgno)
1323 + sizeof(*pagelsn)
1324 + sizeof(next_pgno)
1325 + sizeof(*nextlsn)
1326 + sizeof(nnext_pgno)
1327 + sizeof(*nnextlsn)
1328 + sizeof(u_int32_t) + (page == NULL ? 0 : page->size);
1329 if ((logrec.data = (void *)__db_malloc(logrec.size)) == NULL)
1330 return (ENOMEM);
1332 bp = logrec.data;
1333 memcpy(bp, &rectype, sizeof(rectype));
1334 bp += sizeof(rectype);
1335 memcpy(bp, &txn_num, sizeof(txn_num));
1336 bp += sizeof(txn_num);
1337 memcpy(bp, lsnp, sizeof(DB_LSN));
1338 bp += sizeof(DB_LSN);
1339 memcpy(bp, &fileid, sizeof(fileid));
1340 bp += sizeof(fileid);
1341 memcpy(bp, &pgno, sizeof(pgno));
1342 bp += sizeof(pgno);
1343 if (pagelsn != NULL)
1344 memcpy(bp, pagelsn, sizeof(*pagelsn));
1345 else
1346 memset(bp, 0, sizeof(*pagelsn));
1347 bp += sizeof(*pagelsn);
1348 memcpy(bp, &next_pgno, sizeof(next_pgno));
1349 bp += sizeof(next_pgno);
1350 if (nextlsn != NULL)
1351 memcpy(bp, nextlsn, sizeof(*nextlsn));
1352 else
1353 memset(bp, 0, sizeof(*nextlsn));
1354 bp += sizeof(*nextlsn);
1355 memcpy(bp, &nnext_pgno, sizeof(nnext_pgno));
1356 bp += sizeof(nnext_pgno);
1357 if (nnextlsn != NULL)
1358 memcpy(bp, nnextlsn, sizeof(*nnextlsn));
1359 else
1360 memset(bp, 0, sizeof(*nnextlsn));
1361 bp += sizeof(*nnextlsn);
1362 if (page == NULL) {
1363 zero = 0;
1364 memcpy(bp, &zero, sizeof(u_int32_t));
1365 bp += sizeof(u_int32_t);
1366 } else {
1367 memcpy(bp, &page->size, sizeof(page->size));
1368 bp += sizeof(page->size);
1369 memcpy(bp, page->data, page->size);
1370 bp += page->size;
1372 #ifdef DIAGNOSTIC
1373 if ((u_int32_t)(bp - (u_int8_t *)logrec.data) != logrec.size)
1374 fprintf(stderr, "Error in log record length");
1375 #endif
1376 ret = log_put(logp, ret_lsnp, (DBT *)&logrec, flags);
1377 if (txnid != NULL)
1378 txnid->last_lsn = *ret_lsnp;
1379 __db_free(logrec.data);
1380 return (ret);
1384 * PUBLIC: int __ham_copypage_print
1385 * PUBLIC: __P((DB_LOG *, DBT *, DB_LSN *, int, void *));
1388 __ham_copypage_print(notused1, dbtp, lsnp, notused2, notused3)
1389 DB_LOG *notused1;
1390 DBT *dbtp;
1391 DB_LSN *lsnp;
1392 int notused2;
1393 void *notused3;
1395 __ham_copypage_args *argp;
1396 u_int32_t i;
1397 u_int ch;
1398 int ret;
1400 i = 0;
1401 ch = 0;
1402 notused1 = NULL;
1403 notused2 = 0;
1404 notused3 = NULL;
1406 if ((ret = __ham_copypage_read(dbtp->data, &argp)) != 0)
1407 return (ret);
1408 printf("[%lu][%lu]ham_copypage: rec: %lu txnid %lx prevlsn [%lu][%lu]\n",
1409 (u_long)lsnp->file,
1410 (u_long)lsnp->offset,
1411 (u_long)argp->type,
1412 (u_long)argp->txnid->txnid,
1413 (u_long)argp->prev_lsn.file,
1414 (u_long)argp->prev_lsn.offset);
1415 printf("\tfileid: %lu\n", (u_long)argp->fileid);
1416 printf("\tpgno: %lu\n", (u_long)argp->pgno);
1417 printf("\tpagelsn: [%lu][%lu]\n",
1418 (u_long)argp->pagelsn.file, (u_long)argp->pagelsn.offset);
1419 printf("\tnext_pgno: %lu\n", (u_long)argp->next_pgno);
1420 printf("\tnextlsn: [%lu][%lu]\n",
1421 (u_long)argp->nextlsn.file, (u_long)argp->nextlsn.offset);
1422 printf("\tnnext_pgno: %lu\n", (u_long)argp->nnext_pgno);
1423 printf("\tnnextlsn: [%lu][%lu]\n",
1424 (u_long)argp->nnextlsn.file, (u_long)argp->nnextlsn.offset);
1425 printf("\tpage: ");
1426 for (i = 0; i < argp->page.size; i++) {
1427 ch = ((u_int8_t *)argp->page.data)[i];
1428 if (isprint(ch) || ch == 0xa)
1429 putchar(ch);
1430 else
1431 printf("%#x ", ch);
1433 printf("\n");
1434 printf("\n");
1435 __db_free(argp);
1436 return (0);
1440 * PUBLIC: int __ham_copypage_read __P((void *, __ham_copypage_args **));
1443 __ham_copypage_read(recbuf, argpp)
1444 void *recbuf;
1445 __ham_copypage_args **argpp;
1447 __ham_copypage_args *argp;
1448 u_int8_t *bp;
1450 argp = (__ham_copypage_args *)__db_malloc(sizeof(__ham_copypage_args) +
1451 sizeof(DB_TXN));
1452 if (argp == NULL)
1453 return (ENOMEM);
1454 argp->txnid = (DB_TXN *)&argp[1];
1455 bp = recbuf;
1456 memcpy(&argp->type, bp, sizeof(argp->type));
1457 bp += sizeof(argp->type);
1458 memcpy(&argp->txnid->txnid, bp, sizeof(argp->txnid->txnid));
1459 bp += sizeof(argp->txnid->txnid);
1460 memcpy(&argp->prev_lsn, bp, sizeof(DB_LSN));
1461 bp += sizeof(DB_LSN);
1462 memcpy(&argp->fileid, bp, sizeof(argp->fileid));
1463 bp += sizeof(argp->fileid);
1464 memcpy(&argp->pgno, bp, sizeof(argp->pgno));
1465 bp += sizeof(argp->pgno);
1466 memcpy(&argp->pagelsn, bp, sizeof(argp->pagelsn));
1467 bp += sizeof(argp->pagelsn);
1468 memcpy(&argp->next_pgno, bp, sizeof(argp->next_pgno));
1469 bp += sizeof(argp->next_pgno);
1470 memcpy(&argp->nextlsn, bp, sizeof(argp->nextlsn));
1471 bp += sizeof(argp->nextlsn);
1472 memcpy(&argp->nnext_pgno, bp, sizeof(argp->nnext_pgno));
1473 bp += sizeof(argp->nnext_pgno);
1474 memcpy(&argp->nnextlsn, bp, sizeof(argp->nnextlsn));
1475 bp += sizeof(argp->nnextlsn);
1476 memcpy(&argp->page.size, bp, sizeof(u_int32_t));
1477 bp += sizeof(u_int32_t);
1478 argp->page.data = bp;
1479 bp += argp->page.size;
1480 *argpp = argp;
1481 return (0);
1485 * PUBLIC: int __ham_init_print __P((DB_ENV *));
1488 __ham_init_print(dbenv)
1489 DB_ENV *dbenv;
1491 int ret;
1493 if ((ret = __db_add_recovery(dbenv,
1494 __ham_insdel_print, DB_ham_insdel)) != 0)
1495 return (ret);
1496 if ((ret = __db_add_recovery(dbenv,
1497 __ham_newpage_print, DB_ham_newpage)) != 0)
1498 return (ret);
1499 if ((ret = __db_add_recovery(dbenv,
1500 __ham_splitmeta_print, DB_ham_splitmeta)) != 0)
1501 return (ret);
1502 if ((ret = __db_add_recovery(dbenv,
1503 __ham_splitdata_print, DB_ham_splitdata)) != 0)
1504 return (ret);
1505 if ((ret = __db_add_recovery(dbenv,
1506 __ham_replace_print, DB_ham_replace)) != 0)
1507 return (ret);
1508 if ((ret = __db_add_recovery(dbenv,
1509 __ham_newpgno_print, DB_ham_newpgno)) != 0)
1510 return (ret);
1511 if ((ret = __db_add_recovery(dbenv,
1512 __ham_ovfl_print, DB_ham_ovfl)) != 0)
1513 return (ret);
1514 if ((ret = __db_add_recovery(dbenv,
1515 __ham_copypage_print, DB_ham_copypage)) != 0)
1516 return (ret);
1517 return (0);
1521 * PUBLIC: int __ham_init_recover __P((DB_ENV *));
1524 __ham_init_recover(dbenv)
1525 DB_ENV *dbenv;
1527 int ret;
1529 if ((ret = __db_add_recovery(dbenv,
1530 __ham_insdel_recover, DB_ham_insdel)) != 0)
1531 return (ret);
1532 if ((ret = __db_add_recovery(dbenv,
1533 __ham_newpage_recover, DB_ham_newpage)) != 0)
1534 return (ret);
1535 if ((ret = __db_add_recovery(dbenv,
1536 __ham_splitmeta_recover, DB_ham_splitmeta)) != 0)
1537 return (ret);
1538 if ((ret = __db_add_recovery(dbenv,
1539 __ham_splitdata_recover, DB_ham_splitdata)) != 0)
1540 return (ret);
1541 if ((ret = __db_add_recovery(dbenv,
1542 __ham_replace_recover, DB_ham_replace)) != 0)
1543 return (ret);
1544 if ((ret = __db_add_recovery(dbenv,
1545 __ham_newpgno_recover, DB_ham_newpgno)) != 0)
1546 return (ret);
1547 if ((ret = __db_add_recovery(dbenv,
1548 __ham_ovfl_recover, DB_ham_ovfl)) != 0)
1549 return (ret);
1550 if ((ret = __db_add_recovery(dbenv,
1551 __ham_copypage_recover, DB_ham_copypage)) != 0)
1552 return (ret);
1553 return (0);