72 #define CURR_FORMAT 5U 118 uint4 *dest,
string &err_msg,
119 const string &basename,
124 err_msg +=
"Unable to read ";
136 const string &basename,
141 err_msg +=
"Unable to read ";
150 #define DO_UNPACK_UINT_ERRCHECK(start, end, var) \ 152 if (!do_unpack_uint(start, end, &var, err_msg, basename, #var)) { \ 163 #define REASONABLE_BASE_SIZE 1024 169 string basename = name +
"base" + ch;
172 err_msg +=
"Couldn't open ";
182 const char *start = buf;
189 err_msg +=
"Bad base file format " +
str(format) +
" in " +
199 uint4 have_fakeroot_;
221 err_msg +=
"Revision number mismatch in " +
239 size_t n = end - start;
258 err_msg +=
"Couldn't read revision3 from base file " +
264 err_msg +=
"Revision number mismatch in " +
271 err_msg +=
"Junk at end of base file " + basename +
"\n";
281 const string &tablename,
283 const string * changes_tail)
306 string message(
"Couldn't open base ");
308 message +=
" to write: ";
313 if (changes_fd >= 0) {
317 changes_buf += base_letter;
319 io_write(changes_fd, changes_buf.data(), changes_buf.size());
320 io_write(changes_fd, buf.data(), buf.size());
321 if (changes_tail != NULL) {
322 io_write(changes_fd, changes_tail->data(), changes_tail->size());
328 io_write(h, buf.data(), buf.size());
340 size_t i = n / CHAR_BIT;
341 int bit = 0x1 << n % CHAR_BIT;
353 uint4 i = n / CHAR_BIT;
354 int bit = 0x1 << n % CHAR_BIT;
370 uint4 i = n / CHAR_BIT;
371 int bit = 0x1 << n % CHAR_BIT;
386 #define BIT_MAP_INC 1000 393 uint8_t *new_bit_map0 = 0;
394 uint8_t *new_bit_map = 0;
397 new_bit_map0 =
new uint8_t[n];
398 new_bit_map =
new uint8_t[n];
406 delete [] new_bit_map0;
407 delete [] new_bit_map;
437 if (x != UCHAR_MAX)
break;
439 uint4 n = i * CHAR_BIT;
441 while ((x & d) != 0) { d <<= 1; n++; }
456 size_t offset = (*n) / CHAR_BIT;
457 int bit = 0x1 << (*n) % CHAR_BIT;
459 if (((
bit_map0[offset] & bit) == 0) && ((
bit_map[offset] & bit) != 0)) {
471 uint4 i = n / CHAR_BIT;
472 int bit = 0x1 << n % CHAR_BIT;
473 return (
bit_map[i] & bit) == 0;
480 while (i >= 0 &&
bit_map[i] == 0) {
493 uint4 n = (i + 1) * CHAR_BIT - 1;
494 int d = 0x1 << (CHAR_BIT - 1);
495 while ((x & d) == 0) { d >>= 1; n--; }
uint4 bit_map_low
byte offset into the bit map below which there are no free blocks
#define REASONABLE_BASE_SIZE
void io_write(int fd, const char *p, size_t n)
Write n bytes from block pointed to by p to file descriptor fd.
void swap(ChertTable_base &other)
~ChertTable_base()
Destructor - frees resources.
void calculate_last_block()
DatabaseOpeningError indicates failure to open a database.
bool io_sync(int fd)
Ensure all data previously written to file descriptor fd has been written to disk.
Provides wrappers with POSIXy semantics.
Convert errno value to std::string, thread-safe if possible.
Btree base file implementation.
static bool do_unpack_uint(const char **start, const char *end, uint4 *dest, string &err_msg, const string &basename, const char *varname)
Do most of the error handling from unpack_uint()
Convert types to std::string.
int revision()
Report the revision of the library which the program is linked with.
bool block_free_now(uint4 n) const
Hierarchy of classes which Xapian can throw as exceptions.
chert_tablesize_t item_count
void errno_to_string(int e, string &s)
unsigned long long chert_tablesize_t
A type used to store the number of entries in a table.
#define DO_UNPACK_UINT_ERRCHECK(start, end, var)
string str(int value)
Convert int to std::string.
Wrapper class around a file descriptor to avoid leaks.
bool find_changed_block(uint4 *n) const
Find the first changed block at or after position *n.
bool read(const std::string &name, char ch, bool read_bitmap, std::string &err_msg)
Read values from a base file.
size_t io_read(int fd, char *p, size_t n, size_t min)
Read n bytes (or until EOF) into block pointed to by p from file descriptor fd.
void pack_uint(std::string &s, U value)
Append an encoded unsigned integer to a string.
void pack_string(std::string &s, const std::string &value)
Append an encoded std::string to a string.
void write_to_file(const std::string &filename, char base_letter, const std::string &tablename, int changes_fd, const std::string *changes_tail)
Write the btree base file to disk.
Pack types into strings and unpack them again.
bool block_free_at_start(uint4 n) const
true iff block n was free at the start of the transaction on the B-tree.
Wrappers for low-level POSIX I/O routines.
uint8_t * bit_map
the current state of the bit map of blocks
bool unpack_uint(const char **p, const char *end, U *result)
Decode an unsigned integer from a string.
uint8_t * bit_map0
the initial state of the bit map of blocks: 1 means in use, 0 means free
static string format(const char *fmt, T value)
Various assertion macros.
ChertTable_base()
Construct an object with all zero fields.
#define CURR_FORMAT
This is the current description of the base file format: