1 /** @file chert_check.h
2  * @brief Btree checking
3  */
4 /* Copyright 1999,2000,2001 BrightStation PLC
5  * Copyright 2002 Ananova Ltd
6  * Copyright 2002,2004,2005,2006,2008,2011,2012,2013,2014 Olly Betts
7  * Copyright 2008 Lemur Consulting Ltd
8  *
9  * This program is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License as
11  * published by the Free Software Foundation; either version 2 of the
12  * License, or (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301
22  * USA
23  */
24 
25 #ifndef OM_HGUARD_CHERT_CHECK_H
26 #define OM_HGUARD_CHERT_CHECK_H
27 
28 #include "chert_table.h"
29 #include "noreturn.h"
30 
31 #include <iosfwd>
32 #include <string>
33 
34 class ChertTableCheck : public ChertTable {
35     public:
36 	static void check(const char * tablename, const std::string & path,
37 			  chert_revision_number_t * rev_ptr,
38 			  int opts, std::ostream *out);
39     private:
ChertTableCheck(const char * tablename_,const std::string & path_,bool readonly,std::ostream * out_)40 	ChertTableCheck(const char * tablename_, const std::string &path_,
41 			bool readonly, std::ostream *out_)
42 	    : ChertTable(tablename_, path_, readonly), out(out_),
43 	      check_item_count(0), check_sequential(true),
44 	      last_sequential_block(0) { }
45 
46 	void block_check(Cursor * C_, int j, int opts);
47 	int block_usage(const uint8_t * p) const;
48 	void report_block(int m, int n, const uint8_t * p) const;
49 	void report_block_full(int m, int n, const uint8_t * p) const;
50 	void report_cursor(int N, const Cursor *C_) const;
51 
52 	XAPIAN_NORETURN(void failure(const char * msg) const);
53 	void print_key(const uint8_t * p, int c, int j) const;
54 	void print_tag(const uint8_t * p, int c, int j) const;
55 	void print_spaces(int n) const;
56 	void print_bytes(int n, const uint8_t * p) const;
57 
58 	std::ostream *out;
59 
60 	chert_tablesize_t check_item_count;
61 
62 	bool check_sequential;
63 
64 	uint4 last_sequential_block;
65 };
66 
67 #endif /* OM_HGUARD_CHERT_CHECK_H */
68