Update.
[glibc.git] / db2 / mp / mp_fset.c
bloba7d270600805158180a635ba66ab22bdbacfccc7
1 /*-
2 * See the file LICENSE for redistribution information.
4 * Copyright (c) 1996, 1997
5 * Sleepycat Software. All rights reserved.
6 */
7 #include "config.h"
9 #ifndef lint
10 static const char sccsid[] = "@(#)mp_fset.c 10.10 (Sleepycat) 10/5/97";
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 int flags;
35 BH *bhp;
36 DB_MPOOL *dbmp;
37 MPOOL *mp;
38 MPOOLFILE *mfp;
39 int ret;
41 dbmp = dbmfp->dbmp;
42 mfp = dbmfp->mfp;
43 mp = dbmp->mp;
45 /* Validate arguments. */
46 if (flags != 0) {
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 dbmfp->path);
58 return (EACCES);
62 /* Convert the page address to a buffer header. */
63 bhp = (BH *)((u_int8_t *)pgaddr - SSZA(BH, buf));
65 LOCKREGION(dbmp);
67 if (LF_ISSET(DB_MPOOL_CLEAN) && F_ISSET(bhp, BH_DIRTY)) {
68 ++mp->stat.st_page_clean;
69 --mp->stat.st_page_dirty;
70 F_CLR(bhp, BH_DIRTY);
72 if (LF_ISSET(DB_MPOOL_DIRTY) && !F_ISSET(bhp, BH_DIRTY)) {
73 --mp->stat.st_page_clean;
74 ++mp->stat.st_page_dirty;
75 F_SET(bhp, BH_DIRTY);
77 if (LF_ISSET(DB_MPOOL_DISCARD))
78 F_SET(bhp, BH_DISCARD);
80 UNLOCKREGION(dbmp);
81 return (0);