sdbm_private.h revision 259065
113065Skvn/* Licensed to the Apache Software Foundation (ASF) under one or more 213065Skvn * contributor license agreements. See the NOTICE file distributed with 313065Skvn * this work for additional information regarding copyright ownership. 413065Skvn * The ASF licenses this file to You under the Apache License, Version 2.0 513065Skvn * (the "License"); you may not use this file except in compliance with 613065Skvn * the License. You may obtain a copy of the License at 713065Skvn * 813065Skvn * http://www.apache.org/licenses/LICENSE-2.0 913065Skvn * 1013065Skvn * Unless required by applicable law or agreed to in writing, software 1113065Skvn * distributed under the License is distributed on an "AS IS" BASIS, 1213065Skvn * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1313065Skvn * See the License for the specific language governing permissions and 1413065Skvn * limitations under the License. 1513065Skvn */ 1613065Skvn 1713065Skvn/* 1813065Skvn * sdbm - ndbm work-alike hashed database library 1913065Skvn * based on Per-Ake Larson's Dynamic Hashing algorithms. BIT 18 (1978). 2013065Skvn * author: oz@nexus.yorku.ca 2113065Skvn */ 2213065Skvn 2313065Skvn#ifndef SDBM_PRIVATE_H 2413065Skvn#define SDBM_PRIVATE_H 2513065Skvn 2613065Skvn#include "apr.h" 2713065Skvn#include "apr_pools.h" 2813065Skvn#include "apr_file_io.h" 2913065Skvn#include "apr_errno.h" /* for apr_status_t */ 3013065Skvn 3113065Skvn#if 0 3213065Skvn/* if the block/page size is increased, it breaks perl apr_sdbm_t compatibility */ 3313065Skvn#define DBLKSIZ 16384 3413065Skvn#define PBLKSIZ 8192 3513065Skvn#define PAIRMAX 8008 /* arbitrary on PBLKSIZ-N */ 3613065Skvn#else 3713065Skvn#define DBLKSIZ 4096 3813065Skvn#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 49struct 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 71extern const apr_sdbm_datum_t sdbm_nullitem; 72 73long 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 */ 85