|
DataMuseum.dkPresents historical artifacts from the history of: DKUUG/EUUG Conference tapes |
This is an automatic "excavation" of a thematic subset of
See our Wiki for more about DKUUG/EUUG Conference tapes Excavated with: AutoArchaeologist - Free & Open Source Software. |
top - metrics - downloadIndex: R T
Length: 8886 (0x22b6) Types: TextFile Names: »README«
└─⟦a05ed705a⟧ Bits:30007078 DKUUG GNU 2/12/89 └─⟦0befd2614⟧ »./gdbm-0.8.tar.Z« └─⟦b993d2893⟧ └─⟦this⟧ »gdbm/README«
This is the initial release of GNU dbm. Better documentation will be written soon. For now, this file briefly describes the contents of this release and how to use it. The files are: COPYING - Copying information. README - This file bucket.c, dbminit.c, delete.c, extern.h, falloc.c, fetch.c, findkey.c, gdbm.h, gdbmclose.c, gdbmdelete.c, gdbmerrno.h, gdbmfetch.c, gdbmopen.c, gdbmreorg.c, gdbmseq.c, gdbmstore.c, global.c, hash.c seq.c, store.c, update.c - Source for GNU dbm library. Makefile - Makefile, will make gdbm.a test.c - A simple test program. version.c - The current version number in a string. GNU dbm is a set of database routines that use extendible hashing and works similar to the standard UNIX dbm routines. The basic unit of data is the structure typedef struct { char *dptr; int dsize; } datum; The following is a quick list of the routines. After this list, a longer description of each routine will be given. The routines are: char *gdbm_open ( name, block_size, read_write, fatal_func ) gdbm_close ( dbf ) int gdbm_store ( dbf, key, content ) datum gdbm_fetch ( dbf, key ) int gdbm_delete ( dbf, key ) datum gdbm_firstkey ( dbf ) datum gdbm_nextkey ( dbf, key ) int gdbm_reorganize ( dbf ) gdbm_recovery ( dbf, state ) For compatibility with the standard dbm, the following routines are defined. int dbminit ( name ) int store ( key, content ) datum fetch ( key ) int delete ( key ) datum firstkey () datum nextkey ( key ) An additional routine is needed for use with the compatibility routines. dbmclose () Description of GNU dbm routines. -------------------------------- GNU dbm allows multiple data files. A routine that opens a gdbm file is designated as a "reader" or a "writer". Only one writer may open a gdbm file and many readers may open the file. Readers and writers can not open the gdbm file at the same time. The procedure for opening a gdbm file is: char * dbf; dbf = gdbm_open ( name, block_size, read_write, fatal_func ) The parameters are: char *name - the name of the file (the complete name, gdbm does not append any characters to this name) int block_size - the size of a single transfer from disk to memory. This parameter is ignored unless the file is a new file. The minimum size is 512. If it is less than 512, dbm will use the stat block size for the file system. int read_write - 0 => reader, 1 => writer void (*fatal_func) () - a function for dbm to call if it detects a fatal error. The only parameter of this function is a string. If the value of 0 is provided, dbm will use a default function. The return value, dbf, is the pointer needed by all other routines to access that gdbm file. If the return is the NULL pointer, gdbm_open was not successful. The errors can be found in "gdbm_errno" for gdbm errors and in "errno" for file system errors. (For error codes, see gdbmerrno.h.) In all of the following calls, the parameter "dbf" refers to the pointer returned from gdbm_open. It is important that every file opened is also closed. This is needed to update the reader/writer count on the file. This is done by: gdbm_close(dbf); The database is used by 3 primary routines. The first stores data in the database. ret = gdbm_store ( dbf, key, content ) The parameters are: char *dbf - the pointer returned by gdbm_open datum key - the key data datum content - the data to be associated with the key If a reader calls store, ret gets -1. Otherwise, ret is 0. NOTICE: If you store data for a key that is already in the data base, gdbm replaces the old data with the new data. You do not get two data items for the same key and you do not get an error from gdbm_store. To search for some data: content = gdbm_fetch ( dbf, key ) The parameters are: char *dbf - the pointer returned by gdbm_open datum key - the key data The "datum" returned in content is a pointer to the data found. If the dptr is NULL, no data was found. If dptr is not NULL, then it points to data allocated by malloc. gdbm does not automatically free this data. The user must free this storage when done using it. This eliminates the need to copy the result to save it for later use. (You just save the pointer.) To remove some data from the database: ret = gdbm_delete ( dbf, key ) The parameters are: char *dbf - the pointer returned by gdbm_open datum key - the key data The ret value is -1 if the item is present or the requester is a reader. The ret value is 0 if there was a successful delete. The next two routines allow for accessing all items in the database. This access is not key sequential, but it is guaranteed to visit every key in the database once. (The order has to do with the hash values.) key = gdbm_firstkey ( dbf ) nextkey = gdbm_nextkey ( dbf, key ) The parameters are: char *dbf - the pointer returned by gdbm_open datum key - the key data The return values are both datum. If key.dptr or nextkey.dptr is NULL, there is no first key or next key. Again notice that dptr points to data allocated by malloc and gdbm will not free it for you. The following routine should be used very seldom. ret = gdbm_reorganize ( dbf ) If you have had a lot of deletions and would like to shrink the space used by the gdbm file, the this routine will reorganize the database. gdbm will not shorten the length of a gdbm file except by using this reorganization. (Deleted file space will be reused.) Finally, gdbm does crash detection and recovery. This causes a little overhead in processing of the gdbm_store and gdbm_delete routines. If crash detection and recovery are unimportant or costs too much, you can turn off crash detection and recovery. This is done on an individual file basis. It remains off until a request is made to turn it on again. The following routine changes the state of crash detection and recovery: gdbm_recovery ( dbf, state ) The parameters are: char *dbf - the pointer returned by gdbm_open int state - 0 to turn it off, anything else to turn on. The following two are variables that may need to be used: gdbm_error gdbm_errno - the variable that contains more information about gdbm errors. char * gdbm_version - the string containing the version information. There are a few more things of interest. First, gdbm files are not "sparse". You can copy them with the UNIX cp command and they will not expand in the copying process. Also, there is a compatibility mode for use with programs that already use UNIX dbm. In this compatibility mode, no gdbm file pointer is required by the user. Only one file may be opened at a time. All users in compatibility mode are assumed to be writers. Also, default crash detection and recovery is turned off for compatibility mode. All returned pointers in datum structures point to data that gdbm WILL free. They should be treated as static pointers (as standard UNIX dbm does). The compatibility routine names are the same as the UNIX dbm routine names. Their definitions follow: int dbminit ( name ) int store ( key, content ) datum fetch ( key ) int delete ( key ) datum firstkey () datum nextkey ( key ) An additional routine is needed for use with the compatibility routines. This closes the database file. Adding this routine should be the only change to programs using the standard UNIX dbm. dbmclose () WARNING: standard UNIX dbm and GNU dbm do not have the same data format in the file. You cannot access a standard UNIX dbm file with GNU dbm! Notes on making GNU dbm. ------------------------ The "Makefile" will make both "gdbm.a", the collection of gdbm routines and a simple test program that uses the gdbm routines. There are three make commands: make gdbm.a makes the gdbm.a archive. make test makes both gdbm.a and the test program. make install installs gdbm.a as /usr/lib/libgdbm.a. The makefile is distributed with RANDOM_HASH defined. This causes the hash function in gdbm to use the UNIX random function to produce a well distributed and random hash value. If this computation is too costly for you, you can remove the definition of RANDOM_HASH from the makefile. WARNING: GNU dbm compiled with RANDOM_HASH will not read databases created by GNU dbm compiled without RANDOM_HASH! Also, similar to UNIX dbm, GNU dbm will not create a gdbm file. If it finds a file with zero length, ti will initialize the file. To make a new gdbm database file, "touch file.name" and then run the program that opens "file.name" as a gdbm file. The first execution will initialize the file. Please send bug reports to phil@wwu.edu. Thank you.