File: open.html

package info (click to toggle)
db 2%3A2.4.14-2.7.7.1.c
  • links: PTS
  • area: main
  • in suites: potato
  • size: 12,716 kB
  • ctags: 9,382
  • sloc: ansic: 35,556; tcl: 8,564; cpp: 4,890; sh: 2,075; makefile: 1,723; java: 1,632; sed: 419; awk: 153; asm: 41
file content (205 lines) | stat: -rw-r--r-- 7,605 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
<! "@(#)open.so	10.13 (Sleepycat) 10/4/98">
<!Copyright 1997, 1998 by Sleepycat Software, Inc.  All rights reserved.>
<html>
<body bgcolor=white>
<head>
<title>Berkeley DB: lock_open</title>
<meta name="description" content="Berkeley DB: An embedded database programmatic toolkit.">
<meta name="keywords" content="embedded,database,programmatic,toolkit,b+tree,btr
ee,hash,hashing,transaction,transactions,locking,logging,access method,access me
thods,java,C,C++">
</head>
<h1>lock_open</h1>
<hr size=1 noshade>
<tt>
<h3>
<pre>
#include &lt;db.h&gt;
<p>
int
lock_open(const char *dir, u_int32_t flags,
    int mode, DB_ENV *dbenv, DB_LOCKTAB **regionp);
</pre>
</h3>
<h1>Description</h1>
The lock_open
function copies a pointer, to the "lock region" identified by the <i>directory</i>
<b>dir</b>, into the memory location referenced by <b>regionp</b>.
<p>
The
<b>dir</b> pathname argument is interpreted as described in
<a href="../../ref/env/naming.html">Berkeley DB File Naming</a>.
<p>
The <b>flags</b> and <b>mode</b> arguments specify how files will be opened
and/or created if they do not already exist.
The flags value is specified by logically <b>OR</b>'ing together one or more of the
following values:
<dl compact>
<a name="DB_CREATE">
<p><dt>DB_CREATE<dd>Create any underlying files, as necessary.  If the files do not already
exist and the DB_CREATE flag is not specified, the call will fail.
<a name="DB_THREAD">
<p><dt>DB_THREAD<dd>Cause the m4_reg(DB_LOCKTAB) handle returned by lock_open to be useable
by multiple threads within a single address space, i.e., to be
<i>free-threaded</i>.
</dl>
<p>
All files created by the lock subsystem are created with mode <b>mode</b> (as described
in <b>chmod</b>(2)) and modified by the process' umask value at the time
of creation (see <b>umask</b>(2)))).
The group ownership of created files is based on the system and directory
defaults, and is not further specified by Berkeley DB.
<p>
The locking subsystem is configured
based on the <b>dbenv</b> argument to lock_open which is a pointer to
a structure of type DB_ENV.  Applications normally use the same DB_ENV
structure (initialized by <a href="../../api_c/DbEnv/appinit.html">db_appinit</a>) as an argument to all of
the subsystems in the Berkeley DB package.
<p>
References to the DB_ENV structure are maintained by Berkeley DB, so it may not
be discarded until the last close function, corresponding to an open
function for which it was an argument, has returned.  To ensure
compatibility with future releases of Berkeley DB, all fields of the DB_ENV
structure that are not explicitly set should be initialized to 0 before
the first time the structure is used.  Do this by declaring the structure
external or static, or by calling one of the C library routines
<b>bzero</b>(3) or <b>memset</b>(3).
<p>
The fields of the DB_ENV structure used by lock_open are described below.
If <b>dbenv</b> is NULL or any of its fields are set to 0, defaults
appropriate for the system are used where possible.
<p>
The following fields in the DB_ENV structure may be initialized before
calling lock_open:
<p>
<dl compact>
<p><dt>void *(*db_errcall)(char *db_errpfx, char *buffer);<dd>
<dt>FILE *db_errfile;<dd>
<dt>const char *db_errpfx;<dd>
<dt>int db_verbose;<dd>The error fields of the DB_ENV behave as described for <a href="../../api_c/DbEnv/appinit.html">db_appinit</a>.
<a name="lk_conflicts">
<p><dt>const u_int8_t lk_conflicts[][];<dd>A <b>lk_modes</b> by <b>lk_modes</b> array.
A non-0 value for the array element:
<p><ul><pre>lk_conflicts[requested_mode][held_mode]</pre></ul><p>
indicates that requested_mode and held_mode conflict.
The <i>not-granted</i> mode must be represented by 0.
If <b>lk_conflicts</b> is NULL, the conflicts array
<b>db_rw_conflicts</b> is used; see <a href="../../ref/lock/stdmode.html">Standard Lock Modes</a> for a description of that array.
<a name="lk_detect">
<p><dt>db_detect_t lk_detect;<dd>If non-0, specifies that the deadlock detector be run whenever a lock
conflict occurs, and specifies which transaction should be aborted in
the case of a deadlock.
The <b>lk_detect</b> field must be set to one of the following values.
<dl compact>
<a name="DB_LOCK_DEFAULT">
<p><dt>DB_LOCK_DEFAULT<dd>Use the default policy as specified by <a href="../../utility/db_deadlock.html">db_deadlock</a>.
<a name="DB_LOCK_OLDEST">
<p><dt>DB_LOCK_OLDEST<dd>Abort the oldest transaction.
<a name="DB_LOCK_RANDOM">
<p><dt>DB_LOCK_RANDOM<dd>Abort a random transaction involved in the deadlock.
<a name="DB_LOCK_YOUNGEST">
<p><dt>DB_LOCK_YOUNGEST<dd>Abort the youngest transaction.
</dl>
<a name="lk_max">
<p><dt>u_int32_t lk_max;<dd>The maximum number of locks to be held or requested in the table.
This value is used by lock_open to estimate how much space to
allocate for various lock-table data structures.
If <b>lk_max</b> is 0, a default value is used.
<a name="lk_modes">
<p><dt>u_int32_t lk_modes;<dd>The number of lock modes to be recognized by the lock table (including
the <i>not-granted</i> mode).  If <b>lk_modes</b> is 0, the value
<a href="../../ref/lock/stdmode.html">DB_LOCK_RW_N</a> is used.
</dl>
<p>
The lock_open
function returns the value of <b>errno</b> on failure, and 0 on success.
<p>
<h1>Environment Variables</h1>
<dl compact>
<p><dt>DB_HOME<dd>If the <b>dbenv</b> argument to lock_open was initialized using
<a href="../../api_c/DbEnv/appinit.html">db_appinit</a> the environment variable <b>DB_HOME</b> may
be used as the path of the database home for the interpretation of
the <b>dir</b> argument.
</dl>
<p>
<dl compact>
<p><dt>TMPDIR<dd>If the <b>dbenv</b> argument to lock_open was NULL or not initialized
using <a href="../../api_c/DbEnv/appinit.html">db_appinit</a> the environment variable <b>TMPDIR</b> may
be used as the directory in which to create the lock table, as described in
lock_open.
</dl>
<p>
<h1>Errors</h1>
If a fatal error occurs in Berkeley DB, the lock_open function may fail and return
DB_RUNRECOVERY, at which point all subsequent database calls will also
return DB_RUNRECOVERY.
<p>
The lock_open
function may fail and return <b>errno</b>
for any of the errors specified for the following Berkeley DB and C library
functions:
abort(3),
close(3),
<a href="../../api_c/DbEnv/version.html">db_version</a>,
fcntl(3),
fflush(3),
fprintf(3),
free(3),
fstat(3),
fsync(3),
getenv(3),
getpid(3),
getuid(3),
isdigit(3),
<a href="../../api_c/DbLockTab/unlink.html">lock_unlink</a>,
lseek(3),
malloc(3),
memcpy(3),
memset(3),
mmap(3),
munmap(3),
open(3),
pstat_getdynamic(3),
read(3),
shmat(3),
shmctl(3),
shmdt(3),
sigfillset(3),
sigprocmask(3),
stat(3),
strerror(3),
strlen(3),
sysconf(3),
unlink(3),
vfprintf(3),
vsnprintf(3),
and
write(3).
<p>
In addition, the lock_open
function may fail and return <b>errno</b>
for the following conditions:
<dl compact>
<p><dt>EAGAIN<dd>The shared memory region was locked and (repeatedly) unavailable.
</dl>
<dl compact>
<p><dt>EINVAL<dd>An invalid flag value or parameter was specified.
<p>
The DB_THREAD flag was specified and spinlocks are not implemented for
this architecture.
</dl>
<p>
<h1>See Also</h1>
<a href="../../api_c/DbLockTab/close.html">lock_close</a>,
<a href="../../api_c/DbLockTab/detect.html">lock_detect</a>,
<a href="../../api_c/DbLockTab/get.html">lock_get</a>,
<a href="../../api_c/DbLockTab/id.html">lock_id</a>,
lock_open,
<a href="../../api_c/DbLock/put.html">lock_put</a>,
<a href="../../api_c/DbLockTab/stat.html">lock_stat</a>,
<a href="../../api_c/DbLockTab/unlink.html">lock_unlink</a>
and
<a href="../../api_c/DbLockTab/vec.html">lock_vec</a>.
</tt>
</body>
</html>