Reformat: delete trailing whitespace
[idzebra-moved-to-github.git] / bfile / cfile.h
1 /* This file is part of the Zebra server.
2    Copyright (C) 1994-2011 Index Data
3
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
7 version.
8
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
12 for more details.
13
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
17
18 */
19
20
21
22 #ifndef CFILE_H
23 #define CFILE_H
24
25 #include <yaz/yconfig.h>
26
27 YAZ_BEGIN_CDECL
28
29 /** \brief number of blocks in hash bucket */
30 #define HASH_BUCKET 15
31
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 */
38 };
39
40 /** \brief CFile hash structure info in memory */
41 struct CFile_hash_bucket {
42     struct CFile_ph_bucket ph;
43     int dirty;
44     struct CFile_hash_bucket *h_next, **h_prev;
45     struct CFile_hash_bucket *lru_next, *lru_prev;
46 };
47
48 #define HASH_BSIZE sizeof(struct CFile_ph_bucket)
49
50 /** \brief state of CFile is a hash structure */
51 #define CFILE_STATE_HASH 1
52
53 /** \brief state of CFile is a flat file file */
54 #define CFILE_STATE_FLAT 2
55
56 /** \brief CFile file header */
57 struct CFile_head {
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 */
65 };
66
67 /** \brief All in-memory information per CFile */
68 typedef struct CFile_struct
69 {
70     struct CFile_head head;
71
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 */
85     Zebra_mutex mutex;
86 } *CFile;
87
88 int cf_close (CFile cf);
89
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));
95
96 YAZ_END_CDECL
97
98 #endif
99 /*
100  * Local variables:
101  * c-basic-offset: 4
102  * c-file-style: "Stroustrup"
103  * indent-tabs-mode: nil
104  * End:
105  * vim: shiftwidth=4 tabstop=8 expandtab
106  */
107