8e854cef0e2271d867af5bceb51e38bdb3ff2f96
[idzebra-moved-to-github.git] / index / recindex.h
1 /* This file is part of the Zebra server.
2    Copyright (C) 1994-2009 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 #ifndef RECINDEX_H
21 #define RECINDEX_H
22
23 #include <idzebra/util.h>
24 #include <zebra-lock.h>
25 #include <idzebra/bfile.h>
26
27 YAZ_BEGIN_CDECL
28
29 #define REC_NO_INFO 8
30
31 typedef struct record_info {
32     zint sysno;
33     int newFlag;
34     char *info[REC_NO_INFO];
35     size_t size[REC_NO_INFO];
36     char buf_size[REC_NO_INFO][6];
37     size_t size_size[REC_NO_INFO];
38     Zebra_mutex mutex;
39 } *Record;
40
41 typedef struct records_info *Records;
42
43 /** \brief marks record for deletion (on file storage)
44     \param p records handle
45     \param recpp record pointer
46     \returns ZEBRA_OK / ZEBRA_FAIL
47 */
48 ZEBRA_RES rec_del(Records p, Record *recpp);
49
50 /** \brief frees record (from memory)
51     \param recpp record pointer
52 */
53 void rec_free(Record *recpp);
54
55 /** \brief puts record (writes into file storage)
56     \param p records handle
57     \param recpp record pointer
58     \returns ZEBRA_OK / ZEBRA_FAIL
59 */
60 ZEBRA_RES rec_put(Records p, Record *recpp);
61
62 /** \brief creates new record (to be written to file storage)
63     \param p records handle
64     \returns record pointer (or NULL on error)
65 */
66 Record rec_new(Records p);
67 /** \brief gets record - with given system number
68     \param p records handle
69     \param sysno system ID (external number)
70     \returns record pointer (or NULL on error)
71 */
72 Record rec_get(Records p, zint sysno);
73
74 /** \brief gets root record
75     \param p records handle
76     \returns record pointer (or NULL on error)
77 */
78 Record rec_get_root(Records p);
79 ZEBRA_RES rec_close (Records *p);
80
81 /** \brief opens records system
82     \param bfs block file storage
83     \param rw read-write flag(0=read only, 1=write)
84     \param compression_method REC_COMPRESS_ type 
85 */
86 Records rec_open(BFiles bfs, int rw, int compression_method);
87
88 /** \brief check whether a compression method is supported
89     \param compression_method (REC_COMPRESS_..)
90     \retval 0 if method is unsupported
91     \retval 1 if method is supported
92 */
93 int rec_check_compression_method(int compression_method);
94
95 char *rec_strdup(const char *s, size_t *len);
96 void rec_prstat(Records p, int verbose);
97
98 zint rec_sysno_to_int(zint sysno);
99
100
101 /** \brief No compression ("none") */
102 #define REC_COMPRESS_NONE   0
103 /** \brief BZIP2 compression (slow and requires big chunks) */
104 #define REC_COMPRESS_BZIP2  1
105 /** \brief zlib compression (faster and works off small chunks) */
106 #define REC_COMPRESS_ZLIB   2
107
108
109 enum { 
110     recInfo_fileType, 
111     recInfo_filename, 
112     recInfo_delKeys, 
113     recInfo_databaseName,
114     recInfo_storeData,
115     recInfo_attr,
116     recInfo_sortKeys
117 };
118
119 typedef struct recindex *recindex_t;
120
121 /** \brief opens record index handle
122     \param bfs Block files handle
123     \param rw 1 for read and write; 0 for read-only
124     \param use_isamb 1 if ISAMB is to used for record index; 0 for flat (old)
125 */
126 recindex_t recindex_open(BFiles bfs, int rw, int use_isamb);
127
128 /** \brief closes record index handle
129     \param p records handle
130 */
131 void recindex_close(recindex_t p);
132 int recindex_read_head(recindex_t p, void *buf);
133 const char *recindex_get_fname(recindex_t p);
134 ZEBRA_RES recindex_write_head(recindex_t p, const void *buf, size_t len);
135 int recindex_read_indx(recindex_t p, zint sysno, void *buf, int itemsize, 
136                        int ignoreError);
137 void recindex_write_indx(recindex_t p, zint sysno, void *buf, int itemsize);
138
139 YAZ_END_CDECL
140 #endif
141 /*
142  * Local variables:
143  * c-basic-offset: 4
144  * c-file-style: "Stroustrup"
145  * indent-tabs-mode: nil
146  * End:
147  * vim: shiftwidth=4 tabstop=8 expandtab
148  */
149