1/*	$NetBSD$	*/
2
3/* alock.h - access lock header */
4/* OpenLDAP: pkg/ldap/servers/slapd/alock.h,v 1.3.2.6 2010/04/13 20:23:10 kurt Exp */
5/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
6 *
7 * Copyright 2005-2010 The OpenLDAP Foundation.
8 * Portions Copyright 2004-2005 Symas Corporation.
9 * All rights reserved.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted only as authorized by the OpenLDAP
13 * Public License.
14 *
15 * A copy of this license is available in the file LICENSE in the
16 * top-level directory of the distribution or, alternatively, at
17 * <http://www.OpenLDAP.org/license.html>.
18 */
19/* ACKNOWLEDGEMENTS:
20 * This work was initially developed by Matthew Backes at Symas
21 * Corporation for inclusion in OpenLDAP Software.
22 */
23
24#ifndef _ALOCK_H_
25#define _ALOCK_H_
26
27#include "portable.h"
28#include <ac/time.h>
29#include <ac/unistd.h>
30
31/* environment states (all the slots together) */
32#define ALOCK_CLEAN		(0)
33#define ALOCK_RECOVER	(1)
34#define ALOCK_BUSY		(2)
35#define ALOCK_UNSTABLE	(3)
36
37/* lock user types and states */
38#define ALOCK_UNLOCKED	(0)
39#define ALOCK_LOCKED	(1)
40#define ALOCK_UNIQUE	(2)
41#define ALOCK_DIRTY		(3)
42
43#define ALOCK_SMASK		3
44
45/* lock/state where recovery is not available */
46#define	ALOCK_NOSAVE	4
47
48/* constants */
49#define ALOCK_SLOT_SIZE		(1024)
50#define ALOCK_SLOT_IATTRS	(4)
51#define ALOCK_MAX_APPNAME	(ALOCK_SLOT_SIZE - 8 * ALOCK_SLOT_IATTRS)
52#define ALOCK_MAGIC			(0x12345678)
53
54LDAP_BEGIN_DECL
55
56typedef struct alock_info {
57	int al_fd;
58	int al_slot;
59} alock_info_t;
60
61typedef struct alock_slot {
62	unsigned int al_lock;
63	time_t al_stamp;
64	pid_t al_pid;
65	char * al_appname;
66} alock_slot_t;
67
68LDAP_SLAPD_F (int) alock_open LDAP_P(( alock_info_t * info, const char * appname,
69	const char * envdir, int locktype ));
70LDAP_SLAPD_F (int) alock_scan LDAP_P(( alock_info_t * info ));
71LDAP_SLAPD_F (int) alock_close LDAP_P(( alock_info_t * info, int nosave ));
72LDAP_SLAPD_F (int) alock_recover LDAP_P(( alock_info_t * info ));
73
74LDAP_END_DECL
75
76#endif
77