mariadb/bdb/log/log_get.c
unknown 155e78f014 BDB 4.1.24
BitKeeper/deleted/.del-ex_access.wpj~3df6ae8c99bf7c5f:
  Delete: bdb/build_vxworks/ex_access/ex_access.wpj
BitKeeper/deleted/.del-ex_btrec.wpj~a7622f1c6f432dc6:
  Delete: bdb/build_vxworks/ex_btrec/ex_btrec.wpj
BitKeeper/deleted/.del-ex_dbclient.wpj~7345440f3b204cdd:
  Delete: bdb/build_vxworks/ex_dbclient/ex_dbclient.wpj
BitKeeper/deleted/.del-ex_env.wpj~fbe1ab10b04e8b74:
  Delete: bdb/build_vxworks/ex_env/ex_env.wpj
BitKeeper/deleted/.del-ex_mpool.wpj~4479cfd5c45f327d:
  Delete: bdb/build_vxworks/ex_mpool/ex_mpool.wpj
BitKeeper/deleted/.del-ex_tpcb.wpj~f78093006e14bf41:
  Delete: bdb/build_vxworks/ex_tpcb/ex_tpcb.wpj
BitKeeper/deleted/.del-db_buildall.dsp~bd749ff6da11682:
  Delete: bdb/build_win32/db_buildall.dsp
BitKeeper/deleted/.del-cxx_app.cpp~ad8df8e0791011ed:
  Delete: bdb/cxx/cxx_app.cpp
BitKeeper/deleted/.del-cxx_log.cpp~a50ff3118fe06952:
  Delete: bdb/cxx/cxx_log.cpp
BitKeeper/deleted/.del-cxx_table.cpp~ecd751e79b055556:
  Delete: bdb/cxx/cxx_table.cpp
BitKeeper/deleted/.del-namemap.txt~796a3acd3885d8fd:
  Delete: bdb/cxx/namemap.txt
BitKeeper/deleted/.del-Design.fileop~3ca4da68f1727373:
  Delete: bdb/db/Design.fileop
BitKeeper/deleted/.del-db185_int.h~61bee3736e7959ef:
  Delete: bdb/db185/db185_int.h
BitKeeper/deleted/.del-acconfig.h~411e8854d67ad8b5:
  Delete: bdb/dist/acconfig.h
BitKeeper/deleted/.del-mutex.m4~a13383cde18a64e1:
  Delete: bdb/dist/aclocal/mutex.m4
BitKeeper/deleted/.del-options.m4~b9d0ca637213750a:
  Delete: bdb/dist/aclocal/options.m4
BitKeeper/deleted/.del-programs.m4~3ce7890b47732b30:
  Delete: bdb/dist/aclocal/programs.m4
BitKeeper/deleted/.del-tcl.m4~f944e2db93c3b6db:
  Delete: bdb/dist/aclocal/tcl.m4
BitKeeper/deleted/.del-types.m4~59cae158c9a32cff:
  Delete: bdb/dist/aclocal/types.m4
BitKeeper/deleted/.del-script~d38f6d3a4f159cb4:
  Delete: bdb/dist/build/script
BitKeeper/deleted/.del-configure.in~ac795a92c8fe049c:
  Delete: bdb/dist/configure.in
BitKeeper/deleted/.del-ltconfig~66bbd007d8024af:
  Delete: bdb/dist/ltconfig
BitKeeper/deleted/.del-rec_ctemp~a28554362534f00a:
  Delete: bdb/dist/rec_ctemp
BitKeeper/deleted/.del-s_tcl~2ffe4326459fcd9f:
  Delete: bdb/dist/s_tcl
BitKeeper/deleted/.del-.IGNORE_ME~d8148b08fa7d5d15:
  Delete: bdb/dist/template/.IGNORE_ME
BitKeeper/deleted/.del-btree.h~179f2aefec1753d:
  Delete: bdb/include/btree.h
BitKeeper/deleted/.del-cxx_int.h~6b649c04766508f8:
  Delete: bdb/include/cxx_int.h
BitKeeper/deleted/.del-db.src~6b433ae615b16a8d:
  Delete: bdb/include/db.src
BitKeeper/deleted/.del-db_185.h~ad8b373d9391d35c:
  Delete: bdb/include/db_185.h
BitKeeper/deleted/.del-db_am.h~a714912b6b75932f:
  Delete: bdb/include/db_am.h
BitKeeper/deleted/.del-db_cxx.h~fcafadf45f5d19e9:
  Delete: bdb/include/db_cxx.h
BitKeeper/deleted/.del-db_dispatch.h~6844f20f7eb46904:
  Delete: bdb/include/db_dispatch.h
BitKeeper/deleted/.del-db_int.src~419a3f48b6a01da7:
  Delete: bdb/include/db_int.src
BitKeeper/deleted/.del-db_join.h~76f9747a42c3399a:
  Delete: bdb/include/db_join.h
BitKeeper/deleted/.del-db_page.h~e302ca3a4db3abdc:
  Delete: bdb/include/db_page.h
BitKeeper/deleted/.del-db_server_int.h~e1d20b6ba3bca1ab:
  Delete: bdb/include/db_server_int.h
BitKeeper/deleted/.del-db_shash.h~5fbf2d696fac90f3:
  Delete: bdb/include/db_shash.h
BitKeeper/deleted/.del-db_swap.h~1e60887550864a59:
  Delete: bdb/include/db_swap.h
BitKeeper/deleted/.del-db_upgrade.h~c644eee73701fc8d:
  Delete: bdb/include/db_upgrade.h
BitKeeper/deleted/.del-db_verify.h~b8d6c297c61f342e:
  Delete: bdb/include/db_verify.h
BitKeeper/deleted/.del-debug.h~dc2b4f2cf27ccebc:
  Delete: bdb/include/debug.h
BitKeeper/deleted/.del-hash.h~2aaa548b28882dfb:
  Delete: bdb/include/hash.h
BitKeeper/deleted/.del-lock.h~a761c1b7de57b77f:
  Delete: bdb/include/lock.h
BitKeeper/deleted/.del-log.h~ff20184238e35e4d:
  Delete: bdb/include/log.h
BitKeeper/deleted/.del-mp.h~7e317597622f3411:
  Delete: bdb/include/mp.h
BitKeeper/deleted/.del-mutex.h~d3ae7a2977a68137:
  Delete: bdb/include/mutex.h
BitKeeper/deleted/.del-os.h~91867cc8757cd0e3:
  Delete: bdb/include/os.h
BitKeeper/deleted/.del-os_jump.h~e1b939fa5151d4be:
  Delete: bdb/include/os_jump.h
BitKeeper/deleted/.del-qam.h~6fad0c1b5723d597:
  Delete: bdb/include/qam.h
BitKeeper/deleted/.del-queue.h~4c72c0826c123d5:
  Delete: bdb/include/queue.h
BitKeeper/deleted/.del-region.h~513fe04d977ca0fc:
  Delete: bdb/include/region.h
BitKeeper/deleted/.del-shqueue.h~525fc3e6c2025c36:
  Delete: bdb/include/shqueue.h
BitKeeper/deleted/.del-tcl_db.h~c536fd61a844f23f:
  Delete: bdb/include/tcl_db.h
BitKeeper/deleted/.del-txn.h~c8d94b221ec147e4:
  Delete: bdb/include/txn.h
BitKeeper/deleted/.del-xa.h~ecc466493aae9d9a:
  Delete: bdb/include/xa.h
BitKeeper/deleted/.del-DbRecoveryInit.java~756b52601a0b9023:
  Delete: bdb/java/src/com/sleepycat/db/DbRecoveryInit.java
BitKeeper/deleted/.del-DbTxnRecover.java~74607cba7ab89d6d:
  Delete: bdb/java/src/com/sleepycat/db/DbTxnRecover.java
BitKeeper/deleted/.del-lock_conflict.c~fc5e0f14cf597a2b:
  Delete: bdb/lock/lock_conflict.c
BitKeeper/deleted/.del-log.src~53ac9e7b5cb023f2:
  Delete: bdb/log/log.src
BitKeeper/deleted/.del-log_findckp.c~24287f008916e81f:
  Delete: bdb/log/log_findckp.c
BitKeeper/deleted/.del-log_rec.c~d51711f2cac09297:
  Delete: bdb/log/log_rec.c
BitKeeper/deleted/.del-log_register.c~b40bb4efac75ca15:
  Delete: bdb/log/log_register.c
BitKeeper/deleted/.del-Design~b3d0f179f2767b:
  Delete: bdb/mp/Design
BitKeeper/deleted/.del-os_finit.c~95dbefc6fe79b26c:
  Delete: bdb/os/os_finit.c
BitKeeper/deleted/.del-os_abs.c~df95d1e7db81924:
  Delete: bdb/os_vxworks/os_abs.c
BitKeeper/deleted/.del-os_finit.c~803b484bdb9d0122:
  Delete: bdb/os_vxworks/os_finit.c
BitKeeper/deleted/.del-os_map.c~3a6d7926398b76d3:
  Delete: bdb/os_vxworks/os_map.c
BitKeeper/deleted/.del-os_finit.c~19a227c6d3c78ad:
  Delete: bdb/os_win32/os_finit.c
BitKeeper/deleted/.del-log-corruption.patch~1cf2ecc7c6408d5d:
  Delete: bdb/patches/log-corruption.patch
BitKeeper/deleted/.del-Btree.pm~af6d0c5eaed4a98e:
  Delete: bdb/perl.BerkeleyDB/BerkeleyDB/Btree.pm
BitKeeper/deleted/.del-BerkeleyDB.pm~7244036d4482643:
  Delete: bdb/perl.BerkeleyDB/BerkeleyDB.pm
BitKeeper/deleted/.del-BerkeleyDB.pod~e7b18fd6132448e3:
  Delete: bdb/perl.BerkeleyDB/BerkeleyDB.pod
BitKeeper/deleted/.del-Hash.pm~10292a26c06a5c95:
  Delete: bdb/perl.BerkeleyDB/BerkeleyDB/Hash.pm
BitKeeper/deleted/.del-BerkeleyDB.pod.P~79f76a1495eda203:
  Delete: bdb/perl.BerkeleyDB/BerkeleyDB.pod.P
BitKeeper/deleted/.del-BerkeleyDB.xs~80c99afbd98e392c:
  Delete: bdb/perl.BerkeleyDB/BerkeleyDB.xs
BitKeeper/deleted/.del-Changes~729c1891efa60de9:
  Delete: bdb/perl.BerkeleyDB/Changes
BitKeeper/deleted/.del-MANIFEST~63a1e34aecf157a0:
  Delete: bdb/perl.BerkeleyDB/MANIFEST
BitKeeper/deleted/.del-Makefile.PL~c68797707d8df87a:
  Delete: bdb/perl.BerkeleyDB/Makefile.PL
BitKeeper/deleted/.del-README~5f2f579b1a241407:
  Delete: bdb/perl.BerkeleyDB/README
BitKeeper/deleted/.del-Todo~dca3c66c193adda9:
  Delete: bdb/perl.BerkeleyDB/Todo
BitKeeper/deleted/.del-config.in~ae81681e450e0999:
  Delete: bdb/perl.BerkeleyDB/config.in
BitKeeper/deleted/.del-dbinfo~28ad67d83be4f68e:
  Delete: bdb/perl.BerkeleyDB/dbinfo
BitKeeper/deleted/.del-mkconsts~543ab60669c7a04e:
  Delete: bdb/perl.BerkeleyDB/mkconsts
BitKeeper/deleted/.del-mkpod~182c0ca54e439afb:
  Delete: bdb/perl.BerkeleyDB/mkpod
BitKeeper/deleted/.del-5.004~e008cb5a48805543:
  Delete: bdb/perl.BerkeleyDB/patches/5.004
BitKeeper/deleted/.del-irix_6_5.pl~61662bb08afcdec8:
  Delete: bdb/perl.BerkeleyDB/hints/irix_6_5.pl
BitKeeper/deleted/.del-solaris.pl~6771e7182394e152:
  Delete: bdb/perl.BerkeleyDB/hints/solaris.pl
BitKeeper/deleted/.del-typemap~783b8f5295b05f3d:
  Delete: bdb/perl.BerkeleyDB/typemap
BitKeeper/deleted/.del-5.004_01~6081ce2fff7b0bc:
  Delete: bdb/perl.BerkeleyDB/patches/5.004_01
BitKeeper/deleted/.del-5.004_02~87214eac35ad9e6:
  Delete: bdb/perl.BerkeleyDB/patches/5.004_02
BitKeeper/deleted/.del-5.004_03~9a672becec7cb40f:
  Delete: bdb/perl.BerkeleyDB/patches/5.004_03
BitKeeper/deleted/.del-5.004_04~e326cb51af09d154:
  Delete: bdb/perl.BerkeleyDB/patches/5.004_04
BitKeeper/deleted/.del-5.004_05~7ab457a1e41a92fe:
  Delete: bdb/perl.BerkeleyDB/patches/5.004_05
BitKeeper/deleted/.del-5.005~f9e2d59b5964cd4b:
  Delete: bdb/perl.BerkeleyDB/patches/5.005
BitKeeper/deleted/.del-5.005_01~3eb9fb7b5842ea8e:
  Delete: bdb/perl.BerkeleyDB/patches/5.005_01
BitKeeper/deleted/.del-5.005_02~67477ce0bef717cb:
  Delete: bdb/perl.BerkeleyDB/patches/5.005_02
BitKeeper/deleted/.del-5.005_03~c4c29a1fb21e290a:
  Delete: bdb/perl.BerkeleyDB/patches/5.005_03
BitKeeper/deleted/.del-5.6.0~e1fb9897d124ee22:
  Delete: bdb/perl.BerkeleyDB/patches/5.6.0
BitKeeper/deleted/.del-btree.t~e4a1a3c675ddc406:
  Delete: bdb/perl.BerkeleyDB/t/btree.t
BitKeeper/deleted/.del-db-3.0.t~d2c60991d84558f2:
  Delete: bdb/perl.BerkeleyDB/t/db-3.0.t
BitKeeper/deleted/.del-db-3.1.t~6ee88cd13f55e018:
  Delete: bdb/perl.BerkeleyDB/t/db-3.1.t
BitKeeper/deleted/.del-db-3.2.t~f73b6461f98fd1cf:
  Delete: bdb/perl.BerkeleyDB/t/db-3.2.t
BitKeeper/deleted/.del-destroy.t~cc6a2ae1980a2ecd:
  Delete: bdb/perl.BerkeleyDB/t/destroy.t
BitKeeper/deleted/.del-env.t~a8604a4499c4bd07:
  Delete: bdb/perl.BerkeleyDB/t/env.t
BitKeeper/deleted/.del-examples.t~2571b77c3cc75574:
  Delete: bdb/perl.BerkeleyDB/t/examples.t
BitKeeper/deleted/.del-examples.t.T~8228bdd75ac78b88:
  Delete: bdb/perl.BerkeleyDB/t/examples.t.T
BitKeeper/deleted/.del-examples3.t.T~66a186897a87026d:
  Delete: bdb/perl.BerkeleyDB/t/examples3.t.T
BitKeeper/deleted/.del-examples3.t~fe3822ba2f2d7f83:
  Delete: bdb/perl.BerkeleyDB/t/examples3.t
BitKeeper/deleted/.del-filter.t~f87b045c1b708637:
  Delete: bdb/perl.BerkeleyDB/t/filter.t
BitKeeper/deleted/.del-hash.t~616bfb4d644de3a3:
  Delete: bdb/perl.BerkeleyDB/t/hash.t
BitKeeper/deleted/.del-join.t~29fc39f74a83ca22:
  Delete: bdb/perl.BerkeleyDB/t/join.t
BitKeeper/deleted/.del-mldbm.t~31f5015341eea040:
  Delete: bdb/perl.BerkeleyDB/t/mldbm.t
BitKeeper/deleted/.del-queue.t~8f338034ce44a641:
  Delete: bdb/perl.BerkeleyDB/t/queue.t
BitKeeper/deleted/.del-recno.t~d4ddbd3743add63e:
  Delete: bdb/perl.BerkeleyDB/t/recno.t
BitKeeper/deleted/.del-strict.t~6885cdd2ea71ca2d:
  Delete: bdb/perl.BerkeleyDB/t/strict.t
BitKeeper/deleted/.del-subdb.t~aab62a5d5864c603:
  Delete: bdb/perl.BerkeleyDB/t/subdb.t
BitKeeper/deleted/.del-txn.t~65033b8558ae1216:
  Delete: bdb/perl.BerkeleyDB/t/txn.t
BitKeeper/deleted/.del-unknown.t~f3710458682665e1:
  Delete: bdb/perl.BerkeleyDB/t/unknown.t
BitKeeper/deleted/.del-Changes~436f74a5c414c65b:
  Delete: bdb/perl.DB_File/Changes
BitKeeper/deleted/.del-DB_File.pm~ae0951c6c7665a82:
  Delete: bdb/perl.DB_File/DB_File.pm
BitKeeper/deleted/.del-DB_File.xs~89e49a0b5556f1d8:
  Delete: bdb/perl.DB_File/DB_File.xs
BitKeeper/deleted/.del-DB_File_BS~290fad5dbbb87069:
  Delete: bdb/perl.DB_File/DB_File_BS
BitKeeper/deleted/.del-MANIFEST~90ee581572bdd4ac:
  Delete: bdb/perl.DB_File/MANIFEST
BitKeeper/deleted/.del-Makefile.PL~ac0567bb5a377e38:
  Delete: bdb/perl.DB_File/Makefile.PL
BitKeeper/deleted/.del-README~77e924a5a9bae6b3:
  Delete: bdb/perl.DB_File/README
BitKeeper/deleted/.del-config.in~ab4c2792b86a810b:
  Delete: bdb/perl.DB_File/config.in
BitKeeper/deleted/.del-dbinfo~461c43b30fab2cb:
  Delete: bdb/perl.DB_File/dbinfo
BitKeeper/deleted/.del-dynixptx.pl~50dcddfae25d17e9:
  Delete: bdb/perl.DB_File/hints/dynixptx.pl
BitKeeper/deleted/.del-typemap~55cffb3288a9e587:
  Delete: bdb/perl.DB_File/typemap
BitKeeper/deleted/.del-version.c~a4df0e646f8b3975:
  Delete: bdb/perl.DB_File/version.c
BitKeeper/deleted/.del-5.004_01~d6830d0082702af7:
  Delete: bdb/perl.DB_File/patches/5.004_01
BitKeeper/deleted/.del-5.004_02~78b082dc80c91031:
  Delete: bdb/perl.DB_File/patches/5.004_02
BitKeeper/deleted/.del-5.004~4411ec2e3c9e008b:
  Delete: bdb/perl.DB_File/patches/5.004
BitKeeper/deleted/.del-sco.pl~1e795fe14fe4dcfe:
  Delete: bdb/perl.DB_File/hints/sco.pl
BitKeeper/deleted/.del-5.004_03~33f274648b160d95:
  Delete: bdb/perl.DB_File/patches/5.004_03
BitKeeper/deleted/.del-5.004_04~8f3d1b3cf18bb20a:
  Delete: bdb/perl.DB_File/patches/5.004_04
BitKeeper/deleted/.del-5.004_05~9c0f02e7331e142:
  Delete: bdb/perl.DB_File/patches/5.004_05
BitKeeper/deleted/.del-5.005~c2108cb2e3c8d951:
  Delete: bdb/perl.DB_File/patches/5.005
BitKeeper/deleted/.del-5.005_01~3b45e9673afc4cfa:
  Delete: bdb/perl.DB_File/patches/5.005_01
BitKeeper/deleted/.del-5.005_02~9fe5766bb02a4522:
  Delete: bdb/perl.DB_File/patches/5.005_02
BitKeeper/deleted/.del-5.005_03~ffa1c38c19ae72ea:
  Delete: bdb/perl.DB_File/patches/5.005_03
BitKeeper/deleted/.del-5.6.0~373be3a5ce47be85:
  Delete: bdb/perl.DB_File/patches/5.6.0
BitKeeper/deleted/.del-db-btree.t~3231595a1c241eb3:
  Delete: bdb/perl.DB_File/t/db-btree.t
BitKeeper/deleted/.del-db-hash.t~7c4ad0c795c7fad2:
  Delete: bdb/perl.DB_File/t/db-hash.t
BitKeeper/deleted/.del-db-recno.t~6c2d3d80b9ba4a50:
  Delete: bdb/perl.DB_File/t/db-recno.t
BitKeeper/deleted/.del-db_server.sed~cdb00ebcd48a64e2:
  Delete: bdb/rpc_server/db_server.sed
BitKeeper/deleted/.del-db_server_proc.c~d46c8f409c3747f4:
  Delete: bdb/rpc_server/db_server_proc.c
BitKeeper/deleted/.del-db_server_svc.sed~3f5e59f334fa4607:
  Delete: bdb/rpc_server/db_server_svc.sed
BitKeeper/deleted/.del-db_server_util.c~a809f3a4629acda:
  Delete: bdb/rpc_server/db_server_util.c
BitKeeper/deleted/.del-log.tcl~ff1b41f1355b97d7:
  Delete: bdb/test/log.tcl
BitKeeper/deleted/.del-mpool.tcl~b0df4dc1b04db26c:
  Delete: bdb/test/mpool.tcl
BitKeeper/deleted/.del-mutex.tcl~52fd5c73a150565:
  Delete: bdb/test/mutex.tcl
BitKeeper/deleted/.del-txn.tcl~c4ff071550b5446e:
  Delete: bdb/test/txn.tcl
BitKeeper/deleted/.del-README~e800a12a5392010a:
  Delete: bdb/test/upgrade/README
BitKeeper/deleted/.del-pack-2.6.6.pl~89d5076d758d3e98:
  Delete: bdb/test/upgrade/generate-2.X/pack-2.6.6.pl
BitKeeper/deleted/.del-test-2.6.patch~4a52dc83d447547b:
  Delete: bdb/test/upgrade/generate-2.X/test-2.6.patch
2002-10-30 15:57:05 +04:00

1058 lines
28 KiB
C

/*-
* See the file LICENSE for redistribution information.
*
* Copyright (c) 1996-2002
* Sleepycat Software. All rights reserved.
*/
#include "db_config.h"
#ifndef lint
static const char revid[] = "$Id: log_get.c,v 11.81 2002/08/14 20:09:27 bostic Exp $";
#endif /* not lint */
#ifndef NO_SYSTEM_INCLUDES
#include <sys/types.h>
#include <string.h>
#include <unistd.h>
#endif
#include "db_int.h"
#include "dbinc/crypto.h"
#include "dbinc/db_page.h"
#include "dbinc/hmac.h"
#include "dbinc/log.h"
#include "dbinc/hash.h"
typedef enum { L_ALREADY, L_ACQUIRED, L_NONE } RLOCK;
static int __log_c_close __P((DB_LOGC *, u_int32_t));
static int __log_c_get __P((DB_LOGC *, DB_LSN *, DBT *, u_int32_t));
static int __log_c_get_int __P((DB_LOGC *, DB_LSN *, DBT *, u_int32_t));
static int __log_c_hdrchk __P((DB_LOGC *, HDR *, int *));
static int __log_c_incursor __P((DB_LOGC *, DB_LSN *, HDR *, u_int8_t **));
static int __log_c_inregion __P((DB_LOGC *,
DB_LSN *, RLOCK *, DB_LSN *, HDR *, u_int8_t **));
static int __log_c_io __P((DB_LOGC *,
u_int32_t, u_int32_t, void *, size_t *, int *));
static int __log_c_ondisk __P((DB_LOGC *,
DB_LSN *, DB_LSN *, int, HDR *, u_int8_t **, int *));
static int __log_c_set_maxrec __P((DB_LOGC *, char *));
static int __log_c_shortread __P((DB_LOGC *, int));
/*
* __log_cursor --
* Create a log cursor.
*
* PUBLIC: int __log_cursor __P((DB_ENV *, DB_LOGC **, u_int32_t));
*/
int
__log_cursor(dbenv, logcp, flags)
DB_ENV *dbenv;
DB_LOGC **logcp;
u_int32_t flags;
{
DB_LOGC *logc;
int ret;
PANIC_CHECK(dbenv);
ENV_REQUIRES_CONFIG(dbenv,
dbenv->lg_handle, "DB_ENV->log_cursor", DB_INIT_LOG);
*logcp = NULL;
/* Validate arguments. */
if ((ret = __db_fchk(dbenv, "DB_ENV->log_cursor", flags, 0)) != 0)
return (ret);
/* Allocate memory for the cursor. */
if ((ret = __os_calloc(dbenv, 1, sizeof(DB_LOGC), &logc)) != 0)
goto err;
if ((ret = __os_calloc(dbenv, 1, sizeof(DB_FH), &logc->c_fh)) != 0)
goto err;
logc->bp_size = DB_LOGC_BUF_SIZE;
if ((ret = __os_malloc(dbenv, logc->bp_size, &logc->bp)) != 0)
goto err;
logc->dbenv = dbenv;
logc->close = __log_c_close;
logc->get = __log_c_get;
*logcp = logc;
return (0);
err: if (logc != NULL) {
if (logc->c_fh != NULL)
__os_free(dbenv, logc->c_fh);
__os_free(dbenv, logc);
}
return (ret);
}
/*
* __log_c_close --
* Close a log cursor.
*/
static int
__log_c_close(logc, flags)
DB_LOGC *logc;
u_int32_t flags;
{
DB_ENV *dbenv;
int ret;
dbenv = logc->dbenv;
PANIC_CHECK(dbenv);
if ((ret = __db_fchk(dbenv, "DB_LOGC->close", flags, 0)) != 0)
return (ret);
if (F_ISSET(logc->c_fh, DB_FH_VALID))
(void)__os_closehandle(dbenv, logc->c_fh);
if (logc->c_dbt.data != NULL)
__os_free(dbenv, logc->c_dbt.data);
__os_free(dbenv, logc->bp);
__os_free(dbenv, logc->c_fh);
__os_free(dbenv, logc);
return (0);
}
/*
* __log_c_get --
* Get a log record.
*/
static int
__log_c_get(logc, alsn, dbt, flags)
DB_LOGC *logc;
DB_LSN *alsn;
DBT *dbt;
u_int32_t flags;
{
DB_ENV *dbenv;
DB_LSN saved_lsn;
int ret;
dbenv = logc->dbenv;
PANIC_CHECK(dbenv);
/* Validate arguments. */
switch (flags) {
case DB_CURRENT:
case DB_FIRST:
case DB_LAST:
case DB_NEXT:
case DB_PREV:
break;
case DB_SET:
if (IS_ZERO_LSN(*alsn)) {
__db_err(dbenv, "DB_LOGC->get: invalid LSN");
return (EINVAL);
}
break;
default:
return (__db_ferr(dbenv, "DB_LOGC->get", 1));
}
/*
* On error, we take care not to overwrite the caller's LSN. This
* is because callers looking for the end of the log loop using the
* DB_NEXT flag, and expect to take the last successful lsn out of
* the passed-in structure after DB_LOGC->get fails with DB_NOTFOUND.
*
* !!!
* This line is often flagged an uninitialized memory read during a
* Purify or similar tool run, as the application didn't initialize
* *alsn. If the application isn't setting the DB_SET flag, there is
* no reason it should have initialized *alsn, but we can't know that
* and we want to make sure we never overwrite whatever the application
* put in there.
*/
saved_lsn = *alsn;
/*
* If we get one of the log's header records as a result of doing a
* DB_FIRST, DB_NEXT, DB_LAST or DB_PREV, repeat the operation, log
* file header records aren't useful to applications.
*/
if ((ret = __log_c_get_int(logc, alsn, dbt, flags)) != 0) {
*alsn = saved_lsn;
return (ret);
}
if (alsn->offset == 0 && (flags == DB_FIRST ||
flags == DB_NEXT || flags == DB_LAST || flags == DB_PREV)) {
switch (flags) {
case DB_FIRST:
flags = DB_NEXT;
break;
case DB_LAST:
flags = DB_PREV;
break;
}
if (F_ISSET(dbt, DB_DBT_MALLOC)) {
__os_free(dbenv, dbt->data);
dbt->data = NULL;
}
if ((ret = __log_c_get_int(logc, alsn, dbt, flags)) != 0) {
*alsn = saved_lsn;
return (ret);
}
}
return (0);
}
/*
* __log_c_get_int --
* Get a log record; internal version.
*/
static int
__log_c_get_int(logc, alsn, dbt, flags)
DB_LOGC *logc;
DB_LSN *alsn;
DBT *dbt;
u_int32_t flags;
{
DB_CIPHER *db_cipher;
DB_ENV *dbenv;
DB_LOG *dblp;
DB_LSN last_lsn, nlsn;
HDR hdr;
LOG *lp;
RLOCK rlock;
logfile_validity status;
u_int32_t cnt;
u_int8_t *rp;
int eof, is_hmac, ret;
dbenv = logc->dbenv;
dblp = dbenv->lg_handle;
lp = dblp->reginfo.primary;
is_hmac = 0;
/*
* We don't acquire the log region lock until we need it, and we
* release it as soon as we're done.
*/
rlock = F_ISSET(logc, DB_LOG_LOCKED) ? L_ALREADY : L_NONE;
nlsn = logc->c_lsn;
switch (flags) {
case DB_NEXT: /* Next log record. */
if (!IS_ZERO_LSN(nlsn)) {
/* Increment the cursor by the cursor record size. */
nlsn.offset += logc->c_len;
break;
}
flags = DB_FIRST;
/* FALLTHROUGH */
case DB_FIRST: /* First log record. */
/* Find the first log file. */
if ((ret = __log_find(dblp, 1, &cnt, &status)) != 0)
goto err;
/*
* DB_LV_INCOMPLETE:
* Theoretically, the log file we want could be created
* but not yet written, the "first" log record must be
* in the log buffer.
* DB_LV_NORMAL:
* DB_LV_OLD_READABLE:
* We found a log file we can read.
* DB_LV_NONEXISTENT:
* No log files exist, the "first" log record must be in
* the log buffer.
* DB_LV_OLD_UNREADABLE:
* No readable log files exist, we're at the cross-over
* point between two versions. The "first" log record
* must be in the log buffer.
*/
switch (status) {
case DB_LV_INCOMPLETE:
DB_ASSERT(lp->lsn.file == cnt);
/* FALLTHROUGH */
case DB_LV_NORMAL:
case DB_LV_OLD_READABLE:
nlsn.file = cnt;
break;
case DB_LV_NONEXISTENT:
nlsn.file = 1;
DB_ASSERT(lp->lsn.file == nlsn.file);
break;
case DB_LV_OLD_UNREADABLE:
nlsn.file = cnt + 1;
DB_ASSERT(lp->lsn.file == nlsn.file);
break;
}
nlsn.offset = 0;
break;
case DB_CURRENT: /* Current log record. */
break;
case DB_PREV: /* Previous log record. */
if (!IS_ZERO_LSN(nlsn)) {
/* If at start-of-file, move to the previous file. */
if (nlsn.offset == 0) {
if (nlsn.file == 1 ||
__log_valid(dblp,
nlsn.file - 1, 0, &status) != 0) {
ret = DB_NOTFOUND;
goto err;
}
if (status != DB_LV_NORMAL &&
status != DB_LV_OLD_READABLE) {
ret = DB_NOTFOUND;
goto err;
}
--nlsn.file;
}
nlsn.offset = logc->c_prev;
break;
}
/* FALLTHROUGH */
case DB_LAST: /* Last log record. */
if (rlock == L_NONE) {
rlock = L_ACQUIRED;
R_LOCK(dbenv, &dblp->reginfo);
}
nlsn.file = lp->lsn.file;
nlsn.offset = lp->lsn.offset - lp->len;
break;
case DB_SET: /* Set log record. */
nlsn = *alsn;
break;
}
if (0) { /* Move to the next file. */
next_file: ++nlsn.file;
nlsn.offset = 0;
}
/*
* The above switch statement should have set nlsn to the lsn of
* the requested record.
*/
if (CRYPTO_ON(dbenv)) {
hdr.size = HDR_CRYPTO_SZ;
is_hmac = 1;
} else {
hdr.size = HDR_NORMAL_SZ;
is_hmac = 0;
}
/* Check to see if the record is in the cursor's buffer. */
if ((ret = __log_c_incursor(logc, &nlsn, &hdr, &rp)) != 0)
goto err;
if (rp != NULL)
goto cksum;
/*
* Look to see if we're moving backward in the log with the last record
* coming from the disk -- it means the record can't be in the region's
* buffer. Else, check the region's buffer.
*
* If the record isn't in the region's buffer, we're going to have to
* read the record from disk. We want to make a point of not reading
* past the end of the logical log (after recovery, there may be data
* after the end of the logical log, not to mention the log file may
* have been pre-allocated). So, zero out last_lsn, and initialize it
* inside __log_c_inregion -- if it's still zero when we check it in
* __log_c_ondisk, that's OK, it just means the logical end of the log
* isn't an issue for this request.
*/
ZERO_LSN(last_lsn);
if (!F_ISSET(logc, DB_LOG_DISK) ||
log_compare(&nlsn, &logc->c_lsn) > 0) {
F_CLR(logc, DB_LOG_DISK);
if ((ret = __log_c_inregion(logc,
&nlsn, &rlock, &last_lsn, &hdr, &rp)) != 0)
goto err;
if (rp != NULL)
goto cksum;
}
/*
* We have to read from an on-disk file to retrieve the record.
* If we ever can't retrieve the record at offset 0, we're done,
* return EOF/DB_NOTFOUND.
*
* Discard the region lock if we're still holding it, the on-disk
* reading routines don't need it.
*/
if (rlock == L_ACQUIRED) {
rlock = L_NONE;
R_UNLOCK(dbenv, &dblp->reginfo);
}
if ((ret = __log_c_ondisk(
logc, &nlsn, &last_lsn, flags, &hdr, &rp, &eof)) != 0)
goto err;
if (eof == 1) {
/*
* Only DB_NEXT automatically moves to the next file, and
* it only happens once.
*/
if (flags != DB_NEXT || nlsn.offset == 0)
return (DB_NOTFOUND);
goto next_file;
}
F_SET(logc, DB_LOG_DISK);
cksum: /*
* Discard the region lock if we're still holding it. (The path to
* get here is that we acquired the lock because of the caller's
* flag argument, but we found the record in the cursor's buffer.
* Improbable, but it's easy to avoid.
*/
if (rlock == L_ACQUIRED) {
rlock = L_NONE;
R_UNLOCK(dbenv, &dblp->reginfo);
}
/*
* Checksum: there are two types of errors -- a configuration error
* or a checksum mismatch. The former is always bad. The latter is
* OK if we're searching for the end of the log, and very, very bad
* if we're reading random log records.
*/
db_cipher = dbenv->crypto_handle;
if ((ret = __db_check_chksum(dbenv, db_cipher,
hdr.chksum, rp + hdr.size, hdr.len - hdr.size, is_hmac)) != 0) {
if (F_ISSET(logc, DB_LOG_SILENT_ERR)) {
if (ret == 0 || ret == -1)
ret = EIO;
} else if (ret == -1) {
__db_err(dbenv,
"DB_LOGC->get: log record checksum mismatch");
__db_err(dbenv,
"DB_LOGC->get: catastrophic recovery may be required");
ret = __db_panic(dbenv, DB_RUNRECOVERY);
}
goto err;
}
/*
* If we got a 0-length record, that means we're in the midst of
* some bytes that got 0'd as the result of a vtruncate. We're
* going to have to retry.
*/
if (hdr.len == 0) {
switch (flags) {
case DB_FIRST:
case DB_NEXT:
/* Zero'd records always indicate the end of a file. */
goto next_file;
case DB_LAST:
case DB_PREV:
/*
* We should never get here. If we recover a log
* file with 0's at the end, we'll treat the 0'd
* headers as the end of log and ignore them. If
* we're reading backwards from another file, then
* the first record in that new file should have its
* prev field set correctly.
*/
__db_err(dbenv,
"Encountered zero length records while traversing backwards");
DB_ASSERT(0);
case DB_SET:
default:
/* Return the 0-length record. */
break;
}
}
/* Copy the record into the user's DBT. */
if ((ret = __db_retcopy(dbenv, dbt, rp + hdr.size,
(u_int32_t)(hdr.len - hdr.size),
&logc->c_dbt.data, &logc->c_dbt.ulen)) != 0)
goto err;
if (CRYPTO_ON(dbenv)) {
if ((ret = db_cipher->decrypt(dbenv, db_cipher->data,
hdr.iv, dbt->data, hdr.len - hdr.size)) != 0) {
ret = EAGAIN;
goto err;
}
/*
* Return the original log record size to the user,
* even though we've allocated more than that, possibly.
* The log record is decrypted in the user dbt, not in
* the buffer, so we must do this here after decryption,
* not adjust the len passed to the __db_retcopy call.
*/
dbt->size = hdr.orig_size;
}
/* Update the cursor and the returned LSN. */
*alsn = nlsn;
logc->c_lsn = nlsn;
logc->c_len = hdr.len;
logc->c_prev = hdr.prev;
err: if (rlock == L_ACQUIRED)
R_UNLOCK(dbenv, &dblp->reginfo);
return (ret);
}
/*
* __log_c_incursor --
* Check to see if the requested record is in the cursor's buffer.
*/
static int
__log_c_incursor(logc, lsn, hdr, pp)
DB_LOGC *logc;
DB_LSN *lsn;
HDR *hdr;
u_int8_t **pp;
{
u_int8_t *p;
*pp = NULL;
/*
* Test to see if the requested LSN could be part of the cursor's
* buffer.
*
* The record must be part of the same file as the cursor's buffer.
* The record must start at a byte offset equal to or greater than
* the cursor buffer.
* The record must not start at a byte offset after the cursor
* buffer's end.
*/
if (logc->bp_lsn.file != lsn->file)
return (0);
if (logc->bp_lsn.offset > lsn->offset)
return (0);
if (logc->bp_lsn.offset + logc->bp_rlen <= lsn->offset + hdr->size)
return (0);
/*
* Read the record's header and check if the record is entirely held
* in the buffer. If the record is not entirely held, get it again.
* (The only advantage in having part of the record locally is that
* we might avoid a system call because we already have the HDR in
* memory.)
*
* If the header check fails for any reason, it must be because the
* LSN is bogus. Fail hard.
*/
p = logc->bp + (lsn->offset - logc->bp_lsn.offset);
memcpy(hdr, p, hdr->size);
if (__log_c_hdrchk(logc, hdr, NULL))
return (DB_NOTFOUND);
if (logc->bp_lsn.offset + logc->bp_rlen <= lsn->offset + hdr->len)
return (0);
*pp = p; /* Success. */
return (0);
}
/*
* __log_c_inregion --
* Check to see if the requested record is in the region's buffer.
*/
static int
__log_c_inregion(logc, lsn, rlockp, last_lsn, hdr, pp)
DB_LOGC *logc;
DB_LSN *lsn, *last_lsn;
RLOCK *rlockp;
HDR *hdr;
u_int8_t **pp;
{
DB_ENV *dbenv;
DB_LOG *dblp;
LOG *lp;
size_t len, nr;
u_int32_t b_disk, b_region;
int ret;
u_int8_t *p;
dbenv = logc->dbenv;
dblp = dbenv->lg_handle;
lp = ((DB_LOG *)logc->dbenv->lg_handle)->reginfo.primary;
ret = 0;
*pp = NULL;
/* If we haven't yet acquired the log region lock, do so. */
if (*rlockp == L_NONE) {
*rlockp = L_ACQUIRED;
R_LOCK(dbenv, &dblp->reginfo);
}
/*
* The routines to read from disk must avoid reading past the logical
* end of the log, so pass that information back to it.
*
* Since they're reading directly from the disk, they must also avoid
* reading past the offset we've written out. If the log was
* truncated, it's possible that there are zeroes or garbage on
* disk after this offset, and the logical end of the log can
* come later than this point if the log buffer isn't empty.
*/
*last_lsn = lp->lsn;
if (last_lsn->offset > lp->w_off)
last_lsn->offset = lp->w_off;
/*
* Test to see if the requested LSN could be part of the region's
* buffer.
*
* During recovery, we read the log files getting the information to
* initialize the region. In that case, the region's lsn field will
* not yet have been filled in, use only the disk.
*
* The record must not start at a byte offset after the region buffer's
* end, since that means the request is for a record after the end of
* the log. Do this test even if the region's buffer is empty -- after
* recovery, the log files may continue past the declared end-of-log,
* and the disk reading routine will incorrectly attempt to read the
* remainder of the log.
*
* Otherwise, test to see if the region's buffer actually has what we
* want:
*
* The buffer must have some useful content.
* The record must be in the same file as the region's buffer and must
* start at a byte offset equal to or greater than the region's buffer.
*/
if (IS_ZERO_LSN(lp->lsn))
return (0);
if (lsn->file > lp->lsn.file ||
(lsn->file == lp->lsn.file && lsn->offset >= lp->lsn.offset))
return (DB_NOTFOUND);
if (lp->b_off == 0)
return (0);
if (lsn->file < lp->f_lsn.file || lsn->offset < lp->f_lsn.offset)
return (0);
/*
* The current contents of the cursor's buffer will be useless for a
* future call -- trash it rather than try and make it look correct.
*/
ZERO_LSN(logc->bp_lsn);
/*
* If the requested LSN is greater than the region buffer's first
* byte, we know the entire record is in the buffer.
*
* If the header check fails for any reason, it must be because the
* LSN is bogus. Fail hard.
*/
if (lsn->offset > lp->f_lsn.offset) {
p = dblp->bufp + (lsn->offset - lp->w_off);
memcpy(hdr, p, hdr->size);
if (__log_c_hdrchk(logc, hdr, NULL))
return (DB_NOTFOUND);
if (logc->bp_size <= hdr->len) {
len = ALIGN(hdr->len * 2, 128);
if ((ret =
__os_realloc(logc->dbenv, len, &logc->bp)) != 0)
return (ret);
logc->bp_size = (u_int32_t)len;
}
memcpy(logc->bp, p, hdr->len);
*pp = logc->bp;
return (0);
}
/*
* There's a partial record, that is, the requested record starts
* in a log file and finishes in the region buffer. We have to
* find out how many bytes of the record are in the region buffer
* so we can copy them out into the cursor buffer. First, check
* to see if the requested record is the only record in the region
* buffer, in which case we should copy the entire region buffer.
*
* Else, walk back through the region's buffer to find the first LSN
* after the record that crosses the buffer boundary -- we can detect
* that LSN, because its "prev" field will reference the record we
* want. The bytes we need to copy from the region buffer are the
* bytes up to the record we find. The bytes we'll need to allocate
* to hold the log record are the bytes between the two offsets.
*/
b_disk = lp->w_off - lsn->offset;
if (lp->b_off <= lp->len)
b_region = (u_int32_t)lp->b_off;
else
for (p = dblp->bufp + (lp->b_off - lp->len);;) {
memcpy(hdr, p, hdr->size);
if (hdr->prev == lsn->offset) {
b_region = (u_int32_t)(p - dblp->bufp);
break;
}
p = dblp->bufp + (hdr->prev - lp->w_off);
}
/*
* If we don't have enough room for the record, we have to allocate
* space. We have to do it while holding the region lock, which is
* truly annoying, but there's no way around it. This call is why
* we allocate cursor buffer space when allocating the cursor instead
* of waiting.
*/
if (logc->bp_size <= b_region + b_disk) {
len = ALIGN((b_region + b_disk) * 2, 128);
if ((ret = __os_realloc(logc->dbenv, len, &logc->bp)) != 0)
return (ret);
logc->bp_size = (u_int32_t)len;
}
/* Copy the region's bytes to the end of the cursor's buffer. */
p = (logc->bp + logc->bp_size) - b_region;
memcpy(p, dblp->bufp, b_region);
/* Release the region lock. */
if (*rlockp == L_ACQUIRED) {
*rlockp = L_NONE;
R_UNLOCK(dbenv, &dblp->reginfo);
}
/*
* Read the rest of the information from disk. Neither short reads
* or EOF are acceptable, the bytes we want had better be there.
*/
if (b_disk != 0) {
p -= b_disk;
nr = b_disk;
if ((ret = __log_c_io(
logc, lsn->file, lsn->offset, p, &nr, NULL)) != 0)
return (ret);
if (nr < b_disk)
return (__log_c_shortread(logc, 0));
}
/* Copy the header information into the caller's structure. */
memcpy(hdr, p, hdr->size);
*pp = p;
return (0);
}
/*
* __log_c_ondisk --
* Read a record off disk.
*/
static int
__log_c_ondisk(logc, lsn, last_lsn, flags, hdr, pp, eofp)
DB_LOGC *logc;
DB_LSN *lsn, *last_lsn;
int flags, *eofp;
HDR *hdr;
u_int8_t **pp;
{
DB_ENV *dbenv;
size_t len, nr;
u_int32_t offset;
int ret;
dbenv = logc->dbenv;
*eofp = 0;
nr = hdr->size;
if ((ret =
__log_c_io(logc, lsn->file, lsn->offset, hdr, &nr, eofp)) != 0)
return (ret);
if (*eofp)
return (0);
/* If we read 0 bytes, assume we've hit EOF. */
if (nr == 0) {
*eofp = 1;
return (0);
}
/* Check the HDR. */
if ((ret = __log_c_hdrchk(logc, hdr, eofp)) != 0)
return (ret);
if (*eofp)
return (0);
/* Otherwise, we should have gotten the bytes we wanted. */
if (nr < hdr->size)
return (__log_c_shortread(logc, 0));
/*
* Regardless of how we return, the previous contents of the cursor's
* buffer are useless -- trash it.
*/
ZERO_LSN(logc->bp_lsn);
/*
* Otherwise, we now (finally!) know how big the record is. (Maybe
* we should have just stuck the length of the record into the LSN!?)
* Make sure we have enough space.
*/
if (logc->bp_size <= hdr->len) {
len = ALIGN(hdr->len * 2, 128);
if ((ret = __os_realloc(dbenv, len, &logc->bp)) != 0)
return (ret);
logc->bp_size = (u_int32_t)len;
}
/*
* If we're moving forward in the log file, read this record in at the
* beginning of the buffer. Otherwise, read this record in at the end
* of the buffer, making sure we don't try and read before the start
* of the file. (We prefer positioning at the end because transaction
* aborts use DB_SET to move backward through the log and we might get
* lucky.)
*
* Read a buffer's worth, without reading past the logical EOF. The
* last_lsn may be a zero LSN, but that's OK, the test works anyway.
*/
if (flags == DB_FIRST || flags == DB_NEXT)
offset = lsn->offset;
else if (lsn->offset + hdr->len < logc->bp_size)
offset = 0;
else
offset = (lsn->offset + hdr->len) - logc->bp_size;
nr = logc->bp_size;
if (lsn->file == last_lsn->file && offset + nr >= last_lsn->offset)
nr = last_lsn->offset - offset;
if ((ret =
__log_c_io(logc, lsn->file, offset, logc->bp, &nr, eofp)) != 0)
return (ret);
/*
* We should have at least gotten the bytes up-to-and-including the
* record we're reading.
*/
if (nr < (lsn->offset + hdr->len) - offset)
return (__log_c_shortread(logc, 1));
/* Set up the return information. */
logc->bp_rlen = (u_int32_t)nr;
logc->bp_lsn.file = lsn->file;
logc->bp_lsn.offset = offset;
*pp = logc->bp + (lsn->offset - offset);
return (0);
}
/*
* __log_c_hdrchk --
*
* Check for corrupted HDRs before we use them to allocate memory or find
* records.
*
* If the log files were pre-allocated, a zero-filled HDR structure is the
* logical file end. However, we can see buffers filled with 0's during
* recovery, too (because multiple log buffers were written asynchronously,
* and one made it to disk before a different one that logically precedes
* it in the log file.
*
* XXX
* I think there's a potential pre-allocation recovery flaw here -- if we
* fail to write a buffer at the end of a log file (by scheduling its
* write asynchronously, and it never making it to disk), then succeed in
* writing a log file block to a subsequent log file, I don't think we will
* detect that the buffer of 0's should have marked the end of the log files
* during recovery. I think we may need to always write some garbage after
* each block write if we pre-allocate log files. (At the moment, we do not
* pre-allocate, so this isn't currently an issue.)
*
* Check for impossibly large records. The malloc should fail later, but we
* have customers that run mallocs that treat all allocation failures as fatal
* errors.
*
* Note that none of this is necessarily something awful happening. We let
* the application hand us any LSN they want, and it could be a pointer into
* the middle of a log record, there's no way to tell.
*/
static int
__log_c_hdrchk(logc, hdr, eofp)
DB_LOGC *logc;
HDR *hdr;
int *eofp;
{
DB_ENV *dbenv;
int ret;
dbenv = logc->dbenv;
/* Sanity check the log record's size. */
if (hdr->len <= hdr->size)
goto err;
/*
* If the cursor's max-record value isn't yet set, it means we aren't
* reading these records from a log file and no check is necessary.
*/
if (logc->bp_maxrec != 0 && hdr->len > logc->bp_maxrec) {
/*
* If we fail the check, there's the pathological case that
* we're reading the last file, it's growing, and our initial
* check information was wrong. Get it again, to be sure.
*/
if ((ret = __log_c_set_maxrec(logc, NULL)) != 0) {
__db_err(dbenv, "DB_LOGC->get: %s", db_strerror(ret));
return (ret);
}
if (logc->bp_maxrec != 0 && hdr->len > logc->bp_maxrec)
goto err;
}
if (eofp != NULL) {
if (hdr->prev == 0 && hdr->chksum[0] == 0 && hdr->len == 0) {
*eofp = 1;
return (0);
}
*eofp = 0;
}
return (0);
err: if (!F_ISSET(logc, DB_LOG_SILENT_ERR))
__db_err(dbenv, "DB_LOGC->get: invalid log record header");
return (EIO);
}
/*
* __log_c_io --
* Read records from a log file.
*/
static int
__log_c_io(logc, fnum, offset, p, nrp, eofp)
DB_LOGC *logc;
u_int32_t fnum, offset;
void *p;
size_t *nrp;
int *eofp;
{
DB_ENV *dbenv;
DB_LOG *dblp;
int ret;
char *np;
dbenv = logc->dbenv;
dblp = dbenv->lg_handle;
/*
* If we've switched files, discard the current file handle and acquire
* a new one.
*/
if (F_ISSET(logc->c_fh, DB_FH_VALID) && logc->bp_lsn.file != fnum)
if ((ret = __os_closehandle(dbenv, logc->c_fh)) != 0)
return (ret);
if (!F_ISSET(logc->c_fh, DB_FH_VALID)) {
if ((ret = __log_name(dblp, fnum,
&np, logc->c_fh, DB_OSO_RDONLY | DB_OSO_SEQ)) != 0) {
/*
* If we're allowed to return EOF, assume that's the
* problem, set the EOF status flag and return 0.
*/
if (eofp != NULL) {
*eofp = 1;
ret = 0;
} else if (!F_ISSET(logc, DB_LOG_SILENT_ERR))
__db_err(dbenv, "DB_LOGC->get: %s: %s",
np, db_strerror(ret));
__os_free(dbenv, np);
return (ret);
}
if ((ret = __log_c_set_maxrec(logc, np)) != 0) {
__db_err(dbenv,
"DB_LOGC->get: %s: %s", np, db_strerror(ret));
__os_free(dbenv, np);
return (ret);
}
__os_free(dbenv, np);
}
/* Seek to the record's offset. */
if ((ret = __os_seek(dbenv,
logc->c_fh, 0, 0, offset, 0, DB_OS_SEEK_SET)) != 0) {
if (!F_ISSET(logc, DB_LOG_SILENT_ERR))
__db_err(dbenv,
"DB_LOGC->get: seek: %s", db_strerror(ret));
return (ret);
}
/* Read the data. */
if ((ret = __os_read(dbenv, logc->c_fh, p, *nrp, nrp)) != 0) {
if (!F_ISSET(logc, DB_LOG_SILENT_ERR))
__db_err(dbenv,
"DB_LOGC->get: read: %s", db_strerror(ret));
return (ret);
}
return (0);
}
/*
* __log_c_shortread --
* Read was short -- return a consistent error message and error.
*/
static int
__log_c_shortread(logc, silent)
DB_LOGC *logc;
int silent;
{
if (!silent || !F_ISSET(logc, DB_LOG_SILENT_ERR))
__db_err(logc->dbenv, "DB_LOGC->get: short read");
return (EIO);
}
/*
* __log_c_set_maxrec --
* Bound the maximum log record size in a log file.
*/
static int
__log_c_set_maxrec(logc, np)
DB_LOGC *logc;
char *np;
{
DB_ENV *dbenv;
DB_LOG *dblp;
LOG *lp;
u_int32_t mbytes, bytes;
int ret;
dbenv = logc->dbenv;
dblp = dbenv->lg_handle;
/*
* We don't want to try and allocate huge chunks of memory because
* applications with error-checking malloc's often consider that a
* hard failure. If we're about to look at a corrupted record with
* a bizarre size, we need to know before trying to allocate space
* to hold it. We could read the persistent data at the beginning
* of the file but that's hard -- we may have to decrypt it, checksum
* it and so on. Stat the file instead.
*/
if ((ret =
__os_ioinfo(dbenv, np, logc->c_fh, &mbytes, &bytes, NULL)) != 0)
return (ret);
logc->bp_maxrec = mbytes * MEGABYTE + bytes;
/*
* If reading from the log file currently being written, we could get
* an incorrect size, that is, if the cursor was opened on the file
* when it had only a few hundred bytes, and then the cursor used to
* move forward in the file, after more log records were written, the
* original stat value would be wrong. Use the maximum of the current
* log file size and the size of the buffer -- that should represent
* the max of any log record currently in the file.
*
* The log buffer size is set when the environment is opened and never
* changed, we don't need a lock on it.
*/
lp = dblp->reginfo.primary;
logc->bp_maxrec += lp->buffer_size;
return (0);
}