Bell 32V release
[unix-history] / usr / man / man3 / dbm.3x
CommitLineData
3846ebac
TL
1.TH DBM 3X
2.SH NAME
3dbminit, fetch, store, delete, firstkey, nextkey \- data base subroutines
4.SH SYNOPSIS
5.nf
6.PP
7.B "typedef struct { char *dptr; int dsize; } datum;"
8.PP
9.B dbminit(file)
10.B char *file;
11.PP
12.B datum fetch(key)
13.B datum key;
14.PP
15.B store(key, content)
16.B datum key, content;
17.PP
18.B delete(key)
19.B datum key;
20.PP
21.B datum firstkey();
22.PP
23.B datum nextkey(key);
24.B datum key;
25.SH DESCRIPTION
26These functions maintain
27key/content pairs in a data base.
28The functions will handle very large
29(a billion blocks)
30databases and will access a keyed item
31in one or two filesystem accesses.
32The functions are obtained with the loader option
33.BR \-ldbm .
34.PP
35.IR Key s
36and
37.IR content s
38are
39described by the
40.I datum
41typedef.
42A
43.I datum
44specifies a string of
45.I dsize
46bytes pointed to by
47.I dptr.
48Arbitrary binary data, as well as normal
49ASCII strings, are allowed.
50The data base is stored in two files.
51One file is a directory containing a bit map
52and has `.dir' as its suffix.
53The second file contains all data and
54has `.pag' as its suffix.
55.PP
56Before a database can be accessed,
57it must be opened by
58.I dbminit.
59At the time of this call,
60the files
61.IB file .dir
62and
63.IB file .pag
64must exist.
65(An empty database is created by
66creating zero-length
67`.dir' and `.pag' files.)
68.PP
69Once open,
70the data stored under a key is
71accessed by
72.I fetch
73and data is placed under a key
74by
75.IR store .
76A key (and its associated contents)
77is deleted by
78.IR delete .
79A linear pass through all keys in a database
80may be made,
81in an (apparently) random order,
82by use of
83.I firstkey
84and
85.IR nextkey .
86.I Firstkey
87will return the first key
88in the database.
89With any key
90.I nextkey
91will return the next key in the database.
92This code will traverse the data base:
93.PP
94 for(key=firstkey(); key.dptr!=NULL; key=nextkey(key))
95.SH DIAGNOSTICS
96All functions that return an
97.I int
98indicate errors with negative values.
99A zero return indicates ok.
100Routines that return a
101.I datum
102indicate errors with a null (0)
103.I dptr.
104.SH BUGS
105The
106`.pag'
107file will contain holes so
108that its apparent size is about
109four times its actual content.
110Older UNIX systems may create real
111file blocks for these holes when touched.
112These files cannot be copied
113by normal means (cp, cat, tp, tar, ar)
114without filling in the holes.
115.PP
116.I Dptr
117pointers returned
118by these subroutines
119point into static storage
120that is changed by subsequent calls.
121.PP
122The sum of the sizes of
123a
124key/content pair must not exceed
125the internal block size
126(currently 512 bytes).
127Moreover all key/content pairs that hash
128together must fit on a single block.
129.I Store
130will return an error in the event that
131a disk block fills with inseparable data.
132.PP
133.I Delete
134does not physically reclaim file space,
135although it does make it available for reuse.
136.PP
137The order of keys presented by
138.I firstkey
139and
140.I nextkey
141depends on a hashing function, not on anything
142interesting.