1 /* This file is part of the Zebra server.
2 Copyright (C) 1994-2010 Index Data
4 Zebra is free software; you can redistribute it and/or modify it under
5 the terms of the GNU General Public License as published by the Free
6 Software Foundation; either version 2, or (at your option) any later
9 Zebra is distributed in the hope that it will be useful, but WITHOUT ANY
10 WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 #include <yaz/yconfig.h>
29 /** \brief number of blocks in hash bucket */
30 #define HASH_BUCKET 15
32 /** \brief CFile hash structure on disc */
33 struct CFile_ph_bucket {
34 zint no[HASH_BUCKET]; /**< block number in original file */
35 zint vno[HASH_BUCKET];/**< block number in shadow file */
36 zint this_bucket; /**< this bucket number */
37 zint next_bucket; /**< next bucket number */
40 /** \brief CFile hash structure info in memory */
41 struct CFile_hash_bucket {
42 struct CFile_ph_bucket ph;
44 struct CFile_hash_bucket *h_next, **h_prev;
45 struct CFile_hash_bucket *lru_next, *lru_prev;
48 #define HASH_BSIZE sizeof(struct CFile_ph_bucket)
50 /** \brief state of CFile is a hash structure */
51 #define CFILE_STATE_HASH 1
53 /** \brief state of CFile is a flat file file */
54 #define CFILE_STATE_FLAT 2
56 /** \brief CFile file header */
58 int state; /**< CFILE_STATE_HASH, CFILE_STATE_FLAT, .. */
59 zint next_block; /**< next free block / last block */
60 int block_size; /**< mfile/bfile block size */
61 int hash_size; /**< no of chains in hash table */
62 zint first_bucket; /**< first hash bucket */
63 zint next_bucket; /**< last hash bucket + 1 = first flat bucket */
64 zint flat_bucket; /**< last flat bucket + 1 */
67 /** \brief All in-memory information per CFile */
68 typedef struct CFile_struct
70 struct CFile_head head;
72 MFile block_mf; /**< block meta file */
73 MFile hash_mf; /**< hash or index file (depending on state) */
74 zint *array; /**< array for hash */
75 struct CFile_hash_bucket **parray; /**< holds all hash bucket in memory */
76 struct CFile_hash_bucket *bucket_lru_front; /**< LRU front for hash */
77 struct CFile_hash_bucket *bucket_lru_back; /**< LRU back for hash */
78 int dirty; /**< whether CFile is dirty / header must be rewritten */
79 zint bucket_in_memory; /**< number of buckets in memory */
80 zint max_bucket_in_memory; /**< max number of buckets in memory */
81 char *iobuf; /**< data block .. of size block size */
82 MFile rmf; /**< read meta file (original data / not dirty) */
83 int no_hits; /**< number of bucket cache hits */
84 int no_miss; /**< number of bucket cache misses */
88 int cf_close (CFile cf);
90 CFile cf_open (MFile mf, MFile_area area, const char *fname, int block_size,
91 int wflag, int *firstp);
92 int cf_read (CFile cf, zint no, int offset, int nbytes, void *buf);
93 int cf_write (CFile cf, zint no, int offset, int nbytes, const void *buf);
94 int cf_commit (CFile cf) ZEBRA_GCC_ATTR((warn_unused_result));
102 * c-file-style: "Stroustrup"
103 * indent-tabs-mode: nil
105 * vim: shiftwidth=4 tabstop=8 expandtab