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 (213 lines) | stat: -rw-r--r-- 8,620 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
206
207
208
209
210
211
212
213
<! "@(#)open.so	10.9 (Sleepycat) 10/2/98">
<!Copyright 1997, 1998 by Sleepycat Software, Inc.  All rights reserved.>
<html>
<body bgcolor=white>
<head>
<title>Berkeley DB: memp_fopen</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>memp_fopen</h1>
<hr size=1 noshade>
<tt>
<h3>
<pre>
#include &lt;db.h&gt;
<p>
int
memp_fopen(DB_MPOOL *mp, char *file, u_int32_t flags,
    int mode, size_t pagesize, DB_MPOOL_FINFO *finfop,
    DB_MPOOLFILE **mpf);
</pre>
</h3>
<h1>Description</h1>
<p>
The memp_fopen function opens a file in the pool specified by the
DB_MPOOL <b>mp</b>, copying the DB_MPOOLFILE pointer
representing it into the memory location referenced by <b>mpf</b>.
<p>
The <b>file</b> argument is the name of the file to be opened.
If <b>file</b> is NULL, a private file is created that cannot be
shared with any other process (although it may be shared with
other threads).
<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_NOMMAP">
<p><dt>DB_NOMMAP<dd>Always copy this file into the local cache instead of mapping it into
process memory (see the description of the <b>mp_mmapsize</b> field
of the DB_ENV structure for further information).
<a name="DB_RDONLY">
<p><dt>DB_RDONLY<dd>Open any underlying files for reading only.
Any attempt to write the file using the pool functions will fail,
regardless of the actual permissions of the file.
</dl>
<p>
All files created by the function memp_fopen 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 <b>pagesize</b> argument is the size, in bytes, of the unit of transfer
between the application and the pool, although it is not necessarily the
unit of transfer between the pool and the source file.
<p>
Files opened in the pool may be further configured based on the
<b>finfop</b> argument to memp_fopen, which is a pointer
to a structure of type DB_MPOOL_FINFO).
No references to the <b>finfop</b> structure are maintained by Berkeley DB,
so it may be discarded when the memp_fopen function returns.
In order to ensure compatibility with future releases of Berkeley DB, all fields
of the DB_MPOOL_FINFO 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 the
C library routine <b>bzero</b>(3) or <b>memset</b>(3).
<p>
The fields of the DB_MPOOL_FINFO structure used by memp_fopen are
described below.  If <b>finfop</b> is NULL or any of its fields are
set to their default value, defaults appropriate for the system are used.
<dl compact>
<a name="ftype">
<p><dt>int ftype;<dd>The <b>ftype</b> field should be the same as a <b>ftype</b> argument
previously specified to the <a href="../../api_c/DbMpool/db_register.html">memp_register</a> function, unless no
input or output processing of the file's pages are necessary, in which case
it should be 0.
(See the description of the <a href="../../api_c/DbMpool/db_register.html">memp_register</a> function for
more information.)
<a name="pgcookie">
<p><dt>DBT *pgcookie;<dd>The <b>pgcookie</b> field contains the byte string that is passed to the
<b>pgin</b> and <b>pgout</b> functions for this file, if any.  If no
<b>pgin</b> or <b>pgout</b> functions are specified, the <b>pgcookie</b>
field should be NULL.
(See the description of the <a href="../../api_c/DbMpool/db_register.html">memp_register</a> function for more
information.)
<a name="fileid">
<p><dt>u_int8_t *fileid;<dd>The <b>fileid</b> field is a unique identifier for the file.
The mpool functions must be able to uniquely identify files in order that
multiple processes sharing a file will correctly share its underlying pages.
Normally, the <b>fileid</b> field should be NULL and the mpool functions
will use the file's device and inode numbers (see <b>stat</b>(2))) for
this purpose.  On some filesystems, (e.g., FAT or NFS) file device and inode
numbers are not necessarily unique across system reboots.
<p>
<b>Applications wanting to maintain a shared memory buffer pool across system
reboots, where the pool contains pages from files stored on such filesystems,
must specify a unique file identifier to the memp_fopen call and
each process opening or registering the file must provide the same
unique identifier.</b>
<p>
If the <b>fileid</b> field is non-NULL, it must reference a DB_FILE_ID_LEN
length array of bytes that will be used to uniquely identify the file.
This should not be necessary for most applications.  Specifically, it is
not necessary if the memory pool is re-instantiated after each system
reboot, the application is using the Berkeley DB access methods instead of
calling the pool functions explicitly, or the files in the memory pool
are stored on filesystems where the file device and inode numbers do not
change across system reboots.
<a name="lsn_offset">
<p><dt>int32_t lsn_offset;<dd>The <b>lsn_offset</b> field is the zero-based byte offset in the page of
the page's log sequence number (LSN), or -1 if no LSN offset is specified.
(See the description of the <a href="../../api_c/DbMpool/sync.html">memp_sync</a> function for more
information.)
<a name="clear_len">
<p><dt>u_int32_t clear_len;<dd>The <b>clear_len</b> field is the number of initial bytes in a page
that should be set to zero when the page is created as a result of the
DB_MPOOL_CREATE or DB_MPOOL_NEW flags being specified to <a href="../../api_c/DbMpoolFile/get.html">memp_fget</a>.
If <b>finfop</b> is NULL or <b>clear_len</b> is 0, the entire page is
cleared.
</dl>
<p>
The memp_fopen
function returns the value of <b>errno</b> on failure, and 0 on success.
<p>
<h1>Errors</h1>
If a fatal error occurs in Berkeley DB, the memp_fopen function may fail and return
DB_RUNRECOVERY, at which point all subsequent database calls will also
return DB_RUNRECOVERY.
<p>
The memp_fopen
function may fail and return <b>errno</b>
for any of the errors specified for the following Berkeley DB and C library
functions:
DBmemp->pgin(3),
DBmemp->pgout(3),
abort(3),
close(3),
dbenv->db_paniccall(3),
fcntl(3),
fflush(3),
fprintf(3),
free(3),
fstat(3),
fsync(3),
getenv(3),
getpid(3),
getuid(3),
isdigit(3),
<a href="../../api_c/DbLog/compare.html">log_compare</a>,
<a href="../../api_c/DbLog/flush.html">log_flush</a>,
lseek(3),
malloc(3),
memcmp(3),
memcpy(3),
memset(3),
mmap(3),
open(3),
pread(3),
pstat_getdynamic(3),
pwrite(3),
read(3),
sigfillset(3),
sigprocmask(3),
stat(3),
strerror(3),
strlen(3),
sysconf(3),
time(3),
unlink(3),
vfprintf(3),
vsnprintf(3),
and
write(3).
<p>
In addition, the memp_fopen
function may fail and return <b>errno</b>
for the following conditions:
<dl compact>
<p><dt>EINVAL<dd>An invalid flag value or parameter was specified.
<p>
The file has already been entered into the pool, and the <b>pagesize</b>
value is not the same as when the file was entered into the pool, or the
length of the file is not zero or a multiple of the <b>pagesize</b>.
<p>
The DB_RDONLY flag was specified for an in-memory pool.
</dl>
<p>
<h1>See Also</h1>
<a href="../../api_c/DbMpool/close.html">memp_close</a>,
<a href="../../api_c/DbMpoolFile/close.html">memp_fclose</a>,
<a href="../../api_c/DbMpoolFile/get.html">memp_fget</a>,
memp_fopen,
<a href="../../api_c/DbMpoolFile/put.html">memp_fput</a>,
<a href="../../api_c/DbMpoolFile/set.html">memp_fset</a>,
<a href="../../api_c/DbMpoolFile/sync.html">memp_fsync</a>,
<a href="../../api_c/DbMpool/open.html">memp_open</a>,
<a href="../../api_c/DbMpool/db_register.html">memp_register</a>,
<a href="../../api_c/DbMpool/stat.html">memp_stat</a>,
<a href="../../api_c/DbMpool/stat.html">memp_stat</a>,
<a href="../../api_c/DbMpool/sync.html">memp_sync</a>,
<a href="../../api_c/DbMpool/trickle.html">memp_trickle</a>
and
<a href="../../api_c/DbMpool/unlink.html">memp_unlink</a>.
</tt>
</body>
</html>