Apache Portable Runtime
sdbm_private.h
00001 /* Licensed to the Apache Software Foundation (ASF) under one or more
00002  * contributor license agreements.  See the NOTICE file distributed with
00003  * this work for additional information regarding copyright ownership.
00004  * The ASF licenses this file to You under the Apache License, Version 2.0
00005  * (the "License"); you may not use this file except in compliance with
00006  * the License.  You may obtain a copy of the License at
00007  *
00008  *     http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 
00017 /*
00018  * sdbm - ndbm work-alike hashed database library
00019  * based on Per-Ake Larson's Dynamic Hashing algorithms. BIT 18 (1978).
00020  * author: oz@nexus.yorku.ca
00021  */
00022 
00023 #ifndef SDBM_PRIVATE_H
00024 #define SDBM_PRIVATE_H
00025 
00026 #include "apr.h"
00027 #include "apr_pools.h"
00028 #include "apr_file_io.h"
00029 #include "apr_errno.h" /* for apr_status_t */
00030 
00031 #if 0
00032 /* if the block/page size is increased, it breaks perl apr_sdbm_t compatibility */
00033 #define DBLKSIZ 16384
00034 #define PBLKSIZ 8192
00035 #define PAIRMAX 8008                    /* arbitrary on PBLKSIZ-N */
00036 #else
00037 #define DBLKSIZ 4096
00038 #define PBLKSIZ 1024
00039 #define PAIRMAX 1008                    /* arbitrary on PBLKSIZ-N */
00040 #endif
00041 #define SPLTMAX 10                      /* maximum allowed splits */
00042 
00043 /* for apr_sdbm_t.flags */
00044 #define SDBM_RDONLY             0x1    /* data base open read-only */
00045 #define SDBM_SHARED             0x2    /* data base open for sharing */
00046 #define SDBM_SHARED_LOCK        0x4    /* data base locked for shared read */
00047 #define SDBM_EXCLUSIVE_LOCK     0x8    /* data base locked for write */
00048 
00049 struct apr_sdbm_t {
00050     apr_pool_t *pool;
00051     apr_file_t *dirf;                  /* directory file descriptor */
00052     apr_file_t *pagf;                  /* page file descriptor */
00053     apr_int32_t flags;                 /* status/error flags, see below */
00054     long maxbno;                       /* size of dirfile in bits */
00055     long curbit;                       /* current bit number */
00056     long hmask;                        /* current hash mask */
00057     long blkptr;                       /* current block for nextkey */
00058     int  keyptr;                       /* current key for nextkey */
00059     long blkno;                        /* current page to read/write */
00060     long pagbno;                       /* current page in pagbuf */
00061     char pagbuf[PBLKSIZ];              /* page file block buffer */
00062     long dirbno;                       /* current block in dirbuf */
00063     char dirbuf[DBLKSIZ];              /* directory file block buffer */
00064     int  lckcnt;                       /* number of calls to sdbm_lock */
00065 };
00066 
00067 
00068 #define sdbm_hash apu__sdbm_hash
00069 #define sdbm_nullitem apu__sdbm_nullitem
00070 
00071 extern const apr_sdbm_datum_t sdbm_nullitem;
00072 
00073 long sdbm_hash(const char *str, int len);
00074 
00075 /*
00076  * zero the cache
00077  */
00078 #define SDBM_INVALIDATE_CACHE(db, finfo) \
00079     do { db->dirbno = (!finfo.size) ? 0 : -1; \
00080          db->pagbno = -1; \
00081          db->maxbno = (long)(finfo.size * BYTESIZ); \
00082     } while (0);
00083 
00084 #endif /* SDBM_PRIVATE_H */
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines