libc/db: Sync with FreeBSD
[dragonfly.git] / lib / libc / db / man / recno.3
1 .\" Copyright (c) 1990, 1993
2 .\"     The Regents of the University of California.  All rights reserved.
3 .\"
4 .\" Redistribution and use in source and binary forms, with or without
5 .\" modification, are permitted provided that the following conditions
6 .\" are met:
7 .\" 1. Redistributions of source code must retain the above copyright
8 .\"    notice, this list of conditions and the following disclaimer.
9 .\" 2. Redistributions in binary form must reproduce the above copyright
10 .\"    notice, this list of conditions and the following disclaimer in the
11 .\"    documentation and/or other materials provided with the distribution.
12 .\" 3. Neither the name of the University nor the names of its contributors
13 .\"    may be used to endorse or promote products derived from this software
14 .\"    without specific prior written permission.
15 .\"
16 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
17 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 .\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
20 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 .\" SUCH DAMAGE.
27 .\"
28 .\"     @(#)recno.3     8.5 (Berkeley) 8/18/94
29 .\" $FreeBSD: head/lib/libc/db/man/recno.3 165903 2007-01-09 00:28:16Z imp $
30 .\"
31 .Dd August 18, 1994
32 .Dt RECNO 3
33 .Os
34 .Sh NAME
35 .Nm recno
36 .Nd "record number database access method"
37 .Sh LIBRARY
38 .Lb libc
39 .Sh SYNOPSIS
40 .In sys/types.h
41 .In db.h
42 .Sh DESCRIPTION
43 The routine
44 .Fn dbopen
45 is the library interface to database files.
46 One of the supported file formats is record number files.
47 The general description of the database access methods is in
48 .Xr dbopen 3 ,
49 this manual page describes only the
50 .Nm
51 specific information.
52 .Pp
53 The record number data structure is either variable or fixed-length
54 records stored in a flat-file format, accessed by the logical record
55 number.
56 The existence of record number five implies the existence of records
57 one through four, and the deletion of record number one causes
58 record number five to be renumbered to record number four, as well
59 as the cursor, if positioned after record number one, to shift down
60 one record.
61 .Pp
62 The
63 .Nm
64 access method specific data structure provided to
65 .Fn dbopen
66 is defined in the
67 .In db.h
68 include file as follows:
69 .Bd -literal
70 typedef struct {
71         unsigned long flags;
72         unsigned int cachesize;
73         unsigned int psize;
74         int lorder;
75         size_t reclen;
76         unsigned char bval;
77         char *bfname;
78 } RECNOINFO;
79 .Ed
80 .Pp
81 The elements of this structure are defined as follows:
82 .Bl -tag -width indent
83 .It Va flags
84 The flag value is specified by
85 .Em or Ns 'ing
86 any of the following values:
87 .Bl -tag -width indent
88 .It Dv R_FIXEDLEN
89 The records are fixed-length, not byte delimited.
90 The structure element
91 .Va reclen
92 specifies the length of the record, and the structure element
93 .Va bval
94 is used as the pad character.
95 Any records, inserted into the database, that are less than
96 .Va reclen
97 bytes long are automatically padded.
98 .It Dv R_NOKEY
99 In the interface specified by
100 .Fn dbopen ,
101 the sequential record retrieval fills in both the caller's key and
102 data structures.
103 If the
104 .Dv R_NOKEY
105 flag is specified, the
106 .Em cursor
107 routines are not required to fill in the key structure.
108 This permits applications to retrieve records at the end of files without
109 reading all of the intervening records.
110 .It Dv R_SNAPSHOT
111 This flag requires that a snapshot of the file be taken when
112 .Fn dbopen
113 is called, instead of permitting any unmodified records to be read from
114 the original file.
115 .El
116 .It Va cachesize
117 A suggested maximum size, in bytes, of the memory cache.
118 This value is
119 .Em only
120 advisory, and the access method will allocate more memory rather than fail.
121 If
122 .Va cachesize
123 is 0 (no size is specified) a default cache is used.
124 .It Va psize
125 The
126 .Nm
127 access method stores the in-memory copies of its records
128 in a btree.
129 This value is the size (in bytes) of the pages used for nodes in that tree.
130 If
131 .Va psize
132 is 0 (no page size is specified) a page size is chosen based on the
133 underlying file system I/O block size.
134 See
135 .Xr btree 3
136 for more information.
137 .It Va lorder
138 The byte order for integers in the stored database metadata.
139 The number should represent the order as an integer; for example,
140 big endian order would be the number 4,321.
141 If
142 .Va lorder
143 is 0 (no order is specified) the current host order is used.
144 .It Va reclen
145 The length of a fixed-length record.
146 .It Va bval
147 The delimiting byte to be used to mark the end of a record for
148 variable-length records, and the pad character for fixed-length
149 records.
150 If no value is specified, newlines
151 .Pq Dq \en
152 are used to mark the end
153 of variable-length records and fixed-length records are padded with
154 spaces.
155 .It Va bfname
156 The
157 .Nm
158 access method stores the in-memory copies of its records
159 in a btree.
160 If
161 .Va bfname
162 is
163 .No non\- Ns Dv NULL ,
164 it specifies the name of the btree file,
165 as if specified as the file name for a
166 .Fn dbopen
167 of a btree file.
168 .El
169 .Pp
170 The data part of the key/data pair used by the
171 .Nm
172 access method
173 is the same as other access methods.
174 The key is different.
175 The
176 .Va data
177 field of the key should be a pointer to a memory location of type
178 .Ft recno_t ,
179 as defined in the
180 .In db.h
181 include file.
182 This type is normally the largest unsigned integral type available to
183 the implementation.
184 The
185 .Va size
186 field of the key should be the size of that type.
187 .Pp
188 Because there can be no meta-data associated with the underlying
189 .Nm
190 access method files, any changes made to the default values
191 (e.g.\& fixed record length or byte separator value) must be explicitly
192 specified each time the file is opened.
193 .Pp
194 In the interface specified by
195 .Fn dbopen ,
196 using the
197 .Va put
198 interface to create a new record will cause the creation of multiple,
199 empty records if the record number is more than one greater than the
200 largest record currently in the database.
201 .Sh ERRORS
202 The
203 .Nm
204 access method routines may fail and set
205 .Va errno
206 for any of the errors specified for the library routine
207 .Xr dbopen 3
208 or the following:
209 .Bl -tag -width Er
210 .It Bq Er EINVAL
211 An attempt was made to add a record to a fixed-length database that
212 was too large to fit.
213 .El
214 .Sh SEE ALSO
215 .Xr btree 3 ,
216 .Xr dbopen 3 ,
217 .Xr hash 3 ,
218 .Xr mpool 3
219 .Rs
220 .%T "Document Processing in a Relational Database System"
221 .%A Michael Stonebraker
222 .%A Heidi Stettner
223 .%A Joseph Kalash
224 .%A Antonin Guttman
225 .%A Nadene Lynn
226 .%R "Memorandum No. UCB/ERL M82/32"
227 .%D May 1982
228 .Re
229 .Sh BUGS
230 Only big and little endian byte order is supported.