Apache Portable Runtime Utility Library
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
sdbm_private.h
1 /* Licensed to the Apache Software Foundation (ASF) under one or more
2  * contributor license agreements. See the NOTICE file distributed with
3  * this work for additional information regarding copyright ownership.
4  * The ASF licenses this file to You under the Apache License, Version 2.0
5  * (the "License"); you may not use this file except in compliance with
6  * the License. You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 /*
18  * sdbm - ndbm work-alike hashed database library
19  * based on Per-Ake Larson's Dynamic Hashing algorithms. BIT 18 (1978).
20  * author: oz@nexus.yorku.ca
21  */
22 
23 #ifndef SDBM_PRIVATE_H
24 #define SDBM_PRIVATE_H
25 
26 #include "apr.h"
27 #include "apr_pools.h"
28 #include "apr_file_io.h"
29 #include "apr_errno.h" /* for apr_status_t */
30 
31 #if 0
32 /* if the block/page size is increased, it breaks perl apr_sdbm_t compatibility */
33 #define DBLKSIZ 16384
34 #define PBLKSIZ 8192
35 #define PAIRMAX 8008 /* arbitrary on PBLKSIZ-N */
36 #else
37 #define DBLKSIZ 4096
38 #define PBLKSIZ 1024
39 #define PAIRMAX 1008 /* arbitrary on PBLKSIZ-N */
40 #endif
41 #define SPLTMAX 10 /* maximum allowed splits */
42 
43 /* for apr_sdbm_t.flags */
44 #define SDBM_RDONLY 0x1 /* data base open read-only */
45 #define SDBM_SHARED 0x2 /* data base open for sharing */
46 #define SDBM_SHARED_LOCK 0x4 /* data base locked for shared read */
47 #define SDBM_EXCLUSIVE_LOCK 0x8 /* data base locked for write */
48 
49 struct apr_sdbm_t {
50  apr_pool_t *pool;
51  apr_file_t *dirf; /* directory file descriptor */
52  apr_file_t *pagf; /* page file descriptor */
53  apr_int32_t flags; /* status/error flags, see below */
54  long maxbno; /* size of dirfile in bits */
55  long curbit; /* current bit number */
56  long hmask; /* current hash mask */
57  long blkptr; /* current block for nextkey */
58  int keyptr; /* current key for nextkey */
59  long blkno; /* current page to read/write */
60  long pagbno; /* current page in pagbuf */
61  char pagbuf[PBLKSIZ]; /* page file block buffer */
62  long dirbno; /* current block in dirbuf */
63  char dirbuf[DBLKSIZ]; /* directory file block buffer */
64  int lckcnt; /* number of calls to sdbm_lock */
65 };
66 
67 
68 #define sdbm_hash apu__sdbm_hash
69 #define sdbm_nullitem apu__sdbm_nullitem
70 
71 extern const apr_sdbm_datum_t sdbm_nullitem;
72 
73 long sdbm_hash(const char *str, int len);
74 
75 /*
76  * zero the cache
77  */
78 #define SDBM_INVALIDATE_CACHE(db, finfo) \
79  do { db->dirbno = (!finfo.size) ? 0 : -1; \
80  db->pagbno = -1; \
81  db->maxbno = (long)(finfo.size * BYTESIZ); \
82  } while (0);
83 
84 #endif /* SDBM_PRIVATE_H */