DBM(3X) DBM(3X) NAME dbminit, fetch, store, delete, firstkey, nextkey - data base subrou‐ tines SYNOPSIS #include typedef struct { char *dptr; int dsize; } datum; dbminit(file) char *file; datum fetch(key) datum key; store(key, content) datum key, content; delete(key) datum key; datum firstkey() datum nextkey(key) datum key; DESCRIPTION Note: the dbm library has been superceded by ndbm(3), and is now imple‐‐ mented using ndbm. These functions maintain key/content pairs in a data base. The functions will handle very large (a billion blocks) databases and will access a keyed item in one or two file system accesses. The functions are obtained with the loader option -ldbm. _K_e_ys and _c_o_n_t_e_n_ts are described by the _d_a_t_u_m typedef. A _d_a_t_u_m speci‐ fies a string of _d_s_i_z_e bytes pointed to by _d_p_t_r_. 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 ‘.dir’ as its suffix. The second file contains all data and has ‘.pag’ as its suffix. Before a database can be accessed, it must be opened by _d_b_m_i_n_i_t_. At the time of this call, the files _f_i_l_e.dir and _f_i_l_e.pag must exist. (An empty database is created by creating zero-length ‘.dir’ and ‘.pag’ files.) Once open, the data stored under a key is accessed by _f_e_t_c_h and data is placed under a key by _s_t_o_r_e. A key (and its associated contents) is deleted by _d_e_l_e_t_e. A linear pass through all keys in a database may be made, in an (apparently) random order, by use of _f_i_r_s_t_k_e_y and _n_e_x_t_k_e_y. _F_i_r_s_t_k_e_y will return the first key in the database. With any key _n_e_x_‐ _t_k_e_y will return the next key in the database. This code will traverse the data base: for (key = firstkey(); key.dptr != NULL; key = nextkey(key)) DIAGNOSTICS All functions that return an _i_n_t indicate errors with negative values. A zero return indicates ok. Routines that return a _d_a_t_u_m indicate errors with a null (0) _d_p_t_r_. SEE ALSO ndbm(3) BUGS The ‘.pag’ file will contain holes so that its apparent size is about four times its actual content. Older UNIX systems may create real file blocks for these holes when touched. These files cannot be copied by normal means (cp, cat, tp, tar, ar) without filling in the holes. _D_p_t_r pointers returned by these subroutines point into static storage that is changed by subsequent calls. The sum of the sizes of a key/content pair must not exceed the internal block size (currently 1024 bytes). Moreover all key/content pairs that hash together must fit on a single block. _S_t_o_r_e will return an error in the event that a disk block fills with inseparable data. _D_e_l_e_t_e does not physically reclaim file space, although it does make it available for reuse. The order of keys presented by _f_i_r_s_t_k_e_y and _n_e_x_t_k_e_y depends on a hash‐ ing function, not on anything interesting. 4th Berkeley Distribution May 12, 1986 DBM(3X)