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