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