Main Page | Class Hierarchy | Data Structures | Directories | File List | Data Fields | Related Pages

btree_auto.c

00001 /* Do not edit: automatically built by gen_rec.awk. */
00002 
00003 #include "db_config.h"
00004 
00005 #ifndef NO_SYSTEM_INCLUDES
00006 #include <sys/types.h>
00007 
00008 #include <ctype.h>
00009 #include <string.h>
00010 #endif
00011 
00012 #include "db_int.h"
00013 #include "dbinc/crypto.h"
00014 #include "dbinc/db_page.h"
00015 #include "dbinc/db_dispatch.h"
00016 #include "dbinc/db_am.h"
00017 #include "dbinc/btree.h"
00018 #include "dbinc/log.h"
00019 #include "dbinc/txn.h"
00020 
00021 /*
00022  * PUBLIC: int __bam_split_log __P((DB *, DB_TXN *, DB_LSN *,
00023  * PUBLIC:     u_int32_t, db_pgno_t, DB_LSN *, db_pgno_t, DB_LSN *, u_int32_t,
00024  * PUBLIC:     db_pgno_t, DB_LSN *, db_pgno_t, const DBT *, u_int32_t));
00025  */
00026 int
00027 __bam_split_log(dbp, txnid, ret_lsnp, flags, left, llsn, right, rlsn, indx,
00028     npgno, nlsn, root_pgno, pg, opflags)
00029         DB *dbp;
00030         DB_TXN *txnid;
00031         DB_LSN *ret_lsnp;
00032         u_int32_t flags;
00033         db_pgno_t left;
00034         DB_LSN * llsn;
00035         db_pgno_t right;
00036         DB_LSN * rlsn;
00037         u_int32_t indx;
00038         db_pgno_t npgno;
00039         DB_LSN * nlsn;
00040         db_pgno_t root_pgno;
00041         const DBT *pg;
00042         u_int32_t opflags;
00043 {
00044         DBT logrec;
00045         DB_ENV *dbenv;
00046         DB_TXNLOGREC *lr;
00047         DB_LSN *lsnp, null_lsn, *rlsnp;
00048         u_int32_t zero, uinttmp, rectype, txn_num;
00049         u_int npad;
00050         u_int8_t *bp;
00051         int is_durable, ret;
00052 
00053         dbenv = dbp->dbenv;
00054         COMPQUIET(lr, NULL);
00055 
00056         rectype = DB___bam_split;
00057         npad = 0;
00058         rlsnp = ret_lsnp;
00059 
00060         ret = 0;
00061 
00062         if (LF_ISSET(DB_LOG_NOT_DURABLE) ||
00063             F_ISSET(dbp, DB_AM_NOT_DURABLE)) {
00064                 is_durable = 0;
00065         } else
00066                 is_durable = 1;
00067 
00068         if (txnid == NULL) {
00069                 txn_num = 0;
00070                 lsnp = &null_lsn;
00071                 null_lsn.file = null_lsn.offset = 0;
00072         } else {
00073                 if (TAILQ_FIRST(&txnid->kids) != NULL &&
00074                     (ret = __txn_activekids(dbenv, rectype, txnid)) != 0)
00075                         return (ret);
00076                 /*
00077                  * We need to assign begin_lsn while holding region mutex.
00078                  * That assignment is done inside the DbEnv->log_put call,
00079                  * so pass in the appropriate memory location to be filled
00080                  * in by the log_put code.
00081                  */
00082                 DB_SET_TXN_LSNP(txnid, &rlsnp, &lsnp);
00083                 txn_num = txnid->txnid;
00084         }
00085 
00086         DB_ASSERT(dbp->log_filename != NULL);
00087         if (dbp->log_filename->id == DB_LOGFILEID_INVALID &&
00088             (ret = __dbreg_lazy_id(dbp)) != 0)
00089                 return (ret);
00090 
00091         logrec.size = sizeof(rectype) + sizeof(txn_num) + sizeof(DB_LSN)
00092             + sizeof(u_int32_t)
00093             + sizeof(u_int32_t)
00094             + sizeof(*llsn)
00095             + sizeof(u_int32_t)
00096             + sizeof(*rlsn)
00097             + sizeof(u_int32_t)
00098             + sizeof(u_int32_t)
00099             + sizeof(*nlsn)
00100             + sizeof(u_int32_t)
00101             + sizeof(u_int32_t) + (pg == NULL ? 0 : pg->size)
00102             + sizeof(u_int32_t);
00103         if (CRYPTO_ON(dbenv)) {
00104                 npad =
00105                     ((DB_CIPHER *)dbenv->crypto_handle)->adj_size(logrec.size);
00106                 logrec.size += npad;
00107         }
00108 
00109         if (is_durable || txnid == NULL) {
00110                 if ((ret =
00111                     __os_malloc(dbenv, logrec.size, &logrec.data)) != 0)
00112                         return (ret);
00113         } else {
00114                 if ((ret = __os_malloc(dbenv,
00115                     logrec.size + sizeof(DB_TXNLOGREC), &lr)) != 0)
00116                         return (ret);
00117 #ifdef DIAGNOSTIC
00118                 if ((ret =
00119                     __os_malloc(dbenv, logrec.size, &logrec.data)) != 0) {
00120                         __os_free(dbenv, lr);
00121                         return (ret);
00122                 }
00123 #else
00124                 logrec.data = lr->data;
00125 #endif
00126         }
00127         if (npad > 0)
00128                 memset((u_int8_t *)logrec.data + logrec.size - npad, 0, npad);
00129 
00130         bp = logrec.data;
00131 
00132         memcpy(bp, &rectype, sizeof(rectype));
00133         bp += sizeof(rectype);
00134 
00135         memcpy(bp, &txn_num, sizeof(txn_num));
00136         bp += sizeof(txn_num);
00137 
00138         memcpy(bp, lsnp, sizeof(DB_LSN));
00139         bp += sizeof(DB_LSN);
00140 
00141         uinttmp = (u_int32_t)dbp->log_filename->id;
00142         memcpy(bp, &uinttmp, sizeof(uinttmp));
00143         bp += sizeof(uinttmp);
00144 
00145         uinttmp = (u_int32_t)left;
00146         memcpy(bp, &uinttmp, sizeof(uinttmp));
00147         bp += sizeof(uinttmp);
00148 
00149         if (llsn != NULL)
00150                 memcpy(bp, llsn, sizeof(*llsn));
00151         else
00152                 memset(bp, 0, sizeof(*llsn));
00153         bp += sizeof(*llsn);
00154 
00155         uinttmp = (u_int32_t)right;
00156         memcpy(bp, &uinttmp, sizeof(uinttmp));
00157         bp += sizeof(uinttmp);
00158 
00159         if (rlsn != NULL)
00160                 memcpy(bp, rlsn, sizeof(*rlsn));
00161         else
00162                 memset(bp, 0, sizeof(*rlsn));
00163         bp += sizeof(*rlsn);
00164 
00165         uinttmp = (u_int32_t)indx;
00166         memcpy(bp, &uinttmp, sizeof(uinttmp));
00167         bp += sizeof(uinttmp);
00168 
00169         uinttmp = (u_int32_t)npgno;
00170         memcpy(bp, &uinttmp, sizeof(uinttmp));
00171         bp += sizeof(uinttmp);
00172 
00173         if (nlsn != NULL)
00174                 memcpy(bp, nlsn, sizeof(*nlsn));
00175         else
00176                 memset(bp, 0, sizeof(*nlsn));
00177         bp += sizeof(*nlsn);
00178 
00179         uinttmp = (u_int32_t)root_pgno;
00180         memcpy(bp, &uinttmp, sizeof(uinttmp));
00181         bp += sizeof(uinttmp);
00182 
00183         if (pg == NULL) {
00184                 zero = 0;
00185                 memcpy(bp, &zero, sizeof(u_int32_t));
00186                 bp += sizeof(u_int32_t);
00187         } else {
00188                 memcpy(bp, &pg->size, sizeof(pg->size));
00189                 bp += sizeof(pg->size);
00190                 memcpy(bp, pg->data, pg->size);
00191                 bp += pg->size;
00192         }
00193 
00194         uinttmp = (u_int32_t)opflags;
00195         memcpy(bp, &uinttmp, sizeof(uinttmp));
00196         bp += sizeof(uinttmp);
00197 
00198         DB_ASSERT((u_int32_t)(bp - (u_int8_t *)logrec.data) <= logrec.size);
00199 
00200         if (is_durable || txnid == NULL) {
00201                 if ((ret = __log_put(dbenv, rlsnp,(DBT *)&logrec,
00202                     flags | DB_LOG_NOCOPY)) == 0 && txnid != NULL) {
00203                         *lsnp = *rlsnp;
00204                         if (rlsnp != ret_lsnp)
00205                                  *ret_lsnp = *rlsnp;
00206                 }
00207         } else {
00208 #ifdef DIAGNOSTIC
00209                 /*
00210                  * Set the debug bit if we are going to log non-durable
00211                  * transactions so they will be ignored by recovery.
00212                  */
00213                 memcpy(lr->data, logrec.data, logrec.size);
00214                 rectype |= DB_debug_FLAG;
00215                 memcpy(logrec.data, &rectype, sizeof(rectype));
00216 
00217                 ret = __log_put(dbenv,
00218                     rlsnp, (DBT *)&logrec, flags | DB_LOG_NOCOPY);
00219 #else
00220                 ret = 0;
00221 #endif
00222                 STAILQ_INSERT_HEAD(&txnid->logs, lr, links);
00223                 F_SET((TXN_DETAIL *)txnid->td, TXN_DTL_INMEMORY);
00224                 LSN_NOT_LOGGED(*ret_lsnp);
00225         }
00226 
00227 #ifdef LOG_DIAGNOSTIC
00228         if (ret != 0)
00229                 (void)__bam_split_print(dbenv,
00230                     (DBT *)&logrec, ret_lsnp, DB_TXN_PRINT, NULL);
00231 #endif
00232 
00233 #ifdef DIAGNOSTIC
00234         __os_free(dbenv, logrec.data);
00235 #else
00236         if (is_durable || txnid == NULL)
00237                 __os_free(dbenv, logrec.data);
00238 #endif
00239         return (ret);
00240 }
00241 
00242 /*
00243  * PUBLIC: int __bam_split_read __P((DB_ENV *, void *, __bam_split_args **));
00244  */
00245 int
00246 __bam_split_read(dbenv, recbuf, argpp)
00247         DB_ENV *dbenv;
00248         void *recbuf;
00249         __bam_split_args **argpp;
00250 {
00251         __bam_split_args *argp;
00252         u_int32_t uinttmp;
00253         u_int8_t *bp;
00254         int ret;
00255 
00256         if ((ret = __os_malloc(dbenv,
00257             sizeof(__bam_split_args) + sizeof(DB_TXN), &argp)) != 0)
00258                 return (ret);
00259         bp = recbuf;
00260         argp->txnid = (DB_TXN *)&argp[1];
00261 
00262         memcpy(&argp->type, bp, sizeof(argp->type));
00263         bp += sizeof(argp->type);
00264 
00265         memcpy(&argp->txnid->txnid,  bp, sizeof(argp->txnid->txnid));
00266         bp += sizeof(argp->txnid->txnid);
00267 
00268         memcpy(&argp->prev_lsn, bp, sizeof(DB_LSN));
00269         bp += sizeof(DB_LSN);
00270 
00271         memcpy(&uinttmp, bp, sizeof(uinttmp));
00272         argp->fileid = (int32_t)uinttmp;
00273         bp += sizeof(uinttmp);
00274 
00275         memcpy(&uinttmp, bp, sizeof(uinttmp));
00276         argp->left = (db_pgno_t)uinttmp;
00277         bp += sizeof(uinttmp);
00278 
00279         memcpy(&argp->llsn, bp,  sizeof(argp->llsn));
00280         bp += sizeof(argp->llsn);
00281 
00282         memcpy(&uinttmp, bp, sizeof(uinttmp));
00283         argp->right = (db_pgno_t)uinttmp;
00284         bp += sizeof(uinttmp);
00285 
00286         memcpy(&argp->rlsn, bp,  sizeof(argp->rlsn));
00287         bp += sizeof(argp->rlsn);
00288 
00289         memcpy(&uinttmp, bp, sizeof(uinttmp));
00290         argp->indx = (u_int32_t)uinttmp;
00291         bp += sizeof(uinttmp);
00292 
00293         memcpy(&uinttmp, bp, sizeof(uinttmp));
00294         argp->npgno = (db_pgno_t)uinttmp;
00295         bp += sizeof(uinttmp);
00296 
00297         memcpy(&argp->nlsn, bp,  sizeof(argp->nlsn));
00298         bp += sizeof(argp->nlsn);
00299 
00300         memcpy(&uinttmp, bp, sizeof(uinttmp));
00301         argp->root_pgno = (db_pgno_t)uinttmp;
00302         bp += sizeof(uinttmp);
00303 
00304         memset(&argp->pg, 0, sizeof(argp->pg));
00305         memcpy(&argp->pg.size, bp, sizeof(u_int32_t));
00306         bp += sizeof(u_int32_t);
00307         argp->pg.data = bp;
00308         bp += argp->pg.size;
00309 
00310         memcpy(&uinttmp, bp, sizeof(uinttmp));
00311         argp->opflags = (u_int32_t)uinttmp;
00312         bp += sizeof(uinttmp);
00313 
00314         *argpp = argp;
00315         return (0);
00316 }
00317 
00318 /*
00319  * PUBLIC: int __bam_rsplit_log __P((DB *, DB_TXN *, DB_LSN *,
00320  * PUBLIC:     u_int32_t, db_pgno_t, const DBT *, db_pgno_t, db_pgno_t,
00321  * PUBLIC:     const DBT *, DB_LSN *));
00322  */
00323 int
00324 __bam_rsplit_log(dbp, txnid, ret_lsnp, flags, pgno, pgdbt, root_pgno, nrec, rootent,
00325     rootlsn)
00326         DB *dbp;
00327         DB_TXN *txnid;
00328         DB_LSN *ret_lsnp;
00329         u_int32_t flags;
00330         db_pgno_t pgno;
00331         const DBT *pgdbt;
00332         db_pgno_t root_pgno;
00333         db_pgno_t nrec;
00334         const DBT *rootent;
00335         DB_LSN * rootlsn;
00336 {
00337         DBT logrec;
00338         DB_ENV *dbenv;
00339         DB_TXNLOGREC *lr;
00340         DB_LSN *lsnp, null_lsn, *rlsnp;
00341         u_int32_t zero, uinttmp, rectype, txn_num;
00342         u_int npad;
00343         u_int8_t *bp;
00344         int is_durable, ret;
00345 
00346         dbenv = dbp->dbenv;
00347         COMPQUIET(lr, NULL);
00348 
00349         rectype = DB___bam_rsplit;
00350         npad = 0;
00351         rlsnp = ret_lsnp;
00352 
00353         ret = 0;
00354 
00355         if (LF_ISSET(DB_LOG_NOT_DURABLE) ||
00356             F_ISSET(dbp, DB_AM_NOT_DURABLE)) {
00357                 is_durable = 0;
00358         } else
00359                 is_durable = 1;
00360 
00361         if (txnid == NULL) {
00362                 txn_num = 0;
00363                 lsnp = &null_lsn;
00364                 null_lsn.file = null_lsn.offset = 0;
00365         } else {
00366                 if (TAILQ_FIRST(&txnid->kids) != NULL &&
00367                     (ret = __txn_activekids(dbenv, rectype, txnid)) != 0)
00368                         return (ret);
00369                 /*
00370                  * We need to assign begin_lsn while holding region mutex.
00371                  * That assignment is done inside the DbEnv->log_put call,
00372                  * so pass in the appropriate memory location to be filled
00373                  * in by the log_put code.
00374                  */
00375                 DB_SET_TXN_LSNP(txnid, &rlsnp, &lsnp);
00376                 txn_num = txnid->txnid;
00377         }
00378 
00379         DB_ASSERT(dbp->log_filename != NULL);
00380         if (dbp->log_filename->id == DB_LOGFILEID_INVALID &&
00381             (ret = __dbreg_lazy_id(dbp)) != 0)
00382                 return (ret);
00383 
00384         logrec.size = sizeof(rectype) + sizeof(txn_num) + sizeof(DB_LSN)
00385             + sizeof(u_int32_t)
00386             + sizeof(u_int32_t)
00387             + sizeof(u_int32_t) + (pgdbt == NULL ? 0 : pgdbt->size)
00388             + sizeof(u_int32_t)
00389             + sizeof(u_int32_t)
00390             + sizeof(u_int32_t) + (rootent == NULL ? 0 : rootent->size)
00391             + sizeof(*rootlsn);
00392         if (CRYPTO_ON(dbenv)) {
00393                 npad =
00394                     ((DB_CIPHER *)dbenv->crypto_handle)->adj_size(logrec.size);
00395                 logrec.size += npad;
00396         }
00397 
00398         if (is_durable || txnid == NULL) {
00399                 if ((ret =
00400                     __os_malloc(dbenv, logrec.size, &logrec.data)) != 0)
00401                         return (ret);
00402         } else {
00403                 if ((ret = __os_malloc(dbenv,
00404                     logrec.size + sizeof(DB_TXNLOGREC), &lr)) != 0)
00405                         return (ret);
00406 #ifdef DIAGNOSTIC
00407                 if ((ret =
00408                     __os_malloc(dbenv, logrec.size, &logrec.data)) != 0) {
00409                         __os_free(dbenv, lr);
00410                         return (ret);
00411                 }
00412 #else
00413                 logrec.data = lr->data;
00414 #endif
00415         }
00416         if (npad > 0)
00417                 memset((u_int8_t *)logrec.data + logrec.size - npad, 0, npad);
00418 
00419         bp = logrec.data;
00420 
00421         memcpy(bp, &rectype, sizeof(rectype));
00422         bp += sizeof(rectype);
00423 
00424         memcpy(bp, &txn_num, sizeof(txn_num));
00425         bp += sizeof(txn_num);
00426 
00427         memcpy(bp, lsnp, sizeof(DB_LSN));
00428         bp += sizeof(DB_LSN);
00429 
00430         uinttmp = (u_int32_t)dbp->log_filename->id;
00431         memcpy(bp, &uinttmp, sizeof(uinttmp));
00432         bp += sizeof(uinttmp);
00433 
00434         uinttmp = (u_int32_t)pgno;
00435         memcpy(bp, &uinttmp, sizeof(uinttmp));
00436         bp += sizeof(uinttmp);
00437 
00438         if (pgdbt == NULL) {
00439                 zero = 0;
00440                 memcpy(bp, &zero, sizeof(u_int32_t));
00441                 bp += sizeof(u_int32_t);
00442         } else {
00443                 memcpy(bp, &pgdbt->size, sizeof(pgdbt->size));
00444                 bp += sizeof(pgdbt->size);
00445                 memcpy(bp, pgdbt->data, pgdbt->size);
00446                 bp += pgdbt->size;
00447         }
00448 
00449         uinttmp = (u_int32_t)root_pgno;
00450         memcpy(bp, &uinttmp, sizeof(uinttmp));
00451         bp += sizeof(uinttmp);
00452 
00453         uinttmp = (u_int32_t)nrec;
00454         memcpy(bp, &uinttmp, sizeof(uinttmp));
00455         bp += sizeof(uinttmp);
00456 
00457         if (rootent == NULL) {
00458                 zero = 0;
00459                 memcpy(bp, &zero, sizeof(u_int32_t));
00460                 bp += sizeof(u_int32_t);
00461         } else {
00462                 memcpy(bp, &rootent->size, sizeof(rootent->size));
00463                 bp += sizeof(rootent->size);
00464                 memcpy(bp, rootent->data, rootent->size);
00465                 bp += rootent->size;
00466         }
00467 
00468         if (rootlsn != NULL)
00469                 memcpy(bp, rootlsn, sizeof(*rootlsn));
00470         else
00471                 memset(bp, 0, sizeof(*rootlsn));
00472         bp += sizeof(*rootlsn);
00473 
00474         DB_ASSERT((u_int32_t)(bp - (u_int8_t *)logrec.data) <= logrec.size);
00475 
00476         if (is_durable || txnid == NULL) {
00477                 if ((ret = __log_put(dbenv, rlsnp,(DBT *)&logrec,
00478                     flags | DB_LOG_NOCOPY)) == 0 && txnid != NULL) {
00479                         *lsnp = *rlsnp;
00480                         if (rlsnp != ret_lsnp)
00481                                  *ret_lsnp = *rlsnp;
00482                 }
00483         } else {
00484 #ifdef DIAGNOSTIC
00485                 /*
00486                  * Set the debug bit if we are going to log non-durable
00487                  * transactions so they will be ignored by recovery.
00488                  */
00489                 memcpy(lr->data, logrec.data, logrec.size);
00490                 rectype |= DB_debug_FLAG;
00491                 memcpy(logrec.data, &rectype, sizeof(rectype));
00492 
00493                 ret = __log_put(dbenv,
00494                     rlsnp, (DBT *)&logrec, flags | DB_LOG_NOCOPY);
00495 #else
00496                 ret = 0;
00497 #endif
00498                 STAILQ_INSERT_HEAD(&txnid->logs, lr, links);
00499                 F_SET((TXN_DETAIL *)txnid->td, TXN_DTL_INMEMORY);
00500                 LSN_NOT_LOGGED(*ret_lsnp);
00501         }
00502 
00503 #ifdef LOG_DIAGNOSTIC
00504         if (ret != 0)
00505                 (void)__bam_rsplit_print(dbenv,
00506                     (DBT *)&logrec, ret_lsnp, DB_TXN_PRINT, NULL);
00507 #endif
00508 
00509 #ifdef DIAGNOSTIC
00510         __os_free(dbenv, logrec.data);
00511 #else
00512         if (is_durable || txnid == NULL)
00513                 __os_free(dbenv, logrec.data);
00514 #endif
00515         return (ret);
00516 }
00517 
00518 /*
00519  * PUBLIC: int __bam_rsplit_read __P((DB_ENV *, void *, __bam_rsplit_args **));
00520  */
00521 int
00522 __bam_rsplit_read(dbenv, recbuf, argpp)
00523         DB_ENV *dbenv;
00524         void *recbuf;
00525         __bam_rsplit_args **argpp;
00526 {
00527         __bam_rsplit_args *argp;
00528         u_int32_t uinttmp;
00529         u_int8_t *bp;
00530         int ret;
00531 
00532         if ((ret = __os_malloc(dbenv,
00533             sizeof(__bam_rsplit_args) + sizeof(DB_TXN), &argp)) != 0)
00534                 return (ret);
00535         bp = recbuf;
00536         argp->txnid = (DB_TXN *)&argp[1];
00537 
00538         memcpy(&argp->type, bp, sizeof(argp->type));
00539         bp += sizeof(argp->type);
00540 
00541         memcpy(&argp->txnid->txnid,  bp, sizeof(argp->txnid->txnid));
00542         bp += sizeof(argp->txnid->txnid);
00543 
00544         memcpy(&argp->prev_lsn, bp, sizeof(DB_LSN));
00545         bp += sizeof(DB_LSN);
00546 
00547         memcpy(&uinttmp, bp, sizeof(uinttmp));
00548         argp->fileid = (int32_t)uinttmp;
00549         bp += sizeof(uinttmp);
00550 
00551         memcpy(&uinttmp, bp, sizeof(uinttmp));
00552         argp->pgno = (db_pgno_t)uinttmp;
00553         bp += sizeof(uinttmp);
00554 
00555         memset(&argp->pgdbt, 0, sizeof(argp->pgdbt));
00556         memcpy(&argp->pgdbt.size, bp, sizeof(u_int32_t));
00557         bp += sizeof(u_int32_t);
00558         argp->pgdbt.data = bp;
00559         bp += argp->pgdbt.size;
00560 
00561         memcpy(&uinttmp, bp, sizeof(uinttmp));
00562         argp->root_pgno = (db_pgno_t)uinttmp;
00563         bp += sizeof(uinttmp);
00564 
00565         memcpy(&uinttmp, bp, sizeof(uinttmp));
00566         argp->nrec = (db_pgno_t)uinttmp;
00567         bp += sizeof(uinttmp);
00568 
00569         memset(&argp->rootent, 0, sizeof(argp->rootent));
00570         memcpy(&argp->rootent.size, bp, sizeof(u_int32_t));
00571         bp += sizeof(u_int32_t);
00572         argp->rootent.data = bp;
00573         bp += argp->rootent.size;
00574 
00575         memcpy(&argp->rootlsn, bp,  sizeof(argp->rootlsn));
00576         bp += sizeof(argp->rootlsn);
00577 
00578         *argpp = argp;
00579         return (0);
00580 }
00581 
00582 /*
00583  * PUBLIC: int __bam_adj_log __P((DB *, DB_TXN *, DB_LSN *,
00584  * PUBLIC:     u_int32_t, db_pgno_t, DB_LSN *, u_int32_t, u_int32_t,
00585  * PUBLIC:     u_int32_t));
00586  */
00587 int
00588 __bam_adj_log(dbp, txnid, ret_lsnp, flags, pgno, lsn, indx, indx_copy, is_insert)
00589         DB *dbp;
00590         DB_TXN *txnid;
00591         DB_LSN *ret_lsnp;
00592         u_int32_t flags;
00593         db_pgno_t pgno;
00594         DB_LSN * lsn;
00595         u_int32_t indx;
00596         u_int32_t indx_copy;
00597         u_int32_t is_insert;
00598 {
00599         DBT logrec;
00600         DB_ENV *dbenv;
00601         DB_TXNLOGREC *lr;
00602         DB_LSN *lsnp, null_lsn, *rlsnp;
00603         u_int32_t uinttmp, rectype, txn_num;
00604         u_int npad;
00605         u_int8_t *bp;
00606         int is_durable, ret;
00607 
00608         dbenv = dbp->dbenv;
00609         COMPQUIET(lr, NULL);
00610 
00611         rectype = DB___bam_adj;
00612         npad = 0;
00613         rlsnp = ret_lsnp;
00614 
00615         ret = 0;
00616 
00617         if (LF_ISSET(DB_LOG_NOT_DURABLE) ||
00618             F_ISSET(dbp, DB_AM_NOT_DURABLE)) {
00619                 is_durable = 0;
00620         } else
00621                 is_durable = 1;
00622 
00623         if (txnid == NULL) {
00624                 txn_num = 0;
00625                 lsnp = &null_lsn;
00626                 null_lsn.file = null_lsn.offset = 0;
00627         } else {
00628                 if (TAILQ_FIRST(&txnid->kids) != NULL &&
00629                     (ret = __txn_activekids(dbenv, rectype, txnid)) != 0)
00630                         return (ret);
00631                 /*
00632                  * We need to assign begin_lsn while holding region mutex.
00633                  * That assignment is done inside the DbEnv->log_put call,
00634                  * so pass in the appropriate memory location to be filled
00635                  * in by the log_put code.
00636                  */
00637                 DB_SET_TXN_LSNP(txnid, &rlsnp, &lsnp);
00638                 txn_num = txnid->txnid;
00639         }
00640 
00641         DB_ASSERT(dbp->log_filename != NULL);
00642         if (dbp->log_filename->id == DB_LOGFILEID_INVALID &&
00643             (ret = __dbreg_lazy_id(dbp)) != 0)
00644                 return (ret);
00645 
00646         logrec.size = sizeof(rectype) + sizeof(txn_num) + sizeof(DB_LSN)
00647             + sizeof(u_int32_t)
00648             + sizeof(u_int32_t)
00649             + sizeof(*lsn)
00650             + sizeof(u_int32_t)
00651             + sizeof(u_int32_t)
00652             + sizeof(u_int32_t);
00653         if (CRYPTO_ON(dbenv)) {
00654                 npad =
00655                     ((DB_CIPHER *)dbenv->crypto_handle)->adj_size(logrec.size);
00656                 logrec.size += npad;
00657         }
00658 
00659         if (is_durable || txnid == NULL) {
00660                 if ((ret =
00661                     __os_malloc(dbenv, logrec.size, &logrec.data)) != 0)
00662                         return (ret);
00663         } else {
00664                 if ((ret = __os_malloc(dbenv,
00665                     logrec.size + sizeof(DB_TXNLOGREC), &lr)) != 0)
00666                         return (ret);
00667 #ifdef DIAGNOSTIC
00668                 if ((ret =
00669                     __os_malloc(dbenv, logrec.size, &logrec.data)) != 0) {
00670                         __os_free(dbenv, lr);
00671                         return (ret);
00672                 }
00673 #else
00674                 logrec.data = lr->data;
00675 #endif
00676         }
00677         if (npad > 0)
00678                 memset((u_int8_t *)logrec.data + logrec.size - npad, 0, npad);
00679 
00680         bp = logrec.data;
00681 
00682         memcpy(bp, &rectype, sizeof(rectype));
00683         bp += sizeof(rectype);
00684 
00685         memcpy(bp, &txn_num, sizeof(txn_num));
00686         bp += sizeof(txn_num);
00687 
00688         memcpy(bp, lsnp, sizeof(DB_LSN));
00689         bp += sizeof(DB_LSN);
00690 
00691         uinttmp = (u_int32_t)dbp->log_filename->id;
00692         memcpy(bp, &uinttmp, sizeof(uinttmp));
00693         bp += sizeof(uinttmp);
00694 
00695         uinttmp = (u_int32_t)pgno;
00696         memcpy(bp, &uinttmp, sizeof(uinttmp));
00697         bp += sizeof(uinttmp);
00698 
00699         if (lsn != NULL)
00700                 memcpy(bp, lsn, sizeof(*lsn));
00701         else
00702                 memset(bp, 0, sizeof(*lsn));
00703         bp += sizeof(*lsn);
00704 
00705         uinttmp = (u_int32_t)indx;
00706         memcpy(bp, &uinttmp, sizeof(uinttmp));
00707         bp += sizeof(uinttmp);
00708 
00709         uinttmp = (u_int32_t)indx_copy;
00710         memcpy(bp, &uinttmp, sizeof(uinttmp));
00711         bp += sizeof(uinttmp);
00712 
00713         uinttmp = (u_int32_t)is_insert;
00714         memcpy(bp, &uinttmp, sizeof(uinttmp));
00715         bp += sizeof(uinttmp);
00716 
00717         DB_ASSERT((u_int32_t)(bp - (u_int8_t *)logrec.data) <= logrec.size);
00718 
00719         if (is_durable || txnid == NULL) {
00720                 if ((ret = __log_put(dbenv, rlsnp,(DBT *)&logrec,
00721                     flags | DB_LOG_NOCOPY)) == 0 && txnid != NULL) {
00722                         *lsnp = *rlsnp;
00723                         if (rlsnp != ret_lsnp)
00724                                  *ret_lsnp = *rlsnp;
00725                 }
00726         } else {
00727 #ifdef DIAGNOSTIC
00728                 /*
00729                  * Set the debug bit if we are going to log non-durable
00730                  * transactions so they will be ignored by recovery.
00731                  */
00732                 memcpy(lr->data, logrec.data, logrec.size);
00733                 rectype |= DB_debug_FLAG;
00734                 memcpy(logrec.data, &rectype, sizeof(rectype));
00735 
00736                 ret = __log_put(dbenv,
00737                     rlsnp, (DBT *)&logrec, flags | DB_LOG_NOCOPY);
00738 #else
00739                 ret = 0;
00740 #endif
00741                 STAILQ_INSERT_HEAD(&txnid->logs, lr, links);
00742                 F_SET((TXN_DETAIL *)txnid->td, TXN_DTL_INMEMORY);
00743                 LSN_NOT_LOGGED(*ret_lsnp);
00744         }
00745 
00746 #ifdef LOG_DIAGNOSTIC
00747         if (ret != 0)
00748                 (void)__bam_adj_print(dbenv,
00749                     (DBT *)&logrec, ret_lsnp, DB_TXN_PRINT, NULL);
00750 #endif
00751 
00752 #ifdef DIAGNOSTIC
00753         __os_free(dbenv, logrec.data);
00754 #else
00755         if (is_durable || txnid == NULL)
00756                 __os_free(dbenv, logrec.data);
00757 #endif
00758         return (ret);
00759 }
00760 
00761 /*
00762  * PUBLIC: int __bam_adj_read __P((DB_ENV *, void *, __bam_adj_args **));
00763  */
00764 int
00765 __bam_adj_read(dbenv, recbuf, argpp)
00766         DB_ENV *dbenv;
00767         void *recbuf;
00768         __bam_adj_args **argpp;
00769 {
00770         __bam_adj_args *argp;
00771         u_int32_t uinttmp;
00772         u_int8_t *bp;
00773         int ret;
00774 
00775         if ((ret = __os_malloc(dbenv,
00776             sizeof(__bam_adj_args) + sizeof(DB_TXN), &argp)) != 0)
00777                 return (ret);
00778         bp = recbuf;
00779         argp->txnid = (DB_TXN *)&argp[1];
00780 
00781         memcpy(&argp->type, bp, sizeof(argp->type));
00782         bp += sizeof(argp->type);
00783 
00784         memcpy(&argp->txnid->txnid,  bp, sizeof(argp->txnid->txnid));
00785         bp += sizeof(argp->txnid->txnid);
00786 
00787         memcpy(&argp->prev_lsn, bp, sizeof(DB_LSN));
00788         bp += sizeof(DB_LSN);
00789 
00790         memcpy(&uinttmp, bp, sizeof(uinttmp));
00791         argp->fileid = (int32_t)uinttmp;
00792         bp += sizeof(uinttmp);
00793 
00794         memcpy(&uinttmp, bp, sizeof(uinttmp));
00795         argp->pgno = (db_pgno_t)uinttmp;
00796         bp += sizeof(uinttmp);
00797 
00798         memcpy(&argp->lsn, bp,  sizeof(argp->lsn));
00799         bp += sizeof(argp->lsn);
00800 
00801         memcpy(&uinttmp, bp, sizeof(uinttmp));
00802         argp->indx = (u_int32_t)uinttmp;
00803         bp += sizeof(uinttmp);
00804 
00805         memcpy(&uinttmp, bp, sizeof(uinttmp));
00806         argp->indx_copy = (u_int32_t)uinttmp;
00807         bp += sizeof(uinttmp);
00808 
00809         memcpy(&uinttmp, bp, sizeof(uinttmp));
00810         argp->is_insert = (u_int32_t)uinttmp;
00811         bp += sizeof(uinttmp);
00812 
00813         *argpp = argp;
00814         return (0);
00815 }
00816 
00817 /*
00818  * PUBLIC: int __bam_cadjust_log __P((DB *, DB_TXN *, DB_LSN *,
00819  * PUBLIC:     u_int32_t, db_pgno_t, DB_LSN *, u_int32_t, int32_t, u_int32_t));
00820  */
00821 int
00822 __bam_cadjust_log(dbp, txnid, ret_lsnp, flags, pgno, lsn, indx, adjust, opflags)
00823         DB *dbp;
00824         DB_TXN *txnid;
00825         DB_LSN *ret_lsnp;
00826         u_int32_t flags;
00827         db_pgno_t pgno;
00828         DB_LSN * lsn;
00829         u_int32_t indx;
00830         int32_t adjust;
00831         u_int32_t opflags;
00832 {
00833         DBT logrec;
00834         DB_ENV *dbenv;
00835         DB_TXNLOGREC *lr;
00836         DB_LSN *lsnp, null_lsn, *rlsnp;
00837         u_int32_t uinttmp, rectype, txn_num;
00838         u_int npad;
00839         u_int8_t *bp;
00840         int is_durable, ret;
00841 
00842         dbenv = dbp->dbenv;
00843         COMPQUIET(lr, NULL);
00844 
00845         rectype = DB___bam_cadjust;
00846         npad = 0;
00847         rlsnp = ret_lsnp;
00848 
00849         ret = 0;
00850 
00851         if (LF_ISSET(DB_LOG_NOT_DURABLE) ||
00852             F_ISSET(dbp, DB_AM_NOT_DURABLE)) {
00853                 is_durable = 0;
00854         } else
00855                 is_durable = 1;
00856 
00857         if (txnid == NULL) {
00858                 txn_num = 0;
00859                 lsnp = &null_lsn;
00860                 null_lsn.file = null_lsn.offset = 0;
00861         } else {
00862                 if (TAILQ_FIRST(&txnid->kids) != NULL &&
00863                     (ret = __txn_activekids(dbenv, rectype, txnid)) != 0)
00864                         return (ret);
00865                 /*
00866                  * We need to assign begin_lsn while holding region mutex.
00867                  * That assignment is done inside the DbEnv->log_put call,
00868                  * so pass in the appropriate memory location to be filled
00869                  * in by the log_put code.
00870                  */
00871                 DB_SET_TXN_LSNP(txnid, &rlsnp, &lsnp);
00872                 txn_num = txnid->txnid;
00873         }
00874 
00875         DB_ASSERT(dbp->log_filename != NULL);
00876         if (dbp->log_filename->id == DB_LOGFILEID_INVALID &&
00877             (ret = __dbreg_lazy_id(dbp)) != 0)
00878                 return (ret);
00879 
00880         logrec.size = sizeof(rectype) + sizeof(txn_num) + sizeof(DB_LSN)
00881             + sizeof(u_int32_t)
00882             + sizeof(u_int32_t)
00883             + sizeof(*lsn)
00884             + sizeof(u_int32_t)
00885             + sizeof(u_int32_t)
00886             + sizeof(u_int32_t);
00887         if (CRYPTO_ON(dbenv)) {
00888                 npad =
00889                     ((DB_CIPHER *)dbenv->crypto_handle)->adj_size(logrec.size);
00890                 logrec.size += npad;
00891         }
00892 
00893         if (is_durable || txnid == NULL) {
00894                 if ((ret =
00895                     __os_malloc(dbenv, logrec.size, &logrec.data)) != 0)
00896                         return (ret);
00897         } else {
00898                 if ((ret = __os_malloc(dbenv,
00899                     logrec.size + sizeof(DB_TXNLOGREC), &lr)) != 0)
00900                         return (ret);
00901 #ifdef DIAGNOSTIC
00902                 if ((ret =
00903                     __os_malloc(dbenv, logrec.size, &logrec.data)) != 0) {
00904                         __os_free(dbenv, lr);
00905                         return (ret);
00906                 }
00907 #else
00908                 logrec.data = lr->data;
00909 #endif
00910         }
00911         if (npad > 0)
00912                 memset((u_int8_t *)logrec.data + logrec.size - npad, 0, npad);
00913 
00914         bp = logrec.data;
00915 
00916         memcpy(bp, &rectype, sizeof(rectype));
00917         bp += sizeof(rectype);
00918 
00919         memcpy(bp, &txn_num, sizeof(txn_num));
00920         bp += sizeof(txn_num);
00921 
00922         memcpy(bp, lsnp, sizeof(DB_LSN));
00923         bp += sizeof(DB_LSN);
00924 
00925         uinttmp = (u_int32_t)dbp->log_filename->id;
00926         memcpy(bp, &uinttmp, sizeof(uinttmp));
00927         bp += sizeof(uinttmp);
00928 
00929         uinttmp = (u_int32_t)pgno;
00930         memcpy(bp, &uinttmp, sizeof(uinttmp));
00931         bp += sizeof(uinttmp);
00932 
00933         if (lsn != NULL)
00934                 memcpy(bp, lsn, sizeof(*lsn));
00935         else
00936                 memset(bp, 0, sizeof(*lsn));
00937         bp += sizeof(*lsn);
00938 
00939         uinttmp = (u_int32_t)indx;
00940         memcpy(bp, &uinttmp, sizeof(uinttmp));
00941         bp += sizeof(uinttmp);
00942 
00943         uinttmp = (u_int32_t)adjust;
00944         memcpy(bp, &uinttmp, sizeof(uinttmp));
00945         bp += sizeof(uinttmp);
00946 
00947         uinttmp = (u_int32_t)opflags;
00948         memcpy(bp, &uinttmp, sizeof(uinttmp));
00949         bp += sizeof(uinttmp);
00950 
00951         DB_ASSERT((u_int32_t)(bp - (u_int8_t *)logrec.data) <= logrec.size);
00952 
00953         if (is_durable || txnid == NULL) {
00954                 if ((ret = __log_put(dbenv, rlsnp,(DBT *)&logrec,
00955                     flags | DB_LOG_NOCOPY)) == 0 && txnid != NULL) {
00956                         *lsnp = *rlsnp;
00957                         if (rlsnp != ret_lsnp)
00958                                  *ret_lsnp = *rlsnp;
00959                 }
00960         } else {
00961 #ifdef DIAGNOSTIC
00962                 /*
00963                  * Set the debug bit if we are going to log non-durable
00964                  * transactions so they will be ignored by recovery.
00965                  */
00966                 memcpy(lr->data, logrec.data, logrec.size);
00967                 rectype |= DB_debug_FLAG;
00968                 memcpy(logrec.data, &rectype, sizeof(rectype));
00969 
00970                 ret = __log_put(dbenv,
00971                     rlsnp, (DBT *)&logrec, flags | DB_LOG_NOCOPY);
00972 #else
00973                 ret = 0;
00974 #endif
00975                 STAILQ_INSERT_HEAD(&txnid->logs, lr, links);
00976                 F_SET((TXN_DETAIL *)txnid->td, TXN_DTL_INMEMORY);
00977                 LSN_NOT_LOGGED(*ret_lsnp);
00978         }
00979 
00980 #ifdef LOG_DIAGNOSTIC
00981         if (ret != 0)
00982                 (void)__bam_cadjust_print(dbenv,
00983                     (DBT *)&logrec, ret_lsnp, DB_TXN_PRINT, NULL);
00984 #endif
00985 
00986 #ifdef DIAGNOSTIC
00987         __os_free(dbenv, logrec.data);
00988 #else
00989         if (is_durable || txnid == NULL)
00990                 __os_free(dbenv, logrec.data);
00991 #endif
00992         return (ret);
00993 }
00994 
00995 /*
00996  * PUBLIC: int __bam_cadjust_read __P((DB_ENV *, void *,
00997  * PUBLIC:     __bam_cadjust_args **));
00998  */
00999 int
01000 __bam_cadjust_read(dbenv, recbuf, argpp)
01001         DB_ENV *dbenv;
01002         void *recbuf;
01003         __bam_cadjust_args **argpp;
01004 {
01005         __bam_cadjust_args *argp;
01006         u_int32_t uinttmp;
01007         u_int8_t *bp;
01008         int ret;
01009 
01010         if ((ret = __os_malloc(dbenv,
01011             sizeof(__bam_cadjust_args) + sizeof(DB_TXN), &argp)) != 0)
01012                 return (ret);
01013         bp = recbuf;
01014         argp->txnid = (DB_TXN *)&argp[1];
01015 
01016         memcpy(&argp->type, bp, sizeof(argp->type));
01017         bp += sizeof(argp->type);
01018 
01019         memcpy(&argp->txnid->txnid,  bp, sizeof(argp->txnid->txnid));
01020         bp += sizeof(argp->txnid->txnid);
01021 
01022         memcpy(&argp->prev_lsn, bp, sizeof(DB_LSN));
01023         bp += sizeof(DB_LSN);
01024 
01025         memcpy(&uinttmp, bp, sizeof(uinttmp));
01026         argp->fileid = (int32_t)uinttmp;
01027         bp += sizeof(uinttmp);
01028 
01029         memcpy(&uinttmp, bp, sizeof(uinttmp));
01030         argp->pgno = (db_pgno_t)uinttmp;
01031         bp += sizeof(uinttmp);
01032 
01033         memcpy(&argp->lsn, bp,  sizeof(argp->lsn));
01034         bp += sizeof(argp->lsn);
01035 
01036         memcpy(&uinttmp, bp, sizeof(uinttmp));
01037         argp->indx = (u_int32_t)uinttmp;
01038         bp += sizeof(uinttmp);
01039 
01040         memcpy(&uinttmp, bp, sizeof(uinttmp));
01041         argp->adjust = (int32_t)uinttmp;
01042         bp += sizeof(uinttmp);
01043 
01044         memcpy(&uinttmp, bp, sizeof(uinttmp));
01045         argp->opflags = (u_int32_t)uinttmp;
01046         bp += sizeof(uinttmp);
01047 
01048         *argpp = argp;
01049         return (0);
01050 }
01051 
01052 /*
01053  * PUBLIC: int __bam_cdel_log __P((DB *, DB_TXN *, DB_LSN *,
01054  * PUBLIC:     u_int32_t, db_pgno_t, DB_LSN *, u_int32_t));
01055  */
01056 int
01057 __bam_cdel_log(dbp, txnid, ret_lsnp, flags, pgno, lsn, indx)
01058         DB *dbp;
01059         DB_TXN *txnid;
01060         DB_LSN *ret_lsnp;
01061         u_int32_t flags;
01062         db_pgno_t pgno;
01063         DB_LSN * lsn;
01064         u_int32_t indx;
01065 {
01066         DBT logrec;
01067         DB_ENV *dbenv;
01068         DB_TXNLOGREC *lr;
01069         DB_LSN *lsnp, null_lsn, *rlsnp;
01070         u_int32_t uinttmp, rectype, txn_num;
01071         u_int npad;
01072         u_int8_t *bp;
01073         int is_durable, ret;
01074 
01075         dbenv = dbp->dbenv;
01076         COMPQUIET(lr, NULL);
01077 
01078         rectype = DB___bam_cdel;
01079         npad = 0;
01080         rlsnp = ret_lsnp;
01081 
01082         ret = 0;
01083 
01084         if (LF_ISSET(DB_LOG_NOT_DURABLE) ||
01085             F_ISSET(dbp, DB_AM_NOT_DURABLE)) {
01086                 is_durable = 0;
01087         } else
01088                 is_durable = 1;
01089 
01090         if (txnid == NULL) {
01091                 txn_num = 0;
01092                 lsnp = &null_lsn;
01093                 null_lsn.file = null_lsn.offset = 0;
01094         } else {
01095                 if (TAILQ_FIRST(&txnid->kids) != NULL &&
01096                     (ret = __txn_activekids(dbenv, rectype, txnid)) != 0)
01097                         return (ret);
01098                 /*
01099                  * We need to assign begin_lsn while holding region mutex.
01100                  * That assignment is done inside the DbEnv->log_put call,
01101                  * so pass in the appropriate memory location to be filled
01102                  * in by the log_put code.
01103                  */
01104                 DB_SET_TXN_LSNP(txnid, &rlsnp, &lsnp);
01105                 txn_num = txnid->txnid;
01106         }
01107 
01108         DB_ASSERT(dbp->log_filename != NULL);
01109         if (dbp->log_filename->id == DB_LOGFILEID_INVALID &&
01110             (ret = __dbreg_lazy_id(dbp)) != 0)
01111                 return (ret);
01112 
01113         logrec.size = sizeof(rectype) + sizeof(txn_num) + sizeof(DB_LSN)
01114             + sizeof(u_int32_t)
01115             + sizeof(u_int32_t)
01116             + sizeof(*lsn)
01117             + sizeof(u_int32_t);
01118         if (CRYPTO_ON(dbenv)) {
01119                 npad =
01120                     ((DB_CIPHER *)dbenv->crypto_handle)->adj_size(logrec.size);
01121                 logrec.size += npad;
01122         }
01123 
01124         if (is_durable || txnid == NULL) {
01125                 if ((ret =
01126                     __os_malloc(dbenv, logrec.size, &logrec.data)) != 0)
01127                         return (ret);
01128         } else {
01129                 if ((ret = __os_malloc(dbenv,
01130                     logrec.size + sizeof(DB_TXNLOGREC), &lr)) != 0)
01131                         return (ret);
01132 #ifdef DIAGNOSTIC
01133                 if ((ret =
01134                     __os_malloc(dbenv, logrec.size, &logrec.data)) != 0) {
01135                         __os_free(dbenv, lr);
01136                         return (ret);
01137                 }
01138 #else
01139                 logrec.data = lr->data;
01140 #endif
01141         }
01142         if (npad > 0)
01143                 memset((u_int8_t *)logrec.data + logrec.size - npad, 0, npad);
01144 
01145         bp = logrec.data;
01146 
01147         memcpy(bp, &rectype, sizeof(rectype));
01148         bp += sizeof(rectype);
01149 
01150         memcpy(bp, &txn_num, sizeof(txn_num));
01151         bp += sizeof(txn_num);
01152 
01153         memcpy(bp, lsnp, sizeof(DB_LSN));
01154         bp += sizeof(DB_LSN);
01155 
01156         uinttmp = (u_int32_t)dbp->log_filename->id;
01157         memcpy(bp, &uinttmp, sizeof(uinttmp));
01158         bp += sizeof(uinttmp);
01159 
01160         uinttmp = (u_int32_t)pgno;
01161         memcpy(bp, &uinttmp, sizeof(uinttmp));
01162         bp += sizeof(uinttmp);
01163 
01164         if (lsn != NULL)
01165                 memcpy(bp, lsn, sizeof(*lsn));
01166         else
01167                 memset(bp, 0, sizeof(*lsn));
01168         bp += sizeof(*lsn);
01169 
01170         uinttmp = (u_int32_t)indx;
01171         memcpy(bp, &uinttmp, sizeof(uinttmp));
01172         bp += sizeof(uinttmp);
01173 
01174         DB_ASSERT((u_int32_t)(bp - (u_int8_t *)logrec.data) <= logrec.size);
01175 
01176         if (is_durable || txnid == NULL) {
01177                 if ((ret = __log_put(dbenv, rlsnp,(DBT *)&logrec,
01178                     flags | DB_LOG_NOCOPY)) == 0 && txnid != NULL) {
01179                         *lsnp = *rlsnp;
01180                         if (rlsnp != ret_lsnp)
01181                                  *ret_lsnp = *rlsnp;
01182                 }
01183         } else {
01184 #ifdef DIAGNOSTIC
01185                 /*
01186                  * Set the debug bit if we are going to log non-durable
01187                  * transactions so they will be ignored by recovery.
01188                  */
01189                 memcpy(lr->data, logrec.data, logrec.size);
01190                 rectype |= DB_debug_FLAG;
01191                 memcpy(logrec.data, &rectype, sizeof(rectype));
01192 
01193                 ret = __log_put(dbenv,
01194                     rlsnp, (DBT *)&logrec, flags | DB_LOG_NOCOPY);
01195 #else
01196                 ret = 0;
01197 #endif
01198                 STAILQ_INSERT_HEAD(&txnid->logs, lr, links);
01199                 F_SET((TXN_DETAIL *)txnid->td, TXN_DTL_INMEMORY);
01200                 LSN_NOT_LOGGED(*ret_lsnp);
01201         }
01202 
01203 #ifdef LOG_DIAGNOSTIC
01204         if (ret != 0)
01205                 (void)__bam_cdel_print(dbenv,
01206                     (DBT *)&logrec, ret_lsnp, DB_TXN_PRINT, NULL);
01207 #endif
01208 
01209 #ifdef DIAGNOSTIC
01210         __os_free(dbenv, logrec.data);
01211 #else
01212         if (is_durable || txnid == NULL)
01213                 __os_free(dbenv, logrec.data);
01214 #endif
01215         return (ret);
01216 }
01217 
01218 /*
01219  * PUBLIC: int __bam_cdel_read __P((DB_ENV *, void *, __bam_cdel_args **));
01220  */
01221 int
01222 __bam_cdel_read(dbenv, recbuf, argpp)
01223         DB_ENV *dbenv;
01224         void *recbuf;
01225         __bam_cdel_args **argpp;
01226 {
01227         __bam_cdel_args *argp;
01228         u_int32_t uinttmp;
01229         u_int8_t *bp;
01230         int ret;
01231 
01232         if ((ret = __os_malloc(dbenv,
01233             sizeof(__bam_cdel_args) + sizeof(DB_TXN), &argp)) != 0)
01234                 return (ret);
01235         bp = recbuf;
01236         argp->txnid = (DB_TXN *)&argp[1];
01237 
01238         memcpy(&argp->type, bp, sizeof(argp->type));
01239         bp += sizeof(argp->type);
01240 
01241         memcpy(&argp->txnid->txnid,  bp, sizeof(argp->txnid->txnid));
01242         bp += sizeof(argp->txnid->txnid);
01243 
01244         memcpy(&argp->prev_lsn, bp, sizeof(DB_LSN));
01245         bp += sizeof(DB_LSN);
01246 
01247         memcpy(&uinttmp, bp, sizeof(uinttmp));
01248         argp->fileid = (int32_t)uinttmp;
01249         bp += sizeof(uinttmp);
01250 
01251         memcpy(&uinttmp, bp, sizeof(uinttmp));
01252         argp->pgno = (db_pgno_t)uinttmp;
01253         bp += sizeof(uinttmp);
01254 
01255         memcpy(&argp->lsn, bp,  sizeof(argp->lsn));
01256         bp += sizeof(argp->lsn);
01257 
01258         memcpy(&uinttmp, bp, sizeof(uinttmp));
01259         argp->indx = (u_int32_t)uinttmp;
01260         bp += sizeof(uinttmp);
01261 
01262         *argpp = argp;
01263         return (0);
01264 }
01265 
01266 /*
01267  * PUBLIC: int __bam_repl_log __P((DB *, DB_TXN *, DB_LSN *,
01268  * PUBLIC:     u_int32_t, db_pgno_t, DB_LSN *, u_int32_t, u_int32_t,
01269  * PUBLIC:     const DBT *, const DBT *, u_int32_t, u_int32_t));
01270  */
01271 int
01272 __bam_repl_log(dbp, txnid, ret_lsnp, flags, pgno, lsn, indx, isdeleted, orig,
01273     repl, prefix, suffix)
01274         DB *dbp;
01275         DB_TXN *txnid;
01276         DB_LSN *ret_lsnp;
01277         u_int32_t flags;
01278         db_pgno_t pgno;
01279         DB_LSN * lsn;
01280         u_int32_t indx;
01281         u_int32_t isdeleted;
01282         const DBT *orig;
01283         const DBT *repl;
01284         u_int32_t prefix;
01285         u_int32_t suffix;
01286 {
01287         DBT logrec;
01288         DB_ENV *dbenv;
01289         DB_TXNLOGREC *lr;
01290         DB_LSN *lsnp, null_lsn, *rlsnp;
01291         u_int32_t zero, uinttmp, rectype, txn_num;
01292         u_int npad;
01293         u_int8_t *bp;
01294         int is_durable, ret;
01295 
01296         dbenv = dbp->dbenv;
01297         COMPQUIET(lr, NULL);
01298 
01299         rectype = DB___bam_repl;
01300         npad = 0;
01301         rlsnp = ret_lsnp;
01302 
01303         ret = 0;
01304 
01305         if (LF_ISSET(DB_LOG_NOT_DURABLE) ||
01306             F_ISSET(dbp, DB_AM_NOT_DURABLE)) {
01307                 is_durable = 0;
01308         } else
01309                 is_durable = 1;
01310 
01311         if (txnid == NULL) {
01312                 txn_num = 0;
01313                 lsnp = &null_lsn;
01314                 null_lsn.file = null_lsn.offset = 0;
01315         } else {
01316                 if (TAILQ_FIRST(&txnid->kids) != NULL &&
01317                     (ret = __txn_activekids(dbenv, rectype, txnid)) != 0)
01318                         return (ret);
01319                 /*
01320                  * We need to assign begin_lsn while holding region mutex.
01321                  * That assignment is done inside the DbEnv->log_put call,
01322                  * so pass in the appropriate memory location to be filled
01323                  * in by the log_put code.
01324                  */
01325                 DB_SET_TXN_LSNP(txnid, &rlsnp, &lsnp);
01326                 txn_num = txnid->txnid;
01327         }
01328 
01329         DB_ASSERT(dbp->log_filename != NULL);
01330         if (dbp->log_filename->id == DB_LOGFILEID_INVALID &&
01331             (ret = __dbreg_lazy_id(dbp)) != 0)
01332                 return (ret);
01333 
01334         logrec.size = sizeof(rectype) + sizeof(txn_num) + sizeof(DB_LSN)
01335             + sizeof(u_int32_t)
01336             + sizeof(u_int32_t)
01337             + sizeof(*lsn)
01338             + sizeof(u_int32_t)
01339             + sizeof(u_int32_t)
01340             + sizeof(u_int32_t) + (orig == NULL ? 0 : orig->size)
01341             + sizeof(u_int32_t) + (repl == NULL ? 0 : repl->size)
01342             + sizeof(u_int32_t)
01343             + sizeof(u_int32_t);
01344         if (CRYPTO_ON(dbenv)) {
01345                 npad =
01346                     ((DB_CIPHER *)dbenv->crypto_handle)->adj_size(logrec.size);
01347                 logrec.size += npad;
01348         }
01349 
01350         if (is_durable || txnid == NULL) {
01351                 if ((ret =
01352                     __os_malloc(dbenv, logrec.size, &logrec.data)) != 0)
01353                         return (ret);
01354         } else {
01355                 if ((ret = __os_malloc(dbenv,
01356                     logrec.size + sizeof(DB_TXNLOGREC), &lr)) != 0)
01357                         return (ret);
01358 #ifdef DIAGNOSTIC
01359                 if ((ret =
01360                     __os_malloc(dbenv, logrec.size, &logrec.data)) != 0) {
01361                         __os_free(dbenv, lr);
01362                         return (ret);
01363                 }
01364 #else
01365                 logrec.data = lr->data;
01366 #endif
01367         }
01368         if (npad > 0)
01369                 memset((u_int8_t *)logrec.data + logrec.size - npad, 0, npad);
01370 
01371         bp = logrec.data;
01372 
01373         memcpy(bp, &rectype, sizeof(rectype));
01374         bp += sizeof(rectype);
01375 
01376         memcpy(bp, &txn_num, sizeof(txn_num));
01377         bp += sizeof(txn_num);
01378 
01379         memcpy(bp, lsnp, sizeof(DB_LSN));
01380         bp += sizeof(DB_LSN);
01381 
01382         uinttmp = (u_int32_t)dbp->log_filename->id;
01383         memcpy(bp, &uinttmp, sizeof(uinttmp));
01384         bp += sizeof(uinttmp);
01385 
01386         uinttmp = (u_int32_t)pgno;
01387         memcpy(bp, &uinttmp, sizeof(uinttmp));
01388         bp += sizeof(uinttmp);
01389 
01390         if (lsn != NULL)
01391                 memcpy(bp, lsn, sizeof(*lsn));
01392         else
01393                 memset(bp, 0, sizeof(*lsn));
01394         bp += sizeof(*lsn);
01395 
01396         uinttmp = (u_int32_t)indx;
01397         memcpy(bp, &uinttmp, sizeof(uinttmp));
01398         bp += sizeof(uinttmp);
01399 
01400         uinttmp = (u_int32_t)isdeleted;
01401         memcpy(bp, &uinttmp, sizeof(uinttmp));
01402         bp += sizeof(uinttmp);
01403 
01404         if (orig == NULL) {
01405                 zero = 0;
01406                 memcpy(bp, &zero, sizeof(u_int32_t));
01407                 bp += sizeof(u_int32_t);
01408         } else {
01409                 memcpy(bp, &orig->size, sizeof(orig->size));
01410                 bp += sizeof(orig->size);
01411                 memcpy(bp, orig->data, orig->size);
01412                 bp += orig->size;
01413         }
01414 
01415         if (repl == NULL) {
01416                 zero = 0;
01417                 memcpy(bp, &zero, sizeof(u_int32_t));
01418                 bp += sizeof(u_int32_t);
01419         } else {
01420                 memcpy(bp, &repl->size, sizeof(repl->size));
01421                 bp += sizeof(repl->size);
01422                 memcpy(bp, repl->data, repl->size);
01423                 bp += repl->size;
01424         }
01425 
01426         uinttmp = (u_int32_t)prefix;
01427         memcpy(bp, &uinttmp, sizeof(uinttmp));
01428         bp += sizeof(uinttmp);
01429 
01430         uinttmp = (u_int32_t)suffix;
01431         memcpy(bp, &uinttmp, sizeof(uinttmp));
01432         bp += sizeof(uinttmp);
01433 
01434         DB_ASSERT((u_int32_t)(bp - (u_int8_t *)logrec.data) <= logrec.size);
01435 
01436         if (is_durable || txnid == NULL) {
01437                 if ((ret = __log_put(dbenv, rlsnp,(DBT *)&logrec,
01438                     flags | DB_LOG_NOCOPY)) == 0 && txnid != NULL) {
01439                         *lsnp = *rlsnp;
01440                         if (rlsnp != ret_lsnp)
01441                                  *ret_lsnp = *rlsnp;
01442                 }
01443         } else {
01444 #ifdef DIAGNOSTIC
01445                 /*
01446                  * Set the debug bit if we are going to log non-durable
01447                  * transactions so they will be ignored by recovery.
01448                  */
01449                 memcpy(lr->data, logrec.data, logrec.size);
01450                 rectype |= DB_debug_FLAG;
01451                 memcpy(logrec.data, &rectype, sizeof(rectype));
01452 
01453                 ret = __log_put(dbenv,
01454                     rlsnp, (DBT *)&logrec, flags | DB_LOG_NOCOPY);
01455 #else
01456                 ret = 0;
01457 #endif
01458                 STAILQ_INSERT_HEAD(&txnid->logs, lr, links);
01459                 F_SET((TXN_DETAIL *)txnid->td, TXN_DTL_INMEMORY);
01460                 LSN_NOT_LOGGED(*ret_lsnp);
01461         }
01462 
01463 #ifdef LOG_DIAGNOSTIC
01464         if (ret != 0)
01465                 (void)__bam_repl_print(dbenv,
01466                     (DBT *)&logrec, ret_lsnp, DB_TXN_PRINT, NULL);
01467 #endif
01468 
01469 #ifdef DIAGNOSTIC
01470         __os_free(dbenv, logrec.data);
01471 #else
01472         if (is_durable || txnid == NULL)
01473                 __os_free(dbenv, logrec.data);
01474 #endif
01475         return (ret);
01476 }
01477 
01478 /*
01479  * PUBLIC: int __bam_repl_read __P((DB_ENV *, void *, __bam_repl_args **));
01480  */
01481 int
01482 __bam_repl_read(dbenv, recbuf, argpp)
01483         DB_ENV *dbenv;
01484         void *recbuf;
01485         __bam_repl_args **argpp;
01486 {
01487         __bam_repl_args *argp;
01488         u_int32_t uinttmp;
01489         u_int8_t *bp;
01490         int ret;
01491 
01492         if ((ret = __os_malloc(dbenv,
01493             sizeof(__bam_repl_args) + sizeof(DB_TXN), &argp)) != 0)
01494                 return (ret);
01495         bp = recbuf;
01496         argp->txnid = (DB_TXN *)&argp[1];
01497 
01498         memcpy(&argp->type, bp, sizeof(argp->type));
01499         bp += sizeof(argp->type);
01500 
01501         memcpy(&argp->txnid->txnid,  bp, sizeof(argp->txnid->txnid));
01502         bp += sizeof(argp->txnid->txnid);
01503 
01504         memcpy(&argp->prev_lsn, bp, sizeof(DB_LSN));
01505         bp += sizeof(DB_LSN);
01506 
01507         memcpy(&uinttmp, bp, sizeof(uinttmp));
01508         argp->fileid = (int32_t)uinttmp;
01509         bp += sizeof(uinttmp);
01510 
01511         memcpy(&uinttmp, bp, sizeof(uinttmp));
01512         argp->pgno = (db_pgno_t)uinttmp;
01513         bp += sizeof(uinttmp);
01514 
01515         memcpy(&argp->lsn, bp,  sizeof(argp->lsn));
01516         bp += sizeof(argp->lsn);
01517 
01518         memcpy(&uinttmp, bp, sizeof(uinttmp));
01519         argp->indx = (u_int32_t)uinttmp;
01520         bp += sizeof(uinttmp);
01521 
01522         memcpy(&uinttmp, bp, sizeof(uinttmp));
01523         argp->isdeleted = (u_int32_t)uinttmp;
01524         bp += sizeof(uinttmp);
01525 
01526         memset(&argp->orig, 0, sizeof(argp->orig));
01527         memcpy(&argp->orig.size, bp, sizeof(u_int32_t));
01528         bp += sizeof(u_int32_t);
01529         argp->orig.data = bp;
01530         bp += argp->orig.size;
01531 
01532         memset(&argp->repl, 0, sizeof(argp->repl));
01533         memcpy(&argp->repl.size, bp, sizeof(u_int32_t));
01534         bp += sizeof(u_int32_t);
01535         argp->repl.data = bp;
01536         bp += argp->repl.size;
01537 
01538         memcpy(&uinttmp, bp, sizeof(uinttmp));
01539         argp->prefix = (u_int32_t)uinttmp;
01540         bp += sizeof(uinttmp);
01541 
01542         memcpy(&uinttmp, bp, sizeof(uinttmp));
01543         argp->suffix = (u_int32_t)uinttmp;
01544         bp += sizeof(uinttmp);
01545 
01546         *argpp = argp;
01547         return (0);
01548 }
01549 
01550 /*
01551  * PUBLIC: int __bam_root_log __P((DB *, DB_TXN *, DB_LSN *,
01552  * PUBLIC:     u_int32_t, db_pgno_t, db_pgno_t, DB_LSN *));
01553  */
01554 int
01555 __bam_root_log(dbp, txnid, ret_lsnp, flags, meta_pgno, root_pgno, meta_lsn)
01556         DB *dbp;
01557         DB_TXN *txnid;
01558         DB_LSN *ret_lsnp;
01559         u_int32_t flags;
01560         db_pgno_t meta_pgno;
01561         db_pgno_t root_pgno;
01562         DB_LSN * meta_lsn;
01563 {
01564         DBT logrec;
01565         DB_ENV *dbenv;
01566         DB_TXNLOGREC *lr;
01567         DB_LSN *lsnp, null_lsn, *rlsnp;
01568         u_int32_t uinttmp, rectype, txn_num;
01569         u_int npad;
01570         u_int8_t *bp;
01571         int is_durable, ret;
01572 
01573         dbenv = dbp->dbenv;
01574         COMPQUIET(lr, NULL);
01575 
01576         rectype = DB___bam_root;
01577         npad = 0;
01578         rlsnp = ret_lsnp;
01579 
01580         ret = 0;
01581 
01582         if (LF_ISSET(DB_LOG_NOT_DURABLE) ||
01583             F_ISSET(dbp, DB_AM_NOT_DURABLE)) {
01584                 is_durable = 0;
01585         } else
01586                 is_durable = 1;
01587 
01588         if (txnid == NULL) {
01589                 txn_num = 0;
01590                 lsnp = &null_lsn;
01591                 null_lsn.file = null_lsn.offset = 0;
01592         } else {
01593                 if (TAILQ_FIRST(&txnid->kids) != NULL &&
01594                     (ret = __txn_activekids(dbenv, rectype, txnid)) != 0)
01595                         return (ret);
01596                 /*
01597                  * We need to assign begin_lsn while holding region mutex.
01598                  * That assignment is done inside the DbEnv->log_put call,
01599                  * so pass in the appropriate memory location to be filled
01600                  * in by the log_put code.
01601                  */
01602                 DB_SET_TXN_LSNP(txnid, &rlsnp, &lsnp);
01603                 txn_num = txnid->txnid;
01604         }
01605 
01606         DB_ASSERT(dbp->log_filename != NULL);
01607         if (dbp->log_filename->id == DB_LOGFILEID_INVALID &&
01608             (ret = __dbreg_lazy_id(dbp)) != 0)
01609                 return (ret);
01610 
01611         logrec.size = sizeof(rectype) + sizeof(txn_num) + sizeof(DB_LSN)
01612             + sizeof(u_int32_t)
01613             + sizeof(u_int32_t)
01614             + sizeof(u_int32_t)
01615             + sizeof(*meta_lsn);
01616         if (CRYPTO_ON(dbenv)) {
01617                 npad =
01618                     ((DB_CIPHER *)dbenv->crypto_handle)->adj_size(logrec.size);
01619                 logrec.size += npad;
01620         }
01621 
01622         if (is_durable || txnid == NULL) {
01623                 if ((ret =
01624                     __os_malloc(dbenv, logrec.size, &logrec.data)) != 0)
01625                         return (ret);
01626         } else {
01627                 if ((ret = __os_malloc(dbenv,
01628                     logrec.size + sizeof(DB_TXNLOGREC), &lr)) != 0)
01629                         return (ret);
01630 #ifdef DIAGNOSTIC
01631                 if ((ret =
01632                     __os_malloc(dbenv, logrec.size, &logrec.data)) != 0) {
01633                         __os_free(dbenv, lr);
01634                         return (ret);
01635                 }
01636 #else
01637                 logrec.data = lr->data;
01638 #endif
01639         }
01640         if (npad > 0)
01641                 memset((u_int8_t *)logrec.data + logrec.size - npad, 0, npad);
01642 
01643         bp = logrec.data;
01644 
01645         memcpy(bp, &rectype, sizeof(rectype));
01646         bp += sizeof(rectype);
01647 
01648         memcpy(bp, &txn_num, sizeof(txn_num));
01649         bp += sizeof(txn_num);
01650 
01651         memcpy(bp, lsnp, sizeof(DB_LSN));
01652         bp += sizeof(DB_LSN);
01653 
01654         uinttmp = (u_int32_t)dbp->log_filename->id;
01655         memcpy(bp, &uinttmp, sizeof(uinttmp));
01656         bp += sizeof(uinttmp);
01657 
01658         uinttmp = (u_int32_t)meta_pgno;
01659         memcpy(bp, &uinttmp, sizeof(uinttmp));
01660         bp += sizeof(uinttmp);
01661 
01662         uinttmp = (u_int32_t)root_pgno;
01663         memcpy(bp, &uinttmp, sizeof(uinttmp));
01664         bp += sizeof(uinttmp);
01665 
01666         if (meta_lsn != NULL)
01667                 memcpy(bp, meta_lsn, sizeof(*meta_lsn));
01668         else
01669                 memset(bp, 0, sizeof(*meta_lsn));
01670         bp += sizeof(*meta_lsn);
01671 
01672         DB_ASSERT((u_int32_t)(bp - (u_int8_t *)logrec.data) <= logrec.size);
01673 
01674         if (is_durable || txnid == NULL) {
01675                 if ((ret = __log_put(dbenv, rlsnp,(DBT *)&logrec,
01676                     flags | DB_LOG_NOCOPY)) == 0 && txnid != NULL) {
01677                         *lsnp = *rlsnp;
01678                         if (rlsnp != ret_lsnp)
01679                                  *ret_lsnp = *rlsnp;
01680                 }
01681         } else {
01682 #ifdef DIAGNOSTIC
01683                 /*
01684                  * Set the debug bit if we are going to log non-durable
01685                  * transactions so they will be ignored by recovery.
01686                  */
01687                 memcpy(lr->data, logrec.data, logrec.size);
01688                 rectype |= DB_debug_FLAG;
01689                 memcpy(logrec.data, &rectype, sizeof(rectype));
01690 
01691                 ret = __log_put(dbenv,
01692                     rlsnp, (DBT *)&logrec, flags | DB_LOG_NOCOPY);
01693 #else
01694                 ret = 0;
01695 #endif
01696                 STAILQ_INSERT_HEAD(&txnid->logs, lr, links);
01697                 F_SET((TXN_DETAIL *)txnid->td, TXN_DTL_INMEMORY);
01698                 LSN_NOT_LOGGED(*ret_lsnp);
01699         }
01700 
01701 #ifdef LOG_DIAGNOSTIC
01702         if (ret != 0)
01703                 (void)__bam_root_print(dbenv,
01704                     (DBT *)&logrec, ret_lsnp, DB_TXN_PRINT, NULL);
01705 #endif
01706 
01707 #ifdef DIAGNOSTIC
01708         __os_free(dbenv, logrec.data);
01709 #else
01710         if (is_durable || txnid == NULL)
01711                 __os_free(dbenv, logrec.data);
01712 #endif
01713         return (ret);
01714 }
01715 
01716 /*
01717  * PUBLIC: int __bam_root_read __P((DB_ENV *, void *, __bam_root_args **));
01718  */
01719 int
01720 __bam_root_read(dbenv, recbuf, argpp)
01721         DB_ENV *dbenv;
01722         void *recbuf;
01723         __bam_root_args **argpp;
01724 {
01725         __bam_root_args *argp;
01726         u_int32_t uinttmp;
01727         u_int8_t *bp;
01728         int ret;
01729 
01730         if ((ret = __os_malloc(dbenv,
01731             sizeof(__bam_root_args) + sizeof(DB_TXN), &argp)) != 0)
01732                 return (ret);
01733         bp = recbuf;
01734         argp->txnid = (DB_TXN *)&argp[1];
01735 
01736         memcpy(&argp->type, bp, sizeof(argp->type));
01737         bp += sizeof(argp->type);
01738 
01739         memcpy(&argp->txnid->txnid,  bp, sizeof(argp->txnid->txnid));
01740         bp += sizeof(argp->txnid->txnid);
01741 
01742         memcpy(&argp->prev_lsn, bp, sizeof(DB_LSN));
01743         bp += sizeof(DB_LSN);
01744 
01745         memcpy(&uinttmp, bp, sizeof(uinttmp));
01746         argp->fileid = (int32_t)uinttmp;
01747         bp += sizeof(uinttmp);
01748 
01749         memcpy(&uinttmp, bp, sizeof(uinttmp));
01750         argp->meta_pgno = (db_pgno_t)uinttmp;
01751         bp += sizeof(uinttmp);
01752 
01753         memcpy(&uinttmp, bp, sizeof(uinttmp));
01754         argp->root_pgno = (db_pgno_t)uinttmp;
01755         bp += sizeof(uinttmp);
01756 
01757         memcpy(&argp->meta_lsn, bp,  sizeof(argp->meta_lsn));
01758         bp += sizeof(argp->meta_lsn);
01759 
01760         *argpp = argp;
01761         return (0);
01762 }
01763 
01764 /*
01765  * PUBLIC: int __bam_curadj_log __P((DB *, DB_TXN *, DB_LSN *,
01766  * PUBLIC:     u_int32_t, db_ca_mode, db_pgno_t, db_pgno_t, db_pgno_t,
01767  * PUBLIC:     u_int32_t, u_int32_t, u_int32_t));
01768  */
01769 int
01770 __bam_curadj_log(dbp, txnid, ret_lsnp, flags, mode, from_pgno, to_pgno, left_pgno, first_indx,
01771     from_indx, to_indx)
01772         DB *dbp;
01773         DB_TXN *txnid;
01774         DB_LSN *ret_lsnp;
01775         u_int32_t flags;
01776         db_ca_mode mode;
01777         db_pgno_t from_pgno;
01778         db_pgno_t to_pgno;
01779         db_pgno_t left_pgno;
01780         u_int32_t first_indx;
01781         u_int32_t from_indx;
01782         u_int32_t to_indx;
01783 {
01784         DBT logrec;
01785         DB_ENV *dbenv;
01786         DB_TXNLOGREC *lr;
01787         DB_LSN *lsnp, null_lsn, *rlsnp;
01788         u_int32_t uinttmp, rectype, txn_num;
01789         u_int npad;
01790         u_int8_t *bp;
01791         int is_durable, ret;
01792 
01793         dbenv = dbp->dbenv;
01794         COMPQUIET(lr, NULL);
01795 
01796         rectype = DB___bam_curadj;
01797         npad = 0;
01798         rlsnp = ret_lsnp;
01799 
01800         ret = 0;
01801 
01802         if (LF_ISSET(DB_LOG_NOT_DURABLE) ||
01803             F_ISSET(dbp, DB_AM_NOT_DURABLE)) {
01804                 is_durable = 0;
01805         } else
01806                 is_durable = 1;
01807 
01808         if (txnid == NULL) {
01809                 txn_num = 0;
01810                 lsnp = &null_lsn;
01811                 null_lsn.file = null_lsn.offset = 0;
01812         } else {
01813                 if (TAILQ_FIRST(&txnid->kids) != NULL &&
01814                     (ret = __txn_activekids(dbenv, rectype, txnid)) != 0)
01815                         return (ret);
01816                 /*
01817                  * We need to assign begin_lsn while holding region mutex.
01818                  * That assignment is done inside the DbEnv->log_put call,
01819                  * so pass in the appropriate memory location to be filled
01820                  * in by the log_put code.
01821                  */
01822                 DB_SET_TXN_LSNP(txnid, &rlsnp, &lsnp);
01823                 txn_num = txnid->txnid;
01824         }
01825 
01826         DB_ASSERT(dbp->log_filename != NULL);
01827         if (dbp->log_filename->id == DB_LOGFILEID_INVALID &&
01828             (ret = __dbreg_lazy_id(dbp)) != 0)
01829                 return (ret);
01830 
01831         logrec.size = sizeof(rectype) + sizeof(txn_num) + sizeof(DB_LSN)
01832             + sizeof(u_int32_t)
01833             + sizeof(u_int32_t)
01834             + sizeof(u_int32_t)
01835             + sizeof(u_int32_t)
01836             + sizeof(u_int32_t)
01837             + sizeof(u_int32_t)
01838             + sizeof(u_int32_t)
01839             + sizeof(u_int32_t);
01840         if (CRYPTO_ON(dbenv)) {
01841                 npad =
01842                     ((DB_CIPHER *)dbenv->crypto_handle)->adj_size(logrec.size);
01843                 logrec.size += npad;
01844         }
01845 
01846         if (is_durable || txnid == NULL) {
01847                 if ((ret =
01848                     __os_malloc(dbenv, logrec.size, &logrec.data)) != 0)
01849                         return (ret);
01850         } else {
01851                 if ((ret = __os_malloc(dbenv,
01852                     logrec.size + sizeof(DB_TXNLOGREC), &lr)) != 0)
01853                         return (ret);
01854 #ifdef DIAGNOSTIC
01855                 if ((ret =
01856                     __os_malloc(dbenv, logrec.size, &logrec.data)) != 0) {
01857                         __os_free(dbenv, lr);
01858                         return (ret);
01859                 }
01860 #else
01861                 logrec.data = lr->data;
01862 #endif
01863         }
01864         if (npad > 0)
01865                 memset((u_int8_t *)logrec.data + logrec.size - npad, 0, npad);
01866 
01867         bp = logrec.data;
01868 
01869         memcpy(bp, &rectype, sizeof(rectype));
01870         bp += sizeof(rectype);
01871 
01872         memcpy(bp, &txn_num, sizeof(txn_num));
01873         bp += sizeof(txn_num);
01874 
01875         memcpy(bp, lsnp, sizeof(DB_LSN));
01876         bp += sizeof(DB_LSN);
01877 
01878         uinttmp = (u_int32_t)dbp->log_filename->id;
01879         memcpy(bp, &uinttmp, sizeof(uinttmp));
01880         bp += sizeof(uinttmp);
01881 
01882         uinttmp = (u_int32_t)mode;
01883         memcpy(bp, &uinttmp, sizeof(uinttmp));
01884         bp += sizeof(uinttmp);
01885 
01886         uinttmp = (u_int32_t)from_pgno;
01887         memcpy(bp, &uinttmp, sizeof(uinttmp));
01888         bp += sizeof(uinttmp);
01889 
01890         uinttmp = (u_int32_t)to_pgno;
01891         memcpy(bp, &uinttmp, sizeof(uinttmp));
01892         bp += sizeof(uinttmp);
01893 
01894         uinttmp = (u_int32_t)left_pgno;
01895         memcpy(bp, &uinttmp, sizeof(uinttmp));
01896         bp += sizeof(uinttmp);
01897 
01898         uinttmp = (u_int32_t)first_indx;
01899         memcpy(bp, &uinttmp, sizeof(uinttmp));
01900         bp += sizeof(uinttmp);
01901 
01902         uinttmp = (u_int32_t)from_indx;
01903         memcpy(bp, &uinttmp, sizeof(uinttmp));
01904         bp += sizeof(uinttmp);
01905 
01906         uinttmp = (u_int32_t)to_indx;
01907         memcpy(bp, &uinttmp, sizeof(uinttmp));
01908         bp += sizeof(uinttmp);
01909 
01910         DB_ASSERT((u_int32_t)(bp - (u_int8_t *)logrec.data) <= logrec.size);
01911 
01912         if (is_durable || txnid == NULL) {
01913                 if ((ret = __log_put(dbenv, rlsnp,(DBT *)&logrec,
01914                     flags | DB_LOG_NOCOPY)) == 0 && txnid != NULL) {
01915                         *lsnp = *rlsnp;
01916                         if (rlsnp != ret_lsnp)
01917                                  *ret_lsnp = *rlsnp;
01918                 }
01919         } else {
01920 #ifdef DIAGNOSTIC
01921                 /*
01922                  * Set the debug bit if we are going to log non-durable
01923                  * transactions so they will be ignored by recovery.
01924                  */
01925                 memcpy(lr->data, logrec.data, logrec.size);
01926                 rectype |= DB_debug_FLAG;
01927                 memcpy(logrec.data, &rectype, sizeof(rectype));
01928 
01929                 ret = __log_put(dbenv,
01930                     rlsnp, (DBT *)&logrec, flags | DB_LOG_NOCOPY);
01931 #else
01932                 ret = 0;
01933 #endif
01934                 STAILQ_INSERT_HEAD(&txnid->logs, lr, links);
01935                 F_SET((TXN_DETAIL *)txnid->td, TXN_DTL_INMEMORY);
01936                 LSN_NOT_LOGGED(*ret_lsnp);
01937         }
01938 
01939 #ifdef LOG_DIAGNOSTIC
01940         if (ret != 0)
01941                 (void)__bam_curadj_print(dbenv,
01942                     (DBT *)&logrec, ret_lsnp, DB_TXN_PRINT, NULL);
01943 #endif
01944 
01945 #ifdef DIAGNOSTIC
01946         __os_free(dbenv, logrec.data);
01947 #else
01948         if (is_durable || txnid == NULL)
01949                 __os_free(dbenv, logrec.data);
01950 #endif
01951         return (ret);
01952 }
01953 
01954 /*
01955  * PUBLIC: int __bam_curadj_read __P((DB_ENV *, void *, __bam_curadj_args **));
01956  */
01957 int
01958 __bam_curadj_read(dbenv, recbuf, argpp)
01959         DB_ENV *dbenv;
01960         void *recbuf;
01961         __bam_curadj_args **argpp;
01962 {
01963         __bam_curadj_args *argp;
01964         u_int32_t uinttmp;
01965         u_int8_t *bp;
01966         int ret;
01967 
01968         if ((ret = __os_malloc(dbenv,
01969             sizeof(__bam_curadj_args) + sizeof(DB_TXN), &argp)) != 0)
01970                 return (ret);
01971         bp = recbuf;
01972         argp->txnid = (DB_TXN *)&argp[1];
01973 
01974         memcpy(&argp->type, bp, sizeof(argp->type));
01975         bp += sizeof(argp->type);
01976 
01977         memcpy(&argp->txnid->txnid,  bp, sizeof(argp->txnid->txnid));
01978         bp += sizeof(argp->txnid->txnid);
01979 
01980         memcpy(&argp->prev_lsn, bp, sizeof(DB_LSN));
01981         bp += sizeof(DB_LSN);
01982 
01983         memcpy(&uinttmp, bp, sizeof(uinttmp));
01984         argp->fileid = (int32_t)uinttmp;
01985         bp += sizeof(uinttmp);
01986 
01987         memcpy(&uinttmp, bp, sizeof(uinttmp));
01988         argp->mode = (db_ca_mode)uinttmp;
01989         bp += sizeof(uinttmp);
01990 
01991         memcpy(&uinttmp, bp, sizeof(uinttmp));
01992         argp->from_pgno = (db_pgno_t)uinttmp;
01993         bp += sizeof(uinttmp);
01994 
01995         memcpy(&uinttmp, bp, sizeof(uinttmp));
01996         argp->to_pgno = (db_pgno_t)uinttmp;
01997         bp += sizeof(uinttmp);
01998 
01999         memcpy(&uinttmp, bp, sizeof(uinttmp));
02000         argp->left_pgno = (db_pgno_t)uinttmp;
02001         bp += sizeof(uinttmp);
02002 
02003         memcpy(&uinttmp, bp, sizeof(uinttmp));
02004         argp->first_indx = (u_int32_t)uinttmp;
02005         bp += sizeof(uinttmp);
02006 
02007         memcpy(&uinttmp, bp, sizeof(uinttmp));
02008         argp->from_indx = (u_int32_t)uinttmp;
02009         bp += sizeof(uinttmp);
02010 
02011         memcpy(&uinttmp, bp, sizeof(uinttmp));
02012         argp->to_indx = (u_int32_t)uinttmp;
02013         bp += sizeof(uinttmp);
02014 
02015         *argpp = argp;
02016         return (0);
02017 }
02018 
02019 /*
02020  * PUBLIC: int __bam_rcuradj_log __P((DB *, DB_TXN *, DB_LSN *,
02021  * PUBLIC:     u_int32_t, ca_recno_arg, db_pgno_t, db_recno_t, u_int32_t));
02022  */
02023 int
02024 __bam_rcuradj_log(dbp, txnid, ret_lsnp, flags, mode, root, recno, order)
02025         DB *dbp;
02026         DB_TXN *txnid;
02027         DB_LSN *ret_lsnp;
02028         u_int32_t flags;
02029         ca_recno_arg mode;
02030         db_pgno_t root;
02031         db_recno_t recno;
02032         u_int32_t order;
02033 {
02034         DBT logrec;
02035         DB_ENV *dbenv;
02036         DB_TXNLOGREC *lr;
02037         DB_LSN *lsnp, null_lsn, *rlsnp;
02038         u_int32_t uinttmp, rectype, txn_num;
02039         u_int npad;
02040         u_int8_t *bp;
02041         int is_durable, ret;
02042 
02043         dbenv = dbp->dbenv;
02044         COMPQUIET(lr, NULL);
02045 
02046         rectype = DB___bam_rcuradj;
02047         npad = 0;
02048         rlsnp = ret_lsnp;
02049 
02050         ret = 0;
02051 
02052         if (LF_ISSET(DB_LOG_NOT_DURABLE) ||
02053             F_ISSET(dbp, DB_AM_NOT_DURABLE)) {
02054                 is_durable = 0;
02055         } else
02056                 is_durable = 1;
02057 
02058         if (txnid == NULL) {
02059                 txn_num = 0;
02060                 lsnp = &null_lsn;
02061                 null_lsn.file = null_lsn.offset = 0;
02062         } else {
02063                 if (TAILQ_FIRST(&txnid->kids) != NULL &&
02064                     (ret = __txn_activekids(dbenv, rectype, txnid)) != 0)
02065                         return (ret);
02066                 /*
02067                  * We need to assign begin_lsn while holding region mutex.
02068                  * That assignment is done inside the DbEnv->log_put call,
02069                  * so pass in the appropriate memory location to be filled
02070                  * in by the log_put code.
02071                  */
02072                 DB_SET_TXN_LSNP(txnid, &rlsnp, &lsnp);
02073                 txn_num = txnid->txnid;
02074         }
02075 
02076         DB_ASSERT(dbp->log_filename != NULL);
02077         if (dbp->log_filename->id == DB_LOGFILEID_INVALID &&
02078             (ret = __dbreg_lazy_id(dbp)) != 0)
02079                 return (ret);
02080 
02081         logrec.size = sizeof(rectype) + sizeof(txn_num) + sizeof(DB_LSN)
02082             + sizeof(u_int32_t)
02083             + sizeof(u_int32_t)
02084             + sizeof(u_int32_t)
02085             + sizeof(u_int32_t)
02086             + sizeof(u_int32_t);
02087         if (CRYPTO_ON(dbenv)) {
02088                 npad =
02089                     ((DB_CIPHER *)dbenv->crypto_handle)->adj_size(logrec.size);
02090                 logrec.size += npad;
02091         }
02092 
02093         if (is_durable || txnid == NULL) {
02094                 if ((ret =
02095                     __os_malloc(dbenv, logrec.size, &logrec.data)) != 0)
02096                         return (ret);
02097         } else {
02098                 if ((ret = __os_malloc(dbenv,
02099                     logrec.size + sizeof(DB_TXNLOGREC), &lr)) != 0)
02100                         return (ret);
02101 #ifdef DIAGNOSTIC
02102                 if ((ret =
02103                     __os_malloc(dbenv, logrec.size, &logrec.data)) != 0) {
02104                         __os_free(dbenv, lr);
02105                         return (ret);
02106                 }
02107 #else
02108                 logrec.data = lr->data;
02109 #endif
02110         }
02111         if (npad > 0)
02112                 memset((u_int8_t *)logrec.data + logrec.size - npad, 0, npad);
02113 
02114         bp = logrec.data;
02115 
02116         memcpy(bp, &rectype, sizeof(rectype));
02117         bp += sizeof(rectype);
02118 
02119         memcpy(bp, &txn_num, sizeof(txn_num));
02120         bp += sizeof(txn_num);
02121 
02122         memcpy(bp, lsnp, sizeof(DB_LSN));
02123         bp += sizeof(DB_LSN);
02124 
02125         uinttmp = (u_int32_t)dbp->log_filename->id;
02126         memcpy(bp, &uinttmp, sizeof(uinttmp));
02127         bp += sizeof(uinttmp);
02128 
02129         uinttmp = (u_int32_t)mode;
02130         memcpy(bp, &uinttmp, sizeof(uinttmp));
02131         bp += sizeof(uinttmp);
02132 
02133         uinttmp = (u_int32_t)root;
02134         memcpy(bp, &uinttmp, sizeof(uinttmp));
02135         bp += sizeof(uinttmp);
02136 
02137         uinttmp = (u_int32_t)recno;
02138         memcpy(bp, &uinttmp, sizeof(uinttmp));
02139         bp += sizeof(uinttmp);
02140 
02141         uinttmp = (u_int32_t)order;
02142         memcpy(bp, &uinttmp, sizeof(uinttmp));
02143         bp += sizeof(uinttmp);
02144 
02145         DB_ASSERT((u_int32_t)(bp - (u_int8_t *)logrec.data) <= logrec.size);
02146 
02147         if (is_durable || txnid == NULL) {
02148                 if ((ret = __log_put(dbenv, rlsnp,(DBT *)&logrec,
02149                     flags | DB_LOG_NOCOPY)) == 0 && txnid != NULL) {
02150                         *lsnp = *rlsnp;
02151                         if (rlsnp != ret_lsnp)
02152                                  *ret_lsnp = *rlsnp;
02153                 }
02154         } else {
02155 #ifdef DIAGNOSTIC
02156                 /*
02157                  * Set the debug bit if we are going to log non-durable
02158                  * transactions so they will be ignored by recovery.
02159                  */
02160                 memcpy(lr->data, logrec.data, logrec.size);
02161                 rectype |= DB_debug_FLAG;
02162                 memcpy(logrec.data, &rectype, sizeof(rectype));
02163 
02164                 ret = __log_put(dbenv,
02165                     rlsnp, (DBT *)&logrec, flags | DB_LOG_NOCOPY);
02166 #else
02167                 ret = 0;
02168 #endif
02169                 STAILQ_INSERT_HEAD(&txnid->logs, lr, links);
02170                 F_SET((TXN_DETAIL *)txnid->td, TXN_DTL_INMEMORY);
02171                 LSN_NOT_LOGGED(*ret_lsnp);
02172         }
02173 
02174 #ifdef LOG_DIAGNOSTIC
02175         if (ret != 0)
02176                 (void)__bam_rcuradj_print(dbenv,
02177                     (DBT *)&logrec, ret_lsnp, DB_TXN_PRINT, NULL);
02178 #endif
02179 
02180 #ifdef DIAGNOSTIC
02181         __os_free(dbenv, logrec.data);
02182 #else
02183         if (is_durable || txnid == NULL)
02184                 __os_free(dbenv, logrec.data);
02185 #endif
02186         return (ret);
02187 }
02188 
02189 /*
02190  * PUBLIC: int __bam_rcuradj_read __P((DB_ENV *, void *,
02191  * PUBLIC:     __bam_rcuradj_args **));
02192  */
02193 int
02194 __bam_rcuradj_read(dbenv, recbuf, argpp)
02195         DB_ENV *dbenv;
02196         void *recbuf;
02197         __bam_rcuradj_args **argpp;
02198 {
02199         __bam_rcuradj_args *argp;
02200         u_int32_t uinttmp;
02201         u_int8_t *bp;
02202         int ret;
02203 
02204         if ((ret = __os_malloc(dbenv,
02205             sizeof(__bam_rcuradj_args) + sizeof(DB_TXN), &argp)) != 0)
02206                 return (ret);
02207         bp = recbuf;
02208         argp->txnid = (DB_TXN *)&argp[1];
02209 
02210         memcpy(&argp->type, bp, sizeof(argp->type));
02211         bp += sizeof(argp->type);
02212 
02213         memcpy(&argp->txnid->txnid,  bp, sizeof(argp->txnid->txnid));
02214         bp += sizeof(argp->txnid->txnid);
02215 
02216         memcpy(&argp->prev_lsn, bp, sizeof(DB_LSN));
02217         bp += sizeof(DB_LSN);
02218 
02219         memcpy(&uinttmp, bp, sizeof(uinttmp));
02220         argp->fileid = (int32_t)uinttmp;
02221         bp += sizeof(uinttmp);
02222 
02223         memcpy(&uinttmp, bp, sizeof(uinttmp));
02224         argp->mode = (ca_recno_arg)uinttmp;
02225         bp += sizeof(uinttmp);
02226 
02227         memcpy(&uinttmp, bp, sizeof(uinttmp));
02228         argp->root = (db_pgno_t)uinttmp;
02229         bp += sizeof(uinttmp);
02230 
02231         memcpy(&uinttmp, bp, sizeof(uinttmp));
02232         argp->recno = (db_recno_t)uinttmp;
02233         bp += sizeof(uinttmp);
02234 
02235         memcpy(&uinttmp, bp, sizeof(uinttmp));
02236         argp->order = (u_int32_t)uinttmp;
02237         bp += sizeof(uinttmp);
02238 
02239         *argpp = argp;
02240         return (0);
02241 }
02242 
02243 /*
02244  * PUBLIC: int __bam_relink_log __P((DB *, DB_TXN *, DB_LSN *,
02245  * PUBLIC:     u_int32_t, db_pgno_t, db_pgno_t, db_pgno_t, DB_LSN *, db_pgno_t,
02246  * PUBLIC:     DB_LSN *));
02247  */
02248 int
02249 __bam_relink_log(dbp, txnid, ret_lsnp, flags, pgno, new_pgno, prev, lsn_prev, next,
02250     lsn_next)
02251         DB *dbp;
02252         DB_TXN *txnid;
02253         DB_LSN *ret_lsnp;
02254         u_int32_t flags;
02255         db_pgno_t pgno;
02256         db_pgno_t new_pgno;
02257         db_pgno_t prev;
02258         DB_LSN * lsn_prev;
02259         db_pgno_t next;
02260         DB_LSN * lsn_next;
02261 {
02262         DBT logrec;
02263         DB_ENV *dbenv;
02264         DB_TXNLOGREC *lr;
02265         DB_LSN *lsnp, null_lsn, *rlsnp;
02266         u_int32_t uinttmp, rectype, txn_num;
02267         u_int npad;
02268         u_int8_t *bp;
02269         int is_durable, ret;
02270 
02271         dbenv = dbp->dbenv;
02272         COMPQUIET(lr, NULL);
02273 
02274         rectype = DB___bam_relink;
02275         npad = 0;
02276         rlsnp = ret_lsnp;
02277 
02278         ret = 0;
02279 
02280         if (LF_ISSET(DB_LOG_NOT_DURABLE) ||
02281             F_ISSET(dbp, DB_AM_NOT_DURABLE)) {
02282                 is_durable = 0;
02283         } else
02284                 is_durable = 1;
02285 
02286         if (txnid == NULL) {
02287                 txn_num = 0;
02288                 lsnp = &null_lsn;
02289                 null_lsn.file = null_lsn.offset = 0;
02290         } else {
02291                 if (TAILQ_FIRST(&txnid->kids) != NULL &&
02292                     (ret = __txn_activekids(dbenv, rectype, txnid)) != 0)
02293                         return (ret);
02294                 /*
02295                  * We need to assign begin_lsn while holding region mutex.
02296                  * That assignment is done inside the DbEnv->log_put call,
02297                  * so pass in the appropriate memory location to be filled
02298                  * in by the log_put code.
02299                  */
02300                 DB_SET_TXN_LSNP(txnid, &rlsnp, &lsnp);
02301                 txn_num = txnid->txnid;
02302         }
02303 
02304         DB_ASSERT(dbp->log_filename != NULL);
02305         if (dbp->log_filename->id == DB_LOGFILEID_INVALID &&
02306             (ret = __dbreg_lazy_id(dbp)) != 0)
02307                 return (ret);
02308 
02309         logrec.size = sizeof(rectype) + sizeof(txn_num) + sizeof(DB_LSN)
02310             + sizeof(u_int32_t)
02311             + sizeof(u_int32_t)
02312             + sizeof(u_int32_t)
02313             + sizeof(u_int32_t)
02314             + sizeof(*lsn_prev)
02315             + sizeof(u_int32_t)
02316             + sizeof(*lsn_next);
02317         if (CRYPTO_ON(dbenv)) {
02318                 npad =
02319                     ((DB_CIPHER *)dbenv->crypto_handle)->adj_size(logrec.size);
02320                 logrec.size += npad;
02321         }
02322 
02323         if (is_durable || txnid == NULL) {
02324                 if ((ret =
02325                     __os_malloc(dbenv, logrec.size, &logrec.data)) != 0)
02326                         return (ret);
02327         } else {
02328                 if ((ret = __os_malloc(dbenv,
02329                     logrec.size + sizeof(DB_TXNLOGREC), &lr)) != 0)
02330                         return (ret);
02331 #ifdef DIAGNOSTIC
02332                 if ((ret =
02333                     __os_malloc(dbenv, logrec.size, &logrec.data)) != 0) {
02334                         __os_free(dbenv, lr);
02335                         return (ret);
02336                 }
02337 #else
02338                 logrec.data = lr->data;
02339 #endif
02340         }
02341         if (npad > 0)
02342                 memset((u_int8_t *)logrec.data + logrec.size - npad, 0, npad);
02343 
02344         bp = logrec.data;
02345 
02346         memcpy(bp, &rectype, sizeof(rectype));
02347         bp += sizeof(rectype);
02348 
02349         memcpy(bp, &txn_num, sizeof(txn_num));
02350         bp += sizeof(txn_num);
02351 
02352         memcpy(bp, lsnp, sizeof(DB_LSN));
02353         bp += sizeof(DB_LSN);
02354 
02355         uinttmp = (u_int32_t)dbp->log_filename->id;
02356         memcpy(bp, &uinttmp, sizeof(uinttmp));
02357         bp += sizeof(uinttmp);
02358 
02359         uinttmp = (u_int32_t)pgno;
02360         memcpy(bp, &uinttmp, sizeof(uinttmp));
02361         bp += sizeof(uinttmp);
02362 
02363         uinttmp = (u_int32_t)new_pgno;
02364         memcpy(bp, &uinttmp, sizeof(uinttmp));
02365         bp += sizeof(uinttmp);
02366 
02367         uinttmp = (u_int32_t)prev;
02368         memcpy(bp, &uinttmp, sizeof(uinttmp));
02369         bp += sizeof(uinttmp);
02370 
02371         if (lsn_prev != NULL)
02372                 memcpy(bp, lsn_prev, sizeof(*lsn_prev));
02373         else
02374                 memset(bp, 0, sizeof(*lsn_prev));
02375         bp += sizeof(*lsn_prev);
02376 
02377         uinttmp = (u_int32_t)next;
02378         memcpy(bp, &uinttmp, sizeof(uinttmp));
02379         bp += sizeof(uinttmp);
02380 
02381         if (lsn_next != NULL)
02382                 memcpy(bp, lsn_next, sizeof(*lsn_next));
02383         else
02384                 memset(bp, 0, sizeof(*lsn_next));
02385         bp += sizeof(*lsn_next);
02386 
02387         DB_ASSERT((u_int32_t)(bp - (u_int8_t *)logrec.data) <= logrec.size);
02388 
02389         if (is_durable || txnid == NULL) {
02390                 if ((ret = __log_put(dbenv, rlsnp,(DBT *)&logrec,
02391                     flags | DB_LOG_NOCOPY)) == 0 && txnid != NULL) {
02392                         *lsnp = *rlsnp;
02393                         if (rlsnp != ret_lsnp)
02394                                  *ret_lsnp = *rlsnp;
02395                 }
02396         } else {
02397 #ifdef DIAGNOSTIC
02398                 /*
02399                  * Set the debug bit if we are going to log non-durable
02400                  * transactions so they will be ignored by recovery.
02401                  */
02402                 memcpy(lr->data, logrec.data, logrec.size);
02403                 rectype |= DB_debug_FLAG;
02404                 memcpy(logrec.data, &rectype, sizeof(rectype));
02405 
02406                 ret = __log_put(dbenv,
02407                     rlsnp, (DBT *)&logrec, flags | DB_LOG_NOCOPY);
02408 #else
02409                 ret = 0;
02410 #endif
02411                 STAILQ_INSERT_HEAD(&txnid->logs, lr, links);
02412                 F_SET((TXN_DETAIL *)txnid->td, TXN_DTL_INMEMORY);
02413                 LSN_NOT_LOGGED(*ret_lsnp);
02414         }
02415 
02416 #ifdef LOG_DIAGNOSTIC
02417         if (ret != 0)
02418                 (void)__bam_relink_print(dbenv,
02419                     (DBT *)&logrec, ret_lsnp, DB_TXN_PRINT, NULL);
02420 #endif
02421 
02422 #ifdef DIAGNOSTIC
02423         __os_free(dbenv, logrec.data);
02424 #else
02425         if (is_durable || txnid == NULL)
02426                 __os_free(dbenv, logrec.data);
02427 #endif
02428         return (ret);
02429 }
02430 
02431 /*
02432  * PUBLIC: int __bam_relink_read __P((DB_ENV *, void *, __bam_relink_args **));
02433  */
02434 int
02435 __bam_relink_read(dbenv, recbuf, argpp)
02436         DB_ENV *dbenv;
02437         void *recbuf;
02438         __bam_relink_args **argpp;
02439 {
02440         __bam_relink_args *argp;
02441         u_int32_t uinttmp;
02442         u_int8_t *bp;
02443         int ret;
02444 
02445         if ((ret = __os_malloc(dbenv,
02446             sizeof(__bam_relink_args) + sizeof(DB_TXN), &argp)) != 0)
02447                 return (ret);
02448         bp = recbuf;
02449         argp->txnid = (DB_TXN *)&argp[1];
02450 
02451         memcpy(&argp->type, bp, sizeof(argp->type));
02452         bp += sizeof(argp->type);
02453 
02454         memcpy(&argp->txnid->txnid,  bp, sizeof(argp->txnid->txnid));
02455         bp += sizeof(argp->txnid->txnid);
02456 
02457         memcpy(&argp->prev_lsn, bp, sizeof(DB_LSN));
02458         bp += sizeof(DB_LSN);
02459 
02460         memcpy(&uinttmp, bp, sizeof(uinttmp));
02461         argp->fileid = (int32_t)uinttmp;
02462         bp += sizeof(uinttmp);
02463 
02464         memcpy(&uinttmp, bp, sizeof(uinttmp));
02465         argp->pgno = (db_pgno_t)uinttmp;
02466         bp += sizeof(uinttmp);
02467 
02468         memcpy(&uinttmp, bp, sizeof(uinttmp));
02469         argp->new_pgno = (db_pgno_t)uinttmp;
02470         bp += sizeof(uinttmp);
02471 
02472         memcpy(&uinttmp, bp, sizeof(uinttmp));
02473         argp->prev = (db_pgno_t)uinttmp;
02474         bp += sizeof(uinttmp);
02475 
02476         memcpy(&argp->lsn_prev, bp,  sizeof(argp->lsn_prev));
02477         bp += sizeof(argp->lsn_prev);
02478 
02479         memcpy(&uinttmp, bp, sizeof(uinttmp));
02480         argp->next = (db_pgno_t)uinttmp;
02481         bp += sizeof(uinttmp);
02482 
02483         memcpy(&argp->lsn_next, bp,  sizeof(argp->lsn_next));
02484         bp += sizeof(argp->lsn_next);
02485 
02486         *argpp = argp;
02487         return (0);
02488 }
02489 
02490 /*
02491  * PUBLIC: int __bam_merge_log __P((DB *, DB_TXN *, DB_LSN *,
02492  * PUBLIC:     u_int32_t, db_pgno_t, DB_LSN *, db_pgno_t, DB_LSN *, const DBT *,
02493  * PUBLIC:     const DBT *, const DBT *));
02494  */
02495 int
02496 __bam_merge_log(dbp, txnid, ret_lsnp, flags, pgno, lsn, npgno, nlsn, hdr,
02497     data, ind)
02498         DB *dbp;
02499         DB_TXN *txnid;
02500         DB_LSN *ret_lsnp;
02501         u_int32_t flags;
02502         db_pgno_t pgno;
02503         DB_LSN * lsn;
02504         db_pgno_t npgno;
02505         DB_LSN * nlsn;
02506         const DBT *hdr;
02507         const DBT *data;
02508         const DBT *ind;
02509 {
02510         DBT logrec;
02511         DB_ENV *dbenv;
02512         DB_TXNLOGREC *lr;
02513         DB_LSN *lsnp, null_lsn, *rlsnp;
02514         u_int32_t zero, uinttmp, rectype, txn_num;
02515         u_int npad;
02516         u_int8_t *bp;
02517         int is_durable, ret;
02518 
02519         dbenv = dbp->dbenv;
02520         COMPQUIET(lr, NULL);
02521 
02522         rectype = DB___bam_merge;
02523         npad = 0;
02524         rlsnp = ret_lsnp;
02525 
02526         ret = 0;
02527 
02528         if (LF_ISSET(DB_LOG_NOT_DURABLE) ||
02529             F_ISSET(dbp, DB_AM_NOT_DURABLE)) {
02530                 is_durable = 0;
02531         } else
02532                 is_durable = 1;
02533 
02534         if (txnid == NULL) {
02535                 txn_num = 0;
02536                 lsnp = &null_lsn;
02537                 null_lsn.file = null_lsn.offset = 0;
02538         } else {
02539                 if (TAILQ_FIRST(&txnid->kids) != NULL &&
02540                     (ret = __txn_activekids(dbenv, rectype, txnid)) != 0)
02541                         return (ret);
02542                 /*
02543                  * We need to assign begin_lsn while holding region mutex.
02544                  * That assignment is done inside the DbEnv->log_put call,
02545                  * so pass in the appropriate memory location to be filled
02546                  * in by the log_put code.
02547                  */
02548                 DB_SET_TXN_LSNP(txnid, &rlsnp, &lsnp);
02549                 txn_num = txnid->txnid;
02550         }
02551 
02552         DB_ASSERT(dbp->log_filename != NULL);
02553         if (dbp->log_filename->id == DB_LOGFILEID_INVALID &&
02554             (ret = __dbreg_lazy_id(dbp)) != 0)
02555                 return (ret);
02556 
02557         logrec.size = sizeof(rectype) + sizeof(txn_num) + sizeof(DB_LSN)
02558             + sizeof(u_int32_t)
02559             + sizeof(u_int32_t)
02560             + sizeof(*lsn)
02561             + sizeof(u_int32_t)
02562             + sizeof(*nlsn)
02563             + sizeof(u_int32_t) + (hdr == NULL ? 0 : hdr->size)
02564             + sizeof(u_int32_t) + (data == NULL ? 0 : data->size)
02565             + sizeof(u_int32_t) + (ind == NULL ? 0 : ind->size);
02566         if (CRYPTO_ON(dbenv)) {
02567                 npad =
02568                     ((DB_CIPHER *)dbenv->crypto_handle)->adj_size(logrec.size);
02569                 logrec.size += npad;
02570         }
02571 
02572         if (is_durable || txnid == NULL) {
02573                 if ((ret =
02574                     __os_malloc(dbenv, logrec.size, &logrec.data)) != 0)
02575                         return (ret);
02576         } else {
02577                 if ((ret = __os_malloc(dbenv,
02578                     logrec.size + sizeof(DB_TXNLOGREC), &lr)) != 0)
02579                         return (ret);
02580 #ifdef DIAGNOSTIC
02581                 if ((ret =
02582                     __os_malloc(dbenv, logrec.size, &logrec.data)) != 0) {
02583                         __os_free(dbenv, lr);
02584                         return (ret);
02585                 }
02586 #else
02587                 logrec.data = lr->data;
02588 #endif
02589         }
02590         if (npad > 0)
02591                 memset((u_int8_t *)logrec.data + logrec.size - npad, 0, npad);
02592 
02593         bp = logrec.data;
02594 
02595         memcpy(bp, &rectype, sizeof(rectype));
02596         bp += sizeof(rectype);
02597 
02598         memcpy(bp, &txn_num, sizeof(txn_num));
02599         bp += sizeof(txn_num);
02600 
02601         memcpy(bp, lsnp, sizeof(DB_LSN));
02602         bp += sizeof(DB_LSN);
02603 
02604         uinttmp = (u_int32_t)dbp->log_filename->id;
02605         memcpy(bp, &uinttmp, sizeof(uinttmp));
02606         bp += sizeof(uinttmp);
02607 
02608         uinttmp = (u_int32_t)pgno;
02609         memcpy(bp, &uinttmp, sizeof(uinttmp));
02610         bp += sizeof(uinttmp);
02611 
02612         if (lsn != NULL)
02613                 memcpy(bp, lsn, sizeof(*lsn));
02614         else
02615                 memset(bp, 0, sizeof(*lsn));
02616         bp += sizeof(*lsn);
02617 
02618         uinttmp = (u_int32_t)npgno;
02619         memcpy(bp, &uinttmp, sizeof(uinttmp));
02620         bp += sizeof(uinttmp);
02621 
02622         if (nlsn != NULL)
02623                 memcpy(bp, nlsn, sizeof(*nlsn));
02624         else
02625                 memset(bp, 0, sizeof(*nlsn));
02626         bp += sizeof(*nlsn);
02627 
02628         if (hdr == NULL) {
02629                 zero = 0;
02630                 memcpy(bp, &zero, sizeof(u_int32_t));
02631                 bp += sizeof(u_int32_t);
02632         } else {
02633                 memcpy(bp, &hdr->size, sizeof(hdr->size));
02634                 bp += sizeof(hdr->size);
02635                 memcpy(bp, hdr->data, hdr->size);
02636                 bp += hdr->size;
02637         }
02638 
02639         if (data == NULL) {
02640                 zero = 0;
02641                 memcpy(bp, &zero, sizeof(u_int32_t));
02642                 bp += sizeof(u_int32_t);
02643         } else {
02644                 memcpy(bp, &data->size, sizeof(data->size));
02645                 bp += sizeof(data->size);
02646                 memcpy(bp, data->data, data->size);
02647                 bp += data->size;
02648         }
02649 
02650         if (ind == NULL) {
02651                 zero = 0;
02652                 memcpy(bp, &zero, sizeof(u_int32_t));
02653                 bp += sizeof(u_int32_t);
02654         } else {
02655                 memcpy(bp, &ind->size, sizeof(ind->size));
02656                 bp += sizeof(ind->size);
02657                 memcpy(bp, ind->data, ind->size);
02658                 bp += ind->size;
02659         }
02660 
02661         DB_ASSERT((u_int32_t)(bp - (u_int8_t *)logrec.data) <= logrec.size);
02662 
02663         if (is_durable || txnid == NULL) {
02664                 if ((ret = __log_put(dbenv, rlsnp,(DBT *)&logrec,
02665                     flags | DB_LOG_NOCOPY)) == 0 && txnid != NULL) {
02666                         *lsnp = *rlsnp;
02667                         if (rlsnp != ret_lsnp)
02668                                  *ret_lsnp = *rlsnp;
02669                 }
02670         } else {
02671 #ifdef DIAGNOSTIC
02672                 /*
02673                  * Set the debug bit if we are going to log non-durable
02674                  * transactions so they will be ignored by recovery.
02675                  */
02676                 memcpy(lr->data, logrec.data, logrec.size);
02677                 rectype |= DB_debug_FLAG;
02678                 memcpy(logrec.data, &rectype, sizeof(rectype));
02679 
02680                 ret = __log_put(dbenv,
02681                     rlsnp, (DBT *)&logrec, flags | DB_LOG_NOCOPY);
02682 #else
02683                 ret = 0;
02684 #endif
02685                 STAILQ_INSERT_HEAD(&txnid->logs, lr, links);
02686                 F_SET((TXN_DETAIL *)txnid->td, TXN_DTL_INMEMORY);
02687                 LSN_NOT_LOGGED(*ret_lsnp);
02688         }
02689 
02690 #ifdef LOG_DIAGNOSTIC
02691         if (ret != 0)
02692                 (void)__bam_merge_print(dbenv,
02693                     (DBT *)&logrec, ret_lsnp, DB_TXN_PRINT, NULL);
02694 #endif
02695 
02696 #ifdef DIAGNOSTIC
02697         __os_free(dbenv, logrec.data);
02698 #else
02699         if (is_durable || txnid == NULL)
02700                 __os_free(dbenv, logrec.data);
02701 #endif
02702         return (ret);
02703 }
02704 
02705 /*
02706  * PUBLIC: int __bam_merge_read __P((DB_ENV *, void *, __bam_merge_args **));
02707  */
02708 int
02709 __bam_merge_read(dbenv, recbuf, argpp)
02710         DB_ENV *dbenv;
02711         void *recbuf;
02712         __bam_merge_args **argpp;
02713 {
02714         __bam_merge_args *argp;
02715         u_int32_t uinttmp;
02716         u_int8_t *bp;
02717         int ret;
02718 
02719         if ((ret = __os_malloc(dbenv,
02720             sizeof(__bam_merge_args) + sizeof(DB_TXN), &argp)) != 0)
02721                 return (ret);
02722         bp = recbuf;
02723         argp->txnid = (DB_TXN *)&argp[1];
02724 
02725         memcpy(&argp->type, bp, sizeof(argp->type));
02726         bp += sizeof(argp->type);
02727 
02728         memcpy(&argp->txnid->txnid,  bp, sizeof(argp->txnid->txnid));
02729         bp += sizeof(argp->txnid->txnid);
02730 
02731         memcpy(&argp->prev_lsn, bp, sizeof(DB_LSN));
02732         bp += sizeof(DB_LSN);
02733 
02734         memcpy(&uinttmp, bp, sizeof(uinttmp));
02735         argp->fileid = (int32_t)uinttmp;
02736         bp += sizeof(uinttmp);
02737 
02738         memcpy(&uinttmp, bp, sizeof(uinttmp));
02739         argp->pgno = (db_pgno_t)uinttmp;
02740         bp += sizeof(uinttmp);
02741 
02742         memcpy(&argp->lsn, bp,  sizeof(argp->lsn));
02743         bp += sizeof(argp->lsn);
02744 
02745         memcpy(&uinttmp, bp, sizeof(uinttmp));
02746         argp->npgno = (db_pgno_t)uinttmp;
02747         bp += sizeof(uinttmp);
02748 
02749         memcpy(&argp->nlsn, bp,  sizeof(argp->nlsn));
02750         bp += sizeof(argp->nlsn);
02751 
02752         memset(&argp->hdr, 0, sizeof(argp->hdr));
02753         memcpy(&argp->hdr.size, bp, sizeof(u_int32_t));
02754         bp += sizeof(u_int32_t);
02755         argp->hdr.data = bp;
02756         bp += argp->hdr.size;
02757 
02758         memset(&argp->data, 0, sizeof(argp->data));
02759         memcpy(&argp->data.size, bp, sizeof(u_int32_t));
02760         bp += sizeof(u_int32_t);
02761         argp->data.data = bp;
02762         bp += argp->data.size;
02763 
02764         memset(&argp->ind, 0, sizeof(argp->ind));
02765         memcpy(&argp->ind.size, bp, sizeof(u_int32_t));
02766         bp += sizeof(u_int32_t);
02767         argp->ind.data = bp;
02768         bp += argp->ind.size;
02769 
02770         *argpp = argp;
02771         return (0);
02772 }
02773 
02774 /*
02775  * PUBLIC: int __bam_pgno_log __P((DB *, DB_TXN *, DB_LSN *,
02776  * PUBLIC:     u_int32_t, db_pgno_t, DB_LSN *, u_int32_t, db_pgno_t,
02777  * PUBLIC:     db_pgno_t));
02778  */
02779 int
02780 __bam_pgno_log(dbp, txnid, ret_lsnp, flags, pgno, lsn, indx, opgno, npgno)
02781         DB *dbp;
02782         DB_TXN *txnid;
02783         DB_LSN *ret_lsnp;
02784         u_int32_t flags;
02785         db_pgno_t pgno;
02786         DB_LSN * lsn;
02787         u_int32_t indx;
02788         db_pgno_t opgno;
02789         db_pgno_t npgno;
02790 {
02791         DBT logrec;
02792         DB_ENV *dbenv;
02793         DB_TXNLOGREC *lr;
02794         DB_LSN *lsnp, null_lsn, *rlsnp;
02795         u_int32_t uinttmp, rectype, txn_num;
02796         u_int npad;
02797         u_int8_t *bp;
02798         int is_durable, ret;
02799 
02800         dbenv = dbp->dbenv;
02801         COMPQUIET(lr, NULL);
02802 
02803         rectype = DB___bam_pgno;
02804         npad = 0;
02805         rlsnp = ret_lsnp;
02806 
02807         ret = 0;
02808 
02809         if (LF_ISSET(DB_LOG_NOT_DURABLE) ||
02810             F_ISSET(dbp, DB_AM_NOT_DURABLE)) {
02811                 is_durable = 0;
02812         } else
02813                 is_durable = 1;
02814 
02815         if (txnid == NULL) {
02816                 txn_num = 0;
02817                 lsnp = &null_lsn;
02818                 null_lsn.file = null_lsn.offset = 0;
02819         } else {
02820                 if (TAILQ_FIRST(&txnid->kids) != NULL &&
02821                     (ret = __txn_activekids(dbenv, rectype, txnid)) != 0)
02822                         return (ret);
02823                 /*
02824                  * We need to assign begin_lsn while holding region mutex.
02825                  * That assignment is done inside the DbEnv->log_put call,
02826                  * so pass in the appropriate memory location to be filled
02827                  * in by the log_put code.
02828                  */
02829                 DB_SET_TXN_LSNP(txnid, &rlsnp, &lsnp);
02830                 txn_num = txnid->txnid;
02831         }
02832 
02833         DB_ASSERT(dbp->log_filename != NULL);
02834         if (dbp->log_filename->id == DB_LOGFILEID_INVALID &&
02835             (ret = __dbreg_lazy_id(dbp)) != 0)
02836                 return (ret);
02837 
02838         logrec.size = sizeof(rectype) + sizeof(txn_num) + sizeof(DB_LSN)
02839             + sizeof(u_int32_t)
02840             + sizeof(u_int32_t)
02841             + sizeof(*lsn)
02842             + sizeof(u_int32_t)
02843             + sizeof(u_int32_t)
02844             + sizeof(u_int32_t);
02845         if (CRYPTO_ON(dbenv)) {
02846                 npad =
02847                     ((DB_CIPHER *)dbenv->crypto_handle)->adj_size(logrec.size);
02848                 logrec.size += npad;
02849         }
02850 
02851         if (is_durable || txnid == NULL) {
02852                 if ((ret =
02853                     __os_malloc(dbenv, logrec.size, &logrec.data)) != 0)
02854                         return (ret);
02855         } else {
02856                 if ((ret = __os_malloc(dbenv,
02857                     logrec.size + sizeof(DB_TXNLOGREC), &lr)) != 0)
02858                         return (ret);
02859 #ifdef DIAGNOSTIC
02860                 if ((ret =
02861                     __os_malloc(dbenv, logrec.size, &logrec.data)) != 0) {
02862                         __os_free(dbenv, lr);
02863                         return (ret);
02864                 }
02865 #else
02866                 logrec.data = lr->data;
02867 #endif
02868         }
02869         if (npad > 0)
02870                 memset((u_int8_t *)logrec.data + logrec.size - npad, 0, npad);
02871 
02872         bp = logrec.data;
02873 
02874         memcpy(bp, &rectype, sizeof(rectype));
02875         bp += sizeof(rectype);
02876 
02877         memcpy(bp, &txn_num, sizeof(txn_num));
02878         bp += sizeof(txn_num);
02879 
02880         memcpy(bp, lsnp, sizeof(DB_LSN));
02881         bp += sizeof(DB_LSN);
02882 
02883         uinttmp = (u_int32_t)dbp->log_filename->id;
02884         memcpy(bp, &uinttmp, sizeof(uinttmp));
02885         bp += sizeof(uinttmp);
02886 
02887         uinttmp = (u_int32_t)pgno;
02888         memcpy(bp, &uinttmp, sizeof(uinttmp));
02889         bp += sizeof(uinttmp);
02890 
02891         if (lsn != NULL)
02892                 memcpy(bp, lsn, sizeof(*lsn));
02893         else
02894                 memset(bp, 0, sizeof(*lsn));
02895         bp += sizeof(*lsn);
02896 
02897         uinttmp = (u_int32_t)indx;
02898         memcpy(bp, &uinttmp, sizeof(uinttmp));
02899         bp += sizeof(uinttmp);
02900 
02901         uinttmp = (u_int32_t)opgno;
02902         memcpy(bp, &uinttmp, sizeof(uinttmp));
02903         bp += sizeof(uinttmp);
02904 
02905         uinttmp = (u_int32_t)npgno;
02906         memcpy(bp, &uinttmp, sizeof(uinttmp));
02907         bp += sizeof(uinttmp);
02908 
02909         DB_ASSERT((u_int32_t)(bp - (u_int8_t *)logrec.data) <= logrec.size);
02910 
02911         if (is_durable || txnid == NULL) {
02912                 if ((ret = __log_put(dbenv, rlsnp,(DBT *)&logrec,
02913                     flags | DB_LOG_NOCOPY)) == 0 && txnid != NULL) {
02914                         *lsnp = *rlsnp;
02915                         if (rlsnp != ret_lsnp)
02916                                  *ret_lsnp = *rlsnp;
02917                 }
02918         } else {
02919 #ifdef DIAGNOSTIC
02920                 /*
02921                  * Set the debug bit if we are going to log non-durable
02922                  * transactions so they will be ignored by recovery.
02923                  */
02924                 memcpy(lr->data, logrec.data, logrec.size);
02925                 rectype |= DB_debug_FLAG;
02926                 memcpy(logrec.data, &rectype, sizeof(rectype));
02927 
02928                 ret = __log_put(dbenv,
02929                     rlsnp, (DBT *)&logrec, flags | DB_LOG_NOCOPY);
02930 #else
02931                 ret = 0;
02932 #endif
02933                 STAILQ_INSERT_HEAD(&txnid->logs, lr, links);
02934                 F_SET((TXN_DETAIL *)txnid->td, TXN_DTL_INMEMORY);
02935                 LSN_NOT_LOGGED(*ret_lsnp);
02936         }
02937 
02938 #ifdef LOG_DIAGNOSTIC
02939         if (ret != 0)
02940                 (void)__bam_pgno_print(dbenv,
02941                     (DBT *)&logrec, ret_lsnp, DB_TXN_PRINT, NULL);
02942 #endif
02943 
02944 #ifdef DIAGNOSTIC
02945         __os_free(dbenv, logrec.data);
02946 #else
02947         if (is_durable || txnid == NULL)
02948                 __os_free(dbenv, logrec.data);
02949 #endif
02950         return (ret);
02951 }
02952 
02953 /*
02954  * PUBLIC: int __bam_pgno_read __P((DB_ENV *, void *, __bam_pgno_args **));
02955  */
02956 int
02957 __bam_pgno_read(dbenv, recbuf, argpp)
02958         DB_ENV *dbenv;
02959         void *recbuf;
02960         __bam_pgno_args **argpp;
02961 {
02962         __bam_pgno_args *argp;
02963         u_int32_t uinttmp;
02964         u_int8_t *bp;
02965         int ret;
02966 
02967         if ((ret = __os_malloc(dbenv,
02968             sizeof(__bam_pgno_args) + sizeof(DB_TXN), &argp)) != 0)
02969                 return (ret);
02970         bp = recbuf;
02971         argp->txnid = (DB_TXN *)&argp[1];
02972 
02973         memcpy(&argp->type, bp, sizeof(argp->type));
02974         bp += sizeof(argp->type);
02975 
02976         memcpy(&argp->txnid->txnid,  bp, sizeof(argp->txnid->txnid));
02977         bp += sizeof(argp->txnid->txnid);
02978 
02979         memcpy(&argp->prev_lsn, bp, sizeof(DB_LSN));
02980         bp += sizeof(DB_LSN);
02981 
02982         memcpy(&uinttmp, bp, sizeof(uinttmp));
02983         argp->fileid = (int32_t)uinttmp;
02984         bp += sizeof(uinttmp);
02985 
02986         memcpy(&uinttmp, bp, sizeof(uinttmp));
02987         argp->pgno = (db_pgno_t)uinttmp;
02988         bp += sizeof(uinttmp);
02989 
02990         memcpy(&argp->lsn, bp,  sizeof(argp->lsn));
02991         bp += sizeof(argp->lsn);
02992 
02993         memcpy(&uinttmp, bp, sizeof(uinttmp));
02994         argp->indx = (u_int32_t)uinttmp;
02995         bp += sizeof(uinttmp);
02996 
02997         memcpy(&uinttmp, bp, sizeof(uinttmp));
02998         argp->opgno = (db_pgno_t)uinttmp;
02999         bp += sizeof(uinttmp);
03000 
03001         memcpy(&uinttmp, bp, sizeof(uinttmp));
03002         argp->npgno = (db_pgno_t)uinttmp;
03003         bp += sizeof(uinttmp);
03004 
03005         *argpp = argp;
03006         return (0);
03007 }
03008 
03009 /*
03010  * PUBLIC: int __bam_init_recover __P((DB_ENV *, int (***)(DB_ENV *,
03011  * PUBLIC:     DBT *, DB_LSN *, db_recops, void *), size_t *));
03012  */
03013 int
03014 __bam_init_recover(dbenv, dtabp, dtabsizep)
03015         DB_ENV *dbenv;
03016         int (***dtabp)__P((DB_ENV *, DBT *, DB_LSN *, db_recops, void *));
03017         size_t *dtabsizep;
03018 {
03019         int ret;
03020 
03021         if ((ret = __db_add_recovery(dbenv, dtabp, dtabsizep,
03022             __bam_split_recover, DB___bam_split)) != 0)
03023                 return (ret);
03024         if ((ret = __db_add_recovery(dbenv, dtabp, dtabsizep,
03025             __bam_rsplit_recover, DB___bam_rsplit)) != 0)
03026                 return (ret);
03027         if ((ret = __db_add_recovery(dbenv, dtabp, dtabsizep,
03028             __bam_adj_recover, DB___bam_adj)) != 0)
03029                 return (ret);
03030         if ((ret = __db_add_recovery(dbenv, dtabp, dtabsizep,
03031             __bam_cadjust_recover, DB___bam_cadjust)) != 0)
03032                 return (ret);
03033         if ((ret = __db_add_recovery(dbenv, dtabp, dtabsizep,
03034             __bam_cdel_recover, DB___bam_cdel)) != 0)
03035                 return (ret);
03036         if ((ret = __db_add_recovery(dbenv, dtabp, dtabsizep,
03037             __bam_repl_recover, DB___bam_repl)) != 0)
03038                 return (ret);
03039         if ((ret = __db_add_recovery(dbenv, dtabp, dtabsizep,
03040             __bam_root_recover, DB___bam_root)) != 0)
03041                 return (ret);
03042         if ((ret = __db_add_recovery(dbenv, dtabp, dtabsizep,
03043             __bam_curadj_recover, DB___bam_curadj)) != 0)
03044                 return (ret);
03045         if ((ret = __db_add_recovery(dbenv, dtabp, dtabsizep,
03046             __bam_rcuradj_recover, DB___bam_rcuradj)) != 0)
03047                 return (ret);
03048         if ((ret = __db_add_recovery(dbenv, dtabp, dtabsizep,
03049             __bam_relink_recover, DB___bam_relink)) != 0)
03050                 return (ret);
03051         if ((ret = __db_add_recovery(dbenv, dtabp, dtabsizep,
03052             __bam_merge_recover, DB___bam_merge)) != 0)
03053                 return (ret);
03054         if ((ret = __db_add_recovery(dbenv, dtabp, dtabsizep,
03055             __bam_pgno_recover, DB___bam_pgno)) != 0)
03056                 return (ret);
03057         return (0);
03058 }

Generated on Sun Dec 25 12:14:14 2005 for Berkeley DB 4.4.16 by  doxygen 1.4.2