c162aa69b0df0bd4b31d1e7d408c6d67cddfb0ba
[idzebra-moved-to-github.git] / bfile / cfile.h
1 /* $Id: cfile.h,v 1.17 2005-01-15 19:38:17 adam Exp $
2    Copyright (C) 1995-2005
3    Index Data ApS
4
5 This file is part of the Zebra server.
6
7 Zebra is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
10 version.
11
12 Zebra is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
15 for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with Zebra; see the file LICENSE.zebra.  If not, write to the
19 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
20 02111-1307, USA.
21 */
22
23
24
25 #ifndef CFILE_H
26 #define CFILE_H
27
28 #include <yaz/yconfig.h>
29
30 YAZ_BEGIN_CDECL
31
32 #define HASH_BUCKET 15
33
34 struct CFile_ph_bucket {     /* structure on disc */
35     zint no[HASH_BUCKET];    /* block number in original file */
36     zint vno[HASH_BUCKET];   /* block number in shadow file */
37     zint this_bucket;        /* this bucket number */
38     zint next_bucket;        /* next bucket number */
39 };
40
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 #define CFILE_FLAT 1
51
52 typedef struct CFile_struct
53 {
54     struct CFile_head {
55         int state;               /* 1 = hash, 2 = flat */
56         zint next_block;          /* next free block / last block */
57         int block_size;          /* mfile/bfile block size */
58         int hash_size;           /* no of chains in hash table */
59         zint first_bucket;       /* first hash bucket */
60         zint next_bucket;        /* last hash bucket + 1 = first flat bucket */
61         zint flat_bucket;        /* last flat bucket + 1 */
62     } head;
63     MFile block_mf;
64     MFile hash_mf;
65     zint *array;
66     struct CFile_hash_bucket **parray;
67     struct CFile_hash_bucket *bucket_lru_front, *bucket_lru_back;
68     int dirty;
69     zint bucket_in_memory;
70     zint max_bucket_in_memory;
71     char *iobuf;
72     MFile rmf;
73     int  no_hits;
74     int  no_miss;
75     Zebra_mutex mutex;
76 } *CFile;
77
78 int cf_close (CFile cf);
79 CFile cf_open (MFile mf, MFile_area area, const char *fname, int block_size,
80                int wflag, int *firstp);
81 int cf_read (CFile cf, zint no, int offset, int nbytes, void *buf);
82 int cf_write (CFile cf, zint no, int offset, int nbytes, const void *buf);
83 void cf_unlink (CFile cf);
84 void cf_commit (CFile cf);
85
86 YAZ_END_CDECL
87
88 #endif