1DBM(3X)                                                                DBM(3X)
2
3
4

NAME

6       dbminit,  fetch,  store,  delete, firstkey, nextkey - data base subrou‐
7       tines
8

SYNOPSIS

10       typedef struct { char *dptr; int dsize; } datum;
11
12       dbminit(file)
13       char *file;
14
15       datum fetch(key)
16       datum key;
17
18       store(key, content)
19       datum key, content;
20
21       delete(key)
22       datum key;
23
24       datum firstkey();
25
26       datum nextkey(key);
27       datum key;
28

DESCRIPTION

30       These functions maintain key/content pairs in a data base.   The  func‐
31       tions  will  handle  very  large  (a billion blocks) databases and will
32       access a keyed item in one or two filesystem accesses.   The  functions
33       are obtained with the loader option -ldbm.
34
35       Keys  and  contents are described by the datum typedef.  A datum speci‐
36       fies a string of dsize bytes pointed  to  by  dptr.   Arbitrary  binary
37       data,  as  well as normal ASCII strings, are allowed.  The data base is
38       stored in two files.  One file is a directory containing a bit map  and
39       has  `.dir'  as  its suffix.  The second file contains all data and has
40       `.pag' as its suffix.
41
42       Before a database can be accessed, it must be opened  by  dbminit.   At
43       the time of this call, the files file.dir and file.pag must exist.  (An
44       empty database is created by creating  zero-length  `.dir'  and  `.pag'
45       files.)
46
47       Once open, the data stored under a key is accessed by fetch and data is
48       placed under a key by store.  A key (and its  associated  contents)  is
49       deleted by delete.  A linear pass through all keys in a database may be
50       made, in an (apparently) random order, by use of firstkey and  nextkey.
51       Firstkey  will return the first key in the database.  With any key nex‐
52       tkey will return the next key in the database.  This code will traverse
53       the data base:
54
55            for(key=firstkey(); key.dptr!=NULL; key=nextkey(key))
56

DIAGNOSTICS

58       All  functions that return an int indicate errors with negative values.
59       A zero return indicates ok.  Routines  that  return  a  datum  indicate
60       errors with a null (0) dptr.
61

BUGS

63       The  `.pag'  file will contain holes so that its apparent size is about
64       four times its actual content.  Older UNIX systems may create real file
65       blocks  for  these holes when touched.  These files cannot be copied by
66       normal means (cp, cat, tp, tar, ar) without filling in the holes.
67
68       Dptr pointers returned by these subroutines point into  static  storage
69       that is changed by subsequent calls.
70
71       The sum of the sizes of a key/content pair must not exceed the internal
72       block size (currently 512 bytes).  Moreover all key/content pairs  that
73       hash  together  must fit on a single block.  Store will return an error
74       in the event that a disk block fills with inseparable data.
75
76       Delete does not physically reclaim file space, although it does make it
77       available for reuse.
78
79       The  order of keys presented by firstkey and nextkey depends on a hash‐
80       ing function, not on anything interesting.
81
82
83
84                                                                       DBM(3X)
Impressum