3676941731a8668a5414e563d89ee25cf15c03d6
[idzebra-moved-to-github.git] / index / recindex.h
1 /* $Id: recindex.h,v 1.34 2008-03-05 09:15:04 adam Exp $
2    Copyright (C) 1995-2008
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 this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
20
21 */
22
23 #ifndef RECINDEX_H
24 #define RECINDEX_H
25
26 #include <idzebra/util.h>
27 #include <zebra-lock.h>
28 #include <idzebra/bfile.h>
29
30 YAZ_BEGIN_CDECL
31
32 #define REC_NO_INFO 8
33
34 typedef struct record_info {
35     zint sysno;
36     int newFlag;
37     char *info[REC_NO_INFO];
38     size_t size[REC_NO_INFO];
39     char buf_size[REC_NO_INFO][6];
40     size_t size_size[REC_NO_INFO];
41     Zebra_mutex mutex;
42 } *Record;
43
44 typedef struct records_info *Records;
45
46 /** \brief marks record for deletion (on file storage)
47     \param p records handle
48     \param recpp record pointer
49     \returns ZEBRA_OK / ZEBRA_FAIL
50 */
51 ZEBRA_RES rec_del(Records p, Record *recpp);
52
53 /** \brief frees record (from memory)
54     \param recpp record pointer
55 */
56 void rec_free(Record *recpp);
57
58 /** \brief puts record (writes into file storage)
59     \param p records handle
60     \param recpp record pointer
61     \returns ZEBRA_OK / ZEBRA_FAIL
62 */
63 ZEBRA_RES rec_put(Records p, Record *recpp);
64
65 /** \brief creates new record (to be written to file storage)
66     \param p records handle
67     \returns record pointer (or NULL on error)
68 */
69 Record rec_new(Records p);
70 /** \brief gets record - with given system number
71     \param p records handle
72     \param sysno system ID (external number)
73     \returns record pointer (or NULL on error)
74 */
75 Record rec_get(Records p, zint sysno);
76
77 /** \brief gets root record
78     \param p records handle
79     \returns record pointer (or NULL on error)
80 */
81 Record rec_get_root(Records p);
82 ZEBRA_RES rec_close (Records *p);
83
84 /** \brief opens records system
85     \param bfs block file storage
86     \param rw read-write flag(0=read only, 1=write)
87     \param compression_method REC_COMPRESS_ type 
88 */
89 Records rec_open(BFiles bfs, int rw, int compression_method);
90
91 char *rec_strdup(const char *s, size_t *len);
92 void rec_prstat(Records p);
93
94 zint rec_sysno_to_int(zint sysno);
95
96 /** \brief compression types */
97 #define REC_COMPRESS_NONE   0
98 #define REC_COMPRESS_BZIP2  1
99
100 enum { 
101     recInfo_fileType, 
102     recInfo_filename, 
103     recInfo_delKeys, 
104     recInfo_databaseName,
105     recInfo_storeData,
106     recInfo_attr,
107     recInfo_sortKeys
108 };
109
110 typedef struct recindex *recindex_t;
111
112 /** \brief opens record index handle
113     \param bfs Block files handle
114     \param rw 1 for read and write; 0 for read-only
115     \param use_isamb 1 if ISAMB is to used for record index; 0 for flat (old)
116 */
117 recindex_t recindex_open(BFiles bfs, int rw, int use_isamb);
118
119 /** \brief closes record index handle
120     \param p records handle
121 */
122 void recindex_close(recindex_t p);
123 int recindex_read_head(recindex_t p, void *buf);
124 const char *recindex_get_fname(recindex_t p);
125 ZEBRA_RES recindex_write_head(recindex_t p, const void *buf, size_t len);
126 int recindex_read_indx(recindex_t p, zint sysno, void *buf, int itemsize, 
127                        int ignoreError);
128 void recindex_write_indx(recindex_t p, zint sysno, void *buf, int itemsize);
129
130 YAZ_END_CDECL
131 #endif
132 /*
133  * Local variables:
134  * c-basic-offset: 4
135  * indent-tabs-mode: nil
136  * End:
137  * vim: shiftwidth=4 tabstop=8 expandtab
138  */
139