Add BSD license file
[platform/upstream/db4.git] / log / log_compare.c
1 /*-
2  * See the file LICENSE for redistribution information.
3  *
4  * Copyright (c) 1996-2009 Oracle.  All rights reserved.
5  *
6  * $Id$
7  */
8
9 #include "db_config.h"
10
11 #include "db_int.h"
12 #include "dbinc/log.h"
13
14 /*
15  * log_compare --
16  *      Compare two LSN's; return 1, 0, -1 if first is >, == or < second.
17  *
18  * EXTERN: int log_compare __P((const DB_LSN *, const DB_LSN *));
19  */
20 int
21 log_compare(lsn0, lsn1)
22         const DB_LSN *lsn0, *lsn1;
23 {
24         return (LOG_COMPARE(lsn0, lsn1));
25 }
26
27 /*
28  * __log_check_page_lsn --
29  *      Panic if the page's lsn in past the end of the current log.
30  *
31  * PUBLIC: int __log_check_page_lsn __P((ENV *, DB *, DB_LSN *));
32  */
33 int
34 __log_check_page_lsn(env, dbp, lsnp)
35         ENV *env;
36         DB *dbp;
37         DB_LSN *lsnp;
38 {
39         LOG *lp;
40         int ret;
41
42         lp = env->lg_handle->reginfo.primary;
43         LOG_SYSTEM_LOCK(env);
44
45         ret = LOG_COMPARE(lsnp, &lp->lsn);
46
47         LOG_SYSTEM_UNLOCK(env);
48
49         if (ret < 0)
50                 return (0);
51
52         __db_errx(env,
53             "file %s has LSN %lu/%lu, past end of log at %lu/%lu",
54             dbp == NULL || dbp->fname == NULL ? "unknown" : dbp->fname,
55             (u_long)lsnp->file, (u_long)lsnp->offset,
56             (u_long)lp->lsn.file, (u_long)lp->lsn.offset);
57         __db_errx(env, "%s",
58     "Commonly caused by moving a database from one database environment");
59         __db_errx(env, "%s",
60     "to another without clearing the database LSNs, or by removing all of");
61         __db_errx(env, "%s",
62     "the log files from a database environment");
63         return (EINVAL);
64 }