1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
|
.TH DBM 3X
.CT 2 data_man
.SH NAME
dbminit, fetch, store, delete, firstkey, nextkey \(mi database subroutines
.SH SYNOPSIS
.nf
.B dbminit(file)
.B char *file;
.PP
.B datum fetch(key)
.B datum key;
.PP
.B store(key, value)
.B datum key, value;
.PP
.B delete(key)
.B datum key;
.PP
.B datum firstkey()
.PP
.B datum nextkey(key)
.B datum key;
.SH DESCRIPTION
These functions maintain
key/value pairs (each pair is a
.IR datum )
in a data base.
The functions will handle very large databases
in one or two file system accesses per key.
The functions are loaded
with
.IR ld (1)
option
.BR -ldbm .
A datum is defined as
.IP
.EX
.ta \w'typedef 'u +\w'struct 'u
typedef struct {
char *dptr;
int dsize;
} datum;
.EE
.PP
A
.B datum
object specifies a string of
.B dsize
bytes pointed to by
.BR dptr .
Arbitrary binary data, as well as normal
ASCII strings, are allowed.
The data base is stored in two files.
One file is a directory containing a bit map
and has
.L .dir
as its suffix.
The second file contains all data and
has
.L .pag
as its suffix.
.PP
Before a database can be accessed,
it must be opened by
.I dbminit.
At the time of this call,
the files
.IB file .dir
and
.IB file .pag
must exist.
(An empty database has empty
.L .dir
and
.L .pag
files.)
.PP
The value associated with a key is
retrieved by
.I fetch
and assigned by
.IR store .
A key and its associated value
are deleted by
.IR delete .
A linear pass through all keys in a database
may be made,
in random order,
by use of
.I firstkey
and
.IR nextkey .
.I Firstkey
will return the first key
in the database.
With any key
.I nextkey
will return the next key in the database.
This code will traverse the data base:
.IP
.L
for(key = firstkey(); key.dptr != NULL; key = nextkey(key))
.SH SEE ALSO
.IR cbt (3)
.SH DIAGNOSTICS
All functions that return integers
indicate errors with negative values.
A zero return indicates success.
Routines that return a
.B datum
indicate errors with zero
.BR dptr .
.SH BUGS
The
.L .pag
file contains holes;
its apparent size is about
four times its actual content.
These files cannot be copied
by normal means
.RI ( cat (1),
.IR tar (1),
.IR cpio (1),
.IR ar (1))
without filling in the holes.
.br
Pointers returned
by these subroutines
refer to static data
that is changed by subsequent calls.
.br
The sum of the sizes of
a
key/value pair must not exceed
a fixed internal block size.
Moreover all key/value pairs that hash
together must fit on a single block.
.I Store
will return an error in the event that
a disk block fills with inseparable data.
.br
.I Delete
does not physically reclaim file space,
although it does make it available for reuse.
|