1 /*------------------------------------------------------------------------------
2 *
3 * Copyright (c) 2011-2021, EURid vzw. All rights reserved.
4 * The YADIFA TM software product is provided under the BSD 3-clause license:
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * * Neither the name of EURid nor the names of its contributors may be
16 * used to endorse or promote products derived from this software
17 * without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
30 *
31 *------------------------------------------------------------------------------
32 *
33 */
34
35 #pragma once
36
37 #include <dnsdb/journal-cjf-page.h>
38
39 void journal_cjf_idxt_flush(journal_cjf *jnl);
40
41 const journal_cjf_idxt_tbl_item *journal_cjf_idxt_get_entry(const journal_cjf *jnl, s16 index);
42
43 /**
44 *
45 * Returns the last serial number value at index in the IDXT
46 *
47 * @param jnl
48 * @param index
49 * @return
50 */
51
52 u32 journal_cjf_idxt_get_last_serial(const journal_cjf *jnl, s16 index);
53
54 /**
55 *
56 * Returns the file offset value at index in the current IDXT
57 *
58 * @param jnl
59 * @param index
60 * @return
61 */
62
63 u32 journal_cjf_idxt_get_file_offset(const journal_cjf *jnl, s16 index);
64
65 /**
66 * Appends an PAGE after this one
67 *
68 * @param jnl
69 */
70
71 void journal_cjf_idxt_append_page(journal_cjf *jnl);
72
73 /**
74 * Updates the value of the last serial at current position in the PAGE
75 *
76 * @param jnl
77 * @param last_serial
78 */
79
80 void journal_cjf_idxt_update_last_serial(journal_cjf *jnl, u32 last_serial);
81
82 /**
83 *
84 * Flushes the IDXT to disk if needed, then destroys the structure content.
85 *
86 * @param jnl
87 */
88
89 void journal_cjf_idxt_destroy(journal_cjf *jnl);
90
91 /**
92 * Creates an empty table of indexes (IDXT) for the journal, with a minimum number of entries.
93 * Nothing is written to disk.
94 *
95 * @param jnl
96 * @param entries
97 */
98
99 void journal_cjf_idxt_create(journal_cjf *jnl, s16 entries);
100
101 /**
102 * Loads (or rebuilds) the table of indexes (IDXT)
103 *
104 * @param jnl
105 */
106
107 void journal_cjf_idxt_load(journal_cjf *jnl);
108
109 u32 journal_cjf_idxt_get_last_file_offset(const journal_cjf *jnl);
110
111 u32 journal_cjf_idxt_get_page_serial_from_index(const journal_cjf *jnl, int idx);
112
113 ya_result journal_cjf_idxt_get_page_offset_from_serial(const journal_cjf *jnl, u32 serial, u32 *file_offset);
114
115 ya_result journal_cjf_idxt_get_page_index_from_serial(const journal_cjf *jnl, u32 serial);
116
117 ya_result journal_cjf_idxt_get_page_serial_to(const journal_cjf *jnl, int idx);
118
119 u32 journal_cjf_idxt_get_page_offset(const journal_cjf *jnl, int idx);
120
journal_cjf_idxt_get_page_count(journal_cjf * jnl)121 static inline u32 journal_cjf_idxt_get_page_count(journal_cjf *jnl)
122 {
123 return jnl->idxt.count;
124 }
125