ef0a692ddced1b46021c89d5e2fde90134fd17a9
[idzebra-moved-to-github.git] / bfile / cfile.h
1 /*
2  * Copyright (C) 1995-1999, Index Data
3  * All rights reserved.
4  * Sebastian Hammer, Adam Dickmeiss
5  *
6  * $Id: cfile.h,v 1.13 2000-03-20 19:08:35 adam Exp $
7  */
8
9 #ifndef CFILE_H
10 #define CFILE_H
11
12 #include <yaz/yconfig.h>
13
14 YAZ_BEGIN_CDECL
15
16 #define HASH_BUCKET 15
17
18 struct CFile_ph_bucket {     /* structure on disc */
19     int no[HASH_BUCKET];     /* block number in original file */
20     int vno[HASH_BUCKET];    /* block number in shadow file */
21     int this_bucket;         /* this bucket number */
22     int next_bucket;         /* next bucket number */
23 };
24
25 struct CFile_hash_bucket {
26     struct CFile_ph_bucket ph;
27     int dirty;
28     struct CFile_hash_bucket *h_next, **h_prev;
29     struct CFile_hash_bucket *lru_next, *lru_prev;
30 };
31
32 #define HASH_BSIZE sizeof(struct CFile_ph_bucket)
33
34 #define CFILE_FLAT 1
35
36 typedef struct CFile_struct
37 {
38     struct CFile_head {
39         int state;               /* 1 = hash, 2 = flat */
40         int next_block;          /* next free block / last block */
41         int block_size;          /* mfile/bfile block size */
42         int hash_size;           /* no of chains in hash table */
43         int first_bucket;        /* first hash bucket */
44         int next_bucket;         /* last hash bucket + 1 = first flat bucket */
45         int flat_bucket;         /* last flat bucket + 1 */
46     } head;
47     MFile block_mf;
48     MFile hash_mf;
49     int *array;
50     struct CFile_hash_bucket **parray;
51     struct CFile_hash_bucket *bucket_lru_front, *bucket_lru_back;
52     int dirty;
53     int bucket_in_memory;
54     int max_bucket_in_memory;
55     char *iobuf;
56     MFile rmf;
57     int  no_hits;
58     int  no_miss;
59     Zebra_mutex mutex;
60 } *CFile;
61
62 int cf_close (CFile cf);
63 CFile cf_open (MFile mf, MFile_area area, const char *fname, int block_size,
64                int wflag, int *firstp);
65 int cf_read (CFile cf, int no, int offset, int nbytes, void *buf);
66 int cf_write (CFile cf, int no, int offset, int nbytes, const void *buf);
67 void cf_unlink (CFile cf);
68 void cf_commit (CFile cf);
69
70 YAZ_END_CDECL
71
72 #endif