From 131ddf402e184a45963e9c61af74571ef2ea2c1a Mon Sep 17 00:00:00 2001 From: Sergey Poznyakoff Date: Wed, 3 Aug 2011 21:07:36 +0000 Subject: Update. --- doc/gdbm.3 | 531 ++++++++++++++++++++++++------------------------------------- 1 file changed, 206 insertions(+), 325 deletions(-) (limited to 'doc') diff --git a/doc/gdbm.3 b/doc/gdbm.3 index 1741f04..2eff593 100644 --- a/doc/gdbm.3 +++ b/doc/gdbm.3 @@ -1,268 +1,134 @@ +.\" This file is part of GDBM. +.\" Copyright (C) 2011 Free Software Foundation, Inc. +.\" +.\" GDBM is free software; you can redistribute it and/or modify +.\" it under the terms of the GNU General Public License as published by +.\" the Free Software Foundation; either version 3, or (at your option) +.\" any later version. +.\" +.\" GDBM is distributed in the hope that it will be useful, +.\" but WITHOUT ANY WARRANTY; without even the implied warranty of +.\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +.\" GNU General Public License for more details. +.\" +.\" You should have received a copy of the GNU General Public License +.\" along with GDBM. If not, see . */ +.TH GDBM 3 "August 4, 2011" "GDBM" "GDBM User Reference" .ds ve 1.8.3 -.TH GDBM 3 10/15/2002 .SH NAME GDBM - The GNU database manager. Includes \fBdbm\fR and \fBndbm\fR compatability. (Version \*(ve.) .SH SYNOPSIS +.nf .B #include -.PP -.SM -.B extern gdbm_error -.br -.B gdbm_errno -.PP -.B extern char -.br -.B *gdbm_version -.PP -.B GDBM_FILE -.br -.B gdbm_open (name, block_size, read_write, mode, fatal_func) -.br -.B char * name; -.br -.B int block_size, read_write, mode; -.br -.B void (*fatal_func) (); -.PP -.B void -.br -.B gdbm_close (dbf) -.br -.B GDBM_FILE dbf; -.PP -.B int -.br -.B gdbm_store (dbf, key, content, flag) -.br -.B GDBM_FILE dbf; -.br -.B datum key, content; -.br -.B int flag; -.PP -.B datum -.br -.B gdbm_fetch (dbf, key) -.br -.B GDBM_FILE dbf; -.br -.B datum key; -.PP -.B int -.br -.B gdbm_delete (dbf, key) -.br -.B GDBM_FILE dbf; +.sp +.BI "extern gdbm_error" " gdbm_errno"; .br -.B datum key; -.PP -.B datum +.BI "extern char *" gdbm_version ; .br -.B gdbm_firstkey (dbf) +.BI "GDBM_FILE gdbm_open (const char *" name ", int " block_size ", " +.ti +21 +.BI "int " flags ", int " mode ", " +.ti +21 +.BI "void (*" fatal_func ")(const char *))"; .br -.B GDBM_FILE dbf; -.PP -.B datum +.BI "void gdbm_close (GDBM_FILE " dbf ");" .br -.B gdbm_nextkey (dbf, key) +.BI "int gdbm_store (GDBM_FILE " dbf ", datum " key ", datum " content ", int " flag ); .br -.B GDBM_FILE dbf; +.BI "datum gdbm_fetch (GDBM_FILE " dbf ", datum " key ); .br -.B datum key; -.PP -.B int +.BI "int gdbm_delete (GDBM_FILE " dbf ", datum " key ); .br -.B gdbm_reorganize (dbf) +.BI "datum gdbm_firstkey (GDBM_FILE " dbf ");" .br -.B GDBM_FILE dbf; -.PP -.B void +.BI "datum gdbm_nextkey (GDBM_FILE " dbf ", datum " key ); .br -.B gdbm_sync (dbf) +.BI "int gdbm_reorganize (GDBM_FILE " dbf ");" .br -.B GDBM_FILE dbf; -.PP -.B int +.BI "void gdbm_sync (GDBM_FILE " dbf ");" .br -.B gdbm_exists (dbf, key) +.BI "int gdbm_exists (GDBM_FILE " dbf ", datum " key ); .br -.B GDBM_FILE dbf; +.BI "const char *gdbm_strerror (gdbm_error " errno ); .br -.B datum key; -.PP -.B char * +.BI "int gdbm_setopt (GDBM_FILE " dbf ", int " option ", int " value ", int " size ); .br -.B gdbm_strerror (errno) +.BI "int gdbm_fdesc (GDBM_FILE " dbf ); .br -.B gdbm_error errno; .PP -.B int -.br -.B gdbm_setopt (dbf, option, value, size) -.br -.B GDBM_FILE dbf; -.br -.B int option; -.br -.B int *value; -.br -.B int size; -.PP -.B int -.br -.B gdbm_fdesc (dbf) -.br -.B GDBM_FILE dbf; -.PP -.PP -.B DBM Compatability routines: +.SS DBM Compatability routines: .PP .B #include -.PP -.SM -.B int -.br -.B dbminit (name) -.br -.B char *name; -.PP -.B int .br -.B store (key, content) +.BI "int dbminit (const char *" name ");" .br -.B datum key, content; -.PP -.B datum +.BI "int store (datum " key ", datum " content ); .br -.B fetch (key) +.BI "datum fetch (datum " key ); .br -.B datum key; -.PP -.B int +.BI "int delete (datum " key ); .br -.B delete (key) +.BI "datum firstkey (void);" .br -.B datum key; -.PP -.B datum -.br -.B firstkey () -.PP -.B datum +.BI "datum nextkey (datum " key ); .br -.B nextkey (key) -.br -.B datum key; -.PP -.B int -.br -.B dbmclose () -.PP +.BI "int dbmclose (void);" .PP -.B NDBM Compatability routines: +.SS NDBM Compatability routines: .PP .B #include -.PP -.SM -.B DBM .br -.B *dbm_open (name, flags, mode) +.BI "DBM *dbm_open (const char *" name ", int " flags ", int " mode ); .br -.B char *name; +.BI "void dbm_close (DBM *" file ); +.BI datum dbm_fetch (DBM *" file ", datum " key ); .br -.B int flags, mode; -.PP -.B void +.BI "int dbm_store (DBM *" file ", datum " key ", datum " content ", int " flags ); .br -.B dbm_close (file) +.BI "int dbm_delete (DBM *" file ", datum " key ); .br -.B DBM *file; -.PP -.B datum +.BI "datum dbm_firstkey (DBM *" file ); .br -.B dbm_fetch (file, key) +.BI "datum dbm_nextkey (DBM *" file ", datum " key ); .br -.B DBM *file; -.br -.B datum key; -.PP -.B int +.BI "int dbm_error (DBM *" file ); .br -.B dbm_store (file, key, content, flags) -.br -.B DBM *file; -.br -.B datum key, content; -.br -.B int flags; -.PP -.B int +.BI "int dbm_clearerr (DBM *" file ); .br -.B dbm_delete (file, key) +.BI "int dbm_pagfno (DBM *" file ); .br -.B DBM *file; -.br -.B datum key; -.PP -.B datum -.br -.B dbm_firstkey (file) -.br -.B DBM *file; -.PP -.B datum -.br -.B dbm_nextkey (file) -.br -.B DBM *file; -.PP -.B int +.BI "int dbm_dirfno (DBM *" file ); .br -.B dbm_error (file) -.br -.B DBM *file; -.PP -.B int -.br -.B dbm_clearerr (file) -.br -.B DBM *file; -.PP -.B int -.br -.B dbm_pagfno (file) -.br -.B DBM *file; -.PP -.B int -.br -.B dbm_dirfno (file) -.br -.B DBM *file; -.PP -.B int -.br -.B dbm_rdonly (file) -.br -.B DBM *file; - - +.BI "int dbm_rdonly (DBM *" file ); .SH DESCRIPTION -GNU dbm is a library of routines that manages data files that contain +\fBGNU dbm\fR is a library of routines that manages data files that contain key/data pairs. The access provided is that of storing, retrieval, and deletion by key and a non-sorted traversal of all keys. A process is allowed to use multiple data files at the same time. +This manpage is a short description of the \fBGDBM\fR daemon. +For a detailed discussion, including examples of the configuration and +usage recommendations, refer to the \fBGDBM Manual\fR available in +Texinfo format. To access it, run: + + \fBinfo gdbm\fR + +Should any discrepancies occur between this manpage and the +\fBGDBM Manual\fR, the later shall be considered the authoritative +source. + A process 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: - GDBM_FILE dbf; - - dbf = gdbm_open ( name, block_size, read_write, mode, fatal_func ) +.BI "GDBM_FILE gdbm_open (const char *" name ", int " block_size ", " +.ti +21 +.BI "int " flags ", int " mode ", " +.ti +21 +.BI "void (*" fatal_func ")(const char *))"; \fIName\fR is the name of the file (the complete name, gdbm does not append any characters to this name). \fIBlock_size\fR is @@ -270,35 +136,42 @@ 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. \fIRead_write\fR can have one of the following values: -.br +.TP .B GDBM_READER reader -.br +.TP .B GDBM_WRITER writer -.br +.TP .B GDBM_WRCREAT writer - if database does not exist create new one -.br +.TP .B GDBM_NEWDB writer - create new database regardless if one exists -.br +.PP +The \fBGDBM_NOMMAP\fR added to \fIread_write\fR by bitwise or instructs +\fBgdbm_open\fR to disable the use of +.BR mmap (2). +.PP For the last three (writers of the database) the following may be added added to \fIread_write\fR by bitwise or: -.B GDBM_SYNC, -which causes all database operations to be synchronized to the disk, and -.B GDBM_NOLOCK, -which prevents the library from performing any locking on the database file. +.TP +.B GDBM_SYNC +Causes all database operations to be synchronized to the disk, +.TP +.B GDBM_NOLOCK +Pevents the library from performing any locking on the database file. +.PP The option .B GDBM_FAST is now obsolete, since gdbm defaults to no-sync mode. -.br +.PP \fIMode\fR is the file mode (see \fBchmod(2)\fR and \fBopen(2)\fR) if the file is created. \fI(*Fatal_func) ()\fR is 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, gdbm will use a default function. +If the value of 0 is provided, \fBgdbm\fR will use a default function. -The return value \fIdbf\fR is the pointer needed by all other routines to +The return value is the pointer needed by all other routines to access that gdbm file. If the return is the NULL pointer, \fBgdbm_open\fR was not successful. The errors can be found in \fIgdbm_errno\fR for gdbm errors and in \fIerrno\fR for system errors. (For error codes, see @@ -310,69 +183,64 @@ returned from \fBgdbm_open\fR. 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); - +.BI "void gdbm_close (GDBM_FILE " dbf ");" The database is used by 3 primary routines. The first stores data in the database. - ret = gdbm_store ( dbf, key, content, flag ) +.BI "int gdbm_store (GDBM_FILE " dbf ", datum " key ", datum " content ", int " flag ); \fIDbf\fR is the pointer returned by \fBgdbm_open\fR. \fIKey\fR is the key data. \fIContent\fR is the data to be associated with the \fIkey\fR. \fIFlag\fR can have one of the following values: -.br +.TP .B GDBM_INSERT -insert only, generate an error if key exists -.br +Insert only, generate an error if key exists; +.TP .B GDBM_REPLACE -replace contents if key exists. - +Replace contents if key exists. +.PP If a reader calls \fBgdbm_store\fR, the return value will be -1. -If called with GDBM_INSERT and \fIkey\fR is in the database, the return +If called with \fBGDBM_INSERT\fR and \fIkey\fR is in the database, the return value will be 1. Otherwise, the return value is 0. \fINOTICE: If you store data for a key that is already in the data base, -gdbm replaces the old data with the new data if called with GDBM_REPLACE. +\fBgdbm\fI replaces the old data with the new data if called with \fBGDBM_REPLACE\fI. You do not get two data items for the same key and you do not get an -error from gdbm_store. +error from \fBgdbm_store\fI. -NOTICE: The size in gdbm is not restricted like dbm or ndbm. Your data +NOTICE: The size in \fBgdbm\fI is not restricted like in \fBdbm\fI or \fBndbm\fI. Your data can be as large as you want.\fR +To search for some data, use: -To search for some data: - - content = gdbm_fetch ( dbf, key ) +.BI "datum gdbm_fetch (GDBM_FILE " dbf ", datum " key ); \fIDbf\fR is the pointer returned by \fBgdbm_open\fR. \fIKey\fR is the key data. - If the \fIdptr\fR element of the return value is NULL, no data was found. Otherwise the return value is a pointer to the found data. The storage space for the \fIdptr\fR element is allocated using -\fBmalloc(3C)\fR. \fBGdbm\fI does not automatically free this data. +\fBmalloc(3)\fR. \fBGdbm\fI does not automatically free this data. It is the programmer's responsibility to free this storage when it is -no longer needed.\fR - +no longer needed. To search for some data, without retrieving it: - ret = gdbm_exists ( dbf, key ) +.BI "int gdbm_exists (GDBM_FILE " dbf ", datum " key ); \fIDbf\fR is the pointer returned by \fBgdbm_open\fR. \fIKey\fR is the key data to search for. -If the \fIkey\fR is found within the database, the return value \fIret\fR -will be true. If nothing appropiate is found, \fIret\fR will be false. -This routine is useful for checking for the existance of a record, +If the \fIkey\fR is found within the database, the return value +will be true. If nothing appropiate is found, false is returned. +This routine is useful for checking for the existence of a record, without performing the memory allocation done by \fBgdbm_fetch\fR. - - +.PP To remove some data from the database: - ret = gdbm_delete ( dbf, key ) +.BI "int gdbm_delete (GDBM_FILE " dbf ", datum " key ); \fIDbf\fR is the pointer returned by \fBgdbm_open\fR. \fIKey\fR is the key data. @@ -380,21 +248,20 @@ key data. The return value is -1 if the item is not present or the requester is a reader. The return 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 ) +.BI "datum gdbm_firstkey (GDBM_FILE " dbf ");" +.br +.BI "datum gdbm_nextkey (GDBM_FILE " dbf ", datum " key ); \fIDbf\fR is the pointer returned by \fBgdbm_open\fR. \fIKey\fR is the key data. The return values are both of type \fBdatum\fR. If the \fIdptr\fR element of the return value is NULL, there is no first key or next key. -Again notice that \fIdptr\fR points to data allocated by \fBmalloc(3C)\fR +Again notice that \fIdptr\fR points to data allocated by \fBmalloc(3)\fR and \fBgdbm\fR will not free it for you. These functions were intended to visit the database in read-only algorithms, @@ -405,86 +272,85 @@ hash table to make sure that any collisions in the table do not leave some item `un-findable'. The original key order is NOT guaranteed to remain unchanged in ALL instances. It is possible that some key will not be visited if a loop like the following is executed: - - key = gdbm_firstkey ( dbf ); - while ( key.dptr ) { - nextkey = gdbm_nextkey ( dbf, key ); - if ( some condition ) { - gdbm_delete ( dbf, key ); - free ( key.dptr ); - } - key = nextkey; - } - - +.sp +.nf +.in +5 +key = gdbm_firstkey (dbf); +while (key.dptr) + { + nextkey = gdbm_nextkey (dbf, key); + if (some condition) + gdbm_delete ( dbf, key ); + free (key.dptr); + key = nextkey; + } +.in +.fi +.PP The following routine should be used very infrequently. - ret = gdbm_reorganize ( dbf ) +.BI "int gdbm_reorganize (GDBM_FILE " dbf ");" If you have had a lot of deletions and would like to shrink the space used by the \fBgdbm\fR file, this routine will reorganize the database. \fBGdbm\fR will not shorten the length of a \fBgdbm\fR file except by using this reorganization. (Deleted file space will be reused.) - -Unless your database was opened with the GDBM_SYNC flag, gdbm does not +Unless your database was opened with the \fBGDBM_SYNC\fR flag, \fBgdbm\fR does not wait for writes to be flushed to the disk before continuing. The following routine can be used to guarantee that the database is physically written to the disk file. - gdbm_sync ( dbf ) +.BI "void gdbm_sync (GDBM_FILE " dbf ");" It will not return until the disk file state is syncronized with the in-memory state of the database. - To convert a \fBgdbm\fR error code into English text, use this routine: - ret = gdbm_strerror ( errno ) - -Where \fIerrno\fR is of type \fIgdbm_error\fR, usually the global -variable \fIgdbm_errno\fR. The appropiate phrase is returned. - +.BI "const char *gdbm_strerror (gdbm_error " errno ); \fBGdbm\fR now supports the ability to set certain options on an already open database. - ret = gdbm_setopt ( dbf, option, value, size ) +.BI "int gdbm_setopt (GDBM_FILE " dbf ", int " option ", int " value ", int " size ); Where \fIdbf\fR is the return value from a previous call to \fBgdbm_open\fR, and \fIoption\fR specifies which option to set. The valid options are currently: - - \fBGDBM_CACHESIZE\fR - Set the size of the internal bucket - cache. This option may only be set once on each \fIGDBM_FILE\fR - descriptor, and is set automatically to 100 upon the first - access to the database. - - \fBGDBM_FASTMODE\fR - Set \fBfast mode\fR to either on or off. This - allows \fBfast mode\fR to be toggled on an already open and - active database. \fIvalue\fR (see below) should be set to either - TRUE or FALSE. \fIThis option is now obsolete.\fR - - \fBGDBM_SYNCMODE\fR - Turn on or off file system synchronization operations. - This setting defaults to off; \fIvalue\fR (see below) should be set to either - TRUE or FALSE. - - \fBGDBM_CENTFREE\fR - Set \fBcentral free block pool\fR to either on or off. - The default is off, which is how previous versions of \fBGdbm\fR - handled free blocks. If set, this option causes all subsequent free - blocks to be placed in the \fBglobal\fR pool, allowing (in thoery) - more file space to be reused more quickly. \fIvalue\fR (see below) should - be set to either TRUE or FALSE. - \fINOTICE: This feature is still under study.\fR - - \fBGDBM_COALESCEBLKS\fR - Set \fBfree block merging\fR to either on or off. - The default is off, which is how previous versions of \fBGdbm\fR - handled free blocks. If set, this option causes adjacent free blocks - to be merged. This can become a CPU expensive process with time, though, - especially if used in conjunction with \fBGDBM_CENTFREE\fR. \fIvalue\fR - (see below) should be set to either TRUE or FALSE. - \fINOTICE: This feature is still under study.\fR - +.TP +.B GDBM_CACHESIZE +Set the size of the internal bucket cache. This option may only be set once +on each \fIGDBM_FILE\fR descriptor, and is set automatically to 100 upon the +first access to the database. +.TP +.B GDBM_FASTMODE + Set \fBfast mode\fR to either on or off. This allows \fBfast mode\fR to +be toggled on an already open and active database. \fIvalue\fR (see below) +should be set to either TRUE or FALSE. \fIThis option is now obsolete.\fR +.TP +.B GDBM_SYNCMODE +Turn on or off file system synchronization operations. This setting defaults +to off; \fIvalue\fR (see below) should be set to either TRUE or FALSE. +.TP +.B GDBM_CENTFREE +Set \fBcentral free block pool\fR to either on or off. +The default is off, which is how previous versions of \fBGdbm\fR +handled free blocks. If set, this option causes all subsequent free +blocks to be placed in the \fBglobal\fR pool, allowing (in thoery) +more file space to be reused more quickly. \fIvalue\fR (see below) should +be set to either TRUE or FALSE. +\fINOTICE: This feature is still under study.\fR +.TP +.B GDBM_COALESCEBLKS + Set \fBfree block merging\fR to either on or off. +The default is off, which is how previous versions of \fBGdbm\fR +handled free blocks. If set, this option causes adjacent free blocks +to be merged. This can become a CPU expensive process with time, though, +especially if used in conjunction with \fBGDBM_CENTFREE\fR. \fIvalue\fR +(see below) should be set to either TRUE or FALSE. +\fINOTICE: This feature is still under study.\fR +.PP \fIvalue\fR is the value to set \fIoption\fR to, specified as an integer pointer. \fIsize\fR is the size of the data pointed to by \fIvalue\fR. The return value will be -1 upon failure, or 0 upon success. The global @@ -493,19 +359,22 @@ variable \fIgdbm_errno\fR will be set upon failure. For instance, to set a database to use a cache of 10, after opening it with \fBgdbm_open\fR, but prior to accessing it in any way, the following code could be used: - - int value = 10; +.sp +.nf +.in +5 +int value = 10; - ret = gdbm_setopt( dbf, GDBM_CACHESIZE, &value, sizeof(int)); - - +ret = gdbm_setopt( dbf, GDBM_CACHESIZE, &value, sizeof(int)); +.in +.fi +.PP If the database was opened with the \fBGDBM_NOLOCK\fR flag, the user may wish to perform their own file locking on the database file in order to prevent multiple writers operating on the same file simultaneously. In order to support this, the \fIgdbm_fdesc\fR routine is provided. - ret = gdbm_fdesc ( dbf ) +.BI "int gdbm_fdesc (GDBM_FILE " dbf ); Where \fIdbf\fR is the return value from a previous call to \fBgdbm_open\fR. The return value will be the file descriptor of the database. @@ -515,9 +384,8 @@ The following two external variables may be useful: \fIgdbm_errno\fR is the variable that contains more information about gdbm errors. (gdbm.h has the definitions of the error values and defines gdbm_errno as an external variable.) -.br -\fIgdbm_version\fR is the string containing the version information. +\fIgdbm_version\fR is the string containing the version information. There are a few more things of interest. First, \fBgdbm\fR files are not "sparse". You can copy them with the UNIX \fBcp(1)\fR command and @@ -530,27 +398,34 @@ All users in compatibility mode are assumed to be writers. If the also try to open it as a reader. All returned pointers in datum structures point to data that \fBgdbm\fR WILL free. They should be treated as static pointers (as standard UNIX \fBdbm\fR does). - - .SH LINKING This library is accessed by specifying \fI-lgdbm\fR as the last parameter to the compile line, e.g.: .sp - gcc -o prog prog.c -lgdbm - +.nf +.in +5 +gcc -o prog prog.c -lgdbm +.in +.fi +.PP If you wish to use the \fBdbm\fR or \fBndbm\fR compatibility routines, you must link in the \fIgdbm_compat\fR library as well. For example: .sp - gcc -o prog proc.c -lgdbm -lgdbm_compat - +.nf +.in +5 +gcc -o prog proc.c -lgdbm -lgdbm_compat +.in +.fi .SH BUGS +.SH "BUG REPORTS" +Send bug reports to . .SH "SEE ALSO" dbm, ndbm - .SH AUTHOR by Philip A. Nelson and Jason Downs. -Copyright (C) 1990 - 1999 Free Software Foundation, Inc. +.SH COPYRIGHT +Copyright \(co 1990 - 2011 Free Software Foundation, Inc. GDBM is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -563,9 +438,8 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License -along with GDBM; see the file COPYING. If not, write to -the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. - +along with GDBM. If not, see +.SH CONTACTS You may contact the original author by: .br e-mail: phil@cs.wwu.edu @@ -582,3 +456,10 @@ You may contact the current maintainer by: .br e-mail: downsj@downsj.com +.\" Local variables: +.\" eval: (add-hook 'write-file-hooks 'time-stamp) +.\" time-stamp-start: ".TH GDBM 3 \"" +.\" time-stamp-format: "%:B %:d, %:y" +.\" time-stamp-end: "\"" +.\" time-stamp-line-limit: 20 +.\" end: -- cgit v1.2.1