Update.
[glibc.git] / db2 / mp / mp_fset.c
blob3b352aa55328e85778b41ad89dcbe719cbd39f96
1 /*-
2 * See the file LICENSE for redistribution information.
4 * Copyright (c) 1996, 1997, 1998
5 * Sleepycat Software. All rights reserved.
6 */
7 #include "config.h"
9 #ifndef lint
10 static const char sccsid[] = "@(#)mp_fset.c 10.15 (Sleepycat) 4/26/98";
11 #endif /* not lint */
13 #ifndef NO_SYSTEM_INCLUDES
14 #include <sys/types.h>
16 #include <errno.h>
17 #endif
19 #include "db_int.h"
20 #include "shqueue.h"
21 #include "db_shash.h"
22 #include "mp.h"
23 #include "common_ext.h"
26 * memp_fset --
27 * Mpool page set-flag routine.
29 int
30 memp_fset(dbmfp, pgaddr, flags)
31 DB_MPOOLFILE *dbmfp;
32 void *pgaddr;
33 u_int32_t flags;
35 BH *bhp;
36 DB_MPOOL *dbmp;
37 MPOOL *mp;
38 int ret;
40 dbmp = dbmfp->dbmp;
41 mp = dbmp->mp;
43 /* Validate arguments. */
44 if (flags == 0)
45 return (__db_ferr(dbmp->dbenv, "memp_fset", 1));
47 if ((ret = __db_fchk(dbmp->dbenv, "memp_fset", flags,
48 DB_MPOOL_DIRTY | DB_MPOOL_CLEAN | DB_MPOOL_DISCARD)) != 0)
49 return (ret);
50 if ((ret = __db_fcchk(dbmp->dbenv, "memp_fset",
51 flags, DB_MPOOL_CLEAN, DB_MPOOL_DIRTY)) != 0)
52 return (ret);
54 if (LF_ISSET(DB_MPOOL_DIRTY) && F_ISSET(dbmfp, MP_READONLY)) {
55 __db_err(dbmp->dbenv,
56 "%s: dirty flag set for readonly file page",
57 __memp_fn(dbmfp));
58 return (EACCES);
61 /* Convert the page address to a buffer header. */
62 bhp = (BH *)((u_int8_t *)pgaddr - SSZA(BH, buf));
64 LOCKREGION(dbmp);
66 if (LF_ISSET(DB_MPOOL_CLEAN) && F_ISSET(bhp, BH_DIRTY)) {
67 ++mp->stat.st_page_clean;
68 --mp->stat.st_page_dirty;
69 F_CLR(bhp, BH_DIRTY);
71 if (LF_ISSET(DB_MPOOL_DIRTY) && !F_ISSET(bhp, BH_DIRTY)) {
72 --mp->stat.st_page_clean;
73 ++mp->stat.st_page_dirty;
74 F_SET(bhp, BH_DIRTY);
76 if (LF_ISSET(DB_MPOOL_DISCARD))
77 F_SET(bhp, BH_DISCARD);
79 UNLOCKREGION(dbmp);
80 return (0);