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