xref: /freebsd/lib/libc/db/man/dbopen.3 (revision dc36d6f9bb1753f3808552f3afd30eda9a7b206a)
158f0484fSRodney W. Grimes.\" Copyright (c) 1990, 1993
258f0484fSRodney W. Grimes.\"	The Regents of the University of California.  All rights reserved.
358f0484fSRodney W. Grimes.\"
458f0484fSRodney W. Grimes.\" Redistribution and use in source and binary forms, with or without
558f0484fSRodney W. Grimes.\" modification, are permitted provided that the following conditions
658f0484fSRodney W. Grimes.\" are met:
758f0484fSRodney W. Grimes.\" 1. Redistributions of source code must retain the above copyright
858f0484fSRodney W. Grimes.\"    notice, this list of conditions and the following disclaimer.
958f0484fSRodney W. Grimes.\" 2. Redistributions in binary form must reproduce the above copyright
1058f0484fSRodney W. Grimes.\"    notice, this list of conditions and the following disclaimer in the
1158f0484fSRodney W. Grimes.\"    documentation and/or other materials provided with the distribution.
12*fbbd9655SWarner Losh.\" 3. Neither the name of the University nor the names of its contributors
1358f0484fSRodney W. Grimes.\"    may be used to endorse or promote products derived from this software
1458f0484fSRodney W. Grimes.\"    without specific prior written permission.
1558f0484fSRodney W. Grimes.\"
1658f0484fSRodney W. Grimes.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
1758f0484fSRodney W. Grimes.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1858f0484fSRodney W. Grimes.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1958f0484fSRodney W. Grimes.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2058f0484fSRodney W. Grimes.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2158f0484fSRodney W. Grimes.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2258f0484fSRodney W. Grimes.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2358f0484fSRodney W. Grimes.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2458f0484fSRodney W. Grimes.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2558f0484fSRodney W. Grimes.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2658f0484fSRodney W. Grimes.\" SUCH DAMAGE.
2758f0484fSRodney W. Grimes.\"
28416d1e6fSGlen Barber.Dd September 10, 2010
29d74f3e32SRuslan Ermilov.Dt DBOPEN 3
30d74f3e32SRuslan Ermilov.Os
31d74f3e32SRuslan Ermilov.Sh NAME
32d74f3e32SRuslan Ermilov.Nm dbopen
33d74f3e32SRuslan Ermilov.Nd "database access methods"
34d74f3e32SRuslan Ermilov.Sh SYNOPSIS
3532eef9aeSRuslan Ermilov.In sys/types.h
3632eef9aeSRuslan Ermilov.In db.h
379e542d7dSMark Murray.In fcntl.h
389e542d7dSMark Murray.In limits.h
39d74f3e32SRuslan Ermilov.Ft DB *
40d74f3e32SRuslan Ermilov.Fn dbopen "const char *file" "int flags" "int mode" "DBTYPE type" "const void *openinfo"
41d74f3e32SRuslan Ermilov.Sh DESCRIPTION
421fae73b1SRuslan ErmilovThe
431fae73b1SRuslan Ermilov.Fn dbopen
441fae73b1SRuslan Ermilovfunction
4558f0484fSRodney W. Grimesis the library interface to database files.
4658f0484fSRodney W. GrimesThe supported file formats are btree, hashed and UNIX file oriented.
4758f0484fSRodney W. GrimesThe btree format is a representation of a sorted, balanced tree structure.
4858f0484fSRodney W. GrimesThe hashed format is an extensible, dynamic hashing scheme.
4958f0484fSRodney W. GrimesThe flat-file format is a byte stream file with fixed or variable length
5058f0484fSRodney W. Grimesrecords.
5158f0484fSRodney W. GrimesThe formats and file format specific information are described in detail
5258f0484fSRodney W. Grimesin their respective manual pages
53d74f3e32SRuslan Ermilov.Xr btree 3 ,
54d74f3e32SRuslan Ermilov.Xr hash 3
5558f0484fSRodney W. Grimesand
56d74f3e32SRuslan Ermilov.Xr recno 3 .
57d74f3e32SRuslan Ermilov.Pp
581fae73b1SRuslan ErmilovThe
591fae73b1SRuslan Ermilov.Fn dbopen
601fae73b1SRuslan Ermilovfunction
61d74f3e32SRuslan Ermilovopens
62d74f3e32SRuslan Ermilov.Fa file
6358f0484fSRodney W. Grimesfor reading and/or writing.
6458f0484fSRodney W. GrimesFiles never intended to be preserved on disk may be created by setting
652efeeba5SRuslan Ermilovthe
662efeeba5SRuslan Ermilov.Fa file
672efeeba5SRuslan Ermilovargument to
68d74f3e32SRuslan Ermilov.Dv NULL .
69d74f3e32SRuslan Ermilov.Pp
7058f0484fSRodney W. GrimesThe
71d74f3e32SRuslan Ermilov.Fa flags
7258f0484fSRodney W. Grimesand
73d74f3e32SRuslan Ermilov.Fa mode
74d74f3e32SRuslan Ermilovarguments
7558f0484fSRodney W. Grimesare as specified to the
76d74f3e32SRuslan Ermilov.Xr open 2
77d74f3e32SRuslan Ermilovroutine, however, only the
781569ab8cSGlen Barber.Dv O_CREAT , O_EXCL , O_EXLOCK , O_NOFOLLOW , O_NONBLOCK ,
791569ab8cSGlen Barber.Dv O_RDONLY , O_RDWR , O_SHLOCK , O_SYNC
80d74f3e32SRuslan Ermilovand
81d74f3e32SRuslan Ermilov.Dv O_TRUNC
82d74f3e32SRuslan Ermilovflags are meaningful.
83d74f3e32SRuslan Ermilov(Note, opening a database file
84d74f3e32SRuslan Ermilov.Dv O_WRONLY
85d74f3e32SRuslan Ermilovis not possible.)
8658f0484fSRodney W. Grimes.\"Three additional options may be specified by
87d74f3e32SRuslan Ermilov.\".Em or Ns 'ing
8858f0484fSRodney W. Grimes.\"them into the
89d74f3e32SRuslan Ermilov.\".Fa flags
9058f0484fSRodney W. Grimes.\"argument.
91d74f3e32SRuslan Ermilov.\".Bl -tag -width indent
92d74f3e32SRuslan Ermilov.\".It Dv DB_LOCK
9358f0484fSRodney W. Grimes.\"Do the necessary locking in the database to support concurrent access.
940227791bSRuslan Ermilov.\"If concurrent access is not needed or the database is read-only this
9558f0484fSRodney W. Grimes.\"flag should not be set, as it tends to have an associated performance
9658f0484fSRodney W. Grimes.\"penalty.
97d74f3e32SRuslan Ermilov.\".It Dv DB_SHMEM
9858f0484fSRodney W. Grimes.\"Place the underlying memory pool used by the database in shared
9958f0484fSRodney W. Grimes.\"memory.
10058f0484fSRodney W. Grimes.\"Necessary for concurrent access.
101d74f3e32SRuslan Ermilov.\".It Dv DB_TXN
10258f0484fSRodney W. Grimes.\"Support transactions in the database.
103d74f3e32SRuslan Ermilov.\"The
104d74f3e32SRuslan Ermilov.\".Dv DB_LOCK
105d74f3e32SRuslan Ermilov.\"and
106d74f3e32SRuslan Ermilov.\".Dv DB_SHMEM
107d74f3e32SRuslan Ermilov.\"flags must be set as well.
108d74f3e32SRuslan Ermilov.\".El
109d74f3e32SRuslan Ermilov.Pp
11058f0484fSRodney W. GrimesThe
111d74f3e32SRuslan Ermilov.Fa type
112d74f3e32SRuslan Ermilovargument is of type
113d74f3e32SRuslan Ermilov.Ft DBTYPE
114d74f3e32SRuslan Ermilov(as defined in the
115fe08efe6SRuslan Ermilov.In db.h
116d74f3e32SRuslan Ermilovinclude file) and
117d74f3e32SRuslan Ermilovmay be set to
118d74f3e32SRuslan Ermilov.Dv DB_BTREE , DB_HASH
119d74f3e32SRuslan Ermilovor
120d74f3e32SRuslan Ermilov.Dv DB_RECNO .
121d74f3e32SRuslan Ermilov.Pp
12258f0484fSRodney W. GrimesThe
123d74f3e32SRuslan Ermilov.Fa openinfo
12458f0484fSRodney W. Grimesargument is a pointer to an access method specific structure described
12558f0484fSRodney W. Grimesin the access method's manual page.
12658f0484fSRodney W. GrimesIf
127d74f3e32SRuslan Ermilov.Fa openinfo
128d74f3e32SRuslan Ermilovis
129d74f3e32SRuslan Ermilov.Dv NULL ,
130d74f3e32SRuslan Ermiloveach access method will use defaults appropriate for the system
13158f0484fSRodney W. Grimesand the access method.
132d74f3e32SRuslan Ermilov.Pp
1331fae73b1SRuslan ErmilovThe
1341fae73b1SRuslan Ermilov.Fn dbopen
1351fae73b1SRuslan Ermilovfunction
136d74f3e32SRuslan Ermilovreturns a pointer to a
137d74f3e32SRuslan Ermilov.Ft DB
138d74f3e32SRuslan Ermilovstructure on success and
139d74f3e32SRuslan Ermilov.Dv NULL
140d74f3e32SRuslan Ermilovon error.
141d74f3e32SRuslan ErmilovThe
142d74f3e32SRuslan Ermilov.Ft DB
143d74f3e32SRuslan Ermilovstructure is defined in the
144fe08efe6SRuslan Ermilov.In db.h
145d74f3e32SRuslan Ermilovinclude file, and contains at
14658f0484fSRodney W. Grimesleast the following fields:
147d74f3e32SRuslan Ermilov.Bd -literal
14858f0484fSRodney W. Grimestypedef struct {
14958f0484fSRodney W. Grimes	DBTYPE type;
15016ca32b3SStefan Farfeleder	int (*close)(DB *db);
15158f0484fSRodney W. Grimes	int (*del)(const DB *db, const DBT *key, u_int flags);
15258f0484fSRodney W. Grimes	int (*fd)(const DB *db);
15316ca32b3SStefan Farfeleder	int (*get)(const DB *db, const DBT *key, DBT *data, u_int flags);
15458f0484fSRodney W. Grimes	int (*put)(const DB *db, DBT *key, const DBT *data,
15558f0484fSRodney W. Grimes	     u_int flags);
15658f0484fSRodney W. Grimes	int (*sync)(const DB *db, u_int flags);
15758f0484fSRodney W. Grimes	int (*seq)(const DB *db, DBT *key, DBT *data, u_int flags);
15858f0484fSRodney W. Grimes} DB;
159d74f3e32SRuslan Ermilov.Ed
160d74f3e32SRuslan Ermilov.Pp
16158f0484fSRodney W. GrimesThese elements describe a database type and a set of functions performing
16258f0484fSRodney W. Grimesvarious actions.
16358f0484fSRodney W. GrimesThese functions take a pointer to a structure as returned by
164d74f3e32SRuslan Ermilov.Fn dbopen ,
16558f0484fSRodney W. Grimesand sometimes one or more pointers to key/data structures and a flag value.
166d74f3e32SRuslan Ermilov.Bl -tag -width indent
167d74f3e32SRuslan Ermilov.It Va type
16858f0484fSRodney W. GrimesThe type of the underlying access method (and file format).
169d74f3e32SRuslan Ermilov.It Va close
17058f0484fSRodney W. GrimesA pointer to a routine to flush any cached information to disk, free any
17158f0484fSRodney W. Grimesallocated resources, and close the underlying file(s).
17258f0484fSRodney W. GrimesSince key/data pairs may be cached in memory, failing to sync the file
17358f0484fSRodney W. Grimeswith a
174d74f3e32SRuslan Ermilov.Va close
17558f0484fSRodney W. Grimesor
176d74f3e32SRuslan Ermilov.Va sync
17758f0484fSRodney W. Grimesfunction may result in inconsistent or lost information.
1782efeeba5SRuslan Ermilov.Va close
17958f0484fSRodney W. Grimesroutines return -1 on error (setting
180d74f3e32SRuslan Ermilov.Va errno )
18158f0484fSRodney W. Grimesand 0 on success.
182d74f3e32SRuslan Ermilov.It Va del
18358f0484fSRodney W. GrimesA pointer to a routine to remove key/data pairs from the database.
184d74f3e32SRuslan Ermilov.Pp
1852efeeba5SRuslan ErmilovThe
186d74f3e32SRuslan Ermilov.Fa flags
1872efeeba5SRuslan Ermilovargument
18858f0484fSRodney W. Grimesmay be set to the following value:
189d74f3e32SRuslan Ermilov.Bl -tag -width indent
190d74f3e32SRuslan Ermilov.It Dv R_CURSOR
19158f0484fSRodney W. GrimesDelete the record referenced by the cursor.
19258f0484fSRodney W. GrimesThe cursor must have previously been initialized.
193d74f3e32SRuslan Ermilov.El
194d74f3e32SRuslan Ermilov.Pp
1952efeeba5SRuslan Ermilov.Va delete
19658f0484fSRodney W. Grimesroutines return -1 on error (setting
197d74f3e32SRuslan Ermilov.Va errno ) ,
19858f0484fSRodney W. Grimes0 on success, and 1 if the specified
199d74f3e32SRuslan Ermilov.Fa key
20058f0484fSRodney W. Grimeswas not in the file.
201d74f3e32SRuslan Ermilov.It Va fd
20258f0484fSRodney W. GrimesA pointer to a routine which returns a file descriptor representative
20358f0484fSRodney W. Grimesof the underlying database.
20458f0484fSRodney W. GrimesA file descriptor referencing the same file will be returned to all
20558f0484fSRodney W. Grimesprocesses which call
206d74f3e32SRuslan Ermilov.Fn dbopen
20758f0484fSRodney W. Grimeswith the same
208d74f3e32SRuslan Ermilov.Fa file
20958f0484fSRodney W. Grimesname.
21058f0484fSRodney W. GrimesThis file descriptor may be safely used as an argument to the
211d74f3e32SRuslan Ermilov.Xr fcntl 2
21258f0484fSRodney W. Grimesand
213d74f3e32SRuslan Ermilov.Xr flock 2
21458f0484fSRodney W. Grimeslocking functions.
21558f0484fSRodney W. GrimesThe file descriptor is not necessarily associated with any of the
21658f0484fSRodney W. Grimesunderlying files used by the access method.
21758f0484fSRodney W. GrimesNo file descriptor is available for in memory databases.
218d74f3e32SRuslan Ermilov.Va \&Fd
21958f0484fSRodney W. Grimesroutines return -1 on error (setting
220d74f3e32SRuslan Ermilov.Va errno ) ,
22158f0484fSRodney W. Grimesand the file descriptor on success.
222d74f3e32SRuslan Ermilov.It Va get
22358f0484fSRodney W. GrimesA pointer to a routine which is the interface for keyed retrieval from
22458f0484fSRodney W. Grimesthe database.
22558f0484fSRodney W. GrimesThe address and length of the data associated with the specified
226d74f3e32SRuslan Ermilov.Fa key
22758f0484fSRodney W. Grimesare returned in the structure referenced by
228d74f3e32SRuslan Ermilov.Fa data .
2292efeeba5SRuslan Ermilov.Va get
23058f0484fSRodney W. Grimesroutines return -1 on error (setting
231d74f3e32SRuslan Ermilov.Va errno ) ,
23258f0484fSRodney W. Grimes0 on success, and 1 if the
233d74f3e32SRuslan Ermilov.Fa key
23458f0484fSRodney W. Grimeswas not in the file.
235d74f3e32SRuslan Ermilov.It Va put
23658f0484fSRodney W. GrimesA pointer to a routine to store key/data pairs in the database.
237d74f3e32SRuslan Ermilov.Pp
2382efeeba5SRuslan ErmilovThe
239d74f3e32SRuslan Ermilov.Fa flags
2402efeeba5SRuslan Ermilovargument
24158f0484fSRodney W. Grimesmay be set to one of the following values:
242d74f3e32SRuslan Ermilov.Bl -tag -width indent
243d74f3e32SRuslan Ermilov.It Dv R_CURSOR
24458f0484fSRodney W. GrimesReplace the key/data pair referenced by the cursor.
24558f0484fSRodney W. GrimesThe cursor must have previously been initialized.
246d74f3e32SRuslan Ermilov.It Dv R_IAFTER
24758f0484fSRodney W. GrimesAppend the data immediately after the data referenced by
248d74f3e32SRuslan Ermilov.Fa key ,
24958f0484fSRodney W. Grimescreating a new key/data pair.
25058f0484fSRodney W. GrimesThe record number of the appended key/data pair is returned in the
251d74f3e32SRuslan Ermilov.Fa key
25258f0484fSRodney W. Grimesstructure.
253d74f3e32SRuslan Ermilov(Applicable only to the
254d74f3e32SRuslan Ermilov.Dv DB_RECNO
255d74f3e32SRuslan Ermilovaccess method.)
256d74f3e32SRuslan Ermilov.It Dv R_IBEFORE
25758f0484fSRodney W. GrimesInsert the data immediately before the data referenced by
258d74f3e32SRuslan Ermilov.Fa key ,
25958f0484fSRodney W. Grimescreating a new key/data pair.
26058f0484fSRodney W. GrimesThe record number of the inserted key/data pair is returned in the
261d74f3e32SRuslan Ermilov.Fa key
26258f0484fSRodney W. Grimesstructure.
263d74f3e32SRuslan Ermilov(Applicable only to the
264d74f3e32SRuslan Ermilov.Dv DB_RECNO
265d74f3e32SRuslan Ermilovaccess method.)
266d74f3e32SRuslan Ermilov.It Dv R_NOOVERWRITE
26758f0484fSRodney W. GrimesEnter the new key/data pair only if the key does not previously exist.
268d74f3e32SRuslan Ermilov.It Dv R_SETCURSOR
26958f0484fSRodney W. GrimesStore the key/data pair, setting or initializing the position of the
27058f0484fSRodney W. Grimescursor to reference it.
271d74f3e32SRuslan Ermilov(Applicable only to the
272d74f3e32SRuslan Ermilov.Dv DB_BTREE
273d74f3e32SRuslan Ermilovand
274d74f3e32SRuslan Ermilov.Dv DB_RECNO
275d74f3e32SRuslan Ermilovaccess methods.)
276d74f3e32SRuslan Ermilov.El
277d74f3e32SRuslan Ermilov.Pp
278d74f3e32SRuslan Ermilov.Dv R_SETCURSOR
279d74f3e32SRuslan Ermilovis available only for the
280d74f3e32SRuslan Ermilov.Dv DB_BTREE
281d74f3e32SRuslan Ermilovand
282d74f3e32SRuslan Ermilov.Dv DB_RECNO
283d74f3e32SRuslan Ermilovaccess
28458f0484fSRodney W. Grimesmethods because it implies that the keys have an inherent order
28558f0484fSRodney W. Grimeswhich does not change.
286d74f3e32SRuslan Ermilov.Pp
287d74f3e32SRuslan Ermilov.Dv R_IAFTER
288d74f3e32SRuslan Ermilovand
289d74f3e32SRuslan Ermilov.Dv R_IBEFORE
290d74f3e32SRuslan Ermilovare available only for the
291d74f3e32SRuslan Ermilov.Dv DB_RECNO
29258f0484fSRodney W. Grimesaccess method because they each imply that the access method is able to
29358f0484fSRodney W. Grimescreate new keys.
29458f0484fSRodney W. GrimesThis is only true if the keys are ordered and independent, record numbers
29558f0484fSRodney W. Grimesfor example.
296d74f3e32SRuslan Ermilov.Pp
29758f0484fSRodney W. GrimesThe default behavior of the
298d74f3e32SRuslan Ermilov.Va put
29958f0484fSRodney W. Grimesroutines is to enter the new key/data pair, replacing any previously
30058f0484fSRodney W. Grimesexisting key.
301d74f3e32SRuslan Ermilov.Pp
3022efeeba5SRuslan Ermilov.Va put
30358f0484fSRodney W. Grimesroutines return -1 on error (setting
304d74f3e32SRuslan Ermilov.Va errno ) ,
305d74f3e32SRuslan Ermilov0 on success, and 1 if the
306d74f3e32SRuslan Ermilov.Dv R_NOOVERWRITE
307d74f3e32SRuslan Ermilovflag
30858f0484fSRodney W. Grimeswas set and the key already exists in the file.
309d74f3e32SRuslan Ermilov.It Va seq
31058f0484fSRodney W. GrimesA pointer to a routine which is the interface for sequential
31158f0484fSRodney W. Grimesretrieval from the database.
31258f0484fSRodney W. GrimesThe address and length of the key are returned in the structure
31358f0484fSRodney W. Grimesreferenced by
314d74f3e32SRuslan Ermilov.Fa key ,
31558f0484fSRodney W. Grimesand the address and length of the data are returned in the
31658f0484fSRodney W. Grimesstructure referenced
31758f0484fSRodney W. Grimesby
318d74f3e32SRuslan Ermilov.Fa data .
319d74f3e32SRuslan Ermilov.Pp
32058f0484fSRodney W. GrimesSequential key/data pair retrieval may begin at any time, and the
321d74f3e32SRuslan Ermilovposition of the
322d74f3e32SRuslan Ermilov.Dq cursor
323d74f3e32SRuslan Ermilovis not affected by calls to the
324d74f3e32SRuslan Ermilov.Va del ,
325d74f3e32SRuslan Ermilov.Va get ,
326d74f3e32SRuslan Ermilov.Va put ,
32758f0484fSRodney W. Grimesor
328d74f3e32SRuslan Ermilov.Va sync
32958f0484fSRodney W. Grimesroutines.
33058f0484fSRodney W. GrimesModifications to the database during a sequential scan will be reflected
3311a0a9345SRuslan Ermilovin the scan, i.e., records inserted behind the cursor will not be returned
33258f0484fSRodney W. Grimeswhile records inserted in front of the cursor will be returned.
333d74f3e32SRuslan Ermilov.Pp
334d74f3e32SRuslan ErmilovThe
335d74f3e32SRuslan Ermilov.Fa flags
3362efeeba5SRuslan Ermilovargument
337d74f3e32SRuslan Ermilov.Em must
33858f0484fSRodney W. Grimesbe set to one of the following values:
339d74f3e32SRuslan Ermilov.Bl -tag -width indent
340d74f3e32SRuslan Ermilov.It Dv R_CURSOR
34158f0484fSRodney W. GrimesThe data associated with the specified key is returned.
34258f0484fSRodney W. GrimesThis differs from the
343d74f3e32SRuslan Ermilov.Va get
34458f0484fSRodney W. Grimesroutines in that it sets or initializes the cursor to the location of
34558f0484fSRodney W. Grimesthe key as well.
346d74f3e32SRuslan Ermilov(Note, for the
347d74f3e32SRuslan Ermilov.Dv DB_BTREE
348d74f3e32SRuslan Ermilovaccess method, the returned key is not necessarily an
34958f0484fSRodney W. Grimesexact match for the specified key.
35058f0484fSRodney W. GrimesThe returned key is the smallest key greater than or equal to the specified
35158f0484fSRodney W. Grimeskey, permitting partial key matches and range searches.)
352d74f3e32SRuslan Ermilov.It Dv R_FIRST
35358f0484fSRodney W. GrimesThe first key/data pair of the database is returned, and the cursor
35458f0484fSRodney W. Grimesis set or initialized to reference it.
355d74f3e32SRuslan Ermilov.It Dv R_LAST
35658f0484fSRodney W. GrimesThe last key/data pair of the database is returned, and the cursor
35758f0484fSRodney W. Grimesis set or initialized to reference it.
358d74f3e32SRuslan Ermilov(Applicable only to the
359d74f3e32SRuslan Ermilov.Dv DB_BTREE
360d74f3e32SRuslan Ermilovand
361d74f3e32SRuslan Ermilov.Dv DB_RECNO
362d74f3e32SRuslan Ermilovaccess methods.)
363d74f3e32SRuslan Ermilov.It Dv R_NEXT
36458f0484fSRodney W. GrimesRetrieve the key/data pair immediately after the cursor.
365d74f3e32SRuslan ErmilovIf the cursor is not yet set, this is the same as the
366d74f3e32SRuslan Ermilov.Dv R_FIRST
367d74f3e32SRuslan Ermilovflag.
368d74f3e32SRuslan Ermilov.It Dv R_PREV
36958f0484fSRodney W. GrimesRetrieve the key/data pair immediately before the cursor.
370d74f3e32SRuslan ErmilovIf the cursor is not yet set, this is the same as the
371d74f3e32SRuslan Ermilov.Dv R_LAST
372d74f3e32SRuslan Ermilovflag.
373d74f3e32SRuslan Ermilov(Applicable only to the
374d74f3e32SRuslan Ermilov.Dv DB_BTREE
375d74f3e32SRuslan Ermilovand
376d74f3e32SRuslan Ermilov.Dv DB_RECNO
377d74f3e32SRuslan Ermilovaccess methods.)
378d74f3e32SRuslan Ermilov.El
379d74f3e32SRuslan Ermilov.Pp
380d74f3e32SRuslan Ermilov.Dv R_LAST
381d74f3e32SRuslan Ermilovand
382d74f3e32SRuslan Ermilov.Dv R_PREV
383d74f3e32SRuslan Ermilovare available only for the
384d74f3e32SRuslan Ermilov.Dv DB_BTREE
385d74f3e32SRuslan Ermilovand
386d74f3e32SRuslan Ermilov.Dv DB_RECNO
38758f0484fSRodney W. Grimesaccess methods because they each imply that the keys have an inherent
38858f0484fSRodney W. Grimesorder which does not change.
389d74f3e32SRuslan Ermilov.Pp
3902efeeba5SRuslan Ermilov.Va seq
39158f0484fSRodney W. Grimesroutines return -1 on error (setting
392d74f3e32SRuslan Ermilov.Va errno ) ,
39358f0484fSRodney W. Grimes0 on success and 1 if there are no key/data pairs less than or greater
39458f0484fSRodney W. Grimesthan the specified or current key.
395d74f3e32SRuslan ErmilovIf the
396d74f3e32SRuslan Ermilov.Dv DB_RECNO
397d74f3e32SRuslan Ermilovaccess method is being used, and if the database file
39858f0484fSRodney W. Grimesis a character special file and no complete key/data pairs are currently
39958f0484fSRodney W. Grimesavailable, the
400d74f3e32SRuslan Ermilov.Va seq
40158f0484fSRodney W. Grimesroutines return 2.
402d74f3e32SRuslan Ermilov.It Va sync
40358f0484fSRodney W. GrimesA pointer to a routine to flush any cached information to disk.
40458f0484fSRodney W. GrimesIf the database is in memory only, the
405d74f3e32SRuslan Ermilov.Va sync
40658f0484fSRodney W. Grimesroutine has no effect and will always succeed.
407d74f3e32SRuslan Ermilov.Pp
408d74f3e32SRuslan ErmilovThe
409d74f3e32SRuslan Ermilov.Fa flags
4102efeeba5SRuslan Ermilovargument may be set to the following value:
411d74f3e32SRuslan Ermilov.Bl -tag -width indent
412d74f3e32SRuslan Ermilov.It Dv R_RECNOSYNC
413d74f3e32SRuslan ErmilovIf the
414d74f3e32SRuslan Ermilov.Dv DB_RECNO
415d74f3e32SRuslan Ermilovaccess method is being used, this flag causes
416d74f3e32SRuslan Ermilovthe
417d74f3e32SRuslan Ermilov.Va sync
418d74f3e32SRuslan Ermilovroutine to apply to the btree file which underlies the
41958f0484fSRodney W. Grimesrecno file, not the recno file itself.
42058f0484fSRodney W. Grimes(See the
421d74f3e32SRuslan Ermilov.Va bfname
42258f0484fSRodney W. Grimesfield of the
423d74f3e32SRuslan Ermilov.Xr recno 3
42458f0484fSRodney W. Grimesmanual page for more information.)
425d74f3e32SRuslan Ermilov.El
426d74f3e32SRuslan Ermilov.Pp
4272efeeba5SRuslan Ermilov.Va sync
42858f0484fSRodney W. Grimesroutines return -1 on error (setting
429d74f3e32SRuslan Ermilov.Va errno )
43058f0484fSRodney W. Grimesand 0 on success.
431d74f3e32SRuslan Ermilov.El
432d74f3e32SRuslan Ermilov.Sh "KEY/DATA PAIRS"
43358f0484fSRodney W. GrimesAccess to all file types is based on key/data pairs.
43458f0484fSRodney W. GrimesBoth keys and data are represented by the following data structure:
435d74f3e32SRuslan Ermilov.Bd -literal
43658f0484fSRodney W. Grimestypedef struct {
43758f0484fSRodney W. Grimes	void *data;
43858f0484fSRodney W. Grimes	size_t size;
43958f0484fSRodney W. Grimes} DBT;
440d74f3e32SRuslan Ermilov.Ed
441d74f3e32SRuslan Ermilov.Pp
442d74f3e32SRuslan ErmilovThe elements of the
443d74f3e32SRuslan Ermilov.Ft DBT
444d74f3e32SRuslan Ermilovstructure are defined as follows:
445d74f3e32SRuslan Ermilov.Bl -tag -width "data"
446d74f3e32SRuslan Ermilov.It Va data
44758f0484fSRodney W. GrimesA pointer to a byte string.
448d74f3e32SRuslan Ermilov.It Va size
44958f0484fSRodney W. GrimesThe length of the byte string.
450d74f3e32SRuslan Ermilov.El
451d74f3e32SRuslan Ermilov.Pp
45258f0484fSRodney W. GrimesKey and data byte strings may reference strings of essentially unlimited
45358f0484fSRodney W. Grimeslength although any two of them must fit into available memory at the same
45458f0484fSRodney W. Grimestime.
45558f0484fSRodney W. GrimesIt should be noted that the access methods provide no guarantees about
45658f0484fSRodney W. Grimesbyte string alignment.
457d74f3e32SRuslan Ermilov.Sh ERRORS
45858f0484fSRodney W. GrimesThe
459d74f3e32SRuslan Ermilov.Fn dbopen
46058f0484fSRodney W. Grimesroutine may fail and set
461d74f3e32SRuslan Ermilov.Va errno
46258f0484fSRodney W. Grimesfor any of the errors specified for the library routines
463d74f3e32SRuslan Ermilov.Xr open 2
46458f0484fSRodney W. Grimesand
465d74f3e32SRuslan Ermilov.Xr malloc 3
46658f0484fSRodney W. Grimesor the following:
467d74f3e32SRuslan Ermilov.Bl -tag -width Er
468d74f3e32SRuslan Ermilov.It Bq Er EFTYPE
46958f0484fSRodney W. GrimesA file is incorrectly formatted.
470d74f3e32SRuslan Ermilov.It Bq Er EINVAL
4712efeeba5SRuslan ErmilovAn argument has been specified (hash function, pad byte etc.) that is
47258f0484fSRodney W. Grimesincompatible with the current file specification or which is not
47358f0484fSRodney W. Grimesmeaningful for the function (for example, use of the cursor without
47458f0484fSRodney W. Grimesprior initialization) or there is a mismatch between the version
47558f0484fSRodney W. Grimesnumber of file and the software.
476d74f3e32SRuslan Ermilov.El
477d74f3e32SRuslan Ermilov.Pp
47858f0484fSRodney W. GrimesThe
479d74f3e32SRuslan Ermilov.Va close
48058f0484fSRodney W. Grimesroutines may fail and set
481d74f3e32SRuslan Ermilov.Va errno
48258f0484fSRodney W. Grimesfor any of the errors specified for the library routines
483d74f3e32SRuslan Ermilov.Xr close 2 ,
484d74f3e32SRuslan Ermilov.Xr read 2 ,
485d74f3e32SRuslan Ermilov.Xr write 2 ,
486d74f3e32SRuslan Ermilov.Xr free 3 ,
48758f0484fSRodney W. Grimesor
488d74f3e32SRuslan Ermilov.Xr fsync 2 .
489d74f3e32SRuslan Ermilov.Pp
49058f0484fSRodney W. GrimesThe
491d74f3e32SRuslan Ermilov.Va del ,
492d74f3e32SRuslan Ermilov.Va get ,
493d74f3e32SRuslan Ermilov.Va put
49458f0484fSRodney W. Grimesand
495d74f3e32SRuslan Ermilov.Va seq
49658f0484fSRodney W. Grimesroutines may fail and set
497d74f3e32SRuslan Ermilov.Va errno
49858f0484fSRodney W. Grimesfor any of the errors specified for the library routines
499d74f3e32SRuslan Ermilov.Xr read 2 ,
500d74f3e32SRuslan Ermilov.Xr write 2 ,
501d74f3e32SRuslan Ermilov.Xr free 3
50258f0484fSRodney W. Grimesor
503d74f3e32SRuslan Ermilov.Xr malloc 3 .
504d74f3e32SRuslan Ermilov.Pp
50558f0484fSRodney W. GrimesThe
506d74f3e32SRuslan Ermilov.Va fd
50758f0484fSRodney W. Grimesroutines will fail and set
508d74f3e32SRuslan Ermilov.Va errno
509d74f3e32SRuslan Ermilovto
510d74f3e32SRuslan Ermilov.Er ENOENT
511d74f3e32SRuslan Ermilovfor in memory databases.
512d74f3e32SRuslan Ermilov.Pp
51358f0484fSRodney W. GrimesThe
514d74f3e32SRuslan Ermilov.Va sync
51558f0484fSRodney W. Grimesroutines may fail and set
516d74f3e32SRuslan Ermilov.Va errno
51758f0484fSRodney W. Grimesfor any of the errors specified for the library routine
518d74f3e32SRuslan Ermilov.Xr fsync 2 .
519d74f3e32SRuslan Ermilov.Sh SEE ALSO
520d74f3e32SRuslan Ermilov.Xr btree 3 ,
521d74f3e32SRuslan Ermilov.Xr hash 3 ,
522d74f3e32SRuslan Ermilov.Xr mpool 3 ,
523d74f3e32SRuslan Ermilov.Xr recno 3
524d74f3e32SRuslan Ermilov.Rs
525d74f3e32SRuslan Ermilov.%T "LIBTP: Portable, Modular Transactions for UNIX"
526d74f3e32SRuslan Ermilov.%A Margo Seltzer
527d74f3e32SRuslan Ermilov.%A Michael Olson
528d74f3e32SRuslan Ermilov.%R "USENIX proceedings"
529d74f3e32SRuslan Ermilov.%D Winter 1992
530d74f3e32SRuslan Ermilov.Re
531d74f3e32SRuslan Ermilov.Sh BUGS
532d74f3e32SRuslan ErmilovThe typedef
533d74f3e32SRuslan Ermilov.Ft DBT
534d74f3e32SRuslan Ermilovis a mnemonic for
535d74f3e32SRuslan Ermilov.Dq "data base thang" ,
536d74f3e32SRuslan Ermilovand was used
5370227791bSRuslan Ermilovbecause noone could think of a reasonable name that was not already used.
538d74f3e32SRuslan Ermilov.Pp
53958f0484fSRodney W. GrimesThe file descriptor interface is a kluge and will be deleted in a
54058f0484fSRodney W. Grimesfuture version of the interface.
541d74f3e32SRuslan Ermilov.Pp
54258f0484fSRodney W. GrimesNone of the access methods provide any form of concurrent access,
54358f0484fSRodney W. Grimeslocking, or transactions.
544