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