root/main/trunk/greenstone2/common-src/packages/gdbm/gdbm-1.8.3/gdbmdefs.h @ 25146

Revision 25146, 8.2 KB (checked in by sjm84, 9 years ago)

(Hopefully) fixed stdint.h issues for windows for GDBM

Line 
1/* gdbmdefs.h - The include file for dbm.  Defines structure and constants. */
2
3/*  This file is part of GDBM, the GNU data base manager, by Philip A. Nelson.
4    Copyright (C) 1990, 1991, 1993  Free Software Foundation, Inc.
5
6    GDBM is free software; you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation; either version 2, or (at your option)
9    any later version.
10
11    GDBM is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
15
16    You should have received a copy of the GNU General Public License
17    along with GDBM; see the file COPYING.  If not, write to
18    the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
19
20    You may contact the author by:
21       e-mail:  phil@cs.wwu.edu
22      us-mail:  Philip A. Nelson
23                Computer Science Department
24                Western Washington University
25                Bellingham, WA 98226
26*************************************************************************/
27
28#include "systems.h"
29#include "gdbmconst.h"
30
31/* On MacOS X, off_t is "long long int" but on Linux (CentOS) it is "long int"
32   Also, longs are different sizes between 32 and 64 bit machines.
33   The following ensures that we use the same for all systems, and so lets
34   GDBM read the same database files */
35#ifdef _unix_
36#include <stdint.h>
37#else
38typedef __int8            int8_t;
39typedef __int16           int16_t;
40typedef __int32           int32_t;
41typedef __int64           int64_t;
42typedef unsigned __int8   uint8_t;
43typedef unsigned __int16  uint16_t;
44typedef unsigned __int32  uint32_t;
45typedef unsigned __int64  uint64_t;
46#endif
47#undef off_t
48#define off_t int32_t
49
50/* The type definitions are next.  */
51
52/* The data and key structure.  This structure is defined for compatibility. */
53
54typedef struct {
55    char *dptr;
56    int   dsize;
57      } datum;
58
59
60/* The available file space is stored in an "avail" table.  The one with
61   most activity is contained in the file header. (See below.)  When that
62   one filles up, it is split in half and half is pushed on an "avail
63   stack."  When the active avail table is empty and the "avail stack" is
64   not empty, the top of the stack is popped into the active avail table. */
65
66/* The following structure is the element of the avaliable table.  */
67typedef struct {
68    int   av_size;      /* The size of the available block. */
69    off_t  av_adr;      /* The file address of the available block. */
70      } avail_elem;
71
72/* This is the actual table. The in-memory images of the avail blocks are
73   allocated by malloc using a calculated size.  */
74typedef struct {
75    int   size;     /* The number of avail elements in the table.*/
76    int   count;        /* The number of entries in the table. */
77    off_t next_block;   /* The file address of the next avail block. */
78    avail_elem av_table[1]; /* The table.  Make it look like an array.  */
79      } avail_block;
80
81/* The dbm file header keeps track of the current location of the hash
82   directory and the free space in the file.  */
83
84typedef struct {
85    int   header_magic;  /* 0x13579ace to make sure the header is good. */
86    int   block_size;    /* The  optimal i/o blocksize from stat. */
87    off_t dir;       /* File address of hash directory table. */
88    int   dir_size;      /* Size in bytes of the table.  */
89    int   dir_bits;      /* The number of address bits used in the table.*/
90    int   bucket_size;   /* Size in bytes of a hash bucket struct. */
91    int   bucket_elems;  /* Number of elements in a hash bucket. */
92    off_t next_block;    /* The next unallocated block address. */
93    avail_block avail;   /* This must be last because of the psuedo
94                array in avail.  This avail grows to fill
95                the entire block. */
96      }  gdbm_file_header;
97
98
99/* The dbm hash bucket element contains the full 31 bit hash value, the
100   "pointer" to the key and data (stored together) with their sizes.  It also
101   has a small part of the actual key value.  It is used to verify the first
102   part of the key has the correct value without having to read the actual
103   key. */
104
105typedef struct {
106    int   hash_value;   /* The complete 31 bit value. */
107    char  key_start[SMALL]; /* Up to the first SMALL bytes of the key.  */
108    off_t data_pointer; /* The file address of the key record. The
109                   data record directly follows the key.  */
110    int   key_size;     /* Size of key data in the file. */
111    int   data_size;    /* Size of associated data in the file. */
112      } bucket_element;
113
114
115/* A bucket is a small hash table.  This one consists of a number of
116   bucket elements plus some bookkeeping fields.  The number of elements
117   depends on the optimum blocksize for the storage device and on a
118   parameter given at file creation time.  This bucket takes one block.
119   When one of these tables gets full, it is split into two hash buckets.
120   The contents are split between them by the use of the first few bits
121   of the 31 bit hash function.  The location in a bucket is the hash
122   value modulo the size of the bucket.  The in-memory images of the
123   buckets are allocated by malloc using a calculated size depending of
124   the file system buffer size.  To speed up write, each bucket will have
125   BUCKET_AVAIL avail elements with the bucket. */
126
127typedef struct {
128        int   av_count;        /* The number of bucket_avail entries. */
129        avail_elem bucket_avail[BUCKET_AVAIL];  /* Distributed avail. */
130    int   bucket_bits;     /* The number of bits used to get here. */
131    int   count;           /* The number of element buckets full. */
132    bucket_element h_table[1]; /* The table.  Make it look like an array.*/
133      } hash_bucket;
134
135/* We want to keep from reading buckets as much as possible.  The following is
136   to implement a bucket cache.  When full, buckets will be dropped in a
137   least recently read from disk order.  */
138
139/* To speed up fetching and "sequential" access, we need to implement a
140   data cache for key/data pairs read from the file.  To find a key, we
141   must exactly match the key from the file.  To reduce overhead, the
142   data will be read at the same time.  Both key and data will be stored
143   in a data cache.  Each bucket cached will have a one element data
144   cache.  */
145
146typedef struct {
147        int   hash_val;
148    int   data_size;
149    int   key_size;
150    char *dptr;
151    int   elem_loc;
152      }  data_cache_elem;
153
154typedef struct {
155        hash_bucket *   ca_bucket;
156    off_t           ca_adr;
157    char        ca_changed;   /* Data in the bucket changed. */
158    data_cache_elem ca_data;
159      } cache_elem;
160
161
162
163/* This final structure contains all main memory based information for
164   a gdbm file.  This allows multiple gdbm files to be opened at the same
165   time by one program. */
166
167typedef struct {
168    /* Global variables and pointers to dynamic variables used by gdbm.  */
169
170    /* The file name. */
171    char *name;
172
173    /* The reader/writer status. */
174    int read_write;
175
176    /* Fast_write is set to 1 if no fsyncs are to be done. */
177    int fast_write;
178
179    /* Central_free is set if all free blocks are kept in the header. */
180    int central_free;
181
182    /* Coalesce_blocks is set if we should try to merge free blocks. */
183    int coalesce_blocks;
184
185    /* Whether or not we should do file locking ourselves. */
186    int file_locking;
187
188    /* The fatal error handling routine. */
189    void (*fatal_err) ();
190
191#ifdef MSDOS
192        int need_filelock;
193#endif
194
195    /* The gdbm file descriptor which is set in gdbm_open.  */
196    int desc;
197
198    /* The file header holds information about the database. */
199    gdbm_file_header *header;
200
201    /* The hash table directory from extendible hashing.  See Fagin et al,
202       ACM Trans on Database Systems, Vol 4, No 3. Sept 1979, 315-344 */
203    off_t *dir;
204
205    /* The bucket cache. */
206    cache_elem *bucket_cache;
207    int cache_size;
208    int last_read;
209
210    /* Points to the current hash bucket in the cache. */
211    hash_bucket *bucket;
212
213    /* The directory entry used to get the current hash bucket. */
214    int bucket_dir;
215
216    /* Pointer to the current bucket's cache entry. */
217    cache_elem *cache_entry;
218
219
220    /* Bookkeeping of things that need to be written back at the
221       end of an update. */
222    char  header_changed;
223    char  directory_changed;
224    char  bucket_changed;
225    char  second_changed;
226   
227      } gdbm_file_info;
228
229/* Now define all the routines in use. */
230#include "proto.h"
Note: See TracBrowser for help on using the browser.