1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
|
/*-
* See the file LICENSE for redistribution information.
*
* Copyright (c) 1999-2004
* Sleepycat Software. All rights reserved.
*
* $Id: hash_meta.c,v 11.31 2004/09/22 03:46:22 bostic Exp $
*/
#include "db_config.h"
#ifndef NO_SYSTEM_INCLUDES
#include <sys/types.h>
#endif
#include "db_int.h"
#include "dbinc/db_page.h"
#include "dbinc/db_shash.h"
#include "dbinc/hash.h"
#include "dbinc/lock.h"
#include "dbinc/mp.h"
/*
* Acquire the meta-data page.
*
* PUBLIC: int __ham_get_meta __P((DBC *));
*/
int
__ham_get_meta(dbc)
DBC *dbc;
{
DB *dbp;
DB_MPOOLFILE *mpf;
HASH *hashp;
HASH_CURSOR *hcp;
int ret;
dbp = dbc->dbp;
mpf = dbp->mpf;
hashp = dbp->h_internal;
hcp = (HASH_CURSOR *)dbc->internal;
if ((ret = __db_lget(dbc, 0,
hashp->meta_pgno, DB_LOCK_READ, 0, &hcp->hlock)) != 0)
return (ret);
if ((ret = __memp_fget(mpf,
&hashp->meta_pgno, DB_MPOOL_CREATE, &(hcp->hdr))) != 0)
(void)__LPUT(dbc, hcp->hlock);
return (ret);
}
/*
* Release the meta-data page.
*
* PUBLIC: int __ham_release_meta __P((DBC *));
*/
int
__ham_release_meta(dbc)
DBC *dbc;
{
DB_MPOOLFILE *mpf;
HASH_CURSOR *hcp;
mpf = dbc->dbp->mpf;
hcp = (HASH_CURSOR *)dbc->internal;
if (hcp->hdr)
(void)__memp_fput(mpf, hcp->hdr,
F_ISSET(hcp, H_DIRTY) ? DB_MPOOL_DIRTY : 0);
hcp->hdr = NULL;
F_CLR(hcp, H_DIRTY);
return (__TLPUT(dbc, hcp->hlock));
}
/*
* Mark the meta-data page dirty.
*
* PUBLIC: int __ham_dirty_meta __P((DBC *));
*/
int
__ham_dirty_meta(dbc)
DBC *dbc;
{
DB *dbp;
HASH *hashp;
HASH_CURSOR *hcp;
int ret;
dbp = dbc->dbp;
hashp = dbp->h_internal;
hcp = (HASH_CURSOR *)dbc->internal;
ret = 0;
ret = __db_lget(dbc, LCK_COUPLE,
hashp->meta_pgno, DB_LOCK_WRITE, 0, &hcp->hlock);
if (ret == 0)
F_SET(hcp, H_DIRTY);
return (ret);
}
|