Towards GPL
[idzebra-moved-to-github.git] / isam / memory.h
1 /* $Id: memory.h,v 1.8 2002-08-02 19:26:56 adam Exp $
2    Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002
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 MEMORY_H
26 #define MEMORY_H
27
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31
32 extern int is_mbuf_size[3];
33
34 typedef unsigned int ISAM_P;
35
36 /*
37  * Memory buffer. Used to manage records (keys) in memory for
38  * reading and insertion/deletion.
39  */
40 typedef struct is_mbuf
41 {
42     int refcount;
43     int type;
44 #define IS_MBUF_TYPE_SMALL  0
45 #define IS_MBUF_TYPE_MEDIUM 1
46 #define IS_MBUF_TYPE_LARGE  2 
47     int offset;
48     int num;
49     int cur_record;
50     struct is_mbuf *next;
51     char *data;                 /* dummy */
52 } is_mbuf;
53
54 /*
55  * Structure describing the virtual image of a disk block.
56  * (these blocks may grow beyond the blocksize during insertion).
57  */
58 typedef struct is_mblock
59 {
60     int num_records;              /* number of records */
61     int diskpos;                  /* positive if this block is mapped */
62     int nextpos;                  /* pos of nxt blk. Only valid imm aft. rd. */
63     int bread;                    /* number of bytes read */
64     int state;                    /* state of block in rel. to disk block */
65 #define IS_MBSTATE_UNREAD  0          /* block hasn't been read */
66 #define IS_MBSTATE_PARTIAL 1          /* block has been partially read */
67 #define IS_MBSTATE_CLEAN   2          /* block is clean (unmodified) */
68 #define IS_MBSTATE_DIRTY   3          /* block has been modified */
69     is_mbuf *cur_mbuf;
70     is_mbuf *data;                /* data contained in block */
71
72     struct is_mblock *next;       /* next diskblock */
73 } is_mblock;
74
75 typedef struct isam_struct *ISAM;
76 /*
77  * Descriptor for a specific table.
78  */
79 typedef struct is_mtable
80 {
81     int num_records;               /* total number of records */
82     int pos_type;                  /* blocktype */
83     is_mblock *cur_mblock;
84     is_mbuf *last_mbuf;
85     is_mblock *data;               /* blocks contained in this table */
86     ISAM is;
87 } is_mtable;
88
89 is_mblock *xmalloc_mblock();
90 is_mbuf *xmalloc_mbuf(int type);
91 void xfree_mblock(is_mblock *p);
92 void xfree_mblocks(is_mblock *l);
93 void xfree_mbuf(is_mbuf *p);
94 void xfree_mbufs(is_mbuf *l);
95 void xrelease_mblock(is_mblock *p);
96 void is_m_establish_tab(ISAM is, is_mtable *tab, ISAM_P pos);
97 void is_m_release_tab(is_mtable *tab);
98 void is_m_rewind(is_mtable *tab);
99 void is_m_replace_record(is_mtable *tab, const void *rec);
100 int is_m_write_record(is_mtable *tab, const void *rec);
101 void is_m_unread_record(is_mtable *tab);
102 int is_m_read_record(is_mtable *tab, void *buf, int keep);
103 int is_m_seek_record(is_mtable *tab, const void *rec);
104 void is_m_delete_record(is_mtable *tab);
105 int is_m_peek_record(is_mtable *tab, void *rec);
106 int is_m_read_full(is_mtable *tab, is_mblock *mblock);
107 int is_m_num_records(is_mtable *tab);
108
109 #ifdef __cplusplus
110 }
111 #endif
112
113
114 #endif