1.\" $OpenBSD: recno.3,v 1.20 2015/09/10 10:20:55 jmc 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 $Mdocdate: September 10 2015 $ 36.Dt RECNO 3 37.Os 38.Sh NAME 39.Nm recno 40.Nd record number database access method 41.Sh SYNOPSIS 42.In sys/types.h 43.In 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.In db.h 68include file as follows: 69.Bd -literal -offset indent 70typedef 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 81The elements of this structure are defined as follows: 82.Bl -tag -width XXXXXX 83.It Fa flags 84The flag value is specified by 85.Tn OR Ns 'ing 86any of the following values: 87.Bl -tag -width R_FIXEDLEN 88.It Dv R_FIXEDLEN 89The records are fixed-length, not byte delimited. 90The structure element 91.Fa reclen 92specifies the length of the record, and the structure element 93.Fa bval 94is used as the pad character. 95Any records, inserted into the database, that are less than 96.Fa reclen 97bytes long are automatically padded. 98.It Dv R_NOKEY 99In the interface specified by 100.Fn dbopen , 101the sequential record retrieval fills in both the caller's key and 102data structures. 103If the R_NOKEY flag is specified, the 104.Fa cursor 105routines are not required to fill in the key structure. 106This permits applications to retrieve records at the end of files without 107reading all of the intervening records. 108.It Dv R_SNAPSHOT 109This flag requires that a snapshot of the file be taken when 110.Fn dbopen 111is called, instead of permitting any unmodified records to be read from 112the original file. 113.El 114.It Fa cachesize 115A suggested maximum size, in bytes, of the memory cache. 116This value is 117.Em only 118advisory, and the access method will allocate more memory rather than fail. 119If 120.Fa cachesize 121is 0 (no size is specified) a default cache is used. 122.It Fa psize 123The recno access method stores the in-memory copies of its records 124in a btree. 125This value is the size (in bytes) of the pages used for nodes in that tree. 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 Ql \en 148are used to mark the end 149of variable-length records and fixed-length records are padded with 150spaces. 151.It Fa bfname 152The recno access method stores the in-memory copies of its records 153in a btree. 154If 155.Fa bfname 156is non-NULL, it specifies the name of the 157.Xr btree 3 158file, as if specified as the file name for a 159.Xr dbopen 3 160of a 161.Xr btree 3 162file. 163.El 164.Pp 165The data part of the key/data pair used by the recno access method 166is the same as other access methods. 167The key is different. 168The 169.Fa data 170field of the key should be a pointer to a memory location of type 171.Vt recno_t , 172as defined in the 173.In db.h 174include file. 175This type is normally the largest unsigned integral type available to 176the implementation. 177The 178.Fa size 179field of the key should be the size of that type. 180.Pp 181Because there can be no meta-data associated with the underlying 182recno access method files, any changes made to the default values 183(e.g., fixed record length or byte separator value) must be explicitly 184specified each time the file is opened. 185.Pp 186In the interface specified by 187.Fn dbopen , 188using the 189.Fa put 190interface to create a new record will cause the creation of multiple, 191empty records if the record number is more than one greater than the 192largest record currently in the database. 193.Sh ERRORS 194The 195.Fa recno 196access method routines may fail and set 197.Va errno 198for any of the errors specified for the library routine 199.Xr dbopen 3 , 200or the following: 201.Bl -tag -width XEINVALX 202.It Bq Er EINVAL 203An attempt was made to add a record to a fixed-length database that 204was too large to fit. 205.El 206.Sh SEE ALSO 207.Xr btree 3 , 208.Xr dbopen 3 , 209.Xr hash 3 210.Rs 211.%T "Document Processing in a Relational Database System" 212.%A Michael Stonebraker 213.%A Heidi Stettner 214.%A Joseph Kalash 215.%A Antonin Guttman 216.%A Nadene Lynn 217.%J Memorandum No. UCB/ERL M82/32 218.%D May 1982 219.Re 220.Sh BUGS 221Only big and little endian byte order is supported. 222